2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
;
12 import java
.util
.HashMap
;
15 import org
.eclipse
.jface
.action
.Action
;
16 import org
.eclipse
.jface
.action
.GroupMarker
;
17 import org
.eclipse
.jface
.action
.IToolBarManager
;
18 import org
.eclipse
.jface
.action
.MenuManager
;
19 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
20 import org
.eclipse
.jface
.viewers
.ISelection
;
21 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
22 import org
.eclipse
.jface
.viewers
.TreeViewer
;
23 import org
.eclipse
.swt
.SWT
;
24 import org
.eclipse
.swt
.dnd
.DND
;
25 import org
.eclipse
.swt
.dnd
.Transfer
;
26 import org
.eclipse
.swt
.graphics
.ImageData
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Control
;
29 import org
.eclipse
.swt
.widgets
.Menu
;
30 import org
.eclipse
.swt
.widgets
.Tree
;
31 import org
.eclipse
.ui
.IEditorInput
;
32 import org
.eclipse
.ui
.IEditorPart
;
33 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
34 import org
.eclipse
.ui
.IWorkbenchPart
;
36 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
37 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
38 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
39 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
40 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermEditor
;
41 import eu
.etaxonomy
.taxeditor
.editor
.key
.AbstractGraphKeyEditor
;
42 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementDragListener
;
43 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementDropAdapter
;
44 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementTransfer
;
45 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
46 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainerTree
;
47 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
48 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
49 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
53 * <p>UsesViewPart Class.</p>
55 * @created mar 13, 2012
58 public class UsesViewPart
extends DescriptiveViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
60 /** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.desc"{trunked}</code> */
62 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.uses";
64 private TreeViewer viewer
;
66 private Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
= new HashMap
<TaxonDescription
, FeatureNodeContainerTree
>();
68 private ToggleDescriptionAction showAllElementsAction
;
70 private ToggleDescriptionAction hideAllElementsAction
;
72 private int dndOperations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
76 public void createViewer(Composite parent
) {
77 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
78 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
79 viewer
.setContentProvider(new UsesContentProvider(featureNodeContainerCache
));
80 viewer
.setLabelProvider(new UsesLabelProvider());
81 viewer
.setAutoExpandLevel(2);
82 Transfer
[] transfers
= new Transfer
[] { DescriptionElementTransfer
.getInstance() };
83 viewer
.addDragSupport(dndOperations
, transfers
, new DescriptionElementDragListener(
85 viewer
.addDropSupport(dndOperations
, transfers
,
86 new DescriptionElementDropAdapter(viewer
));
87 getSite().setSelectionProvider(viewer
);
88 showAllElementsAction
= new ToggleDescriptionAction(false);
89 hideAllElementsAction
= new ToggleDescriptionAction(true);
96 private void createToolbar() {
97 IToolBarManager toolBarManager
= getViewSite().getActionBars().getToolBarManager();
98 toolBarManager
.add(showAllElementsAction
);
99 toolBarManager
.add(hideAllElementsAction
);
103 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
104 if(EditorUtil
.getActiveEditor() == null){
109 if(part
instanceof BulkEditor
){
114 if(part
instanceof AbstractGraphKeyEditor
){
119 if(part
instanceof DefinedTermEditor
){
124 if(part
instanceof MultiPageTaxonEditor
){
125 if(! part
.equals(this.part
)){
126 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
127 featureNodeContainerCache
.clear();
128 showViewer(part
, new StructuredSelection(input
));
135 private void createMenu(){
136 MenuManager menuManager
= new MenuManager();
137 menuManager
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
139 getSite().registerContextMenu(menuManager
, viewer
);
141 // FIXME for some reason this is not working
142 menuManager
.add(showAllElementsAction
);
143 menuManager
.add(hideAllElementsAction
);
145 Control control
= viewer
.getControl();
146 Menu menu
= menuManager
.createContextMenu(control
);
148 control
.setMenu(menu
);
152 private class ToggleDescriptionAction
extends Action
{
153 private boolean expanded
;
155 public ToggleDescriptionAction(boolean expand
){
156 super(null, Action
.AS_PUSH_BUTTON
);
158 setImageAndTooltip();
161 private void setImageAndTooltip(){
162 setImageDescriptor(new ImageDescriptor() {
164 public ImageData
getImageData() {
165 setText(expanded ?
"Collapse All" : "Expand All");
166 String resource
= expanded ? ImageResources
.COLLAPSE_ALL
: ImageResources
.EXPAND_ALL
;
167 return ImageResources
.getImage(resource
).getImageData();
171 String toolTipText
= expanded ?
"Collapse all" : "Show all descriptive data";
172 setToolTipText(toolTipText
);
178 viewer
.collapseAll();
182 setImageAndTooltip();