AT: commiting recent merge from trunk
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / userecords / UseRecordsViewer.java
1 package eu.etaxonomy.taxeditor.view.userecords;
2
3 import org.eclipse.jface.viewers.ISelection;
4 import org.eclipse.jface.viewers.SelectionChangedEvent;
5 import org.eclipse.swt.SWT;
6 import org.eclipse.swt.widgets.Composite;
7 import org.eclipse.ui.forms.widgets.Section;
8
9 import eu.etaxonomy.cdm.model.common.TermVocabulary;
10 import eu.etaxonomy.cdm.model.description.DescriptionBase;
11 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
12 import eu.etaxonomy.cdm.model.reference.Reference;
13 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
14 import eu.etaxonomy.taxeditor.ui.element.RootElement;
15 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.DetailType;
16 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory.EntityDetailType;
17 import eu.etaxonomy.taxeditor.ui.section.description.DescribedSpecimenSection;
18 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionDetailSection;
19 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailSection;
20 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementMediaSection;
21 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceSection;
22 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceSection;
23 import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageSection;
24 import eu.etaxonomy.taxeditor.ui.section.description.ScopeSection;
25 import eu.etaxonomy.taxeditor.ui.section.name.NameRelationshipDetailSection;
26 import eu.etaxonomy.taxeditor.ui.section.name.NomenclaturalStatusSection;
27 import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
28 import eu.etaxonomy.taxeditor.ui.section.name.ProtologueSection;
29 import eu.etaxonomy.taxeditor.ui.section.name.TypeDesignationSection;
30 import eu.etaxonomy.taxeditor.ui.section.reference.NomenclaturalReferenceDetailSection;
31 import eu.etaxonomy.taxeditor.ui.section.reference.ReferenceDetailSection;
32 import eu.etaxonomy.taxeditor.ui.section.taxon.ParsingMessagesSection;
33 import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonBaseDetailSection;
34 import eu.etaxonomy.taxeditor.ui.section.userecords.UseRecordDetailSection;
35 import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermVocabularyDetailSection;
36 import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
37 import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
38
39
40
41
42
43 public class UseRecordsViewer extends AbstractCdmDataViewer {
44
45 private ISelection selection;
46
47 public UseRecordsViewer(Composite parent, AbstractCdmViewPart viewPart) {
48 super(parent, viewPart);
49 }
50 @Override
51 protected void showParts() {
52 if (getInput() instanceof TaxonBase) {
53 createTaxonSections(rootElement);
54
55 } else if (getInput() instanceof DescriptionBase) {
56 if (((DescriptionBase) getInput()).isImageGallery()) {
57 createImageGallerySection(rootElement);
58
59 } else {
60 createUseSection(rootElement);
61
62 }
63 } else if (getInput() instanceof DescriptionElementBase) {
64 createUseRecordSection(rootElement);
65
66 } else if (getInput() instanceof TermVocabulary) {
67 createTermVocabularySection(rootElement);
68
69 }
70
71 /*if (getInput() instanceof TaxonBase) {
72 if (currentViewPart != VIEW_PART.TAXON) {
73 createTaxonSections(rootElement);
74 currentViewPart = VIEW_PART.TAXON;
75 }
76 } else if (getInput() instanceof Reference) {
77 if (currentViewPart != VIEW_PART.REFEERENCE) {
78 createReferenceSections(rootElement);
79 currentViewPart = VIEW_PART.REFEERENCE;
80 }
81 } else if (getInput() instanceof DescriptionBase) {
82 if (((DescriptionBase) getInput()).isImageGallery()) {
83 if (currentViewPart != VIEW_PART.IMAGE_GALLERY) {
84 createImageGallerySection(rootElement);
85 currentViewPart = VIEW_PART.IMAGE_GALLERY;
86 }
87 } else {
88 if (currentViewPart != VIEW_PART.DESCRIPTION) {
89 createDescriptionSection(rootElement);
90 currentViewPart = VIEW_PART.DESCRIPTION;
91 }
92 }
93 } else if (getInput() instanceof DescriptionElementBase) {
94 if (currentViewPart != VIEW_PART.DESCRIPTION_ELEMENT) {
95 createDescriptionElementSection(rootElement);
96 currentViewPart = VIEW_PART.DESCRIPTION_ELEMENT;
97 }
98 } else {
99 destroySections();
100 currentViewPart = VIEW_PART.EMPTY;
101 }
102 layout();
103 */
104 }
105 private void createTaxonSections(RootElement parent) {
106 destroySections();
107
108 TaxonBaseDetailSection taxonBaseDetailSection = (TaxonBaseDetailSection) formFactory
109 .createCdmDetailSection(DetailType.TAXONBASE,
110 getConversationHolder(), parent, this, Section.TWISTIE);
111
112 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
113
114 NonViralNameDetailSection nonViralNameSection = (NonViralNameDetailSection) formFactory
115 .createCdmDetailSection(DetailType.NONVIRALNAME,
116 getConversationHolder(), parent, this, Section.TWISTIE
117 | Section.EXPANDED);
118
119 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
120
121 NomenclaturalReferenceDetailSection referenceDetailSection = (NomenclaturalReferenceDetailSection) formFactory
122 .createCdmDetailSection(DetailType.NOMENCLATURALREFERENCE,
123 getConversationHolder(), parent, this, Section.TWISTIE);
124
125 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
126
127 NomenclaturalStatusSection nomenclaturalStatusSection = (NomenclaturalStatusSection) formFactory
128 .createEntityDetailSection(
129 EntityDetailType.NOMENCLATURALSTATUS,
130 getConversationHolder(), parent, Section.TWISTIE);
131
132 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
133
134 ProtologueSection protologSection = (ProtologueSection) formFactory
135 .createEntityDetailSection(EntityDetailType.PROTOLOG,
136 getConversationHolder(), parent, Section.TWISTIE);
137
138 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
139
140 TypeDesignationSection typeDesignationSection = (TypeDesignationSection) formFactory
141 .createEntityDetailSection(EntityDetailType.TYPEDESIGNATION,
142 getConversationHolder(), parent, Section.TWISTIE);
143
144 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
145
146 NameRelationshipDetailSection nameRelationshipSection = (NameRelationshipDetailSection) formFactory
147 .createEntityDetailSection(EntityDetailType.NAME_RELATIONSHIP,
148 getConversationHolder(), parent, Section.TWISTIE);
149
150 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
151
152 ParsingMessagesSection parsingMessagesSection = (ParsingMessagesSection) formFactory
153 .createCdmDetailSection(DetailType.PARSINGMESSAGE,
154 getConversationHolder(), parent, this, Section.EXPANDED);
155
156 addPart(taxonBaseDetailSection);
157 addPart(nonViralNameSection);
158 addPart(nomenclaturalStatusSection);
159 addPart(protologSection);
160 addPart(referenceDetailSection);
161 addPart(typeDesignationSection);
162 addPart(nameRelationshipSection);
163 addPart(parsingMessagesSection);
164 }
165
166 private void createTermVocabularySection(RootElement parent) {
167 destroySections();
168
169 TermVocabularyDetailSection termVocabularyDetailSection = (TermVocabularyDetailSection) formFactory
170 .createCdmDetailSection(DetailType.TERM_VOCABULARY,
171 getConversationHolder(), parent, this, Section.TWISTIE
172 | Section.EXPANDED);
173 addPart(termVocabularyDetailSection);
174 }
175
176 private void createUseRecordSection(RootElement parent) {
177 destroySections();
178
179 UseRecordDetailSection descriptionUseRecordSection = (UseRecordDetailSection) formFactory
180 .createCdmDetailSection(DetailType.USE_RECORD,
181 getConversationHolder(), parent, this, Section.TWISTIE
182 | Section.EXPANDED);
183
184 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
185
186 addPart(descriptionUseRecordSection);
187
188
189 }
190
191 private void createUseSection(RootElement parent) {
192 destroySections();
193 DescriptionDetailSection descriptionDetailSection = (DescriptionDetailSection) formFactory
194 .createCdmDetailSection(DetailType.DESCRIPTION,
195 getConversationHolder(), parent, this, Section.TWISTIE
196 | Section.EXPANDED);
197
198 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
199
200 /*NaturalLanguageSection naturalLanguageSection = (NaturalLanguageSection) formFactory
201 .createCdmDetailSection(DetailType.NATURAL_LANGUAGE,
202 getConversationHolder(), parent, this, Section.TWISTIE
203 | Section.EXPANDED);
204
205 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
206
207 DescribedSpecimenSection describedSpecimenSection = (DescribedSpecimenSection) formFactory
208 .createEntityDetailSection(EntityDetailType.DESCRIBED_SPECIMEN,
209 getConversationHolder(), parent, Section.TWISTIE);
210
211 formFactory.createHorizontalSeparator(parent, SWT.BORDER);*/
212
213 DescriptionSourceSection descriptionSourceSection = (DescriptionSourceSection) formFactory
214 .createEntityDetailSection(EntityDetailType.DESCRIPTIONSOURCE,
215 getConversationHolder(), parent, Section.TWISTIE);
216
217 /*formFactory.createHorizontalSeparator(parent, SWT.BORDER);
218
219 ScopeSection scopeSection = (ScopeSection) formFactory
220 .createEntityDetailSection(EntityDetailType.SCOPE,
221 getConversationHolder(), parent, Section.TWISTIE);
222
223 formFactory.createHorizontalSeparator(parent, SWT.BORDER);*/
224
225 addPart(descriptionDetailSection);
226 addPart(descriptionSourceSection);
227
228 }
229
230
231
232 private void createImageGallerySection(RootElement parent) {
233 destroySections();
234 DescriptionDetailSection descriptionDetailSection = (DescriptionDetailSection) formFactory
235 .createCdmDetailSection(DetailType.DESCRIPTION,
236 getConversationHolder(), parent, this, Section.TWISTIE
237 | Section.EXPANDED);
238
239 addPart(descriptionDetailSection);
240 }
241
242 private void createReferenceSections(RootElement parent) {
243 destroySections();
244
245 ReferenceDetailSection referenceDetailSection = (ReferenceDetailSection) formFactory
246 .createCdmDetailSection(DetailType.REFERENCEBASE,
247 getConversationHolder(), parent, this, Section.TWISTIE
248 | Section.EXPANDED);
249
250 addPart(referenceDetailSection);
251
252 }
253 @Override
254 public ISelection getSelection() {
255 return selection;
256 }
257 @Override
258 public void setSelection(ISelection selection, boolean reveal) {
259 this.selection = selection;
260 SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(
261 this, selection);
262 fireSelectionChanged(selectionChangedEvent);
263 }
264
265 }