Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Le Menez2016-05-26 08:45:11 +0000
committerGerrit Code Review @ Eclipse.org2016-05-26 14:09:40 +0000
commit433df5924053ff7bc2c43df3564123c2ca3759a5 (patch)
treea5919d2e39548f349a9baafc14885c35680b2427 /plugins/uml
parentbc347b54c15a4decd8dd576c80225aca3237fd3d (diff)
downloadorg.eclipse.papyrus-433df5924053ff7bc2c43df3564123c2ca3759a5.tar.gz
org.eclipse.papyrus-433df5924053ff7bc2c43df3564123c2ca3759a5.tar.xz
org.eclipse.papyrus-433df5924053ff7bc2c43df3564123c2ca3759a5.zip
Bug 494613: [Diagram] The class org.eclipse.papyrus.uml.diagram.menu.providers.HandlerStateSourceProvider must be fully rewritten (improving memory usage)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=494613 - Temporary solution: cached handlers Change-Id: I505003532074895f8a706acb425d77405eb3ea4d Signed-off-by: Quentin Le Menez <quentin.lemenez@cea.fr>
Diffstat (limited to 'plugins/uml')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/providers/HandlerStateSourceProvider.java76
1 files changed, 49 insertions, 27 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/providers/HandlerStateSourceProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/providers/HandlerStateSourceProvider.java
index 0ea761e8faf..98cecb68a30 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/providers/HandlerStateSourceProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/providers/HandlerStateSourceProvider.java
@@ -14,6 +14,9 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.menu.providers;
+import java.util.HashMap;
+import java.util.Map;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.papyrus.infra.gmfdiag.menu.handlers.ToggleCanonicalHandler;
import org.eclipse.papyrus.uml.diagram.common.providers.AbstractActionStateSourceProvider;
@@ -94,6 +97,8 @@ public class HandlerStateSourceProvider extends AbstractActionStateSourceProvide
public static final String SHOW_HIDE_CONNECTION_LABELS = "showHideLabels"; //$NON-NLS-1$
+ private Map<String, AbstractHandler> cachedHandlers;
+
/**
*
* Constructor.
@@ -129,6 +134,7 @@ public class HandlerStateSourceProvider extends AbstractActionStateSourceProvide
currentState.put(LINE_STYLE_TREE, DISABLED);
currentState.put(SHOW_HIDE_CONNECTION_LABELS, DISABLED);
+ cachedHandlers = createCachedHandlers();
}
@@ -156,6 +162,43 @@ public class HandlerStateSourceProvider extends AbstractActionStateSourceProvide
}
+ /**
+ * Temporary fix for the multiple call of the method to avoid creating new handlers every time the user selects an object in the diagram (Bug 494613)
+ *
+ * @since 2.0
+ */
+ private Map<String, AbstractHandler> createCachedHandlers() {
+ Map<String, AbstractHandler> map = new HashMap<>();
+ map.put(SHOW_HIDE_COMPARTMENTS, new ShowHideCompartmentHandler());
+ map.put(SHOW_HIDE_CONTENTS, new ShowHideContentsHandler());
+ map.put(TOGGLE_CANONICAL, new ToggleCanonicalHandler());
+ map.put(COPY_APPEARANCE_PROPERTIES, new CopyAppearancePropertiesHandler());
+
+ map.put(SORT_FILTER_COMPARTMENT_ITEMS, new SortFilterCompartmentItemsHandler());
+ map.put(ZOOM, new ZoomHandler());
+
+ map.put(BRING_TO_FRONT, new ZOrderHandler(BRING_TO_FRONT));
+ map.put(SEND_TO_BACK, new ZOrderHandler(SEND_TO_BACK));
+ map.put(BRING_FORWARD, new ZOrderHandler(BRING_FORWARD));
+ map.put(SEND_BACKWARD, new ZOrderHandler(SEND_BACKWARD));
+ map.put(ARRANGE_ALL, new ArrangeHandler(ARRANGE_ALL));
+ map.put(ARRANGE_SELECTION, new ArrangeHandler(ARRANGE_SELECTION));
+
+ map.put(SELECT_ALL, new SelectHandler(SELECT_ALL));
+ map.put(SELECT_ALL_CONNECTORS, new SelectHandler(SELECT_ALL_CONNECTORS));
+ map.put(SELECT_ALL_SHAPES, new SelectHandler(SELECT_ALL_SHAPES));
+
+ map.put(FONT, new FontHandler());
+
+ map.put(FILL_COLOR, new FillColorHandler());
+ map.put(LINE_COLOR, new LineColorHandler());
+ map.put(LINE_STYLE, new LineStyleHandler(LineStyleAction.RECTILINEAR));
+ map.put(LINE_STYLE_TREE, new LineStyleHandler(LineStyleAction.TREE));
+ map.put(SHOW_HIDE_CONNECTION_LABELS, new ShowHideLabelsHandler(ShowHideLabelsAction.SHOW_PARAMETER));
+
+ return map;
+ }
+
/**
*
@@ -164,34 +207,13 @@ public class HandlerStateSourceProvider extends AbstractActionStateSourceProvide
*/
@Override
protected void refreshActions() {
- refresh(SHOW_HIDE_CONTENTS, new ShowHideContentsHandler());
- refresh(SHOW_HIDE_COMPARTMENTS, new ShowHideCompartmentHandler());
- refresh(TOGGLE_CANONICAL, new ToggleCanonicalHandler());
- refresh(COPY_APPEARANCE_PROPERTIES, new CopyAppearancePropertiesHandler());
-
- refresh(SORT_FILTER_COMPARTMENT_ITEMS, new SortFilterCompartmentItemsHandler());
- refresh(ZOOM, new ZoomHandler());
-
- refresh(BRING_TO_FRONT, new ZOrderHandler(BRING_TO_FRONT));
- refresh(SEND_TO_BACK, new ZOrderHandler(SEND_TO_BACK));
- refresh(BRING_FORWARD, new ZOrderHandler(BRING_FORWARD));
- refresh(SEND_BACKWARD, new ZOrderHandler(SEND_BACKWARD));
- refresh(ARRANGE_ALL, new ArrangeHandler(ARRANGE_ALL));
- refresh(ARRANGE_SELECTION, new ArrangeHandler(ARRANGE_SELECTION));
-
- refresh(SELECT_ALL, new SelectHandler(SELECT_ALL));
- refresh(SELECT_ALL_CONNECTORS, new SelectHandler(SELECT_ALL_CONNECTORS));
- refresh(SELECT_ALL_SHAPES, new SelectHandler(SELECT_ALL_SHAPES));
-
- refresh(FONT, new FontHandler());
-
- refresh(FILL_COLOR, new FillColorHandler());
- refresh(LINE_COLOR, new LineColorHandler());
- refresh(LINE_STYLE, new LineStyleHandler(LineStyleAction.RECTILINEAR));
- refresh(LINE_STYLE_TREE, new LineStyleHandler(LineStyleAction.TREE));
- refresh(SHOW_HIDE_CONNECTION_LABELS, new ShowHideLabelsHandler(ShowHideLabelsAction.SHOW_PARAMETER));
+ for (String key : cachedHandlers.keySet()) {
+ refresh(key, cachedHandlers.get(key));
+ }
}
+
+
/**
* Refresh the state of the handlers
*
@@ -215,7 +237,7 @@ public class HandlerStateSourceProvider extends AbstractActionStateSourceProvide
* @param handler
* the handler to refresh
* @return
- * <code>true</code> if the status of the handler is enabled
+ * <code>true</code> if the status of the handler is enabled
*/
protected boolean test(AbstractHandler handler) {
return isSelectionInDiagram() && handler.isEnabled();

Back to the top