1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.taxeditor.editor.view.uses;
|
10
|
|
11
|
import java.net.URI;
|
12
|
import java.net.URISyntaxException;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Map;
|
15
|
import java.util.UUID;
|
16
|
|
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;
|
40
|
|
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;
|
72
|
|
73
|
|
74
|
/**
|
75
|
* The Class create a speific Use View to keep the taxonomic view clean
|
76
|
* @author a.theys
|
77
|
* @created mar 13, 2012
|
78
|
* @version 1.0
|
79
|
*/
|
80
|
public class UsesViewPart extends DescriptiveViewPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
|
81
|
|
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;
|
87
|
|
88
|
private int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
|
89
|
|
90
|
|
91
|
/** {@inheritDoc} */
|
92
|
@Override
|
93
|
public void createViewer(Composite parent) {
|
94
|
|
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());
|
99
|
|
100
|
//viewer.setSorter(new DescriptiveViewerSorter());
|
101
|
|
102
|
viewer.setAutoExpandLevel(2);
|
103
|
|
104
|
|
105
|
|
106
|
Transfer[] transfers = new Transfer[] { DescriptionElementTransfer.getInstance() };
|
107
|
viewer.addDragSupport(dndOperations, transfers, new DescriptionElementDragListener(
|
108
|
this));
|
109
|
viewer.addDropSupport(dndOperations, transfers,
|
110
|
new DescriptionElementDropAdapter(viewer));
|
111
|
|
112
|
// Propagate selection from viewer
|
113
|
getSite().setSelectionProvider(viewer);
|
114
|
|
115
|
showAllElementsAction = new ToggleDescriptionAction(false);
|
116
|
hideAllElementsAction = new ToggleDescriptionAction(true);
|
117
|
|
118
|
// Add context menu to tree
|
119
|
createMenu();
|
120
|
|
121
|
createToolbar();
|
122
|
|
123
|
}
|
124
|
|
125
|
|
126
|
/* (non-Javadoc)
|
127
|
* @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
|
128
|
*/
|
129
|
/** {@inheritDoc} */
|
130
|
@Override
|
131
|
protected ISelection getInitialSelection() {
|
132
|
if(getEditor() != null){
|
133
|
return new StructuredSelection(getEditor().getEditorInput());
|
134
|
}
|
135
|
|
136
|
return super.getInitialSelection();
|
137
|
}
|
138
|
|
139
|
private void createToolbar() {
|
140
|
IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
|
141
|
toolBarManager.add(showAllElementsAction);
|
142
|
toolBarManager.add(hideAllElementsAction);
|
143
|
}
|
144
|
|
145
|
|
146
|
private void createMenu(){
|
147
|
MenuManager menuManager = new MenuManager();
|
148
|
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
|
149
|
|
150
|
getSite().registerContextMenu(menuManager, viewer);
|
151
|
|
152
|
// FIXME for some reason this is not working
|
153
|
menuManager.add(showAllElementsAction);
|
154
|
menuManager.add(hideAllElementsAction);
|
155
|
|
156
|
Control control = viewer.getControl();
|
157
|
Menu menu = menuManager.createContextMenu(control);
|
158
|
|
159
|
control.setMenu(menu);
|
160
|
}
|
161
|
|
162
|
|
163
|
|
164
|
@Override
|
165
|
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
166
|
if(EditorUtil.getActiveEditor() == null){
|
167
|
showEmptyPage();
|
168
|
return;
|
169
|
}
|
170
|
|
171
|
if(part instanceof BulkEditor){
|
172
|
showEmptyPage();
|
173
|
return;
|
174
|
}
|
175
|
|
176
|
if(part instanceof AbstractGraphKeyEditor){
|
177
|
showEmptyPage();
|
178
|
return;
|
179
|
}
|
180
|
|
181
|
if(part instanceof DefinedTermEditor){
|
182
|
showEmptyPage();
|
183
|
return;
|
184
|
}
|
185
|
|
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));
|
191
|
}
|
192
|
showViewer();
|
193
|
}
|
194
|
|
195
|
}
|
196
|
|
197
|
|
198
|
|
199
|
/*@Override
|
200
|
public void showViewer(IWorkbenchPart part, IStructuredSelection selection) {
|
201
|
this.part = part;
|
202
|
|
203
|
Object element = selection.getFirstElement();
|
204
|
|
205
|
getViewer().setInput(descService.listTaxonDescriptions((Taxon) element, null, null, null, null, null, null));
|
206
|
|
207
|
showViewer();
|
208
|
}*/
|
209
|
|
210
|
|
211
|
|
212
|
private class ToggleDescriptionAction extends Action{
|
213
|
private boolean expanded;
|
214
|
|
215
|
public ToggleDescriptionAction(boolean expand){
|
216
|
super(null, Action.AS_PUSH_BUTTON);
|
217
|
expanded = expand;
|
218
|
setImageAndTooltip();
|
219
|
}
|
220
|
|
221
|
private void setImageAndTooltip(){
|
222
|
setImageDescriptor(new ImageDescriptor() {
|
223
|
@Override
|
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();
|
228
|
}
|
229
|
});
|
230
|
|
231
|
String toolTipText = expanded ? "Collapse all" : "Show all descriptive data";
|
232
|
setToolTipText(toolTipText);
|
233
|
}
|
234
|
|
235
|
@Override
|
236
|
public void run() {
|
237
|
if(expanded){
|
238
|
viewer.collapseAll();
|
239
|
}else{
|
240
|
viewer.expandAll();
|
241
|
}
|
242
|
setImageAndTooltip();
|
243
|
}
|
244
|
}
|
245
|
|
246
|
/** {@inheritDoc} */
|
247
|
@Override
|
248
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
249
|
viewer.refresh();
|
250
|
return super.postOperation(objectAffectedByOperation);
|
251
|
}
|
252
|
|
253
|
/** {@inheritDoc} */
|
254
|
@Override
|
255
|
public void changed(Object object) {
|
256
|
for(FeatureNodeContainerTree containerTree : featureNodeContainerCache.values()){
|
257
|
containerTree.buildTree();
|
258
|
}
|
259
|
viewer.refresh();
|
260
|
|
261
|
if(object instanceof DescriptionElementBase){
|
262
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
|
263
|
DescriptionBase description = descriptionElement.getInDescription();
|
264
|
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
|
265
|
|
266
|
FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
|
267
|
viewer.expandToLevel(featureNodeContainer, 1);
|
268
|
|
269
|
}
|
270
|
|
271
|
if(object != null){
|
272
|
StructuredSelection selection = new StructuredSelection(object);
|
273
|
viewer.setSelection(selection, true);
|
274
|
}
|
275
|
|
276
|
super.changed(object);
|
277
|
}
|
278
|
|
279
|
|
280
|
/** {@inheritDoc} */
|
281
|
@Override
|
282
|
public Viewer getViewer() {
|
283
|
return viewer;
|
284
|
}
|
285
|
|
286
|
}
|