Lines 10-27
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jface.tests.databinding.scenarios; |
11 |
package org.eclipse.jface.tests.databinding.scenarios; |
12 |
|
12 |
|
|
|
13 |
import java.util.ArrayList; |
14 |
import java.util.List; |
15 |
|
13 |
import org.eclipse.jface.examples.databinding.model.Account; |
16 |
import org.eclipse.jface.examples.databinding.model.Account; |
14 |
import org.eclipse.jface.examples.databinding.model.Catalog; |
17 |
import org.eclipse.jface.examples.databinding.model.Catalog; |
15 |
import org.eclipse.jface.examples.databinding.model.Category; |
18 |
import org.eclipse.jface.examples.databinding.model.Category; |
16 |
import org.eclipse.jface.examples.databinding.model.SampleData; |
19 |
import org.eclipse.jface.examples.databinding.model.SampleData; |
17 |
import org.eclipse.jface.internal.databinding.provisional.description.Property; |
20 |
import org.eclipse.jface.internal.databinding.provisional.description.Property; |
18 |
import org.eclipse.jface.internal.databinding.provisional.description.TableModelDescription; |
21 |
import org.eclipse.jface.internal.databinding.provisional.description.TableModelDescription; |
|
|
22 |
import org.eclipse.jface.internal.databinding.provisional.observable.list.AbstractObservableList; |
23 |
import org.eclipse.jface.internal.databinding.provisional.viewers.TableViewerEditorManager; |
19 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
24 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
|
|
25 |
import org.eclipse.jface.viewers.StructuredSelection; |
20 |
import org.eclipse.jface.viewers.TableViewer; |
26 |
import org.eclipse.jface.viewers.TableViewer; |
|
|
27 |
import org.eclipse.jface.viewers.TextCellEditor; |
21 |
import org.eclipse.swt.SWT; |
28 |
import org.eclipse.swt.SWT; |
22 |
import org.eclipse.swt.graphics.Image; |
29 |
import org.eclipse.swt.graphics.Image; |
23 |
import org.eclipse.swt.layout.FillLayout; |
30 |
import org.eclipse.swt.layout.FillLayout; |
|
|
31 |
import org.eclipse.swt.widgets.Event; |
24 |
import org.eclipse.swt.widgets.TableColumn; |
32 |
import org.eclipse.swt.widgets.TableColumn; |
|
|
33 |
import org.eclipse.swt.widgets.Text; |
25 |
|
34 |
|
26 |
/** |
35 |
/** |
27 |
* To run the tests in this class, right-click and select "Run As JUnit Plug-in |
36 |
* To run the tests in this class, right-click and select "Run As JUnit Plug-in |
Lines 35-41
Link Here
|
35 |
private TableViewer tableViewer; |
44 |
private TableViewer tableViewer; |
36 |
|
45 |
|
37 |
private Catalog catalog; |
46 |
private Catalog catalog; |
38 |
|
47 |
|
39 |
private Category category; |
48 |
private Category category; |
40 |
|
49 |
|
41 |
private TableColumn firstNameColumn; |
50 |
private TableColumn firstNameColumn; |
Lines 57-70
Link Here
|
57 |
firstNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); |
66 |
firstNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); |
58 |
firstNameColumn.setWidth(50); |
67 |
firstNameColumn.setWidth(50); |
59 |
lastNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); |
68 |
lastNameColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); |
60 |
lastNameColumn.setWidth(50); |
69 |
lastNameColumn.setWidth(50); |
61 |
stateColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); |
70 |
stateColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); |
62 |
stateColumn.setWidth(50); |
71 |
stateColumn.setWidth(50); |
63 |
fancyColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); |
72 |
fancyColumn = new TableColumn(tableViewer.getTable(), SWT.NONE); |
64 |
fancyColumn.setWidth(250); |
73 |
fancyColumn.setWidth(250); |
65 |
|
74 |
|
66 |
catalog = SampleData.CATALOG_2005; // Lodging source |
75 |
catalog = SampleData.CATALOG_2005; // Lodging source |
67 |
category = SampleData.WINTER_CATEGORY; |
76 |
category = SampleData.WINTER_CATEGORY; |
68 |
|
77 |
|
69 |
images = new Image[] { |
78 |
images = new Image[] { |
70 |
getShell().getDisplay().getSystemImage(SWT.ICON_ERROR), |
79 |
getShell().getDisplay().getSystemImage(SWT.ICON_ERROR), |
Lines 83-106
Link Here
|
83 |
} |
92 |
} |
84 |
|
93 |
|
85 |
private String getValue(String text) { |
94 |
private String getValue(String text) { |
86 |
if (text==null) |
95 |
if (text == null) |
87 |
return ""; |
96 |
return ""; |
88 |
return text; |
97 |
return text; |
89 |
} |
98 |
} |
90 |
|
99 |
|
91 |
public void testScenario01() { |
100 |
public void testScenario01() { |
92 |
// Show that a TableViewer with three columns renders the accounts |
101 |
// Show that a TableViewer with three columns renders the accounts |
93 |
Account[] accounts = catalog.getAccounts(); |
102 |
Account[] accounts = catalog.getAccounts(); |
94 |
|
103 |
|
95 |
TableModelDescription tableModelDescription = new TableModelDescription(new Property(catalog, "accounts"),new String[]{"firstName","lastName","state"}); |
104 |
TableModelDescription tableModelDescription = new TableModelDescription( |
96 |
getDbc().bind(tableViewer, |
105 |
new Property(catalog, "accounts"), new String[] { "firstName", |
97 |
tableModelDescription, null); |
106 |
"lastName", "state" }); |
|
|
107 |
getDbc().bind(tableViewer, tableModelDescription, null); |
98 |
|
108 |
|
99 |
// Verify the data in the table columns matches the accounts |
109 |
// Verify the data in the table columns matches the accounts |
100 |
for (int i = 0; i < accounts.length; i++) { |
110 |
for (int i = 0; i < accounts.length; i++) { |
101 |
Account account = catalog.getAccounts()[i]; |
111 |
Account account = catalog.getAccounts()[i]; |
102 |
String col_0 = ((ITableLabelProvider) tableViewer |
112 |
String col_0 = ((ITableLabelProvider) tableViewer |
103 |
.getLabelProvider()).getColumnText(account, 0); |
113 |
.getLabelProvider()).getColumnText(account, 0); |
104 |
assertEquals(getValue(account.getFirstName()), col_0); |
114 |
assertEquals(getValue(account.getFirstName()), col_0); |
105 |
String col_1 = ((ITableLabelProvider) tableViewer |
115 |
String col_1 = ((ITableLabelProvider) tableViewer |
106 |
.getLabelProvider()).getColumnText(account, 1); |
116 |
.getLabelProvider()).getColumnText(account, 1); |
Lines 112-412
Link Here
|
112 |
} |
122 |
} |
113 |
} |
123 |
} |
114 |
|
124 |
|
115 |
public void testScenario02() throws SecurityException, IllegalArgumentException { |
125 |
public void testEditColumnWithTextCellEditor() throws Exception { |
|
|
126 |
TableModelDescription description = new TableModelDescription( |
127 |
new Property(catalog, "accounts", Account.class, Boolean.TRUE), |
128 |
new String[] { "firstName", "lastName" }); |
129 |
|
130 |
getDbc().bind(tableViewer, description, null); |
131 |
|
132 |
TableViewerEditorManager manager = new TableViewerEditorManager( |
133 |
tableViewer, description, getDbc()); |
134 |
TextCellEditor editor = new TextCellEditor(); |
135 |
manager.bind(editor, "firstName", String.class, null); |
136 |
|
137 |
Account account = catalog.getAccounts()[0]; |
138 |
String originalValue = account.getFirstName(); |
139 |
|
140 |
tableViewer.editElement(account, 0); |
141 |
assertEquals(account, |
142 |
((StructuredSelection) tableViewer.getSelection()) |
143 |
.getFirstElement()); |
144 |
|
145 |
String newValue = editor.getValue().toString() + "," |
146 |
+ editor.getValue().toString(); |
147 |
editor.setValue(newValue); |
148 |
|
149 |
// Value shouldn't yet change |
150 |
assertEquals(originalValue, account.getFirstName()); |
151 |
|
152 |
getShell().open(); |
153 |
|
154 |
// Apply value |
155 |
Text text = (Text) editor.getControl(); |
156 |
Event event = new Event(); |
157 |
event.detail = SWT.TRAVERSE_RETURN; |
158 |
text.notifyListeners(SWT.Traverse, event); |
159 |
tableViewer.getTable().setFocus(); |
160 |
|
161 |
assertEquals(newValue, account.getFirstName()); |
162 |
} |
163 |
|
164 |
public void testCancelEditOfTextCellEditor() throws Exception { |
165 |
TableModelDescription description = new TableModelDescription( |
166 |
new Property(catalog, "accounts", Account.class, Boolean.TRUE), |
167 |
new String[] { "firstName", "lastName" }); |
168 |
|
169 |
getDbc().bind(tableViewer, description, null); |
170 |
|
171 |
TableViewerEditorManager manager = new TableViewerEditorManager( |
172 |
tableViewer, description, getDbc()); |
173 |
TextCellEditor editor = new TextCellEditor(); |
174 |
manager.bind(editor, "firstName", String.class, null); |
175 |
|
176 |
Account account = catalog.getAccounts()[0]; |
177 |
String originalValue = account.getFirstName(); |
178 |
|
179 |
tableViewer.editElement(account, 0); |
180 |
assertEquals(account, |
181 |
((StructuredSelection) tableViewer.getSelection()) |
182 |
.getFirstElement()); |
183 |
|
184 |
String newValue = editor.getValue().toString() + "," |
185 |
+ editor.getValue().toString(); |
186 |
editor.setValue(newValue); |
187 |
|
188 |
// Value shouldn't yet change |
189 |
assertEquals(originalValue, account.getFirstName()); |
190 |
|
191 |
// Aborts the edit |
192 |
tableViewer.getTable().setFocus(); |
193 |
|
194 |
assertEquals(originalValue, account.getFirstName()); |
195 |
} |
196 |
|
197 |
private class ObservableList extends AbstractObservableList { |
198 |
private List list; |
199 |
|
200 |
private Object elementType; |
201 |
|
202 |
private ObservableList(Object elementType) { |
203 |
list = new ArrayList(); |
204 |
this.elementType = elementType; |
205 |
} |
206 |
|
207 |
/* |
208 |
* (non-Javadoc) |
209 |
* |
210 |
* @see org.eclipse.jface.internal.databinding.provisional.observable.list.AbstractObservableList#add(java.lang.Object) |
211 |
*/ |
212 |
public boolean add(Object o) { |
213 |
return list.add(o); |
214 |
} |
215 |
|
216 |
/* |
217 |
* (non-Javadoc) |
218 |
* |
219 |
* @see org.eclipse.jface.internal.databinding.provisional.observable.list.AbstractObservableList#doGetSize() |
220 |
*/ |
221 |
protected int doGetSize() { |
222 |
return list.size(); |
223 |
} |
224 |
|
225 |
/* |
226 |
* (non-Javadoc) |
227 |
* |
228 |
* @see java.util.AbstractList#get(int) |
229 |
*/ |
230 |
public Object get(int index) { |
231 |
return list.get(index); |
232 |
} |
233 |
|
234 |
/* |
235 |
* (non-Javadoc) |
236 |
* |
237 |
* @see org.eclipse.jface.internal.databinding.provisional.observable.list.IObservableList#getElementType() |
238 |
*/ |
239 |
public Object getElementType() { |
240 |
return elementType; |
241 |
} |
242 |
} |
243 |
|
244 |
public void testScenario02() throws SecurityException, |
245 |
IllegalArgumentException { |
116 |
// Show that a TableViewer with three columns can be used to update |
246 |
// Show that a TableViewer with three columns can be used to update |
117 |
// columns |
247 |
// columns |
118 |
// Account[] accounts = catalog.getAccounts(); |
248 |
// Account[] accounts = catalog.getAccounts(); |
119 |
// |
249 |
// |
120 |
// TableModelDescription tableModelDescription = new TableModelDescription(new Property(catalog, "accounts"), new String[]{"firstName","lastName","state"}); |
250 |
// TableModelDescription tableModelDescription = new |
121 |
//// tableViewerDescription.addEditableColumn("firstName"); |
251 |
// TableModelDescription(new |
122 |
//// tableViewerDescription.addEditableColumn("lastName", null, null, new PhoneConverter()); |
252 |
// Property(catalog, "accounts"), new |
123 |
//// tableViewerDescription.addEditableColumn("state", null, null, new StateConverter()); |
253 |
// String[]{"firstName","lastName","state"}); |
124 |
// getDbc().bind(tableViewer, |
254 |
// // tableViewerDescription.addEditableColumn("firstName"); |
125 |
// tableModelDescription, null); |
255 |
// // tableViewerDescription.addEditableColumn("lastName", null, null, |
126 |
// |
256 |
// new |
127 |
// Account account = accounts[0]; |
257 |
// PhoneConverter()); |
128 |
// // Select the first item in the table |
258 |
// // tableViewerDescription.addEditableColumn("state", null, null, new |
129 |
// tableViewer.editElement(account, 0); |
259 |
// StateConverter()); |
130 |
// // Set the text property of the cell editor which is now active over the "firstName" column |
260 |
// getDbc().bind(tableViewer, |
131 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
261 |
// tableModelDescription, null); |
132 |
// TextCellEditor firstNameEditor = (TextCellEditor) cellEditors[0]; |
262 |
// |
133 |
// // Change the firstName and test it goes to the model |
263 |
// Account account = accounts[0]; |
134 |
// enterText((Text) firstNameEditor.getControl(), "Bill"); |
264 |
// // Select the first item in the table |
135 |
// // Check whether the model has changed |
265 |
// tableViewer.editElement(account, 0); |
136 |
// assertEquals("Bill",account.getFirstName()); |
266 |
// // Set the text property of the cell editor which is now active over |
|
|
267 |
// the |
268 |
// "firstName" column |
269 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
270 |
// TextCellEditor firstNameEditor = (TextCellEditor) cellEditors[0]; |
271 |
// // Change the firstName and test it goes to the model |
272 |
// enterText((Text) firstNameEditor.getControl(), "Bill"); |
273 |
// // Check whether the model has changed |
274 |
// assertEquals("Bill",account.getFirstName()); |
137 |
} |
275 |
} |
138 |
|
276 |
|
139 |
public void testScenario04() { |
277 |
public void testScenario04() { |
140 |
// // Show that when an item is added to a collection the table gets an extra item |
278 |
// // Show that when an item is added to a collection the table gets an |
141 |
// Account[] accounts = catalog.getAccounts(); |
279 |
// extra |
142 |
// |
280 |
// item |
143 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
281 |
// Account[] accounts = catalog.getAccounts(); |
144 |
// tableViewer); |
282 |
// |
145 |
// tableViewerDescription.addColumn("firstName"); |
283 |
// TableViewerDescription tableViewerDescription = new |
146 |
// tableViewerDescription.addColumn("lastName"); |
284 |
// TableViewerDescription( |
147 |
// tableViewerDescription.addColumn("state"); |
285 |
// tableViewer); |
148 |
// tableViewerDescription.addColumn(null,new IConverter(){ |
286 |
// tableViewerDescription.addColumn("firstName"); |
149 |
// |
287 |
// tableViewerDescription.addColumn("lastName"); |
150 |
// public Class getModelType() { |
288 |
// tableViewerDescription.addColumn("state"); |
151 |
// return Account.class; |
289 |
// tableViewerDescription.addColumn(null,new IConverter(){ |
152 |
// } |
290 |
// |
153 |
// |
291 |
// public Class getModelType() { |
154 |
// public Class getTargetType() { |
292 |
// return Account.class; |
155 |
// return ViewerLabel.class; |
293 |
// } |
156 |
// } |
294 |
// |
157 |
// |
295 |
// public Class getTargetType() { |
158 |
// public Object convertTargetToModel(Object targetObject) { |
296 |
// return ViewerLabel.class; |
159 |
// return null; |
297 |
// } |
160 |
// } |
298 |
// |
161 |
// |
299 |
// public Object convertTargetToModel(Object targetObject) { |
162 |
// public Object convertModelToTarget(Object modelObject) { |
300 |
// return null; |
163 |
// Account account = (Account) modelObject; |
301 |
// } |
164 |
// return new ViewerLabel(account.toString(), images[new Random().nextInt(images.length)]); |
302 |
// |
165 |
// }}); |
303 |
// public Object convertModelToTarget(Object modelObject) { |
166 |
// getDbc().bind(tableViewerDescription, |
304 |
// Account account = (Account) modelObject; |
167 |
// new Property(catalog, "accounts"), null); |
305 |
// return new ViewerLabel(account.toString(), images[new |
168 |
// |
306 |
// Random().nextInt(images.length)]); |
169 |
// //interact(); |
307 |
// }}); |
170 |
// |
308 |
// getDbc().bind(tableViewerDescription, |
171 |
// // Verify the number of accounts matches the number of items in the table |
309 |
// new Property(catalog, "accounts"), null); |
172 |
// assertEquals(tableViewer.getTable().getItemCount(),accounts.length); |
310 |
// |
173 |
// // Add a new account and verify that the number of items in the table increases |
311 |
// //interact(); |
174 |
// Account newAccount = new Account(); |
312 |
// |
175 |
// newAccount.setFirstName("Finbar"); |
313 |
// // Verify the number of accounts matches the number of items in the |
176 |
// newAccount.setLastName("McGoo"); |
314 |
// table |
177 |
// newAccount.setLastName("NC"); |
315 |
// assertEquals(tableViewer.getTable().getItemCount(),accounts.length); |
178 |
// catalog.addAccount(newAccount); |
316 |
// // Add a new account and verify that the number of items in the table |
179 |
// // The number of items should have gone up by one |
317 |
// increases |
180 |
// assertEquals(tableViewer.getTable().getItemCount(),accounts.length + 1); |
318 |
// Account newAccount = new Account(); |
181 |
// // The number of items should still match the number of accounts (i.e. test the model) |
319 |
// newAccount.setFirstName("Finbar"); |
182 |
// assertEquals(tableViewer.getTable().getItemCount(),catalog.getAccounts().length); |
320 |
// newAccount.setLastName("McGoo"); |
183 |
// // Remove the account that was just added |
321 |
// newAccount.setLastName("NC"); |
184 |
// catalog.removeAccount(newAccount); |
322 |
// catalog.addAccount(newAccount); |
185 |
// // The number of items should match the original |
323 |
// // The number of items should have gone up by one |
186 |
// assertEquals(tableViewer.getTable().getItemCount(),accounts.length); |
324 |
// assertEquals(tableViewer.getTable().getItemCount(),accounts.length + |
187 |
// // The number of items should still match the number of accounts (i.e. test the model is reset) |
325 |
// 1); |
188 |
// assertEquals(tableViewer.getTable().getItemCount(),catalog.getAccounts().length); |
326 |
// // The number of items should still match the number of accounts |
189 |
// |
327 |
// (i.e. test |
190 |
// // Test adding and removing to the model on a non UI thread |
328 |
// the model) |
191 |
// int numberOfAccounts = catalog.getAccounts().length; |
329 |
// assertEquals(tableViewer.getTable().getItemCount(),catalog.getAccounts().length); |
192 |
// final Account barney = new Account(); |
330 |
// // Remove the account that was just added |
193 |
// barney.setFirstName("Barney"); |
331 |
// catalog.removeAccount(newAccount); |
194 |
// barney.setLastName("Smith"); |
332 |
// // The number of items should match the original |
195 |
// barney.setLastName("CA"); |
333 |
// assertEquals(tableViewer.getTable().getItemCount(),accounts.length); |
196 |
// invokeNonUI(new Runnable(){ |
334 |
// // The number of items should still match the number of accounts |
197 |
// public void run(){ |
335 |
// (i.e. test |
198 |
// catalog.addAccount(barney); |
336 |
// the model is reset) |
199 |
// } |
337 |
// assertEquals(tableViewer.getTable().getItemCount(),catalog.getAccounts().length); |
200 |
// }); |
338 |
// |
201 |
// spinEventLoop(0); |
339 |
// // Test adding and removing to the model on a non UI thread |
202 |
// // The number of items should have gone up by one |
340 |
// int numberOfAccounts = catalog.getAccounts().length; |
203 |
// assertEquals(tableViewer.getTable().getItemCount(),numberOfAccounts + 1); |
341 |
// final Account barney = new Account(); |
204 |
// |
342 |
// barney.setFirstName("Barney"); |
205 |
// invokeNonUI(new Runnable(){ |
343 |
// barney.setLastName("Smith"); |
206 |
// public void run(){ |
344 |
// barney.setLastName("CA"); |
207 |
// catalog.removeAccount(barney); |
345 |
// invokeNonUI(new Runnable(){ |
208 |
// } |
346 |
// public void run(){ |
209 |
// }); |
347 |
// catalog.addAccount(barney); |
210 |
// spinEventLoop(0); |
348 |
// } |
211 |
// // The number of items should have reverted to the original number before barney was added and removed |
349 |
// }); |
212 |
// assertEquals(tableViewer.getTable().getItemCount(),numberOfAccounts); |
350 |
// spinEventLoop(0); |
213 |
// |
351 |
// // The number of items should have gone up by one |
|
|
352 |
// assertEquals(tableViewer.getTable().getItemCount(),numberOfAccounts + |
353 |
// 1); |
354 |
// |
355 |
// invokeNonUI(new Runnable(){ |
356 |
// public void run(){ |
357 |
// catalog.removeAccount(barney); |
358 |
// } |
359 |
// }); |
360 |
// spinEventLoop(0); |
361 |
// // The number of items should have reverted to the original number |
362 |
// before |
363 |
// barney was added and removed |
364 |
// assertEquals(tableViewer.getTable().getItemCount(),numberOfAccounts); |
365 |
// |
214 |
} |
366 |
} |
215 |
|
367 |
|
216 |
public void testScenario03() { |
368 |
public void testScenario03() { |
217 |
// // Show that converters work for table columns |
369 |
// // Show that converters work for table columns |
218 |
// Account[] accounts = catalog.getAccounts(); |
370 |
// Account[] accounts = catalog.getAccounts(); |
219 |
// |
371 |
// |
220 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
372 |
// TableViewerDescription tableViewerDescription = new |
221 |
// tableViewer); |
373 |
// TableViewerDescription( |
222 |
// tableViewerDescription.addEditableColumn("lastName"); |
374 |
// tableViewer); |
223 |
// tableViewerDescription.addEditableColumn("phone", null, null , |
375 |
// tableViewerDescription.addEditableColumn("lastName"); |
224 |
// new PhoneConverter()); |
376 |
// tableViewerDescription.addEditableColumn("phone", null, null , |
225 |
// tableViewerDescription.addEditableColumn("state", null, null , |
377 |
// new PhoneConverter()); |
226 |
// new StateConverter()); |
378 |
// tableViewerDescription.addEditableColumn("state", null, null , |
227 |
// getDbc().bind(tableViewerDescription, |
379 |
// new StateConverter()); |
228 |
// new Property(catalog, "accounts"), null); |
380 |
// getDbc().bind(tableViewerDescription, |
229 |
// |
381 |
// new Property(catalog, "accounts"), null); |
230 |
// // Verify that the data in the the table columns matches the expected |
382 |
// |
231 |
// // What we are looking for is that the phone numbers are converterted to |
383 |
// // Verify that the data in the the table columns matches the expected |
232 |
// // nnn-nnn-nnnn and that |
384 |
// // What we are looking for is that the phone numbers are converterted |
233 |
// // the state letters are converted to state names |
385 |
// to |
234 |
// // Verify the data in the table columns matches the accounts |
386 |
// // nnn-nnn-nnnn and that |
235 |
// PhoneConverter phoneConverter = new PhoneConverter(); |
387 |
// // the state letters are converted to state names |
236 |
// StateConverter stateConverter = new StateConverter(); |
388 |
// // Verify the data in the table columns matches the accounts |
237 |
// for (int i = 0; i < accounts.length; i++) { |
389 |
// PhoneConverter phoneConverter = new PhoneConverter(); |
238 |
// Account account = catalog.getAccounts()[i]; |
390 |
// StateConverter stateConverter = new StateConverter(); |
239 |
// // Check the phone number |
391 |
// for (int i = 0; i < accounts.length; i++) { |
240 |
// String col_phone = ((ITableLabelProvider) tableViewer |
392 |
// Account account = catalog.getAccounts()[i]; |
241 |
// .getLabelProvider()).getColumnText(account, 1); |
393 |
// // Check the phone number |
242 |
// assertEquals(getValue((String)phoneConverter |
394 |
// String col_phone = ((ITableLabelProvider) tableViewer |
243 |
// .convertModelToTarget(account.getPhone())), col_phone); |
395 |
// .getLabelProvider()).getColumnText(account, 1); |
244 |
// String col_state = ((ITableLabelProvider) tableViewer |
396 |
// assertEquals(getValue((String)phoneConverter |
245 |
// .getLabelProvider()).getColumnText(account, 2); |
397 |
// .convertModelToTarget(account.getPhone())), col_phone); |
246 |
// assertEquals(getValue((String)stateConverter |
398 |
// String col_state = ((ITableLabelProvider) tableViewer |
247 |
// .convertModelToTarget(account.getState())), col_state); |
399 |
// .getLabelProvider()).getColumnText(account, 2); |
248 |
// } |
400 |
// assertEquals(getValue((String)stateConverter |
|
|
401 |
// .convertModelToTarget(account.getState())), col_state); |
402 |
// } |
249 |
} |
403 |
} |
250 |
|
404 |
|
251 |
public void testScenario05() { |
405 |
public void testScenario05() { |
252 |
// // Show that when the model changes then the UI refreshes to reflect this |
406 |
// // Show that when the model changes then the UI refreshes to reflect |
253 |
// |
407 |
// this |
254 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
408 |
// |
255 |
// tableViewer); |
409 |
// TableViewerDescription tableViewerDescription = new |
256 |
// tableViewerDescription.addColumn("lastName"); |
410 |
// TableViewerDescription( |
257 |
// tableViewerDescription.addColumn("phone", |
411 |
// tableViewer); |
258 |
// new PhoneConverter()); |
412 |
// tableViewerDescription.addColumn("lastName"); |
259 |
// tableViewerDescription.addColumn("state", |
413 |
// tableViewerDescription.addColumn("phone", |
260 |
// new StateConverter()); |
414 |
// new PhoneConverter()); |
261 |
// getDbc().bind(tableViewerDescription, |
415 |
// tableViewerDescription.addColumn("state", |
262 |
// new Property(catalog, "accounts"), null); |
416 |
// new StateConverter()); |
263 |
// |
417 |
// getDbc().bind(tableViewerDescription, |
264 |
// final Account account = catalog.getAccounts()[0]; |
418 |
// new Property(catalog, "accounts"), null); |
265 |
// String lastName = tableViewer.getTable().getItem(0).getText(0); |
419 |
// |
266 |
// // Check the firstName in the TableItem is the same as the model |
420 |
// final Account account = catalog.getAccounts()[0]; |
267 |
// assertEquals(lastName,account.getLastName()); |
421 |
// String lastName = tableViewer.getTable().getItem(0).getText(0); |
268 |
// // Now change the model and check again |
422 |
// // Check the firstName in the TableItem is the same as the model |
269 |
// account.setLastName("Gershwin"); |
423 |
// assertEquals(lastName,account.getLastName()); |
270 |
// lastName = tableViewer.getTable().getItem(0).getText(0); |
424 |
// // Now change the model and check again |
271 |
// assertEquals(lastName,account.getLastName()); |
425 |
// account.setLastName("Gershwin"); |
272 |
// |
426 |
// lastName = tableViewer.getTable().getItem(0).getText(0); |
273 |
// // Test the model update on a non UI thread |
427 |
// assertEquals(lastName,account.getLastName()); |
274 |
// invokeNonUI(new Runnable(){ |
428 |
// |
275 |
// public void run(){ |
429 |
// // Test the model update on a non UI thread |
276 |
// account.setLastName("Mozart"); |
430 |
// invokeNonUI(new Runnable(){ |
277 |
// } |
431 |
// public void run(){ |
278 |
// }); |
432 |
// account.setLastName("Mozart"); |
279 |
// spinEventLoop(0); |
433 |
// } |
280 |
// lastName = tableViewer.getTable().getItem(0).getText(0); |
434 |
// }); |
281 |
// assertEquals(lastName,account.getLastName()); |
435 |
// spinEventLoop(0); |
282 |
// |
436 |
// lastName = tableViewer.getTable().getItem(0).getText(0); |
283 |
} |
437 |
// assertEquals(lastName,account.getLastName()); |
284 |
|
438 |
// |
285 |
public void testScenario06(){ |
439 |
} |
286 |
// // Check that explicit type means that defaulting of converters works |
440 |
|
287 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
441 |
public void testScenario06() { |
288 |
// tableViewer); |
442 |
// // Check that explicit type means that defaulting of converters works |
289 |
// tableViewerDescription.addEditableColumn("price"); |
443 |
// TableViewerDescription tableViewerDescription = new |
290 |
// tableViewerDescription.getColumn(0).setPropertyType(Double.TYPE); |
444 |
// TableViewerDescription( |
291 |
// getDbc().bind(tableViewerDescription, |
445 |
// tableViewer); |
292 |
// new Property(catalog, "transporations"), null); |
446 |
// tableViewerDescription.addEditableColumn("price"); |
293 |
// Transportation transporation = catalog.getTransporations()[0]; |
447 |
// tableViewerDescription.getColumn(0).setPropertyType(Double.TYPE); |
294 |
// tableViewer.editElement(transporation, 0); |
448 |
// getDbc().bind(tableViewerDescription, |
295 |
// // Set the text property of the cell editor which is now active over the "firstName" column |
449 |
// new Property(catalog, "transporations"), null); |
296 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
450 |
// Transportation transporation = catalog.getTransporations()[0]; |
297 |
// TextCellEditor priceEditor = (TextCellEditor) cellEditors[0]; |
451 |
// tableViewer.editElement(transporation, 0); |
298 |
// // Change the firstName and test it goes to the model |
452 |
// // Set the text property of the cell editor which is now active over |
299 |
// enterText((Text) priceEditor.getControl(), "123.45"); |
453 |
// the |
300 |
// // Verify the model is updated |
454 |
// "firstName" column |
301 |
// assertEquals(transporation.getPrice(),123.45,0); |
455 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
302 |
|
456 |
// TextCellEditor priceEditor = (TextCellEditor) cellEditors[0]; |
303 |
} |
457 |
// // Change the firstName and test it goes to the model |
304 |
|
458 |
// enterText((Text) priceEditor.getControl(), "123.45"); |
305 |
public void testScenario07(){ |
459 |
// // Verify the model is updated |
306 |
// // Verify that even when a column's property type is not set, that it is worked out lazily from the target type |
460 |
// assertEquals(transporation.getPrice(),123.45,0); |
307 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
461 |
|
308 |
// tableViewer); |
462 |
} |
309 |
// tableViewerDescription.addEditableColumn("price"); |
463 |
|
310 |
// // The column's type is not set to be Double.TYPE. This will be inferred once the first Transportation object is set |
464 |
public void testScenario07() { |
311 |
// // into the ObservableCollection |
465 |
// // Verify that even when a column's property type is not set, that it |
312 |
// getDbc().bind(tableViewerDescription, |
466 |
// is |
313 |
// new Property(catalog, "transporations"), null); |
467 |
// worked out lazily from the target type |
314 |
// Transportation transporation = catalog.getTransporations()[0]; |
468 |
// TableViewerDescription tableViewerDescription = new |
315 |
// tableViewer.editElement(transporation, 0); |
469 |
// TableViewerDescription( |
316 |
// // Set the text property of the cell editor which is now active over the "firstName" column |
470 |
// tableViewer); |
317 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
471 |
// tableViewerDescription.addEditableColumn("price"); |
318 |
// TextCellEditor priceEditor = (TextCellEditor) cellEditors[0]; |
472 |
// // The column's type is not set to be Double.TYPE. This will be |
319 |
// // Change the firstName and test it goes to the model |
473 |
// inferred once |
320 |
// enterText((Text) priceEditor.getControl(), "123.45"); |
474 |
// the first Transportation object is set |
321 |
// // Verify the model is updated |
475 |
// // into the ObservableCollection |
322 |
// assertEquals(transporation.getPrice(),123.45,0); |
476 |
// getDbc().bind(tableViewerDescription, |
323 |
// |
477 |
// new Property(catalog, "transporations"), null); |
324 |
} |
478 |
// Transportation transporation = catalog.getTransporations()[0]; |
325 |
|
479 |
// tableViewer.editElement(transporation, 0); |
326 |
public void testScenario08_00(){ |
480 |
// // Set the text property of the cell editor which is now active over |
327 |
// // Verify that binding to a Collection property (rather than an array) works when specifying data type |
481 |
// the |
328 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
482 |
// "firstName" column |
329 |
// tableViewer); |
483 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
330 |
// tableViewerDescription.addEditableColumn("userId"); |
484 |
// TextCellEditor priceEditor = (TextCellEditor) cellEditors[0]; |
331 |
// tableViewerDescription.addEditableColumn("password"); |
485 |
// // Change the firstName and test it goes to the model |
332 |
// getDbc().bind(tableViewerDescription, |
486 |
// enterText((Text) priceEditor.getControl(), "123.45"); |
333 |
// new Property(catalog, "signons", Signon.class, null), null); |
487 |
// // Verify the model is updated |
334 |
// Signon firstSignon = (Signon) catalog.getSignons().get(0); |
488 |
// assertEquals(transporation.getPrice(),123.45,0); |
335 |
// // Verify the UI matches the model |
489 |
// |
336 |
// TableItem firstTableItem = tableViewer.getTable().getItem(0); |
490 |
} |
337 |
// assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); |
491 |
|
338 |
// // Change the model and ensure the UI refreshes |
492 |
public void testScenario08_00() { |
339 |
// firstSignon.setPassword("Eclipse123Rocks"); |
493 |
// // Verify that binding to a Collection property (rather than an |
340 |
// assertEquals("Eclipse123Rocks",firstSignon.getPassword()); |
494 |
// array) works |
341 |
// assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); |
495 |
// when specifying data type |
342 |
// // Change the GUI and ensure the model refreshes |
496 |
// TableViewerDescription tableViewerDescription = new |
343 |
// tableViewer.editElement(firstSignon, 1); |
497 |
// TableViewerDescription( |
344 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
498 |
// tableViewer); |
345 |
// TextCellEditor passwordEditor = (TextCellEditor) cellEditors[1]; |
499 |
// tableViewerDescription.addEditableColumn("userId"); |
346 |
// enterText((Text) passwordEditor.getControl(), "Cricket11Players"); |
500 |
// tableViewerDescription.addEditableColumn("password"); |
347 |
// assertEquals("Cricket11Players",firstSignon.getPassword()); |
501 |
// getDbc().bind(tableViewerDescription, |
348 |
// |
502 |
// new Property(catalog, "signons", Signon.class, null), null); |
349 |
} |
503 |
// Signon firstSignon = (Signon) catalog.getSignons().get(0); |
350 |
|
504 |
// // Verify the UI matches the model |
351 |
public void testScenario08_01(){ |
505 |
// TableItem firstTableItem = tableViewer.getTable().getItem(0); |
352 |
// // Verify that binding to a Collection property (rather than an array) works without specifying data type |
506 |
// assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); |
353 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription( |
507 |
// // Change the model and ensure the UI refreshes |
354 |
// tableViewer); |
508 |
// firstSignon.setPassword("Eclipse123Rocks"); |
355 |
// tableViewerDescription.addEditableColumn("userId"); |
509 |
// assertEquals("Eclipse123Rocks",firstSignon.getPassword()); |
356 |
// tableViewerDescription.addEditableColumn("password"); |
510 |
// assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); |
357 |
// getDbc().bind(tableViewerDescription, |
511 |
// // Change the GUI and ensure the model refreshes |
358 |
// new Property(catalog, "signons"), null); |
512 |
// tableViewer.editElement(firstSignon, 1); |
359 |
// Signon firstSignon = (Signon) catalog.getSignons().get(0); |
513 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
360 |
// // Verify the UI matches the model |
514 |
// TextCellEditor passwordEditor = (TextCellEditor) cellEditors[1]; |
361 |
// TableItem firstTableItem = tableViewer.getTable().getItem(0); |
515 |
// enterText((Text) passwordEditor.getControl(), "Cricket11Players"); |
362 |
// assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); |
516 |
// assertEquals("Cricket11Players",firstSignon.getPassword()); |
363 |
// // Change the model and ensure the UI refreshes |
517 |
// |
364 |
// firstSignon.setPassword("Eclipse123Rocks"); |
518 |
} |
365 |
// assertEquals("Eclipse123Rocks",firstSignon.getPassword()); |
519 |
|
366 |
// assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); |
520 |
public void testScenario08_01() { |
367 |
// // Change the GUI and ensure the model refreshes |
521 |
// // Verify that binding to a Collection property (rather than an |
368 |
// tableViewer.editElement(firstSignon, 1); |
522 |
// array) works |
369 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
523 |
// without specifying data type |
370 |
// TextCellEditor passwordEditor = (TextCellEditor) cellEditors[1]; |
524 |
// TableViewerDescription tableViewerDescription = new |
371 |
// enterText((Text) passwordEditor.getControl(), "Cricket11Players"); |
525 |
// TableViewerDescription( |
372 |
// assertEquals("Cricket11Players",firstSignon.getPassword()); |
526 |
// tableViewer); |
373 |
// |
527 |
// tableViewerDescription.addEditableColumn("userId"); |
374 |
} |
528 |
// tableViewerDescription.addEditableColumn("password"); |
375 |
|
529 |
// getDbc().bind(tableViewerDescription, |
376 |
public void testScenario09(){ |
530 |
// new Property(catalog, "signons"), null); |
377 |
// // Verify that nested properties work. Catalog has adventures. Adventure has defaultLodging. Loding has name. |
531 |
// Signon firstSignon = (Signon) catalog.getSignons().get(0); |
378 |
// TableViewerDescription tableViewerDescription = new TableViewerDescription(tableViewer); |
532 |
// // Verify the UI matches the model |
379 |
// tableViewerDescription.addColumn("name"); |
533 |
// TableItem firstTableItem = tableViewer.getTable().getItem(0); |
380 |
// tableViewerDescription.addColumn("defaultLodging.name"); |
534 |
// assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); |
381 |
// getDbc().bind(tableViewerDescription,new Property(category, "adventures"),null); |
535 |
// // Change the model and ensure the UI refreshes |
382 |
// |
536 |
// firstSignon.setPassword("Eclipse123Rocks"); |
383 |
} |
537 |
// assertEquals("Eclipse123Rocks",firstSignon.getPassword()); |
384 |
/** |
538 |
// assertEquals(firstTableItem.getText(1),firstSignon.getPassword()); |
385 |
public void testScenario10(){ |
539 |
// // Change the GUI and ensure the model refreshes |
386 |
// Verify that for TIME_EARLY updating occurs on a per key basic for a TextCellEditor |
540 |
// tableViewer.editElement(firstSignon, 1); |
387 |
// Show that converters work for table columns |
541 |
// CellEditor[] cellEditors = tableViewer.getCellEditors(); |
388 |
Account[] accounts = catalog.getAccounts(); |
542 |
// TextCellEditor passwordEditor = (TextCellEditor) cellEditors[1]; |
389 |
Account firstAccount = accounts[0]; |
543 |
// enterText((Text) passwordEditor.getControl(), "Cricket11Players"); |
390 |
SampleData.getSWTObservableFactory().setUpdateTime(DataBindingContext.TIME_EARLY); |
544 |
// assertEquals("Cricket11Players",firstSignon.getPassword()); |
391 |
TableViewerDescription tableViewerDescription = new TableViewerDescription(tableViewer); |
545 |
// |
392 |
tableViewerDescription.addEditableColumn("lastName"); |
546 |
} |
393 |
tableViewerDescription.addColumn("lastName"); |
547 |
|
394 |
getDbc().bind(tableViewerDescription,new Property(catalog, "accounts"), null); |
548 |
public void testScenario09() { |
395 |
|
549 |
// // Verify that nested properties work. Catalog has adventures. |
396 |
// Verify that the first account is shown in the first row with the last name correctly |
550 |
// Adventure has |
397 |
assertEquals(tableViewer.getTable().getItem(0).getData(),firstAccount); |
551 |
// defaultLodging. Loding has name. |
398 |
assertEquals(tableViewer.getTable().getItem(0).getText(0),firstAccount.getLastName()); |
552 |
// TableViewerDescription tableViewerDescription = new |
399 |
assertEquals(tableViewer.getTable().getItem(0).getText(1),firstAccount.getLastName()); |
553 |
// TableViewerDescription(tableViewer); |
400 |
// Create a cell editor over the first column |
554 |
// tableViewerDescription.addColumn("name"); |
401 |
tableViewer.editElement(firstAccount, 0); |
555 |
// tableViewerDescription.addColumn("defaultLodging.name"); |
402 |
// Set the text property of the cell editor which is now active over the "firstName" column |
556 |
// getDbc().bind(tableViewerDescription,new Property(category, |
403 |
CellEditor[] cellEditors = tableViewer.getCellEditors(); |
557 |
// "adventures"),null); |
404 |
TextCellEditor lastNameCellEditor = (TextCellEditor) cellEditors[0]; |
558 |
// |
405 |
((Text)lastNameCellEditor.getControl()).setText("E"); |
559 |
} |
406 |
// Verify that the key press goes to the model |
560 |
|
407 |
assertEquals(firstAccount.getLastName(),"E"); |
561 |
/** |
408 |
|
562 |
* public void testScenario10(){ // Verify that for TIME_EARLY updating |
409 |
} |
563 |
* occurs on a per key basic for a TextCellEditor // Show that converters |
410 |
**/ |
564 |
* work for table columns Account[] accounts = catalog.getAccounts(); |
|
|
565 |
* Account firstAccount = accounts[0]; |
566 |
* SampleData.getSWTObservableFactory().setUpdateTime(DataBindingContext.TIME_EARLY); |
567 |
* TableViewerDescription tableViewerDescription = new |
568 |
* TableViewerDescription(tableViewer); |
569 |
* tableViewerDescription.addEditableColumn("lastName"); |
570 |
* tableViewerDescription.addColumn("lastName"); |
571 |
* getDbc().bind(tableViewerDescription,new Property(catalog, "accounts"), |
572 |
* null); // Verify that the first account is shown in the first row with |
573 |
* the last name correctly |
574 |
* assertEquals(tableViewer.getTable().getItem(0).getData(),firstAccount); |
575 |
* assertEquals(tableViewer.getTable().getItem(0).getText(0),firstAccount.getLastName()); |
576 |
* assertEquals(tableViewer.getTable().getItem(0).getText(1),firstAccount.getLastName()); // |
577 |
* Create a cell editor over the first column |
578 |
* tableViewer.editElement(firstAccount, 0); // Set the text property of the |
579 |
* cell editor which is now active over the "firstName" column CellEditor[] |
580 |
* cellEditors = tableViewer.getCellEditors(); TextCellEditor |
581 |
* lastNameCellEditor = (TextCellEditor) cellEditors[0]; |
582 |
* ((Text)lastNameCellEditor.getControl()).setText("E"); // Verify that the |
583 |
* key press goes to the model assertEquals(firstAccount.getLastName(),"E"); } |
584 |
*/ |
411 |
} |
585 |
} |
412 |
|
|
|