Revision 0d4ff026
Added by Alex Theys almost 12 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/UsesViewPart.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.taxeditor.editor.view.uses; |
10 | 10 |
|
11 |
import java.util.HashMap; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import org.eclipse.jface.action.Action; |
|
15 |
import org.eclipse.jface.action.GroupMarker; |
|
16 |
import org.eclipse.jface.action.IToolBarManager; |
|
17 |
import org.eclipse.jface.action.MenuManager; |
|
18 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
19 |
import org.eclipse.jface.viewers.ISelection; |
|
20 |
import org.eclipse.jface.viewers.StructuredSelection; |
|
21 | 11 |
import org.eclipse.jface.viewers.TreeViewer; |
22 |
import org.eclipse.jface.viewers.Viewer; |
|
23 | 12 |
import org.eclipse.swt.SWT; |
24 |
import org.eclipse.swt.dnd.DND; |
|
25 | 13 |
import org.eclipse.swt.dnd.Transfer; |
26 |
import org.eclipse.swt.graphics.ImageData; |
|
27 | 14 |
import org.eclipse.swt.widgets.Composite; |
28 |
import org.eclipse.swt.widgets.Control; |
|
29 |
import org.eclipse.swt.widgets.Menu; |
|
30 | 15 |
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; |
|
35 | 16 |
|
36 | 17 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
37 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
38 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
|
39 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
|
40 |
import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor; |
|
41 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
|
42 |
import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor; |
|
43 |
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermEditor; |
|
44 |
import eu.etaxonomy.taxeditor.editor.key.AbstractGraphKeyEditor; |
|
45 | 18 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementTransfer; |
46 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainer; |
|
47 |
import eu.etaxonomy.taxeditor.model.FeatureNodeContainerTree; |
|
19 |
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptiveViewPart; |
|
48 | 20 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
49 | 21 |
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData; |
50 |
import eu.etaxonomy.taxeditor.model.ImageResources; |
|
51 |
import eu.etaxonomy.taxeditor.view.AbstractCdmEditorViewPart; |
|
52 | 22 |
|
53 | 23 |
|
54 | 24 |
/** |
... | ... | |
57 | 27 |
* @created mar 13, 2012 |
58 | 28 |
* @version 1.0 |
59 | 29 |
*/ |
60 |
public class UsesViewPart extends AbstractCdmEditorViewPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
|
|
30 |
public class UsesViewPart extends DescriptiveViewPart implements IPartContentHasDetails, IPartContentHasSupplementalData {
|
|
61 | 31 |
|
32 |
/** Constant <code>ID="eu.etaxonomy.taxeditor.editor.view.uses"</code> */ |
|
62 | 33 |
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.uses"; |
63 |
private TreeViewer viewer; |
|
64 |
private Map<TaxonDescription, FeatureNodeContainerTree> featureNodeContainerCache = new HashMap<TaxonDescription, FeatureNodeContainerTree>(); |
|
65 |
private ToggleDescriptionAction showAllElementsAction; |
|
66 |
private ToggleDescriptionAction hideAllElementsAction; |
|
67 |
|
|
68 |
private int dndOperations = DND.DROP_COPY | DND.DROP_MOVE; |
|
69 |
|
|
70 |
|
|
71 | 34 |
/** {@inheritDoc} */ |
72 | 35 |
@Override |
73 | 36 |
public void createViewer(Composite parent) { |
... | ... | |
99 | 62 |
|
100 | 63 |
} |
101 | 64 |
|
102 |
|
|
103 |
/* (non-Javadoc) |
|
104 |
* @see eu.etaxonomy.taxeditor.model.AbstractCdmViewPart#getInitialSelection() |
|
105 |
*/ |
|
106 |
/** {@inheritDoc} */ |
|
107 |
@Override |
|
108 |
protected ISelection getInitialSelection() { |
|
109 |
if(getEditor() != null){ |
|
110 |
return new StructuredSelection(getEditor().getEditorInput()); |
|
111 |
} |
|
112 |
|
|
113 |
return super.getInitialSelection(); |
|
114 |
} |
|
115 |
|
|
116 |
private void createToolbar() { |
|
117 |
IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager(); |
|
118 |
toolBarManager.add(showAllElementsAction); |
|
119 |
toolBarManager.add(hideAllElementsAction); |
|
120 |
} |
|
121 |
|
|
122 |
|
|
123 |
private void createMenu(){ |
|
124 |
MenuManager menuManager = new MenuManager(); |
|
125 |
menuManager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); |
|
126 |
|
|
127 |
getSite().registerContextMenu(menuManager, viewer); |
|
128 |
|
|
129 |
// FIXME for some reason this is not working |
|
130 |
menuManager.add(showAllElementsAction); |
|
131 |
menuManager.add(hideAllElementsAction); |
|
132 |
|
|
133 |
Control control = viewer.getControl(); |
|
134 |
Menu menu = menuManager.createContextMenu(control); |
|
135 |
|
|
136 |
control.setMenu(menu); |
|
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
@Override |
|
142 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
|
143 |
if(EditorUtil.getActiveEditor() == null){ |
|
144 |
showEmptyPage(); |
|
145 |
return; |
|
146 |
} |
|
147 |
|
|
148 |
if(part instanceof BulkEditor){ |
|
149 |
showEmptyPage(); |
|
150 |
return; |
|
151 |
} |
|
152 |
|
|
153 |
if(part instanceof AbstractGraphKeyEditor){ |
|
154 |
showEmptyPage(); |
|
155 |
return; |
|
156 |
} |
|
157 |
|
|
158 |
if(part instanceof DefinedTermEditor){ |
|
159 |
showEmptyPage(); |
|
160 |
return; |
|
161 |
} |
|
162 |
|
|
163 |
if(part instanceof MultiPageTaxonEditor){ |
|
164 |
if(! part.equals(this.part)){ |
|
165 |
//TaxonEditorInput input = (TaxonEditorInput)((IEditorPart) part).getEditorInput(); |
|
166 |
IEditorInput input = ((IEditorPart) part).getEditorInput(); |
|
167 |
featureNodeContainerCache.clear(); |
|
168 |
//showViewer(part, new StructuredSelection(CdmStore.getService(IDescriptionService.class).listTaxonDescriptions(input.getTaxonNode().getTaxon(), null, null, null, null, null, null))); |
|
169 |
showViewer(part, new StructuredSelection(input)); |
|
170 |
} |
|
171 |
showViewer(); |
|
172 |
} |
|
173 |
|
|
174 |
} |
|
175 |
|
|
176 |
|
|
177 |
private class ToggleDescriptionAction extends Action{ |
|
178 |
private boolean expanded; |
|
179 |
|
|
180 |
public ToggleDescriptionAction(boolean expand){ |
|
181 |
super(null, Action.AS_PUSH_BUTTON); |
|
182 |
expanded = expand; |
|
183 |
setImageAndTooltip(); |
|
184 |
} |
|
185 |
|
|
186 |
private void setImageAndTooltip(){ |
|
187 |
setImageDescriptor(new ImageDescriptor() { |
|
188 |
@Override |
|
189 |
public ImageData getImageData() { |
|
190 |
setText(expanded ? "Collapse All" : "Expand All"); |
|
191 |
String resource = expanded ? ImageResources.COLLAPSE_ALL : ImageResources.EXPAND_ALL; |
|
192 |
return ImageResources.getImage(resource).getImageData(); |
|
193 |
} |
|
194 |
}); |
|
195 |
|
|
196 |
String toolTipText = expanded ? "Collapse all" : "Show all descriptive data"; |
|
197 |
setToolTipText(toolTipText); |
|
198 |
} |
|
199 |
|
|
200 |
@Override |
|
201 |
public void run() { |
|
202 |
if(expanded){ |
|
203 |
viewer.collapseAll(); |
|
204 |
}else{ |
|
205 |
viewer.expandAll(); |
|
206 |
} |
|
207 |
setImageAndTooltip(); |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 | 65 |
/** {@inheritDoc} */ |
212 | 66 |
@Override |
213 | 67 |
public boolean postOperation(CdmBase objectAffectedByOperation) { |
... | ... | |
215 | 69 |
return super.postOperation(objectAffectedByOperation); |
216 | 70 |
} |
217 | 71 |
|
218 |
/** {@inheritDoc} */ |
|
219 |
@Override |
|
220 |
public void changed(Object object) { |
|
221 |
for(FeatureNodeContainerTree containerTree : featureNodeContainerCache.values()){ |
|
222 |
containerTree.buildTree(); |
|
223 |
} |
|
224 |
viewer.refresh(); |
|
225 |
|
|
226 |
if(object instanceof DescriptionElementBase){ |
|
227 |
DescriptionElementBase descriptionElement = (DescriptionElementBase) object; |
|
228 |
DescriptionBase description = descriptionElement.getInDescription(); |
|
229 |
FeatureNodeContainerTree containerTree = featureNodeContainerCache.get(description); |
|
230 |
|
|
231 |
FeatureNodeContainer featureNodeContainer = containerTree.getFeatureNodeContainerForDescriptionElement(descriptionElement); |
|
232 |
viewer.expandToLevel(featureNodeContainer, 1); |
|
233 |
|
|
234 |
} |
|
235 |
|
|
236 |
if(object != null){ |
|
237 |
StructuredSelection selection = new StructuredSelection(object); |
|
238 |
viewer.setSelection(selection, true); |
|
239 |
} |
|
240 |
|
|
241 |
super.changed(object); |
|
242 |
} |
|
243 |
|
|
244 | 72 |
|
245 |
/** {@inheritDoc} */ |
|
246 |
@Override |
|
247 |
public Viewer getViewer() { |
|
248 |
return viewer; |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* <p>onComplete</p> |
|
253 |
* |
|
254 |
* @return a boolean. |
|
255 |
*/ |
|
256 |
@Override |
|
257 |
public boolean onComplete() { |
|
258 |
return false; |
|
259 |
} |
|
260 | 73 |
|
261 | 74 |
} |
Also available in: Unified diff
AT: committing changes to the TaxEditor Post second round of code review