Merged refactoring from development branch.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / 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.view.supplementaldata;
12
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.ISelectionChangedListener;
15 import org.eclipse.jface.viewers.IStructuredSelection;
16 import org.eclipse.jface.viewers.SelectionChangedEvent;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.ui.forms.widgets.Section;
20
21 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
22 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
23 import eu.etaxonomy.cdm.model.common.VersionableEntity;
24 import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
25 import eu.etaxonomy.taxeditor.model.IElementHasDetails;
26 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
27 import eu.etaxonomy.taxeditor.ui.forms.RootElement;
28 import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.EntityDetailType;
29 import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationSection;
30 import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditSection;
31 import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionSection;
32 import eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection;
33 import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerSection;
34 import eu.etaxonomy.taxeditor.ui.section.supplemental.MediaSection;
35 import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsSection;
36 import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
37 import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection;
38 import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
39 import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
40 import eu.etaxonomy.taxeditor.view.detail.DetailsViewer;
41
42 /**
43 * <p>SupplementalDataViewer class.</p>
44 *
45 * @author n.hoffmann
46 * @created Feb 12, 2010
47 * @version 1.0
48 */
49 public class SupplementalDataViewer extends AbstractCdmDataViewer implements ISelectionChangedListener {
50
51 private enum VIEW_PART{
52 VersionableEntity,
53 AnnotatableEntity,
54 IdentifiableEntity,
55 IdentifiableMediaEntity,
56 EMPTY;
57 }
58
59 private VIEW_PART currentViewPart;
60
61
62 /**
63 * <p>Constructor for SupplementalDataViewer.</p>
64 *
65 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
66 * @param viewPart a {@link eu.etaxonomy.taxeditor.view.AbstractCdmViewPart} object.
67 */
68 public SupplementalDataViewer(Composite parent, AbstractCdmViewPart viewPart) {
69 super(parent, viewPart);
70 }
71
72
73 /* (non-Javadoc)
74 * @see org.eclipse.jface.viewers.Viewer#getSelection()
75 */
76 /** {@inheritDoc} */
77 @Override
78 public ISelection getSelection() {
79 return null;
80 }
81
82 /* (non-Javadoc)
83 * @see org.eclipse.jface.viewers.Viewer#setSelection(org.eclipse.jface.viewers.ISelection, boolean)
84 */
85 /** {@inheritDoc} */
86 @Override
87 public void setSelection(ISelection selection, boolean reveal) {
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 IElementHasDetails){
101 input = ((IElementHasDetails) 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 AnnotationSection annotationSection = (AnnotationSection)
146 formFactory.createEntityDetailSection(EntityDetailType.ANNOTATION, getConversationHolder(), parent, Section.TWISTIE);
147
148 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
149
150 MarkerSection markerSection = (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 CreditSection creditSection = (CreditSection)
166 formFactory.createEntityDetailSection(EntityDetailType.CREDIT, getConversationHolder(), parent, Section.TWISTIE);
167
168 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
169
170 ExtensionSection extensionSection = (ExtensionSection)
171 formFactory.createEntityDetailSection(EntityDetailType.EXTENSION, getConversationHolder(), parent, Section.TWISTIE);
172
173 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
174
175 RightsSection rightsSection = (RightsSection)
176 formFactory.createEntityDetailSection(EntityDetailType.RIGHTS, getConversationHolder(), parent, Section.TWISTIE);
177
178 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
179
180 SourceSection sourceSection = (SourceSection)
181 formFactory.createEntityDetailSection(EntityDetailType.SOURCE, getConversationHolder(), parent, Section.TWISTIE);
182
183 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
184
185 addPart(creditSection);
186 addPart(extensionSection);
187 addPart(rightsSection);
188 addPart(sourceSection);
189
190 if(currentViewPart == VIEW_PART.IdentifiableEntity){
191 createVersionSection(parent);
192 }
193 }
194
195 private void createIdentifiableMediaSections(RootElement parent){
196 createIdentifiableSections(parent);
197 MediaSection mediaSection = (MediaSection)
198 formFactory.createEntityDetailSection(EntityDetailType.MEDIA, getConversationHolder(), parent, Section.TWISTIE);
199
200 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
201
202 addPart(mediaSection);
203
204 if(currentViewPart == VIEW_PART.IdentifiableMediaEntity){
205 createVersionSection(parent);
206 }
207 }
208
209 private void createVersionSection(RootElement parent){
210 VersionSection versionSection = formFactory.createVersionSection(parent, Section.NO_TITLE | Section.EXPANDED);
211 addPart(versionSection);
212 }
213
214 /*
215 * (non-Javadoc)
216 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
217 */
218 /** {@inheritDoc} */
219 public void selectionChanged(SelectionChangedEvent event) {
220 if(event.getSource() instanceof DetailsViewer){
221 if(event.getSelection() == CdmFormFactory.EMPTY_SELECTION){
222 setInput(null);
223 currentViewPart = VIEW_PART.EMPTY;
224 return;
225 }
226
227 IStructuredSelection selection = (IStructuredSelection) event.getSelection();
228 setInput(selection.getFirstElement());
229 }
230 }
231 }