-// $Id$
/**
* Copyright (C) 2015 EDIT
* European Distributed Institute of Taxonomy
*/
package eu.etaxonomy.taxeditor.navigation.navigator.operation;
-import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.widgets.Display;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.application.CdmChangeEvent.Action;
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
import eu.etaxonomy.cdm.api.service.UpdateResult;
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
+import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
+import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.navigation.l10n.Messages;
+import eu.etaxonomy.taxeditor.navigation.navigator.e4.TaxonNavigatorE4;
+import eu.etaxonomy.taxeditor.navigation.navigator.e4.TreeNodeDropAdapterE4.MovingType;
+import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
import eu.etaxonomy.taxeditor.operation.RemotingCdmUpdateOperation;
+import eu.etaxonomy.taxeditor.store.CdmStore;
/**
* @author cmathew
* @date 19 Jun 2015
*
*/
-public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation {
+public class RemotingMoveTaxonOperation extends RemotingCdmUpdateOperation implements IPostMoniteredOperationEnabled {
- private final static String LABEL = "Move Taxon operation";
+ private final static String LABEL = Messages.RemotingMoveTaxonOperation_MOVE_OP;
private Set<UUID> taxonNodesToMoveUuid;
private final UUID newParentTreeNodeUuid;
- private final boolean moveToParentNode;
+ private final MovingType moveToParentNode;
+ private TaxonNavigatorE4 taxonNavigator;
public RemotingMoveTaxonOperation(Object source,
boolean async,
- UUID taxonNodeToMoveUuid,
+ Set<UUID> taxonNodeToMoveUuid,
UUID newParentTreeNodeUuid,
- boolean moveToParentNode) {
+ MovingType moveToParentNode) {
super(LABEL, Action.Update, source,async);
- taxonNodesToMoveUuid = new HashSet<UUID>();
- taxonNodesToMoveUuid.add(taxonNodeToMoveUuid);
+ taxonNodesToMoveUuid = taxonNodeToMoveUuid;
this.newParentTreeNodeUuid = newParentTreeNodeUuid;
this.moveToParentNode = moveToParentNode;
- }
-
- public RemotingMoveTaxonOperation(Object source,
- boolean async,
- TaxonNode taxonNodeToMove,
- TaxonNode newParentTreeNode,
- boolean moveToParentNode) {
- super(LABEL, Action.Update, source,async);
- taxonNodesToMoveUuid = new HashSet<UUID>();
- taxonNodesToMoveUuid.add(taxonNodeToMove.getUuid());
- this.newParentTreeNodeUuid = newParentTreeNode.getUuid();
- this.moveToParentNode = moveToParentNode;
- }
- public RemotingMoveTaxonOperation(Object source,
- boolean async,
- Set<UUID> taxonNodesToMoveUuid,
- TaxonNode newParentTreeNode,
- boolean moveToParentNode) {
- super(LABEL, Action.Update, source,async);
- this.taxonNodesToMoveUuid = taxonNodesToMoveUuid;
- this.newParentTreeNodeUuid = newParentTreeNode.getUuid();
- this.moveToParentNode = moveToParentNode;
}
/* (non-Javadoc)
*/
@Override
protected UpdateResult doUpdateExecute(IProgressMonitor monitor, IAdaptable info) throws Exception {
- return CdmApplicationState.getService(ITaxonNodeService.class).moveTaxonNodes(taxonNodesToMoveUuid,
- newParentTreeNodeUuid);
+ runMoniteredOperation();
+ return updateResult;
+ }
+
+ public void runMoniteredOperation() {
+ ITaxonNodeService nodeService;
+ final UUID uuid;
+ int movingTypeInt = -1;
+ switch (this.moveToParentNode) {
+ case CHILD:
+ movingTypeInt = 0;
+ break;
+ case BEHIND:
+ movingTypeInt = 2;
+ break;
+
+ default:
+ updateResult = new UpdateResult();
+ updateResult.setAbort();
+ updateResult.addException(new Exception("The moving type is invalid.")); //$NON-NLS-1$
+
+ }
+ if (movingTypeInt >-1){
+ uuid = CdmApplicationState.getLongRunningTasksService().monitLongRunningTask(taxonNodesToMoveUuid,
+ newParentTreeNodeUuid, movingTypeInt);
+
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ AbstractUtility.executeMoniteredOperation("Move Taxon to new parent: ",
+ uuid,
+ 500,
+ false,
+ RemotingMoveTaxonOperation.this,
+ null,
+ true);
+ }
+ });
+ }
+
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void postOperation(IRemotingProgressMonitor monitor) {
+ monitor.done();
+ TaxonNodeDto parentDto = CdmStore.getService(ITaxonNodeService.class).dto(newParentTreeNodeUuid);
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, parentDto);
+
}
}