10 |
10 |
import java.util.Set;
|
11 |
11 |
import java.util.UUID;
|
12 |
12 |
|
|
13 |
import javax.annotation.PostConstruct;
|
|
14 |
import javax.annotation.PreDestroy;
|
|
15 |
import javax.inject.Inject;
|
|
16 |
import javax.inject.Named;
|
|
17 |
|
13 |
18 |
import org.eclipse.core.runtime.IProgressMonitor;
|
14 |
|
import org.eclipse.jface.action.MenuManager;
|
|
19 |
import org.eclipse.e4.core.di.annotations.Optional;
|
|
20 |
import org.eclipse.e4.ui.di.Focus;
|
|
21 |
import org.eclipse.e4.ui.di.Persist;
|
|
22 |
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
|
23 |
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
|
24 |
import org.eclipse.e4.ui.services.EMenuService;
|
|
25 |
import org.eclipse.e4.ui.services.IServiceConstants;
|
|
26 |
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
|
27 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
15 |
28 |
import org.eclipse.jface.util.LocalSelectionTransfer;
|
16 |
29 |
import org.eclipse.jface.viewers.AbstractTreeViewer;
|
17 |
30 |
import org.eclipse.jface.viewers.ISelection;
|
18 |
31 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
32 |
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
19 |
33 |
import org.eclipse.jface.viewers.StructuredSelection;
|
20 |
34 |
import org.eclipse.jface.viewers.TreeNode;
|
21 |
35 |
import org.eclipse.jface.viewers.TreeSelection;
|
... | ... | |
26 |
40 |
import org.eclipse.swt.layout.GridData;
|
27 |
41 |
import org.eclipse.swt.layout.GridLayout;
|
28 |
42 |
import org.eclipse.swt.widgets.Composite;
|
29 |
|
import org.eclipse.swt.widgets.Control;
|
30 |
|
import org.eclipse.swt.widgets.Display;
|
31 |
|
import org.eclipse.swt.widgets.Menu;
|
32 |
43 |
import org.eclipse.swt.widgets.Tree;
|
33 |
|
import org.eclipse.ui.IEditorInput;
|
34 |
|
import org.eclipse.ui.IEditorPart;
|
35 |
|
import org.eclipse.ui.IEditorSite;
|
36 |
44 |
import org.eclipse.ui.IMemento;
|
37 |
|
import org.eclipse.ui.ISelectionListener;
|
38 |
|
import org.eclipse.ui.ISelectionService;
|
39 |
|
import org.eclipse.ui.IWorkbenchPart;
|
40 |
|
import org.eclipse.ui.PartInitException;
|
41 |
|
import org.eclipse.ui.part.EditorPart;
|
42 |
45 |
|
43 |
46 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
44 |
47 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
... | ... | |
73 |
76 |
* Displays the derivate hierarchy of the specimen specified in the editor input.
|
74 |
77 |
*
|
75 |
78 |
*/
|
76 |
|
public class DerivateView extends EditorPart implements IPartContentHasFactualData, IConversationEnabled,
|
|
79 |
public class DerivateView implements IPartContentHasFactualData, IConversationEnabled,
|
77 |
80 |
ICdmEntitySessionEnabled, IDirtyMarkable, IPostOperationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
|
78 |
|
IContextListener, ISelectionListener {
|
|
81 |
IContextListener {
|
|
82 |
|
79 |
83 |
private static final String SPECIMEN_EDITOR = Messages.DerivateView_SPECIMEN_EDITOR;
|
80 |
84 |
|
81 |
85 |
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$
|
... | ... | |
101 |
105 |
|
102 |
106 |
private static final int WARN_THRESHOLD = 200;
|
103 |
107 |
|
104 |
|
private DelaySelection delaySelection = null;
|
105 |
|
/**
|
106 |
|
* This is the monitor for the DelaySelection runnable.
|
107 |
|
* If it is <code>true</code> then it is currently delaying a selection.
|
108 |
|
*/
|
109 |
|
private boolean isInDelay;
|
110 |
|
|
111 |
|
|
112 |
|
/**
|
113 |
|
* This class invokes internal_selectionChanged() in a separate thread.
|
114 |
|
* This allows an asynchronous and/or delayed handling of selection changes
|
115 |
|
*/
|
116 |
|
private class DelaySelection implements Runnable{
|
117 |
|
private IWorkbenchPart part;
|
118 |
|
private ISelection selection;
|
119 |
|
|
120 |
|
public DelaySelection(IWorkbenchPart part, ISelection selection) {
|
121 |
|
super();
|
122 |
|
this.part = part;
|
123 |
|
this.selection = selection;
|
124 |
|
}
|
125 |
|
|
126 |
|
@Override
|
127 |
|
public void run() {
|
128 |
|
try{
|
129 |
|
selectionChanged_internal(part, selection);
|
130 |
|
}
|
131 |
|
finally{
|
132 |
|
isInDelay = false;
|
133 |
|
}
|
134 |
|
}
|
135 |
|
|
136 |
|
public synchronized void setSelection(ISelection selection) {
|
137 |
|
this.selection = selection;
|
138 |
|
}
|
139 |
|
|
140 |
|
public synchronized void setPart(IWorkbenchPart part) {
|
141 |
|
this.part = part;
|
142 |
|
}
|
143 |
|
|
144 |
|
}
|
145 |
108 |
|
146 |
109 |
private ConversationHolder conversation;
|
147 |
110 |
|
148 |
111 |
private TreeViewer viewer;
|
149 |
112 |
|
150 |
|
private boolean isDirty;
|
151 |
|
|
152 |
113 |
private final int dndOperations = DND.DROP_MOVE;
|
153 |
114 |
|
154 |
115 |
private DerivateLabelProvider labelProvider;
|
... | ... | |
177 |
138 |
|
178 |
139 |
private Taxon selectedTaxon;
|
179 |
140 |
|
180 |
|
private ISelectionService selectionService;
|
|
141 |
@Inject
|
|
142 |
private ESelectionService selService;
|
|
143 |
|
|
144 |
@Inject
|
|
145 |
private MDirtyable dirty;
|
|
146 |
|
|
147 |
@Inject
|
|
148 |
private EPartService partService;
|
181 |
149 |
|
182 |
150 |
/**
|
183 |
151 |
* Default constructor
|
184 |
152 |
*/
|
|
153 |
@Inject
|
185 |
154 |
public DerivateView() {
|
186 |
155 |
}
|
187 |
156 |
|
... | ... | |
189 |
158 |
/**
|
190 |
159 |
* {@inheritDoc}
|
191 |
160 |
*/
|
192 |
|
@Override
|
193 |
|
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
|
194 |
|
this.setSite(site);
|
195 |
|
this.setInput(input);
|
|
161 |
private void init(){
|
196 |
162 |
this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>();
|
197 |
163 |
this.rootElements = new HashSet<SpecimenOrObservationBase<?>>();
|
198 |
164 |
|
... | ... | |
206 |
172 |
CdmStore.getContextManager().addContextListener(this);
|
207 |
173 |
}
|
208 |
174 |
|
209 |
|
@Override
|
210 |
|
public void createPartControl(Composite parent) {
|
|
175 |
@PostConstruct
|
|
176 |
public void createPartControl(Composite parent, EMenuService menuService) {
|
|
177 |
init();
|
211 |
178 |
|
212 |
179 |
parent.setLayout(new GridLayout());
|
213 |
180 |
|
... | ... | |
234 |
201 |
viewer.setLabelProvider(labelProvider);
|
235 |
202 |
viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
|
236 |
203 |
viewer.getTree().setEnabled(CdmStore.isActive());
|
237 |
|
// Propagate selection from viewer
|
238 |
|
getSite().setSelectionProvider(viewer);
|
239 |
204 |
|
240 |
|
//listen to selection changes
|
241 |
|
selectionService = getSite().getWorkbenchWindow().getSelectionService();
|
242 |
|
selectionService.addSelectionListener(this);
|
|
205 |
// Propagate selection from viewer
|
|
206 |
viewer.addSelectionChangedListener((SelectionChangedEvent event) -> {
|
|
207 |
IStructuredSelection isel = (IStructuredSelection) event.getSelection();
|
|
208 |
selService.setSelection((isel.size() == 1 ? isel.getFirstElement() : isel.toArray()));
|
|
209 |
});
|
243 |
210 |
|
244 |
211 |
//create context menu
|
245 |
|
MenuManager menuManager = new MenuManager();
|
246 |
|
menuManager.setRemoveAllWhenShown(true);
|
247 |
|
getSite().registerContextMenu(menuManager, viewer);
|
248 |
|
Control control = viewer.getControl();
|
249 |
|
Menu menu = menuManager.createContextMenu(control);
|
250 |
|
control.setMenu(menu);
|
|
212 |
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.specimeneditor");
|
|
213 |
// MenuManager menuManager = new MenuManager();
|
|
214 |
// menuManager.setRemoveAllWhenShown(true);
|
|
215 |
// getSite().registerContextMenu(menuManager, viewer);
|
|
216 |
// Control control = viewer.getControl();
|
|
217 |
// Menu menu = menuManager.createContextMenu(control);
|
|
218 |
// control.setMenu(menu);
|
251 |
219 |
|
252 |
220 |
//init tree
|
253 |
|
Collection<UUID> derivativeUuids = ((DerivateViewEditorInput)getEditorInput()).getDerivativeUuids();
|
254 |
|
checkWarnThreshold(derivativeUuids);
|
255 |
|
updateRootEntities(derivativeUuids);
|
256 |
|
//set taxon filter
|
257 |
|
derivateSearchCompositeController.setTaxonFilter(((DerivateViewEditorInput) getEditorInput()).getTaxonUuid());
|
|
221 |
//TODO e4
|
|
222 |
// Collection<UUID> derivativeUuids = ((DerivateViewEditorInput)getEditorInput()).getDerivativeUuids();
|
|
223 |
// checkWarnThreshold(derivativeUuids);
|
|
224 |
// updateRootEntities(derivativeUuids);
|
|
225 |
// set taxon filter
|
|
226 |
//TODO e4
|
|
227 |
// derivateSearchCompositeController.setTaxonFilter(((DerivateViewEditorInput) getEditorInput()).getTaxonUuid());
|
258 |
228 |
//reset status bar
|
259 |
|
getEditorSite().getActionBars().getStatusLineManager().setMessage(""); //$NON-NLS-1$
|
|
229 |
//TODO e4
|
|
230 |
// getEditorSite().getActionBars().getStatusLineManager().setMessage(""); //$NON-NLS-1$
|
260 |
231 |
|
261 |
232 |
//add drag'n'drop support
|
262 |
233 |
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer(),};
|
... | ... | |
325 |
296 |
labelProvider.updateLabelCache(rootElements);
|
326 |
297 |
viewer.setInput(rootElements);
|
327 |
298 |
|
328 |
|
getEditorSite().getActionBars().getStatusLineManager().setMessage(String.format(Messages.DerivateView_CNT_DERIVATIVES_FOUND, rootElements.size()));
|
|
299 |
//TODO e4
|
|
300 |
// getEditorSite().getActionBars().getStatusLineManager().setMessage(String.format(Messages.DerivateView_CNT_DERIVATIVES_FOUND, rootElements.size()));
|
329 |
301 |
|
330 |
302 |
//set selection to derivatives if the filter criteria
|
331 |
303 |
//taxon assignment or derivative type are set
|
... | ... | |
346 |
318 |
labelProvider.updateLabelCache(rootElements);
|
347 |
319 |
}
|
348 |
320 |
|
349 |
|
@Override
|
|
321 |
@Persist
|
350 |
322 |
public void doSave(IProgressMonitor monitor) {
|
351 |
323 |
String taskName = Messages.DerivateView_SAVING_HIERARCHY;
|
352 |
324 |
monitor.beginTask(taskName, 3);
|
... | ... | |
365 |
337 |
this.setDirty(false);
|
366 |
338 |
monitor.worked(1);
|
367 |
339 |
monitor.done();
|
368 |
|
firePropertyChange(PROP_DIRTY);
|
|
340 |
dirty.setDirty(false);
|
369 |
341 |
refreshTree();
|
370 |
342 |
}
|
371 |
343 |
|
372 |
|
@Override
|
373 |
|
public void doSaveAs() {
|
374 |
|
}
|
375 |
|
|
376 |
|
@Override
|
377 |
|
public String getTitleToolTip() {
|
378 |
|
return Messages.DerivateView_DERIVATIVE_EDITOR;
|
379 |
|
}
|
380 |
|
|
381 |
|
@Override
|
382 |
|
public boolean isDirty() {
|
383 |
|
return isDirty;
|
384 |
|
}
|
|
344 |
// @Override
|
|
345 |
// public String getTitleToolTip() {
|
|
346 |
//TODO e4
|
|
347 |
// return Messages.DerivateView_DERIVATIVE_EDITOR;
|
|
348 |
// }
|
385 |
349 |
|
386 |
350 |
/**
|
387 |
351 |
* @param isDirty the isDirty to set
|
388 |
352 |
*/
|
389 |
353 |
public void setDirty(boolean isDirty) {
|
390 |
|
this.isDirty = isDirty;
|
|
354 |
dirty.setDirty(isDirty);
|
391 |
355 |
}
|
392 |
356 |
|
393 |
|
@Override
|
394 |
|
public boolean isSaveAsAllowed() {
|
395 |
|
return false;
|
396 |
|
}
|
397 |
|
|
398 |
|
@Override
|
|
357 |
@Focus
|
399 |
358 |
public void setFocus() {
|
400 |
359 |
//make sure to bind again if maybe in another view the conversation was unbound
|
401 |
360 |
if(conversation!=null && !conversation.isBound()){
|
... | ... | |
419 |
378 |
@Override
|
420 |
379 |
public void changed(Object element) {
|
421 |
380 |
setDirty(true);
|
422 |
|
firePropertyChange(IEditorPart.PROP_DIRTY);
|
|
381 |
// firePropertyChange(IEditorPart.PROP_DIRTY);
|
423 |
382 |
viewer.update(new TreeNode(element), null);
|
424 |
383 |
}
|
425 |
384 |
|
... | ... | |
524 |
483 |
return cdmEntitySession;
|
525 |
484 |
}
|
526 |
485 |
|
527 |
|
@Override
|
|
486 |
@PreDestroy
|
528 |
487 |
public void dispose() {
|
529 |
|
super.dispose();
|
530 |
488 |
if(conversation!=null){
|
531 |
489 |
conversation.close();
|
532 |
490 |
}
|
... | ... | |
534 |
492 |
cdmEntitySession.dispose();
|
535 |
493 |
}
|
536 |
494 |
}
|
537 |
|
public void selectionChanged_internal(IWorkbenchPart part, ISelection selection) {
|
538 |
|
if(part == this){
|
|
495 |
|
|
496 |
|
|
497 |
@Inject
|
|
498 |
@Optional
|
|
499 |
public void selectionChanged(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) ISelection selection,
|
|
500 |
@Named(IServiceConstants.ACTIVE_PART) MPart activePart, MPart thisPart)
|
|
501 |
{
|
|
502 |
if(activePart == this || viewer==null){
|
539 |
503 |
return;
|
540 |
504 |
}
|
541 |
505 |
if(viewer.getTree().isDisposed()){
|
542 |
506 |
return;
|
543 |
507 |
}
|
544 |
508 |
if(listenToSelectionChange){
|
545 |
|
if(part instanceof MultiPageTaxonEditor){
|
546 |
|
selectedTaxon = ((MultiPageTaxonEditor) part).getTaxon();
|
|
509 |
if(activePart instanceof MultiPageTaxonEditor){
|
|
510 |
selectedTaxon = ((MultiPageTaxonEditor) activePart).getTaxon();
|
547 |
511 |
}
|
548 |
512 |
else if(selection instanceof IStructuredSelection){
|
549 |
513 |
Object selectedElement = ((IStructuredSelection) selection).getFirstElement();
|
... | ... | |
564 |
528 |
}
|
565 |
529 |
checkWarnThreshold(uuids);
|
566 |
530 |
updateRootEntities(uuids);
|
567 |
|
setPartName(SPECIMEN_EDITOR+": " + selectedTaxon.getName()); //$NON-NLS-1$
|
568 |
|
}
|
569 |
|
}
|
570 |
|
}
|
571 |
531 |
|
572 |
|
@Override
|
573 |
|
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
574 |
|
if(delaySelection==null){
|
575 |
|
delaySelection = new DelaySelection(part, selection);
|
576 |
|
}
|
577 |
|
delaySelection.setPart(part);
|
578 |
|
delaySelection.setSelection(selection);
|
579 |
|
if(!isInDelay){
|
580 |
|
isInDelay = true;
|
581 |
|
Display.getCurrent().asyncExec(delaySelection);
|
|
532 |
thisPart.setLabel(SPECIMEN_EDITOR+": " + selectedTaxon.getName()); //$NON-NLS-1$
|
|
533 |
}
|
582 |
534 |
}
|
583 |
535 |
}
|
584 |
536 |
|
585 |
|
|
586 |
537 |
private void checkWarnThreshold(Collection<UUID> uuids) {
|
587 |
538 |
if(uuids!=null && uuids.size()>WARN_THRESHOLD){
|
588 |
539 |
MessagingUtils.warningDialog(Messages.DerivateView_PERF_WARNING, this.getClass(), String.format(Messages.DerivateView_PERF_WARNING_MESSAGE, uuids.size()));
|
... | ... | |
607 |
558 |
derivateSearchCompositeController.setEnabled(!listenToSelectionChange);
|
608 |
559 |
if(!listenToSelectionChange){
|
609 |
560 |
selectedTaxon = null;
|
610 |
|
setPartName(SPECIMEN_EDITOR);
|
|
561 |
//TODO e4
|
|
562 |
// setPartName(SPECIMEN_EDITOR);
|
611 |
563 |
}
|
612 |
564 |
else if(selectedTaxon==null){
|
613 |
|
setPartName(SPECIMEN_EDITOR+Messages.DerivateView_NO_TAXON_SELECTED);
|
|
565 |
//TODO e4
|
|
566 |
// setPartName(SPECIMEN_EDITOR+Messages.DerivateView_NO_TAXON_SELECTED);
|
614 |
567 |
}
|
615 |
568 |
}
|
616 |
569 |
|
... | ... | |
663 |
616 |
public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
|
664 |
617 |
}
|
665 |
618 |
|
|
619 |
|
|
620 |
public boolean isDirty() {
|
|
621 |
return dirty.isDirty();
|
|
622 |
}
|
|
623 |
|
666 |
624 |
}
|
incomplete migration of specimen editor