performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / editor / view / supplementaldata / SupplementalDataViewer.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.supplementaldata;
12
13 import org.apache.log4j.Logger;
14 import org.eclipse.jface.viewers.ISelection;
15 import org.eclipse.jface.viewers.ISelectionChangedListener;
16 import org.eclipse.jface.viewers.IStructuredSelection;
17 import org.eclipse.jface.viewers.SelectionChangedEvent;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.ui.forms.widgets.Section;
21
22 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
23 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
24 import eu.etaxonomy.cdm.model.common.VersionableEntity;
25 import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
26 import eu.etaxonomy.taxeditor.editor.name.AbstractGroupedContainer;
27 import eu.etaxonomy.taxeditor.editor.view.AbstractCdmDataViewer;
28 import eu.etaxonomy.taxeditor.editor.view.detail.DetailsViewer;
29 import eu.etaxonomy.taxeditor.forms.AbstractFormSection;
30 import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
31 import eu.etaxonomy.taxeditor.forms.RootElement;
32 import eu.etaxonomy.taxeditor.forms.CdmFormFactory.EntityDetailType;
33 import eu.etaxonomy.taxeditor.model.AbstractCdmViewPart;
34 import eu.etaxonomy.taxeditor.section.supplemental.HeadlineSection;
35 import eu.etaxonomy.taxeditor.section.supplemental.VersionSection;
36
37 /**
38 * <p>SupplementalDataViewer class.</p>
39 *
40 * @author n.hoffmann
41 * @created Feb 12, 2010
42 * @version 1.0
43 */
44 public class SupplementalDataViewer extends AbstractCdmDataViewer implements ISelectionChangedListener {
45 private static final Logger logger = Logger
46 .getLogger(SupplementalDataViewer.class);
47
48 private enum VIEW_PART{
49 VersionableEntity,
50 AnnotatableEntity,
51 IdentifiableEntity,
52 IdentifiableMediaEntity,
53 EMPTY;
54 }
55
56 private VIEW_PART currentViewPart;
57
58 private DetailsViewer detailsViewer;
59
60
61 /**
62 * <p>Constructor for SupplementalDataViewer.</p>
63 *
64 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
65 * @param viewPart a {@link eu.etaxonomy.taxeditor.model.AbstractCdmViewPart} object.
66 */
67 public SupplementalDataViewer(Composite parent, AbstractCdmViewPart viewPart) {
68 super(parent, viewPart);
69 }
70
71
72 /* (non-Javadoc)
73 * @see org.eclipse.jface.viewers.Viewer#getSelection()
74 */
75 /** {@inheritDoc} */
76 @Override
77 public ISelection getSelection() {
78 return null;
79 }
80
81 /* (non-Javadoc)
82 * @see org.eclipse.jface.viewers.Viewer#setSelection(org.eclipse.jface.viewers.ISelection, boolean)
83 */
84 /** {@inheritDoc} */
85 @Override
86 public void setSelection(ISelection selection, boolean reveal) {
87 // TODO Auto-generated method stub
88
89 }
90
91 /* (non-Javadoc)
92 * @see eu.etaxonomy.taxeditor.editor.view.AbstractDetailsViewer#showParts(eu.etaxonomy.cdm.model.common.AnnotatableEntity)
93 */
94 /** {@inheritDoc} */
95 @Override
96 protected void showParts() {
97
98 Object input;
99
100 if(getInput() instanceof AbstractGroupedContainer){
101 input = ((AbstractGroupedContainer) getInput()).getData();
102 }else{
103 input = getInput();
104 }
105
106 if(input instanceof IdentifiableMediaEntity){
107 if(currentViewPart != VIEW_PART.IdentifiableMediaEntity){
108 currentViewPart = VIEW_PART.IdentifiableMediaEntity;
109 createIdentifiableMediaSections(rootElement);
110 }
111 }else if(input instanceof IdentifiableEntity){
112 if(currentViewPart != VIEW_PART.IdentifiableEntity){
113 currentViewPart = VIEW_PART.IdentifiableEntity;
114 createIdentifiableSections(rootElement);
115 }
116 }else if(input instanceof AnnotatableEntity){
117 if(currentViewPart != VIEW_PART.AnnotatableEntity){
118 currentViewPart = VIEW_PART.AnnotatableEntity;
119 createAnnotationSections(rootElement);
120 }
121 }else if(input instanceof VersionableEntity){
122 if(currentViewPart != VIEW_PART.VersionableEntity){
123 currentViewPart = VIEW_PART.VersionableEntity;
124 createHeadlineSection(rootElement);
125 }
126 }else{
127 currentViewPart = VIEW_PART.EMPTY;
128 }
129
130 layout();
131 }
132
133 private void createHeadlineSection(RootElement parent){
134 destroySections();
135 HeadlineSection headlineSection = formFactory.createHeadlineSection(parent);
136 addPart(headlineSection);
137
138 if(currentViewPart == VIEW_PART.VersionableEntity){
139 createVersionSection(parent);
140 }
141 }
142
143 private void createAnnotationSections(RootElement parent){
144 createHeadlineSection(parent);
145 AbstractFormSection annotationSection =
146 formFactory.createEntityDetailSection(EntityDetailType.ANNOTATION, getConversationHolder(), parent, Section.TWISTIE);
147
148 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
149
150 AbstractFormSection markerSection =
151 formFactory.createEntityDetailSection(EntityDetailType.MARKER, getConversationHolder(), parent, Section.TWISTIE);
152
153 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
154
155 addPart(annotationSection);
156 addPart(markerSection);
157
158 if(currentViewPart == VIEW_PART.AnnotatableEntity){
159 createVersionSection(parent);
160 }
161 }
162
163 private void createIdentifiableSections(RootElement parent){
164 createAnnotationSections(parent);
165 AbstractFormSection creditSection = formFactory.createEntityDetailSection(EntityDetailType.CREDIT, getConversationHolder(), parent, Section.TWISTIE);
166
167 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
168
169 AbstractFormSection extensionSection = formFactory.createEntityDetailSection(EntityDetailType.EXTENSION, getConversationHolder(), parent, Section.TWISTIE);
170
171 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
172
173 AbstractFormSection rightsSection = formFactory.createEntityDetailSection(EntityDetailType.RIGHTS, getConversationHolder(), parent, Section.TWISTIE);
174
175 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
176
177 AbstractFormSection sourceSection = formFactory.createEntityDetailSection(EntityDetailType.SOURCE, getConversationHolder(), parent, Section.TWISTIE);
178
179 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
180
181 addPart(creditSection);
182 addPart(extensionSection);
183 addPart(rightsSection);
184 addPart(sourceSection);
185
186 if(currentViewPart == VIEW_PART.IdentifiableEntity){
187 createVersionSection(parent);
188 }
189 }
190
191 private void createIdentifiableMediaSections(RootElement parent){
192 createIdentifiableSections(parent);
193 AbstractFormSection mediaSection = formFactory.createEntityDetailSection(EntityDetailType.MEDIA, getConversationHolder(), parent, Section.TWISTIE);
194
195 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
196
197 addPart(mediaSection);
198
199 if(currentViewPart == VIEW_PART.IdentifiableMediaEntity){
200 createVersionSection(parent);
201 }
202 }
203
204 private void createVersionSection(RootElement parent){
205 VersionSection versionSection = formFactory.createVersionSection(parent, Section.NO_TITLE | Section.EXPANDED);
206 addPart(versionSection);
207 }
208
209 /*
210 * (non-Javadoc)
211 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
212 */
213 /** {@inheritDoc} */
214 public void selectionChanged(SelectionChangedEvent event) {
215 if(event.getSource() instanceof DetailsViewer){
216 detailsViewer = (DetailsViewer) event.getSource();
217
218 if(event.getSelection() == CdmFormFactory.EMPTY_SELECTION){
219 setInput(null);
220 currentViewPart = VIEW_PART.EMPTY;
221 return;
222 }
223
224 IStructuredSelection selection = (IStructuredSelection) event.getSelection();
225 setInput(selection.getFirstElement());
226 }
227 }
228 }