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