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