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