summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2013-12-11 02:58:20 (EST)
committerLaurent Wouters2013-12-11 02:58:20 (EST)
commita044b7edf9d8e18937aebee38e1d39f001695b2e (patch)
treebb3f29e33e0828651fd971780a99852021e10779
parent1c2ab3ecf11d18c39e68b616ec352f360ea1cb2d (diff)
downloadorg.eclipse.papyrus-a044b7edf9d8e18937aebee38e1d39f001695b2e.zip
org.eclipse.papyrus-a044b7edf9d8e18937aebee38e1d39f001695b2e.tar.gz
org.eclipse.papyrus-a044b7edf9d8e18937aebee38e1d39f001695b2e.tar.bz2
423729: [Performances - Symbols] SVG Images are reloaded too often
Refactored the refresh mechanism so that it includes the cache of SVG documents can be cleared https://bugs.eclipse.org/bugs/show_bug.cgi?id=423729 Change-Id: Ie41e92215146843ac61b0f0a6cdb78f3664f4c8a Signed-off-by: Laurent Wouters <laurent.wouters@cea.fr>
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml20
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/BaseCSSEngine.java16
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/WorkspaceCSSEngine.java2
-rw-r--r--plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/handler/CSSRefreshHandler.java33
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java29
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/RefreshHandler.java41
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java24
7 files changed, 107 insertions, 58 deletions
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml
index b82a4ff..d1f57f8 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/plugin.xml
@@ -10,26 +10,6 @@
uri="http://www.eclipse.org/gmf/runtime/1.0.2/notation">
</factory>
</extension>
- <extension point="org.eclipse.ui.handlers">
- <handler
- class="org.eclipse.papyrus.infra.gmfdiag.css.handler.CSSRefreshHandler"
- commandId="org.eclipse.ui.file.refresh">
- <activeWhen>
- <and>
- <with variable="activePartId">
- <equals value="org.eclipse.papyrus.infra.core.papyrusEditor">
- </equals>
- </with>
- <with variable="activeContexts">
- <iterate ifEmpty="false" operator="or">
- <equals value="Papyrus CSS">
- </equals>
- </iterate>
- </with>
- </and>
- </activeWhen>
- </handler>
- </extension>
<extension
point="org.eclipse.ui.contexts">
<context
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/BaseCSSEngine.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/BaseCSSEngine.java
index 0c65a81..afc1f81 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/BaseCSSEngine.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/BaseCSSEngine.java
@@ -16,7 +16,10 @@ import java.net.URL;
import org.eclipse.e4.ui.css.core.dom.IElementProvider;
import org.eclipse.e4.ui.css.core.engine.CSSElementContext;
+import org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.handler.RefreshHandler;
import org.eclipse.papyrus.infra.gmfdiag.css.Activator;
+import org.eclipse.ui.IEditorPart;
import org.w3c.dom.Element;
/**
@@ -30,9 +33,10 @@ import org.w3c.dom.Element;
* @see DiagramCSSEngine
*/
@SuppressWarnings("restriction")
-public class BaseCSSEngine extends ExtendedCSSEngineImpl {
+public class BaseCSSEngine extends ExtendedCSSEngineImpl implements IRefreshHandlerPart {
private BaseCSSEngine() {
+ RefreshHandler.register(this);
try {
styleSheetURLs.add(new URL("platform:/plugin/" + Activator.PLUGIN_ID + "/resources/base.css")); //$NON-NLS-1$ //$NON-NLS-2$
} catch (MalformedURLException ex) {
@@ -43,7 +47,15 @@ public class BaseCSSEngine extends ExtendedCSSEngineImpl {
/**
* The Singleton instance of BaseCSSEngine
*/
- public static ExtendedCSSEngine instance = new BaseCSSEngine();
+ public static final ExtendedCSSEngine INSTANCE = new BaseCSSEngine();
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart#refresh(org.eclipse.ui.IEditorPart)
+ */
+ public void refresh(IEditorPart editorPart) {
+ // Resets this engine, regardless of the current editor
+ this.reset();
+ }
//Unsupported operations. The BaseCSSEngine should never be used directly.
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/WorkspaceCSSEngine.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/WorkspaceCSSEngine.java
index 6ac7f33..f01dfca 100644
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/WorkspaceCSSEngine.java
+++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/WorkspaceCSSEngine.java
@@ -34,7 +34,7 @@ import org.w3c.dom.Element;
public class WorkspaceCSSEngine extends ExtendedCSSEngineImpl {
private WorkspaceCSSEngine() {
- super(BaseCSSEngine.instance);
+ super(BaseCSSEngine.INSTANCE);
}
public static ExtendedCSSEngine instance = new WorkspaceCSSEngine();
diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/handler/CSSRefreshHandler.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/handler/CSSRefreshHandler.java
deleted file mode 100644
index f538b27..0000000
--- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/handler/CSSRefreshHandler.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*****************************************************************************
- * 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.css.handler;
-
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.papyrus.infra.gmfdiag.common.handler.RefreshHandler;
-import org.eclipse.papyrus.infra.gmfdiag.css.engine.BaseCSSEngine;
-
-/**
- * A Handler for refreshing a single Papyrus Diagram
- * It will refresh the CSS Stylesheets before refreshing the diagram.
- *
- * @author Camille Letavernier
- *
- */
-public class CSSRefreshHandler extends RefreshHandler {
-
- @Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- BaseCSSEngine.instance.reset();
- return super.execute(event);
- }
-}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java
new file mode 100755
index 0000000..c5d11f2
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java
@@ -0,0 +1,29 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Laurent Wouters (CEA LIST) laurent.wouters@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.handler;
+
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Represents a handler of refresh event
+ *
+ * @author Laurent Wouters
+ */
+public interface IRefreshHandlerPart {
+ /**
+ * Refresh what needs to be, taking into account that the active editor is the given one
+ *
+ * @param editorPart
+ * The currently active editor
+ */
+ void refresh(IEditorPart editorPart);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/RefreshHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/RefreshHandler.java
index fe74c2f..dacfdea 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/RefreshHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/RefreshHandler.java
@@ -11,6 +11,11 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.gmfdiag.common.handler;
+import java.lang.ref.WeakReference;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -31,6 +36,25 @@ import org.eclipse.ui.IEditorPart;
//TODO: To be refactored. Move to infra/gmfdiag/menu when the plugin exists
public class RefreshHandler extends AbstractHandler {
+ /**
+ * The registry of refresh handler parts that are NOT specific to an editor
+ * We use weak references so that we do not block the garbage collection of objects
+ */
+ private static Collection<WeakReference<IRefreshHandlerPart>> PARTS = new LinkedList<WeakReference<IRefreshHandlerPart>>();
+
+ /**
+ * Register a refresher part that is not attached to any editor
+ *
+ * @param refresher
+ * The refresher part
+ */
+ public static synchronized void register(IRefreshHandlerPart refresher) {
+ PARTS.add(new WeakReference<IRefreshHandlerPart>(refresher));
+ }
+
+ /**
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart activeEditor;
try {
@@ -40,8 +64,25 @@ public class RefreshHandler extends AbstractHandler {
return null;
}
+ // Refresh the base GMF objects
DiagramHelper.refresh(activeEditor);
+ // Call the relevant hooks
+ callRefresherHooks(activeEditor);
+
return null;
}
+
+ private synchronized void callRefresherHooks(IEditorPart activeEditor) {
+ Iterator<WeakReference<IRefreshHandlerPart>> iterator = PARTS.iterator();
+ while (iterator.hasNext()) {
+ WeakReference<IRefreshHandlerPart> wr = iterator.next();
+ IRefreshHandlerPart part = wr.get();
+ if (part != null) {
+ part.refresh(activeEditor);
+ } else {
+ iterator.remove();
+ }
+ }
+ }
}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
index 9f1bab1..e73fc03 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
@@ -26,13 +26,16 @@ import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
import org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedImageFactory;
+import org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.handler.RefreshHandler;
+import org.eclipse.ui.IEditorPart;
import org.w3c.dom.Document;
import org.w3c.dom.svg.SVGDocument;
/**
* Abstract implementation of the shape provider interface.
*/
-public abstract class AbstractShapeProvider extends AbstractProvider implements IShapeProvider {
+public abstract class AbstractShapeProvider extends AbstractProvider implements IShapeProvider, IRefreshHandlerPart {
/** field for name */
protected static final String NAME = "name";
@@ -60,6 +63,13 @@ public abstract class AbstractShapeProvider extends AbstractProvider implements
/**
+ * Initializes this provider
+ */
+ public AbstractShapeProvider() {
+ RefreshHandler.register(this);
+ }
+
+ /**
* Returns the bundle identifier for this provider
*
* @return the bundle identifier for this provider
@@ -124,7 +134,7 @@ public abstract class AbstractShapeProvider extends AbstractProvider implements
* The location to load the document from
* @return the Document SVG from its location, can return null if this is not a svg
*/
- protected SVGDocument getSVGDocument(String location) {
+ protected synchronized SVGDocument getSVGDocument(String location) {
if (cache == null)
cache = new HashMap<String, SVGDocument>();
if (cache.containsKey(location))
@@ -185,4 +195,14 @@ public abstract class AbstractShapeProvider extends AbstractProvider implements
return writer.toString();
}
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart#refresh(org.eclipse.ui.IEditorPart)
+ */
+ public synchronized void refresh(IEditorPart editorPart) {
+ // Clears the cache of loaded SVG documents
+ // This will force their reloading
+ if (cache != null)
+ cache.clear();
+ }
}