comparison org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet018CheckboxTableViewerCheckedSelection.d @ 100:e884642ad36e

more work on examples
author Frank Benoit <benoit@tionex.de>
date Thu, 23 Apr 2009 00:02:38 +0200
parents 5d5bd660917f
children
comparison
equal deleted inserted replaced
99:5d5bd660917f 100:e884642ad36e
142 newValue); 142 newValue);
143 } 143 }
144 } 144 }
145 145
146 // The data model class. 146 // The data model class.
147 static class Person extends AbstractModelObject { 147 static class Person : AbstractModelObject {
148 private String name; 148 private String name;
149 private Set friends = new HashSet(); 149 private Set friends = new HashSet();
150 150
151 public String getName() { 151 public String getName() {
152 return name; 152 return name;
175 // Typically each View class has a corresponding ViewModel class. 175 // Typically each View class has a corresponding ViewModel class.
176 // 176 //
177 // The ViewModel is responsible for getting the objects to edit from the 177 // The ViewModel is responsible for getting the objects to edit from the
178 // data access tier. Since this snippet doesn't have any persistent objects 178 // data access tier. Since this snippet doesn't have any persistent objects
179 // to retrieve, this ViewModel just instantiates a model object to edit. 179 // to retrieve, this ViewModel just instantiates a model object to edit.
180 static class ViewModel extends AbstractModelObject { 180 static class ViewModel : AbstractModelObject {
181 private List people = new ArrayList(); 181 private List people = new ArrayList();
182 182
183 public List getPeople() { 183 public List getPeople() {
184 return new ArrayList(people); 184 return new ArrayList(people);
185 } 185 }
302 addPersonButton.addListener(SWT.Selection, new Listener() { 302 addPersonButton.addListener(SWT.Selection, new Listener() {
303 public void handleEvent(Event event) { 303 public void handleEvent(Event event) {
304 InputDialog dlg = new InputDialog(shell, "Add Person", 304 InputDialog dlg = new InputDialog(shell, "Add Person",
305 "Enter name:", "<Name>", new IInputValidator() { 305 "Enter name:", "<Name>", new IInputValidator() {
306 public String isValid(String newText) { 306 public String isValid(String newText) {
307 if (newText == null 307 if (newText is null
308 || newText.length() == 0) 308 || newText.length() is 0)
309 return "Name cannot be empty"; 309 return "Name cannot be empty";
310 return null; 310 return null;
311 } 311 }
312 }); 312 });
313 if (dlg.open() == Window.OK) { 313 if (dlg.open() is Window.OK) {
314 Person person = new Person(); 314 Person person = new Person();
315 person.setName(dlg.getValue()); 315 person.setName(dlg.getValue());
316 people.add(person); 316 people.add(person);
317 peopleViewer.setSelection(new StructuredSelection( 317 peopleViewer.setSelection(new StructuredSelection(
318 person)); 318 person));
339 final IObservableValue selectedPerson = ViewersObservables 339 final IObservableValue selectedPerson = ViewersObservables
340 .observeSingleSelection(peopleViewer); 340 .observeSingleSelection(peopleViewer);
341 341
342 IObservableValue personSelected = new ComputedValue(bool.TYPE) { 342 IObservableValue personSelected = new ComputedValue(bool.TYPE) {
343 protected Object calculate() { 343 protected Object calculate() {
344 return bool.valueOf(selectedPerson.getValue() != null); 344 return bool.valueOf(selectedPerson.getValue() !is null);
345 } 345 }
346 }; 346 };
347 dbc.bindValue(SWTObservables.observeEnabled(removePersonButton), 347 dbc.bindValue(SWTObservables.observeEnabled(removePersonButton),
348 personSelected); 348 personSelected);
349 dbc.bindValue(SWTObservables.observeEnabled(friendsViewer 349 dbc.bindValue(SWTObservables.observeEnabled(friendsViewer