Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java95
1 files changed, 8 insertions, 87 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java
index 09613a5afd4..4567e2afa28 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/handler/CutHandler.java
@@ -13,25 +13,12 @@
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer.handler;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.command.CompoundCommand;
-import org.eclipse.emf.common.command.UnexecutableCommand;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.DefaultCopyCommand;
-import org.eclipse.papyrus.infra.gmfdiag.common.strategy.IStrategy;
-import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.IPasteStrategy;
-import org.eclipse.papyrus.infra.gmfdiag.common.strategy.paste.PasteStrategyManager;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
/**
* Handler for the Cut Action in Model Explorer : it's a copy followed by a delete
@@ -48,89 +35,23 @@ public class CutHandler extends AbstractCommandHandler {
@Override
protected Command getCommand() {
CompoundCommand cutInModelExplorerCommand = new CompoundCommand("Cut in Model Explorer Command"); //$NON-NLS-1$
- DefaultCopyCommand copyCommand = buildCopyCommand();
+ Command copyCommand = CopyHandler.buildCopyCommand(getEditingDomain(), getSelectedElements());
cutInModelExplorerCommand.append(copyCommand);
- Command create = buildDeleteCommand();
- cutInModelExplorerCommand.append(create);
+ Command deleteCommand = DeleteCommandHandler.buildDeleteCommand(getSelectedElements());
+ cutInModelExplorerCommand.append(deleteCommand);
return cutInModelExplorerCommand;
}
-
- /**
- * Construct a copy command with the cut selection
- * @return the copy command
- */
- protected DefaultCopyCommand buildCopyCommand() {
- List<EObject> selection = getSelectedElements();
- TransactionalEditingDomain editingDomain = getEditingDomain();
- PapyrusClipboard<Object> papyrusClipboard = PapyrusClipboard.getNewInstance();
- DefaultCopyCommand defaultCopyCommand = new DefaultCopyCommand(editingDomain, papyrusClipboard, selection);
- List<IStrategy> allStrategies = PasteStrategyManager.getInstance().getAllStrategies();
- for(IStrategy iStrategy : allStrategies) {
- IPasteStrategy iPasteStrategy = (IPasteStrategy)iStrategy;
- iPasteStrategy.prepare(papyrusClipboard);
- }
- return defaultCopyCommand;
- }
-
-
/**
- * Construct a delete command with the cut selection
- * @return the delete command
- */
- protected Command buildDeleteCommand() {
-
- ICommand gmfCommand = null;
-
- // Parameters store the Request parameters of the previous request
- // if multiple elements are selected for deletion.
- Map parameters = new HashMap();
-
- for(EObject selectedEObject : getSelectedElements()) {
-
- if(selectedEObject == null) {
- continue;
- }
-
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(selectedEObject);
- if(provider == null) {
- continue;
- }
-
- // Retrieve delete command from the Element Edit service
- DestroyElementRequest request = new DestroyElementRequest(selectedEObject, false);
- // Add parameters (contains the list of previously dependents to be deleted
- // by previous commands.
- request.getParameters().putAll(parameters);
-
- ICommand deleteCommand = provider.getEditCommand(request);
-
- // Add current EObject destroy command to the global command
- gmfCommand = CompositeCommand.compose(gmfCommand, deleteCommand);
-
- // Store the new parameters for next delete command.
- parameters.clear();
- parameters.putAll(request.getParameters());
- }
-
- if(gmfCommand == null) {
- return UnexecutableCommand.INSTANCE;
- }
-
- Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(gmfCommand.reduce());
- return emfCommand;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler#computeEnabled()
+ * {@inheritDoc}
*/
@Override
- protected boolean computeEnabled() { // copy is enable as long as there is an EObject to put in the Clipboard
- return !getSelectedElements().isEmpty();
+ protected boolean computeEnabled() {
+ List<EObject> selectedElements = getSelectedElements();
+ return CopyHandler.isCopyEnabled(selectedElements) && DeleteCommandHandler.isDeleteEnabled(selectedElements);
}
+
/*
* (non-Javadoc)
*

Back to the top