1
|
/**
|
2
|
* Copyright (C) 2017 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.featuretree.e4.handler;
|
10
|
|
11
|
import javax.inject.Named;
|
12
|
|
13
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
14
|
import org.eclipse.e4.core.di.annotations.Execute;
|
15
|
import org.eclipse.e4.core.di.annotations.Optional;
|
16
|
import org.eclipse.e4.ui.di.UISynchronize;
|
17
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
18
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
21
|
|
22
|
import eu.etaxonomy.cdm.persistence.dto.TermTreeDto;
|
23
|
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
|
24
|
import eu.etaxonomy.taxeditor.featuretree.e4.TermTreeEditor;
|
25
|
import eu.etaxonomy.taxeditor.featuretree.e4.operation.RemoveFeatureTreeOperation;
|
26
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
27
|
|
28
|
/**
|
29
|
* @author pplitzner
|
30
|
* @since Jul 12, 2017
|
31
|
*
|
32
|
*/
|
33
|
public class RemoveFeatureTreeHandler {
|
34
|
|
35
|
@Execute
|
36
|
public void execute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
37
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection, UISynchronize sync){
|
38
|
IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
|
39
|
|
40
|
if (StoreUtil.promptCheckIsDirty(editor)) {
|
41
|
return;
|
42
|
}
|
43
|
if(!StoreUtil.confirmDelete()){
|
44
|
return;
|
45
|
}
|
46
|
|
47
|
for (Object selectedObject : selection.toArray()) {
|
48
|
TermTreeDto featureTree = (TermTreeDto) selectedObject;
|
49
|
((TermTreeEditor)editor).removeTree(featureTree);
|
50
|
((TermTreeEditor)editor).getViewer().setInput(((TermTreeEditor)editor).getTrees());
|
51
|
RemoveFeatureTreeOperation operation = new RemoveFeatureTreeOperation(featureTree.getUuid(), editor, editor);
|
52
|
// AbstractUtility.executeOperation(operation, sync);
|
53
|
editor.addOperation(operation);
|
54
|
editor.setDirty();
|
55
|
editor.refresh();
|
56
|
}
|
57
|
}
|
58
|
|
59
|
@CanExecute
|
60
|
public boolean canExecute(
|
61
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
62
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
|
63
|
MHandledMenuItem menuItem) {
|
64
|
boolean canExecute = selection!=null && !selection.isEmpty();
|
65
|
if(canExecute){
|
66
|
for(Object object:selection.toArray()){
|
67
|
canExecute &= object instanceof TermTreeDto;
|
68
|
}
|
69
|
}
|
70
|
canExecute &= thisPart.getObject() instanceof IFeatureTreeEditor;
|
71
|
menuItem.setVisible(canExecute);
|
72
|
return canExecute;
|
73
|
}
|
74
|
|
75
|
}
|