aab69070b4fa02cba09c81910156e8787dd6165f
[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 /**
1400 * <p>
1401 * createCdmDetailSection
1402 * </p>
1403 *
1404 * @param detailType
1405 * a
1406 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
1407 * object.
1408 * @param parentElement
1409 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1410 * object.
1411 * @param selectionProvider
1412 * a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
1413 * @param style
1414 * a int.
1415 * @param conversation
1416 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1417 * object.
1418 * @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1419 * object.
1420 */
1421 public AbstractFormSection createCdmDetailSection(DetailType detailType, ConversationHolder conversation,
1422 ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style) {
1423 AbstractFormSection section = null;
1424
1425 System.out.println("DetailSection: " + detailType);
1426 switch (detailType) {
1427 case SCIENTIFICNAME:
1428 section = new NameDetailSection(this, conversation, parentElement, selectionProvider, style);
1429 break;
1430 case REFERENCEBASE:
1431 section = new ReferenceDetailSection(this, conversation, parentElement, selectionProvider, style);
1432 break;
1433 case NOMENCLATURALREFERENCE:
1434 section = new NomenclaturalReferenceDetailSection(this, conversation, parentElement, selectionProvider,
1435 style);
1436 break;
1437 case TAXONBASE:
1438 section = new TaxonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1439 break;
1440 case AUTHORSHIP:
1441 section = new AuthorshipDetailSection(this, conversation, parentElement, selectionProvider, style);
1442 break;
1443 case TEAMORPERSONBASE:
1444 section = new TeamOrPersonBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1445 break;
1446 case TEAM:
1447 section = new TeamDetailSection(this, conversation, parentElement, null, style);
1448 break;
1449 case PERSON:
1450 section = new PersonDetailSection(this, conversation, parentElement, null, style);
1451 break;
1452 case DESCRIPTION:
1453 section = new DescriptionDetailSection(this, conversation, parentElement, selectionProvider, style);
1454 break;
1455 case DESCRIPTIONELEMENT:
1456 section = new DescriptionElementDetailSection(this, conversation, parentElement, selectionProvider, style);
1457 break;
1458 case PARSINGMESSAGE:
1459 section = new ParsingMessagesSection(this, conversation, parentElement, selectionProvider, style);
1460 break;
1461 case NONVIRALNAME:
1462 section = new NonViralNameDetailSection(this, conversation, parentElement, selectionProvider, style);
1463 break;
1464 case MEDIA:
1465 section = new eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection(this, conversation,
1466 parentElement, selectionProvider, style);
1467 break;
1468 case DERIVED_UNIT_FACADE:
1469 section = new DerivedUnitFacadeDetailSection(this, conversation, parentElement, selectionProvider, style);
1470 break;
1471 case FIELD_OBSERVATION:
1472 section = new FieldObservationDetailSection(this, conversation, parentElement, selectionProvider, style);
1473 break;
1474 case GATHERING_EVENT:
1475 section = new GatheringEventDetailSection(this, conversation, parentElement, selectionProvider, style);
1476 break;
1477 case DERIVED_UNIT:
1478 section = new DerivedUnitBaseDetailSection(this, conversation, parentElement, selectionProvider, style);
1479 break;
1480 case NATURAL_LANGUAGE:
1481 section = new NaturalLanguageSection(this, conversation, parentElement, selectionProvider, style);
1482 break;
1483 case FEATURE_DISTRIBUTION:
1484 section = new FeatureDistributionDetailSection(this, conversation, parentElement, selectionProvider, style);
1485 break;
1486 case CLASSIFICATION:
1487 section = new ClassificationDetailSection(this, conversation, parentElement, selectionProvider, style);
1488 break;
1489 case TAXON_NODE:
1490 section = new TaxonNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1491 break;
1492 case POLYTOMOUS_KEY:
1493 section = new PolytomousKeyDetailSection(this, conversation, parentElement, selectionProvider, style);
1494 break;
1495 case POLYTOMOUS_KEY_NODE:
1496 section = new PolytomousKeyNodeDetailSection(this, conversation, parentElement, selectionProvider, style);
1497 break;
1498 case INSTITUTION:
1499 section = new InstitutionDetailSection(this, conversation, parentElement, selectionProvider, style);
1500 break;
1501 case DERIVED_UNIT_GENERAL:
1502 section = new GeneralDetailSection(this, conversation, parentElement, selectionProvider, style);
1503 break;
1504 case HYBRID:
1505 section = new HybridDetailSection(this, conversation, parentElement, selectionProvider, style);
1506 break;
1507 case USER:
1508 section = new UserDetailSection(this, conversation, parentElement, selectionProvider, style);
1509 break;
1510 case GROUP:
1511 section = new GroupDetailSection(this, conversation, parentElement, selectionProvider, style);
1512 break;
1513 case DETERMINATION:
1514 section = new DeterminationDetailSection(this, conversation, parentElement, selectionProvider, style);
1515 break;
1516 case TAXON_RELATIONSHIP:
1517 section = new TaxonRelationshipDetailSection(this, conversation, parentElement, selectionProvider, style);
1518 break;
1519 case REFERENCED_ENTITY:
1520 section = new ReferencedEntityDetailSection(this, conversation, parentElement, selectionProvider, style);
1521 break;
1522 case TERM_VOCABULARY:
1523 section = new TermVocabularyDetailSection(this, conversation, parentElement, selectionProvider, style);
1524 break;
1525 case NAMED_AREA:
1526 section = new NamedAreaDetailSection(this, conversation, parentElement, selectionProvider, style);
1527 break;
1528 case USE_RECORD:
1529 section = new UseRecordDetailSection(this, conversation, parentElement, selectionProvider, style);
1530 break;
1531 }
1532
1533 if (section == null) {
1534 throw new RuntimeException("You tried to create a cdm detail section that is not implemented yet.");
1535 }
1536
1537 parentElement.addElement(section);
1538 adapt(section);
1539 return section;
1540 }
1541
1542 /**
1543 * <p>
1544 * createCdmDetailElement
1545 * </p>
1546 *
1547 * @param detailType
1548 * a
1549 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType}
1550 * object.
1551 * @param style
1552 * a int.
1553 * @param parentElement
1554 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1555 * object.
1556 * @return a
1557 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement}
1558 * object.
1559 */
1560 public AbstractCdmDetailElement createCdmDetailElement(DetailType detailType, ICdmFormElement parentElement, int style) {
1561 AbstractCdmDetailElement element = null;
1562
1563 switch (detailType) {
1564 case SCIENTIFICNAME:
1565 element = new NameDetailElement(this, parentElement, style);
1566 break;
1567 case REFERENCEBASE:
1568 element = new ReferenceDetailElement(this, parentElement, style);
1569 break;
1570 case NOMENCLATURALREFERENCE:
1571 element = new NomenclaturalReferenceDetailElement(this, parentElement, style);
1572 break;
1573 case TAXONBASE:
1574 element = new TaxonBaseDetailElement(this, parentElement, style);
1575 break;
1576 case AUTHORSHIP:
1577 element = new AuthorshipDetailElement(this, parentElement, style);
1578 break;
1579 case TEAM:
1580 element = new TeamDetailElement(this, parentElement, style);
1581 break;
1582 case PERSON:
1583 element = new PersonDetailElement(this, parentElement, style);
1584 break;
1585 case DESCRIPTION:
1586 element = new DescriptionDetailElement(this, parentElement, style);
1587 break;
1588 case DESCRIPTIONELEMENT:
1589 element = new DescriptionElementDetailElement(this, parentElement, style);
1590 break;
1591 case NONVIRALNAME:
1592 element = new NonViralNameDetailElement(this, parentElement);
1593 break;
1594 case DERIVED_UNIT_FACADE:
1595 element = new DerivedUnitFacadeDetailElement(this, parentElement);
1596 break;
1597 case FIELD_OBSERVATION:
1598 element = new FieldObservationDetailElement(this, parentElement);
1599 break;
1600 case GATHERING_EVENT:
1601 element = new GatheringEventDetailElement(this, parentElement);
1602 break;
1603 case DERIVED_UNIT:
1604 element = new DerivedUnitBaseDetailElement(this, parentElement);
1605 break;
1606 case NATURAL_LANGUAGE:
1607 element = new NaturalLanguageDetailElement(this, parentElement);
1608 break;
1609 case FEATURE_DISTRIBUTION:
1610 element = new FeatureDistributionDetailElement(this, parentElement);
1611 break;
1612 case CLASSIFICATION:
1613 element = new ClassificationDetailElement(this, parentElement);
1614 break;
1615 case TAXON_NODE:
1616 element = new TaxonNodeDetailElement(this, parentElement);
1617 break;
1618 case COLLECTION:
1619 element = new CollectionDetailElement(this, parentElement);
1620 break;
1621 case POLYTOMOUS_KEY:
1622 element = new PolytomousKeyDetailElement(this, parentElement);
1623 break;
1624 case POLYTOMOUS_KEY_NODE:
1625 element = new PolytomousKeyNodeDetailElement(this, parentElement);
1626 break;
1627 case INSTITUTION:
1628 element = new InstitutionDetailElement(this, parentElement);
1629 break;
1630 case DERIVED_UNIT_GENERAL:
1631 element = new GeneralDetailElement(this, parentElement);
1632 break;
1633 case HYBRID:
1634 element = new HybridDetailElement(this, parentElement);
1635 break;
1636 case USER:
1637 element = new UserDetailElement(this, parentElement);
1638 break;
1639 case GROUP:
1640 element = new GroupDetailElement(this, parentElement);
1641 break;
1642 case GRANTEDAUTHORITY:
1643 element = new GrantedAuthorityDetailElement(this, parentElement);
1644 break;
1645 case DETERMINATION:
1646 element = new DeterminationDetailElement(this, parentElement);
1647 break;
1648 case TAXON_RELATIONSHIP:
1649 element = new TaxonRelationshipDetailElement(this, parentElement);
1650 break;
1651 case REFERENCED_ENTITY:
1652 element = new RefereneEntityDetailElement(this, parentElement);
1653 break;
1654 case TERM_VOCABULARY:
1655 element = new TermVocabularyDetailElement(this, parentElement);
1656 break;
1657 case NAMED_AREA:
1658 element = new eu.etaxonomy.taxeditor.ui.section.vocabulary.NamedAreaDetailElement(this, parentElement);
1659 break;
1660 case NAMED_AREA_LEVEL:
1661 element = new DefinedTermDetailElement<NamedAreaLevel>(this, parentElement);
1662 break;
1663 case USE_RECORD:
1664 // element = new UseRecordDetailElement(this, parentElement, style);
1665 element = new UseRecordDetailElement(this, parentElement);
1666 break;
1667 }
1668
1669 if (element == null) {
1670 AbstractUtility.error(this.getClass(),
1671 "Detail element was not created. Seems like the case was not implemented for the requested detail type: "
1672 + detailType, null);
1673 }
1674
1675 adapt(element);
1676 parentElement.addElement(element);
1677 return element;
1678 }
1679
1680 /**
1681 *
1682 * Used to define which {@link AbstractEntityCollectionSection} should be
1683 * created in
1684 * {@link CdmFormFactory#createEntityDetailSection(EntityDetailType, ConversationHolder, ICdmFormElement, int)}
1685 *
1686 * @author n.hoffmann
1687 * @created Mar 5, 2010
1688 * @version 1.0
1689 */
1690 public static enum EntityDetailType {
1691 TEAM, // never used
1692 TEAMMEMBER,
1693 ANNOTATION,
1694 CREDIT,
1695 DESCRIPTIONELEMENTSOURCE,
1696 EXTENSION,
1697 MARKER,
1698 MEDIA,
1699 DESCRIPTIONELEMENTMEDIA,
1700 MEDIAREPRESENTATION,
1701 MEDIAREPRESENTATIONPART,
1702 MODIFIER,
1703 NOMENCLATURALSTATUS,
1704 NAME_RELATIONSHIP,
1705 PROTOLOG,
1706 RIGHTS,
1707 SOURCE,
1708 SCOPE,
1709 DESCRIPTIONSOURCE,
1710 TYPEDESIGNATION,
1711 STATE_DATA,
1712 STATISTICAL_MEASUREMENT_VALUE,
1713 DESCRIBED_SPECIMEN,
1714 COLLECTING_AREA, DETERMINATION_EVENT, // never used
1715 SPECIMEN_COLLECTION,
1716 IDENTIFIABLE_SOURCE_COLLECTION,
1717 GEOGRAPHICAL_SCOPE, // never used
1718 SCOPE_RESTRICTION,
1719 MEMBER,
1720 GRANTED_AUTHORITY,
1721 GROUPS_BY_USER,
1722 TAXONOMIC_SCOPE,
1723 DETERMINATION_CURRENT,
1724 DETERMINATION_HISTORY
1725 }
1726
1727 /**
1728 * <p>
1729 * createEntityDetailSection
1730 * </p>
1731 *
1732 * @param entityDetailType
1733 * a
1734 * {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType}
1735 * object.
1736 * @param style
1737 * a int.
1738 * @param conversation
1739 * a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
1740 * object.
1741 * @param parentElement
1742 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
1743 * object.
1744 * @return a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1745 * object.
1746 */
1747 public AbstractFormSection createEntityDetailSection(EntityDetailType entityDetailType,
1748 ConversationHolder conversation, ICdmFormElement parentElement, int style) {
1749 AbstractFormSection section = null;
1750
1751 System.out.println("EntityDetailSection: " + entityDetailType);
1752 switch (entityDetailType) {
1753 case TEAM:
1754 // TODO this is not an AbstractEntityCollectionSection
1755 section = new TeamDetailSection(this, conversation, parentElement, null, style);
1756 break;
1757 case TEAMMEMBER:
1758 section = new TeamMemberSection(this, conversation, parentElement, style);
1759 break;
1760 case ANNOTATION:
1761 section = new AnnotationSection(this, conversation, parentElement, style);
1762 break;
1763 case CREDIT:
1764 section = new CreditSection(this, conversation, parentElement, style);
1765 break;
1766 case DESCRIPTIONELEMENTSOURCE:
1767 section = new DescriptionElementSourceSection(this, conversation, parentElement, style);
1768 break;
1769 case EXTENSION:
1770 section = new ExtensionSection(this, conversation, parentElement, style);
1771 break;
1772 case MARKER:
1773 section = new MarkerSection(this, conversation, parentElement, style);
1774 break;
1775 case MEDIA:
1776 section = new MediaSection(this, conversation, parentElement, style);
1777 break;
1778 case DESCRIPTIONELEMENTMEDIA:
1779 section = new DescriptionElementMediaSection(this, conversation, parentElement, style);
1780 break;
1781 case MEDIAREPRESENTATION:
1782 section = new MediaRepresentationSection(this, conversation, parentElement, style);
1783 break;
1784 case MEDIAREPRESENTATIONPART:
1785 section = new MediaRepresentationPartSection(this, conversation, parentElement, style);
1786 break;
1787 case MODIFIER:
1788 section = new ModifierSection(this, conversation, parentElement, style);
1789 break;
1790 case NOMENCLATURALSTATUS:
1791 section = new NomenclaturalStatusSection(this, conversation, parentElement, style);
1792 break;
1793 case NAME_RELATIONSHIP:
1794 section = new NameRelationshipDetailSection(this, conversation, parentElement, style);
1795 break;
1796 case PROTOLOG:
1797 section = new ProtologueSection(this, conversation, parentElement, style);
1798 break;
1799 case RIGHTS:
1800 section = new RightsSection(this, conversation, parentElement, style);
1801 break;
1802 case SOURCE:
1803 section = new SourceSection(this, conversation, parentElement, style);
1804 break;
1805 case SCOPE:
1806 section = new ScopeSection(this, conversation, parentElement, style);
1807 break;
1808 case DESCRIPTIONSOURCE:
1809 section = new DescriptionSourceSection(this, conversation, parentElement, style);
1810 break;
1811 case TYPEDESIGNATION:
1812 section = new TypeDesignationSection(this, conversation, parentElement, style);
1813 break;
1814 case STATE_DATA:
1815 section = new StateDataSection(this, conversation, parentElement, style);
1816 break;
1817 case STATISTICAL_MEASUREMENT_VALUE:
1818 section = new StatisticalMeasurementValueSection(this, conversation, parentElement, style);
1819 break;
1820 case DESCRIBED_SPECIMEN:
1821 section = new DescribedSpecimenSection(this, conversation, parentElement, style);
1822 break;
1823 case COLLECTING_AREA:
1824 section = new CollectingAreasDetailSection(this, conversation, parentElement, style);
1825 break;
1826 case DETERMINATION_CURRENT:
1827 section = new CurrentDeterminationDetailSection(this, conversation, parentElement, style);
1828 break;
1829 case DETERMINATION_HISTORY:
1830 section = new DeterminationHistoryDetailSection(this, conversation, parentElement, style);
1831 break;
1832 case SPECIMEN_COLLECTION:
1833 section = new SpecimenCollectionDetailSection(this, conversation, parentElement, style);
1834 break;
1835 case IDENTIFIABLE_SOURCE_COLLECTION:
1836 section = new SourceCollectionDetailSection(this, conversation, parentElement, style);
1837 break;
1838 case GEOGRAPHICAL_SCOPE:
1839 section = new GeographicalScopeDetailSection(this, conversation, parentElement, style);
1840 break;
1841 case SCOPE_RESTRICTION:
1842 section = new ScopeRestrictionSection(this, conversation, parentElement, style);
1843 break;
1844 case MEMBER:
1845 section = new MemberDetailSection(this, conversation, parentElement, style);
1846 break;
1847 case GRANTED_AUTHORITY:
1848 section = new GrantedAuthorityDetailSection(this, conversation, parentElement, style);
1849 break;
1850 case GROUPS_BY_USER:
1851 section = new GroupsByUserDetailSection(this, conversation, parentElement, style);
1852 break;
1853 case TAXONOMIC_SCOPE:
1854 section = new TaxonomicScopeSection(this, conversation, parentElement, style);
1855 break;
1856 }
1857 parentElement.addElement(section);
1858 adapt(section);
1859 return section;
1860 }
1861
1862 /**
1863 * <p>
1864 * createEntityCollectionElement
1865 * </p>
1866 *
1867 * @param removeListener
1868 * a {@link org.eclipse.swt.events.SelectionListener} object.
1869 * @param style
1870 * a int.
1871 * @param parentElement
1872 * a
1873 * {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
1874 * object.
1875 * @param versionableEntity
1876 * a {@link eu.etaxonomy.cdm.model.common.IVersionableEntity}
1877 * object.
1878 * @param backgroundColor
1879 * a {@link org.eclipse.swt.graphics.Color} object.
1880 * @return a
1881 * {@link eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement}
1882 * object.
1883 */
1884 public AbstractEntityCollectionElement createEntityCollectionElement(AbstractFormSection parentElement,
1885 Object versionableEntity, SelectionListener removeListener, Color backgroundColor, int style) {
1886 AbstractEntityCollectionElement element = null;
1887
1888 Object entity = HibernateProxyHelper.deproxy(versionableEntity);
1889
1890 if (entity instanceof Annotation) {
1891 element = new AnnotationElement(this, parentElement, (Annotation) entity, removeListener, style);
1892 } else if (entity instanceof Person) {
1893 element = new TeamMemberElement(this, parentElement, (Person) entity, removeListener, style);
1894 } else if (entity instanceof Credit) {
1895 element = new CreditElement(this, parentElement, (Credit) entity, removeListener, style);
1896 } else if (entity instanceof Extension) {
1897 element = new ExtensionElement(this, parentElement, (Extension) entity, removeListener, style);
1898 } else if (entity instanceof Marker) {
1899 element = new MarkerElement(this, parentElement, (Marker) entity, removeListener, style);
1900 } else if (entity instanceof Media) {
1901 element = new MediaElement(this, parentElement, (Media) entity, removeListener, style);
1902 } else if (entity instanceof MediaRepresentation) {
1903 element = new MediaRepresentationElement(this, parentElement, (MediaRepresentation) entity, removeListener,
1904 style);
1905 } else if (entity instanceof ImageFile) {
1906 element = new ImageFileElement(this, parentElement, (ImageFile) entity, removeListener, style);
1907 } else if (entity instanceof MediaRepresentationPart) {
1908 element = new MediaRepresentationPartElement(this, parentElement, (MediaRepresentationPart) entity,
1909 removeListener, style);
1910 } else if (entity instanceof NomenclaturalStatus) {
1911 element = new NomenclaturalStatusElement(this, parentElement, (NomenclaturalStatus) entity, removeListener,
1912 style);
1913 } else if (entity instanceof Rights) {
1914 element = new RightsElement(this, parentElement, (Rights) entity, removeListener, style);
1915 } else if (entity instanceof DescriptionElementSource) {
1916 element = new DescriptionElementSourceElement(this, parentElement, (DescriptionElementSource) entity,
1917 removeListener, style);
1918 } else if (entity instanceof IdentifiableSource) {
1919 element = new IdentifiableSourceElement(this, parentElement, (IdentifiableSource) entity, removeListener,
1920 style);
1921 } else if (entity instanceof Scope) {
1922 element = new ScopeElement(this, parentElement, (Scope) entity, removeListener, style);
1923 } else if (entity instanceof Modifier) {
1924 element = new ModifierElement(this, parentElement, (Modifier) entity, removeListener, style);
1925 } else if (entity instanceof Reference) {
1926 element = new DescriptionSourceElement(this, parentElement, (Reference) entity, removeListener, style);
1927 } else if (entity instanceof NameTypeDesignation) {
1928 element = new NameTypeDesignationElement(this, parentElement, (NameTypeDesignation) entity, removeListener,
1929 style);
1930 } else if (entity instanceof NameRelationship) {
1931 element = new NameRelationshipDetailElement(this, parentElement, (NameRelationship) entity, removeListener,
1932 style);
1933 } else if (entity instanceof SpecimenTypeDesignation) {
1934 element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
1935 removeListener, style);
1936 } else if (entity instanceof StateData) {
1937 element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
1938 } else if (entity instanceof StatisticalMeasurementValue) {
1939 element = new StatisticalMeasurementValueElement(this, parentElement, (StatisticalMeasurementValue) entity,
1940 removeListener, style);
1941 } else if (entity instanceof DerivedUnit) {
1942 element = new DerivedUnitElement(this, parentElement, (DerivedUnit) entity, removeListener, style);
1943 } else if (entity instanceof NamedArea) {
1944 element = new NamedAreaDetailElement(this, parentElement, (NamedArea) entity, removeListener, style);
1945 } else if (entity instanceof DeterminationEvent) {
1946 element = new DeterminationEventDetailElement(this, parentElement, (DeterminationEvent) entity,
1947 removeListener, style);
1948 } else if (entity instanceof Specimen) {
1949 element = new SpecimenCollectionDetailElement(this, parentElement, (Specimen) entity, removeListener, style);
1950 } else if (entity instanceof User) {
1951 element = new MemberDetailElement(this, parentElement, (User) entity, removeListener, style);
1952 } else if (entity instanceof GrantedAuthority) {
1953 element = new GrantedAuthorityCollectionElement(this, parentElement, (GrantedAuthorityImpl) entity,
1954 removeListener, style);
1955 } else if (entity instanceof Group) {
1956 element = new GroupsByUserDetailElement(this, parentElement, (Group) entity, removeListener, style);
1957 } else if (entity instanceof Taxon) {
1958 element = new TaxonDetailElement(this, parentElement, (Taxon) entity, removeListener, style);
1959 } else if (entity instanceof DescriptionElementBase) {
1960 // this is the special case for protologs, maybe we can do this
1961 // differently when API improves
1962 DescriptionElementBase descriptionElement = (DescriptionElementBase) entity;
1963 if (descriptionElement.getFeature().equals(Feature.PROTOLOGUE())) {
1964 element = new ProtologueElement(this, parentElement, descriptionElement, removeListener, style);
1965 }
1966 }
1967
1968 if (element == null) {
1969 AbstractUtility.errorDialog("No element for entity", this,
1970 "Could not generate element for entity. Looks like the case is not handled already. Check implementation. Entity: "
1971 + entity, null);
1972 }
1973
1974 else if (backgroundColor != null && !backgroundColor.isDisposed()) {
1975 element.setPersistentBackground(backgroundColor);
1976 }
1977
1978 adapt(element);
1979 parentElement.addElement(element);
1980 return element;
1981 }
1982
1983 /**
1984 * <p>
1985 * Creates a selection element for the given type T.
1986 * </p>
1987 * <p>
1988 * <strong>Selection elements not handled by this method:</strong>
1989 * <ul>
1990 * <li>{@link TaxonNodeSelectionElement} see
1991 * {@link #createTaxonNodeSelectionElement(ConversationHolder, ICdmFormElement, String, TaxonNode, int, int)}
1992 * </li>
1993 * <li>{@link NomenclaturalAuthorTeamSelectionElement} see
1994 * {@link #createNomenclaturalAuthorTeamSelectionElement(ConversationHolder, ICdmFormElement, String, Team, int, int)}
1995 * </li>
1996 * </ul>
1997 * </p>
1998 *
1999 * @param clazz
2000 * a {@link Class} object of the type that you want the selection
2001 * element to handle
2002 * @param parentElement
2003 * a {@link ICdmFormElement} object.
2004 * @param labelString
2005 * a {@link String} object.
2006 * @param selectionType
2007 * @param selection
2008 * a {@link ICdmBase} object.
2009 * @param style
2010 * a int.
2011 * @param conversation
2012 * a {@link ConversationHolder} object.
2013 * @return a {@link EntitySelectionElement} object.
2014 */
2015 public <T extends ICdmBase> EntitySelectionElement<T> createSelectionElement(Class<T> clazz,
2016 ConversationHolder conversation, ICdmFormElement parentElement, String labelString, T selection, int mode,
2017 int style) {
2018 EntitySelectionElement<T> element = new EntitySelectionElement<T>(this, conversation, parentElement, clazz,
2019 labelString, selection, mode, style);
2020 adapt(element);
2021 parentElement.addElement(element);
2022 return element;
2023 }
2024
2025 public TaxonNodeSelectionElement createTaxonNodeSelectionElement(ConversationHolder conversation,
2026 ICdmFormElement parentElement, String labelString, TaxonNode selection, int mode, int style) {
2027 TaxonNodeSelectionElement element = new TaxonNodeSelectionElement(this, conversation, parentElement,
2028 labelString, selection, mode, style);
2029 adapt(element);
2030 parentElement.addElement(element);
2031 return element;
2032 }
2033
2034 public NomenclaturalAuthorTeamSelectionElement createNomenclaturalAuthorTeamSelectionElement(
2035 ConversationHolder conversation, ICdmFormElement parentElement, String labelString, Team selection,
2036 int mode, int style) {
2037 NomenclaturalAuthorTeamSelectionElement element = new NomenclaturalAuthorTeamSelectionElement(this,
2038 conversation, parentElement, labelString, selection, mode, style);
2039 adapt(element);
2040 parentElement.addElement(element);
2041 return element;
2042 }
2043
2044 /** {@inheritDoc} */
2045 public LabelElement createLabel(ICdmFormElement parentElement, String text) {
2046 LabelElement labelElement = new LabelElement(this, parentElement, text);
2047 adapt(labelElement);
2048 parentElement.addElement(labelElement);
2049 return labelElement;
2050 }
2051
2052 /**
2053 * <p>
2054 * Getter for the field <code>selectionProvider</code>.
2055 * </p>
2056 *
2057 * @return a {@link org.eclipse.jface.viewers.ISelectionProvider} object.
2058 */
2059 public ISelectionProvider getSelectionProvider() {
2060 return selectionProvider;
2061 }
2062
2063 /**
2064 * <p>
2065 * createDetailedDescriptionDetailElement
2066 * </p>
2067 *
2068 * @param parentElement
2069 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
2070 * object.
2071 * @param entity
2072 * a
2073 * {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase}
2074 * object.
2075 * @param style
2076 * a int.
2077 * @return a
2078 * {@link eu.etaxonomy.taxeditor.ui.section.description.detail.AbstractDetailedDescriptionDetailElement}
2079 * object.
2080 */
2081 public AbstractDetailedDescriptionDetailElement createDetailedDescriptionDetailElement(
2082 ICdmFormElement parentElement, DescriptionElementBase entity, int style) {
2083 AbstractDetailedDescriptionDetailElement detailedDescriptionElement = null;
2084
2085 if (entity instanceof CategoricalData) {
2086 detailedDescriptionElement = new CategoricalDataDetailElement(this, parentElement,
2087 (CategoricalData) entity, style);
2088 } else if (entity instanceof CommonTaxonName) {
2089 detailedDescriptionElement = new CommonNameDetailElement(this, parentElement, (CommonTaxonName) entity,
2090 style);
2091 } else if (entity instanceof Distribution) {
2092 detailedDescriptionElement = new DistributionDetailElement(this, parentElement, (Distribution) entity,
2093 style);
2094 } else if (entity instanceof IndividualsAssociation) {
2095 detailedDescriptionElement = new IndividualsAssociationDetailElement(this, parentElement,
2096 (IndividualsAssociation) entity, style);
2097 } else if (entity instanceof QuantitativeData) {
2098 detailedDescriptionElement = new QuantitativeDataDetailElement(this, parentElement,
2099 (QuantitativeData) entity, style);
2100 } else if (entity instanceof TaxonInteraction) {
2101 detailedDescriptionElement = new TaxonInteractionDetailElement(this, parentElement,
2102 (TaxonInteraction) entity, style);
2103 } else if (entity instanceof TextData) {
2104 detailedDescriptionElement = new TextDataDetailElement(this, parentElement, (TextData) entity, style);
2105 } else {
2106 throw new IllegalStateException("There is no interface for the given description element");
2107 }
2108 adapt(detailedDescriptionElement);
2109 parentElement.addElement(detailedDescriptionElement);
2110 return detailedDescriptionElement;
2111
2112 }
2113
2114 /**
2115 * Creates a styled text as a part of the form.
2116 *
2117 * @param parent
2118 * the text parent
2119 * @param value
2120 * the text initial value
2121 * @param style
2122 * the text style
2123 * @return the text widget
2124 */
2125 public StyledText createStyledText(Composite parent, String value, int style) {
2126 StyledText text = new StyledText(parent, getBorderStyle() | style | getOrientation());
2127 if (value != null) {
2128 text.setText(value);
2129 }
2130 text.setForeground(getColors().getForeground());
2131 text.setBackground(getColors().getBackground());
2132 // text.addFocusListener(visibilityHandler);
2133 return text;
2134 }
2135
2136 }