From 23a75b0aeb2e82056b55cc54cae944898b58bfa1 Mon Sep 17 00:00:00 2001 From: cletavernie Date: Fri, 31 May 2013 14:07:29 +0000 Subject: 409472: Severe performance bottleneck while creating activity diagram from "imported" model. https://bugs.eclipse.org/bugs/show_bug.cgi?id=409472 --- .../handler/AbstractStyleHandler.java | 1 + .../infra/gmfdiag/css/engine/DiagramCSSEngine.java | 1 + .../gmfdiag/css/engine/ExtendedCSSEngineImpl.java | 1 + .../css/preferences/ThemePreferencesPage.java | 1 + .../editpolicies/ShapeCompartmentEditPolicy.java | 94 +++++++++++++++------- .../infra/gmfdiag/common/helper/DiagramHelper.java | 14 +++- 6 files changed, 83 insertions(+), 29 deletions(-) (limited to 'plugins/infra/gmfdiag') diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java index 436380c2d5f..20630eb8add 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css.configuration/src/org/eclipse/papyrus/infra/gmfdiag/css/configuration/handler/AbstractStyleHandler.java @@ -166,6 +166,7 @@ public abstract class AbstractStyleHandler extends AbstractHandler { try { resource.save(new HashMap()); BaseCSSEngine.instance.reset(); + DiagramHelper.setNeedsRefresh(); DiagramHelper.refreshDiagrams(); } catch (IOException ex) { Activator.log.error(ex); diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/DiagramCSSEngine.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/DiagramCSSEngine.java index 7aed0e59bd5..ffae587eb03 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/DiagramCSSEngine.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/DiagramCSSEngine.java @@ -106,6 +106,7 @@ public class DiagramCSSEngine extends ExtendedCSSEngineImpl implements IChangeLi public void handleChange(ChangeEvent event) { resetCache(); + DiagramHelper.setNeedsRefresh(); DiagramHelper.refreshDiagrams(); //FIXME: Should be contextual. We should only refresh the editor(s) containing this Diagram } diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ExtendedCSSEngineImpl.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ExtendedCSSEngineImpl.java index 6e7b277a76e..013da33c1dc 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ExtendedCSSEngineImpl.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/engine/ExtendedCSSEngineImpl.java @@ -353,6 +353,7 @@ public abstract class ExtendedCSSEngineImpl extends AbstractCSSEngine implements //FIXME: It seems the refresh can create a deadlock in some cases + DiagramHelper.setNeedsRefresh(); Display.getDefault().asyncExec(new Runnable() { public void run() { diff --git a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferencesPage.java b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferencesPage.java index 84b17145b6e..0d1f24dd949 100644 --- a/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferencesPage.java +++ b/plugins/infra/gmfdiag/css/org.eclipse.papyrus.infra.gmfdiag.css/src/org/eclipse/papyrus/infra/gmfdiag/css/preferences/ThemePreferencesPage.java @@ -73,6 +73,7 @@ public class ThemePreferencesPage extends FieldEditorPreferencePage implements I boolean result = super.performOk(); if(needsRefresh) { WorkspaceCSSEngine.instance.reset(); + DiagramHelper.setNeedsRefresh(); DiagramHelper.refreshDiagrams(); } return result; diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java index 190fa9d5b31..88fea4dcf86 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java @@ -32,7 +32,6 @@ import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener; import org.eclipse.papyrus.infra.gmfdiag.common.Activator; import org.eclipse.papyrus.infra.gmfdiag.common.commands.CreateShapeCompartmentViewCommand; import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand; -import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IShapeCompartmentEditPart; import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.NotificationManager; import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ShapeService; @@ -50,7 +49,7 @@ public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements N /** manager for notifications: should the compartment react to the notification? */ protected NotificationManager notificationManager; - + /** * Creates a new AppliedStereotype display edit policy */ @@ -62,6 +61,7 @@ public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements N * * {@inheritDoc} */ + @Override public void activate() { super.activate(); // retrieve the view and the element managed by the edit part @@ -71,13 +71,14 @@ public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements N } notificationManager = ShapeService.getInstance().createNotificationManager(getDiagramEventBroker(), view, this); createShapeCompartment(); - + } /** * * {@inheritDoc} */ + @Override public void deactivate() { // retrieve the view and the element managed by the edit part View view = getView(); @@ -120,34 +121,68 @@ public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements N */ protected void executeShapeCompartmentCreation(final IGraphicalEditPart editPart) { try { - getEditingDomain(editPart).runExclusive(new Runnable() { + // getEditingDomain(editPart).runExclusive(new Runnable() { + + /** + * {@inheritDoc} + */ + // public void run() { + Display.getCurrent().syncExec(new Runnable() { /** * {@inheritDoc} */ public void run() { - Display.getCurrent().asyncExec(new Runnable() { + //boolean isVisible = hasToDisplayCompartment(editPart.getNotationView()); + CreateShapeCompartmentViewCommand command = new CreateShapeCompartmentViewCommand(getEditingDomain(editPart), "Create Compartment", "Command that creates the compartment displaying shapes", editPart.getNotationView(), /* isVisible */false); + Map options = new HashMap(); + //options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE); + try { + //This should not change the command stack, as this transaction will only manipulate transient views. Create a transaction manually, if needed + InternalTransactionalEditingDomain editingDomain = (InternalTransactionalEditingDomain)editPart.getEditingDomain(); + InternalTransaction activeTransaction = editingDomain.getActiveTransaction(); + if(activeTransaction != null && activeTransaction.isActive()) { + if(activeTransaction.isReadOnly()) { + //We're in a read-only active transaction (e.g. post-commit). + //Typical case: We create a new gmf::View in a transaction. + //The transaction has been committed, and the edit part is being created during the post-commit + //post-commit is read-only. We cannot create a read-write transaction in this state, so we need + //to deactive the read-only transaction first. - /** - * {@inheritDoc} - */ - public void run() { - //boolean isVisible = hasToDisplayCompartment(editPart.getNotationView()); - CreateShapeCompartmentViewCommand command = new CreateShapeCompartmentViewCommand(getEditingDomain(editPart), "Create Compartment", "Command that creates the compartment displaying shapes", editPart.getNotationView(), /*isVisible*/ false); - Map options = new HashMap(); - options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE); - try{ - InternalTransaction it=((InternalTransactionalEditingDomain) editPart.getEditingDomain()).startTransaction(false, options); + try { + //Deactivate the read-only transaction + editingDomain.deactivate(activeTransaction); + + //Start a new read-write transaction + InternalTransaction it = editingDomain.startTransaction(false, options); + command.execute(); + it.commit(); + } finally { + //Reactive the read-only transaction + editingDomain.activate(activeTransaction); + } + + } else { + //We're already in an active read-write transaction. Simply execute the command + //Never happens? command.execute(); - it.commit(); - } catch(Exception e){ - Activator.log.error(e); } - // editPart.getEditingDomain().getCommandStack().execute(command); + } else { + //We're not in a transaction. Start a new read-write transaction + //Typical case: opening the diagram + InternalTransaction it = editingDomain.startTransaction(false, options); + command.execute(); + it.commit(); } - }); + + } catch (Exception e) { + Activator.log.error(e); + } + // editPart.getEditingDomain().getCommandStack().execute(command); } }); + // } + // }); } catch (Exception e) { Activator.log.error(e); } @@ -155,13 +190,15 @@ public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements N /** * Returns the editing domain for the given edit Part - * @param editPart the edit part from which editing domain is searched - * @return the editing domain + * + * @param editPart + * the edit part from which editing domain is searched + * @return the editing domain */ protected TransactionalEditingDomain getEditingDomain(IGraphicalEditPart editPart) { return editPart.getEditingDomain(); } - + /** * Gets the diagram event broker from the editing domain. * @@ -202,6 +239,7 @@ public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements N /** * Returns the view corresponding to the shape compartment + * * @param node * @return */ @@ -233,13 +271,13 @@ public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements N public void run() { SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(editPart.getEditingDomain(), view, isVisible); //use to avoid to put it in the command stack - Map options = new HashMap(); - options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE); + Map options = new HashMap(); + options.put(Transaction.OPTION_UNPROTECTED, Boolean.TRUE); try { - InternalTransaction it=((InternalTransactionalEditingDomain) editPart.getEditingDomain()).startTransaction(false, options); + InternalTransaction it = ((InternalTransactionalEditingDomain)editPart.getEditingDomain()).startTransaction(false, options); setCommand.execute(); it.commit(); - } catch(Exception e){ + } catch (Exception e) { Activator.log.error(e); } } @@ -250,5 +288,5 @@ public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements N Activator.log.error(e); } } - + } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramHelper.java index 8ab63c01f65..fece295adf1 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramHelper.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/DiagramHelper.java @@ -85,15 +85,27 @@ public class DiagramHelper { } } } - } + private static boolean needsRefresh = false; + /** * Refreshes all opened diagrams */ public static void refreshDiagrams() { + synchronized(DiagramHelper.class) { + if(!needsRefresh) { + return; + } + needsRefresh = false; + } + for(IMultiDiagramEditor activeMultiEditor : EditorUtils.getMultiDiagramEditors()) { refresh(activeMultiEditor); } } + + public synchronized static void setNeedsRefresh() { + needsRefresh = true; + } } -- cgit v1.2.3