added a readme file
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / detail / DetailsViewer.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.editor.view.detail;
12
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.SelectionChangedEvent;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.ui.forms.widgets.Section;
18
19 import eu.etaxonomy.cdm.model.agent.Person;
20 import eu.etaxonomy.cdm.model.agent.Team;
21 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
22 import eu.etaxonomy.cdm.model.description.DescriptionBase;
23 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
24 import eu.etaxonomy.cdm.model.media.Media;
25 import eu.etaxonomy.cdm.model.name.NonViralName;
26 import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
27 import eu.etaxonomy.cdm.model.reference.Reference;
28 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
29 import eu.etaxonomy.taxeditor.editor.EditorUtil;
30 import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
31 import eu.etaxonomy.taxeditor.editor.Page;
32 import eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer;
33 import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
34 import eu.etaxonomy.taxeditor.editor.view.AbstractCdmDataViewer;
35 import eu.etaxonomy.taxeditor.forms.AbstractFormSection;
36 import eu.etaxonomy.taxeditor.forms.CdmFormFactory.DetailType;
37 import eu.etaxonomy.taxeditor.forms.CdmFormFactory.EntityDetailType;
38 import eu.etaxonomy.taxeditor.forms.RootElement;
39 import eu.etaxonomy.taxeditor.model.AbstractCdmViewPart;
40 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
41
42 /**
43 * <p>DetailsViewer class.</p>
44 *
45 * @author n.hoffmann
46 * @created Feb 12, 2010
47 * @version 1.0
48 */
49 public class DetailsViewer extends AbstractCdmDataViewer {
50
51 private enum VIEW_PART{
52 TAXON,
53 NAME,
54 REFEERENCE,
55 TEAM,
56 PERSON,
57 DESCRIPTION,
58 DESCRIPTION_ELEMENT,
59 EMPTY,
60 MEDIA,
61 TEAM_OR_PERSON_BASE,
62 DERIVED_UNIT_BASE,
63 FIELD_OBSERVATION,
64 FEATURE_DISTRIBUTION
65 }
66
67 private VIEW_PART currentViewPart;
68
69 private ISelection selection;
70
71 private AbstractGroupedContainer sourceContainer;
72
73 /**
74 * <p>Constructor for DetailsViewer.</p>
75 *
76 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
77 * @param viewPart a {@link eu.etaxonomy.taxeditor.model.AbstractCdmViewPart} object.
78 */
79 public DetailsViewer(Composite parent, AbstractCdmViewPart viewPart) {
80 super(parent, viewPart);
81 }
82
83 /* (non-Javadoc)
84 * @see org.eclipse.jface.viewers.Viewer#refresh()
85 */
86 /** {@inheritDoc} */
87 @Override
88 protected void showParts() {
89 if(getInput() instanceof TaxonBase){
90 if(currentViewPart != VIEW_PART.TAXON){
91 createTaxonSections(rootElement);
92 currentViewPart = VIEW_PART.TAXON;
93
94 // preserve a pointer to the AbstractNameComposite
95 MultiPageTaxonEditor editor = EditorUtil.getActiveMultiPageTaxonEditor();
96 if(editor != null){
97 TaxonNameEditor page = (TaxonNameEditor) editor.getPage(Page.NAME);
98 for(AbstractGroupedContainer container : page.getGroupedContainers()){
99 if(container.getData() == getInput()){
100 sourceContainer = container;
101 }
102 }
103 }
104 }
105 }else if(getInput() instanceof NonViralName){
106 if(currentViewPart != VIEW_PART.NAME){
107 createNameSections(rootElement);
108 currentViewPart = VIEW_PART.NAME;
109 }
110 }else if(getInput() instanceof Reference){
111 if(currentViewPart != VIEW_PART.REFEERENCE){
112 createReferenceSections(rootElement);
113 currentViewPart = VIEW_PART.REFEERENCE;
114 }
115 }else if(getInput() instanceof Team){
116 if(currentViewPart != VIEW_PART.TEAM){
117 createTeamDetailSection(rootElement);
118 currentViewPart = VIEW_PART.TEAM;
119 }
120 }else if(getInput() instanceof Person){
121 if(currentViewPart != VIEW_PART.PERSON){
122 createPersonDetailSection(rootElement);
123 currentViewPart = VIEW_PART.PERSON;
124 }
125 }else if(getInput() instanceof TeamOrPersonBase){
126 // fallback
127 if(currentViewPart != VIEW_PART.TEAM_OR_PERSON_BASE){
128 createTeamOrPersonBaseDetailSection(rootElement);
129 currentViewPart = VIEW_PART.TEAM_OR_PERSON_BASE;
130 }
131 }else if(getInput() instanceof DescriptionBase){
132 if(currentViewPart != VIEW_PART.DESCRIPTION){
133 createDescriptionSection(rootElement);
134 currentViewPart = VIEW_PART.DESCRIPTION;
135 }
136 }else if(getInput() instanceof DescriptionElementBase){
137 if(currentViewPart != VIEW_PART.DESCRIPTION_ELEMENT){
138 createDescriptionElementSection(rootElement);
139 currentViewPart = VIEW_PART.DESCRIPTION_ELEMENT;
140 }
141 }else if(getInput() instanceof Media){
142 if(currentViewPart != VIEW_PART.MEDIA){
143 createMediaElementSection(rootElement);
144 currentViewPart = VIEW_PART.MEDIA;
145 }
146 }else if(getInput() instanceof DerivedUnitBase){
147 if(currentViewPart != VIEW_PART.DERIVED_UNIT_BASE){
148 createDerivedUnitBaseElementSection(rootElement);
149 currentViewPart = VIEW_PART.DERIVED_UNIT_BASE;
150 }
151 }else if(getInput() instanceof DerivedUnitBase){
152 if(currentViewPart != VIEW_PART.FIELD_OBSERVATION){
153 createFieldObservationElementSection(rootElement);
154 currentViewPart = VIEW_PART.FIELD_OBSERVATION;
155 }
156 }else if(getInput() instanceof FeatureNodeContainer) {
157 if(currentViewPart != VIEW_PART.FEATURE_DISTRIBUTION){
158 createFeatureDistributionSection(rootElement);
159 currentViewPart = VIEW_PART.FEATURE_DISTRIBUTION;
160 }
161 }else{
162 destroySections();
163 currentViewPart = VIEW_PART.EMPTY;
164 }
165
166 layout();
167 }
168
169
170 /* (non-Javadoc)
171 * @see org.eclipse.jface.viewers.Viewer#getSelection()
172 */
173 /** {@inheritDoc} */
174 @Override
175 public ISelection getSelection() {
176 return selection;
177 }
178
179 /* (non-Javadoc)
180 * @see org.eclipse.jface.viewers.Viewer#setSelection(org.eclipse.jface.viewers.ISelection, boolean)
181 */
182 /** {@inheritDoc} */
183 @Override
184 public void setSelection(ISelection selection, boolean reveal) {
185 this.selection = selection;
186 SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(this, selection);
187 fireSelectionChanged(selectionChangedEvent);
188 }
189
190
191 private void createTaxonSections(RootElement parent) {
192 destroySections();
193
194 AbstractFormSection taxonBaseDetailSection =
195 formFactory.createCdmDetailSection(DetailType.TAXONBASE, getConversationHolder(), parent, this, Section.TWISTIE);
196
197 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
198
199 AbstractFormSection nonViralNameSection =
200 formFactory.createCdmDetailSection(DetailType.NONVIRALNAME, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
201
202 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
203
204 AbstractFormSection referenceBaseDetailSection =
205 formFactory.createCdmDetailSection(DetailType.NOMENCLATURALREFERENCE, getConversationHolder(), parent, this, Section.TWISTIE);
206
207 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
208
209 AbstractFormSection nomenclaturalStatusSection =
210 formFactory.createEntityDetailSection(EntityDetailType.NOMENCLATURALSTATUS, getConversationHolder(), parent, Section.TWISTIE);
211
212 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
213
214 AbstractFormSection protologSection =
215 formFactory.createEntityDetailSection(EntityDetailType.PROTOLOG, getConversationHolder(), parent, Section.TWISTIE);
216
217 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
218
219 AbstractFormSection typeDesignationSection =
220 formFactory.createEntityDetailSection(EntityDetailType.TYPEDESIGNATION, getConversationHolder(), parent, Section.TWISTIE);
221
222 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
223
224 AbstractFormSection nameRelationshipSection =
225 formFactory.createEntityDetailSection(EntityDetailType.NAME_RELATIONSHIP, getConversationHolder(), parent, Section.TWISTIE);
226
227 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
228
229 AbstractFormSection parsingMessagesSection =
230 formFactory.createCdmDetailSection(DetailType.PARSINGMESSAGE, getConversationHolder(), parent, this, Section.EXPANDED);
231
232
233
234 addPart(taxonBaseDetailSection);
235 addPart(nonViralNameSection);
236 addPart(nomenclaturalStatusSection);
237 addPart(protologSection);
238 addPart(referenceBaseDetailSection);
239 addPart(typeDesignationSection);
240 addPart(parsingMessagesSection);
241 addPart(nameRelationshipSection);
242 }
243
244 private void createNameSections(RootElement parent) {
245 destroySections();
246 AbstractFormSection nonViralNameSection =
247 formFactory.createCdmDetailSection(DetailType.NONVIRALNAME, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
248
249 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
250
251 AbstractFormSection referenceBaseDetailSection =
252 formFactory.createCdmDetailSection(DetailType.NOMENCLATURALREFERENCE, getConversationHolder(), parent, this, Section.TWISTIE);
253
254 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
255
256 AbstractFormSection nomenclaturalStatusSection =
257 formFactory.createEntityDetailSection(EntityDetailType.NOMENCLATURALSTATUS, getConversationHolder(), parent, Section.TWISTIE);
258
259 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
260
261 AbstractFormSection protologSection =
262 formFactory.createEntityDetailSection(EntityDetailType.PROTOLOG, getConversationHolder(), parent, Section.TWISTIE);
263
264 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
265
266 AbstractFormSection typeDesignationSection =
267 formFactory.createEntityDetailSection(EntityDetailType.TYPEDESIGNATION, getConversationHolder(), parent, Section.TWISTIE);
268
269 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
270
271 AbstractFormSection nameRelationshipSection =
272 formFactory.createEntityDetailSection(EntityDetailType.NAME_RELATIONSHIP, getConversationHolder(), parent, Section.TWISTIE);
273
274 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
275
276 addPart(nonViralNameSection);
277 addPart(nomenclaturalStatusSection);
278 addPart(protologSection);
279 addPart(referenceBaseDetailSection);
280 addPart(typeDesignationSection);
281 addPart(nameRelationshipSection);
282 }
283
284 private void createReferenceSections(RootElement parent) {
285 destroySections();
286 AbstractFormSection referenceBaseDetailSection =
287 formFactory.createCdmDetailSection(DetailType.REFERENCEBASE, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
288 addPart(referenceBaseDetailSection);
289 }
290
291 private void createTeamOrPersonBaseDetailSection(RootElement parent) {
292 destroySections();
293 AbstractFormSection teamOrPersonBaseDetailSection =
294 formFactory.createCdmDetailSection(DetailType.TEAMORPERSONBASE, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
295
296 addPart(teamOrPersonBaseDetailSection);
297 }
298
299 private void createTeamDetailSection(RootElement parent){
300 destroySections();
301 AbstractFormSection teamDetailSection =
302 formFactory.createCdmDetailSection(DetailType.TEAM, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
303
304 addPart(teamDetailSection);
305 }
306
307
308 private void createPersonDetailSection(RootElement parent) {
309 destroySections();
310 AbstractFormSection personDetailSection =
311 formFactory.createCdmDetailSection(DetailType.PERSON, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
312 addPart(personDetailSection);
313 }
314
315 private void createDescriptionElementSection(RootElement parent) {
316 destroySections();
317
318 AbstractFormSection descriptionElementDetailSection =
319 formFactory.createCdmDetailSection(DetailType.DESCRIPTIONELEMENT, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
320
321 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
322
323 AbstractFormSection descriptionElementSourceSection =
324 formFactory.createEntityDetailSection(EntityDetailType.DESCRIPTIONELEMENTSOURCE, getConversationHolder(), parent, Section.TWISTIE);
325
326 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
327
328 AbstractFormSection descriptionElementMediaSection =
329 formFactory.createEntityDetailSection(EntityDetailType.DESCRIPTIONELEMENTMEDIA, getConversationHolder(), parent, Section.TWISTIE);
330
331 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
332
333 addPart(descriptionElementDetailSection);
334 addPart(descriptionElementSourceSection);
335 addPart(descriptionElementMediaSection);
336 }
337
338 private void createDescriptionSection(RootElement parent) {
339 destroySections();
340 AbstractFormSection descriptionDetailSection =
341 formFactory.createCdmDetailSection(DetailType.DESCRIPTION, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
342
343 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
344
345 AbstractFormSection naturalLanguageSection =
346 formFactory.createCdmDetailSection(DetailType.NATURAL_LANGUAGE, getConversationHolder(), parent, this,Section.TWISTIE | Section.EXPANDED);
347
348 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
349
350 AbstractFormSection describedSpecimenSection =
351 formFactory.createEntityDetailSection(EntityDetailType.DESCRIBED_SPECIMEN, getConversationHolder(), parent, Section.TWISTIE);
352
353 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
354
355 AbstractFormSection descriptionSourceSection =
356 formFactory.createEntityDetailSection(EntityDetailType.DESCRIPTIONSOURCE, getConversationHolder(), parent, Section.TWISTIE);
357
358 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
359
360 AbstractFormSection scopeSection =
361 formFactory.createEntityDetailSection(EntityDetailType.SCOPE, getConversationHolder(), parent, Section.TWISTIE);
362
363 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
364
365 addPart(descriptionDetailSection);
366 addPart(naturalLanguageSection);
367 addPart(describedSpecimenSection);
368 addPart(descriptionSourceSection);
369 addPart(scopeSection);
370 }
371
372
373 private void createMediaElementSection(RootElement parent) {
374 destroySections();
375 AbstractFormSection mediaDetailSection = formFactory.createCdmDetailSection(DetailType.MEDIA, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
376
377 addPart(mediaDetailSection);
378 }
379
380 private void createDerivedUnitBaseElementSection(RootElement parent){
381 destroySections();
382
383 AbstractFormSection derivedUnitBaseElementSection = formFactory.createCdmDetailSection(DetailType.DERIVED_UNIT_FACADE, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
384
385 addPart(derivedUnitBaseElementSection);
386 }
387
388 private void createFieldObservationElementSection(RootElement parent){
389 destroySections();
390
391 AbstractFormSection fieldObservationElementSection = formFactory.createCdmDetailSection(DetailType.FIELD_OBSERVATION, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
392
393 addPart(fieldObservationElementSection);
394 }
395
396 /**
397 * @param rootElement
398 */
399 private void createFeatureDistributionSection(RootElement parent) {
400 destroySections();
401
402 AbstractFormSection featureDistributionSection =formFactory.createCdmDetailSection(DetailType.FEATURE_DISTRIBUTION, getConversationHolder(), parent, this, Section.TWISTIE | Section.EXPANDED);
403
404 addPart(featureDistributionSection);
405 }
406 }