diff options
| author | Maxime Porhel | 2018-09-27 15:15:39 +0000 |
|---|---|---|
| committer | Maxime Porhel | 2018-09-28 14:38:47 +0000 |
| commit | bdd78fcfefe41f214a57ce06d86390d8199a0f1b (patch) | |
| tree | 4dcec959ea4d23d34c5c4733e7dcae0d21e7acce | |
| parent | 3aca9b5245e6ba16d7cc0f07000bda7447580e96 (diff) | |
| download | org.eclipse.sirius-bdd78fcfefe41f214a57ce06d86390d8199a0f1b.tar.gz org.eclipse.sirius-bdd78fcfefe41f214a57ce06d86390d8199a0f1b.tar.xz org.eclipse.sirius-bdd78fcfefe41f214a57ce06d86390d8199a0f1b.zip | |
[525261] Do not duplicate uid in style management
All copies done by EcoreUtil.copier and whose result is added to the
resource breaks the id /cache/uri fragment mecanisms.
This commits fix the copy/paste layout and copy/paste format and allows
to have several layout/format paste.
Bug: 525261
Change-Id: I7bc023e7e0c49c38a1ed7578054283c7da06ea6f
Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
6 files changed, 68 insertions, 51 deletions
diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/SiriusCopier.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/SiriusCopier.java index 0cdf129301..0d0d8cefe2 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/SiriusCopier.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/SiriusCopier.java @@ -31,6 +31,36 @@ public class SiriusCopier extends Copier { private static final long serialVersionUID = -5736164116383051335L; /** + * Creates an instance. + */ + public SiriusCopier() { + super(); + } + + /** + * Creates an instance that resolves proxies or not as specified. + * + * @param resolveProxies + * whether proxies should be resolved while copying. + */ + public SiriusCopier(boolean resolveProxies) { + this.resolveProxies = resolveProxies; + } + + /** + * Creates an instance that resolves proxies or not and uses non-copied references or not as specified. + * + * @param resolveProxies + * whether proxies should be resolved while copying. + * @param useOriginalReferences + * whether non-copied references should be used while copying. + */ + public SiriusCopier(boolean resolveProxies, boolean useOriginalReferences) { + this.resolveProxies = resolveProxies; + this.useOriginalReferences = useOriginalReferences; + } + + /** * This method does not copy {@link EAttribute} that is an id (see {@link EAttribute#isID()}).<br/> * If the id has not been set by the factory and if the attribute type is String, sets it using the * EcoreUtil.generateUUID(). @@ -45,6 +75,7 @@ public class SiriusCopier extends Copier { // See org.eclipse.emf.ecore.util.EcoreUtil.setID(EObject, String) valueToCopy = EcoreUtil.generateUUID(); } + return; } super.copyAttributeValue(eAttribute, eObject, valueToCopy, setting); } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/AbstractSiriusFormatDataManager.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/AbstractSiriusFormatDataManager.java index df9b366fcf..ee28b5ae57 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/AbstractSiriusFormatDataManager.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/format/AbstractSiriusFormatDataManager.java @@ -28,7 +28,6 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.gef.ConnectionEditPart; import org.eclipse.gef.EditPartViewer; import org.eclipse.gef.GraphicalEditPart; @@ -52,6 +51,7 @@ import org.eclipse.gmf.runtime.notation.RoutingStyle; import org.eclipse.gmf.runtime.notation.Smoothness; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint; +import org.eclipse.sirius.common.tools.api.util.SiriusCopier; import org.eclipse.sirius.common.tools.api.util.StringUtil; import org.eclipse.sirius.diagram.AbstractDNode; import org.eclipse.sirius.diagram.ContainerStyle; @@ -461,9 +461,8 @@ public abstract class AbstractSiriusFormatDataManager implements SiriusFormatDat * The format data containing the sirius style */ protected void applySiriusStyle(DSemanticDecorator semanticDecorator, AbstractFormatData formatData) { - // Make a copy of the style to allow several Paste with the same - // FormatData. - Style copyOfSiriusStyle = EcoreUtil.copy(formatData.getSiriusStyle()); + // Make a copy of the style to allow several Paste with the same FormatData. + Style copyOfSiriusStyle = SiriusCopier.Helper.copy(formatData.getSiriusStyle()); if ((semanticDecorator instanceof DNode || semanticDecorator instanceof DNodeListElement) && copyOfSiriusStyle instanceof NodeStyle) { if (semanticDecorator instanceof DNode) { computeCustomFeatures(((DNode) semanticDecorator).getOwnedStyle(), copyOfSiriusStyle); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/AbstractSiriusLayoutDataManager.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/AbstractSiriusLayoutDataManager.java index 2744ee067b..4e13c6b321 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/AbstractSiriusLayoutDataManager.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/layout/AbstractSiriusLayoutDataManager.java @@ -28,7 +28,6 @@ import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.gef.ConnectionEditPart; import org.eclipse.gef.EditPartViewer; import org.eclipse.gef.GraphicalEditPart; @@ -52,6 +51,7 @@ import org.eclipse.gmf.runtime.notation.RoutingStyle; import org.eclipse.gmf.runtime.notation.Smoothness; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint; +import org.eclipse.sirius.common.tools.api.util.SiriusCopier; import org.eclipse.sirius.common.tools.api.util.StringUtil; import org.eclipse.sirius.diagram.AbstractDNode; import org.eclipse.sirius.diagram.ContainerStyle; @@ -91,13 +91,11 @@ import com.google.common.collect.Iterables; /** * An abstract implementation for {@link SiriusLayoutDataManager}. <BR> - * Provide a method to store a layout from a graphicalEditPart and iterates on - * it's children. + * Provide a method to store a layout from a graphicalEditPart and iterates on it's children. * * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> * @deprecated since Sirius 4.1.0. Use - * {@link org.eclipse.sirius.diagram.ui.tools.api.format.AbstractSiriusFormatDataManager} - * instead. + * {@link org.eclipse.sirius.diagram.ui.tools.api.format.AbstractSiriusFormatDataManager} instead. * */ @Deprecated @@ -164,8 +162,7 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat * Apply the format to the <code>rootEditPart</code>. * * @param rootEditPart - * The root edit from which we would try to apply the current - * stored format + * The root edit from which we would try to apply the current stored format * @param applyLayout * true if the layout must be applied, false otherwise * @param applyStyle @@ -343,8 +340,8 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat } /** - * Search a layout corresponding to the semantic decorator and applies it to - * the node. Then it applies to it's children and outgoing edges. + * Search a layout corresponding to the semantic decorator and applies it to the node. Then it applies to it's + * children and outgoing edges. * * @param semanticDecorator * The semantic decorator to search the corresponding layout @@ -452,8 +449,7 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat } /** - * Apply the Sirius style contained in <code>layoutData</code> on the - * <code>semanticDecorator</code>. + * Apply the Sirius style contained in <code>layoutData</code> on the <code>semanticDecorator</code>. * * @param semanticDecorator * The {@link DSemanticDecorator} on which to apply the style. @@ -461,9 +457,8 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat * The layout data containing the sirius style */ protected void applySiriusStyle(DSemanticDecorator semanticDecorator, AbstractLayoutData layoutData) { - // Make a copy of the style to allow several Paste with the same - // LayoutData. - Style copyOfSiriusStyle = EcoreUtil.copy(layoutData.getSiriusStyle()); + // Make a copy of the style to allow several Paste with the same LayoutData. + Style copyOfSiriusStyle = SiriusCopier.Helper.copy(layoutData.getSiriusStyle()); if ((semanticDecorator instanceof DNode || semanticDecorator instanceof DNodeListElement) && copyOfSiriusStyle instanceof NodeStyle) { if (semanticDecorator instanceof DNode) { computeCustomFeatures(((DNode) semanticDecorator).getOwnedStyle(), copyOfSiriusStyle); @@ -482,15 +477,13 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat } /** - * Copies the appearance of the old view to the new view. Typically this - * means copying the visibility and the styles of the root and it's - * children. + * Copies the appearance of the old view to the new view. Typically this means copying the visibility and the styles + * of the root and it's children. * * @param newView * The new view to copy style features to * @param layoutData - * The layout data containing the old view to copy style features - * from + * The layout data containing the old view to copy style features from */ @SuppressWarnings("unchecked") protected void applyGMFStyle(View newView, AbstractLayoutData layoutData) { @@ -749,8 +742,7 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat * @param gmfView * GMF view * @param discoveredKeys - * The {@link LayoutDataKey} discovered during the current store - * action. + * The {@link LayoutDataKey} discovered during the current store action. */ protected void addNodeChildren(final DNode parentNode, final NodeLayoutData parentLayoutData, final IGraphicalEditPart parentEditPart, final View gmfView, Collection<LayoutDataKey> discoveredKeys) { @@ -771,8 +763,7 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat * @param parentSavedEditPart * The previous saved editPart (corresponds to parentLayoutData) * @param discoveredKeys - * The {@link LayoutDataKey} discovered during the current store - * action. + * The {@link LayoutDataKey} discovered during the current store action. */ protected void checkDataAndAddChildLayout(final NodeLayoutData parentLayoutData, final AbstractDNode child, final IGraphicalEditPart parentSavedEditPart, Collection<LayoutDataKey> discoveredKeys) { @@ -796,8 +787,7 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat * @param parentEditPart * The editPart corresponding to the parent LayoutData * @param discoveredKeys - * The {@link LayoutDataKey} discovered during the current store - * action. + * The {@link LayoutDataKey} discovered during the current store action. */ protected void addNodeContainerChildren(final DNodeContainer container, final NodeLayoutData parentLayoutData, final IGraphicalEditPart parentEditPart, Collection<LayoutDataKey> discoveredKeys) { for (final DDiagramElement child : container.getOwnedDiagramElements()) { @@ -820,8 +810,7 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat * @param parentEditPart * The editPart corresponding to the parent LayoutData * @param discoveredKeys - * The {@link LayoutDataKey} discovered during the current store - * action. + * The {@link LayoutDataKey} discovered during the current store action. */ protected void addNodeListChildren(final DNodeList nodeList, final NodeLayoutData parentLayoutData, final IGraphicalEditPart parentEditPart, Collection<LayoutDataKey> discoveredKeys) { for (final DNode child : nodeList.getOwnedBorderedNodes()) { @@ -946,9 +935,8 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat } /** - * Add the layout data of the label of the edge. This layout data sets the - * <code>edgeLabelLayoutData</code> of the {@link EdgeLayoutData}. It's not - * added to the layout data with a key in the manager. + * Add the layout data of the label of the edge. This layout data sets the <code>edgeLabelLayoutData</code> of the + * {@link EdgeLayoutData}. It's not added to the layout data with a key in the manager. * * @param parentLayoutData * The edge layout data @@ -969,9 +957,8 @@ public abstract class AbstractSiriusLayoutDataManager implements SiriusLayoutDat } /** - * Check for each attribute of newStyle if it is the same in oldStyle. On - * the other hand, this attribute is added to the custom features of the - * newStyle. + * Check for each attribute of newStyle if it is the same in oldStyle. On the other hand, this attribute is added to + * the custom features of the newStyle. * * @param oldStyle * The old style to compare with diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/format/FormatDataHelperImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/format/FormatDataHelperImpl.java index 596c35bdeb..88d8f2acff 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/format/FormatDataHelperImpl.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/format/FormatDataHelperImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2016 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 2018 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 @@ -17,7 +17,6 @@ import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.PointList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.gef.ConnectionEditPart; import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; @@ -31,6 +30,7 @@ import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.Size; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.common.tools.api.util.SiriusCopier; import org.eclipse.sirius.diagram.DDiagramElement; import org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery; import org.eclipse.sirius.diagram.formatdata.AbstractFormatData; @@ -143,11 +143,12 @@ public class FormatDataHelperImpl implements FormatDataHelper { private void copyViewStyleInFormatData(AbstractFormatData formatData, View view) { // 1-Copy Sirius Style if (view.getElement() instanceof DStylizable) { - formatData.setSiriusStyle(EcoreUtil.copy(((DStylizable) view.getElement()).getStyle())); + // If several paste can be done, the paste might also need to update the id. + formatData.setSiriusStyle(SiriusCopier.Helper.copy(((DStylizable) view.getElement()).getStyle())); } // 2-Copy GMF view to retrieve GMF style - EcoreUtil.Copier copierWithoutElementRef = new EcoreUtil.Copier(false, false); + SiriusCopier copierWithoutElementRef = new SiriusCopier(false, false); View viewCopy = (View) copierWithoutElementRef.copy(view); formatData.setGmfView(viewCopy); } @@ -298,8 +299,7 @@ public class FormatDataHelperImpl implements FormatDataHelper { } /** - * Creates a new Point which is translated by the values of the provided - * Point. + * Creates a new Point which is translated by the values of the provided Point. * * @param originalPoint * The point to translate. @@ -315,8 +315,7 @@ public class FormatDataHelperImpl implements FormatDataHelper { } /** - * Creates a new Point which is translated by the values of the provided - * Point. + * Creates a new Point which is translated by the values of the provided Point. * * @param originalPoint * The point to translate. diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/LayoutDataHelperImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/LayoutDataHelperImpl.java index 12a544ff83..ba2b53b776 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/LayoutDataHelperImpl.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/LayoutDataHelperImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 2018 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 @@ -17,7 +17,6 @@ import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.PointList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.gef.ConnectionEditPart; import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; @@ -31,6 +30,7 @@ import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.Size; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.common.tools.api.util.SiriusCopier; import org.eclipse.sirius.diagram.DDiagramElement; import org.eclipse.sirius.diagram.business.api.query.DDiagramElementQuery; import org.eclipse.sirius.diagram.layoutdata.AbstractLayoutData; @@ -143,11 +143,12 @@ public class LayoutDataHelperImpl implements LayoutDataHelper { private void copyNodeStyleInLayoutData(AbstractLayoutData layoutData, View view) { // 1-Copy Sirius Style if (view.getElement() instanceof DStylizable) { - layoutData.setSiriusStyle(EcoreUtil.copy(((DStylizable) view.getElement()).getStyle())); + // If several paste can be done, the paste might also need to udpate the id. + layoutData.setSiriusStyle(SiriusCopier.Helper.copy(((DStylizable) view.getElement()).getStyle())); } // 2-Copy GMF view to retrieve GMF style - EcoreUtil.Copier copierWithoutElementRef = new EcoreUtil.Copier(false, false); + SiriusCopier copierWithoutElementRef = new SiriusCopier(false, false); View viewCopy = (View) copierWithoutElementRef.copy(view); layoutData.setGmfView(viewCopy); } diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/helper/StyleHelper.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/helper/StyleHelper.java index 01b219b5db..7a327e754a 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/helper/StyleHelper.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/helper/StyleHelper.java @@ -18,12 +18,12 @@ import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; import org.eclipse.sirius.business.api.metamodel.helper.FontFormatHelper; import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; import org.eclipse.sirius.common.tools.api.util.EqualityHelper; +import org.eclipse.sirius.common.tools.api.util.SiriusCopier; import org.eclipse.sirius.common.tools.api.util.StringUtil; import org.eclipse.sirius.diagram.AbstractDNode; import org.eclipse.sirius.diagram.BeginLabelStyle; @@ -731,7 +731,7 @@ public final class StyleHelper { } } if (brokenStyle && style.eContainer() instanceof AbstractDNode) { - EObject copy = EcoreUtil.copy(createNodeStyle(description)); + EObject copy = SiriusCopier.Helper.copy(createNodeStyle(description)); final NodeStyle newStyle = (NodeStyle) copy; affectStyle((AbstractDNode) style.eContainer(), newStyle); } |
