Changeset 358 for trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt
- Timestamp:
- 01/27/12 11:00:50 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/swt/EditSequenceDialog.java
r287 r358 5 5 import org.eclipse.swt.widgets.Dialog; 6 6 import org.eclipse.swt.widgets.Display; 7 import org.eclipse.swt.widgets.Listener; 7 8 import org.eclipse.swt.widgets.MessageBox; 8 9 import org.eclipse.swt.widgets.Shell; … … 16 17 import org.eclipse.swt.events.SelectionAdapter; 17 18 import org.eclipse.swt.events.SelectionEvent; 19 import org.eclipse.swt.graphics.Point; 18 20 19 21 import de.ugoe.cs.eventbench.data.Event; … … 25 27 private TableColumn tblclmnEventType; 26 28 private TableColumn tblclmnEventTarget; 27 29 28 30 private java.util.List<Event<?>> sequence; 29 31 private SortedSet<String> targets; … … 31 33 /** 32 34 * Create the dialog. 35 * 33 36 * @param parent 34 37 * @param style … … 60 63 */ 61 64 private void createContents() { 62 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL); 65 shell = new Shell(getParent(), SWT.SHELL_TRIM | SWT.BORDER 66 | SWT.APPLICATION_MODAL); 63 67 shell.setSize(450, 300); 64 68 shell.setText(getText()); 65 69 shell.setLayout(new GridLayout(3, false)); 66 70 67 71 table = new Table(shell, SWT.BORDER | SWT.FULL_SELECTION); 68 72 table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1)); 69 73 table.setHeaderVisible(true); 70 74 table.setLinesVisible(true); 71 75 72 76 tblclmnEventType = new TableColumn(table, SWT.NONE); 73 77 tblclmnEventType.setWidth(100); 74 78 tblclmnEventType.setText("Event Type"); 75 79 76 80 tblclmnEventTarget = new TableColumn(table, SWT.NONE); 77 81 tblclmnEventTarget.setWidth(100); 78 82 tblclmnEventTarget.setText("Event Target"); 79 83 84 // this listener makes the table entries multiline 85 Listener paintListener = new Listener() { 86 public void handleEvent(org.eclipse.swt.widgets.Event event) { 87 switch (event.type) { 88 case SWT.MeasureItem: { 89 TableItem item = (TableItem) event.item; 90 String text = item.getText(event.index); 91 Point size = event.gc.textExtent(text); 92 event.width = size.x; 93 event.height = Math.max(event.height, size.y); 94 break; 95 } 96 case SWT.PaintItem: { 97 TableItem item = (TableItem) event.item; 98 String text = item.getText(event.index); 99 Point size = event.gc.textExtent(text); 100 int offset = event.index == 0 ? Math.max(0, 101 (event.height - size.y) / 2) : 0; 102 event.gc.drawText(text, event.x, event.y + offset, true); 103 break; 104 } 105 case SWT.EraseItem: { 106 event.detail &= ~SWT.FOREGROUND; 107 break; 108 } 109 } 110 } 111 112 }; 113 table.addListener(SWT.MeasureItem, paintListener); 114 table.addListener(SWT.PaintItem, paintListener); 115 table.addListener(SWT.EraseItem, paintListener); 116 80 117 updateTableContents(); 81 118 82 119 Button btnInsertBefore = new Button(shell, SWT.NONE); 83 120 btnInsertBefore.addSelectionListener(new SelectionAdapter() { … … 85 122 public void widgetSelected(SelectionEvent e) { 86 123 int index = table.getSelectionIndex(); 87 if ( index==-1) {124 if (index == -1) { 88 125 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 89 126 messageBox.setMessage("No event selected!"); … … 96 133 }); 97 134 btnInsertBefore.setText("Insert Before"); 98 135 99 136 Button btnInsertAfter = new Button(shell, SWT.NONE); 100 137 btnInsertAfter.addSelectionListener(new SelectionAdapter() { … … 102 139 public void widgetSelected(SelectionEvent e) { 103 140 int index = table.getSelectionIndex(); 104 if ( index==-1) {141 if (index == -1) { 105 142 MessageBox messageBox = new MessageBox(shell, SWT.ERROR); 106 143 messageBox.setMessage("No event selected!"); … … 108 145 messageBox.open(); 109 146 } else { 110 openInsertDialog(index +1);147 openInsertDialog(index + 1); 111 148 } 112 149 } 113 150 }); 114 151 btnInsertAfter.setText("Insert After"); 115 152 116 153 Button btnClose = new Button(shell, SWT.NONE); 117 154 btnClose.addSelectionListener(new SelectionAdapter() { … … 124 161 125 162 } 126 163 127 164 private void updateTableContents() { 128 165 table.removeAll(); 129 for ( Event<?> event : sequence) {166 for (Event<?> event : sequence) { 130 167 TableItem tableItem = new TableItem(table, SWT.NONE); 131 tableItem.setText(new String[]{event.getType(),event.getTarget()}); 168 String target = event.getTarget(); 169 if (target != null) { 170 // the target is split into multiple lines, as one line may 171 // only be 259 characters in tables with Windows 172 target = target.replace("].", "].\n"); 173 } 174 tableItem.setText(new String[] { event.getType(), target }); 175 } 176 for (int i = 0; i < table.getColumnCount(); i++) { 177 table.getColumn(i).pack(); 132 178 } 133 179 } 134 180 135 181 private void openInsertDialog(int position) { 136 InsertAssertionDialog insertDialog = new InsertAssertionDialog(shell, SWT.NONE, targets); 182 InsertAssertionDialog insertDialog = new InsertAssertionDialog(shell, 183 SWT.NONE, targets); 137 184 Event<?> event = insertDialog.open(); 138 if ( event!=null) {185 if (event != null) { 139 186 sequence.add(position, event); 140 187 updateTableContents();
Note: See TracChangeset
for help on using the changeset viewer.