Mercurial > projects > dwt2
comparison org.eclipse.jface.examples.databinding/src/org/eclipse/jface/examples/databinding/snippets/Snippet020TreeViewerWithSetFactory.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 |
---|---|
155 public void widgetSelected(final SelectionEvent e) { | 155 public void widgetSelected(final SelectionEvent e) { |
156 TreeItem selectedItem = beanViewer.getTree().getSelection()[0]; | 156 TreeItem selectedItem = beanViewer.getTree().getSelection()[0]; |
157 Bean bean = (Bean) selectedItem.getData(); | 157 Bean bean = (Bean) selectedItem.getData(); |
158 TreeItem parentItem = selectedItem.getParentItem(); | 158 TreeItem parentItem = selectedItem.getParentItem(); |
159 Bean parent; | 159 Bean parent; |
160 if (parentItem == null) | 160 if (parentItem is null) |
161 parent = input; | 161 parent = input; |
162 else | 162 else |
163 parent = (Bean) parentItem.getData(); | 163 parent = (Bean) parentItem.getData(); |
164 | 164 |
165 Set set = new HashSet(parent.getSet()); | 165 Set set = new HashSet(parent.getSet()); |
179 | 179 |
180 pasteButton = new Button(group, SWT.NONE); | 180 pasteButton = new Button(group, SWT.NONE); |
181 pasteButton.addSelectionListener(new SelectionAdapter() { | 181 pasteButton.addSelectionListener(new SelectionAdapter() { |
182 public void widgetSelected(final SelectionEvent e) { | 182 public void widgetSelected(final SelectionEvent e) { |
183 Bean copy = (Bean) clipboard.getValue(); | 183 Bean copy = (Bean) clipboard.getValue(); |
184 if (copy == null) | 184 if (copy is null) |
185 return; | 185 return; |
186 Bean parent = getSelectedBean(); | 186 Bean parent = getSelectedBean(); |
187 if (parent == null) | 187 if (parent is null) |
188 parent = input; | 188 parent = input; |
189 | 189 |
190 Set set = new HashSet(parent.getSet()); | 190 Set set = new HashSet(parent.getSet()); |
191 set.add(copy); | 191 set.add(copy); |
192 parent.setSet(set); | 192 parent.setSet(set); |
257 private void initExtraBindings(DataBindingContext dbc) { | 257 private void initExtraBindings(DataBindingContext dbc) { |
258 final IObservableValue beanViewerSelection = ViewersObservables | 258 final IObservableValue beanViewerSelection = ViewersObservables |
259 .observeSingleSelection(beanViewer); | 259 .observeSingleSelection(beanViewer); |
260 IObservableValue beanSelected = new ComputedValue(bool.TYPE) { | 260 IObservableValue beanSelected = new ComputedValue(bool.TYPE) { |
261 protected Object calculate() { | 261 protected Object calculate() { |
262 return bool.valueOf(beanViewerSelection.getValue() != null); | 262 return bool.valueOf(beanViewerSelection.getValue() !is null); |
263 } | 263 } |
264 }; | 264 }; |
265 dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), | 265 dbc.bindValue(SWTObservables.observeEnabled(addChildBeanButton), |
266 beanSelected); | 266 beanSelected); |
267 dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), | 267 dbc.bindValue(SWTObservables.observeEnabled(removeBeanButton), |
270 clipboard = new WritableValue(); | 270 clipboard = new WritableValue(); |
271 dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected); | 271 dbc.bindValue(SWTObservables.observeEnabled(copyButton), beanSelected); |
272 dbc.bindValue(SWTObservables.observeEnabled(pasteButton), | 272 dbc.bindValue(SWTObservables.observeEnabled(pasteButton), |
273 new ComputedValue(bool.TYPE) { | 273 new ComputedValue(bool.TYPE) { |
274 protected Object calculate() { | 274 protected Object calculate() { |
275 return bool.valueOf(clipboard.getValue() != null); | 275 return bool.valueOf(clipboard.getValue() !is null); |
276 } | 276 } |
277 }); | 277 }); |
278 | 278 |
279 ViewerSupport.bind(beanViewer, input, BeanProperties.set("set", | 279 ViewerSupport.bind(beanViewer, input, BeanProperties.set("set", |
280 Bean.class), BeanProperties.value(Bean.class, "text")); | 280 Bean.class), BeanProperties.value(Bean.class, "text")); |
307 changeSupport.firePropertyChange("text", this.text, | 307 changeSupport.firePropertyChange("text", this.text, |
308 this.text = value); | 308 this.text = value); |
309 } | 309 } |
310 | 310 |
311 public Set getSet() { | 311 public Set getSet() { |
312 if (set == null) | 312 if (set is null) |
313 return null; | 313 return null; |
314 return new HashSet(set); | 314 return new HashSet(set); |
315 } | 315 } |
316 | 316 |
317 public void setSet(Set set) { | 317 public void setSet(Set set) { |
318 if (set != null) | 318 if (set !is null) |
319 set = new HashSet(set); | 319 set = new HashSet(set); |
320 changeSupport.firePropertyChange("set", this.set, this.set = set); | 320 changeSupport.firePropertyChange("set", this.set, this.set = set); |
321 } | 321 } |
322 | 322 |
323 public bool hasListeners(String propertyName) { | 323 public bool hasListeners(String propertyName) { |