*/
package eu.etaxonomy.taxeditor.navigation.navigator.e4.handler;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
import java.util.UUID;
+import javax.inject.Named;
+
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.swt.widgets.Shell;
-import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
import eu.etaxonomy.taxeditor.navigation.navigator.TaxonNavigatorLabels;
-import eu.etaxonomy.taxeditor.navigation.navigator.TreeNodeDropAdapter.MovingType;
+import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
import eu.etaxonomy.taxeditor.navigation.navigator.operation.RemotingMoveTaxonOperation;
import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
*/
public class RemotingMoveTaxonNodeHandlerE4 extends RemotingCdmHandlerE4 {
- private TaxonNode oldTaxonNode;
+ private Set<UUID> oldTaxonNodeUUIDs = new HashSet<>();
public RemotingMoveTaxonNodeHandlerE4() {
super(TaxonNavigatorLabels.MOVE_TAXON_LABEL);
}
@Override
- public IStatus allowOperations(TreeSelection selection,
+ public IStatus allowOperations(IStructuredSelection selection,
Shell shell,
MPart activePart,
MHandledMenuItem menuItem) {
// check that only a single taxon tree node has been selected
- if(selection.size() > 1) {
- return new Status(IStatus.ERROR,
- "unknown", //$NON-NLS-1$
- TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
- }
+// if(selection.size() > 1) {
+// return new Status(IStatus.ERROR,
+// "unknown", //$NON-NLS-1$
+// TaxonNavigatorLabels.SINGLE_TAXON_SELECTION_MESSAGE);
+// }
// check for no taxon tree node selected
if(selection.size() == 0) {
TaxonNavigatorLabels.NO_TAXON_SELECTION_MESSAGE);
}
// check that selected object is a taxon node
- Object obj = selection.iterator().next();
- if(obj instanceof TaxonNode) {
- oldTaxonNode = (TaxonNode)obj;
- } else {
- return new Status(IStatus.ERROR,
- "unknown", //$NON-NLS-1$
- TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+ Object obj ;
+ Iterator iter = selection.iterator();
+ while (iter.hasNext()){
+ obj = iter.next();
+ if(obj instanceof TaxonNodeDto) {
+ oldTaxonNodeUUIDs.add(((TaxonNodeDto)obj).getUuid());
+ } else {
+ return new Status(IStatus.ERROR,
+ "unknown", //$NON-NLS-1$
+ TaxonNavigatorLabels.SELECTED_OBJECT_NOT_TREE_NODE_MESSAGE);
+ }
}
return Status.OK_STATUS;
}
@Override
- public AbstractOperation prepareOperation(TreeSelection selection,
+ public AbstractOperation prepareOperation(IStructuredSelection selection,
Shell shell,
MPart activePart,
MHandledMenuItem menuItem) {
TaxonNode parentTaxonNode;
-
- List<UUID> excludeTaxa = new ArrayList<UUID>();
- excludeTaxa.add(oldTaxonNode.getTaxon().getUuid());
-
MovingType moveToNewParent = MovingType.CHILD;
if (PreferencesUtil.getSortNodesNaturally()){
parentTaxonNode = TaxonNodeSelectionDialog.select(shell,
- new ConversationHolderMock(),
+// new ConversationHolderMock(),
Messages.RemotingMoveTaxonNodeHandler_CHOOSE_TAXON,
- excludeTaxa,
+ oldTaxonNodeUUIDs,
null,
- oldTaxonNode.getClassification());
+ null, true);
String[] buttonLables = {Messages.RemotingMoveTaxonNodeHandler_CHILD, Messages.RemotingMoveTaxonNodeHandler_BEHIND,Messages.RemotingMoveTaxonNodeHandler_CANCEL};
MessageDialog dialog = new MessageDialog(null, Messages.RemotingMoveTaxonNodeHandler_TARGET_NODE, null, Messages.RemotingMoveTaxonNodeHandler_TARGET_NODE_MESSAGE, MessageDialog.QUESTION_WITH_CANCEL, buttonLables, 0);
dialog.open();
}
} else {
parentTaxonNode = TaxonNodeSelectionDialog.select(shell,
- new ConversationHolderMock(),
+// new ConversationHolderMock(),
Messages.RemotingMoveTaxonNodeHandler_CHOOSE_PARENT,
- excludeTaxa,
- oldTaxonNode,
- oldTaxonNode.getClassification());
+ oldTaxonNodeUUIDs,
+ null,
+ null, true);
}
if(parentTaxonNode != null){
- if(NavigationUtil.isDirty(parentTaxonNode)){
+ if(NavigationUtil.isDirty(parentTaxonNode, partService)){
MessageDialog.openWarning(shell,
Messages.RemotingMoveTaxonNodeHandler_UNSAVED_PARENT,
Messages.RemotingMoveTaxonNodeHandler_UNSAVED_PARENT_MESSAGE);
return new RemotingMoveTaxonOperation(getTrigger(),
false,
- oldTaxonNode.getUuid(),
+ oldTaxonNodeUUIDs,
parentTaxonNode.getUuid(),
moveToNewParent);
}
return null;
}
+ @CanExecute
+ private boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)TreeSelection selection, MHandledMenuItem menuItem){
+ boolean canExecute = false;
+ canExecute = (selection.getFirstElement() instanceof TaxonNodeDto) && ((TaxonNodeDto)selection.getFirstElement()).getTaxonUuid() != null;
+ menuItem.setVisible(canExecute);
+ return canExecute;
+ }
+
@Override
public void onComplete() {
}