1 | package de.ugoe.cs.eventbench.swt;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 | import java.util.SortedSet;
|
---|
6 |
|
---|
7 | import org.eclipse.swt.widgets.Dialog;
|
---|
8 | import org.eclipse.swt.widgets.Display;
|
---|
9 | import org.eclipse.swt.widgets.Shell;
|
---|
10 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
11 | import org.eclipse.swt.events.SelectionEvent;
|
---|
12 | import org.eclipse.swt.layout.GridLayout;
|
---|
13 | import org.eclipse.swt.widgets.TabFolder;
|
---|
14 | import org.eclipse.swt.SWT;
|
---|
15 | import org.eclipse.swt.widgets.TabItem;
|
---|
16 | import org.eclipse.swt.layout.GridData;
|
---|
17 | import org.eclipse.swt.widgets.Button;
|
---|
18 |
|
---|
19 | import de.ugoe.cs.eventbench.data.Event;
|
---|
20 |
|
---|
21 | public class InsertAssertionDialog extends Dialog {
|
---|
22 |
|
---|
23 | protected Event<?> result;
|
---|
24 | protected Shell shell;
|
---|
25 |
|
---|
26 | private TabFolder tabFolder;
|
---|
27 |
|
---|
28 | List<AbstractInsertEventComposite> insertEventComposites;
|
---|
29 | SortedSet<String> targets;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Create the dialog.
|
---|
33 | * @param parent
|
---|
34 | * @param style
|
---|
35 | */
|
---|
36 | public InsertAssertionDialog(Shell parent, int style, SortedSet<String> targets) {
|
---|
37 | super(parent, style);
|
---|
38 | setText("SWT Dialog");
|
---|
39 | this.targets = targets;
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Open the dialog.
|
---|
44 | * @return the result
|
---|
45 | */
|
---|
46 | public Event<?> open() {
|
---|
47 | result = null;
|
---|
48 | insertEventComposites = new ArrayList<AbstractInsertEventComposite>();
|
---|
49 | createContents();
|
---|
50 | shell.open();
|
---|
51 | shell.layout();
|
---|
52 | Display display = getParent().getDisplay();
|
---|
53 | while (!shell.isDisposed()) {
|
---|
54 | if (!display.readAndDispatch()) {
|
---|
55 | display.sleep();
|
---|
56 | }
|
---|
57 | }
|
---|
58 | return result;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Create contents of the dialog.
|
---|
63 | */
|
---|
64 | private void createContents() {
|
---|
65 | shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL);
|
---|
66 | shell.setSize(450, 300);
|
---|
67 | shell.setText(getText());
|
---|
68 | shell.setLayout(new GridLayout(2, false));
|
---|
69 |
|
---|
70 | tabFolder = new TabFolder(shell, SWT.NONE);
|
---|
71 | tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
---|
72 |
|
---|
73 |
|
---|
74 | TabItem tbtmTextEquals = new TabItem(tabFolder, SWT.NONE);
|
---|
75 | tbtmTextEquals.setText("TextEquals");
|
---|
76 | AbstractInsertEventComposite compTextEquals = new InsertTextEquals(tabFolder, SWT.NO_BACKGROUND, targets);
|
---|
77 | tbtmTextEquals.setControl(compTextEquals);
|
---|
78 | insertEventComposites.add(compTextEquals);
|
---|
79 |
|
---|
80 | TabItem tbtmFileEquals = new TabItem(tabFolder, SWT.NONE);
|
---|
81 | tbtmFileEquals.setText("FileEquals");
|
---|
82 | AbstractInsertEventComposite compFileEquals = new InsertFileEquals(tabFolder, SWT.NO_BACKGROUND, targets);
|
---|
83 | tbtmFileEquals.setControl(compFileEquals);
|
---|
84 | insertEventComposites.add(compFileEquals);
|
---|
85 |
|
---|
86 | Button btnInsert = new Button(shell, SWT.NONE);
|
---|
87 | btnInsert.setText("Insert");
|
---|
88 | btnInsert.addSelectionListener(new SelectionAdapter() {
|
---|
89 | @Override
|
---|
90 | public void widgetSelected(SelectionEvent e) {
|
---|
91 | int index = tabFolder.getSelectionIndex();
|
---|
92 | result = insertEventComposites.get(index).getEvent();
|
---|
93 | shell.dispose();
|
---|
94 | }
|
---|
95 | });
|
---|
96 |
|
---|
97 | Button btnAbort = new Button(shell, SWT.NONE);
|
---|
98 | btnAbort.setText("Abort");
|
---|
99 | btnAbort.addSelectionListener(new SelectionAdapter() {
|
---|
100 | @Override
|
---|
101 | public void widgetSelected(SelectionEvent e) {
|
---|
102 | shell.dispose();
|
---|
103 | }
|
---|
104 | });
|
---|
105 | }
|
---|
106 | }
|
---|