Project

General

Profile

Download (7.04 KB) Statistics
| Branch: | Tag: | Revision:
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.ExpandableComposite;
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.preference.IPreferenceKeys;
27
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
28
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
29
import eu.etaxonomy.taxeditor.ui.element.RootElement;
30
import eu.etaxonomy.taxeditor.ui.section.media.MediaSection;
31
import eu.etaxonomy.taxeditor.ui.section.supplemental.AnnotationSection;
32
import eu.etaxonomy.taxeditor.ui.section.supplemental.CdmBaseSection;
33
import eu.etaxonomy.taxeditor.ui.section.supplemental.CreditSection;
34
import eu.etaxonomy.taxeditor.ui.section.supplemental.ExtensionSection;
35
import eu.etaxonomy.taxeditor.ui.section.supplemental.HeadlineSection;
36
import eu.etaxonomy.taxeditor.ui.section.supplemental.MarkerSection;
37
import eu.etaxonomy.taxeditor.ui.section.supplemental.RightsSection;
38
import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
39
import eu.etaxonomy.taxeditor.ui.section.supplemental.VersionSection;
40
import eu.etaxonomy.taxeditor.view.AbstractCdmDataViewer;
41
import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart;
42
import eu.etaxonomy.taxeditor.view.detail.DetailsViewer;
43

    
44
/**
45
 * <p>SupplementalDataViewer class.</p>
46
 *
47
 * @author n.hoffmann
48
 * @created Feb 12, 2010
49
 * @version 1.0
50
 */
51
public class SupplementalDataViewer extends AbstractCdmDataViewer implements ISelectionChangedListener {
52

    
53
	private boolean showDebug;
54

    
55

    
56
	/**
57
	 * <p>Constructor for SupplementalDataViewer.</p>
58
	 *
59
	 * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
60
	 * @param viewPart a {@link eu.etaxonomy.taxeditor.view.AbstractCdmViewPart} object.
61
	 */
62
	public SupplementalDataViewer(Composite parent, AbstractCdmViewPart viewPart) {
63
		super(parent, viewPart);
64
	}
65

    
66

    
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.jface.viewers.Viewer#getSelection()
69
	 */
70
	/** {@inheritDoc} */
71
	@Override
72
	public ISelection getSelection() {
73
		return null;
74
	}
75

    
76
	/* (non-Javadoc)
77
	 * @see org.eclipse.jface.viewers.Viewer#setSelection(org.eclipse.jface.viewers.ISelection, boolean)
78
	 */
79
	/** {@inheritDoc} */
80
	@Override
81
	public void setSelection(ISelection selection, boolean reveal) {
82

    
83
	}
84

    
85
	/* (non-Javadoc)
86
	 * @see eu.etaxonomy.taxeditor.editor.view.AbstractDetailsViewer#showParts(eu.etaxonomy.cdm.model.common.AnnotatableEntity)
87
	 */
88
	/** {@inheritDoc} */
89
	@Override
90
	protected void showParts() {
91

    
92
		showDebug = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_DEBUG_INFORMATION);
93

    
94
		Object input;
95

    
96
		if(getInput() instanceof IElementHasDetails){
97
			input = ((IElementHasDetails) getInput()).getData();
98
		}else{
99
			input = getInput();
100
		}
101

    
102
		destroySections();
103
		//1. Headline
104
		createHeadlineSection(rootElement);
105
		//2. Annotatable entitiy
106
		if(input instanceof AnnotatableEntity){
107
				createAnnotationSections(rootElement);
108
		}
109
		//3. Identifiable entity
110
		if(input instanceof IdentifiableEntity){
111
			createIdentifiableSections(rootElement);
112
		}
113
		//4. Identifiable media entity
114
		if(input instanceof IdentifiableMediaEntity){
115
			createIdentifiableMediaSections(rootElement);
116
		}
117
		//5. Versionable
118
		if(input instanceof VersionableEntity){
119
				createVersionSection(rootElement);
120
		}
121
		//6. CdmBase
122
		if(showDebug){
123
			createCdmBaseSection(rootElement);
124
		}
125

    
126
		layout();
127
	}
128

    
129

    
130

    
131
	private void createHeadlineSection(RootElement parent){
132
		HeadlineSection headlineSection = formFactory.createHeadlineSection(parent);
133
		addPart(headlineSection);
134
	}
135

    
136
    private void createAnnotationSections(RootElement parent) {
137
        AnnotationSection annotationSection = formFactory.createAnnotationSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
138

    
139
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
140

    
141
        MarkerSection markerSection = formFactory.createMarkerSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
142

    
143
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
144

    
145
        addPart(annotationSection);
146
        addPart(markerSection);
147
    }
148

    
149
    private void createIdentifiableSections(RootElement parent) {
150
        CreditSection creditSection = formFactory.createCreditSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
151

    
152
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
153

    
154
        ExtensionSection extensionSection = formFactory.createExtensionSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
155

    
156
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
157

    
158
        RightsSection rightsSection = formFactory.createRightsSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
159

    
160
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
161

    
162
        SourceSection sourceSection = formFactory.createSourceSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
163

    
164
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
165

    
166
        addPart(creditSection);
167
        addPart(extensionSection);
168
        addPart(rightsSection);
169
        addPart(sourceSection);
170

    
171
	}
172

    
173
    private void createIdentifiableMediaSections(RootElement parent) {
174
        MediaSection mediaSection = formFactory.createMediaSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
175

    
176
        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
177

    
178
        addPart(mediaSection);
179
    }
180

    
181
	private void createVersionSection(RootElement parent){
182
		VersionSection versionSection = formFactory.createVersionSection(parent, ExpandableComposite.NO_TITLE | ExpandableComposite.EXPANDED);
183
		addPart(versionSection);
184
	}
185

    
186
	/**
187
	 * @param rootElement
188
	 */
189
	private void createCdmBaseSection(RootElement parent) {
190

    
191
		CdmBaseSection cdmBaseSection = formFactory.createCdmBaseSection(parent, ExpandableComposite.NO_TITLE | ExpandableComposite.EXPANDED);
192
		addPart(cdmBaseSection);
193
	}
194

    
195
	/*
196
	 * (non-Javadoc)
197
	 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
198
	 */
199
	/** {@inheritDoc} */
200
	@Override
201
    public void selectionChanged(SelectionChangedEvent event) {
202
		if(event.getSource() instanceof DetailsViewer){
203
			if(event.getSelection() == CdmFormFactory.EMPTY_SELECTION){
204
				setInput(null);
205
				return;
206
			}
207

    
208
			IStructuredSelection selection = (IStructuredSelection) event.getSelection();
209
			setInput(selection.getFirstElement());
210
		}
211
	}
212
}
(2-2/2)