source: trunk/autoquest-ui-swt/src/main/java/de/ugoe/cs/autoquest/ui/swt/InsertAssertionDialog.java @ 922

Last change on this file since 922 was 922, checked in by sherbold, 12 years ago
  • renaming of packages from de.ugoe.cs.quest to de.ugoe.cs.autoquest
  • Property svn:mime-type set to text/plain
File size: 3.5 KB
Line 
1package de.ugoe.cs.autoquest.ui.swt;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.eclipse.swt.widgets.Dialog;
7import org.eclipse.swt.widgets.Display;
8import org.eclipse.swt.widgets.Shell;
9import org.eclipse.swt.events.SelectionAdapter;
10import org.eclipse.swt.events.SelectionEvent;
11import org.eclipse.swt.layout.GridLayout;
12import org.eclipse.swt.widgets.TabFolder;
13import org.eclipse.swt.SWT;
14import org.eclipse.swt.widgets.TabItem;
15import org.eclipse.swt.layout.GridData;
16import org.eclipse.swt.widgets.Button;
17
18import de.ugoe.cs.autoquest.eventcore.Event;
19import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel;
20
21public class InsertAssertionDialog extends Dialog {
22
23    protected Event result;
24    protected Shell shell;
25
26    private TabFolder tabFolder;
27
28    List<AbstractInsertEventComposite> insertEventComposites;
29    GUIModel guiModel;
30
31    /**
32     * Create the dialog.
33     *
34     * @param parent
35     * @param style
36     */
37    public InsertAssertionDialog(Shell parent, int style, GUIModel guiModel) {
38        super(parent, style);
39        setText("SWT Dialog");
40        this.guiModel = guiModel;
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, guiModel);
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, guiModel);
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}
Note: See TracBrowser for help on using the repository browser.