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
.IToolBarManager
;
19 import org
.eclipse
.jface
.action
.MenuManager
;
20 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
21 import org
.eclipse
.jface
.viewers
.ISelection
;
22 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
23 import org
.eclipse
.jface
.viewers
.TreeViewer
;
24 import org
.eclipse
.jface
.viewers
.Viewer
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.dnd
.DND
;
27 import org
.eclipse
.swt
.dnd
.Transfer
;
28 import org
.eclipse
.swt
.graphics
.ImageData
;
29 import org
.eclipse
.swt
.widgets
.Composite
;
30 import org
.eclipse
.swt
.widgets
.Control
;
31 import org
.eclipse
.swt
.widgets
.Menu
;
32 import org
.eclipse
.swt
.widgets
.Tree
;
33 import org
.eclipse
.ui
.IEditorInput
;
34 import org
.eclipse
.ui
.IEditorPart
;
35 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
36 import org
.eclipse
.ui
.IWorkbenchPart
;
38 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
39 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
40 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
41 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
42 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
43 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
44 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
45 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermEditor
;
46 import eu
.etaxonomy
.taxeditor
.editor
.key
.AbstractGraphKeyEditor
;
47 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
48 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainerTree
;
49 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
50 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
51 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
52 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
55 * <p>DescriptiveViewPart class.</p>
58 * @created Jun 9, 2010
61 public class DescriptiveViewPart
extends AbstractCdmEditorViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
63 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.desc"{trunked}</code> */
64 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.descriptive";
66 protected TreeViewer viewer
;
68 protected Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
= new HashMap
<TaxonDescription
, FeatureNodeContainerTree
>();
70 protected ToggleDescriptionAction showAllElementsAction
;
72 protected ToggleDescriptionAction hideAllElementsAction
;
74 protected int dndOperations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
78 public void createViewer(Composite parent
) {
79 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
80 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
81 viewer
.setContentProvider(new DescriptiveContentProvider(featureNodeContainerCache
));
82 viewer
.setLabelProvider(new DescriptiveLabelProvider());
83 viewer
.setSorter(new DescriptiveViewerSorter());
84 viewer
.setAutoExpandLevel(2);
85 Transfer
[] transfers
= new Transfer
[] { DescriptionElementTransfer
.getInstance() };
86 viewer
.addDragSupport(dndOperations
, transfers
, new DescriptionElementDragListener(
88 viewer
.addDropSupport(dndOperations
, transfers
,
89 new DescriptionElementDropAdapter(viewer
));
91 // Propagate selection from viewer
92 getSite().setSelectionProvider(viewer
);
94 showAllElementsAction
= new ToggleDescriptionAction(false);
95 hideAllElementsAction
= new ToggleDescriptionAction(true);
97 // Add context menu to tree
103 // if(getEditor() != null){
104 // viewer.setInput(getEditor().getEditorInput());
109 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
113 protected ISelection
getInitialSelection() {
114 if(getEditor() != null){
115 return new StructuredSelection(getEditor().getEditorInput());
118 return super.getInitialSelection();
121 protected void createToolbar() {
122 IToolBarManager toolBarManager
= getViewSite().getActionBars().getToolBarManager();
123 toolBarManager
.add(showAllElementsAction
);
124 toolBarManager
.add(hideAllElementsAction
);
128 * TODO add to the views menu
130 protected void createMenu(){
131 MenuManager menuManager
= new MenuManager();
132 menuManager
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
134 getSite().registerContextMenu(menuManager
, viewer
);
136 // FIXME for some reason this is not working
137 menuManager
.add(showAllElementsAction
);
138 menuManager
.add(hideAllElementsAction
);
140 Control control
= viewer
.getControl();
141 Menu menu
= menuManager
.createContextMenu(control
);
143 control
.setMenu(menu
);
147 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
148 if(EditorUtil
.getActiveEditor() == null){
153 if(part
instanceof BulkEditor
){
158 if(part
instanceof AbstractGraphKeyEditor
){
163 if(part
instanceof DefinedTermEditor
){
168 if(part
instanceof MultiPageTaxonEditor
){
169 if(! part
.equals(this.part
)){
170 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
171 featureNodeContainerCache
.clear();
172 showViewer(part
, new StructuredSelection(input
));
181 * @created May 28, 2010
184 protected class ToggleDescriptionAction
extends Action
{
185 private boolean expanded
;
187 public ToggleDescriptionAction(boolean expand
){
188 super(null, Action
.AS_PUSH_BUTTON
);
190 setImageAndTooltip();
193 private void setImageAndTooltip(){
194 setImageDescriptor(new ImageDescriptor() {
196 public ImageData
getImageData() {
197 setText(expanded ?
"Collapse All" : "Expand All");
198 String resource
= expanded ? ImageResources
.COLLAPSE_ALL
: ImageResources
.EXPAND_ALL
;
199 return ImageResources
.getImage(resource
).getImageData();
203 String toolTipText
= expanded ?
"Collapse all" : "Show all descriptive data";
204 setToolTipText(toolTipText
);
210 viewer
.collapseAll();
214 setImageAndTooltip();
220 public boolean postOperation(CdmBase objectAffectedByOperation
) {
221 return super.postOperation(objectAffectedByOperation
);
226 public void changed(Object object
) {
227 for(FeatureNodeContainerTree containerTree
: featureNodeContainerCache
.values()){
228 containerTree
.buildTree();
232 if(object
instanceof DescriptionElementBase
){
233 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) object
;
234 DescriptionBase description
= descriptionElement
.getInDescription();
235 FeatureNodeContainerTree containerTree
= featureNodeContainerCache
.get(description
);
237 FeatureNodeContainer featureNodeContainer
= containerTree
.getFeatureNodeContainerForDescriptionElement(descriptionElement
);
238 viewer
.expandToLevel(featureNodeContainer
, 1);
243 StructuredSelection selection
= new StructuredSelection(object
);
244 viewer
.setSelection(selection
, true);
247 super.changed(object
);
252 public Viewer
getViewer() {
261 public boolean onComplete() {