1
|
/**
|
2
|
* Copyright (C) 2015 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.navigation.navigator.e4.handler;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import javax.inject.Named;
|
16
|
|
17
|
import org.eclipse.core.commands.operations.AbstractOperation;
|
18
|
import org.eclipse.core.runtime.IStatus;
|
19
|
import org.eclipse.core.runtime.Status;
|
20
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
21
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
22
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
23
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
24
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
25
|
import org.eclipse.jface.viewers.TreeSelection;
|
26
|
import org.eclipse.swt.widgets.Display;
|
27
|
import org.eclipse.swt.widgets.Shell;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
|
30
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
31
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
32
|
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
|
33
|
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
|
34
|
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
|
35
|
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveFactualDataOperation;
|
36
|
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
|
37
|
import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonNodeSelectionDialog;
|
38
|
|
39
|
/**
|
40
|
* @author cmathew
|
41
|
* @date 19 Jun 2015
|
42
|
*
|
43
|
*/
|
44
|
public class RemotingMoveFactualDataHandlerE4 extends RemotingCdmHandlerE4 {
|
45
|
|
46
|
private TaxonNode sourceTaxonNode;
|
47
|
private TaxonNode targetTaxonNode;
|
48
|
|
49
|
public RemotingMoveFactualDataHandlerE4() {
|
50
|
super(TaxonNavigatorLabels.MOVE_FACTUAL_DATA_LABEL);
|
51
|
}
|
52
|
|
53
|
@Override
|
54
|
public IStatus allowOperations(IStructuredSelection selection,
|
55
|
Shell shell,
|
56
|
MPart activePart,
|
57
|
MHandledMenuItem menuItem) {
|
58
|
// check that only a single taxon tree node has been selected
|
59
|
if(selection.size() > 1) {
|
60
|
return new Status(IStatus.ERROR,
|
61
|
"unknown", //$NON-NLS-1$
|
62
|
TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
|
63
|
}
|
64
|
|
65
|
// check for no taxon tree node selected
|
66
|
if(selection.size() == 0) {
|
67
|
return new Status(IStatus.ERROR,
|
68
|
"unknown", //$NON-NLS-1$
|
69
|
TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
|
70
|
}
|
71
|
|
72
|
// check that selected object is a taxon node
|
73
|
Object obj = selection.iterator().next();
|
74
|
if(obj instanceof ITaxonTreeNode) {
|
75
|
sourceTaxonNode = (TaxonNode)obj;
|
76
|
} else {
|
77
|
return new Status(IStatus.ERROR,
|
78
|
"unknown", //$NON-NLS-1$
|
79
|
TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
|
80
|
}
|
81
|
|
82
|
if(NavigationUtil.isDirty(sourceTaxonNode, partService)) {
|
83
|
return new Status(IStatus.ERROR,
|
84
|
"unknown", //$NON-NLS-1$
|
85
|
TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
|
86
|
}
|
87
|
|
88
|
List<UUID> excludeTaxa = new ArrayList<UUID>();
|
89
|
excludeTaxa.add(sourceTaxonNode.getTaxon().getUuid());
|
90
|
|
91
|
targetTaxonNode = TaxonNodeSelectionDialog.select(shell,
|
92
|
new ConversationHolderMock(),
|
93
|
Messages.RemotingMoveFactualDataHandler_CHOOSE_TAXA,
|
94
|
excludeTaxa,
|
95
|
sourceTaxonNode,
|
96
|
sourceTaxonNode.getClassification());
|
97
|
|
98
|
if(targetTaxonNode == null) {
|
99
|
return new Status(IStatus.CANCEL,
|
100
|
"unknown", //$NON-NLS-1$
|
101
|
""); //$NON-NLS-1$
|
102
|
}
|
103
|
if(NavigationUtil.isDirty(targetTaxonNode, partService)){
|
104
|
return new Status(IStatus.ERROR,
|
105
|
"unknown", //$NON-NLS-1$
|
106
|
TaxonNavigatorLabels.UNSAVED_CHANGES_MESSAGE);
|
107
|
}
|
108
|
return Status.OK_STATUS;
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
public AbstractOperation prepareOperation(IStructuredSelection selection,
|
113
|
Shell shell,
|
114
|
MPart activePart,
|
115
|
MHandledMenuItem menuItem) {
|
116
|
return new RemotingMoveFactualDataOperation(getTrigger(),
|
117
|
false,
|
118
|
sourceTaxonNode.getTaxon().getUuid(),
|
119
|
targetTaxonNode.getTaxon().getUuid());
|
120
|
}
|
121
|
|
122
|
@CanExecute
|
123
|
private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
|
124
|
boolean canExecute = false;
|
125
|
canExecute = selection.getFirstElement() instanceof TaxonNode
|
126
|
&& ((TaxonNode) selection.getFirstElement()).getTaxon()!=null;
|
127
|
menuItem.setVisible(canExecute);
|
128
|
return canExecute;
|
129
|
}
|
130
|
|
131
|
@Override
|
132
|
public void onComplete() {
|
133
|
Display.getDefault().asyncExec(new Runnable(){
|
134
|
@Override
|
135
|
public void run() {
|
136
|
//FIXME E4 refresh factual view via events or similar
|
137
|
// try {
|
138
|
// //close and re-open to refresh factual data view
|
139
|
// MultiPageTaxonEditor sourceEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(sourceTaxonNode.getUuid());
|
140
|
// MultiPageTaxonEditor targetEditor = (MultiPageTaxonEditor) EditorUtil.findEditorByTaxonNodeUuid(targetTaxonNode.getUuid());
|
141
|
// if(targetEditor != null){
|
142
|
// AbstractUtility.close(sourceEditor);
|
143
|
// AbstractUtility.close(targetEditor);
|
144
|
// }
|
145
|
// EditorUtil.openTaxonNodeE4(sourceTaxonNode.getUuid());
|
146
|
// EditorUtil.openTaxonNodeE4(targetTaxonNode.getUuid());
|
147
|
// } catch (PartInitException e) {
|
148
|
// MessagingUtils.error(this.getClass(), e);
|
149
|
// throw new RuntimeException(e);
|
150
|
// } catch (Exception e) {
|
151
|
// MessagingUtils.warningDialog(Messages.RemotingMoveFactualDataHandler_CREATE_FAILED, this, e.getMessage());
|
152
|
// }
|
153
|
}
|
154
|
|
155
|
});
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* {@inheritDoc}
|
160
|
*/
|
161
|
@Override
|
162
|
protected Object getTrigger() {
|
163
|
return this;
|
164
|
}
|
165
|
}
|