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