Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGabriel Pascual2014-12-16 15:29:47 +0000
committerGabriel Pascual2014-12-16 15:32:47 +0000
commitaa9edd5250ba1ae0d2013eaeeb3e54a75e9cec8f (patch)
tree575510d7eb68025aa5120be6c73148cef36ee701 /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu
parentf6ea58918b8098ceff7a997e127742b6f258a6c0 (diff)
downloadorg.eclipse.papyrus-aa9edd5250ba1ae0d2013eaeeb3e54a75e9cec8f.tar.gz
org.eclipse.papyrus-aa9edd5250ba1ae0d2013eaeeb3e54a75e9cec8f.tar.xz
org.eclipse.papyrus-aa9edd5250ba1ae0d2013eaeeb3e54a75e9cec8f.zip
455305: [Performances] Copy/Cut/Paste commands show severe performance
degradation https://bugs.eclipse.org/bugs/show_bug.cgi?id=455305 - Implement computeEnable() when is necessary - Overriden setEnable() instead of isEnable() method Change-Id: Ie9acd89a5520d940785d1e27124f63e260e7d391 Signed-off-by: Gabriel Pascual <gabriel.pascual@all4tec.net>
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java119
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java69
2 files changed, 128 insertions, 60 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java
index 6efe2b00689..122c3928ce9 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CopyInDiagramHandler.java
@@ -10,7 +10,7 @@
* Contributors:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - bug 430701
- * Gabriel Pascual (ALL4TEC) - bug 441318
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - bug 441318, bug 455305
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.menu.handlers;
@@ -19,7 +19,6 @@ import java.util.Collection;
import java.util.List;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -28,7 +27,6 @@ import org.eclipse.gef.commands.Command;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.internal.commands.CopyCommand;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
import org.eclipse.gmf.runtime.diagram.ui.render.clipboard.AWTClipboardHelper;
import org.eclipse.gmf.runtime.diagram.ui.render.internal.commands.CopyImageCommand;
@@ -56,13 +54,32 @@ import org.eclipse.swt.widgets.Text;
*/
public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
+ /** The Constant COPY_COMMAND_LABEL. */
+ private static final String COPY_COMMAND_LABEL = "Copy In Diagram"; //$NON-NLS-1$
+
+ /** The Constant ACTIVE_SHELL_VARIABLE_KEY. */
+ private static final String ACTIVE_SHELL_VARIABLE_KEY = "activeShell"; //$NON-NLS-1$
+
+ /** The Constant ACTIVE_FOCUS_VARIABLE_KEY. */
+ private static final String ACTIVE_FOCUS_VARIABLE_KEY = "activeFocusControl"; //$NON-NLS-1$
+
+ /** The Constant COPY_IMAGE_COMMAND_LABEL. */
+ private static final String COPY_IMAGE_COMMAND_LABEL = "Create image to allow paste on system"; //$NON-NLS-1$
+
+ /** The active focus control. */
+ private Object activeFocusControl = null;
+
+ /** The active shell. */
+ private Object activeShell = null;
/**
* Construct copy command from the selection.
*
- * @param editingDomain the editing domain
- * @param selectedElements the selected elements
+ * @param editingDomain
+ * the editing domain
+ * @param selectedElements
+ * the selected elements
* @return the command
*/
public static Command buildCopyCommand(TransactionalEditingDomain editingDomain, Collection<IGraphicalEditPart> selectedElements) {
@@ -81,7 +98,7 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
selectedElementModels.add(iGraphicalEditPart.getModel());
}
- PapyrusCopyImageCommand copyImageCommand = new PapyrusCopyImageCommand("Create image to allow paste on system", diagram, selectedElementModels, diagramEditPart); //$NON-NLS-1$
+ PapyrusCopyImageCommand copyImageCommand = new PapyrusCopyImageCommand(COPY_IMAGE_COMMAND_LABEL, diagram, selectedElementModels, diagramEditPart);
if (copyImageCommand.canExecute()) {
Command gmFtoGEFCommandWrapper = GMFtoGEFCommandWrapper.wrap(copyImageCommand);
result = NonDirtyingUtils.chain(result, gmFtoGEFCommandWrapper);
@@ -94,7 +111,7 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
IPasteStrategy iIPasteStrategy = (IPasteStrategy) iStrategy;
iIPasteStrategy.prepare(papyrusClipboard, null);
}
-
+ result.setLabel(COPY_COMMAND_LABEL);
return result;
}
@@ -121,29 +138,44 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
*/
@Override
public void setEnabled(Object evaluationContext) {
+
+ // Local handling
if (evaluationContext instanceof IEvaluationContext) {
IEvaluationContext iEvaluationContext = (IEvaluationContext) evaluationContext;
- Object activeFocusControl = iEvaluationContext.getVariable("activeFocusControl"); //$NON-NLS-1$
- Object activeShell = iEvaluationContext.getVariable("activeShell"); //$NON-NLS-1$
- Control focusControl = null;
- if (activeShell instanceof Shell) {
- Shell shell = (Shell) activeShell;
- Display display = shell.getDisplay();
- if (display != null) {
- focusControl = display.getFocusControl();
- }
- }
- if (activeFocusControl instanceof StyledText || focusControl instanceof Text) { // true if the focus is on an internal xtext editor or a text edit
- setBaseEnabled(false);
- } else {
- PapyrusClipboard<Object> instance = PapyrusClipboard.getInstance();
- super.setEnabled(evaluationContext);
- PapyrusClipboard.setInstance(instance);
- }
+ activeFocusControl = iEvaluationContext.getVariable(ACTIVE_FOCUS_VARIABLE_KEY);
+ activeShell = iEvaluationContext.getVariable(ACTIVE_SHELL_VARIABLE_KEY);
}
+
+ // Parent handling
+ super.setEnabled(evaluationContext);
}
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.menu.handlers.AbstractGraphicalCommandHandler#computeEnabled()
+ *
+ * @return
+ */
+ @Override
+ protected boolean computeEnabled() {
+ boolean isEnable = false;
+ Control focusControl = null;
+ if (activeShell instanceof Shell) {
+ Shell shell = (Shell) activeShell;
+ Display display = shell.getDisplay();
+ if (display != null) {
+ focusControl = display.getFocusControl();
+ }
+ }
+ if (!(activeFocusControl instanceof StyledText) && !(focusControl instanceof Text)) { // false if the focus is on an internal xtext editor or a text edit
+ PapyrusClipboard<Object> instance = PapyrusClipboard.getInstance();
+ PapyrusClipboard.setInstance(instance);
+ isEnable = true;
+ }
+
+ return isEnable;
+
+ }
/**
* Papyrus implementation of {@link CopyImageCommand}.
@@ -151,21 +183,26 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
* <p>
* Bug 441318 :<br/>
* Fix override {@link CopyImageCommand} to permit Undo. This workaround is used by GMF.
- *</p>
+ * </p>
*/
@SuppressWarnings("restriction")
static class PapyrusCopyImageCommand extends org.eclipse.gmf.runtime.diagram.ui.render.internal.commands.CopyImageCommand implements INonDirtying {
-
+
/**
* Instantiates a new papyrus copy image command.
*
- * @param label the label
- * @param viewContext the view context
- * @param source the source
- * @param diagramEP the diagram ep
+ * @param label
+ * the label
+ * @param viewContext
+ * the view context
+ * @param source
+ * the source
+ * @param diagramEP
+ * the diagram ep
*/
- PapyrusCopyImageCommand(String label, View viewContext, @SuppressWarnings("rawtypes") List source, DiagramEditPart diagramEP) { super(label, viewContext, source, diagramEP);
+ PapyrusCopyImageCommand(String label, View viewContext, @SuppressWarnings("rawtypes") List source, DiagramEditPart diagramEP) {
+ super(label, viewContext, source, diagramEP);
}
/**
@@ -177,13 +214,14 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
public boolean canExecute() {
return AWTClipboardHelper.getInstance().isImageCopySupported();
}
-
+
/**
* Can undo.
*
* @return true, if successful
* @see org.eclipse.gmf.runtime.diagram.ui.render.internal.commands.CopyImageCommand#canUndo()
*/
+ @Override
public boolean canUndo() {
return true;
}
@@ -193,6 +231,7 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
*
* @return
*/
+ @Override
public boolean canRedo() {
return true;
}
@@ -205,10 +244,11 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
* @return
* @throws ExecutionException
*/
+ @Override
protected CommandResult doUndoWithResult(
- IProgressMonitor progressMonitor, IAdaptable info)
- throws ExecutionException {
-
+ IProgressMonitor progressMonitor, IAdaptable info)
+ throws ExecutionException {
+
return CommandResult.newOKCommandResult();
}
@@ -220,12 +260,13 @@ public class CopyInDiagramHandler extends AbstractGraphicalCommandHandler {
* @return
* @throws ExecutionException
*/
+ @Override
protected CommandResult doRedoWithResult(
- IProgressMonitor progressMonitor, IAdaptable info)
- throws ExecutionException {
-
+ IProgressMonitor progressMonitor, IAdaptable info)
+ throws ExecutionException {
+
return CommandResult.newOKCommandResult();
}
-
+
}
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java
index bfe87514368..492bee3b170 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.menu/src/org/eclipse/papyrus/infra/gmfdiag/menu/handlers/CutInDiagramHandler.java
@@ -9,6 +9,7 @@
*
* Contributors:
* Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - bug 455305
*
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.menu.handlers;
@@ -40,12 +41,27 @@ import org.eclipse.swt.widgets.Text;
*/
public class CutInDiagramHandler extends AbstractGraphicalCommandHandler {
+ /** The Constant DELETE_COMMAND_LABEL. */
+ private static final String DELETE_COMMAND_LABEL = "Delete From Model"; //$NON-NLS-1$
+
+ /** The Constant CUT_COMMAND_LABEL. */
+ private static final String CUT_COMMAND_LABEL = "Cut In Diagram Command"; //$NON-NLS-1$
+
+ /** The Constant ACTIVE_SHELL. */
private static final String ACTIVE_SHELL = "activeShell"; //$NON-NLS-1$
+
+ /** The Constant ACTIVE_FOCUS_CONTROL. */
private static final String ACTIVE_FOCUS_CONTROL = "activeFocusControl"; //$NON-NLS-1$
+ /** The active focus control. */
+ private Object activeFocusControl;
+
+ /** The active shell. */
+ private Object activeShell;
+
@Override
protected Command getCommand() {
- CompoundCommand cutInDiagramCommand = new CompoundCommand("Cut in Diagram Command"); //$NON-NLS-1$
+ CompoundCommand cutInDiagramCommand = new CompoundCommand(CUT_COMMAND_LABEL);
Command buildCopy = CopyInDiagramHandler.buildCopyCommand(getEditingDomain(), getSelectedElements());
cutInDiagramCommand.add(buildCopy);
Command buildDelete = buildDeleteCommand();
@@ -75,7 +91,7 @@ public class CutInDiagramHandler extends AbstractGraphicalCommandHandler {
// Iterate over selection and retrieve the deletion command from each
// edit part
// Add each returned command to the composite command
- CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Delete From Model"); //$NON-NLS-1$
+ CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, DELETE_COMMAND_LABEL);
Iterator<IGraphicalEditPart> it = editParts.iterator();
while (it.hasNext()) {
@@ -99,7 +115,7 @@ public class CutInDiagramHandler extends AbstractGraphicalCommandHandler {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.papyrus.infra.gmfdiag.menu.handlers.
* AbstractGraphicalCommandHandler#setEnabled(java.lang.Object)
*/
@@ -107,26 +123,37 @@ public class CutInDiagramHandler extends AbstractGraphicalCommandHandler {
public void setEnabled(Object evaluationContext) {
if (evaluationContext instanceof IEvaluationContext) {
IEvaluationContext iEvaluationContext = (IEvaluationContext) evaluationContext;
- Object activeFocusControl = iEvaluationContext.getVariable(ACTIVE_FOCUS_CONTROL);
- Object activeShell = iEvaluationContext.getVariable(ACTIVE_SHELL);
- Control focusControl = null;
- if (activeShell instanceof Shell) {
- Shell shell = (Shell) activeShell;
- Display display = shell.getDisplay();
- if (display != null) {
- focusControl = display.getFocusControl();
- }
- }
- if (activeFocusControl instanceof StyledText || focusControl instanceof Text) { // true if the focus is
- // on an internal xtext
- // editor or a text edit
- setBaseEnabled(false);
- } else {
- PapyrusClipboard<Object> instance = PapyrusClipboard.getInstance();
- super.setEnabled(evaluationContext);
- PapyrusClipboard.setInstance(instance);
+ activeFocusControl = iEvaluationContext.getVariable(ACTIVE_FOCUS_CONTROL);
+ activeShell = iEvaluationContext.getVariable(ACTIVE_SHELL);
+
+ }
+
+ super.setEnabled(evaluationContext);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.menu.handlers.AbstractGraphicalCommandHandler#computeEnabled()
+ *
+ * @return
+ */
+ @Override
+ protected boolean computeEnabled() {
+ boolean isEnabled = false;
+ Control focusControl = null;
+ if (activeShell instanceof Shell) {
+ Shell shell = (Shell) activeShell;
+ Display display = shell.getDisplay();
+ if (display != null) {
+ focusControl = display.getFocusControl();
}
}
+ if (!(activeFocusControl instanceof StyledText) && !(focusControl instanceof Text)) { // false if the focus is on an internal xtext editor or a text edit
+ PapyrusClipboard<Object> instance = PapyrusClipboard.getInstance();
+ PapyrusClipboard.setInstance(instance);
+ isEnabled = true;
+ }
+
+ return isEnabled;
}
}

Back to the top