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.
9 package eu
.etaxonomy
.taxeditor
.editor
.view
.uses
;
12 import java
.net
.URISyntaxException
;
13 import java
.util
.HashMap
;
15 import java
.util
.UUID
;
17 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
18 import org
.eclipse
.jface
.action
.Action
;
19 import org
.eclipse
.jface
.action
.GroupMarker
;
20 import org
.eclipse
.jface
.action
.IToolBarManager
;
21 import org
.eclipse
.jface
.action
.MenuManager
;
22 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
23 import org
.eclipse
.jface
.viewers
.ISelection
;
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
.IMemento
;
38 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
39 import org
.eclipse
.ui
.IWorkbenchPart
;
41 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
42 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
43 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
44 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
45 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
46 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
47 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
48 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
49 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
50 import eu
.etaxonomy
.cdm
.model
.description
.Modifier
;
51 import eu
.etaxonomy
.cdm
.model
.description
.State
;
52 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
53 import eu
.etaxonomy
.taxeditor
.bulkeditor
.BulkEditor
;
54 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
55 import eu
.etaxonomy
.taxeditor
.editor
.MultiPageTaxonEditor
;
56 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermEditor
;
57 import eu
.etaxonomy
.taxeditor
.editor
.key
.AbstractGraphKeyEditor
;
58 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementDragListener
;
59 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementDropAdapter
;
60 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptionElementTransfer
;
61 import eu
.etaxonomy
.taxeditor
.editor
.view
.descriptive
.DescriptiveViewPart
;
62 import eu
.etaxonomy
.taxeditor
.model
.ContextListenerAdapter
;
63 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainer
;
64 import eu
.etaxonomy
.taxeditor
.model
.FeatureNodeContainerTree
;
65 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
66 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
67 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
68 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
69 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
70 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
71 import eu
.etaxonomy
.taxeditor
.view
.AbstractCdmEditorViewPart
;
75 * The Class create a speific Use View to keep the taxonomic view clean
77 * @created mar 13, 2012
80 public class UsesViewPart
extends DescriptiveViewPart
implements IPartContentHasDetails
, IPartContentHasSupplementalData
{
82 public static final String ID
= "eu.etaxonomy.taxeditor.editor.view.uses";
83 private TreeViewer viewer
;
84 private Map
<TaxonDescription
, FeatureNodeContainerTree
> featureNodeContainerCache
= new HashMap
<TaxonDescription
, FeatureNodeContainerTree
>();
85 private ToggleDescriptionAction showAllElementsAction
;
86 private ToggleDescriptionAction hideAllElementsAction
;
88 private int dndOperations
= DND
.DROP_COPY
| DND
.DROP_MOVE
;
93 public void createViewer(Composite parent
) {
95 viewer
= new TreeViewer(new Tree(parent
, SWT
.MULTI
| SWT
.H_SCROLL
96 | SWT
.V_SCROLL
| SWT
.FULL_SELECTION
));
97 viewer
.setContentProvider(new UsesContentProvider(featureNodeContainerCache
));
98 viewer
.setLabelProvider(new UsesLabelProvider());
100 //viewer.setSorter(new DescriptiveViewerSorter());
102 viewer
.setAutoExpandLevel(2);
106 Transfer
[] transfers
= new Transfer
[] { DescriptionElementTransfer
.getInstance() };
107 viewer
.addDragSupport(dndOperations
, transfers
, new DescriptionElementDragListener(
109 viewer
.addDropSupport(dndOperations
, transfers
,
110 new DescriptionElementDropAdapter(viewer
));
112 // Propagate selection from viewer
113 getSite().setSelectionProvider(viewer
);
115 showAllElementsAction
= new ToggleDescriptionAction(false);
116 hideAllElementsAction
= new ToggleDescriptionAction(true);
118 // Add context menu to tree
127 * @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
131 protected ISelection
getInitialSelection() {
132 if(getEditor() != null){
133 return new StructuredSelection(getEditor().getEditorInput());
136 return super.getInitialSelection();
139 private void createToolbar() {
140 IToolBarManager toolBarManager
= getViewSite().getActionBars().getToolBarManager();
141 toolBarManager
.add(showAllElementsAction
);
142 toolBarManager
.add(hideAllElementsAction
);
146 private void createMenu(){
147 MenuManager menuManager
= new MenuManager();
148 menuManager
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
150 getSite().registerContextMenu(menuManager
, viewer
);
152 // FIXME for some reason this is not working
153 menuManager
.add(showAllElementsAction
);
154 menuManager
.add(hideAllElementsAction
);
156 Control control
= viewer
.getControl();
157 Menu menu
= menuManager
.createContextMenu(control
);
159 control
.setMenu(menu
);
165 public void selectionChanged(IWorkbenchPart part
, ISelection selection
) {
166 if(EditorUtil
.getActiveEditor() == null){
171 if(part
instanceof BulkEditor
){
176 if(part
instanceof AbstractGraphKeyEditor
){
181 if(part
instanceof DefinedTermEditor
){
186 if(part
instanceof MultiPageTaxonEditor
){
187 if(! part
.equals(this.part
)){
188 IEditorInput input
= ((IEditorPart
) part
).getEditorInput();
189 featureNodeContainerCache
.clear();
190 showViewer(part
, new StructuredSelection(input
));
200 public void showViewer(IWorkbenchPart part, IStructuredSelection selection) {
203 Object element = selection.getFirstElement();
205 getViewer().setInput(descService.listTaxonDescriptions((Taxon) element, null, null, null, null, null, null));
212 private class ToggleDescriptionAction
extends Action
{
213 private boolean expanded
;
215 public ToggleDescriptionAction(boolean expand
){
216 super(null, Action
.AS_PUSH_BUTTON
);
218 setImageAndTooltip();
221 private void setImageAndTooltip(){
222 setImageDescriptor(new ImageDescriptor() {
224 public ImageData
getImageData() {
225 setText(expanded ?
"Collapse All" : "Expand All");
226 String resource
= expanded ? ImageResources
.COLLAPSE_ALL
: ImageResources
.EXPAND_ALL
;
227 return ImageResources
.getImage(resource
).getImageData();
231 String toolTipText
= expanded ?
"Collapse all" : "Show all descriptive data";
232 setToolTipText(toolTipText
);
238 viewer
.collapseAll();
242 setImageAndTooltip();
248 public boolean postOperation(CdmBase objectAffectedByOperation
) {
250 return super.postOperation(objectAffectedByOperation
);
255 public void changed(Object object
) {
256 for(FeatureNodeContainerTree containerTree
: featureNodeContainerCache
.values()){
257 containerTree
.buildTree();
261 if(object
instanceof DescriptionElementBase
){
262 DescriptionElementBase descriptionElement
= (DescriptionElementBase
) object
;
263 DescriptionBase description
= descriptionElement
.getInDescription();
264 FeatureNodeContainerTree containerTree
= featureNodeContainerCache
.get(description
);
266 FeatureNodeContainer featureNodeContainer
= containerTree
.getFeatureNodeContainerForDescriptionElement(descriptionElement
);
267 viewer
.expandToLevel(featureNodeContainer
, 1);
272 StructuredSelection selection
= new StructuredSelection(object
);
273 viewer
.setSelection(selection
, true);
276 super.changed(object
);
282 public Viewer
getViewer() {