1 | package de.ugoe.cs.quest.ui.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.quest.eventcore.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 | *
|
---|
34 | * @param parent
|
---|
35 | * @param style
|
---|
36 | */
|
---|
37 | public InsertAssertionDialog(Shell parent, int style, SortedSet<String> targets) {
|
---|
38 | super(parent, style);
|
---|
39 | setText("SWT Dialog");
|
---|
40 | this.targets = targets;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Open the dialog.
|
---|
45 | *
|
---|
46 | * @return the result
|
---|
47 | */
|
---|
48 | public Event open() {
|
---|
49 | result = null;
|
---|
50 | insertEventComposites = new ArrayList<AbstractInsertEventComposite>();
|
---|
51 | createContents();
|
---|
52 | shell.open();
|
---|
53 | shell.layout();
|
---|
54 | Display display = getParent().getDisplay();
|
---|
55 | while (!shell.isDisposed()) {
|
---|
56 | if (!display.readAndDispatch()) {
|
---|
57 | display.sleep();
|
---|
58 | }
|
---|
59 | }
|
---|
60 | return result;
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Create contents of the dialog.
|
---|
65 | */
|
---|
66 | private void createContents() {
|
---|
67 | shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL);
|
---|
68 | shell.setSize(450, 300);
|
---|
69 | shell.setText(getText());
|
---|
70 | shell.setLayout(new GridLayout(2, false));
|
---|
71 |
|
---|
72 | tabFolder = new TabFolder(shell, SWT.NONE);
|
---|
73 | tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
---|
74 |
|
---|
75 | TabItem tbtmTextEquals = new TabItem(tabFolder, SWT.NONE);
|
---|
76 | tbtmTextEquals.setText("TextEquals");
|
---|
77 | AbstractInsertEventComposite compTextEquals =
|
---|
78 | new InsertTextEquals(tabFolder, SWT.NO_BACKGROUND, targets);
|
---|
79 | tbtmTextEquals.setControl(compTextEquals);
|
---|
80 | insertEventComposites.add(compTextEquals);
|
---|
81 |
|
---|
82 | TabItem tbtmFileEquals = new TabItem(tabFolder, SWT.NONE);
|
---|
83 | tbtmFileEquals.setText("FileEquals");
|
---|
84 | AbstractInsertEventComposite compFileEquals =
|
---|
85 | new InsertFileEquals(tabFolder, SWT.NO_BACKGROUND, targets);
|
---|
86 | tbtmFileEquals.setControl(compFileEquals);
|
---|
87 | insertEventComposites.add(compFileEquals);
|
---|
88 |
|
---|
89 | Button btnInsert = new Button(shell, SWT.NONE);
|
---|
90 | btnInsert.setText("Insert");
|
---|
91 | btnInsert.addSelectionListener(new SelectionAdapter() {
|
---|
92 | @Override
|
---|
93 | public void widgetSelected(SelectionEvent e) {
|
---|
94 | int index = tabFolder.getSelectionIndex();
|
---|
95 | result = insertEventComposites.get(index).getEvent();
|
---|
96 | shell.dispose();
|
---|
97 | }
|
---|
98 | });
|
---|
99 |
|
---|
100 | Button btnAbort = new Button(shell, SWT.NONE);
|
---|
101 | btnAbort.setText("Abort");
|
---|
102 | btnAbort.addSelectionListener(new SelectionAdapter() {
|
---|
103 | @Override
|
---|
104 | public void widgetSelected(SelectionEvent e) {
|
---|
105 | shell.dispose();
|
---|
106 | }
|
---|
107 | });
|
---|
108 | }
|
---|
109 | }
|
---|