refactored NumberWithLabelElement to a single constructor with java.lang.Number as...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / CdmFormFactory.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.ui.element;
5
6 import java.net.URI;
7 import java.util.ArrayList;
8 import java.util.HashSet;
9 import java.util.List;
10 import java.util.Map;
11 import java.util.Set;
12
13 import org.eclipse.jface.util.IPropertyChangeListener;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.ISelectionProvider;
16 import org.eclipse.jface.window.Window;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.custom.StyledText;
19 import org.eclipse.swt.events.FocusAdapter;
20 import org.eclipse.swt.events.FocusEvent;
21 import org.eclipse.swt.events.FocusListener;
22 import org.eclipse.swt.events.MouseAdapter;
23 import org.eclipse.swt.events.MouseEvent;
24 import org.eclipse.swt.events.MouseListener;
25 import org.eclipse.swt.events.SelectionEvent;
26 import org.eclipse.swt.events.SelectionListener;
27 import org.eclipse.swt.events.TypedEvent;
28 import org.eclipse.swt.graphics.Color;
29 import org.eclipse.swt.graphics.Font;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Display;
33 import org.eclipse.swt.widgets.Event;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.ui.forms.IFormColors;
36 import org.eclipse.ui.forms.widgets.FormToolkit;
37 import org.eclipse.ui.forms.widgets.Section;
38 import org.eclipse.ui.internal.forms.widgets.FormFonts;
39 import org.joda.time.Partial;
40 import org.springframework.security.core.GrantedAuthority;
41
42 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
43 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
44 import eu.etaxonomy.cdm.model.agent.Person;
45 import eu.etaxonomy.cdm.model.agent.Team;
46 import eu.etaxonomy.cdm.model.common.Annotation;
47 import eu.etaxonomy.cdm.model.common.CdmBase;
48 import eu.etaxonomy.cdm.model.common.Credit;
49 import eu.etaxonomy.cdm.model.common.DefinedTerm;
50 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
51 import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
52 import eu.etaxonomy.cdm.model.common.Extension;
53 import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
54 import eu.etaxonomy.cdm.model.common.Group;
55 import eu.etaxonomy.cdm.model.common.ICdmBase;
56 import eu.etaxonomy.cdm.model.common.IDefinedTerm;
57 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
58 import eu.etaxonomy.cdm.model.common.Language;
59 import eu.etaxonomy.cdm.model.common.LanguageString;
60 import eu.etaxonomy.cdm.model.common.Marker;
61 import eu.etaxonomy.cdm.model.common.TimePeriod;
62 import eu.etaxonomy.cdm.model.common.User;
63 import eu.etaxonomy.cdm.model.common.VersionableEntity;
64 import eu.etaxonomy.cdm.model.description.CategoricalData;
65 import eu.etaxonomy.cdm.model.description.CommonTaxonName;
66 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
67 import eu.etaxonomy.cdm.model.description.Distribution;
68 import eu.etaxonomy.cdm.model.description.Feature;
69 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
70 import eu.etaxonomy.cdm.model.description.KeyStatement;
71 import eu.etaxonomy.cdm.model.description.QuantitativeData;
72 import eu.etaxonomy.cdm.model.description.StateData;
73 import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
74 import eu.etaxonomy.cdm.model.description.TaxonInteraction;
75 import eu.etaxonomy.cdm.model.description.TextData;
76 import eu.etaxonomy.cdm.model.location.NamedArea;
77 import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
78 import eu.etaxonomy.cdm.model.location.Point;
79 import eu.etaxonomy.cdm.model.media.ImageFile;
80 import eu.etaxonomy.cdm.model.media.Media;
81 import eu.etaxonomy.cdm.model.media.MediaRepresentation;
82 import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
83 import eu.etaxonomy.cdm.model.media.Rights;
84 import eu.etaxonomy.cdm.model.name.NameRelationship;
85 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
86 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
87 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
88 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
89 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
90 import eu.etaxonomy.cdm.model.reference.Reference;
91 import eu.etaxonomy.cdm.model.taxon.Taxon;
92 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
93 import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
94 import eu.etaxonomy.taxeditor.store.StoreUtil;
95 import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
96 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
97 import eu.etaxonomy.taxeditor.ui.openurl.IOpenUrlEnabled;
98 import eu.etaxonomy.taxeditor.ui.openurl.OpenUrlSelectorElement;
99 import eu.etaxonomy.taxeditor.ui.password.EditPasswordElement;
100 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
101 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
102 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
103 import eu.etaxonomy.taxeditor.ui.section.EmptyElement;
104 import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionDetailElement;
105 import eu.etaxonomy.taxeditor.ui.section.agent.InstitutionDetailSection;
106 import eu.etaxonomy.taxeditor.ui.section.agent.PersonDetailElement;
107 import eu.etaxonomy.taxeditor.ui.section.agent.PersonDetailSection;
108 import eu.etaxonomy.taxeditor.ui.section.agent.TeamDetailElement;
109 import eu.etaxonomy.taxeditor.ui.section.agent.TeamDetailSection;
110 import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberElement;
111 import eu.etaxonomy.taxeditor.ui.section.agent.TeamMemberSection;
112 import eu.etaxonomy.taxeditor.ui.section.agent.TeamOrPersonBaseDetailSection;
113 import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailElement;
114 import eu.etaxonomy.taxeditor.ui.section.classification.ClassificationDetailSection;
115 import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailElement;
116 import eu.etaxonomy.taxeditor.ui.section.classification.TaxonNodeDetailSection;
117 import eu.etaxonomy.taxeditor.ui.section.common.ReferencedEntityDetailSection;
118 import eu.etaxonomy.taxeditor.ui.section.common.RefereneEntityDetailElement;
119 import eu.etaxonomy.taxeditor.ui.section.description.DerivedUnitElement;
120 import eu.etaxonomy.taxeditor.ui.section.description.DescribedSpecimenSection;
121 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailElement;
122 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailSection;
123 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailElement;
124 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailSection;
125 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementMediaSection;
126 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceElement;
127 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceSection;
128 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceElement;
129 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceSection;
130 import eu.etaxonomy.taxeditor.ui.section.description.ModifierElement;
131 import eu.etaxonomy.taxeditor.ui.section.description.ModifierSection;
132 import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageDetailElement;
133 import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageSection;
134 import eu.etaxonomy.taxeditor.ui.section.description.ScopeElement;
135 import eu.etaxonomy.taxeditor.ui.section.description.ScopeSection;
136 import eu.etaxonomy.taxeditor.ui.section.description.StateDataElement;
137 import eu.etaxonomy.taxeditor.ui.section.description.StateDataSection;
138 import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueElement;
139 import eu.etaxonomy.taxeditor.ui.section.description.StatisticalMeasurementValueSection;
140 import eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement;
141 import eu.etaxonomy.taxeditor.ui.section.description.detail.CategoricalDataDetailElement;
142 import eu.etaxonomy.taxeditor.ui.section.description.detail.CommonNameDetailElement;
143 import eu.etaxonomy.taxeditor.ui.section.description.detail.DistributionDetailElement;
144 import eu.etaxonomy.taxeditor.ui.section.description.detail.IndividualsAssociationDetailElement;
145 import eu.etaxonomy.taxeditor.ui.section.description.detail.QuantitativeDataDetailElement;
146 import eu.etaxonomy.taxeditor.ui.section.description.detail.TaxonInteractionDetailElement;
147 import eu.etaxonomy.taxeditor.ui.section.description.detail.TextDataDetailElement;
148 import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailElement;
149 import eu.etaxonomy.taxeditor.ui.section.feature.FeatureDistributionDetailSection;
150 import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityCollectionElement;
151 import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailElement;
152 import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityDetailSection;
153 import eu.etaxonomy.taxeditor.ui.section.group.GroupDetailElement;
154 import eu.etaxonomy.taxeditor.ui.section.group.GroupDetailSection;
155 import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailElement;
156 import eu.etaxonomy.taxeditor.ui.section.group.MemberDetailSection;
157 import eu.etaxonomy.taxeditor.ui.section.key.GeographicalScopeDetailSection;
158 import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailElement;
159 import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyDetailSection;
160 import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyNodeDetailElement;
161 import eu.etaxonomy.taxeditor.ui.section.key.PolytomousKeyNodeDetailSection;
162 import eu.etaxonomy.taxeditor.ui.section.key.ScopeRestrictionSection;
163 import eu.etaxonomy.taxeditor.ui.section.key.TaxonomicScopeSection;
164 import eu.etaxonomy.taxeditor.ui.section.media.ImageFileElement;
165 import eu.etaxonomy.taxeditor.ui.section.media.MediaElement;
166 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationElement;
167 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartElement;
168 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationPartSection;
169 import eu.etaxonomy.taxeditor.ui.section.media.MediaRepresentationSection;
170 import eu.etaxonomy.taxeditor.ui.section.media.MediaSection;
171 import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailElement;
172 import eu.etaxonomy.taxeditor.ui.section.name.AuthorshipDetailSection;
173 import eu.etaxonomy.taxeditor.ui.section.name.HybridDetailElement;
174 import eu.etaxonomy.taxeditor.ui.section.name.HybridDetailSection;
175 import eu.etaxonomy.taxeditor.ui.section.name.NameDetailElement;
176 import eu.etaxonomy.taxeditor.ui.section.name.NameDetailSection;
177 import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailElement;
178 import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection;
179 import eu.etaxonomy.taxeditor.ui.section.name.NameTypeDesignationElement;
180 import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusElement;
181 import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusSection;
182 import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailElement;
183 import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
184 import eu.etaxonomy.taxeditor.ui.section.name.ProtologueElement;
185 import eu.etaxonomy.taxeditor.ui.section.name.ProtologueSection;
186 import eu.etaxonomy.taxeditor.ui.section.name.SpecimenTypeDesignationElement;
187 import eu.etaxonomy.taxeditor.ui.section.name.TypeDesignationSection;
188 import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectingAreasDetailSection;
189 import eu.etaxonomy.taxeditor.ui.section.occurrence.CollectionDetailElement;
190 import eu.etaxonomy.taxeditor.ui.section.occurrence.CurrentDeterminationDetailSection;
191 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseDetailElement;
192 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitBaseDetailSection;
193 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitFacadeDetailElement;
194 import eu.etaxonomy.taxeditor.ui.section.occurrence.DerivedUnitFacadeDetailSection;
195 import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailElement;
196 import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationDetailSection;
197 import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationEventDetailElement;
198 import eu.etaxonomy.taxeditor.ui.section.occurrence.DeterminationHistoryDetailSection;
199 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailElement;
200 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldObservationDetailSection;
201 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailElement;
202 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailSection;
203 import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralDetailElement;
204 import eu.etaxonomy.taxeditor.ui.section.occurrence.GeneralDetailSection;
205 import eu.etaxonomy.taxeditor.ui.section.occurrence.NamedAreaDetailElement;
206 import eu.etaxonomy.taxeditor.ui.section.occurrence.SourceCollectionDetailSection;
207 import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailElement;
208 import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailSection;
209 import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailElement;
210 import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailSection;
211 import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailElement;
212 import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailSection;
213 import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationElement;
214 import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationSection;
215 import eu.etaxonomy.taxeditor.ui.section.supplemental.CdmBaseElement;
216 import eu.etaxonomy.taxeditor.ui.section.supplemental.CdmBaseSection;
217 import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditElement;
218 import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditSection;
219 import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionElement;
220 import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionSection;
221 import eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection;
222 import eu.etaxonomy.taxeditor.ui.section.supplemental.IdentifiableSourceElement;
223 import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerElement;
224 import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerSection;
225 import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsElement;
226 import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsSection;
227 import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
228 import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement;
229 import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection;
230 import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement;
231 import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessagesSection;
232 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailElement;
233 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailSection;
234 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailElement;
235 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonRelationshipDetailElement;
236 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonRelationshipDetailSection;
237 import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailElement;
238 import eu.etaxonomy.taxeditor.ui.section.user.GroupsByUserDetailSection;
239 import eu.etaxonomy.taxeditor.ui.section.user.UserDetailElement;
240 import eu.etaxonomy.taxeditor.ui.section.user.UserDetailSection;
241 import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailElement;
242 import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailSection;
243 import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailElement;
244 import eu.etaxonomy.taxeditor.ui.section.vocabulary.DefinedTermDetailSection;
245 import eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailSection;
246 import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailElement;
247 import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailSection;
248 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
249 import eu.etaxonomy.taxeditor.ui.selection.NomenclaturalAuthorTeamSelectionElement;
250 import eu.etaxonomy.taxeditor.ui.selection.TaxonNodeSelectionElement;
251
252 /**
253 * <p>
254 * CdmFormFactory class.
255 * </p>
256 *
257 * @author n.hoffmann
258 * @created Feb 24, 2010
259 * @version 1.0
260 */
261 public class CdmFormFactory extends FormToolkit {
262
263 private BoldFontHolder2 boldFontHolder2;
264 private MouseListener selectionMouseHandler;
265 private FocusListener selectionFocusHandler;
266
267 private final Set selectionListenerList = new HashSet();
268
269 private final List<IPropertyChangeListener> propertyChangeListeners = new ArrayList<IPropertyChangeListener>();
270
271 private final int orientation = Window.getDefaultOrientation();
272 private ISelectionProvider selectionProvider;
273
274 /** Constant <code>EMPTY_SELECTION</code> */
275 public static ISelection EMPTY_SELECTION = new ISelection() {
276 @Override
277 public boolean isEmpty() {
278 return true;
279 }
280 };
281
282 /**
283 *
284 * @author n.hoffmann
285 * @date Jan 25, 2010
286 *
287 */
288 private class SelectionMouseHandler extends MouseAdapter {
289 @Override
290 public void mouseDown(MouseEvent e) {
291 notifySelectionListeners(e);
292 }
293 }
294
295 /**
296 *
297 * @author n.hoffmann
298 * @date Jan 25, 2010
299 *
300 */
301 private class SelectionFocusHandler extends FocusAdapter {
302 @Override
303 public void focusGained(FocusEvent e) {
304 notifySelectionListeners(e);
305 }
306 }
307
308 private void notifySelectionListeners(TypedEvent e) {
309 Event event = new Event();
310 event.widget = e.widget;
311 SelectionEvent selectionEvent = new SelectionEvent(event);
312
313 for (Object listener : selectionListenerList) {
314 ((SelectionListener) listener).widgetSelected(selectionEvent);
315 }
316 }
317
318 /**
319 * <p>
320 * Constructor for CdmFormFactory.
321 * </p>
322 *
323 * @param display
324 * a {@link org.eclipse.swt.widgets.Display} object.
325 * @param selectionProvider
326 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
327 */
328 public CdmFormFactory(Display display, ISelectionProvider selectionProvider) {
329 super(display);
330 this.selectionProvider = selectionProvider;
331 init();
332 }
333
334 /**
335 * <p>
336 * Constructor for CdmFormFactory.
337 * </p>
338 *
339 * @param display
340 * a {@link org.eclipse.swt.widgets.Display} object.
341 */
342 public CdmFormFactory(Display display) {
343 super(display);
344 init();
345 }
346
347 /**
348 *
349 */
350 private void init() {
351 boldFontHolder2 = new BoldFontHolder2();
352 selectionMouseHandler = new SelectionMouseHandler();
353 selectionFocusHandler = new SelectionFocusHandler();
354 }
355
356 /**
357 * Creates an instance initialized with the correct selectionProvider
358 *
359 * Make sure to remove the instance when the entityComposite disposes via
360 * destroySelectionArbitrator(..)
361 *
362 * @param entityElement
363 * a {@link eu.etaxonomy.taxeditor.ui.element.IEntityElement}
364 * object.
365 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
366 * object.
367 */
368 public SelectionArbitrator createSelectionArbitrator(
369 IEntityElement entityElement) {
370 SelectionArbitrator selectionArbitrator = new SelectionArbitrator(
371 entityElement);
372 selectionArbitrator.addSelectionProvider(selectionProvider);
373 selectionProvider.addSelectionChangedListener(selectionArbitrator);
374 addSelectionListener(selectionArbitrator);
375 return selectionArbitrator;
376 }
377
378 /**
379 * <p>
380 * destroySelectionArbitrator
381 * </p>
382 *
383 * @param selectionArbitrator
384 * a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator}
385 * object.
386 */
387 public void destroySelectionArbitrator(
388 SelectionArbitrator selectionArbitrator) {
389 removeSelectionListener(selectionArbitrator);
390 if (selectionProvider != null) {
391 selectionProvider
392 .removeSelectionChangedListener(selectionArbitrator);
393 } else {
394 StoreUtil
395 .error(this.getClass(),
396 "Tried to destroy a selection listener from this factories listeners but was null",
397 null);
398 }
399 }
400
401 /** {@inheritDoc} */
402 @Override
403 public void adapt(Composite composite) {
404 composite.addMouseListener(selectionMouseHandler);
405 super.adapt(composite);
406 }
407
408 /**
409 * <p>
410 * adapt
411 * </p>
412 *
413 * @param formElement
414 * a
415 * {@link eu.etaxonomy.taxeditor.ui.element.AbstractCdmFormElement}
416 * object.
417 */
418 public void adapt(AbstractCdmFormElement formElement) {
419 formElement.setPropertyChangeListeners(propertyChangeListeners);
420 }
421
422 /** {@inheritDoc} */
423 @Override
424 public void adapt(Control control, boolean trackFocus, boolean trackKeyboard) {
425 if (trackFocus) {
426 control.addFocusListener(selectionFocusHandler);
427 }
428 super.adapt(control, trackFocus, trackKeyboard);
429 }
430
431 /**
432 * <p>
433 * destroyElement
434 * </p>
435 *
436 * @param formElement
437 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
438 * object.
439 */
440 public void destroyElement(ICdmFormElement formElement) {
441 // return if element was not initialized
442 if (formElement == null) {
443 return;
444 }
445 // destroy selection arbitrator, if any
446 if (formElement instanceof ISelectableElement) {
447 destroySelectionArbitrator(((ISelectableElement) formElement)
448 .getSelectionArbitrator());
449 }
450 // remove this element form its parents list of elements
451 // ICdmFormElement parentElement = formElement.getParentElement();
452 // if(parentElement != null){
453 // parentElement.removeElement(formElement);
454 // }
455 // call destroy on child elements recursively
456 for (ICdmFormElement childElement : formElement.getElements()) {
457 destroyElement(childElement);
458 }
459 // dispose of the controls
460 for (Control control : formElement.getControls()) {
461 // we added the layoutComposite of the parental element as the
462 // layout composite to this formElement
463 // but we do not want to destroy it.
464 if (control.equals(formElement.getLayoutComposite())) {
465 continue;
466 } else {
467 control.dispose();
468 control = null;
469 }
470 }
471 }
472
473 /**
474 * <p>
475 * createEmptyCell
476 * </p>
477 *
478 * @param parent
479 * a {@link org.eclipse.swt.widgets.Composite} object.
480 * @return a {@link org.eclipse.swt.widgets.Label} object.
481 */
482 public Label createEmptyCell(Composite parent) {
483 return this.createLabel(parent, null);
484 }
485
486 /**
487 * <p>
488 * createMultilineTextWithLabel
489 * </p>
490 *
491 * @param labelString
492 * a {@link java.lang.String} object.
493 * @param textHeight
494 * a int.
495 * @param style
496 * a int.
497 * @param parentElement
498 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
499 * object.
500 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
501 * object.
502 */
503 public TextWithLabelElement createMultilineTextWithLabel(
504 ICdmFormElement parentElement, String labelString, int textHeight,
505 int style) {
506 TextWithLabelElement element = new TextWithLabelElement(this,
507 parentElement, labelString, "", textHeight, style);
508 adapt(element);
509 parentElement.addElement(element);
510 return element;
511 }
512
513 /**
514 * <p>
515 * createMultiLanguageTextElement
516 * </p>
517 *
518 * @param parentElement
519 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
520 * object.
521 * @param labelString
522 * a {@link java.lang.String} object.
523 * @param multilanguageText
524 * a {@link java.util.Map} object.
525 * @param textHeight
526 * a int.
527 * @param style
528 * a int.
529 * @return a
530 * {@link eu.etaxonomy.taxeditor.ui.element.MultilanguageTextElement}
531 * object.
532 */
533 public MultilanguageTextElement createMultiLanguageTextElement(
534 ICdmFormElement parentElement, String labelString,
535 Map<Language, LanguageString> multilanguageText, int textHeight,
536 int style) {
537 MultilanguageTextElement element = new MultilanguageTextElement(this,
538 parentElement, labelString, multilanguageText, textHeight,
539 style);
540 adapt(element);
541 parentElement.addElement(element);
542 return element;
543 }
544
545 public KeyStatementElement createKeyStatementElement(
546 ICdmFormElement parentElement, String labelString,
547 KeyStatement keyStatement, int textHeight, int style) {
548 KeyStatementElement element = new KeyStatementElement(this,
549 parentElement, labelString, keyStatement, textHeight, style);
550 adapt(element);
551 parentElement.addElement(element);
552 return element;
553 }
554
555 /**
556 * <p>
557 * createTextWithLabelElement
558 * </p>
559 *
560 * @param labelString
561 * a {@link java.lang.String} object.
562 * @param initialText
563 * a {@link java.lang.String} object.
564 * @param style
565 * a int.
566 * @param parentElement
567 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
568 * object.
569 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
570 * object.
571 */
572 public TextWithLabelElement createTextWithLabelElement(
573 ICdmFormElement parentElement, String labelString,
574 String initialText, int style) {
575 TextWithLabelElement element = new TextWithLabelElement(this,
576 parentElement, labelString, initialText, null, style);
577 adapt(element);
578 parentElement.addElement(element);
579 return element;
580 }
581
582 public UriWithLabelElement createUriWithLabelElement(
583 ICdmFormElement parentElement, String labelString, URI initialUri,
584 int style) {
585 UriWithLabelElement element = new UriWithLabelElement(this,
586 parentElement, labelString, initialUri, null, style);
587 adapt(element);
588 parentElement.addElement(element);
589 return element;
590 }
591
592 /**
593 * @param element
594 * @param string
595 * @param uri
596 * @param style
597 * @return
598 */
599 public OpenUrlSelectorElement createOpenUrlSelectorElement(
600 ICdmFormElement parentElement, String labelString,
601 IOpenUrlEnabled openUrlEnabled, int style) {
602 OpenUrlSelectorElement element = new OpenUrlSelectorElement(this,
603 parentElement, labelString, openUrlEnabled, style);
604 adapt(element);
605 parentElement.addElement(element);
606 return element;
607 }
608
609 /**
610 *
611 * @param parentElement
612 * @param labelString
613 * @param conversationEnabled
614 * @param user
615 * @param style
616 * @return
617 */
618 public EditPasswordElement createEditPasswordElement(
619 ICdmFormElement parentElement, String labelString,
620 ConversationHolder conversation, User user, int style) {
621 EditPasswordElement element = new EditPasswordElement(this,
622 parentElement, labelString, user, conversation);
623 adapt(element);
624 parentElement.addElement(element);
625 return element;
626 }
627
628 /**
629 * <p>
630 * createIntegerTextWithLabelElement
631 * </p>
632 *
633 * @param parentElement
634 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
635 * object.
636 * @param labelString
637 * a {@link java.lang.String} object.
638 * @param initialInteger
639 * a {@link java.lang.Integer} object.
640 * @param style
641 * a int.
642 * @return a {@link eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement}
643 * object.
644 */
645 public NumberWithLabelElement createNumberTextWithLabelElement(
646 ICdmFormElement parentElement, String labelString,
647 Number initialNumber, int style) {
648 NumberWithLabelElement element = new NumberWithLabelElement(this,
649 parentElement, labelString, initialNumber, style);
650 adapt(element);
651 parentElement.addElement(element);
652 return element;
653 }
654
655
656 /**
657 * <p>
658 * createLanguageStringWithLabelElement
659 * </p>
660 *
661 * @param parentElement
662 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
663 * object.
664 * @param labelString
665 * a {@link java.lang.String} object.
666 * @param languageString
667 * a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
668 * @param style
669 * a int.
670 * @return a
671 * {@link eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement}
672 * object.
673 */
674 public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
675 ICdmFormElement parentElement, String labelString,
676 LanguageString languageString, int style) {
677 LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
678 this, parentElement, labelString, languageString, style);
679 adapt(element);
680 parentElement.addElement(element);
681 return element;
682 }
683
684 /**
685 * <p>
686 * createLanguageStringWithLabelElement
687 * </p>
688 *
689 * @param parentElement
690 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
691 * object.
692 * @param labelString
693 * a {@link java.lang.String} object.
694 * @param languageString
695 * a {@link eu.etaxonomy.cdm.model.common.LanguageString} object.
696 * @param height
697 * a int.
698 * @param style
699 * a int.
700 * @return a
701 * {@link eu.etaxonomy.taxeditor.ui.element.LanguageStringWithLabelElement}
702 * object.
703 */
704 public LanguageStringWithLabelElement createLanguageStringWithLabelElement(
705 ICdmFormElement parentElement, String labelString,
706 LanguageString languageString, int height, int style) {
707 LanguageStringWithLabelElement element = new LanguageStringWithLabelElement(
708 this, parentElement, labelString, languageString, height, style);
709 adapt(element);
710 parentElement.addElement(element);
711 return element;
712 }
713
714 /**
715 * <p>
716 * createTextElement
717 * </p>
718 *
719 * @param parentElement
720 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
721 * object.
722 * @param initialText
723 * a {@link java.lang.String} object.
724 * @param style
725 * a int.
726 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement}
727 * object.
728 */
729 public TextWithLabelElement createTextElement(
730 ICdmFormElement parentElement, String initialText, int style) {
731 TextWithLabelElement element = new TextWithLabelElement(this,
732 parentElement, null, initialText, null, style);
733 adapt(element);
734 parentElement.addElement(element);
735 return element;
736 }
737
738 /**
739 * <p>
740 * createKeyValueViewerElement
741 * </p>
742 *
743 * @param parentElement
744 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
745 * object.
746 * @param keyHeading
747 * a {@link java.lang.String} object.
748 * @param valueHeading
749 * a {@link java.lang.String} object.
750 * @param map
751 * a {@link java.util.Map} object.
752 * @return a {@link eu.etaxonomy.taxeditor.ui.element.KeyValueViewerElement}
753 * object.
754 */
755 public KeyValueViewerElement createKeyValueViewerElement(
756 ICdmFormElement parentElement, String keyHeading,
757 String valueHeading, Map<Object, Object> map) {
758 KeyValueViewerElement element = new KeyValueViewerElement(this,
759 parentElement, keyHeading, valueHeading, map);
760 adapt(element);
761 parentElement.addElement(element);
762 return element;
763 }
764
765 /**
766 * <p>
767 * createTermComboElement
768 * </p>
769 *
770 * @param termComboType
771 * a
772 * {@link eu.eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.TermComboType}
773 * object.
774 * @param parentElement
775 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
776 * object.
777 * @param labelString
778 * a {@link java.lang.String} object.
779 * @param selection
780 * a {@link eu.etaxonomy.cdm.model.common.DefinedTermBase}
781 * object.
782 * @param style
783 * a int.
784 * @return a {@link eu.etaxonomy.taxeditor.ui.combo.TermComboElement}
785 * object.
786 */
787
788 public <T extends DefinedTermBase> TermComboElement<T> createTermComboElement(
789 Class<T> termComboType, ICdmFormElement parentElement,
790 String labelString, T selection, int style) {
791 TermComboElement<T> element = new TermComboElement<T>(this, parentElement, termComboType, labelString, selection, style);
792 adapt(element);
793 parentElement.addElement(element);
794 return element;
795 }
796
797 /**
798 * <p>
799 * createEnumComboElement
800 * </p>
801 *
802 * @param enumComboType
803 * a
804 * {@link eu.eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EnumComboType}
805 * object.
806 * @param parentElement
807 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
808 * object.
809 * @param style
810 * a int.
811 * @return a {@link eu.etaxonomy.taxeditor.ui.term.AbstractEnumComboElement}
812 * object.
813 */
814 public <T extends IDefinedTerm> EnumComboElement<T> createEnumComboElement(
815 Class<T> enumComboType, ICdmFormElement parentElement,
816 int style) {
817 EnumComboElement<T> element = new EnumComboElement<T>(this, parentElement, enumComboType, style);
818 adapt(element);
819 parentElement.addElement(element);
820 return element;
821 }
822
823 /**
824 * <p>
825 * createBrowserElement
826 * </p>
827 *
828 * @param imageUri
829 * a {@link java.net.URI} object.
830 * @param style
831 * a int.
832 * @param parentElement
833 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
834 * object.
835 * @return a {@link eu.etaxonomy.taxeditor.ui.element.BrowserElement} object.
836 */
837 public BrowserElement createBrowserElement(ICdmFormElement parentElement,
838 URI imageUri, int style) {
839 BrowserElement element = new BrowserElement(this, parentElement,
840 imageUri, style);
841 adapt(element);
842 parentElement.addElement(element);
843 return element;
844 }
845
846 /**
847 * <p>
848 * createImageElement
849 * </p>
850 *
851 * @param parentElement
852 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
853 * object.
854 * @param imageUri
855 * a {@link java.net.URI} object.
856 * @param style
857 * a int.
858 * @return a {@link eu.etaxonomy.taxeditor.ui.element.ImageElement} object.
859 */
860 public ImageElement createImageElement(ICdmFormElement parentElement,
861 URI imageUri, int style) {
862 ImageElement element = new ImageElement(this, parentElement, imageUri,
863 style);
864 adapt(element);
865 parentElement.addElement(element);
866 return element;
867 }
868
869 /**
870 * <p>
871 * createTextActionElement
872 * </p>
873 *
874 * @param labelString
875 * a {@link java.lang.String} object.
876 * @param initialText
877 * a {@link java.lang.String} object.
878 * @param style
879 * a int.
880 * @param parentElement
881 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
882 * object.
883 * @param buttonLabel
884 * a {@link java.lang.String} object.
885 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TextActionElement}
886 * object.
887 */
888 public TextActionElement createTextActionElement(
889 ICdmFormElement parentElement, String labelString,
890 String buttonLabel, String initialText, int style) {
891 TextActionElement element = new TextActionElement(this, parentElement,
892 labelString, buttonLabel, initialText, style);
893 adapt(element);
894 parentElement.addElement(element);
895 return element;
896 }
897
898 /**
899 * <p>
900 * createCheckbox
901 * </p>
902 *
903 * @param parentElement
904 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
905 * object.
906 * @param label
907 * a {@link java.lang.String} object.
908 * @param initialState
909 * a boolean.
910 * @param style
911 * a int.
912 * @return a {@link eu.etaxonomy.taxeditor.ui.element.CheckboxElement} object.
913 */
914 public CheckboxElement createCheckbox(ICdmFormElement parentElement,
915 String label, boolean initialState, int style) {
916 CheckboxElement element = new CheckboxElement(this, parentElement,
917 label, initialState, style | orientation);
918 adapt(element);
919 parentElement.addElement(element);
920 return element;
921 }
922
923 /**
924 * Creates a section as a part of the form.
925 *
926 * @return the section widget
927 * @param section
928 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
929 * object.
930 */
931 public Section adapt(AbstractFormSection section) {
932 section.setMenu(section.getLayoutComposite().getMenu());
933 adapt(section, true, true);
934
935 // handle focus and property change events for cdm use
936 section.addFocusListener(selectionFocusHandler);
937 section.setPropertyChangeListeners(propertyChangeListeners);
938
939 if (section.getToggle() != null) {
940 section.getToggle().setHoverDecorationColor(
941 getColors().getColor(IFormColors.TB_TOGGLE_HOVER));
942 section.getToggle().setDecorationColor(
943 getColors().getColor(IFormColors.TB_TOGGLE));
944 }
945
946 section.setFont(boldFontHolder2.getBoldFont(section
947 .getLayoutComposite().getFont()));
948
949 if ((section.getStyle() & Section.TITLE_BAR) != 0
950 || (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
951 getColors().initializeSectionToolBarColors();
952 section.setTitleBarBackground(getColors().getColor(
953 IFormColors.TB_BG));
954 section.setTitleBarBorderColor(getColors().getColor(
955 IFormColors.TB_BORDER));
956 }
957 // call setTitleBarForeground regardless as it also sets the label color
958 section.setTitleBarForeground(getColors().getColor(
959 IFormColors.TB_TOGGLE));
960 return section;
961 }
962
963 private class BoldFontHolder2 {
964 private Font normalFont;
965
966 private Font boldFont;
967
968 public BoldFontHolder2() {
969 }
970
971 public Font getBoldFont(Font font) {
972 createBoldFont(font);
973 return boldFont;
974 }
975
976 private void createBoldFont(Font font) {
977 if (normalFont == null || !normalFont.equals(font)) {
978 normalFont = font;
979 dispose();
980 }
981 if (boldFont == null) {
982 boldFont = FormFonts.getInstance().getBoldFont(
983 getColors().getDisplay(), normalFont);
984 }
985 }
986
987 public void dispose() {
988 if (boldFont != null) {
989 FormFonts.getInstance().markFinished(boldFont,
990 getColors().getDisplay());
991 boldFont = null;
992 }
993 }
994 }
995
996 /**
997 * <p>
998 * createToggleableTextField
999 * </p>
1000 *
1001 * @param parentElement
1002 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1003 * object.
1004 * @param labelString
1005 * a {@link java.lang.String} object.
1006 * @param initialText
1007 * a {@link java.lang.String} object.
1008 * @param initialState
1009 * a boolean.
1010 * @param style
1011 * a int.
1012 * @return a {@link eu.etaxonomy.taxeditor.ui.element.ToggleableTextElement}
1013 * object.
1014 */
1015 public ToggleableTextElement createToggleableTextField(
1016 ICdmFormElement parentElement, String labelString,
1017 String initialText, boolean initialState, int style) {
1018 ToggleableTextElement element = new ToggleableTextElement(this,
1019 parentElement, labelString, initialText, initialState, style
1020 | orientation);
1021 adapt(element);
1022 parentElement.addElement(element);
1023 return element;
1024 }
1025
1026 /**
1027 * <p>
1028 * createTimePeriodElement
1029 * </p>
1030 *
1031 * @param parentElement
1032 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1033 * object.
1034 * @param labelString
1035 * a {@link java.lang.String} object.
1036 * @param timePeriod
1037 * a {@link eu.etaxonomy.cdm.model.common.TimePeriod} object.
1038 * @param style
1039 * a int.
1040 * @return a {@link eu.etaxonomy.taxeditor.ui.element.TimePeriodElement}
1041 * object.
1042 */
1043 public TimePeriodElement createTimePeriodElement(
1044 ICdmFormElement parentElement, String labelString,
1045 TimePeriod timePeriod, int style) {
1046 TimePeriodElement element = new TimePeriodElement(this, parentElement,
1047 labelString, timePeriod, style);
1048 adapt(element);
1049 parentElement.addElement(element);
1050 return element;
1051 }
1052
1053 /**
1054 * <p>
1055 * createPointElement
1056 * </p>
1057 *
1058 * @param style
1059 * a int.
1060 * @param parentElement
1061 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1062 * object.
1063 * @param point
1064 * a {@link eu.etaxonomy.cdm.model.location.Point} object.
1065 * @return a {@link eu.etaxonomy.taxeditor.ui.element.PointElement} object.
1066 */
1067 public PointElement createPointElement(ICdmFormElement parentElement,
1068 Point point, int style) {
1069 PointElement element = new PointElement(this, parentElement, point,
1070 style);
1071 adapt(element);
1072 parentElement.addElement(element);
1073 return element;
1074 }
1075
1076 /**
1077 * <p>
1078 * createDateDetailSection
1079 * </p>
1080 *
1081 * @param parentElement
1082 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1083 * object.
1084 * @param style
1085 * a int.
1086 * @return a {@link eu.etaxonomy.taxeditor.ui.element.DateDetailSection}
1087 * object.
1088 */
1089 public DateDetailSection createDateDetailSection(
1090 ICdmFormElement parentElement, int style) {
1091 DateDetailSection section = new DateDetailSection(this, parentElement,
1092 style);
1093 parentElement.addElement(section);
1094 adapt(section);
1095 return section;
1096 }
1097
1098 /**
1099 * <p>
1100 * createPartialElement
1101 * </p>
1102 *
1103 * @param parentElement
1104 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1105 * object.
1106 * @param labelString
1107 * a {@link java.lang.String} object.
1108 * @param partial
1109 * a {@link org.joda.time.Partial} object.
1110 * @param style
1111 * a int.
1112 * @return a {@link eu.etaxonomy.taxeditor.ui.element.PartialElement} object.
1113 */
1114 public PartialElement createPartialElement(ICdmFormElement parentElement,
1115 String labelString, Partial partial, int style) {
1116 PartialElement element = new PartialElement(this, parentElement,
1117 labelString, style);
1118 adapt(element);
1119 parentElement.addElement(element);
1120 return element;
1121 }
1122
1123 /**
1124 * <p>
1125 * addSelectionListener
1126 * </p>
1127 *
1128 * @param listener
1129 * a {@link org.eclipse.swt.events.SelectionListener} object.
1130 */
1131 public void addSelectionListener(SelectionListener listener) {
1132 selectionListenerList.add(listener);
1133 }
1134
1135 /**
1136 * <p>
1137 * removeSelectionListener
1138 * </p>
1139 *
1140 * @param listener
1141 * a {@link org.eclipse.swt.events.SelectionListener} object.
1142 */
1143 public void removeSelectionListener(SelectionListener listener) {
1144 if (listener == null) {
1145 StoreUtil
1146 .error(this.getClass(),
1147 "Tried to remove a selection listener from this factories listeners but was null",
1148 null);
1149 } else {
1150 selectionListenerList.remove(listener);
1151 }
1152 }
1153
1154 /**
1155 * <p>
1156 * addPropertyChangeListener
1157 * </p>
1158 *
1159 * @param listener
1160 * a {@link org.eclipse.jface.util.IPropertyChangeListener}
1161 * object.
1162 */
1163 public void addPropertyChangeListener(IPropertyChangeListener listener) {
1164 if(propertyChangeListeners.contains(listener)){
1165 return;
1166 }
1167 propertyChangeListeners.add(0, listener);
1168 }
1169
1170 /**
1171 * <p>
1172 * removePropertyChangeListener
1173 * </p>
1174 *
1175 * @param listener
1176 * a {@link org.eclipse.jface.util.IPropertyChangeListener}
1177 * object.
1178 */
1179 public void removePropertyChangeListener(IPropertyChangeListener listener) {
1180 propertyChangeListeners.remove(listener);
1181 }
1182
1183 /**
1184 * <p>
1185 * createHorizontalSeparator
1186 * </p>
1187 *
1188 * @param parentElement
1189 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1190 * object.
1191 * @param style
1192 * a int.
1193 * @return a {@link org.eclipse.swt.widgets.Label} object.
1194 */
1195 public Label createHorizontalSeparator(ICdmFormElement parentElement,
1196 int style) {
1197 Label separator = this.createSeparator(
1198 parentElement.getLayoutComposite(), SWT.HORIZONTAL | style);
1199 separator.setLayoutData(LayoutConstants.FILL_HORIZONTALLY());
1200 return separator;
1201 }
1202
1203 /**
1204 * <p>
1205 * createVersionElement
1206 * </p>
1207 *
1208 * @param parentElement
1209 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1210 * object.
1211 * @param entity
1212 * a {@link eu.etaxonomy.cdm.model.common.VersionableEntity}
1213 * object.
1214 * @param style
1215 * a int.
1216 * @return a
1217 * {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionElement}
1218 * object.
1219 */
1220 public VersionElement createVersionElement(ICdmFormElement parentElement,
1221 VersionableEntity entity, int style) {
1222 VersionElement element = new VersionElement(this, parentElement,
1223 entity, style);
1224 adapt(element);
1225 parentElement.addElement(element);
1226 return element;
1227 }
1228
1229 /**
1230 * @param cdmBaseSection
1231 * @param object
1232 * @param style
1233 * @return
1234 */
1235 public CdmBaseElement createCdmBaseElement(ICdmFormElement parentElement,
1236 CdmBase entity, int style) {
1237 CdmBaseElement element = new CdmBaseElement(this, parentElement,
1238 entity, style);
1239 adapt(element);
1240 parentElement.addElement(element);
1241 return element;
1242 }
1243
1244
1245 /**
1246 * <p>
1247 * createVersionSection
1248 * </p>
1249 *
1250 * @param parentElement
1251 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1252 * object.
1253 * @param style
1254 * a int.
1255 * @return a
1256 * {@link eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection}
1257 * object.
1258 */
1259 public VersionSection createVersionSection(ICdmFormElement parentElement,
1260 int style) {
1261 VersionSection section = new VersionSection(this, parentElement, style);
1262 parentElement.addElement(section);
1263 adapt(section);
1264 return section;
1265 }
1266
1267 /**
1268 * @param parent
1269 * @param i
1270 * @return
1271 */
1272 public CdmBaseSection createCdmBaseSection(ICdmFormElement parentElement, int style) {
1273 CdmBaseSection section = new CdmBaseSection(this, parentElement, style);
1274 parentElement.addElement(section);
1275 adapt(section);
1276 return section;
1277 }
1278
1279 /**
1280 * <p>
1281 * createEmptyElement
1282 * </p>
1283 *
1284 * @param parentElement
1285 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1286 * object.
1287 * @return a {@link eu.etaxonomy.taxeditor.ui.section.EmptyElement} object.
1288 */
1289 public EmptyElement createEmptyElement(ICdmFormElement parentElement) {
1290 EmptyElement element = new EmptyElement(this, parentElement, null,
1291 SWT.NULL);
1292 adapt(element);
1293 parentElement.addElement(element);
1294 return element;
1295 }
1296
1297 /**
1298 * <p>
1299 * createHeadlineSection
1300 * </p>
1301 *
1302 * @param parentElement
1303 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1304 * object.
1305 * @return a
1306 * {@link eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection}
1307 * object.
1308 */
1309 public HeadlineSection createHeadlineSection(ICdmFormElement parentElement) {
1310 HeadlineSection section = new HeadlineSection(this, parentElement,
1311 SWT.NULL);
1312 parentElement.addElement(section);
1313 adapt(section);
1314 return section;
1315 }
1316
1317 /**
1318 * <p>
1319 * createParsingMessageElement
1320 * </p>
1321 *
1322 * @param parentElement
1323 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1324 * object.
1325 * @param parserProblem
1326 * a {@link eu.etaxonomy.cdm.strategy.parser.ParserProblem}
1327 * object.
1328 * @param style
1329 * a int.
1330 * @return a
1331 * {@link eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessageElement}
1332 * object.
1333 */
1334 public ParsingMessageElement createParsingMessageElement(
1335 ICdmFormElement parentElement, ParserProblem parserProblem,
1336 int style) {
1337 ParsingMessageElement element = new ParsingMessageElement(this,
1338 parentElement, parserProblem, style);
1339 adapt(element);
1340 parentElement.addElement(element);
1341 return element;
1342 }
1343
1344 // SIMPLIFY
1345
1346 /**
1347 *
1348 */
1349 public static enum DetailType {
1350 AUTHORSHIP,
1351 CLASSIFICATION,
1352 COLLECTION,
1353 DERIVED_UNIT,
1354 DERIVED_UNIT_FACADE,
1355 DERIVED_UNIT_GENERAL,
1356 DESCRIPTION,
1357 DESCRIPTIONELEMENT,
1358 DETERMINATION,
1359 FEATURE_DISTRIBUTION,
1360 FIELD_OBSERVATION,
1361 GATHERING_EVENT,
1362 GRANTEDAUTHORITY,
1363 GROUP,
1364 HYBRID,
1365 INSTITUTION,
1366 MEDIA,
1367 NAMED_AREA,
1368 NAMED_AREA_LEVEL,
1369 NAMERELATIONSHIP,
1370 NATURAL_LANGUAGE,
1371 NOMENCLATURALREFERENCE,
1372 NONVIRALNAME,
1373 PARSINGMESSAGE,
1374 PERSON,
1375 POLYTOMOUS_KEY,
1376 POLYTOMOUS_KEY_NODE,
1377 REFERENCEBASE,
1378 REFERENCED_ENTITY,
1379 SCIENTIFICNAME,
1380 TAXON_NODE,
1381 TAXON_RELATIONSHIP,
1382 TAXONBASE,
1383 TEAM,
1384 TEAMORPERSONBASE,
1385 TERM_VOCABULARY,
1386 USE_RECORD,
1387 USER
1388 }
1389
1390 public AbstractFormSection createDefinedTermDetailSection(Class definedTermClass,
1391 ConversationHolder conversation, ICdmFormElement parentElement,
1392 ISelectionProvider selectionProvider, int style) {
1393
1394 AbstractFormSection section = new DefinedTermDetailSection(this, definedTermClass, conversation, parentElement, selectionProvider, style);
1395
1396 parentElement.addElement(section);
1397 adapt(section);
1398 return section;
1399
1400 }
1401
1402 /**
1403 * @param definedTermClass
1404 * @param formElement
1405 * @param style
1406 * @return
1407 */
1408 public AbstractCdmDetailElement createDefinedTermDetailElement(
1409 Class definedTermClass, AbstractCdmDetailSection parentElement,
1410 int style) {
1411 AbstractCdmDetailElement element = null;
1412
1413 if (NamedArea.class.isAssignableFrom(definedTermClass)){
1414 element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1415 }
1416 else {
1417 element = new DefinedTermDetailElement(this, parentElement);
1418 }
1419
1420 adapt(element);
1421 parentElement.addElement(element);
1422 return element;
1423 }
1424
1425 /**
1426 * <p>
1427 * createCdmDetailSection
1428 * </p>
1429 *
1430 * @param detailType
1431 * a
1432 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
1433 * object.
1434 * @param parentElement
1435 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1436 * object.
1437 * @param selectionProvider
1438 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1439 * @param style
1440 * a int.
1441 * @param conversation
1442 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1443 * object.
1444 * @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1445 * object.
1446 */
1447 public AbstractFormSection createCdmDetailSection(DetailType detailType,
1448 ConversationHolder conversation, ICdmFormElement parentElement,
1449 ISelectionProvider selectionProvider, int style) {
1450 AbstractFormSection section = null;
1451
1452 switch (detailType) {
1453 case SCIENTIFICNAME:
1454 section = new NameDetailSection(this, conversation, parentElement,
1455 selectionProvider, style);
1456 break;
1457 case REFERENCEBASE:
1458 section = new ReferenceDetailSection(this, conversation,
1459 parentElement, selectionProvider, style);
1460 break;
1461 case NOMENCLATURALREFERENCE:
1462 section = new NomenclaturalReferenceDetailSection(this,
1463 conversation, parentElement, selectionProvider, style);
1464 break;
1465 case TAXONBASE:
1466 section = new TaxonBaseDetailSection(this, conversation,
1467 parentElement, selectionProvider, style);
1468 break;
1469 case AUTHORSHIP:
1470 section = new AuthorshipDetailSection(this, conversation,
1471 parentElement, selectionProvider, style);
1472 break;
1473 case TEAMORPERSONBASE:
1474 section = new TeamOrPersonBaseDetailSection(this, conversation,
1475 parentElement, selectionProvider, style);
1476 break;
1477 case TEAM:
1478 section = new TeamDetailSection(this, conversation, parentElement,
1479 null, style);
1480 break;
1481 case PERSON:
1482 section = new PersonDetailSection(this, conversation,
1483 parentElement, null, style);
1484 break;
1485 case DESCRIPTION:
1486 section = new DescriptionDetailSection(this, conversation,
1487 parentElement, selectionProvider, style);
1488 break;
1489 case DESCRIPTIONELEMENT:
1490 section = new DescriptionElementDetailSection(this, conversation,
1491 parentElement, selectionProvider, style);
1492 break;
1493 case PARSINGMESSAGE:
1494 section = new ParsingMessagesSection(this, conversation,
1495 parentElement, selectionProvider, style);
1496 break;
1497 case NONVIRALNAME:
1498 section = new NonViralNameDetailSection(this, conversation,
1499 parentElement, selectionProvider, style);
1500 break;
1501 case MEDIA:
1502 section = new eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection(
1503 this, conversation, parentElement, selectionProvider, style);
1504 break;
1505 case DERIVED_UNIT_FACADE:
1506 section = new DerivedUnitFacadeDetailSection(this, conversation,
1507 parentElement, selectionProvider, style);
1508 break;
1509 case FIELD_OBSERVATION:
1510 section = new FieldObservationDetailSection(this, conversation,
1511 parentElement, selectionProvider, style);
1512 break;
1513 case GATHERING_EVENT:
1514 section = new GatheringEventDetailSection(this, conversation,
1515 parentElement, selectionProvider, style);
1516 break;
1517 case DERIVED_UNIT:
1518 section = new DerivedUnitBaseDetailSection(this, conversation,
1519 parentElement, selectionProvider, style);
1520 break;
1521 case NATURAL_LANGUAGE:
1522 section = new NaturalLanguageSection(this, conversation,
1523 parentElement, selectionProvider, style);
1524 break;
1525 case FEATURE_DISTRIBUTION:
1526 section = new FeatureDistributionDetailSection(this, conversation,
1527 parentElement, selectionProvider, style);
1528 break;
1529 case CLASSIFICATION:
1530 section = new ClassificationDetailSection(this, conversation,
1531 parentElement, selectionProvider, style);
1532 break;
1533 case TAXON_NODE:
1534 section = new TaxonNodeDetailSection(this, conversation,
1535 parentElement, selectionProvider, style);
1536 break;
1537 case POLYTOMOUS_KEY:
1538 section = new PolytomousKeyDetailSection(this, conversation,
1539 parentElement, selectionProvider, style);
1540 break;
1541 case POLYTOMOUS_KEY_NODE:
1542 section = new PolytomousKeyNodeDetailSection(this, conversation,
1543 parentElement, selectionProvider, style);
1544 break;
1545 case INSTITUTION:
1546 section = new InstitutionDetailSection(this, conversation,
1547 parentElement, selectionProvider, style);
1548 break;
1549 case DERIVED_UNIT_GENERAL:
1550 section = new GeneralDetailSection(this, conversation,
1551 parentElement, selectionProvider, style);
1552 break;
1553 case HYBRID:
1554 section = new HybridDetailSection(this, conversation,
1555 parentElement, selectionProvider, style);
1556 break;
1557 case USER:
1558 section = new UserDetailSection(this, conversation, parentElement,
1559 selectionProvider, style);
1560 break;
1561 case GROUP:
1562 section = new GroupDetailSection(this, conversation, parentElement,
1563 selectionProvider, style);
1564 break;
1565 case DETERMINATION:
1566 section = new DeterminationDetailSection(this, conversation, parentElement,
1567 selectionProvider, style);
1568 break;
1569 case TAXON_RELATIONSHIP:
1570 section = new TaxonRelationshipDetailSection(this, conversation, parentElement,
1571 selectionProvider, style);
1572 break;
1573 case REFERENCED_ENTITY:
1574 section = new ReferencedEntityDetailSection(this, conversation, parentElement,
1575 selectionProvider, style);
1576 break;
1577 case TERM_VOCABULARY:
1578 section = new TermVocabularyDetailSection(this, conversation, parentElement,
1579 selectionProvider, style);
1580 break;
1581 case NAMED_AREA:
1582 section = new NamedAreaDetailSection(this, conversation, parentElement,
1583 selectionProvider, style);
1584 break;
1585 case USE_RECORD:
1586 section = new UseRecordDetailSection(this, conversation, parentElement,
1587 selectionProvider, style);
1588 break;
1589 }
1590
1591
1592 if (section == null) {
1593 throw new RuntimeException(
1594 "You tried to create a cdm detail section that is not implemented yet.");
1595 }
1596
1597 parentElement.addElement(section);
1598 adapt(section);
1599 return section;
1600 }
1601
1602
1603
1604 /**
1605 * <p>
1606 * createCdmDetailElement
1607 * </p>
1608 *
1609 * @param detailType
1610 * a
1611 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
1612 * object.
1613 * @param style
1614 * a int.
1615 * @param parentElement
1616 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1617 * object.
1618 * @return a
1619 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
1620 * object.
1621 */
1622 public AbstractCdmDetailElement createCdmDetailElement(
1623 DetailType detailType, ICdmFormElement parentElement, int style) {
1624 AbstractCdmDetailElement element = null;
1625
1626 switch (detailType) {
1627 case SCIENTIFICNAME:
1628 element = new NameDetailElement(this, parentElement, style);
1629 break;
1630 case REFERENCEBASE:
1631 element = new ReferenceDetailElement(this, parentElement, style);
1632 break;
1633 case NOMENCLATURALREFERENCE:
1634 element = new NomenclaturalReferenceDetailElement(this,
1635 parentElement, style);
1636 break;
1637 case TAXONBASE:
1638 element = new TaxonBaseDetailElement(this, parentElement, style);
1639 break;
1640 case AUTHORSHIP:
1641 element = new AuthorshipDetailElement(this, parentElement, style);
1642 break;
1643 case TEAM:
1644 element = new TeamDetailElement(this, parentElement, style);
1645 break;
1646 case PERSON:
1647 element = new PersonDetailElement(this, parentElement, style);
1648 break;
1649 case DESCRIPTION:
1650 element = new DescriptionDetailElement(this, parentElement, style);
1651 break;
1652 case DESCRIPTIONELEMENT:
1653 element = new DescriptionElementDetailElement(this, parentElement,
1654 style);
1655 break;
1656 case NONVIRALNAME:
1657 element = new NonViralNameDetailElement(this, parentElement);
1658 break;
1659 case DERIVED_UNIT_FACADE:
1660 element = new DerivedUnitFacadeDetailElement(this, parentElement);
1661 break;
1662 case FIELD_OBSERVATION:
1663 element = new FieldObservationDetailElement(this, parentElement);
1664 break;
1665 case GATHERING_EVENT:
1666 element = new GatheringEventDetailElement(this, parentElement);
1667 break;
1668 case DERIVED_UNIT:
1669 element = new DerivedUnitBaseDetailElement(this, parentElement);
1670 break;
1671 case NATURAL_LANGUAGE:
1672 element = new NaturalLanguageDetailElement(this, parentElement);
1673 break;
1674 case FEATURE_DISTRIBUTION:
1675 element = new FeatureDistributionDetailElement(this, parentElement);
1676 break;
1677 case CLASSIFICATION:
1678 element = new ClassificationDetailElement(this, parentElement);
1679 break;
1680 case TAXON_NODE:
1681 element = new TaxonNodeDetailElement(this, parentElement);
1682 break;
1683 case COLLECTION:
1684 element = new CollectionDetailElement(this, parentElement);
1685 break;
1686 case POLYTOMOUS_KEY:
1687 element = new PolytomousKeyDetailElement(this, parentElement);
1688 break;
1689 case POLYTOMOUS_KEY_NODE:
1690 element = new PolytomousKeyNodeDetailElement(this, parentElement);
1691 break;
1692 case INSTITUTION:
1693 element = new InstitutionDetailElement(this, parentElement);
1694 break;
1695 case DERIVED_UNIT_GENERAL:
1696 element = new GeneralDetailElement(this, parentElement);
1697 break;
1698 case HYBRID:
1699 element = new HybridDetailElement(this, parentElement);
1700 break;
1701 case USER:
1702 element = new UserDetailElement(this, parentElement);
1703 break;
1704 case GROUP:
1705 element = new GroupDetailElement(this, parentElement);
1706 break;
1707 case GRANTEDAUTHORITY:
1708 element = new GrantedAuthorityDetailElement(this, parentElement);
1709 break;
1710 case DETERMINATION:
1711 element = new DeterminationDetailElement(this, parentElement);
1712 break;
1713 case TAXON_RELATIONSHIP:
1714 element = new TaxonRelationshipDetailElement(this, parentElement);
1715 break;
1716 case REFERENCED_ENTITY:
1717 element = new RefereneEntityDetailElement(this, parentElement);
1718 break;
1719 case TERM_VOCABULARY:
1720 element = new TermVocabularyDetailElement(this, parentElement);
1721 break;
1722 case NAMED_AREA:
1723 element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1724 break;
1725 case NAMED_AREA_LEVEL:
1726 element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
1727 break;
1728 case USE_RECORD:
1729 //element = new UseRecordDetailElement(this, parentElement, style);
1730 element = new UseRecordDetailElement(this, parentElement);
1731 break;
1732 }
1733
1734 if (element == null) {
1735 StoreUtil
1736 .error(this.getClass(),
1737 "Detail element was not created. Seems like the case was not implemented for the requested detail type: "
1738 + detailType, null);
1739 }
1740
1741 adapt(element);
1742 parentElement.addElement(element);
1743 return element;
1744 }
1745
1746 /**
1747 *
1748 * @author n.hoffmann
1749 * @created Mar 5, 2010
1750 * @version 1.0
1751 */
1752 public static enum EntityDetailType {
1753 TEAM,
1754 TEAMMEMBER,
1755 ANNOTATION,
1756 CREDIT,
1757 DESCRIPTIONELEMENTSOURCE,
1758 EXTENSION,
1759 MARKER,
1760 MEDIA,
1761 DESCRIPTIONELEMENTMEDIA,
1762 MEDIAREPRESENTATION,
1763 MEDIAREPRESENTATIONPART,
1764 MODIFIER,
1765 NOMENCLATURALSTATUS,
1766 NAME_RELATIONSHIP,
1767 PROTOLOG,
1768 RIGHTS,
1769 SOURCE,
1770 SCOPE,
1771 DESCRIPTIONSOURCE,
1772 TYPEDESIGNATION,
1773 STATE_DATA,
1774 STATISTICAL_MEASUREMENT_VALUE,
1775 DESCRIBED_SPECIMEN,
1776 COLLECTING_AREA,
1777 DETERMINATION_EVENT,
1778 SPECIMEN_COLLECTION,
1779 IDENTIFIABLE_SOURCE_COLLECTION,
1780 GEOGRAPHICAL_SCOPE,
1781 SCOPE_RESTRICTION,
1782 MEMBER,
1783 GRANTED_AUTHORITY,
1784 GROUPS_BY_USER,
1785 TAXONOMIC_SCOPE,
1786 DETERMINATION_CURRENT,
1787 DETERMINATION_HISTORY
1788 }
1789
1790 /**
1791 * <p>
1792 * createEntityDetailSection
1793 * </p>
1794 *
1795 * @param entityDetailType
1796 * a
1797 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType}
1798 * object.
1799 * @param style
1800 * a int.
1801 * @param conversation
1802 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1803 * object.
1804 * @param parentElement
1805 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1806 * object.
1807 * @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1808 * object.
1809 */
1810 public AbstractFormSection createEntityDetailSection(
1811 EntityDetailType entityDetailType, ConversationHolder conversation,
1812 ICdmFormElement parentElement, int style) {
1813 AbstractFormSection section = null;
1814
1815 switch (entityDetailType) {
1816 case TEAM:
1817 section = new TeamDetailSection(this, conversation, parentElement,
1818 null, style);
1819 break;
1820 case TEAMMEMBER:
1821 section = new TeamMemberSection(this, conversation, parentElement,
1822 style);
1823 break;
1824 case ANNOTATION:
1825 section = new AnnotationSection(this, conversation, parentElement,
1826 style);
1827 break;
1828 case CREDIT:
1829 section = new CreditSection(this, conversation, parentElement,
1830 style);
1831 break;
1832 case DESCRIPTIONELEMENTSOURCE:
1833 section = new DescriptionElementSourceSection(this, conversation,
1834 parentElement, style);
1835 break;
1836 case EXTENSION:
1837 section = new ExtensionSection(this, conversation, parentElement,
1838 style);
1839 break;
1840 case MARKER:
1841 section = new MarkerSection(this, conversation, parentElement,
1842 style);
1843 break;
1844 case MEDIA:
1845 section = new MediaSection(this, conversation, parentElement, style);
1846 break;
1847 case DESCRIPTIONELEMENTMEDIA:
1848 section = new DescriptionElementMediaSection(this, conversation,
1849 parentElement, style);
1850 break;
1851 case MEDIAREPRESENTATION:
1852 section = new MediaRepresentationSection(this, conversation,
1853 parentElement, style);
1854 break;
1855 case MEDIAREPRESENTATIONPART:
1856 section = new MediaRepresentationPartSection(this, conversation,
1857 parentElement, style);
1858 break;
1859 case MODIFIER:
1860 section = new ModifierSection(this, conversation, parentElement,
1861 style);
1862 break;
1863 case NOMENCLATURALSTATUS:
1864 section = new NomenclaturalStatusSection(this, conversation,
1865 parentElement, style);
1866 break;
1867 case NAME_RELATIONSHIP:
1868 section = new NameRelationshipDetailSection(this, conversation,
1869 parentElement, style);
1870 break;
1871 case PROTOLOG:
1872 section = new ProtologueSection(this, conversation, parentElement,
1873 style);
1874 break;
1875 case RIGHTS:
1876 section = new RightsSection(this, conversation, parentElement,
1877 style);
1878 break;
1879 case SOURCE:
1880 section = new SourceSection(this, conversation, parentElement,
1881 style);
1882 break;
1883 case SCOPE:
1884 section = new ScopeSection(this, conversation, parentElement, style);
1885 break;
1886 case DESCRIPTIONSOURCE:
1887 section = new DescriptionSourceSection(this, conversation,
1888 parentElement, style);
1889 break;
1890 case TYPEDESIGNATION:
1891 section = new TypeDesignationSection(this, conversation,
1892 parentElement, style);
1893 break;
1894 case STATE_DATA:
1895 section = new StateDataSection(this, conversation, parentElement,
1896 style);
1897 break;
1898 case STATISTICAL_MEASUREMENT_VALUE:
1899 section = new StatisticalMeasurementValueSection(this,
1900 conversation, parentElement, style);
1901 break;
1902 case DESCRIBED_SPECIMEN:
1903 section = new DescribedSpecimenSection(this, conversation,
1904 parentElement, style);
1905 break;
1906 case COLLECTING_AREA:
1907 section = new CollectingAreasDetailSection(this, conversation,
1908 parentElement, style);
1909 break;
1910 case DETERMINATION_CURRENT:
1911 section = new CurrentDeterminationDetailSection(this, conversation,
1912 parentElement, style);
1913 break;
1914 case DETERMINATION_HISTORY:
1915 section = new DeterminationHistoryDetailSection(this, conversation,
1916 parentElement, style);
1917 break;
1918 case SPECIMEN_COLLECTION:
1919 section = new SpecimenCollectionDetailSection(this, conversation,
1920 parentElement, style);
1921 break;
1922 case IDENTIFIABLE_SOURCE_COLLECTION:
1923 section = new SourceCollectionDetailSection(this, conversation,
1924 parentElement, style);
1925 break;
1926 case GEOGRAPHICAL_SCOPE:
1927 section = new GeographicalScopeDetailSection(this, conversation,
1928 parentElement, style);
1929 break;
1930 case SCOPE_RESTRICTION:
1931 section = new ScopeRestrictionSection(this, conversation,
1932 parentElement, style);
1933 break;
1934 case MEMBER:
1935 section = new MemberDetailSection(this, conversation,
1936 parentElement, style);
1937 break;
1938 case GRANTED_AUTHORITY:
1939 section = new GrantedAuthorityDetailSection(this, conversation,
1940 parentElement, style);
1941 break;
1942 case GROUPS_BY_USER:
1943 section = new GroupsByUserDetailSection(this, conversation,
1944 parentElement, style);
1945 break;
1946 case TAXONOMIC_SCOPE:
1947 section = new TaxonomicScopeSection(this, conversation,
1948 parentElement, style);
1949 break;
1950 }
1951 parentElement.addElement(section);
1952 adapt(section);
1953 return section;
1954 }
1955
1956 /**
1957 * <p>
1958 * createEntityCollectionElement
1959 * </p>
1960 *
1961 * @param removeListener
1962 * a {@link org.eclipse.swt.events.SelectionListener} object.
1963 * @param style
1964 * a int.
1965 * @param parentElement
1966 * a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1967 * object.
1968 * @param versionableEntity
1969 * a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
1970 * object.
1971 * @param backgroundColor
1972 * a {@link org.eclipse.swt.graphics.Color} object.
1973 * @return a
1974 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
1975 * object.
1976 */
1977 public AbstractEntityCollectionElement createEntityCollectionElement(
1978 AbstractFormSection parentElement, Object versionableEntity,
1979 SelectionListener removeListener, Color backgroundColor, int style) {
1980 AbstractEntityCollectionElement element = null;
1981
1982 Object entity = HibernateProxyHelper.deproxy(versionableEntity);
1983
1984 if (entity instanceof Annotation) {
1985 element = new AnnotationElement(this, parentElement,
1986 (Annotation) entity, removeListener, style);
1987 } else if (entity instanceof Person) {
1988 element = new TeamMemberElement(this, parentElement,
1989 (Person) entity, removeListener, style);
1990 } else if (entity instanceof Credit) {
1991 element = new CreditElement(this, parentElement, (Credit) entity,
1992 removeListener, style);
1993 } else if (entity instanceof Extension) {
1994 element = new ExtensionElement(this, parentElement,
1995 (Extension) entity, removeListener, style);
1996 } else if (entity instanceof Marker) {
1997 element = new MarkerElement(this, parentElement, (Marker) entity,
1998 removeListener, style);
1999 } else if (entity instanceof Media) {
2000 element = new MediaElement(this, parentElement, (Media) entity,
2001 removeListener, style);
2002 } else if (entity instanceof MediaRepresentation) {
2003 element = new MediaRepresentationElement(this, parentElement,
2004 (MediaRepresentation) entity, removeListener, style);
2005 } else if (entity instanceof ImageFile) {
2006 element = new ImageFileElement(this, parentElement,
2007 (ImageFile) entity, removeListener, style);
2008 } else if (entity instanceof MediaRepresentationPart){
2009 element = new MediaRepresentationPartElement(this, parentElement,
2010 (MediaRepresentationPart) entity, removeListener, style);
2011 } else if (entity instanceof NomenclaturalStatus) {
2012 element = new NomenclaturalStatusElement(this, parentElement,
2013 (NomenclaturalStatus) entity, removeListener, style);
2014 } else if (entity instanceof Rights) {
2015 element = new RightsElement(this, parentElement, (Rights) entity,
2016 removeListener, style);
2017 } else if (entity instanceof DescriptionElementSource) {
2018 element = new DescriptionElementSourceElement(this, parentElement,
2019 (DescriptionElementSource) entity, removeListener, style);
2020 } else if (entity instanceof IdentifiableSource) {
2021 element = new IdentifiableSourceElement(this, parentElement,
2022 (IdentifiableSource) entity, removeListener, style);
2023 } else if (entity instanceof DefinedTerm) {
2024 //FIXME:3.3MC
2025 element = new ScopeElement(this, parentElement, (DefinedTerm) entity,
2026 removeListener, style);
2027 } else if (entity instanceof DefinedTerm) {
2028 element = new ModifierElement(this, parentElement,
2029 (DefinedTerm) entity, removeListener, style);
2030 } else if (entity instanceof Reference) {
2031 element = new DescriptionSourceElement(this, parentElement,
2032 (Reference) entity, removeListener, style);
2033 } else if (entity instanceof NameTypeDesignation) {
2034 element = new NameTypeDesignationElement(this, parentElement,
2035 (NameTypeDesignation) entity, removeListener, style);
2036 } else if (entity instanceof NameRelationship) {
2037 element = new NameRelationshipDetailElement(this, parentElement,
2038 (NameRelationship) entity, removeListener, style);
2039 } else if (entity instanceof SpecimenTypeDesignation) {
2040 element = new SpecimenTypeDesignationElement(this, parentElement,
2041 (SpecimenTypeDesignation) entity, removeListener, style);
2042 } else if (entity instanceof StateData) {
2043 element = new StateDataElement(this, parentElement,
2044 (StateData) entity, removeListener, style);
2045 } else if (entity instanceof StatisticalMeasurementValue) {
2046 element = new StatisticalMeasurementValueElement(this,
2047 parentElement, (StatisticalMeasurementValue) entity,
2048 removeListener, style);
2049 } else if (entity instanceof DerivedUnit) {
2050 //FIXME:3.3MC
2051 element = new DerivedUnitElement(this, parentElement,
2052 (DerivedUnit) entity, removeListener, style);
2053 } else if (entity instanceof NamedArea) {
2054 element = new NamedAreaDetailElement(this, parentElement,
2055 (NamedArea) entity, removeListener, style);
2056 } else if (entity instanceof DeterminationEvent) {
2057 element = new DeterminationEventDetailElement(this, parentElement,
2058 (DeterminationEvent) entity, removeListener, style);
2059 } else if (entity instanceof DerivedUnit) {
2060 //FIXME:3.3MC
2061 element = new SpecimenCollectionDetailElement(this, parentElement,
2062 (DerivedUnit) entity, removeListener, style);
2063 } else if (entity instanceof User) {
2064 element = new MemberDetailElement(this, parentElement,
2065 (User) entity, removeListener, style);
2066 } else if (entity instanceof GrantedAuthority) {
2067 element = new GrantedAuthorityCollectionElement(this, parentElement,
2068 (GrantedAuthorityImpl) entity, removeListener, style);
2069 } else if (entity instanceof Group) {
2070 element = new GroupsByUserDetailElement(this, parentElement,
2071 (Group) entity, removeListener, style);
2072 } else if (entity instanceof Taxon) {
2073 element = new TaxonDetailElement(this, parentElement,
2074 (Taxon) entity, removeListener, style);
2075 } else if (entity instanceof DescriptionElementBase) {
2076 // this is the special case for protologs, maybe we can do this
2077 // differently when API improves
2078 DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
2079 if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
2080 element = new ProtologueElement(this, parentElement,
2081 descriptionElement, removeListener, style);
2082 }
2083 }
2084
2085 if (element == null) {
2086 StoreUtil
2087 .errorDialog(
2088 "No element for entity",
2089 this,
2090 "Could not generate element for entity. "
2091 + "Looks like the case is not handled already. Check implementation. Entity: "
2092 + entity, null);
2093
2094 }
2095
2096 if (backgroundColor != null && !backgroundColor.isDisposed()) {
2097 element.setPersistentBackground(backgroundColor);
2098 }
2099
2100 adapt(element);
2101 parentElement.addElement(element);
2102 return element;
2103 }
2104
2105 /**
2106 * <p>
2107 * Creates a selection element for the given type T.
2108 * </p>
2109 * <p>
2110 * <strong>Selection elements not handled by this method:</strong>
2111 * <ul>
2112 * <li>{@link TaxonNodeSelectionElement} see {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}</li>
2113 * <li>{@link NomenclaturalAuthorTeamSelectionElement} see {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}</li>
2114 * </ul>
2115 * </p>
2116 *
2117 * @param clazz
2118 * a {@link Class} object of the type that you want the selection element to handle
2119 * @param parentElement
2120 * a {@link ICdmFormElement}
2121 * object.
2122 * @param labelString
2123 * a {@link String} object.
2124 * @param selectionType
2125 * @param selection
2126 * a {@link ICdmBase} object.
2127 * @param style
2128 * a int.
2129 * @param conversation
2130 * a {@link ConversationHolder} object.
2131 * @return a
2132 * {@link EntitySelectionElement}
2133 * object.
2134 */
2135 public <T extends ICdmBase> EntitySelectionElement<T> createSelectionElement(
2136 Class<T> clazz, ConversationHolder conversation,
2137 ICdmFormElement parentElement, String labelString,
2138 T selection, int mode, int style) {
2139 EntitySelectionElement<T> element = new EntitySelectionElement<T>(this, conversation, parentElement, clazz, labelString, selection, mode, style);
2140 adapt(element);
2141 parentElement.addElement(element);
2142 return element;
2143 }
2144
2145 public TaxonNodeSelectionElement createTaxonNodeSelectionElement(
2146 ConversationHolder conversation,
2147 ICdmFormElement parentElement, String labelString,
2148 TaxonNode selection, int mode, int style) {
2149 TaxonNodeSelectionElement element = new TaxonNodeSelectionElement(this, conversation, parentElement, labelString, selection, mode, style);
2150 adapt(element);
2151 parentElement.addElement(element);
2152 return element;
2153 }
2154
2155 public NomenclaturalAuthorTeamSelectionElement createNomenclaturalAuthorTeamSelectionElement(
2156 ConversationHolder conversation,
2157 ICdmFormElement parentElement, String labelString,
2158 Team selection, int mode, int style) {
2159 NomenclaturalAuthorTeamSelectionElement element = new NomenclaturalAuthorTeamSelectionElement(this, conversation, parentElement, labelString, selection, mode, style);
2160 adapt(element);
2161 parentElement.addElement(element);
2162 return element;
2163 }
2164
2165
2166 /** {@inheritDoc} */
2167 public LabelElement createLabel(ICdmFormElement parentElement, String text) {
2168 LabelElement labelElement = new LabelElement(this, parentElement, text);
2169 adapt(labelElement);
2170 parentElement.addElement(labelElement);
2171 return labelElement;
2172 }
2173
2174 /**
2175 * <p>
2176 * Getter for the field <code>selectionProvider</code>.
2177 * </p>
2178 *
2179 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
2180 */
2181 public ISelectionProvider getSelectionProvider() {
2182 return selectionProvider;
2183 }
2184
2185 /**
2186 * <p>
2187 * createDetailedDescriptionDetailElement
2188 * </p>
2189 *
2190 * @param parentElement
2191 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
2192 * object.
2193 * @param entity
2194 * a
2195 * {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
2196 * object.
2197 * @param style
2198 * a int.
2199 * @return a
2200 * {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
2201 * object.
2202 */
2203 public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
2204 ICdmFormElement parentElement, DescriptionElementBase entity,
2205 int style) {
2206 AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
2207
2208 if (entity instanceof CategoricalData) {
2209 detailedDescriptionElement = new CategoricalDataDetailElement(this,
2210 parentElement, (CategoricalData) entity, style);
2211 } else if (entity instanceof CommonTaxonName) {
2212 detailedDescriptionElement = new CommonNameDetailElement(this,
2213 parentElement, (CommonTaxonName) entity, style);
2214 } else if (entity instanceof Distribution) {
2215 detailedDescriptionElement = new DistributionDetailElement(this,
2216 parentElement, (Distribution) entity, style);
2217 } else if (entity instanceof IndividualsAssociation) {
2218 detailedDescriptionElement = new IndividualsAssociationDetailElement(
2219 this, parentElement, (IndividualsAssociation) entity, style);
2220 } else if (entity instanceof QuantitativeData) {
2221 detailedDescriptionElement = new QuantitativeDataDetailElement(
2222 this, parentElement, (QuantitativeData) entity, style);
2223 } else if (entity instanceof TaxonInteraction) {
2224 detailedDescriptionElement = new TaxonInteractionDetailElement(
2225 this, parentElement, (TaxonInteraction) entity, style);
2226 } else if (entity instanceof TextData) {
2227 detailedDescriptionElement = new TextDataDetailElement(this,
2228 parentElement, (TextData) entity, style);
2229 } else {
2230 throw new IllegalStateException(
2231 "There is no interface for the given description element");
2232 }
2233 adapt(detailedDescriptionElement);
2234 parentElement.addElement(detailedDescriptionElement);
2235 return detailedDescriptionElement;
2236
2237 }
2238
2239 /**
2240 * Creates a styled text as a part of the form.
2241 *
2242 * @param parent
2243 * the text parent
2244 * @param value
2245 * the text initial value
2246 * @param style
2247 * the text style
2248 * @return the text widget
2249 */
2250 public StyledText createStyledText(Composite parent, String value, int style) {
2251 StyledText text = new StyledText(parent, getBorderStyle() | style
2252 | getOrientation());
2253 if (value != null)
2254 text.setText(value);
2255 text.setForeground(getColors().getForeground());
2256 text.setBackground(getColors().getBackground());
2257 // text.addFocusListener(visibilityHandler);
2258 return text;
2259 }
2260
2261
2262
2263
2264
2265
2266 }