ref #8260: save expansion state for supplemental data
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / e4 / supplementaldata / SupplementalDataViewerE4.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.view.e4.supplementaldata;
11
12 import javax.inject.Inject;
13
14 import org.eclipse.e4.core.di.annotations.Optional;
15 import org.eclipse.e4.ui.di.UIEventTopic;
16 import org.eclipse.jface.viewers.ISelection;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.ui.forms.widgets.ExpandableComposite;
19
20 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
21 import eu.etaxonomy.cdm.model.reference.ISourceable;
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.cdm.persistence.hibernate.CdmDataChangeMap;
26 import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
27 import eu.etaxonomy.taxeditor.model.IElementHasDetails;
28 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
29 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
30 import eu.etaxonomy.taxeditor.ui.element.RootElement;
31 import eu.etaxonomy.taxeditor.ui.section.media.MediaSection;
32 import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationSection;
33 import eu.etaxonomy.taxeditor.ui.section.supplemental.CdmBaseSection;
34 import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditSection;
35 import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionSection;
36 import eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection;
37 import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerSection;
38 import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsSection;
39 import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
40 import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection;
41 import eu.etaxonomy.taxeditor.ui.section.supplemental.identifier.IdentifierSection;
42 import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4;
43
44 /**
45 *
46 * @author pplitzner
47 * @since Aug 10, 2017
48 *
49 */
50 public class SupplementalDataViewerE4 extends AbstractCdmDataViewerE4 {
51
52 private boolean showDebug;
53
54 /** {@inheritDoc} */
55 @Override
56 public ISelection getSelection() {
57 return null;
58 }
59
60 /** {@inheritDoc} */
61 @Override
62 public void setSelection(ISelection selection, boolean reveal) {
63
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 protected void showParts() {
69
70 showDebug = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_DEBUG_INFORMATION);
71
72 Object input;
73
74 if(getInput() instanceof IElementHasDetails){
75 input = ((IElementHasDetails) getInput()).getData();
76 }else{
77 input = getInput();
78 }
79
80 destroySections();
81 //1. Headline
82 createHeadlineSection(rootElement);
83 //2. Annotatable entitiy
84 if(input instanceof AnnotatableEntity){
85 createAnnotationSections(rootElement);
86 }
87 //3. Identifiable entity
88 if(input instanceof IdentifiableEntity){
89 createIdentifiableSections(rootElement);
90 }
91 if(input instanceof ISourceable && !(input instanceof IdentifiableEntity)){
92 createSourceSection(rootElement);
93 }
94 //4. Identifiable media entity
95 if(input instanceof IdentifiableMediaEntity){
96 createIdentifiableMediaSections(rootElement);
97 }
98 //5. Versionable
99 if(input instanceof VersionableEntity){
100 createVersionSection(rootElement);
101 }
102 //6. CdmBase
103 if(showDebug){
104 createCdmBaseSection(rootElement);
105 }
106
107 layout();
108 }
109
110 private void createHeadlineSection(RootElement parent){
111 HeadlineSection headlineSection = formFactory.createHeadlineSection(parent);
112 addPart(headlineSection);
113 }
114
115 private void createSourceSection(RootElement parent){
116 int expandStyle = getSectionStyle(SourceSection.class, false);
117 SourceSection sourceSection = formFactory.createSourceSection(getConversationHolder(), parent, expandStyle);
118 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
119 addPart(sourceSection);
120 }
121
122 private void createAnnotationSections(RootElement parent) {
123 int expandStyle = getSectionStyle(AnnotationSection.class, false);
124 AnnotationSection annotationSection = formFactory.createAnnotationSection(getConversationHolder(), parent, expandStyle);
125
126 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
127 expandStyle = getSectionStyle(MarkerSection.class, false);
128 MarkerSection markerSection = formFactory.createMarkerSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
129
130 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
131
132 addPart(annotationSection);
133 addPart(markerSection);
134 }
135
136 private void createIdentifiableSections(RootElement parent) {
137 int expandStyle = getSectionStyle(SourceSection.class, false);
138 SourceSection sourceSection = formFactory.createSourceSection(getConversationHolder(), parent, expandStyle);
139
140 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
141 expandStyle = getSectionStyle(IdentifierSection.class, false);
142 IdentifierSection identifierSection = formFactory.createIdentifierDetailSection(getConversationHolder(), parent, expandStyle);
143
144 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
145 expandStyle = getSectionStyle(ExtensionSection.class, false);
146 ExtensionSection extensionSection = formFactory.createExtensionSection(getConversationHolder(), parent, expandStyle);
147
148 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
149 expandStyle = getSectionStyle(CreditSection.class, false);
150 CreditSection creditSection = formFactory.createCreditSection(getConversationHolder(), parent, expandStyle);
151
152 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
153 expandStyle = getSectionStyle(RightsSection.class, false);
154 RightsSection rightsSection = formFactory.createRightsSection(getConversationHolder(), parent, expandStyle);
155
156 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
157
158 addPart(sourceSection);
159 addPart(identifierSection);
160 addPart(extensionSection);
161 addPart(creditSection);
162 addPart(rightsSection);
163
164 }
165
166 private void createIdentifiableMediaSections(RootElement parent) {
167 int expandStyle = getSectionStyle(MediaSection.class, false);
168 MediaSection mediaSection = formFactory.createMediaSection(getConversationHolder(), parent, expandStyle);
169
170 formFactory.createHorizontalSeparator(parent, SWT.BORDER);
171
172 addPart(mediaSection);
173 }
174
175 private void createVersionSection(RootElement parent){
176 VersionSection versionSection = formFactory.createVersionSection(parent, ExpandableComposite.NO_TITLE | ExpandableComposite.EXPANDED);
177 addPart(versionSection);
178 }
179
180 private void createCdmBaseSection(RootElement parent) {
181
182 CdmBaseSection cdmBaseSection = formFactory.createCdmBaseSection(parent, ExpandableComposite.NO_TITLE | ExpandableComposite.EXPANDED);
183 addPart(cdmBaseSection);
184 }
185
186 @Override
187 public void update(CdmDataChangeMap arg0) {
188 }
189
190 @Inject
191 @Optional
192 private void updateView(@UIEventTopic(WorkbenchEventConstants.REFRESH_SUPPLEMENTAL)boolean refresh){
193 if(refresh){
194 this.refresh();
195 }
196 }
197 }