1 | package de.ugoe.cs.eventbench.swt;
|
---|
2 |
|
---|
3 | import java.util.SortedSet;
|
---|
4 |
|
---|
5 | import org.eclipse.swt.widgets.Dialog;
|
---|
6 | import org.eclipse.swt.widgets.Display;
|
---|
7 | import org.eclipse.swt.widgets.MessageBox;
|
---|
8 | import org.eclipse.swt.widgets.Shell;
|
---|
9 | import org.eclipse.swt.widgets.TableItem;
|
---|
10 | import org.eclipse.swt.layout.GridLayout;
|
---|
11 | import org.eclipse.swt.SWT;
|
---|
12 | import org.eclipse.swt.widgets.Button;
|
---|
13 | import org.eclipse.swt.layout.GridData;
|
---|
14 | import org.eclipse.swt.widgets.Table;
|
---|
15 | import org.eclipse.swt.widgets.TableColumn;
|
---|
16 | import org.eclipse.swt.events.SelectionAdapter;
|
---|
17 | import org.eclipse.swt.events.SelectionEvent;
|
---|
18 |
|
---|
19 | import de.ugoe.cs.eventbench.data.Event;
|
---|
20 |
|
---|
21 | public class EditSequenceDialog extends Dialog {
|
---|
22 |
|
---|
23 | protected Shell shell;
|
---|
24 | private Table table;
|
---|
25 | private TableColumn tblclmnEventType;
|
---|
26 | private TableColumn tblclmnEventTarget;
|
---|
27 |
|
---|
28 | private java.util.List<Event<?>> sequence;
|
---|
29 | private SortedSet<String> targets;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Create the dialog.
|
---|
33 | * @param parent
|
---|
34 | * @param style
|
---|
35 | */
|
---|
36 | public EditSequenceDialog(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 | */
|
---|
45 | public void open(java.util.List<Event<?>> sequence) {
|
---|
46 | this.sequence = sequence;
|
---|
47 | createContents();
|
---|
48 | shell.open();
|
---|
49 | shell.layout();
|
---|
50 | Display display = getParent().getDisplay();
|
---|
51 | while (!shell.isDisposed()) {
|
---|
52 | if (!display.readAndDispatch()) {
|
---|
53 | display.sleep();
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Create contents of the dialog.
|
---|
60 | */
|
---|
61 | private void createContents() {
|
---|
62 | shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL);
|
---|
63 | shell.setSize(450, 300);
|
---|
64 | shell.setText(getText());
|
---|
65 | shell.setLayout(new GridLayout(3, false));
|
---|
66 |
|
---|
67 | table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION);
|
---|
68 | table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
|
---|
69 | table.setHeaderVisible(true);
|
---|
70 | table.setLinesVisible(true);
|
---|
71 |
|
---|
72 | tblclmnEventType = new TableColumn(table, SWT.NONE);
|
---|
73 | tblclmnEventType.setWidth(100);
|
---|
74 | tblclmnEventType.setText("Event Type");
|
---|
75 |
|
---|
76 | tblclmnEventTarget = new TableColumn(table, SWT.NONE);
|
---|
77 | tblclmnEventTarget.setWidth(100);
|
---|
78 | tblclmnEventTarget.setText("Event Target");
|
---|
79 |
|
---|
80 | updateTableContents();
|
---|
81 |
|
---|
82 | Button btnInsertBefore = new Button(shell, SWT.NONE);
|
---|
83 | btnInsertBefore.addSelectionListener(new SelectionAdapter() {
|
---|
84 | @Override
|
---|
85 | public void widgetSelected(SelectionEvent e) {
|
---|
86 | int index = table.getSelectionIndex();
|
---|
87 | if( index==-1 ) {
|
---|
88 | MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
|
---|
89 | messageBox.setMessage("No event selected!");
|
---|
90 | messageBox.setText("Error");
|
---|
91 | messageBox.open();
|
---|
92 | } else {
|
---|
93 | openInsertDialog(index);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | });
|
---|
97 | btnInsertBefore.setText("Insert Before");
|
---|
98 |
|
---|
99 | Button btnInsertAfter = new Button(shell, SWT.NONE);
|
---|
100 | btnInsertAfter.addSelectionListener(new SelectionAdapter() {
|
---|
101 | @Override
|
---|
102 | public void widgetSelected(SelectionEvent e) {
|
---|
103 | int index = table.getSelectionIndex();
|
---|
104 | if( index==-1 ) {
|
---|
105 | MessageBox messageBox = new MessageBox(shell, SWT.ERROR);
|
---|
106 | messageBox.setMessage("No event selected!");
|
---|
107 | messageBox.setText("Error");
|
---|
108 | messageBox.open();
|
---|
109 | } else {
|
---|
110 | openInsertDialog(index+1);
|
---|
111 | }
|
---|
112 | }
|
---|
113 | });
|
---|
114 | btnInsertAfter.setText("Insert After");
|
---|
115 |
|
---|
116 | Button btnClose = new Button(shell, SWT.NONE);
|
---|
117 | btnClose.addSelectionListener(new SelectionAdapter() {
|
---|
118 | @Override
|
---|
119 | public void widgetSelected(SelectionEvent e) {
|
---|
120 | shell.dispose();
|
---|
121 | }
|
---|
122 | });
|
---|
123 | btnClose.setText("Close");
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|
127 | private void updateTableContents() {
|
---|
128 | table.removeAll();
|
---|
129 | for( Event<?> event : sequence ) {
|
---|
130 | TableItem tableItem = new TableItem(table, SWT.NONE);
|
---|
131 | tableItem.setText(new String[]{event.getType(),event.getTarget()});
|
---|
132 | }
|
---|
133 | }
|
---|
134 |
|
---|
135 | private void openInsertDialog(int position) {
|
---|
136 | InsertAssertionDialog insertDialog = new InsertAssertionDialog(shell, SWT.NONE, targets);
|
---|
137 | Event<?> event = insertDialog.open();
|
---|
138 | if( event!=null ) {
|
---|
139 | sequence.add(position, event);
|
---|
140 | updateTableContents();
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | }
|
---|