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