1
|
|
2
|
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
|
3
|
|
4
|
import javax.inject.Named;
|
5
|
|
6
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
7
|
import org.eclipse.core.runtime.IStatus;
|
8
|
import org.eclipse.core.runtime.Status;
|
9
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
10
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
11
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
12
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
13
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
14
|
import org.eclipse.jface.viewers.TreeSelection;
|
15
|
import org.eclipse.swt.widgets.Shell;
|
16
|
|
17
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
18
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
19
|
import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
|
20
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.AggregateTaxonDescriptionsOperation;
|
21
|
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
|
22
|
|
23
|
public class AggregateTaxonDescriptionsHandler extends RemotingCdmHandlerE4 {
|
24
|
private TaxonNavigatorE4 navigator;
|
25
|
|
26
|
public AggregateTaxonDescriptionsHandler() {
|
27
|
super("Aggregate taxon descriptions");
|
28
|
}
|
29
|
|
30
|
@Override
|
31
|
public IStatus allowOperations(IStructuredSelection selection,
|
32
|
Shell shell,
|
33
|
MPart activePart,
|
34
|
MHandledMenuItem menuItem) {
|
35
|
if(selection!=null
|
36
|
&& !selection.isEmpty()
|
37
|
&& selection.getFirstElement() instanceof TaxonNodeDto){
|
38
|
|
39
|
TaxonNodeDto node = (TaxonNodeDto) selection.getFirstElement();
|
40
|
boolean confirm = MessagingUtils.confirmDialog("Create aggregated description",
|
41
|
String.format("The aggregated description will be stored at the selected taxon %s"
|
42
|
, node.getTaxonTitleCache()));
|
43
|
|
44
|
return confirm?Status.OK_STATUS:Status.CANCEL_STATUS;
|
45
|
}
|
46
|
return Status.CANCEL_STATUS;
|
47
|
}
|
48
|
|
49
|
@Override
|
50
|
public AbstractOperation prepareOperation(IStructuredSelection selection,
|
51
|
Shell shell,
|
52
|
MPart activePart,
|
53
|
MHandledMenuItem menuItem) {
|
54
|
|
55
|
return new AggregateTaxonDescriptionsOperation(getTrigger(),
|
56
|
false,
|
57
|
((TaxonNodeDto) selection.getFirstElement()).getUuid()
|
58
|
);
|
59
|
}
|
60
|
|
61
|
@CanExecute
|
62
|
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
|
63
|
boolean canExecute = false;
|
64
|
canExecute = selection.getFirstElement() instanceof TaxonNodeDto
|
65
|
&& ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid() != null;
|
66
|
menuItem.setVisible(canExecute);
|
67
|
return canExecute;
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public void onComplete() {
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
protected Object getTrigger() {
|
76
|
return this;
|
77
|
}
|
78
|
|
79
|
}
|