Revision b0ce5b17
Added by Patrick Plitzner over 10 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/AbstractFormSection.java | ||
---|---|---|
1 | 1 |
/** |
2 |
*
|
|
2 |
* |
|
3 | 3 |
*/ |
4 | 4 |
package eu.etaxonomy.taxeditor.ui.element; |
5 | 5 |
|
... | ... | |
33 | 33 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
34 | 34 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
35 | 35 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
36 |
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
|
36 |
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
|
37 | 37 |
|
38 | 38 |
/** |
39 | 39 |
* <p> |
40 |
* Abstract AbstractFormSection class. |
|
40 |
* Abstract super class for a {@link Section} GUI element that visualizes a CDM |
|
41 |
* entity, manages a conversation and listens to selections |
|
41 | 42 |
* </p> |
42 |
* |
|
43 |
* |
|
44 |
* @param <ENTITY> A CDM entity which should be visualized by this section. |
|
45 |
* |
|
43 | 46 |
* @author n.hoffmann |
44 | 47 |
* @created Feb 22, 2010 |
45 | 48 |
* @version 1.0 |
46 | 49 |
* @param <T> |
47 | 50 |
*/ |
51 |
//TODO shouldn't ENTITY be bound with super class ICdmBase for example (AbstractFormSection<ENTITY extends ICdmBase>)? |
|
48 | 52 |
public abstract class AbstractFormSection<ENTITY> extends Section implements |
49 |
ISelectionChangedListener, ICdmFormElement, IEntityElement<ENTITY>,
|
|
53 |
ISelectionChangedListener, IEntityElement<ENTITY>, |
|
50 | 54 |
IConversationEnabled { |
51 | 55 |
|
52 | 56 |
private ISelectionProvider selectionProvider; |
53 | 57 |
|
54 | 58 |
private ENTITY entity; |
55 | 59 |
|
56 |
private Set<ICdmFormElement> elements = new HashSet<ICdmFormElement>(); |
|
60 |
private final Set<ICdmFormElement> elements = new HashSet<ICdmFormElement>();
|
|
57 | 61 |
|
58 | 62 |
protected CdmFormFactory formFactory; |
59 | 63 |
|
... | ... | |
67 | 71 |
* <p> |
68 | 72 |
* Constructor for AbstractFormSection. |
69 | 73 |
* </p> |
70 |
*
|
|
74 |
* |
|
71 | 75 |
* @param conversation |
72 | 76 |
* TODO |
73 | 77 |
* @param style |
... | ... | |
81 | 85 |
* @param <ENTITY> |
82 | 86 |
* a ENTITY object. |
83 | 87 |
*/ |
84 |
protected AbstractFormSection(CdmFormFactory formFactory, ICdmFormElement parentElement, |
|
85 |
int style) { |
|
88 |
protected AbstractFormSection(CdmFormFactory formFactory, ICdmFormElement parentElement, int style) { |
|
86 | 89 |
super(parentElement.getLayoutComposite(), style); |
87 | 90 |
|
88 | 91 |
this.parentElement = parentElement; |
... | ... | |
103 | 106 |
this.setClient(client); |
104 | 107 |
} |
105 | 108 |
|
106 |
/** |
|
107 |
* <p> |
|
108 |
* Constructor for AbstractFormSection. |
|
109 |
* </p> |
|
110 |
* |
|
111 |
* @param formFactory |
|
112 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
113 |
* object. |
|
114 |
* @param conversation |
|
115 |
* a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} |
|
116 |
* object. |
|
117 |
* @param parentElement |
|
118 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
119 |
* object. |
|
120 |
* @param selectionProvider |
|
121 |
* a {@link org.eclipse.jface.viewers.ISelectionProvider} object. |
|
122 |
* @param style |
|
123 |
* a int. |
|
124 |
*/ |
|
125 |
protected AbstractFormSection(CdmFormFactory formFactory, |
|
126 |
ICdmFormElement parentElement, |
|
127 |
ISelectionProvider selectionProvider, int style) { |
|
128 |
this(formFactory, parentElement, style); |
|
129 |
this.selectionProvider = selectionProvider; |
|
130 |
} |
|
109 |
/** |
|
110 |
* <p> |
|
111 |
* Constructor for AbstractFormSection. |
|
112 |
* </p> |
|
113 |
* |
|
114 |
* @param formFactory |
|
115 |
* a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} |
|
116 |
* object. |
|
117 |
* @param conversation |
|
118 |
* a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} |
|
119 |
* object. |
|
120 |
* @param parentElement |
|
121 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
|
122 |
* object. |
|
123 |
* @param selectionProvider |
|
124 |
* a {@link org.eclipse.jface.viewers.ISelectionProvider} object. |
|
125 |
* @param style |
|
126 |
* a int. |
|
127 |
*/ |
|
128 |
protected AbstractFormSection(CdmFormFactory formFactory, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) { |
|
129 |
this(formFactory, parentElement, style); |
|
130 |
this.selectionProvider = selectionProvider; |
|
131 |
} |
|
131 | 132 |
|
132 | 133 |
/** |
133 | 134 |
* <p> |
134 | 135 |
* Getter for the field <code>propertyChangeListeners</code>. |
135 | 136 |
* </p> |
136 |
*
|
|
137 |
* |
|
137 | 138 |
* @return a {@link java.util.Set} object. |
138 | 139 |
*/ |
139 |
public List<IPropertyChangeListener> getPropertyChangeListeners() { |
|
140 |
@Override |
|
141 |
public List<IPropertyChangeListener> getPropertyChangeListeners() { |
|
140 | 142 |
return propertyChangeListeners; |
141 | 143 |
} |
142 | 144 |
|
143 | 145 |
/** {@inheritDoc} */ |
144 |
public void setPropertyChangeListeners( |
|
146 |
@Override |
|
147 |
public void setPropertyChangeListeners( |
|
145 | 148 |
List<IPropertyChangeListener> propertyChangeListeners) { |
146 | 149 |
this.propertyChangeListeners = propertyChangeListeners; |
147 | 150 |
} |
... | ... | |
150 | 153 |
* <p> |
151 | 154 |
* Setter for the field <code>entity</code>. |
152 | 155 |
* </p> |
153 |
*
|
|
156 |
* |
|
154 | 157 |
* @param entity |
155 | 158 |
* a ENTITY object. |
156 | 159 |
*/ |
... | ... | |
160 | 163 |
|
161 | 164 |
/* |
162 | 165 |
* (non-Javadoc) |
163 |
*
|
|
166 |
* |
|
164 | 167 |
* @see eu.etaxonomy.taxeditor.forms.IEntityElement#getEntity() |
165 | 168 |
*/ |
166 | 169 |
/** |
167 | 170 |
* <p> |
168 | 171 |
* Getter for the field <code>entity</code>. |
169 | 172 |
* </p> |
170 |
*
|
|
173 |
* |
|
171 | 174 |
* @return a ENTITY object. |
172 | 175 |
*/ |
173 |
public ENTITY getEntity() { |
|
176 |
@Override |
|
177 |
public ENTITY getEntity() { |
|
174 | 178 |
return entity; |
175 | 179 |
} |
176 | 180 |
|
... | ... | |
178 | 182 |
* <p> |
179 | 183 |
* getToggle |
180 | 184 |
* </p> |
181 |
*
|
|
185 |
* |
|
182 | 186 |
* @return a {@link org.eclipse.ui.forms.widgets.ToggleHyperlink} object. |
183 | 187 |
*/ |
184 | 188 |
public ToggleHyperlink getToggle() { |
... | ... | |
189 | 193 |
* <p> |
190 | 194 |
* getSection |
191 | 195 |
* </p> |
192 |
*
|
|
196 |
* |
|
193 | 197 |
* @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} |
194 | 198 |
* object. |
195 | 199 |
*/ |
... | ... | |
199 | 203 |
|
200 | 204 |
/* |
201 | 205 |
* (non-Javadoc) |
202 |
*
|
|
206 |
* |
|
203 | 207 |
* @see |
204 | 208 |
* eu.etaxonomy.taxeditor.forms.IPropertyChangeEmitter#firePropertyChangeEvent |
205 | 209 |
* () |
206 | 210 |
*/ |
207 | 211 |
/** {@inheritDoc} */ |
208 |
public void firePropertyChangeEvent(CdmPropertyChangeEvent event) { |
|
209 |
Assert.isNotNull(propertyChangeListeners, |
|
210 |
"No property change listeners."); |
|
211 |
try { |
|
212 |
for (Object listener : propertyChangeListeners) { |
|
213 |
((IPropertyChangeListener) listener).propertyChange(event); |
|
214 |
} |
|
215 |
} catch (ConcurrentModificationException e) { |
|
216 |
StoreUtil.warn(getClass(), |
|
217 |
"ConcurrentModificationException while handling PropertyChangeEvents." |
|
218 |
+ " It seems like this is not critical"); |
|
219 |
} |
|
212 |
@Override |
|
213 |
public void firePropertyChangeEvent(CdmPropertyChangeEvent event) { |
|
214 |
Assert.isNotNull(propertyChangeListeners, "No property change listeners."); |
|
215 |
try { |
|
216 |
for (Object listener : propertyChangeListeners) { |
|
217 |
((IPropertyChangeListener) listener).propertyChange(event); |
|
218 |
} |
|
219 |
} catch (ConcurrentModificationException e) { |
|
220 |
AbstractUtility.warn(getClass(), "ConcurrentModificationException while handling PropertyChangeEvents." |
|
221 |
+ " It seems like this is not critical"); |
|
222 |
} |
|
220 | 223 |
} |
221 | 224 |
|
222 | 225 |
/** |
223 | 226 |
* Fires a {@link CdmPropertyChangeEvent} with the given object as source. |
224 |
*
|
|
227 |
* |
|
225 | 228 |
* @param object |
226 | 229 |
* the object on which the property changed |
227 | 230 |
*/ |
... | ... | |
232 | 235 |
/** |
233 | 236 |
* Fires a {@link CdmPropertyChangeEvent} with the given object as source |
234 | 237 |
* also containing the originating event |
235 |
*
|
|
238 |
* |
|
236 | 239 |
* @param object |
237 | 240 |
* the object on which the property changed |
238 | 241 |
* @param originatingEvent |
... | ... | |
246 | 249 |
|
247 | 250 |
/* |
248 | 251 |
* (non-Javadoc) |
249 |
*
|
|
252 |
* |
|
250 | 253 |
* @see org.eclipse.swt.widgets.Composite#setFocus() |
251 | 254 |
*/ |
252 | 255 |
/** {@inheritDoc} */ |
... | ... | |
257 | 260 |
|
258 | 261 |
/* |
259 | 262 |
* (non-Javadoc) |
260 |
*
|
|
263 |
* |
|
261 | 264 |
* @see |
262 | 265 |
* org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse |
263 | 266 |
* .jface.util.PropertyChangeEvent) |
264 | 267 |
*/ |
265 | 268 |
/** {@inheritDoc} */ |
266 |
public void propertyChange(PropertyChangeEvent event) { |
|
269 |
@Override |
|
270 |
public void propertyChange(PropertyChangeEvent event) { |
|
267 | 271 |
firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event)); |
268 | 272 |
} |
269 | 273 |
|
270 | 274 |
/* |
271 | 275 |
* (non-Javadoc) |
272 |
*
|
|
276 |
* |
|
273 | 277 |
* @see |
274 | 278 |
* org.eclipse.swt.widgets.Control#setBackground(org.eclipse.swt.graphics |
275 | 279 |
* .Color) |
... | ... | |
283 | 287 |
getLayoutComposite().setBackground(color); |
284 | 288 |
super.setBackground(color); |
285 | 289 |
} |
286 |
|
|
290 |
|
|
287 | 291 |
@Override |
288 | 292 |
public void setPersistentBackground(Color color) { |
289 | 293 |
persistentBackgroundColor = color; |
290 | 294 |
setBackground(color); |
291 | 295 |
} |
292 |
|
|
296 |
|
|
293 | 297 |
@Override |
294 | 298 |
public Color getPersistentBackground() { |
295 | 299 |
return persistentBackgroundColor; |
296 | 300 |
} |
297 |
|
|
301 |
|
|
298 | 302 |
|
299 | 303 |
/** |
300 | 304 |
* <p> |
301 | 305 |
* widgetSelected |
302 | 306 |
* </p> |
303 |
*
|
|
307 |
* |
|
304 | 308 |
* @param e |
305 | 309 |
* a {@link org.eclipse.swt.events.SelectionEvent} object. |
306 | 310 |
*/ |
307 | 311 |
public void widgetSelected(SelectionEvent e) { |
308 |
Widget widget = e.widget; |
|
309 |
|
|
310 |
if (widget instanceof Control) { |
|
311 |
Control control = (Control) widget; |
|
312 |
if (checkControlAncestryForWidget(control)) { |
|
313 |
if (getEntity() != null) { |
|
314 |
IStructuredSelection selection = new StructuredSelection( |
|
315 |
getEntity()); |
|
316 |
if (selectionProvider != null) { |
|
317 |
selectionProvider.setSelection(selection); |
|
318 |
} |
|
319 |
} |
|
320 |
} |
|
321 |
} |
|
312 |
Widget widget = e.widget; |
|
313 |
|
|
314 |
if (widget instanceof Control) { |
|
315 |
Control control = (Control) widget; |
|
316 |
if (checkControlAncestryForWidget(control)) { |
|
317 |
if (getEntity() != null) { |
|
318 |
IStructuredSelection selection = new StructuredSelection(getEntity()); |
|
319 |
if (selectionProvider != null) { |
|
320 |
selectionProvider.setSelection(selection); |
|
321 |
} |
|
322 |
} |
|
323 |
} |
|
324 |
} |
|
322 | 325 |
} |
323 | 326 |
|
324 | 327 |
private boolean checkControlAncestryForWidget(Control control) { |
... | ... | |
335 | 338 |
} |
336 | 339 |
|
337 | 340 |
/** {@inheritDoc} */ |
338 |
public void setSelected(boolean selected) { |
|
341 |
@Override |
|
342 |
public void setSelected(boolean selected) { |
|
339 | 343 |
if (selected) { |
340 | 344 |
setBackground(Display.getCurrent().getSystemColor( |
341 | 345 |
SWT.COLOR_LIST_SELECTION)); |
... | ... | |
345 | 349 |
} |
346 | 350 |
|
347 | 351 |
/** {@inheritDoc} */ |
348 |
public void selectionChanged(SelectionChangedEvent event) { |
|
352 |
@Override |
|
353 |
public void selectionChanged(SelectionChangedEvent event) { |
|
349 | 354 |
if (event.getSelection() == CdmFormFactory.EMPTY_SELECTION) { |
350 | 355 |
return; |
351 | 356 |
} |
... | ... | |
365 | 370 |
* <p> |
366 | 371 |
* addSelectionListener |
367 | 372 |
* </p> |
368 |
*
|
|
373 |
* |
|
369 | 374 |
* @param listener |
370 | 375 |
* a {@link org.eclipse.swt.events.SelectionListener} object. |
371 | 376 |
*/ |
... | ... | |
377 | 382 |
* <p> |
378 | 383 |
* removeSelectionListener |
379 | 384 |
* </p> |
380 |
*
|
|
385 |
* |
|
381 | 386 |
* @param listener |
382 | 387 |
* a {@link org.eclipse.swt.events.SelectionListener} object. |
383 | 388 |
*/ |
... | ... | |
386 | 391 |
} |
387 | 392 |
|
388 | 393 |
/** {@inheritDoc} */ |
389 |
public void addElement(ICdmFormElement element) { |
|
394 |
@Override |
|
395 |
public void addElement(ICdmFormElement element) { |
|
390 | 396 |
elements.add(element); |
391 | 397 |
} |
392 | 398 |
|
... | ... | |
394 | 400 |
* <p> |
395 | 401 |
* removeElement |
396 | 402 |
* </p> |
397 |
*
|
|
403 |
* |
|
398 | 404 |
* @param element |
399 | 405 |
* a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} |
400 | 406 |
* object. |
... | ... | |
408 | 414 |
* removeElements |
409 | 415 |
* </p> |
410 | 416 |
*/ |
411 |
public void removeElements() { |
|
417 |
@Override |
|
418 |
public void removeElements() { |
|
412 | 419 |
for (ICdmFormElement childElement : getElements()) { |
413 | 420 |
// recursion |
414 | 421 |
childElement.removeElements(); |
... | ... | |
416 | 423 |
// unregister selection arbitrator |
417 | 424 |
if (childElement instanceof ISelectableElement) { |
418 | 425 |
ISelectableElement selectableElement = (ISelectableElement) childElement; |
419 |
if (selectableElement != null |
|
420 |
&& selectableElement.getSelectionArbitrator() != null) { |
|
426 |
if (selectableElement.getSelectionArbitrator() != null) { |
|
421 | 427 |
formFactory.destroySelectionArbitrator(selectableElement |
422 | 428 |
.getSelectionArbitrator()); |
423 | 429 |
} |
... | ... | |
447 | 453 |
* <p> |
448 | 454 |
* Getter for the field <code>parentElement</code>. |
449 | 455 |
* </p> |
450 |
*
|
|
456 |
* |
|
451 | 457 |
* @return a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object. |
452 | 458 |
*/ |
453 |
public ICdmFormElement getParentElement() { |
|
459 |
@Override |
|
460 |
public ICdmFormElement getParentElement() { |
|
454 | 461 |
return parentElement; |
455 | 462 |
} |
456 | 463 |
|
... | ... | |
458 | 465 |
* <p> |
459 | 466 |
* Getter for the field <code>elements</code>. |
460 | 467 |
* </p> |
461 |
*
|
|
468 |
* |
|
462 | 469 |
* @return a {@link java.util.Set} object. |
463 | 470 |
*/ |
464 |
public Set<ICdmFormElement> getElements() { |
|
471 |
@Override |
|
472 |
public Set<ICdmFormElement> getElements() { |
|
465 | 473 |
return elements; |
466 | 474 |
} |
467 | 475 |
|
... | ... | |
469 | 477 |
* <p> |
470 | 478 |
* getControls |
471 | 479 |
* </p> |
472 |
*
|
|
480 |
* |
|
473 | 481 |
* @return a {@link java.util.Set} object. |
474 | 482 |
*/ |
475 |
public Set<Control> getControls() { |
|
483 |
@Override |
|
484 |
public Set<Control> getControls() { |
|
476 | 485 |
Set<Control> controls = new HashSet<Control>(); |
477 | 486 |
|
478 | 487 |
for (Control control : getChildren()) { |
... | ... | |
493 | 502 |
* <p> |
494 | 503 |
* getLayoutComposite |
495 | 504 |
* </p> |
496 |
*
|
|
505 |
* |
|
497 | 506 |
* @return a {@link org.eclipse.swt.widgets.Composite} object. |
498 | 507 |
*/ |
499 |
public Composite getLayoutComposite() { |
|
508 |
@Override |
|
509 |
public Composite getLayoutComposite() { |
|
500 | 510 |
return (Composite) getClient(); |
501 | 511 |
} |
502 | 512 |
|
503 | 513 |
/** {@inheritDoc} */ |
504 |
public boolean containsFormElement(ICdmFormElement formElement) { |
|
514 |
@Override |
|
515 |
public boolean containsFormElement(ICdmFormElement formElement) { |
|
505 | 516 |
if (formElement == this) { |
506 | 517 |
return true; |
507 | 518 |
} else { |
... | ... | |
519 | 530 |
* <p> |
520 | 531 |
* Getter for the field <code>formFactory</code>. |
521 | 532 |
* </p> |
522 |
*
|
|
533 |
* |
|
523 | 534 |
* @return a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object. |
524 | 535 |
*/ |
525 | 536 |
public CdmFormFactory getFormFactory() { |
... | ... | |
528 | 539 |
|
529 | 540 |
/* |
530 | 541 |
* (non-Javadoc) |
531 |
*
|
|
542 |
* |
|
532 | 543 |
* @see eu.etaxonomy.taxeditor.forms.ICdmFormElement#refresh() |
533 | 544 |
*/ |
534 | 545 |
/** |
... | ... | |
536 | 547 |
* refresh |
537 | 548 |
* </p> |
538 | 549 |
*/ |
539 |
public void refresh() { |
|
550 |
@Override |
|
551 |
public void refresh() { |
|
540 | 552 |
// empty default implementation |
541 | 553 |
|
542 | 554 |
} |
... | ... | |
545 | 557 |
* <p> |
546 | 558 |
* getConversationHolder |
547 | 559 |
* </p> |
548 |
*
|
|
560 |
* |
|
549 | 561 |
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} |
550 | 562 |
* object. |
551 | 563 |
*/ |
552 |
public ConversationHolder getConversationHolder() { |
|
564 |
@Override |
|
565 |
public ConversationHolder getConversationHolder() { |
|
553 | 566 |
if(getParentElement() instanceof RootElement || getParentElement() == null){ |
554 |
|
|
555 |
IEditorPart activeEditor = StoreUtil.getActiveEditor();
|
|
567 |
|
|
568 |
IEditorPart activeEditor = AbstractUtility.getActiveEditor();
|
|
556 | 569 |
if(activeEditor instanceof IConversationEnabled){ |
557 |
ConversationHolder conversation = ((IConversationEnabled) StoreUtil.getActiveEditor()).getConversationHolder();
|
|
570 |
ConversationHolder conversation = ((IConversationEnabled) AbstractUtility.getActiveEditor()).getConversationHolder();
|
|
558 | 571 |
return conversation; |
559 | 572 |
} |
560 | 573 |
}else if(getParentElement() instanceof IConversationEnabled){ |
561 | 574 |
return ((IConversationEnabled) getParentElement()).getConversationHolder(); |
562 | 575 |
} |
563 |
StoreUtil.errorDialog("Could not get conversation for AbstractFormSection",
|
|
564 |
getClass(), "There is an error in the implementation. There should have been an active editor but it wasn't",
|
|
576 |
AbstractUtility.errorDialog("Could not get conversation for AbstractFormSection",
|
|
577 |
getClass(), "There is an error in the implementation. There should have been an active editor but it wasn't", |
|
565 | 578 |
new IllegalArgumentException()); |
566 | 579 |
return null; |
567 |
|
|
580 |
|
|
568 | 581 |
} |
569 | 582 |
|
570 | 583 |
/** {@inheritDoc} */ |
571 |
public void update(CdmDataChangeMap changeEvents) { |
|
584 |
@Override |
|
585 |
public void update(CdmDataChangeMap changeEvents) { |
|
572 | 586 |
} |
573 | 587 |
|
574 | 588 |
|
Also available in: Unified diff
merged trunk into branch