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