1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.editor.view.descriptive;
|
12
|
|
13
|
import java.util.HashMap;
|
14
|
import java.util.Map;
|
15
|
|
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.ITreeContentProvider;
|
23
|
import org.eclipse.jface.viewers.StructuredSelection;
|
24
|
import org.eclipse.jface.viewers.TreeViewer;
|
25
|
import org.eclipse.jface.viewers.Viewer;
|
26
|
import org.eclipse.swt.SWT;
|
27
|
import org.eclipse.swt.dnd.DND;
|
28
|
import org.eclipse.swt.dnd.Transfer;
|
29
|
import org.eclipse.swt.graphics.ImageData;
|
30
|
import org.eclipse.swt.widgets.Composite;
|
31
|
import org.eclipse.swt.widgets.Control;
|
32
|
import org.eclipse.swt.widgets.Menu;
|
33
|
import org.eclipse.swt.widgets.Tree;
|
34
|
import org.eclipse.ui.IEditorInput;
|
35
|
import org.eclipse.ui.IEditorPart;
|
36
|
import org.eclipse.ui.IWorkbenchActionConstants;
|
37
|
import org.eclipse.ui.IWorkbenchPart;
|
38
|
|
39
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
40
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
41
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
42
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
43
|
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
|
44
|
import eu.etaxonomy.taxeditor.editor.EditorUtil;
|
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.FeatureNodeContainer;
|
49
|
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree;
|
50
|
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
|
51
|
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData;
|
52
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
53
|
import eu.etaxonomy.taxeditor.ui.section.taxon.TaxonDetailElement;
|
54
|
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart;
|
55
|
|
56
|
/**
|
57
|
* <p>DescriptiveViewPart class.</p>
|
58
|
*
|
59
|
* @author n.hoffmann
|
60
|
* @created Jun 9, 2010
|
61
|
* @version 1.0
|
62
|
*/
|
63
|
public class DescriptiveViewPart extends AbstractCdmEditorViewPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
|
64
|
|
65
|
/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.desc"{trunked}</code> */
|
66
|
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.descriptive";
|
67
|
|
68
|
protected TreeViewer viewer;
|
69
|
|
70
|
/**
|
71
|
* Maps {@link FeatureNodeContainerTree} to their corresponding {@link TaxonDescritpion}.<br>
|
72
|
* This serves as input for the {@link ITreeContentProvider} of the {@link TreeViewer}
|
73
|
*/
|
74
|
protected Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache = new HashMap<TaxonDescription, FeatureNodeContainerTree>();
|
75
|
|
76
|
protected ToggleDescriptionAction showAllElementsAction;
|
77
|
|
78
|
protected ToggleDescriptionAction hideAllElementsAction;
|
79
|
|
80
|
protected int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
|
81
|
|
82
|
/** {@inheritDoc} */
|
83
|
@Override
|
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(
|
93
|
this));
|
94
|
viewer.addDropSupport(dndOperations, transfers,
|
95
|
new DescriptionElementDropAdapter(viewer));
|
96
|
|
97
|
// Propagate selection from viewer
|
98
|
getSite().setSelectionProvider(viewer);
|
99
|
|
100
|
showAllElementsAction = new ToggleDescriptionAction(false);
|
101
|
hideAllElementsAction = new ToggleDescriptionAction(true);
|
102
|
|
103
|
// Add context menu to tree
|
104
|
createMenu();
|
105
|
|
106
|
createToolbar();
|
107
|
|
108
|
// set initial input
|
109
|
// if(getEditor() != null){
|
110
|
// viewer.setInput(getEditor().getEditorInput());
|
111
|
// }
|
112
|
}
|
113
|
|
114
|
/* (non-Javadoc)
|
115
|
* @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection()
|
116
|
*/
|
117
|
/** {@inheritDoc} */
|
118
|
@Override
|
119
|
protected ISelection getInitialSelection() {
|
120
|
if(getEditor() != null){
|
121
|
return new StructuredSelection(getEditor().getEditorInput());
|
122
|
}
|
123
|
|
124
|
return super.getInitialSelection();
|
125
|
}
|
126
|
|
127
|
protected void createToolbar() {
|
128
|
IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
|
129
|
toolBarManager.add(showAllElementsAction);
|
130
|
toolBarManager.add(hideAllElementsAction);
|
131
|
}
|
132
|
|
133
|
/*
|
134
|
* TODO add to the views menu
|
135
|
*/
|
136
|
protected void createMenu(){
|
137
|
MenuManager menuManager = new MenuManager();
|
138
|
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
|
139
|
|
140
|
getSite().registerContextMenu(menuManager, viewer);
|
141
|
|
142
|
// FIXME for some reason this is not working
|
143
|
menuManager.add(showAllElementsAction);
|
144
|
menuManager.add(hideAllElementsAction);
|
145
|
|
146
|
Control control = viewer.getControl();
|
147
|
Menu menu = menuManager.createContextMenu(control);
|
148
|
|
149
|
control.setMenu(menu);
|
150
|
}
|
151
|
|
152
|
/** {@inheritDoc} */
|
153
|
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
154
|
if(EditorUtil.getActiveEditor() == null){
|
155
|
showEmptyPage();
|
156
|
return;
|
157
|
}
|
158
|
|
159
|
if(part instanceof BulkEditor){
|
160
|
showEmptyPage();
|
161
|
return;
|
162
|
}
|
163
|
|
164
|
if(part instanceof AbstractGraphKeyEditor){
|
165
|
showEmptyPage();
|
166
|
return;
|
167
|
}
|
168
|
|
169
|
if(part instanceof DefinedTermEditor){
|
170
|
showEmptyPage();
|
171
|
return;
|
172
|
}
|
173
|
|
174
|
if(part instanceof MultiPageTaxonEditor){
|
175
|
if(! part.equals(this.part)){
|
176
|
IEditorInput input = ((IEditorPart) part).getEditorInput();
|
177
|
featureNodeContainerCache.clear();
|
178
|
showViewer(part, new StructuredSelection(input));
|
179
|
}
|
180
|
showViewer();
|
181
|
}
|
182
|
}
|
183
|
|
184
|
/**
|
185
|
*
|
186
|
* @author n.hoffmann
|
187
|
* @created May 28, 2010
|
188
|
* @version 1.0
|
189
|
*/
|
190
|
protected class ToggleDescriptionAction extends Action{
|
191
|
private boolean expanded;
|
192
|
|
193
|
public ToggleDescriptionAction(boolean expand){
|
194
|
super(null, Action.AS_PUSH_BUTTON);
|
195
|
expanded = expand;
|
196
|
setImageAndTooltip();
|
197
|
}
|
198
|
|
199
|
private void setImageAndTooltip(){
|
200
|
setImageDescriptor(new ImageDescriptor() {
|
201
|
@Override
|
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();
|
206
|
}
|
207
|
});
|
208
|
|
209
|
String toolTipText = expanded ? "Collapse all" : "Show all descriptive data";
|
210
|
setToolTipText(toolTipText);
|
211
|
}
|
212
|
|
213
|
@Override
|
214
|
public void run() {
|
215
|
if(expanded){
|
216
|
viewer.collapseAll();
|
217
|
}else{
|
218
|
viewer.expandAll();
|
219
|
}
|
220
|
setImageAndTooltip();
|
221
|
}
|
222
|
}
|
223
|
|
224
|
/** {@inheritDoc} */
|
225
|
@Override
|
226
|
public boolean postOperation(CdmBase objectAffectedByOperation) {
|
227
|
return super.postOperation(objectAffectedByOperation);
|
228
|
}
|
229
|
|
230
|
/** {@inheritDoc} */
|
231
|
@Override
|
232
|
public void changed(Object object) {
|
233
|
for(FeatureNodeContainerTree containerTree : featureNodeContainerCache.values()){
|
234
|
containerTree.buildTree();
|
235
|
}
|
236
|
viewer.refresh();
|
237
|
|
238
|
if(object instanceof DescriptionElementBase){
|
239
|
DescriptionElementBase descriptionElement = (DescriptionElementBase) object;
|
240
|
DescriptionBase description = descriptionElement.getInDescription();
|
241
|
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description);
|
242
|
|
243
|
FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement);
|
244
|
viewer.expandToLevel(featureNodeContainer, 1);
|
245
|
|
246
|
}
|
247
|
|
248
|
if(object != null){
|
249
|
StructuredSelection selection = new StructuredSelection(object);
|
250
|
viewer.setSelection(selection, true);
|
251
|
}
|
252
|
|
253
|
super.changed(object);
|
254
|
}
|
255
|
|
256
|
/** {@inheritDoc} */
|
257
|
@Override
|
258
|
public Viewer getViewer() {
|
259
|
return viewer;
|
260
|
}
|
261
|
|
262
|
/**
|
263
|
* <p>onComplete</p>
|
264
|
*
|
265
|
* @return a boolean.
|
266
|
*/
|
267
|
public boolean onComplete() {
|
268
|
return false;
|
269
|
}
|
270
|
}
|