3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
;
13 import java
.util
.HashMap
;
16 import org
.eclipse
.jface
.action
.Action
;
17 import org
.eclipse
.jface
.action
.GroupMarker
;
18 import org
.eclipse
.jface
.action
.IAction
;
19 import org
.eclipse
.jface
.action
.IToolBarManager
;
20 import org
.eclipse
.jface
.action
.MenuManager
;
21 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
22 import org
.eclipse
.jface
.viewers
.ISelection
;
23 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
24 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
25 import org
.eclipse
.jface
.viewers
.TreeViewer
;
26 import org
.eclipse
.jface
.viewers
.Viewer
;
27 import org
.eclipse
.swt
.SWT
;
28 import org
.eclipse
.swt
.dnd
.DND
;
29 import org
.eclipse
.swt
.dnd
.Transfer
;
30 import org
.eclipse
.swt
.graphics
.ImageData
;
31 import org
.eclipse
.swt
.widgets
.Composite
;
32 import org
.eclipse
.swt
.widgets
.Control
;
33 import org
.eclipse
.swt
.widgets
.Menu
;
34 import org
.eclipse
.swt
.widgets
.Tree
;
35 import org
.eclipse
.ui
.IEditorInput
;
36 import org
.eclipse
.ui
.IEditorPart
;
37 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
38 import org
.eclipse
.ui
.IWorkbenchPart
;
40 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
41 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
42 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
43 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
44 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
45 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
46 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermEditor
;
47 import eu
.etaxonomy
.taxeditor
.editor
.key
.AbstractGraphKeyEditor
;
48 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
49 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
50 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainerTree
;
51 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
52 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
53 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
54 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
57 * <p>DescriptiveViewPart class.</p>
60 * @created Jun 9, 2010
63 public class DescriptiveViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
65 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.desc"{trunked}</code> */
66 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.descriptive";
68 protected TreeViewer viewer
;
71 * Maps {@link FeatureNodeContainerTree} to their corresponding {@link TaxonDescritpion}.<br>
72 * This serves as input for the {@link ITreeContentProvider} of the {@link TreeViewer}
74 protected Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
= new HashMap
<TaxonDescription
, FeatureNodeContainerTree
>();
76 protected ToggleDescriptionAction showAllElementsAction
;
78 protected ToggleDescriptionAction hideAllElementsAction
;
80 protected int dndOperations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
84 public void createViewer(Composite parent
) {
85 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
86 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
87 viewer
.setContentProvider(new DescriptiveContentProvider(featureNodeContainerCache
));
88 viewer
.setLabelProvider(new DescriptiveLabelProvider());
89 viewer
.setSorter(new DescriptiveViewerSorter());
90 viewer
.setAutoExpandLevel(2);
91 Transfer
[] transfers
= new Transfer
[] { DescriptionElementTransfer
.getInstance() };
92 viewer
.addDragSupport(dndOperations
, transfers
, new DescriptionElementDragListener(
94 viewer
.addDropSupport(dndOperations
, transfers
,
95 new DescriptionElementDropAdapter(viewer
));
97 // Propagate selection from viewer
98 getSite().setSelectionProvider(viewer
);
100 showAllElementsAction
= new ToggleDescriptionAction(false);
101 hideAllElementsAction
= new ToggleDescriptionAction(true);
103 // Add context menu to tree
109 // if(getEditor() != null){
110 // viewer.setInput(getEditor().getEditorInput());
115 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
119 protected ISelection
getInitialSelection() {
120 if(getEditor() != null){
121 return new StructuredSelection(getEditor().getEditorInput());
124 return super.getInitialSelection();
127 protected void createToolbar() {
128 IToolBarManager toolBarManager
= getViewSite().getActionBars().getToolBarManager();
129 toolBarManager
.add(showAllElementsAction
);
130 toolBarManager
.add(hideAllElementsAction
);
134 * TODO add to the views menu
136 protected void createMenu(){
137 MenuManager menuManager
= new MenuManager();
138 menuManager
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
140 getSite().registerContextMenu(menuManager
, viewer
);
142 // FIXME for some reason this is not working
143 menuManager
.add(showAllElementsAction
);
144 menuManager
.add(hideAllElementsAction
);
146 Control control
= viewer
.getControl();
147 Menu menu
= menuManager
.createContextMenu(control
);
149 control
.setMenu(menu
);
154 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
155 if(AbstractUtility
.getActiveEditor() == null){
160 if(part
instanceof BulkEditor
){
165 if(part
instanceof AbstractGraphKeyEditor
){
170 if(part
instanceof DefinedTermEditor
){
175 if(part
instanceof MultiPageTaxonEditor
){
176 if(! part
.equals(this.part
)){
177 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
178 featureNodeContainerCache
.clear();
179 showViewer(part
, new StructuredSelection(input
));
187 * @created May 28, 2010
190 protected class ToggleDescriptionAction
extends Action
{
191 private final boolean expanded
;
193 public ToggleDescriptionAction(boolean expand
){
194 super(null, IAction
.AS_PUSH_BUTTON
);
196 setImageAndTooltip();
199 private void setImageAndTooltip(){
200 setImageDescriptor(new ImageDescriptor() {
202 public ImageData
getImageData() {
203 setText(expanded ?
"Collapse All" : "Expand All");
204 String resource
= expanded ? ImageResources
.COLLAPSE_ALL
: ImageResources
.EXPAND_ALL
;
205 return ImageResources
.getImage(resource
).getImageData();
209 String toolTipText
= expanded ?
"Collapse all" : "Show all descriptive data";
210 setToolTipText(toolTipText
);
216 viewer
.collapseAll();
220 setImageAndTooltip();
226 public boolean postOperation(CdmBase objectAffectedByOperation
) {
227 return super.postOperation(objectAffectedByOperation
);
232 public void changed(Object object
) {
233 for(FeatureNodeContainerTree containerTree
: featureNodeContainerCache
.values()){
234 containerTree
.buildTree();
238 if(object
instanceof DescriptionElementBase
){
239 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) object
;
240 DescriptionBase description
= descriptionElement
.getInDescription();
241 FeatureNodeContainerTree containerTree
= featureNodeContainerCache
.get(description
);
243 FeatureNodeContainer featureNodeContainer
= containerTree
.getFeatureNodeContainerForDescriptionElement(descriptionElement
);
244 viewer
.expandToLevel(featureNodeContainer
, 1);
249 StructuredSelection selection
= new StructuredSelection(object
);
250 viewer
.setSelection(selection
, true);
253 super.changed(object
);
258 public Viewer
getViewer() {
268 public boolean onComplete() {