diff options
author | Pauline DEVILLE | 2024-05-07 15:12:48 +0000 |
---|---|---|
committer | Pauline DEVILLE | 2024-05-24 08:35:00 +0000 |
commit | 52fe947b5ece6b0188caab7fbdfdaf8bee263969 (patch) | |
tree | 68fc01aa5a0ef914b3a75f4daa6640807952e958 | |
parent | 38bdae40c0f296369260762e800b19d6d5bcbdb6 (diff) | |
download | org.eclipse.papyrus-bugs/583278_6.6_maintenance.tar.gz org.eclipse.papyrus-bugs/583278_6.6_maintenance.tar.xz org.eclipse.papyrus-bugs/583278_6.6_maintenance.zip |
Bug 583091 - [MemoryLeak] Release EditPartsbugs/583278_6.6_maintenance
Change-Id: Ic069bd65555df99e1b5b73a59b4e57b7fb54fe74
Signed-off-by: Pauline DEVILLE <pauline.deville@cea.fr>
9 files changed, 232 insertions, 143 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.canonical/src/org/eclipse/papyrus/infra/gmfdiag/canonical/editpolicy/CanonicalStateListener.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.canonical/src/org/eclipse/papyrus/infra/gmfdiag/canonical/editpolicy/CanonicalStateListener.java index c69dbbac4dc..fb27dc085e0 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.canonical/src/org/eclipse/papyrus/infra/gmfdiag/canonical/editpolicy/CanonicalStateListener.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.canonical/src/org/eclipse/papyrus/infra/gmfdiag/canonical/editpolicy/CanonicalStateListener.java @@ -1,6 +1,6 @@ /***************************************************************************** - * Copyright (c) 2015 Christian W. Damus and others. - * + * Copyright (c) 2015, 2024 Christian W. Damus and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -10,7 +10,8 @@ * * Contributors: * Christian W. Damus - Initial API and implementation - * + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 + * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.canonical.editpolicy; @@ -38,7 +39,7 @@ import com.google.common.collect.MapMaker; /** * A {@link DiagramEventBroker} listener that is notified when the {@link CanonicalStyle} of a view changes. */ -public class CanonicalStateListener extends ReferenceCounted<CanonicalStateListener>implements NotificationListener { +public class CanonicalStateListener extends ReferenceCounted<CanonicalStateListener> implements NotificationListener { private static final ConcurrentMap<IGraphicalEditPart, CanonicalStateListener> listeners = new MapMaker().weakKeys().weakValues().makeMap(); private final IGraphicalEditPart owner; @@ -66,12 +67,12 @@ public class CanonicalStateListener extends ReferenceCounted<CanonicalStateListe * <p> * <b>Note</b> that the resulting listener is automatically {@linkplain ReferenceCounted#retain() retained} on the caller's behalf. The caller will have to {@linkplain ReferenceCounted#release() release} the listener when it is no longer needed. * </p> - * + * * @param editPart * an edit part * @return its shared canonical state listener. Do not {@linkplain ReferenceCounted#retain() retain} it, otherwise you will * have doubly retained it - * + * * @see ReferenceCounted#retain() * @see ReferenceCounted#release() */ @@ -245,7 +246,7 @@ public class CanonicalStateListener extends ReferenceCounted<CanonicalStateListe /** * Handles a change in the implicit canonical style of a notation view (such as from changes in CSS stylesheets). - * + * * @param requestor * the handler of the entity making the poke request, which should be skipped in the poke * (presumably because it already knows about the canonical state change) @@ -272,7 +273,7 @@ public class CanonicalStateListener extends ReferenceCounted<CanonicalStateListe } private static Predicate<Object> not(final Object excluded) { - return (excluded == null) ? null : new Predicate<Object>() { + return (excluded == null) ? null : new Predicate<>() { @Override public boolean apply(Object input) { return input != excluded; @@ -284,15 +285,15 @@ public class CanonicalStateListener extends ReferenceCounted<CanonicalStateListe // Nested types // - public interface Handler { + public static interface Handler { /** * Obtains a runnable that will be invoked on the display thread (for safe access to diagram edit parts) * to handle the addition/update of the canonical {@code style}. - * + * * @param style * the added or changed canonical style - * + * * @return a runnable to run in response, or {@code null} if no response is needed */ Runnable handleAdd(CanonicalStyle style); @@ -300,10 +301,10 @@ public class CanonicalStateListener extends ReferenceCounted<CanonicalStateListe /** * Obtains a runnable that will be invoked on the display thread (for safe access to diagram edit parts) * to handle the removal of the canonical {@code style}. - * + * * @param style * the removed canonical style - * + * * @return a runnable to run in response, or {@code null} if no response is needed */ Runnable handleRemove(CanonicalStyle style); diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java index cacfe83db0a..ece4071fc59 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SynchronizableGmfDiagramEditor.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010, 2017 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2010, 2017, 2024 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -15,6 +15,7 @@ * Christian W. Damus - bug 465416 * Simon Delisle - Move ReconcilerHelper to a separate class * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 491816 + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common; @@ -36,6 +37,7 @@ import org.eclipse.gef.ui.parts.ContentOutlinePage; import org.eclipse.gef.ui.views.palette.PalettePage; import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint; import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart; import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties; @@ -58,6 +60,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstants import org.eclipse.papyrus.infra.gmfdiag.common.reconciler.DiagramVersioningUtils; import org.eclipse.papyrus.infra.gmfdiag.common.utils.CommandIds; import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart; +import org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf.router.LinkLFDiagramRootEditPart; import org.eclipse.papyrus.infra.sync.service.ISyncService; import org.eclipse.papyrus.infra.ui.editor.reload.IReloadContextProvider; import org.eclipse.papyrus.infra.ui.util.EclipseCommandUtils; @@ -100,6 +103,36 @@ public class SynchronizableGmfDiagramEditor extends DiagramDocumentEditor implem } /** + * @see org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor#dispose() + * + */ + + @Override + public void dispose() { + DiagramEditPart diagramEP = getDiagramEditPart(); + + if (diagramEP.getParent() instanceof LinkLFDiagramRootEditPart srep) { + if (diagramEP.getParent() instanceof DiagramRootEditPart parent) { + parent.removeNotify(); + } + } + deactivateNodeEditParts(diagramEP); + super.dispose(); + if (palettePages != null) { + palettePages.forEach(p -> p.dispose()); + } + } + + private void deactivateNodeEditParts(EditPart ep) { + for (EditPart child : ep.getChildren()) { + deactivateNodeEditParts(child); + child.setParent(null); + } + ep.deactivate(); + ep.getChildren().clear(); + } + + /** * reveal all editpart that represent an element in the given list. * * @see org.eclipse.papyrus.infra.core.ui.IRevealSemanticElement#revealSemanticElement(java.util.List) diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java index 29701136823..5e4deb3c324 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/BorderDisplayEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010, 2014 CEA LIST and others. + * Copyright (c) 2010, 2014, 2024 CEA LIST and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,6 +11,7 @@ * Contributors: * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies; @@ -117,6 +118,16 @@ public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IC styleObservable.dispose(); styleObservable = null; } + + View view = (View) getHost().getModel(); + if (view != null) { + getDiagramEventBroker().removeNotificationListener(view, this); + } + + EObject semanticElement = EMFHelper.getEObject(getHost()); + if (semanticElement != null) { + getDiagramEventBroker().removeNotificationListener(semanticElement, this); + } } /** @@ -214,7 +225,7 @@ public class BorderDisplayEditPolicy extends GraphicalEditPolicyEx implements IC getPrimaryShape().setBorder(defaultBorder); // If a length or a length ratio is defined in notation or CSS ((OneTopLineResizableBorder) defaultBorder).setLength(NotationUtils.getIntValue(view, LINE_LENGTH, DEFAULT_LENGTH_VALUE)); - ((OneTopLineResizableBorder) defaultBorder).setLengthRatio(new Float(NotationUtils.getStringValue(view, LINE_LENGTH_RATIO, LINE_LENGTH_RATIO_DEFAULT_VALUE).replace(',', '.')));// $NON-NLS-1$ + ((OneTopLineResizableBorder) defaultBorder).setLengthRatio(new Float(NotationUtils.getStringValue(view, LINE_LENGTH_RATIO, LINE_LENGTH_RATIO_DEFAULT_VALUE).replace(',', '.')));// $NON-NLS-1$ ((OneTopLineResizableBorder) defaultBorder).setLinePosition(getlinePosition()); // If it's the first one, set border to null. diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/LinkLFSVGNodePlateFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/LinkLFSVGNodePlateFigure.java index 2618854e7a6..21a21510162 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/LinkLFSVGNodePlateFigure.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/LinkLFSVGNodePlateFigure.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014 CEA LIST and others. + * Copyright (c) 2014, 2024 CEA LIST and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,11 +12,14 @@ * CEA LIST - Initial API and implementation * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 482586 * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 531596 + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.common.figure.node; +import java.lang.ref.WeakReference; + import org.eclipse.draw2d.ConnectionAnchor; import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.PrecisionPoint; @@ -29,7 +32,7 @@ public class LinkLFSVGNodePlateFigure extends SVGNodePlateFigure { public static final String ENABLE_LINKLF = "papyrus.linklf_enable"; //$NON-NLS-1$ - private final GraphicalEditPart myHost; + private final WeakReference<GraphicalEditPart> myHost; private boolean myLinkLFIsEnabled = false; @@ -38,7 +41,7 @@ public class LinkLFSVGNodePlateFigure extends SVGNodePlateFigure { */ public LinkLFSVGNodePlateFigure(GraphicalEditPart hostEP, int width, int height) { super(width, height); - myHost = hostEP; + myHost = new WeakReference<>(hostEP); } /** @@ -69,7 +72,7 @@ public class LinkLFSVGNodePlateFigure extends SVGNodePlateFigure { } else { result = new LinkLFSlidableRoundedRectangleAnchor(this, p); } - result.setEditPart(myHost); + result.setEditPart(myHost.get()); return result; } @@ -100,7 +103,7 @@ public class LinkLFSVGNodePlateFigure extends SVGNodePlateFigure { return getConnectionAnchor(szAnchor); } - LinkLFNodeFigure.forceSideForBorderItemAnchorLocation(myHost, pt); + LinkLFNodeFigure.forceSideForBorderItemAnchorLocation(myHost.get(), pt); return createAnchor(pt); } @@ -113,6 +116,8 @@ public class LinkLFSVGNodePlateFigure extends SVGNodePlateFigure { * @since 3.100 */ public GraphicalEditPart getGraphicalEditPart() { - return myHost; + return myHost.get(); } + + } diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.tooling.runtime/src/org/eclipse/papyrus/infra/gmfdiag/tooling/runtime/linklf/LinkLFShapeCompartmentEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.tooling.runtime/src/org/eclipse/papyrus/infra/gmfdiag/tooling/runtime/linklf/LinkLFShapeCompartmentEditPart.java index ee07ca67a48..ea4af008d58 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.tooling.runtime/src/org/eclipse/papyrus/infra/gmfdiag/tooling/runtime/linklf/LinkLFShapeCompartmentEditPart.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.tooling.runtime/src/org/eclipse/papyrus/infra/gmfdiag/tooling/runtime/linklf/LinkLFShapeCompartmentEditPart.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2014-15, 2021 CEA LIST, Montages AG, ARTAL and others + * Copyright (c) 2014-2015, 2021, 2024 CEA LIST, Montages AG, ARTAL and others * * * All rights reserved. This program and the accompanying materials @@ -12,6 +12,8 @@ * Contributors: * Anatoly Tishenko (tishenko@montages.com) - Initial API and implementation * Etienne ALLOGO (ARTAL) - etienne.allogo@artal.fr - Bug 569174 : Pull up refreshVisuals/setRatio for shape compartments + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 + * *****************************************************************************/ package org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf; @@ -65,7 +67,7 @@ public class LinkLFShapeCompartmentEditPart extends ShapeCompartmentEditPart { } } }; - + public LinkLFShapeCompartmentEditPart(View view) { super(view); } @@ -89,13 +91,14 @@ public class LinkLFShapeCompartmentEditPart extends ShapeCompartmentEditPart { @Override public void removeNotify() { getViewer().removePropertyChangeListener(myGridListener); + unsetScrollGridBehaviour(getCompartmentFigure()); super.removeNotify(); } protected void updateGridBehavior() { Rectangle gridSpec = getGridSpec(getViewer()); if (gridSpec != null) { - setScrollGridBehaviour((ResizableCompartmentFigure) getFigure()); + setScrollGridBehaviour(getCompartmentFigure()); } } @@ -107,6 +110,34 @@ public class LinkLFShapeCompartmentEditPart extends ShapeCompartmentEditPart { updateStepIncrements(sp); } + private void unsetScrollGridBehaviour( + ResizableCompartmentFigure compartmentFigure) { + ScrollPane sp = compartmentFigure.getScrollPane(); + undecorateHorizontalRange(sp); + undecorateVerticalRange(sp); + updateStepIncrements(sp); + } + + /** + * Undecorate vertical range of the given pane + * + * @param pane + */ + private void undecorateVerticalRange(ScrollPane pane) { + pane.setViewport(null); + pane.setVerticalScrollBar(null); + } + + /** + * Undecorate vertical range of the given pane + * + * @param pane + */ + private void undecorateHorizontalRange(ScrollPane pane) { + pane.setViewport(null); + pane.setHorizontalScrollBar(null); + } + private void updateStepIncrements(ScrollPane pane) { Rectangle gridSpec = getGridSpec(getViewer()); if (gridSpec == null) { diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java index 39350438950..fad35356e64 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2009, 2016 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2009, 2016, 2024 CEA LIST, Christian W. Damus, and others. * * * All rights reserved. This program and the accompanying materials @@ -16,14 +16,17 @@ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Bug 393532 * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 Stereotype Display * Christian W. Damus - bug 492482 + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.editpolicies; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.notify.Notification; @@ -32,6 +35,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener; @@ -98,6 +102,8 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic protected List<Stereotype> stereotypeList = Collections.emptyList(); + private Set<EObject> suscribedListeners = new HashSet<>(); + private final NotificationPreCommitListener precommitListener = this::handlePrecommit; static { @@ -142,6 +148,7 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic */ protected void subscribe(EObject notifier) { // Subscribe to pre-commit, not post-commit events + suscribedListeners.add(notifier); getDiagramEventBroker().addNotificationListener(notifier, precommitListener); } @@ -154,6 +161,7 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic */ protected void unsubscribe(EObject notifier) { // Unsubscribe from pre-commit, not post-commit events + suscribedListeners.remove(notifier); getDiagramEventBroker().removeNotificationListener(notifier, precommitListener); } @@ -245,9 +253,6 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic refreshHost(); } } - - - } @@ -349,11 +354,6 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic } createAppliedStereotypeBraceProperties(stereotype); - - - - - } /** @@ -401,13 +401,13 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic */ protected void createAppliedStereotypeLabel(final Stereotype stereotype) { - final View node = hostEditPart.getNotationView(); - // create only if the Label doesn't exist yet - if (!helper.isLabelExist(node, stereotype)) { - // Create the Decoration Node - executeStereotypeLabelCreation(hostEditPart, stereotype); + final View node = hostEditPart.getNotationView(); + // create only if the Label doesn't exist yet + if (!helper.isLabelExist(node, stereotype)) { + // Create the Decoration Node + executeStereotypeLabelCreation(hostEditPart, stereotype); + } } - } /** @@ -417,14 +417,13 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic * the stereotype application */ protected void createAppliedStereotypeBraceCompartment(final Stereotype stereotype) { - final View node = hostEditPart.getNotationView(); - // doesn't exist already - if (!helper.isBraceCompartmentExist(node, stereotype)) { - // Create Compartment - executeAppliedStereotypeBraceCompartmentCreation(hostEditPart, stereotype); - + final View node = hostEditPart.getNotationView(); + // doesn't exist already + if (!helper.isBraceCompartmentExist(node, stereotype)) { + // Create Compartment + executeAppliedStereotypeBraceCompartmentCreation(hostEditPart, stereotype); + } } - } /** * In charge of properties view creation @@ -434,17 +433,16 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic */ protected void createAppliedStereotypeBraceProperties(final Stereotype stereotype) { - Node compartment = helper.getStereotypeBraceCompartment(hostEditPart.getNotationView(), stereotype); - if (compartment != null && stereotype != null) { - - EList<Property> properties = stereotype.allAttributes(); - for (Property property : properties) { - createAppliedStereotypeBraceProperty(compartment, property); - subscribe(helper.getStereotypePropertyInBrace(hostView, stereotype, property)); + Node compartment = helper.getStereotypeBraceCompartment(hostEditPart.getNotationView(), stereotype); + if (compartment != null && stereotype != null) { + EList<Property> properties = stereotype.allAttributes(); + for (Property property : properties) { + createAppliedStereotypeBraceProperty(compartment, property); + subscribe(helper.getStereotypePropertyInBrace(hostView, stereotype, property)); + } } } - } @@ -460,12 +458,11 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic // if stereotype is null all property of stereotype has to be removed! if (property != null && !property.getName().startsWith(Extension.METACLASS_ROLE_PREFIX)) { if (!helper.isBracePropertyExist(compartment, property)) { - // go through each stereotype property - executeAppliedStereotypeBracePropertyViewCreation(hostEditPart, compartment, property); - + // go through each stereotype property + executeAppliedStereotypeBracePropertyViewCreation(hostEditPart, compartment, property); + } } } - } /** * List on all the existing node contained into the main view. @@ -486,13 +483,13 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic if (((View) child).getElement() instanceof Stereotype) { Stereotype childStereotype = (Stereotype) ((View) child).getElement(); if (hostSemanticElement != null && !hostSemanticElement.isStereotypeApplied(childStereotype)) { - executeStereotypeViewRemove(hostEditPart, (View) child); + executeStereotypeViewRemove(hostEditPart, (View) child); + } } } } } } - } /** * The goal of this method is to execute the a command to create a notation node for a compartment of stereotype @@ -599,6 +596,7 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic * Remove Listeners added in this Edit Policy */ public void removeListener() { + View view = getView(); if (null != view) { unsubscribe(view); @@ -612,6 +610,8 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic unsubscribe(hostSemanticElement); // removes the reference to the semantic element hostSemanticElement = null; + unsubscribe(hostView); + hostView = null; } } @@ -626,7 +626,7 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic // Remove Brace Compartment Listener BasicCompartment compartment = helper.getStereotypeBraceCompartment(hostView, stereotype); if (null != compartment) { - subscribe(helper.getStereotypeBraceCompartment(hostView, stereotype)); + unsubscribe(helper.getStereotypeBraceCompartment(hostView, stereotype)); } // Remove Brace Properties Listener if (null != compartment && null != stereotype) { @@ -639,9 +639,11 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic } } - - + HashSet<EObject> copySuscribedListeners = new HashSet<>(suscribedListeners); + for (EObject listener : copySuscribedListeners) { + unsubscribe(listener); + } + suscribedListeners.clear(); } - } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeEmptyEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeEmptyEditPart.java index b5ddbbb32f8..b932e54bee2 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeEmptyEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpart/AppliedStereotypeEmptyEditPart.java @@ -1,6 +1,6 @@ /***************************************************************************** - * Copyright (c) 2015 CEA LIST and others. - * + * Copyright (c) 2015, 2024 CEA LIST and others. + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -11,7 +11,8 @@ * Contributors: * Celine JANSSENS (ALL4TEC) - Initial API and implementation * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 Stereotype Display - * + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 + * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpart; @@ -26,9 +27,9 @@ import org.eclipse.papyrus.uml.diagram.stereotype.edition.provider.StereotypePro /** * This Edit Part is a dummy edit part with no figure to be linked to a Notation View that is not representing a graphical object. * The Views related to this edit Part are Views of type StereotypeBrace, StereotypeLabel and StereotypeBraceProperty - * + * * @see StereotypePropertiesEditPartProvider - * + * * @author Celine JANSSENS * */ @@ -36,7 +37,7 @@ public class AppliedStereotypeEmptyEditPart extends GraphicalEditPart { public static final String ID = "AppliedStereotypesEmptyNode";//$NON-NLS-1$ - + private IFigure figure; /** @@ -77,25 +78,27 @@ public class AppliedStereotypeEmptyEditPart @Override protected IFigure createFigure() { if (figure == null) { - figure = new Figure() { - @Override - public void paint(org.eclipse.draw2d.Graphics graphics) { - // Nothing to do - }; + figure = new StereotypeEmptyFigure(); + } + return figure; - /** - * @see org.eclipse.draw2d.Figure#getBounds() - * - * @return - */ - @Override - public Rectangle getBounds() { - return new Rectangle(); - } + } - }; + private static class StereotypeEmptyFigure extends Figure { + @Override + public void paint(org.eclipse.draw2d.Graphics graphics) { + // Nothing to do + }; + + /** + * @see org.eclipse.draw2d.Figure#getBounds() + * + * @return + */ + @Override + public Rectangle getBounds() { + return new Rectangle(); } - return figure; } } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentEditPolicy.java index 35d3661599c..3a2c6d7f2ad 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCommentEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2012, 2016 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2012, 2016, 2024 CEA LIST, Christian W. Damus, and others. * * * All rights reserved. This program and the accompanying materials @@ -15,6 +15,7 @@ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Bug 393532 * Christian W. Damus - bugs 492407, 492482 * Calin Glitia (Esterel Technologies SAS) - Bug 491258 + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies; @@ -56,7 +57,7 @@ import org.eclipse.uml2.uml.Stereotype; * * As soon as one stereotype is applied a shape that represent the comment of the applied stereotype is created. it will also * create the edge between the shape and the comment of the shape. - * + * * This shape is serialized in the notation file, and its not associated to 1 applied stereotype. */ public class AppliedStereotypeCommentEditPolicy extends AppliedStereotypeNodeLabelDisplayEditPolicy { @@ -178,6 +179,7 @@ public class AppliedStereotypeCommentEditPolicy extends AppliedStereotypeNodeLab } } } + super.removeListener(); } @@ -261,10 +263,10 @@ public class AppliedStereotypeCommentEditPolicy extends AppliedStereotypeNodeLab protected void createAppliedStereotypeCompartment(final Stereotype stereotype) { // doesn't exist already if (comment != null && !helper.isCompartmentExist(comment, stereotype)) { - // Create Compartment - executeAppliedStereotypeCompartmentCreation(hostEditPart, stereotype, StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_TYPE); + // Create Compartment + executeAppliedStereotypeCompartmentCreation(hostEditPart, stereotype, StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_TYPE); + } } - } /** @@ -301,8 +303,8 @@ public class AppliedStereotypeCommentEditPolicy extends AppliedStereotypeNodeLab // if stereotype is null all property of stereotype has to be removed! if (property != null && !property.getName().startsWith(Extension.METACLASS_ROLE_PREFIX)) { if (!helper.isPropertyExist(compartment, property)) { - // go through each stereotype property - executeAppliedStereotypePropertyViewCreation(hostEditPart, compartment, property); + // go through each stereotype property + executeAppliedStereotypePropertyViewCreation(hostEditPart, compartment, property); } } @@ -318,11 +320,10 @@ public class AppliedStereotypeCommentEditPolicy extends AppliedStereotypeNodeLab protected void createAppliedStereotypeBraceCompartment(Stereotype stereotype) { // doesn't exist already if (comment != null && !helper.isCompartmentExist(comment, stereotype)) { - // Create Compartment - executeAppliedStereotypeCompartmentCreation(hostEditPart, stereotype, StereotypeDisplayConstant.STEREOTYPE_BRACE_TYPE); - + // Create Compartment + executeAppliedStereotypeCompartmentCreation(hostEditPart, stereotype, StereotypeDisplayConstant.STEREOTYPE_BRACE_TYPE); + } } - } /** * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractAppliedStereotypeDisplayEditPolicy#createAppliedStereotypeBraceProperties(org.eclipse.uml2.uml.Stereotype) @@ -411,37 +412,37 @@ public class AppliedStereotypeCommentEditPolicy extends AppliedStereotypeNodeLab */ protected void executeAppliedStereotypeCommentCreation(final EObject node) { - final TransactionalEditingDomain domain = hostEditPart.getEditingDomain(); + final TransactionalEditingDomain domain = hostEditPart.getEditingDomain(); + + int x = 200; + int y = 100; + if (hostEditPart.getModel() instanceof Node) { + LayoutConstraint constraint = ((Node) hostEditPart.getModel()).getLayoutConstraint(); + if (constraint instanceof Bounds) { + x = x + ((Bounds) constraint).getX(); + y = ((Bounds) constraint).getY(); + } - int x = 200; - int y = 100; - if (hostEditPart.getModel() instanceof Node) { - LayoutConstraint constraint = ((Node) hostEditPart.getModel()).getLayoutConstraint(); - if (constraint instanceof Bounds) { - x = x + ((Bounds) constraint).getX(); - y = ((Bounds) constraint).getY(); } + if (hostEditPart.getModel() instanceof Edge && ((((Edge) hostEditPart.getModel()).getSource()) instanceof Node)) { - } - if (hostEditPart.getModel() instanceof Edge && ((((Edge) hostEditPart.getModel()).getSource()) instanceof Node)) { + LayoutConstraint constraint = ((Node) ((Edge) hostEditPart.getModel()).getSource()).getLayoutConstraint(); + if (constraint instanceof Bounds) { + x = x + ((Bounds) constraint).getX(); + y = ((Bounds) constraint).getY() - 100; + } - LayoutConstraint constraint = ((Node) ((Edge) hostEditPart.getModel()).getSource()).getLayoutConstraint(); - if (constraint instanceof Bounds) { - x = x + ((Bounds) constraint).getX(); - y = ((Bounds) constraint).getY() - 100; } - - } - boolean isBorderElement = false; - if (hostEditPart instanceof BorderedBorderItemEditPart) { - isBorderElement = true; - } - if (helper.getStereotypeComment((View) getHost().getModel()) == null) { - CreateAppliedStereotypeCommentViewCommand command = new CreateAppliedStereotypeCommentViewCommand(domain, (View) hostEditPart.getModel(), x, y, node, isBorderElement); - // Record for undo if possible, otherwise unprotected - execute(command); + boolean isBorderElement = false; + if (hostEditPart instanceof BorderedBorderItemEditPart) { + isBorderElement = true; + } + if (helper.getStereotypeComment((View) getHost().getModel()) == null) { + CreateAppliedStereotypeCommentViewCommand command = new CreateAppliedStereotypeCommentViewCommand(domain, (View) hostEditPart.getModel(), x, y, node, isBorderElement); + // Record for undo if possible, otherwise unprotected + execute(command); + } } - } /** * In Charge to delete the Comment Node. @@ -474,4 +475,4 @@ public class AppliedStereotypeCommentEditPolicy extends AppliedStereotypeNodeLab } -} +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java index 969b9a9b69a..50d6012597a 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.stereotype.edition/src/org/eclipse/papyrus/uml/diagram/stereotype/edition/editpolicies/AppliedStereotypeCompartmentEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2012, 2016 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2012, 2016, 2024 CEA LIST, Christian W. Damus, and others. * * * All rights reserved. This program and the accompanying materials @@ -15,6 +15,7 @@ * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.fr - Bug 393532 * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display * Christian W. Damus - bug 492482 + * Pauline DEVILLE (CEA LIST) pauline.deville@cea.fr - Bug 583091 * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.stereotype.edition.editpolicies; @@ -98,11 +99,14 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod for (Property property : properties) { unsubscribe(helper.getStereotypeProperty(hostView, stereotype, property)); } + unsubscribe(helper.getStereotypeCompartment(hostView, stereotype)); + } } } + super.removeListener(); } /** @@ -128,14 +132,13 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod * the stereotype application */ protected void createAppliedStereotypeCompartment(final Stereotype stereotype) { - final View node = hostEditPart.getNotationView(); - // doesn't exist already - if (!helper.isCompartmentExist(node, stereotype)) { - // Create Compartment - executeAppliedStereotypeCompartmentCreation(hostEditPart, stereotype); - + final View node = hostEditPart.getNotationView(); + // doesn't exist already + if (!helper.isCompartmentExist(node, stereotype)) { + // Create Compartment + executeAppliedStereotypeCompartmentCreation(hostEditPart, stereotype); + } } - } /** @@ -147,16 +150,15 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod protected void createAppliedStereotypeProperties(final Stereotype stereotype) { - Node compartment = helper.getStereotypeCompartment(hostEditPart.getNotationView(), stereotype); - if (null != compartment && null != stereotype) { + Node compartment = helper.getStereotypeCompartment(hostEditPart.getNotationView(), stereotype); + if (null != compartment && null != stereotype) { - EList<Property> properties = stereotype.allAttributes(); - for (Property property : properties) { - createAppliedStereotypeProperty(compartment, property); - subscribe(helper.getStereotypeProperty(hostView, stereotype, property)); - - } + EList<Property> properties = stereotype.allAttributes(); + for (Property property : properties) { + createAppliedStereotypeProperty(compartment, property); + subscribe(helper.getStereotypeProperty(hostView, stereotype, property)); + } } } @@ -176,12 +178,12 @@ public class AppliedStereotypeCompartmentEditPolicy extends AppliedStereotypeNod // if stereotype is null all property of stereotype has to be removed! if (null != property && !property.getName().startsWith(Extension.METACLASS_ROLE_PREFIX)) { if (!helper.isPropertyExist(compartment, property)) { - // go through each stereotype property - executeAppliedStereotypePropertyViewCreation(hostEditPart, compartment, property); + // go through each stereotype property + executeAppliedStereotypePropertyViewCreation(hostEditPart, compartment, property); + } } } - } /** |