diff options
author | Laurent Redor | 2016-06-10 09:18:34 +0000 |
---|---|---|
committer | Laurent Redor | 2016-06-23 08:30:56 +0000 |
commit | 00392405793fe522b104537cd28e05250f00fcd3 (patch) | |
tree | e9f6b37fc072781f8b8158400ce45308c773670d | |
parent | 205ab97c714bf3f9d93114b9498f31ffa715bea1 (diff) | |
download | org.eclipse.sirius-00392405793fe522b104537cd28e05250f00fcd3.tar.gz org.eclipse.sirius-00392405793fe522b104537cd28e05250f00fcd3.tar.xz org.eclipse.sirius-00392405793fe522b104537cd28e05250f00fcd3.zip |
[495859] Initialize wrapped command at the first call
The command is now the same in canExecute() and execute() methods. This
avoids to create the command twice (performance enhancement).
Bug: 495859
Change-Id: I0bc9a4eb2b8d38d023062d8fff541652d37c0f2e
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r-- | plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/provider/AbstractLayoutProvider.java | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/provider/AbstractLayoutProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/provider/AbstractLayoutProvider.java index bc859e99d7..430df88b01 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/provider/AbstractLayoutProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/provider/AbstractLayoutProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2016 THALES GLOBAL SERVICES 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 @@ -304,8 +304,11 @@ public abstract class AbstractLayoutProvider extends AbstractLayoutEditPartProvi */ protected static class CommandWrapper extends Command { - /** The wrapped command. */ - private Command executedCommand; + /** + * The wrapped command, initialized at the first call to + * {@link #getWrappedCommand()}. + */ + private Command wrappedCommand; /** The request. */ private final Request request; @@ -333,9 +336,7 @@ public abstract class AbstractLayoutProvider extends AbstractLayoutEditPartProvi */ @Override public void execute() { - final Command cmd = this.getWrappedCommand(); - cmd.execute(); - executedCommand = cmd; + this.getWrappedCommand().execute(); } /** @@ -379,18 +380,15 @@ public abstract class AbstractLayoutProvider extends AbstractLayoutEditPartProvi } private Command getWrappedCommand() { - final Command result; - if (executedCommand == null) { + if (wrappedCommand == null) { final Command cmd = editPart.getCommand(request); if (cmd == null) { - result = UnexecutableCommand.INSTANCE; + wrappedCommand = UnexecutableCommand.INSTANCE; } else { - result = cmd; + wrappedCommand = cmd; } - } else { - result = executedCommand; } - return result; + return wrappedCommand; } /** @@ -535,7 +533,7 @@ public abstract class AbstractLayoutProvider extends AbstractLayoutEditPartProvi private static void resetWrappedCommand(final Command command) { if (command instanceof CommandWrapper) { - ((CommandWrapper) command).executedCommand = null; + ((CommandWrapper) command).wrappedCommand = null; } else if (command instanceof CompoundCommand) { final Object[] children = ((CompoundCommand) command).getChildren(); for (Object element : children) { |