1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany
|
---|
2 | //
|
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
---|
4 | // you may not use this file except in compliance with the License.
|
---|
5 | // You may obtain a copy of the License at
|
---|
6 | //
|
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0
|
---|
8 | //
|
---|
9 | // Unless required by applicable law or agreed to in writing, software
|
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS,
|
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
12 | // See the License for the specific language governing permissions and
|
---|
13 | // limitations under the License.
|
---|
14 |
|
---|
15 | package de.ugoe.cs.autoquest.ui.swt;
|
---|
16 |
|
---|
17 | import java.util.ArrayList;
|
---|
18 | import java.util.List;
|
---|
19 |
|
---|
20 | import org.eclipse.swt.widgets.Dialog;
|
---|
21 | import org.eclipse.swt.widgets.Display;
|
---|
22 | import org.eclipse.swt.widgets.Shell;
|
---|
23 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
24 | import org.eclipse.swt.events.SelectionEvent;
|
---|
25 | import org.eclipse.swt.layout.GridLayout;
|
---|
26 | import org.eclipse.swt.widgets.TabFolder;
|
---|
27 | import org.eclipse.swt.SWT;
|
---|
28 | import org.eclipse.swt.widgets.TabItem;
|
---|
29 | import org.eclipse.swt.layout.GridData;
|
---|
30 | import org.eclipse.swt.widgets.Button;
|
---|
31 |
|
---|
32 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
33 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
|
---|
34 |
|
---|
35 | public class InsertAssertionDialog extends Dialog {
|
---|
36 |
|
---|
37 | protected Event result;
|
---|
38 | protected Shell shell;
|
---|
39 |
|
---|
40 | private TabFolder tabFolder;
|
---|
41 |
|
---|
42 | List<AbstractInsertEventComposite> insertEventComposites;
|
---|
43 | GUIModel guiModel;
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Create the dialog.
|
---|
47 | *
|
---|
48 | * @param parent
|
---|
49 | * @param style
|
---|
50 | */
|
---|
51 | public InsertAssertionDialog(Shell parent, int style, GUIModel guiModel) {
|
---|
52 | super(parent, style);
|
---|
53 | setText("SWT Dialog");
|
---|
54 | this.guiModel = guiModel;
|
---|
55 | }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Open the dialog.
|
---|
59 | *
|
---|
60 | * @return the result
|
---|
61 | */
|
---|
62 | public Event open() {
|
---|
63 | result = null;
|
---|
64 | insertEventComposites = new ArrayList<AbstractInsertEventComposite>();
|
---|
65 | createContents();
|
---|
66 | shell.open();
|
---|
67 | shell.layout();
|
---|
68 | Display display = getParent().getDisplay();
|
---|
69 | while (!shell.isDisposed()) {
|
---|
70 | if (!display.readAndDispatch()) {
|
---|
71 | display.sleep();
|
---|
72 | }
|
---|
73 | }
|
---|
74 | return result;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * Create contents of the dialog.
|
---|
79 | */
|
---|
80 | private void createContents() {
|
---|
81 | shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL);
|
---|
82 | shell.setSize(450, 300);
|
---|
83 | shell.setText(getText());
|
---|
84 | shell.setLayout(new GridLayout(2, false));
|
---|
85 |
|
---|
86 | tabFolder = new TabFolder(shell, SWT.NONE);
|
---|
87 | tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
|
---|
88 |
|
---|
89 | TabItem tbtmTextEquals = new TabItem(tabFolder, SWT.NONE);
|
---|
90 | tbtmTextEquals.setText("TextEquals");
|
---|
91 | AbstractInsertEventComposite compTextEquals =
|
---|
92 | new InsertTextEquals(tabFolder, SWT.NO_BACKGROUND, guiModel);
|
---|
93 | tbtmTextEquals.setControl(compTextEquals);
|
---|
94 | insertEventComposites.add(compTextEquals);
|
---|
95 |
|
---|
96 | TabItem tbtmFileEquals = new TabItem(tabFolder, SWT.NONE);
|
---|
97 | tbtmFileEquals.setText("FileEquals");
|
---|
98 | AbstractInsertEventComposite compFileEquals =
|
---|
99 | new InsertFileEquals(tabFolder, SWT.NO_BACKGROUND, guiModel);
|
---|
100 | tbtmFileEquals.setControl(compFileEquals);
|
---|
101 | insertEventComposites.add(compFileEquals);
|
---|
102 |
|
---|
103 | Button btnInsert = new Button(shell, SWT.NONE);
|
---|
104 | btnInsert.setText("Insert");
|
---|
105 | btnInsert.addSelectionListener(new SelectionAdapter() {
|
---|
106 | @Override
|
---|
107 | public void widgetSelected(SelectionEvent e) {
|
---|
108 | int index = tabFolder.getSelectionIndex();
|
---|
109 | result = insertEventComposites.get(index).getEvent();
|
---|
110 | shell.dispose();
|
---|
111 | }
|
---|
112 | });
|
---|
113 |
|
---|
114 | Button btnAbort = new Button(shell, SWT.NONE);
|
---|
115 | btnAbort.setText("Abort");
|
---|
116 | btnAbort.addSelectionListener(new SelectionAdapter() {
|
---|
117 | @Override
|
---|
118 | public void widgetSelected(SelectionEvent e) {
|
---|
119 | shell.dispose();
|
---|
120 | }
|
---|
121 | });
|
---|
122 | }
|
---|
123 | }
|
---|