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