diff options
| author | Maxime Porhel | 2017-02-16 10:53:05 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2017-02-20 15:52:50 +0000 |
| commit | 3da308551815a35744eee1a9a44c94be0db9e22d (patch) | |
| tree | b5cf256129c9ba104263c3e38dd721b61e6282c2 | |
| parent | 50180002f550cd10df5b9bff6328c44a0c7a3276 (diff) | |
| download | org.eclipse.sirius-3da308551815a35744eee1a9a44c94be0db9e22d.tar.gz org.eclipse.sirius-3da308551815a35744eee1a9a44c94be0db9e22d.tar.xz org.eclipse.sirius-3da308551815a35744eee1a9a44c94be0db9e22d.zip | |
[512292] Optimize EditModeDecorator
IPermissionAuthority retrieval, lockStatus computation and isBroken
checks were made at least twice: one in shouldBeDecorated, the other one
in getDecorationImage.
As AbstractSiriusDecorator.refresh checks that the decoration image is
not null, we can do the costly computation only once and do it in the
getDecorationImage().
Bug: 512292
Change-Id: I8b79aa39659e5612d528787b5c249fdb839d4027
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
2 files changed, 47 insertions, 44 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/decorators/AbstractSiriusDecorator.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/decorators/AbstractSiriusDecorator.java index 47ea8e5067..7e24b39deb 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/decorators/AbstractSiriusDecorator.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/decorators/AbstractSiriusDecorator.java @@ -75,25 +75,28 @@ public abstract class AbstractSiriusDecorator extends AbstractDecorator { if (view != null && (shouldConsiderDetachedViews() || view.eResource() != null)) { final EditPart editPart = (EditPart) getDecoratorTarget().getAdapter(EditPart.class); if (shouldBeDecorated(editPart)) { - // Get margin - int margin = MARGIN; - if (editPart instanceof org.eclipse.gef.GraphicalEditPart) { - margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart) editPart).getFigure()).DPtoLP(margin); - } - Image decorationImage = getDecorationImage(editPart); if (null != decorationImage) { boolean isVolatile = !shouldBeVisibleAtPrint(); if (editPart instanceof AbstractConnectionEditPart) { addDecoration(getDecoratorTarget().addConnectionDecoration(decorationImage, 50, isVolatile)); } else { - addDecoration(getDecoratorTarget().addShapeDecoration(decorationImage, getDirection(editPart), margin, isVolatile)); + addDecoration(getDecoratorTarget().addShapeDecoration(decorationImage, getDirection(editPart), getMargin(editPart), isVolatile)); } } } } } + private int getMargin(EditPart editPart) { + // Get margin + int margin = MARGIN; + if (editPart instanceof org.eclipse.gef.GraphicalEditPart) { + margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart) editPart).getFigure()).DPtoLP(margin); + } + return margin; + } + private void refreshTooltip(IDecoration decoration) { EditPart editPart = (EditPart) getDecoratorTarget().getAdapter(EditPart.class); if (editPart instanceof IDiagramElementEditPart) { @@ -119,10 +122,8 @@ public abstract class AbstractSiriusDecorator extends AbstractDecorator { } /** - * Tells if the decoration added by this decorator should be visible at - * image export or print. By default true is returned to have decoration - * visible at image export and print. Override this method to change this - * behavior. + * Tells if the decoration added by this decorator should be visible at image export or print. By default true is + * returned to have decoration visible at image export and print. Override this method to change this behavior. * * @return true to have decorations visible at image export and at print */ @@ -131,11 +132,10 @@ public abstract class AbstractSiriusDecorator extends AbstractDecorator { } /** - * Indicates whether this decorator should consider detached {@link View}s - * (i.e. {@link View}s which eResource() is null). + * Indicates whether this decorator should consider detached {@link View}s (i.e. {@link View}s which eResource() is + * null). * - * @return true if this decorator should consider detached {@link View}s, - * false otherwise. + * @return true if this decorator should consider detached {@link View}s, false otherwise. */ protected boolean shouldConsiderDetachedViews() { return false; @@ -165,8 +165,7 @@ public abstract class AbstractSiriusDecorator extends AbstractDecorator { * * @param editPart * the editPart to check - * @return true if the editPart respect conditions to be decorate, false - * otherwise + * @return true if the editPart respect conditions to be decorate, false otherwise */ protected boolean shouldBeDecorated(final EditPart editPart) { boolean shouldBeDecorated = true; @@ -261,14 +260,12 @@ public abstract class AbstractSiriusDecorator extends AbstractDecorator { } /** - * Indicates if the given editPart should contain decorations according to - * its type. For example, {@link DNodeListNameEditPart}s should not be - * decorated. + * Indicates if the given editPart should contain decorations according to its type. For example, + * {@link DNodeListNameEditPart}s should not be decorated. * * @param editPart * the edit part to inspect - * @return true if the given editPart should contain decorations, false - * otherwise + * @return true if the given editPart should contain decorations, false otherwise */ public boolean isDecorableEditPart(IDiagramElementEditPart editPart) { boolean result = true; diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/providers/decorators/EditModeDecorator.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/providers/decorators/EditModeDecorator.java index 002889b263..16e1943856 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/providers/decorators/EditModeDecorator.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/providers/decorators/EditModeDecorator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2017 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 @@ -47,8 +47,7 @@ public class EditModeDecorator extends AbstractSiriusDecorator { * * @param editPart * the edit part to check - * @return <code>true</code> if the editPart is not broken to be decorated, - * <code>false</code> otherwise + * @return <code>true</code> if the editPart is not broken to be decorated, <code>false</code> otherwise */ protected boolean isBroken(EditPart editPart) { if (editPart instanceof IDiagramElementEditPart) { @@ -81,14 +80,24 @@ public class EditModeDecorator extends AbstractSiriusDecorator { * * @param editPart * the editPart to check - * @return true if the editPart respect conditions to be decorate, false - * otherwise + * @return true if the editPart respect conditions to be decorate, false otherwise */ @Override protected boolean shouldBeDecorated(final EditPart editPart) { - boolean shouldBeDecorated = super.shouldBeDecorated(editPart); + return editPart instanceof IDiagramElementEditPart && super.shouldBeDecorated(editPart); + } - if (shouldBeDecorated && editPart instanceof IDiagramElementEditPart) { + /** + * Get the decoration image.<br> + * + * @param editPart + * the edit part to get the decoration image from + * @return <code>null</code> if no image found. + */ + @Override + protected Image getDecorationImage(EditPart editPart) { + Image decorationImage = null; + if (editPart instanceof IDiagramElementEditPart) { IDiagramElementEditPart part = (IDiagramElementEditPart) editPart; // Case 1 : permission authority forbids the edition of the semantic @@ -98,37 +107,34 @@ public class EditModeDecorator extends AbstractSiriusDecorator { if (auth != null) { EObject representedObject = part.resolveTargetSemanticElement(); if (representedObject != null) { - shouldBeDecorated = LockStatus.LOCKED_BY_OTHER.equals(auth.getLockStatus(representedObject)); + decorationImage = getLockStatusDecorationImage(auth.getLockStatus(representedObject)); } } } // Case 2 : edit part is broken - if (!shouldBeDecorated) { - shouldBeDecorated = isBroken(editPart); + if (decorationImage == null && isBroken(editPart)) { + // If the edit part is broken, we return a "deleted" image (red cross) + decorationImage = DiagramUIPlugin.getPlugin().getImage(DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.DELETE_FROM_DIAGRAM_ICON)); } } - return shouldBeDecorated; + return decorationImage; } /** - * Get the decoration image.<br> + * Return the image corresponding to the given {@link LockStatus}. * - * @param editPart - * the edit part to get the decoration image from - * @return <code>null</code> if no image found. + * @param lockStatus + * the lock status of the element to decorate. + * @return the image corresponding to the given {@link LockStatus} */ - @Override - protected Image getDecorationImage(EditPart editPart) { - if (isBroken(editPart)) { - // If the edit part is borken, we return a "delete" image (red - // cross) - return DiagramUIPlugin.getPlugin().getImage(DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.DELETE_FROM_DIAGRAM_ICON)); - } else { + protected Image getLockStatusDecorationImage(LockStatus lockStatus) { + if (LockStatus.LOCKED_BY_OTHER.equals(lockStatus)) { // It means that the semantic element referenced by this edit part // is not editable, we return a "locked" image (red padlock) return DiagramUIPlugin.getPlugin().getImage(SiriusEditPlugin.Implementation.getBundledImageDescriptor("icons/full/decorator/permission_denied.gif")); //$NON-NLS-1$ } + return null; } @Override |
