diff options
author | Camille Letavernier | 2015-12-14 09:16:30 +0000 |
---|---|---|
committer | Camille Letavernier | 2015-12-14 09:16:30 +0000 |
commit | 84d9e14baaef64fe0b462a7f28270fb21fb4b081 (patch) | |
tree | 48f1c50332d6030a1b6f36286e43faf5a27cf05e /plugins | |
parent | 3d832f3db477c0ec841ef509dcfa93569e5ec386 (diff) | |
download | org.eclipse.papyrus-84d9e14baaef64fe0b462a7f28270fb21fb4b081.tar.gz org.eclipse.papyrus-84d9e14baaef64fe0b462a7f28270fb21fb4b081.tar.xz org.eclipse.papyrus-84d9e14baaef64fe0b462a7f28270fb21fb4b081.zip |
Revert "Bug 483436 [Api] Break in CustomizableDropEditPolicy"
This reverts commit 4b1361f7269cf0db9ce94494de959859a64a1435.
Diffstat (limited to 'plugins')
3 files changed, 209 insertions, 335 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java index f26f2ccb5a8..8387e373cc3 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java @@ -15,7 +15,6 @@ package org.eclipse.papyrus.infra.gmfdiag.dnd.policy; import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; @@ -46,7 +45,6 @@ import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand import org.eclipse.papyrus.infra.gmfdiag.dnd.Activator; import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.DefaultDropStrategy; import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.DropStrategy; -import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.MultipleDropStrategy; import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalCommandsDropStrategy; import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy; import org.eclipse.swt.dnd.DND; @@ -230,53 +228,29 @@ public class CustomizableDropEditPolicy extends DragDropEditPolicy { * @return */ protected Command getCustomCommand(Request request) { - //extendedMatchingStrategies match Strategy to List of Commands - final Map<DropStrategy, List<Command>> extendedMatchingStrategies = findExtendedStrategies(request); - - //Reverting to a simple matchingStrategies a strategy to a command - final Map<DropStrategy, Command> matchingStrategies = getStrategies(extendedMatchingStrategies); - + final Map<DropStrategy, List<Command>> matchingStrategies = findStrategies(request); // Only one strategy: return the associated command - if (extendedMatchingStrategies.size() == 1) { - //Switch case if the DropStrategy is able to propose multiple commands - DropStrategy dropStrategy = extendedMatchingStrategies.keySet().iterator().next(); - if(dropStrategy instanceof MultipleDropStrategy){ - List<Command> proposalCommands = new ArrayList<Command>(); - List<Command> cs = ((MultipleDropStrategy)dropStrategy).getCommands(request, getHost()); - for(Command command : cs){ - if (command != null && command.canExecute()) { - proposalCommands.add(command); - } - } - - // If there is no default choice, ask user (Open a choice List) - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - - DefaultActionHandler handler = new DefaultActionHandler() { - - public void defaultActionSelected(Command defaultCommand) { - //At present time, no default command for MultipleDropStrategy - } - - public String getLabel() { - return "Change the default strategy"; - } - }; - - Activator.log.info("proposalCommands"+proposalCommands.size());; - SelectAndExecuteCommand command = new SelectAndExecuteCommand("Select drop", shell, new LinkedList<Command>(proposalCommands), handler); - return new ICommandProxy(command); - - } - else{ - return matchingStrategies.values().iterator().next(); + if (matchingStrategies.size() == 1) { + DropStrategy ds = matchingStrategies.keySet().iterator().next(); + if (ds instanceof TransactionalDropStrategy) { + // given a drop strategy, return the single associated command. + return matchingStrategies.get(ds).get(0); + } else if (ds instanceof TransactionalCommandsDropStrategy) { + // this case is not manage, the default command associated with a TransactionalCommandsDropStrategy + // in charge of managing multiple commands per strategy is not take into account in this version. + return null; + } else if (ds instanceof DefaultDropStrategy) { + // given a default drop strategy, return the single associated command. + return matchingStrategies.get(ds).get(0); + } else { + Activator.log.warn("Drop strategy not taken into account: " + ds); + return null; } - } // More than one strategy - if (extendedMatchingStrategies.size() > 1) { + if (matchingStrategies.size() > 1) { boolean useDefault = true; // FIXME: What's the exact semantic of EVENT_DETAIL=DND_COPY in Papyrus? @@ -288,11 +262,20 @@ public class CustomizableDropEditPolicy extends DragDropEditPolicy { } } - // Search for a default strategy in case of basic DropStrategy + // Search for a default strategy if (useDefault) { DropStrategy defaultStrategy = DropStrategyManager.instance.getDefaultDropStrategy(matchingStrategies.keySet()); if (defaultStrategy != null) { - return matchingStrategies.get(defaultStrategy); + + if (defaultStrategy instanceof TransactionalCommandsDropStrategy) { + // this case is not managed due to multiple commands associated with the strategy + Activator.log.warn("Default strategies of type TransactionalCommandsDropStrategy are not taken into account"); + return null; + } else if (defaultStrategy instanceof TransactionalDropStrategy) { + // return the single command associated with a TransactionalDropStrategy + return matchingStrategies.get(defaultStrategy).get(0); + } + } } @@ -303,7 +286,7 @@ public class CustomizableDropEditPolicy extends DragDropEditPolicy { DefaultActionHandler handler = new DefaultActionHandler() { public void defaultActionSelected(Command defaultCommand) { - DropStrategy defaultStrategy = findExtendedStrategy(extendedMatchingStrategies, defaultCommand); + DropStrategy defaultStrategy = findStrategy(matchingStrategies, defaultCommand); if (defaultStrategy != null) { DropStrategyManager.instance.setDefaultDropStrategy(matchingStrategies.keySet(), defaultStrategy); } @@ -315,14 +298,13 @@ public class CustomizableDropEditPolicy extends DragDropEditPolicy { }; ArrayList<Command> proposalCommands = new ArrayList<Command>(); - for(List<Command> cs: extendedMatchingStrategies.values()){ - for(Command c : cs){ - if(c!=null){ + for (List<Command> cs : matchingStrategies.values()) { + for (Command c : cs) { + if (c != null) { proposalCommands.add(c); } } } - Activator.log.info("proposalCommands"+proposalCommands.size());; SelectAndExecuteCommand command = new SelectAndExecuteCommand("Select drop", shell, new LinkedList<Command>(proposalCommands), handler); return new ICommandProxy(command); } @@ -331,17 +313,8 @@ public class CustomizableDropEditPolicy extends DragDropEditPolicy { return null; } - protected static DropStrategy findStrategy(Map<DropStrategy, Command> matchingStrategies, Command command) { - for (Map.Entry<DropStrategy, Command> entry : matchingStrategies.entrySet()) { - if (entry.getValue() == command ) { - return entry.getKey(); - } - } - return null; - } - - protected static DropStrategy findExtendedStrategy(Map<DropStrategy, List<Command>> extendedMatchingStrategies, Command command) { - for (Map.Entry<DropStrategy, List<Command>> entry : extendedMatchingStrategies.entrySet()) { + private static DropStrategy findStrategy(Map<DropStrategy, List<Command>> matchingStrategies, Command command) { + for (Map.Entry<DropStrategy, List<Command>> entry : matchingStrategies.entrySet()) { if (entry.getValue().contains(command)) { return entry.getKey(); @@ -351,109 +324,51 @@ public class CustomizableDropEditPolicy extends DragDropEditPolicy { } /** - * Returns a map of DropStrategy / Command, from an initial Map that maps DropStrategy to List of commands. The map may be empty. - * - * @param Map<DropStrategy, List<Command>> - * @return - */ - protected Map<DropStrategy, Command> getStrategies(Map<DropStrategy, List<Command>> extendedMatchingStrategies) { - Map<DropStrategy, Command> matchingStrategies = new LinkedHashMap<DropStrategy, Command>(); - for(DropStrategy d : extendedMatchingStrategies.keySet()){ - Iterator<Command> i = extendedMatchingStrategies.get(d).iterator(); - if(i.hasNext()){ - matchingStrategies.put(d, i.next()); - } - } - return matchingStrategies; - } - - /** - * Returns a map of DropStrategy / Command, for each Strategy which can handle - * the given request. All the returned commands are executable. The map may be empty. - * - * @param request - * @return - */ - protected Map<DropStrategy, Command> findStrategies(Request request) { - Map<DropStrategy, Command> matchingStrategies = new LinkedHashMap<DropStrategy, Command>(); - - for (DropStrategy strategy : DropStrategyManager.instance.getActiveStrategies()) { - try { // Strategies are provided through extension points; we can't guarantee they won't crash - - if(strategy instanceof MultipleDropStrategy){ - List<Command> commands = ((MultipleDropStrategy)strategy).getCommands(request, getHost()); - if (commands != null && commands.size()>0) { - //take the first one, and fill the map withit - Command command =commands.get(0); - if (command != null && command.canExecute()) { - matchingStrategies.put(strategy, command); - } - } - } - else{ - - Command command = strategy.getCommand(request, getHost()); - if (command != null && command.canExecute()) { - matchingStrategies.put(strategy, command); - } - } - } catch (Throwable t) { - String message = String.format("An error occurred when trying to execute a custom Drop strategy: %s", strategy.getLabel()); - Activator.log.error(message, t); - } - } - - Command command = defaultDropStrategy.getCommand(request, getHost()); - if (command != null && command.canExecute()) { - matchingStrategies.put(defaultDropStrategy, command); - } - - return matchingStrategies; - } - - /** * Returns a map of DropStrategy / Command, for each Strategy which can handle * the given request. All the returned commands are executable. The map may be empty. * * @param request - * @return + * @return a non null map, and foreach DropStrategy a non null List */ - protected Map<DropStrategy, List<Command>> findExtendedStrategies(Request request) { + protected Map<DropStrategy, List<Command>> findStrategies(Request request) { Map<DropStrategy, List<Command>> matchingStrategies = new LinkedHashMap<DropStrategy, List<Command>>(); - //Retrieve strategies + // Retrieve strategies for (DropStrategy strategy : DropStrategyManager.instance.getActiveStrategies()) { ArrayList<Command> selectedCommands = new ArrayList<Command>(); - if(strategy instanceof TransactionalCommandsDropStrategy){ - List<Command> cs = ((TransactionalCommandsDropStrategy)strategy).getCommands(request, getHost()); - for(Command command : cs){ + if (strategy instanceof TransactionalCommandsDropStrategy) { + List<Command> cs = ((TransactionalCommandsDropStrategy) strategy).getCommands(request, getHost()); + for (Command command : cs) { if (command != null && command.canExecute()) { selectedCommands.add(command); } } - } - else if(strategy instanceof TransactionalDropStrategy){ + } else { Command command = strategy.getCommand(request, getHost()); if (command != null && command.canExecute()) { selectedCommands.add(command); } } - - matchingStrategies.put(strategy, selectedCommands); + // Do not reference strategies that have no executable commands + if (selectedCommands.size() > 0) { + matchingStrategies.put(strategy, selectedCommands); + } } - //Retrieve defaultStrategy - ArrayList<Command> selectedCommands = new ArrayList<Command>(); - selectedCommands.add(defaultDropStrategy.getCommand(request, getHost())); - matchingStrategies.put(defaultDropStrategy, selectedCommands); + // Retrieve defaultStrategy + Command command = defaultDropStrategy.getCommand(request, getHost()); + if (command != null && command.canExecute()) { + ArrayList<Command> selectedCommands = new ArrayList<Command>(); + selectedCommands.add(command); + matchingStrategies.put(defaultDropStrategy, selectedCommands); + } return matchingStrategies; } - /** * @see org.eclipse.gef.EditPolicy#showTargetFeedback(org.eclipse.gef.Request) */ diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/MultipleDropStrategy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/MultipleDropStrategy.java deleted file mode 100644 index 30f89b864be..00000000000 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/MultipleDropStrategy.java +++ /dev/null @@ -1,41 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2015 CEA LIST and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * CEA LIST - Initial API and implementation - * - *****************************************************************************/ - -package org.eclipse.papyrus.infra.gmfdiag.dnd.strategy; - -import java.util.List; - -import org.eclipse.gef.EditPart; -import org.eclipse.gef.Request; -import org.eclipse.gef.commands.Command; - -/** - * @author flefevre - * - */ -public interface MultipleDropStrategy extends DropStrategy { - - /** - * The list of candidates commandes to be executed when the strategy is applied. - * Should return null if the strategy cannot handle the request. - * - * @param request - * The drop request - * @param targetEditPart - * The target edit part - * @return - * A list of commands, or null if the strategy cannot handle the request - */ - public List<Command> getCommands(Request request, EditPart targetEditPart); - -} diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/TransactionalCommandsDropStrategy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/TransactionalCommandsDropStrategy.java index 8d2f1b69cee..0dd83ae790d 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/TransactionalCommandsDropStrategy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/TransactionalCommandsDropStrategy.java @@ -1,157 +1,157 @@ -/***************************************************************************** - * Copyright (c) 2012 CEA LIST. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.infra.gmfdiag.dnd.strategy; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.emf.edit.domain.EditingDomain; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.gef.EditPart; -import org.eclipse.gef.Request; -import org.eclipse.gef.commands.Command; -import org.eclipse.gmf.runtime.common.core.command.CommandResult; -import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; -import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; -import org.eclipse.papyrus.infra.emf.utils.EMFHelper; -import org.eclipse.papyrus.infra.gmfdiag.dnd.Activator; - -/** - * An abstract implementation for TransactionalCommandsDropStrategy. Extenders do not - * need to implement their commands' #undo and #redo methods. - * The differences with TransactionalDropStrategy is the fact that this class give the priority to the CommandS rather to the Command - * - * @author Camille Letavernier - */ -public abstract class TransactionalCommandsDropStrategy extends AbstractDropStrategy implements MultipleDropStrategy { - - protected boolean isTransactional(EditPart targetEditPart) { - return getTransactionalEditingDomain(targetEditPart) != null; - } - - protected TransactionalEditingDomain getTransactionalEditingDomain(EditPart targetEditPart) { - EditingDomain domain = getEditingDomain(targetEditPart); - if (domain instanceof TransactionalEditingDomain) { - return (TransactionalEditingDomain) domain; - } - return null; - } - - protected EditingDomain getEditingDomain(EditPart targetEditPart) { - return EMFHelper.resolveEditingDomain(targetEditPart); - } - - protected abstract List<Command> doGetCommands(Request request, EditPart targetEditPart); - - - /** - * The command to be executed when the strategy is applied. - * Should return null if the strategy cannot handle the request. - * - * @param request - * The drop request - * @param targetEditPart - * The target edit part - * @return - * A command, or null if the strategy cannot handle the request - */ - protected Command doGetCommand(Request request, EditPart targetEditPart) { - List<Command> commands = doGetCommands(request, targetEditPart); - if(commands!=null && commands.size()>0){ - return commands.get(0); - } - return null; - } - - /** - * @see org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.DropStrategy#getCommands(org.eclipse.gef.Request, org.eclipse.gef.EditPart) - * - * @param request - * @param targetEditPart - * @return - */ - public List<Command> getCommands(Request request, EditPart targetEditPart) { - List<Command> commands = new ArrayList<Command>(); - if(doGetCommands(request,targetEditPart)!=null && doGetCommands(request,targetEditPart).size()!=0){ - - for(final Command c : doGetCommands(request,targetEditPart)){ - String label = c.getLabel(); - if (label == null || "".equals(label)) { - label = getLabel(); - } - - AbstractTransactionalCommand transactionalCommand = new AbstractTransactionalCommand(getTransactionalEditingDomain(targetEditPart), label, null) { - - @Override - protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - try { - c.execute(); - return CommandResult.newOKCommandResult(); - } catch (Exception ex) { - Activator.log.error(ex); - return CommandResult.newErrorCommandResult(ex); - } - } - }; - commands.add(new ICommandProxy(transactionalCommand)); - } - } - return commands; - } - - /** - * @see org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.DropStrategy#getCommand(org.eclipse.gef.Request, org.eclipse.gef.EditPart) - * - * @param request - * @param targetEditPart - * @return - */ - public Command getCommand(Request request, EditPart targetEditPart) { - - final Command command; - List<Command> commands = doGetCommands(request,targetEditPart); - if(commands!=null && commands.size()>0){ - command = commands.get(0); - } - else{ - return null; - } - - if (command == null) { - return null; - } - - String label = command.getLabel(); - if (label == null || "".equals(label)) { - label = getLabel(); - } - - AbstractTransactionalCommand transactionalCommand = new AbstractTransactionalCommand(getTransactionalEditingDomain(targetEditPart), label, null) { - - @Override - protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - try { - command.execute(); - return CommandResult.newOKCommandResult(); - } catch (Exception ex) { - Activator.log.error(ex); - return CommandResult.newErrorCommandResult(ex); - } - } - }; - - return new ICommandProxy(transactionalCommand); - } -} +/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.dnd.strategy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.dnd.Activator;
+
+/**
+ * An abstract implementation for TransactionalCommandsDropStrategy. Extenders do not
+ * need to implement their commands' #undo and #redo methods.
+ * The differences with TransactionalDropStrategy is the fact that this class give the priority to the CommandS rather to the Command
+ *
+ * @author Camille Letavernier
+ */
+public abstract class TransactionalCommandsDropStrategy extends TransactionalDropStrategy {
+
+ protected boolean isTransactional(EditPart targetEditPart) {
+ return getTransactionalEditingDomain(targetEditPart) != null;
+ }
+
+ protected TransactionalEditingDomain getTransactionalEditingDomain(EditPart targetEditPart) {
+ EditingDomain domain = getEditingDomain(targetEditPart);
+ if (domain instanceof TransactionalEditingDomain) {
+ return (TransactionalEditingDomain) domain;
+ }
+ return null;
+ }
+
+ protected EditingDomain getEditingDomain(EditPart targetEditPart) {
+ return EMFHelper.resolveEditingDomain(targetEditPart);
+ }
+
+ protected abstract List<Command> doGetCommands(Request request, EditPart targetEditPart);
+
+
+ /**
+ * The command to be executed when the strategy is applied.
+ * Should return null if the strategy cannot handle the request.
+ *
+ * @param request
+ * The drop request
+ * @param targetEditPart
+ * The target edit part
+ * @return
+ * A command, or null if the strategy cannot handle the request
+ */
+ protected Command doGetCommand(Request request, EditPart targetEditPart) {
+ List<Command> commands = doGetCommands(request, targetEditPart);
+ if(commands!=null && commands.size()>0){
+ return commands.get(0);
+ }
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.DropStrategy#getCommands(org.eclipse.gef.Request, org.eclipse.gef.EditPart)
+ *
+ * @param request
+ * @param targetEditPart
+ * @return
+ */
+ public List<Command> getCommands(Request request, EditPart targetEditPart) {
+ List<Command> commands = new ArrayList<Command>();
+ if(doGetCommands(request,targetEditPart)!=null && doGetCommands(request,targetEditPart).size()!=0){
+
+ for(final Command c : doGetCommands(request,targetEditPart)){
+ String label = c.getLabel();
+ if (label == null || "".equals(label)) {
+ label = getLabel();
+ }
+
+ AbstractTransactionalCommand transactionalCommand = new AbstractTransactionalCommand(getTransactionalEditingDomain(targetEditPart), label, null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ try {
+ c.execute();
+ return CommandResult.newOKCommandResult();
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ return CommandResult.newErrorCommandResult(ex);
+ }
+ }
+ };
+ commands.add(new ICommandProxy(transactionalCommand));
+ }
+ }
+ return commands;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.DropStrategy#getCommand(org.eclipse.gef.Request, org.eclipse.gef.EditPart)
+ *
+ * @param request
+ * @param targetEditPart
+ * @return
+ */
+ public Command getCommand(Request request, EditPart targetEditPart) {
+
+ final Command command;
+ List<Command> commands = doGetCommands(request,targetEditPart);
+ if(commands!=null && commands.size()>0){
+ command = commands.get(0);
+ }
+ else{
+ return null;
+ }
+
+ if (command == null) {
+ return null;
+ }
+
+ String label = command.getLabel();
+ if (label == null || "".equals(label)) {
+ label = getLabel();
+ }
+
+ AbstractTransactionalCommand transactionalCommand = new AbstractTransactionalCommand(getTransactionalEditingDomain(targetEditPart), label, null) {
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ try {
+ command.execute();
+ return CommandResult.newOKCommandResult();
+ } catch (Exception ex) {
+ Activator.log.error(ex);
+ return CommandResult.newErrorCommandResult(ex);
+ }
+ }
+ };
+
+ return new ICommandProxy(transactionalCommand);
+ }
+}
|