|
Lines 16-27
Link Here
|
| 16 |
import org.eclipse.jface.examples.databinding.model.SampleData; |
16 |
import org.eclipse.jface.examples.databinding.model.SampleData; |
| 17 |
import org.eclipse.jface.internal.databinding.provisional.description.Property; |
17 |
import org.eclipse.jface.internal.databinding.provisional.description.Property; |
| 18 |
import org.eclipse.jface.internal.databinding.provisional.description.TableModelDescription; |
18 |
import org.eclipse.jface.internal.databinding.provisional.description.TableModelDescription; |
|
|
19 |
import org.eclipse.jface.internal.databinding.provisional.viewers.TableViewerEditorManager; |
| 19 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
20 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
|
21 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 20 |
import org.eclipse.jface.viewers.TableViewer; |
22 |
import org.eclipse.jface.viewers.TableViewer; |
|
|
23 |
import org.eclipse.jface.viewers.TextCellEditor; |
| 21 |
import org.eclipse.swt.SWT; |
24 |
import org.eclipse.swt.SWT; |
| 22 |
import org.eclipse.swt.graphics.Image; |
25 |
import org.eclipse.swt.graphics.Image; |
| 23 |
import org.eclipse.swt.layout.FillLayout; |
26 |
import org.eclipse.swt.layout.FillLayout; |
|
|
27 |
import org.eclipse.swt.widgets.Event; |
| 24 |
import org.eclipse.swt.widgets.TableColumn; |
28 |
import org.eclipse.swt.widgets.TableColumn; |
|
|
29 |
import org.eclipse.swt.widgets.Text; |
| 25 |
|
30 |
|
| 26 |
/** |
31 |
/** |
| 27 |
* To run the tests in this class, right-click and select "Run As JUnit Plug-in |
32 |
* To run the tests in this class, right-click and select "Run As JUnit Plug-in |
|
Lines 112-117
Link Here
|
| 112 |
} |
117 |
} |
| 113 |
} |
118 |
} |
| 114 |
|
119 |
|
|
|
120 |
public void testEditColumnWithTextCellEditor() throws Exception { |
| 121 |
TableModelDescription description = new TableModelDescription( |
| 122 |
new Property(catalog, "accounts", Account.class, Boolean.TRUE), |
| 123 |
new String[] { "firstName", "lastName" }); |
| 124 |
|
| 125 |
getDbc().bind(tableViewer, description, null); |
| 126 |
|
| 127 |
TableViewerEditorManager manager = new TableViewerEditorManager( |
| 128 |
tableViewer, description, getDbc()); |
| 129 |
TextCellEditor editor = new TextCellEditor(); |
| 130 |
manager.bind(editor, "firstName", String.class, null); |
| 131 |
|
| 132 |
Account account = catalog.getAccounts()[0]; |
| 133 |
String originalValue = account.getFirstName(); |
| 134 |
|
| 135 |
tableViewer.editElement(account, 0); |
| 136 |
assertEquals(account, |
| 137 |
((StructuredSelection) tableViewer.getSelection()) |
| 138 |
.getFirstElement()); |
| 139 |
|
| 140 |
String newValue = editor.getValue().toString() + "," |
| 141 |
+ editor.getValue().toString(); |
| 142 |
editor.setValue(newValue); |
| 143 |
|
| 144 |
// Value shouldn't yet change |
| 145 |
assertEquals(originalValue, account.getFirstName()); |
| 146 |
|
| 147 |
getShell().open(); |
| 148 |
|
| 149 |
// Apply value |
| 150 |
Text text = (Text) editor.getControl(); |
| 151 |
Event event = new Event(); |
| 152 |
event.detail = SWT.TRAVERSE_RETURN; |
| 153 |
text.notifyListeners(SWT.Traverse, event); |
| 154 |
tableViewer.getTable().setFocus(); |
| 155 |
|
| 156 |
assertEquals(newValue, account.getFirstName()); |
| 157 |
} |
| 158 |
|
| 159 |
public void testCancelEditOfTextCellEditor() throws Exception { |
| 160 |
TableModelDescription description = new TableModelDescription( |
| 161 |
new Property(catalog, "accounts", Account.class, Boolean.TRUE), |
| 162 |
new String[] { "firstName", "lastName" }); |
| 163 |
|
| 164 |
getDbc().bind(tableViewer, description, null); |
| 165 |
|
| 166 |
TableViewerEditorManager manager = new TableViewerEditorManager( |
| 167 |
tableViewer, description, getDbc()); |
| 168 |
TextCellEditor editor = new TextCellEditor(); |
| 169 |
manager.bind(editor, "firstName", String.class, null); |
| 170 |
|
| 171 |
Account account = catalog.getAccounts()[0]; |
| 172 |
String originalValue = account.getFirstName(); |
| 173 |
|
| 174 |
tableViewer.editElement(account, 0); |
| 175 |
assertEquals(account, |
| 176 |
((StructuredSelection) tableViewer.getSelection()) |
| 177 |
.getFirstElement()); |
| 178 |
|
| 179 |
String newValue = editor.getValue().toString() + "," |
| 180 |
+ editor.getValue().toString(); |
| 181 |
editor.setValue(newValue); |
| 182 |
|
| 183 |
// Value shouldn't yet change |
| 184 |
assertEquals(originalValue, account.getFirstName()); |
| 185 |
|
| 186 |
// Aborts the edit |
| 187 |
tableViewer.getTable().setFocus(); |
| 188 |
|
| 189 |
assertEquals(originalValue, account.getFirstName()); |
| 190 |
} |
| 191 |
|
| 115 |
public void testScenario02() throws SecurityException, IllegalArgumentException { |
192 |
public void testScenario02() throws SecurityException, IllegalArgumentException { |
| 116 |
// Show that a TableViewer with three columns can be used to update |
193 |
// Show that a TableViewer with three columns can be used to update |
| 117 |
// columns |
194 |
// columns |
|
Lines 135-141
Link Here
|
| 135 |
// // Check whether the model has changed |
212 |
// // Check whether the model has changed |
| 136 |
// assertEquals("Bill",account.getFirstName()); |
213 |
// assertEquals("Bill",account.getFirstName()); |
| 137 |
} |
214 |
} |
| 138 |
|
215 |
|
| 139 |
public void testScenario04() { |
216 |
public void testScenario04() { |
| 140 |
// // Show that when an item is added to a collection the table gets an extra item |
217 |
// // Show that when an item is added to a collection the table gets an extra item |
| 141 |
// Account[] accounts = catalog.getAccounts(); |
218 |
// Account[] accounts = catalog.getAccounts(); |
|
Lines 212-218
Link Here
|
| 212 |
// assertEquals(tableViewer.getTable().getItemCount(),numberOfAccounts); |
289 |
// assertEquals(tableViewer.getTable().getItemCount(),numberOfAccounts); |
| 213 |
// |
290 |
// |
| 214 |
} |
291 |
} |
| 215 |
|
292 |
|
| 216 |
public void testScenario03() { |
293 |
public void testScenario03() { |
| 217 |
// // Show that converters work for table columns |
294 |
// // Show that converters work for table columns |
| 218 |
// Account[] accounts = catalog.getAccounts(); |
295 |
// Account[] accounts = catalog.getAccounts(); |
|
Lines 247-253
Link Here
|
| 247 |
// .convertModelToTarget(account.getState())), col_state); |
324 |
// .convertModelToTarget(account.getState())), col_state); |
| 248 |
// } |
325 |
// } |
| 249 |
} |
326 |
} |
| 250 |
|
327 |
|
| 251 |
public void testScenario05() { |
328 |
public void testScenario05() { |
| 252 |
// // Show that when the model changes then the UI refreshes to reflect this |
329 |
// // Show that when the model changes then the UI refreshes to reflect this |
| 253 |
// |
330 |
// |
|
Lines 281-287
Link Here
|
| 281 |
// assertEquals(lastName,account.getLastName()); |
358 |
// assertEquals(lastName,account.getLastName()); |
| 282 |
// |
359 |
// |
| 283 |
} |
360 |
} |
| 284 |
|
361 |
|
| 285 |
public void testScenario06(){ |
362 |
public void testScenario06(){ |
| 286 |
// // Check that explicit type means that defaulting of converters works |
363 |
// // Check that explicit type means that defaulting of converters works |
| 287 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
364 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
|
Lines 301-307
Link Here
|
| 301 |
// assertEquals(transporation.getPrice(),123.45,0); |
378 |
// assertEquals(transporation.getPrice(),123.45,0); |
| 302 |
|
379 |
|
| 303 |
} |
380 |
} |
| 304 |
|
381 |
|
| 305 |
public void testScenario07(){ |
382 |
public void testScenario07(){ |
| 306 |
// // Verify that even when a column's property type is not set, that it is worked out lazily from the target type |
383 |
// // Verify that even when a column's property type is not set, that it is worked out lazily from the target type |
| 307 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
384 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
|
Lines 322-328
Link Here
|
| 322 |
// assertEquals(transporation.getPrice(),123.45,0); |
399 |
// assertEquals(transporation.getPrice(),123.45,0); |
| 323 |
// |
400 |
// |
| 324 |
} |
401 |
} |
| 325 |
|
402 |
|
| 326 |
public void testScenario08_00(){ |
403 |
public void testScenario08_00(){ |
| 327 |
// // Verify that binding to a Collection property (rather than an array) works when specifying data type |
404 |
// // Verify that binding to a Collection property (rather than an array) works when specifying data type |
| 328 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
405 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
|
Lines 347-353
Link Here
|
| 347 |
// assertEquals("Cricket11Players",firstSignon.getPassword()); |
424 |
// assertEquals("Cricket11Players",firstSignon.getPassword()); |
| 348 |
// |
425 |
// |
| 349 |
} |
426 |
} |
| 350 |
|
427 |
|
| 351 |
public void testScenario08_01(){ |
428 |
public void testScenario08_01(){ |
| 352 |
// // Verify that binding to a Collection property (rather than an array) works without specifying data type |
429 |
// // Verify that binding to a Collection property (rather than an array) works without specifying data type |
| 353 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
430 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
|
Lines 372-378
Link Here
|
| 372 |
// assertEquals("Cricket11Players",firstSignon.getPassword()); |
449 |
// assertEquals("Cricket11Players",firstSignon.getPassword()); |
| 373 |
// |
450 |
// |
| 374 |
} |
451 |
} |
| 375 |
|
452 |
|
| 376 |
public void testScenario09(){ |
453 |
public void testScenario09(){ |
| 377 |
// // Verify that nested properties work. Catalog has adventures. Adventure has defaultLodging. Loding has name. |
454 |
// // Verify that nested properties work. Catalog has adventures. Adventure has defaultLodging. Loding has name. |
| 378 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription(tableViewer); |
455 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription(tableViewer); |
|
Lines 381-412
Link Here
|
| 381 |
// getDbc().bind(tableViewerDescription,new Property(category, "adventures"),null); |
458 |
// getDbc().bind(tableViewerDescription,new Property(category, "adventures"),null); |
| 382 |
// |
459 |
// |
| 383 |
} |
460 |
} |
| 384 |
/** |
|
|
| 385 |
public void testScenario10(){ |
| 386 |
// Verify that for TIME_EARLY updating occurs on a per key basic for a TextCellEditor |
| 387 |
// Show that converters work for table columns |
| 388 |
Account[] accounts = catalog.getAccounts(); |
| 389 |
Account firstAccount = accounts[0]; |
| 390 |
SampleData.getSWTObservableFactory().setUpdateTime(DataBindingContext.TIME_EARLY); |
| 391 |
TableViewerDescription tableViewerDescription = new TableViewerDescription(tableViewer); |
| 392 |
tableViewerDescription.addEditableColumn("lastName"); |
| 393 |
tableViewerDescription.addColumn("lastName"); |
| 394 |
getDbc().bind(tableViewerDescription,new Property(catalog, "accounts"), null); |
| 395 |
|
| 396 |
// Verify that the first account is shown in the first row with the last name correctly |
| 397 |
assertEquals(tableViewer.getTable().getItem(0).getData(),firstAccount); |
| 398 |
assertEquals(tableViewer.getTable().getItem(0).getText(0),firstAccount.getLastName()); |
| 399 |
assertEquals(tableViewer.getTable().getItem(0).getText(1),firstAccount.getLastName()); |
| 400 |
// Create a cell editor over the first column |
| 401 |
tableViewer.editElement(firstAccount, 0); |
| 402 |
// Set the text property of the cell editor which is now active over the "firstName" column |
| 403 |
CellEditor[] cellEditors = tableViewer.getCellEditors(); |
| 404 |
TextCellEditor lastNameCellEditor = (TextCellEditor) cellEditors[0]; |
| 405 |
((Text)lastNameCellEditor.getControl()).setText("E"); |
| 406 |
// Verify that the key press goes to the model |
| 407 |
assertEquals(firstAccount.getLastName(),"E"); |
| 408 |
|
| 409 |
} |
| 410 |
**/ |
| 411 |
} |
| 412 |
|
461 |
|
|
|
462 |
/** |
| 463 |
* public void testScenario10(){ // Verify that for TIME_EARLY updating |
| 464 |
* occurs on a per key basic for a TextCellEditor // Show that converters |
| 465 |
* work for table columns Account[] accounts = catalog.getAccounts(); |
| 466 |
* Account firstAccount = accounts[0]; |
| 467 |
* SampleData.getSWTObservableFactory().setUpdateTime(DataBindingContext.TIME_EARLY); |
| 468 |
* TableViewerDescription tableViewerDescription = new |
| 469 |
* TableViewerDescription(tableViewer); |
| 470 |
* tableViewerDescription.addEditableColumn("lastName"); |
| 471 |
* tableViewerDescription.addColumn("lastName"); |
| 472 |
* getDbc().bind(tableViewerDescription,new Property(catalog, "accounts"), |
| 473 |
* null); // Verify that the first account is shown in the first row with |
| 474 |
* the last name correctly |
| 475 |
* assertEquals(tableViewer.getTable().getItem(0).getData(),firstAccount); |
| 476 |
* assertEquals(tableViewer.getTable().getItem(0).getText(0),firstAccount.getLastName()); |
| 477 |
* assertEquals(tableViewer.getTable().getItem(0).getText(1),firstAccount.getLastName()); // |
| 478 |
* Create a cell editor over the first column |
| 479 |
* tableViewer.editElement(firstAccount, 0); // Set the text property of the |
| 480 |
* cell editor which is now active over the "firstName" column CellEditor[] |
| 481 |
* cellEditors = tableViewer.getCellEditors(); TextCellEditor |
| 482 |
* lastNameCellEditor = (TextCellEditor) cellEditors[0]; |
| 483 |
* ((Text)lastNameCellEditor.getControl()).setText("E"); // Verify that the |
| 484 |
* key press goes to the model assertEquals(firstAccount.getLastName(),"E"); } |
| 485 |
*/ |
| 486 |
} |