diff options
| author | Laurent Redor | 2018-10-11 16:48:39 +0000 |
|---|---|---|
| committer | Laurent Redor | 2018-10-11 16:55:58 +0000 |
| commit | a325e533a8f9e155784b4ffcb874546375dc7288 (patch) | |
| tree | 84ae07a0733d6b257c16cf025b50f0926b13ee36 | |
| parent | aae93420a53352b578ed63d2544b0d6a091198bd (diff) | |
| download | org.eclipse.sirius-a325e533a8f9e155784b4ffcb874546375dc7288.tar.gz org.eclipse.sirius-a325e533a8f9e155784b4ffcb874546375dc7288.tar.xz org.eclipse.sirius-a325e533a8f9e155784b4ffcb874546375dc7288.zip | |
[540056] Improve Link Note delete lifecycle
Link notes are no longer automatically deleted when the linked
representation is deleted. This prevents unnecessary locks in
collaborative sirius and the user won't lose the note text. If
a linked representation is deleted, the note will indicate that
it was linked to a representation that has been deleted.
Bug: 540056
Cherry-picked-from: 535648
Signed-off-by: Felix Dorner <felix.dorner@gmail.com>
Change-Id: Ib2583ee8ce4cdf9cab67db194bf64b1ac1446fd6
21 files changed, 721 insertions, 56 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties index 63df1da868..6249f78c90 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties @@ -104,7 +104,7 @@ menu.showHide.label = Show/Hide palettetool.linkNote.description = Create a Note that references another representation palettetool.linkNote.label = Representation Link palettetool.linkNote.elementTypeName=LinkNote - +palettetool.linkNote.deletedLabel=Broken representation link ## GENERATED ## _UI_CreateChild_text = {0} @@ -1077,6 +1077,8 @@ RemoveBendpointsHandler_cmdLabel = Remove Bend-points RemoveInvalidViewsCommand_label = Remove invalid views RepairGMFbendpointsMigrationParticipant_edgesModified = \n\t* In diagram "{0}", bend-points of some edges have been repaired because their GMF coordinates were not correct. RepairGMFbendpointsMigrationParticipant_title = Migration done for "Wrong edge bend-points" (the result of this migration will be saved on the next session save): +RepresentationLinkMigrationParticipant_title = Link notes were migrated on the following diagrams: +RepresentationLinkMigrationParticipant_entry = * {0} DeleteMultipleConnectorMigrationParticipant_edgesModified = \n\t* In diagram "{0}", connectors style of some edges have been deleted because only one is required. DeleteMultipleConnectorMigrationParticipant_title = Migration done for "Multiple Connector Style" (the result of this migration will be saved on the next session save): diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml index 1bc55dd3af..001d548379 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.xml +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.xml @@ -11,7 +11,7 @@ Contributors: Obeo - Initial API and implementation - Felix Dorner <felix.dorner@gmail.com> - Bug 533002 + Felix Dorner <felix.dorner@gmail.com> - Bug 533002, 540056 --> <plugin> @@ -1924,6 +1924,10 @@ class="org.eclipse.sirius.diagram.ui.business.internal.migration.DeleteMultipleConnectorStyleMigrationParticipant" kind="RepresentationsFile"> </participant> + <participant + class="org.eclipse.sirius.diagram.ui.business.internal.migration.RepresentationLinkMigrationParticipant" + kind="RepresentationsFile"> + </participant> </extension> <extension point="org.eclipse.emf.edit.itemProviderAdapterFactories"> diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java index b8ab467cab..f2528deaea 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/api/query/ViewQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2012, 2018 THALES GLOBAL SERVICES and others. * 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 @@ -9,6 +9,7 @@ * * Contributors: * Obeo - initial API and implementation + * Felix Dorner <felix.dorner@gmail.com> - Bug 540056 *******************************************************************************/ package org.eclipse.sirius.diagram.ui.business.api.query; @@ -16,9 +17,11 @@ import java.util.LinkedHashSet; import java.util.Optional; import java.util.Set; +import org.eclipse.emf.ecore.EAnnotation; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.diagram.core.util.ViewType; import org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants; import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities; @@ -45,6 +48,7 @@ import org.eclipse.sirius.diagram.ui.part.SiriusVisualIDRegistry; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.sirius.ext.base.Option; import org.eclipse.sirius.ext.base.Options; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.DStylizable; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.FontData; @@ -70,6 +74,11 @@ public class ViewQuery { public static final String VERTICAL_ALIGNMENT = "verticalAlignment"; //$NON-NLS-1$ /** + * custom data key for link notes, used in the {@link #SPECIFIC_STYLES} annotation. + */ + public static final String REPRESENTATION_LINK_NOTE = "representationlink"; //$NON-NLS-1$ + + /** * The set of GMF style attributes customizable for which not corresponding Sirius style property exists. */ public static final Set<EAttribute> CUSTOMIZABLE_GMF_EXCLUSIVE_STYLE_ATTRIBUTES = new LinkedHashSet<EAttribute>(); @@ -319,6 +328,27 @@ public class ViewQuery { } /** + * Is the view a representation link note? + * + * @return true if this is a representation link note, false otherwise + */ + public boolean isRepresentationLink() { + EAnnotation specificStyles = view.getEAnnotation(ViewQuery.SPECIFIC_STYLES); + return specificStyles != null && specificStyles.getDetails().containsKey(REPRESENTATION_LINK_NOTE) && ViewType.NOTE.equals(view.getType()); + } + + /** + * For a representation link, check if it refers to a deleted representation descriptor. Invocations should be + * guarded by {@link #isRepresentationLink()}. + * + * @return true if the representation link note view has a dangling target, false otherwise. + */ + public boolean isRepresentationLinkBroken() { + EObject element = view.getElement(); + return !(element instanceof DRepresentationDescriptor) || element.eIsProxy() || element.eResource() == null; + } + + /** * Return the {@link DDiagram} of the {@link Diagram} that is either the given view or a parent of the given view if * such element exists. * diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/migration/RepresentationLinkMigrationParticipant.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/migration/RepresentationLinkMigrationParticipant.java new file mode 100644 index 0000000000..55ad7c26a0 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/migration/RepresentationLinkMigrationParticipant.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2018 THALES GLOBAL SERVICES. + * 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: + * Felix Dorner <felix.dorner@gmail.com> - initial API and implementation + */ +package org.eclipse.sirius.diagram.ui.business.internal.migration; + +import java.text.MessageFormat; +import java.util.Iterator; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gmf.runtime.diagram.core.util.ViewType; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.business.api.migration.AbstractRepresentationsFileMigrationParticipant; +import org.eclipse.sirius.business.api.query.DViewQuery; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.DiagramPlugin; +import org.eclipse.sirius.diagram.ui.business.api.query.DDiagramGraphicalQuery; +import org.eclipse.sirius.diagram.ui.internal.view.factories.SiriusNoteViewFactory; +import org.eclipse.sirius.diagram.ui.provider.Messages; +import org.eclipse.sirius.ext.base.Option; +import org.eclipse.sirius.viewpoint.DAnalysis; +import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.sirius.viewpoint.DView; +import org.osgi.framework.Version; + +/** + * Reuse the sirius 'specific styles' annotation to mark all existing link notes with a special details entry. This + * marker neccessary to differenciate between link notes whose target representation descriptor has been deleted and + * normal notes. + * + * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=535648">Bug 535648</a> + * @author Felix Dorner <felix.dorner@gmail.com> + */ +public class RepresentationLinkMigrationParticipant extends AbstractRepresentationsFileMigrationParticipant { + + /** + * The version for which this migration is added. + */ + public static final Version MIGRATION_VERSION = new Version("14.1.0.201810111800"); //$NON-NLS-1$ + + private boolean migrateDiagram(Diagram diag) { + boolean changed = false; + Iterator<EObject> it = diag.eAllContents(); + while (it.hasNext()) { + EObject next = it.next(); + if (next instanceof View && ViewType.NOTE.equals(((View) next).getType()) && ((View) next).getElement() instanceof DRepresentationDescriptor) { + SiriusNoteViewFactory.markAsLinkNote((View) next); + changed = true; + } + } + return changed; + } + + @Override + protected void postLoad(DAnalysis dAnalysis, Version loadedVersion) { + if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) { + StringBuilder builder = new StringBuilder(); + boolean isModified = false; + for (DView view : dAnalysis.getOwnedViews()) { + for (DRepresentation representation : new DViewQuery(view).getLoadedRepresentations()) { + if (representation instanceof DDiagram) { + DDiagramGraphicalQuery query = new DDiagramGraphicalQuery((DDiagram) representation); + Option<Diagram> option = query.getAssociatedGMFDiagram(); + if (option.some() && migrateDiagram(option.get())) { + builder.append(MessageFormat.format(Messages.RepresentationLinkMigrationParticipant_entry, representation.getName())).append(System.lineSeparator()); + isModified = true; + } + } + } + } + if (isModified) { + builder.insert(0, System.lineSeparator()); + builder.insert(0, Messages.RepresentationLinkMigrationParticipant_title); + DiagramPlugin.getDefault().logInfo(builder.toString()); + } + } + } + + @Override + public Version getMigrationVersion() { + return MIGRATION_VERSION; + } + +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/listener/RepresentationLinkPostCommitListener.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/listener/RepresentationLinkPostCommitListener.java new file mode 100644 index 0000000000..7a1ac05cbe --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/listener/RepresentationLinkPostCommitListener.java @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2018 THALES GLOBAL SERVICES. + * 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: + * Felix Dorner <felix.dorner@gmail.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.edit.internal.part.listener; + +import static org.eclipse.emf.transaction.NotificationFilter.createFeatureFilter; + +import java.util.Collection; +import java.util.HashSet; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.ECrossReferenceAdapter; +import org.eclipse.emf.transaction.NotificationFilter; +import org.eclipse.emf.transaction.ResourceSetChangeEvent; +import org.eclipse.emf.transaction.ResourceSetListenerImpl; +import org.eclipse.gef.EditPart; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.Shape; +import org.eclipse.sirius.diagram.business.api.query.EObjectQuery; +import org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusNoteEditPart; +import org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.sirius.viewpoint.ViewpointPackage; + +/** + * Triggers refresh of this diagram's representation links when appropriate. + */ +public class RepresentationLinkPostCommitListener extends ResourceSetListenerImpl { + + private DDiagramEditorImpl diagramEditor; + + /** + * Default constructor. + * + * @param dDiagramEditorImpl + * listened part. + */ + public RepresentationLinkPostCommitListener(DDiagramEditorImpl dDiagramEditorImpl) { + // Representation links must be refreshed not only when the target representation + // is deleted, but also when the target representation is added after + // undoing a deletion + super(createFeatureFilter(ViewpointPackage.Literals.DVIEW__OWNED_REPRESENTATION_DESCRIPTORS).and(NotificationFilter.NOT_TOUCH)); + diagramEditor = dDiagramEditorImpl; + diagramEditor.getEditingDomain().addResourceSetListener(this); + } + + @Override + public boolean isPrecommitOnly() { + return false; + } + + @Override + public boolean isPostcommitOnly() { + return true; + } + + @Override + public void resourceSetChanged(ResourceSetChangeEvent event) { + Collection<DRepresentationDescriptor> affected = new HashSet<DRepresentationDescriptor>(); + for (Notification notif : event.getNotifications()) { + switch (notif.getEventType()) { + case Notification.REMOVE: + affected.add((DRepresentationDescriptor) notif.getOldValue()); + break; + case Notification.REMOVE_MANY: + affected.addAll((Collection<DRepresentationDescriptor>) notif.getOldValue()); + break; + case Notification.ADD: + affected.add((DRepresentationDescriptor) notif.getNewValue()); + break; + case Notification.ADD_MANY: + affected.addAll((Collection<DRepresentationDescriptor>) notif.getNewValue()); + break; + default: + break; + } + } + + ECrossReferenceAdapter semanticCrossReferencer = diagramEditor.getSession().getSemanticCrossReferencer(); + for (DRepresentationDescriptor descriptor : affected) { + for (EObject referencer : new EObjectQuery(descriptor, semanticCrossReferencer).getInverseReferences(NotationPackage.Literals.VIEW__ELEMENT)) { + if (referencer instanceof Shape && ((Shape) referencer).getDiagram() == diagramEditor.getDiagram()) { + EditPart part = (EditPart) diagramEditor.getDiagramGraphicalViewer().getEditPartRegistry().get(referencer); + if (part instanceof SiriusNoteEditPart) { + ((SiriusNoteEditPart) part).refreshDiagramNameCompartmentEditPart(); + } + } + } + } + } + + /** + * Dispose this listener. + */ + public void dispose() { + if (getTarget() != null) { + getTarget().removeResourceSetListener(this); + } + diagramEditor = null; + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/SiriusDiagramNameCompartmentEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/SiriusDiagramNameCompartmentEditPart.java index 19c555d654..b86b5977fe 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/SiriusDiagramNameCompartmentEditPart.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/SiriusDiagramNameCompartmentEditPart.java @@ -13,17 +13,21 @@ package org.eclipse.sirius.diagram.ui.internal.edit.parts; +import org.eclipse.draw2d.IFigure; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.edit.provider.IItemLabelProvider; import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; import org.eclipse.gef.DragTracker; +import org.eclipse.gef.EditPart; import org.eclipse.gef.Request; import org.eclipse.gmf.runtime.diagram.ui.editparts.TopGraphicEditPart; import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.DiagramNameCompartmentEditPart; import org.eclipse.gmf.runtime.gef.ui.internal.tools.DelegatingDragEditPartsTracker; import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; import org.eclipse.swt.graphics.Image; /** @@ -37,6 +41,15 @@ public class SiriusDiagramNameCompartmentEditPart extends DiagramNameCompartment @Override protected Image getLabelIcon(int i) { + EditPart ep = getParent(); + if (ep instanceof SiriusNoteEditPart) { + if (((SiriusNoteEditPart) ep).isRepresentationLink()) { + if (((SiriusNoteEditPart) ep).isRepresentationLinkBroken()) { + return DiagramUIPlugin.getPlugin().getImage(DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.DELETED_DIAG_ELEM_DECORATOR_ICON)); + } + } + } + if (getElement() != null) { EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(getElement()); if (domain instanceof AdapterFactoryEditingDomain) { @@ -49,6 +62,15 @@ public class SiriusDiagramNameCompartmentEditPart extends DiagramNameCompartment return super.getLabelIcon(i); } + @Override + protected String getLabelText() { + EditPart ep = getParent(); + if (ep instanceof SiriusNoteEditPart && ((SiriusNoteEditPart) ep).isRepresentationLink() && (((SiriusNoteEditPart) ep).isRepresentationLinkBroken())) { + return DiagramUIPlugin.getPlugin().getString("palettetool.linkNote.deletedLabel"); //$NON-NLS-1$ + } + return super.getLabelText(); + } + /** * @see org.eclipse.gef.EditPart#getDragTracker(org.eclipse.gef.Request) */ @@ -59,6 +81,37 @@ public class SiriusDiagramNameCompartmentEditPart extends DiagramNameCompartment return new DelegatingDragEditPartsTracker(tgep, tgep); } + /** + * Overridden to handle dangling link notes in sirius collab. + */ + @Override + protected void setVisibility(boolean vis) { + EditPart parent = getParent(); + if (parent instanceof SiriusNoteEditPart && ((SiriusNoteEditPart) parent).isRepresentationLink()) { + // This code is copied from GraphicalEditPart to avoid calling + // the parent class method: DiagramNameCompartmentEditPart is invisible + // if the view element is null, but this collides with the case + // of a dangling representation link in sirius collab. + if (!vis && getSelected() != SELECTED_NONE) + getViewer().deselect(this); + + IFigure _figure = getFigure(); + if (_figure.isVisible() == vis) { + return; + } + + // if we are going to hide the node then connections coming to the + // node or outside it should be hidden as well + if (getFlag(FLAG__AUTO_CONNECTIONS_VISIBILITY)) { + setConnectionsVisibility(vis); + } + _figure.setVisible(vis); + _figure.revalidate(); + } else { + super.setVisibility(vis); + } + } + private EObject getElement() { View primary = getPrimaryView(); if (primary != null) { diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/SiriusNoteEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/SiriusNoteEditPart.java index 1d67efe463..af18bebf6f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/SiriusNoteEditPart.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/SiriusNoteEditPart.java @@ -18,22 +18,19 @@ import java.util.Optional; import org.eclipse.draw2d.Graphics; import org.eclipse.draw2d.geometry.Insets; -import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notification; -import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.gef.DragTracker; import org.eclipse.gef.Request; +import org.eclipse.gmf.runtime.diagram.core.util.ViewType; import org.eclipse.gmf.runtime.diagram.ui.editparts.DescriptionCompartmentEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.NoteEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; import org.eclipse.gmf.runtime.diagram.ui.figures.NoteFigure; -import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.DiagramNameCompartmentEditPart; import org.eclipse.gmf.runtime.diagram.ui.internal.properties.Properties; import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode; import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; -import org.eclipse.gmf.runtime.notation.NotationPackage; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.sirius.business.api.helper.SiriusUtil; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DiagramPackage; import org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery; @@ -52,11 +49,6 @@ import com.google.common.collect.Iterables; */ public class SiriusNoteEditPart extends NoteEditPart { - /* this handles removal of representation link notes when the referenced diagram is deleted */ - static final Adapter LINK_ADAPTER = new DiagramLinkAdapter(); - - private boolean diagramLinkMode = false; - /** * Default constructor. * @@ -102,8 +94,11 @@ public class SiriusNoteEditPart extends NoteEditPart { addListenerFilter("ShowingMode", this, diagram.get(), DiagramPackage.eINSTANCE.getDDiagram_IsInShowingMode()); //$NON-NLS-1$ } } - if (isRepresentationLink()) { - getNotationView().eAdapters().add(LINK_ADAPTER); + if (isRepresentationLink() && !isRepresentationLinkBroken()) { + DRepresentationDescriptor linkedDescriptor = (DRepresentationDescriptor) getNotationView().getElement(); + if (linkedDescriptor != null) { + addListenerFilter("DiagramLink_RepresentationNameChange", this, linkedDescriptor); //$NON-NLS-1$ + } } } @@ -112,9 +107,7 @@ public class SiriusNoteEditPart extends NoteEditPart { protected void removeNotationalListeners() { super.removeNotationalListeners(); removeListenerFilter("ShowingMode"); //$NON-NLS-1$ - if (isRepresentationLink()) { - getNotationView().eAdapters().remove(LINK_ADAPTER); - } + removeListenerFilter("DiagramLink_RepresentationNameChange"); //$NON-NLS-1$ } @Override @@ -178,16 +171,8 @@ public class SiriusNoteEditPart extends NoteEditPart { @Override protected void handleNotificationEvent(Notification notification) { super.handleNotificationEvent(notification); - - // this handles representation link note label refresh when the linked representation name changes - if (isRepresentationLink()) { - if (getNotationView().getElement() == notification.getNotifier() && notification.getFeature() == ViewpointPackage.Literals.DREPRESENTATION_DESCRIPTOR__NAME) { - Iterable<DiagramNameCompartmentEditPart> diagramNameCompartmentEditPartsfilter = Iterables.filter(this.getChildren(), DiagramNameCompartmentEditPart.class); - if (Iterables.size(diagramNameCompartmentEditPartsfilter) == 1) { - DiagramNameCompartmentEditPart diagramNameCompartmentEditPart = Iterables.getOnlyElement(diagramNameCompartmentEditPartsfilter); - refreshChild(diagramNameCompartmentEditPart); - } - } + if (notification.getNotifier() == getNotationView().getElement() && notification.getFeature() == ViewpointPackage.Literals.DREPRESENTATION_DESCRIPTOR__NAME) { + refreshDiagramNameCompartmentEditPart(); } } @@ -205,24 +190,45 @@ public class SiriusNoteEditPart extends NoteEditPart { /** * Is this a diagram link or is it a 'simple' note? * + * @see {@link ViewQuery#isRepresentationLink()} * @return true if this is a diagram link, false otherwise */ public boolean isRepresentationLink() { - return getNotationView() != null && getNotationView().getElement() instanceof DRepresentationDescriptor; + boolean result = false; + View view = getNotationView(); + if (view != null) { + ViewQuery query = new ViewQuery(view); + result = query.isRepresentationLink(); + } + return result; } - /* - * This just deletes the view when the element reference is unset, i.e. when the view's DRepresentationDescriptor is - * deleted. + /** + * For a representation link, check if it refers to a deleted representation descriptor. Invocations should be + * guarded by {@link #isRepresentationLink()}. + * + * @see {@link ViewQuery#isRepresentationLinkBroken()} + * @return true if the link note view has a dangling target, false otherwise. */ - static class DiagramLinkAdapter extends AdapterImpl { - @Override - public void notifyChanged(Notification msg) { - if (msg.getEventType() == Notification.UNSET && msg.getFeature() == NotationPackage.Literals.VIEW__ELEMENT) { - ((View) msg.getNotifier()).eAdapters().remove(this); - SiriusUtil.delete((View) msg.getNotifier()); - } + boolean isRepresentationLinkBroken() { + boolean result = false; + View view = getNotationView(); + if (view != null) { + ViewQuery query = new ViewQuery(view); + result = query.isRepresentationLinkBroken(); } + return result; } + /** + * Refresh the name compartment of this note. + */ + public void refreshDiagramNameCompartmentEditPart() { + for (Object ep : getChildren()) { + IGraphicalEditPart gep = (IGraphicalEditPart) ep; + if (gep.getNotationView() != null && ViewType.DIAGRAM_NAME.equals(gep.getNotationView().getType())) { + gep.refresh(); + } + } + } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/view/factories/SiriusNoteViewFactory.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/view/factories/SiriusNoteViewFactory.java index 957e87e323..253cb62564 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/view/factories/SiriusNoteViewFactory.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/view/factories/SiriusNoteViewFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2017, 2018 THALES GLOBAL SERVICES. * 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 @@ -9,12 +9,14 @@ * * Contributors: * Obeo - initial API and implementation + * Felix Dorner <felix.dorner@gmail.com> - Bug 540056 *******************************************************************************/ package org.eclipse.sirius.diagram.ui.internal.view.factories; import java.util.Collection; import java.util.List; +import org.eclipse.core.runtime.IAdaptable; import org.eclipse.draw2d.PositionConstants; import org.eclipse.emf.ecore.EAnnotation; import org.eclipse.emf.ecore.EObject; @@ -27,6 +29,7 @@ import org.eclipse.gmf.runtime.notation.TextAlignment; import org.eclipse.gmf.runtime.notation.TextStyle; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import com.google.common.collect.Iterables; @@ -35,6 +38,8 @@ import com.google.common.collect.Iterables; * in GMF runtime 1.8.0 (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=432387). This factory creates notes with the * old default alignment value. * + * Also handles specific view creation for representation links. + * * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> * */ @@ -58,6 +63,22 @@ public class SiriusNoteViewFactory extends NoteViewFactory { } /** + * Made public for migration of old representation links. + * + * @param view + * the representation link view + */ + public static void markAsLinkNote(View view) { + EAnnotation specificStyles = view.getEAnnotation(ViewQuery.SPECIFIC_STYLES); + if (specificStyles == null) { + specificStyles = EcoreFactory.eINSTANCE.createEAnnotation(); + specificStyles.setSource(ViewQuery.SPECIFIC_STYLES); + view.getEAnnotations().add(specificStyles); + } + specificStyles.getDetails().put(ViewQuery.REPRESENTATION_LINK_NOTE, null); + } + + /** * Set the {@link TextStyle} with the default horizontal alignment. * * @param styles @@ -78,4 +99,16 @@ public class SiriusNoteViewFactory extends NoteViewFactory { setDefaultHorizontalAlignment(styles); return styles; } + + /** + * Overridden to mark representation link views with a special annotation. + */ + @Override + protected void decorateView(View containerView, View view, IAdaptable semanticAdapter, String semanticHint, int index, boolean persisted) { + super.decorateView(containerView, view, semanticAdapter, semanticHint, index, persisted); + EObject element = view.getElement(); + if (element instanceof DRepresentationDescriptor) { + markAsLinkNote(view); + } + } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java index 40bfba896c..f8b2eaf491 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java @@ -9,6 +9,7 @@ * * Contributors: * Obeo - initial API and implementation + * Felix Dorner <felix.dorner@gmail.com> - Bug 540056 *******************************************************************************/ package org.eclipse.sirius.diagram.ui.tools.internal.editor; @@ -138,6 +139,7 @@ import org.eclipse.sirius.diagram.ui.business.internal.command.RefreshDiagramOnO import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDDiagramEditPart; import org.eclipse.sirius.diagram.ui.edit.api.part.AbstractDiagramNameEditPart; import org.eclipse.sirius.diagram.ui.edit.internal.part.listener.DiagramHeaderPostCommitListener; +import org.eclipse.sirius.diagram.ui.edit.internal.part.listener.RepresentationLinkPostCommitListener; import org.eclipse.sirius.diagram.ui.edit.internal.part.listener.SynchronizedStatusPostCommitListener; import org.eclipse.sirius.diagram.ui.edit.internal.part.listener.VisibilityPostCommitListener; import org.eclipse.sirius.diagram.ui.internal.refresh.SiriusDiagramSessionEventBroker; @@ -389,6 +391,8 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE private SynchronizedStatusPostCommitListener statusBarPostCommitListener; + private RepresentationLinkPostCommitListener representationLinkPostCommitListener; + private GMFDiagramUpdater gmfDiagramUpdater; private DialectEditorDialogFactory myDialogFactory = new DiagramDialectEditorDialogFactory(this); @@ -593,6 +597,7 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE tabbarPostCommitListener = new TabbarRefresher(getEditingDomain()); visibilityPostCommitListener = new VisibilityPostCommitListener(getDiagramEditPart()); statusBarPostCommitListener = new SynchronizedStatusPostCommitListener(this); + representationLinkPostCommitListener = new RepresentationLinkPostCommitListener(this); if (isHeaderSectionEnabled()) { diagramHeaderPostCommitListener = new DiagramHeaderPostCommitListener(getEditingDomain(), getDiagramHeader()); } @@ -916,6 +921,10 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE diagramHeaderPostCommitListener.dispose(); diagramHeaderPostCommitListener = null; } + if (representationLinkPostCommitListener != null) { + representationLinkPostCommitListener.dispose(); + representationLinkPostCommitListener = null; + } } @Override diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/testers/LinkNoteTester.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/testers/LinkNoteTester.java index 23a26b1c2f..b096e094e9 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/testers/LinkNoteTester.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/testers/LinkNoteTester.java @@ -13,7 +13,9 @@ package org.eclipse.sirius.diagram.ui.tools.internal.testers; import org.eclipse.core.expressions.PropertyTester; -import org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusNoteEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery; /** * Tester to know if an IGraphicalEditPart represents a representation link note. @@ -34,7 +36,14 @@ public class LinkNoteTester extends PropertyTester { @Override public boolean test(Object receiver, String property, Object[] args, Object expectedValue) { if (PROPERTY_IS_LINK_NOTE.equals(property)) { - return receiver instanceof SiriusNoteEditPart && ((SiriusNoteEditPart) receiver).isRepresentationLink(); + boolean result = false; + IGraphicalEditPart part = (IGraphicalEditPart) receiver; + View view = part.getNotationView(); + if (view != null) { + ViewQuery query = new ViewQuery(view); + result = query.isRepresentationLink(); + } + return result; } throw new IllegalArgumentException("Unknown property: " + property); //$NON-NLS-1$ } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java index 417bb99a2a..4cb89656bb 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java @@ -947,6 +947,12 @@ public final class Messages { public static String RepairGMFbendpointsMigrationParticipant_title; @TranslatableMessage + public static String RepresentationLinkMigrationParticipant_title; + + @TranslatableMessage + public static String RepresentationLinkMigrationParticipant_entry; + + @TranslatableMessage public static String DeleteMultipleConnectorMigrationParticipant_title; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 7f5c520d9b..ae08764819 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -109,6 +109,9 @@ <ul> <li><span class="label label-success">Added</span> A quick fix is now available on the error marker signaling a modeling project without a representations file. Processing this quick fix will create a new empty representation file.</li> <li><span class="label label-info">Modified</span> The tool “Link Note”, introduced in Sirius 6.0.0, has been renamed into “Representation Link”.</li> + <li><span class="label label-info">Modified</span> A “Representation Link” is no longer deleted automatically when the targeted representation is deleted. Instead, the note header changes to “Broken Representation Link” and the note icon changes to a small red diagonal cross. You can refer to the + <a href="user/diagrams/Diagrams.html#notes">user documentation</a> for more details. + </li> </ul> <h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3> <ul> @@ -228,6 +231,15 @@ </li> </ul> </li> + <li><span class="label label-success">Added</span> The query + <code>isRepresentationLink()</code> has been added in + <code>org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery</code> to know if the view is a representation link or a normal note. + </li> + <li><span class="label label-success">Added</span> The query + <code>isRepresentationLinkBroken()</code> has been added in + <code>org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery</code> to know, for a representation link, if it refers to a deleted representation descriptor. Invocations should be guarded by + <code>isRepresentationLink()</code>. + </li> <li><span class="label label-info">Modified</span> The interface <code>org.eclipse.sirius.diagram.ui.tools.api.figure.ViewNodeContainerFigureDesc</code> has been moved to <code>org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures</code> package. @@ -398,6 +410,10 @@ <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=539944">bugzilla #539944</a> for more details). The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is <em>14.1.0.201810051700</em>. </li> + <li><span class="label label-success">Added</span> A migration participant has been added to update existing representation link. (see + <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=535648">bugzilla #533175</a> for more details). The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is + <em>14.1.0.201810111800</em>. + </li> </ul> <h2 id="sirius6.0.0">Changes in Sirius 6.0.0</h2> <h3 id="UserVisibleChanges2">User-Visible Changes</h3> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index 7876ab5bf1..a2f23862e1 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -20,7 +20,7 @@ h3. User-Visible Changes !user/diagrams/images/show_hide_mode_tabbar_activate.png! * <span class="label label-success">Added</span> A quick fix is now available on the error marker signaling a modeling project without a representations file. Processing this quick fix will create a new empty representation file. * <span class="label label-info">Modified</span> The tool "Link Note", introduced in Sirius 6.0.0, has been renamed into "Representation Link". - +* <span class="label label-info">Modified</span> A "Representation Link" is no longer deleted automatically when the targeted representation is deleted. Instead, the note header changes to "Broken Representation Link" and the note icon changes to a small red diagonal cross. You can refer to the "user documentation":user/diagrams/Diagrams.html#notes for more details. h3. Specifier-Visible Changes @@ -63,6 +63,8 @@ h4. Changes in @org.eclipse.sirius.diagram.ui@ ** @stdGetViewsWithSameMapping(DSemanticDiagram, List<DSemanticDecorator>)@: Return the list of @DSemanticDecorator@ having the same mappings as the current selected diagram elements. ** @stdGetViewsRepresentingSelectedType(DSemanticDiagram)@: Return the list of @DSemanticDecorator@ in the current diagram representing semantic element having the EType provided by the end-user through a dialog box. This dialog box can be improved. There is currently no completion, neither validation. ** @stdGetViewsOfExpression(DSemanticDiagram)@: Return the list of @DSemanticDecorator@ corresponding to the evaluation of an expression written by the end-user in a dialog box. This dialog box can be improved. There is currently no completion, neither validation. +* <span class="label label-success">Added</span> The query @isRepresentationLink()@ has been added in @org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery@ to know if the view is a representation link or a normal note. +* <span class="label label-success">Added</span> The query @isRepresentationLinkBroken()@ has been added in @org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery@ to know, for a representation link, if it refers to a deleted representation descriptor. Invocations should be guarded by @isRepresentationLink()@. * <span class="label label-info">Modified</span> The interface @org.eclipse.sirius.diagram.ui.tools.api.figure.ViewNodeContainerFigureDesc@ has been moved to @org.eclipse.sirius.ext.gmf.runtime.gef.ui.figures@ package. * <span class="label label-info">Modified</span> The interface @org.eclipse.sirius.diagram.ui.tools.api.figure.StyledFigure@ has been moved to @org.eclipse.sirius.ext.draw2d.figure@ package. * <span class="label label-info">Modified</span> The interface @org.eclipse.sirius.diagram.ui.tools.api.figure.ITransparentFigure@ has been moved to @org.eclipse.sirius.ext.draw2d.figure@ package. @@ -113,6 +115,8 @@ h4. Migrations * <span class="label label-success">Added</span> A migration participant has been added to convert the serialized xmi:id to the technical id (uid attribut) for Sirius model elements of the .aird files (see "bugzilla #525261":https://bugs.eclipse.org/bugs/show_bug.cgi?id=525261 for more details). The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is _14.1.0.201808300808_. * <span class="label label-success">Added</span> A migration participant has been added to fix diagrams with corrupted Note, Text or Note Attachment (see "bugzilla #539550":https://bugs.eclipse.org/bugs/show_bug.cgi?id=539550 for more details). The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is _14.1.0.201809271200_. * <span class="label label-success">Added</span> A migration participant has been added to fix edge with multiple connector style (see "bugzilla #539944":https://bugs.eclipse.org/bugs/show_bug.cgi?id=539944 for more details). The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is _14.1.0.201810051700_. +* <span class="label label-success">Added</span> A migration participant has been added to update existing representation link. (see "bugzilla #533175":https://bugs.eclipse.org/bugs/show_bug.cgi?id=535648 for more details). The corresponding version, stored in attribute version of viewpoint:DAnalysis of the aird file, is _14.1.0.201810111800_. + h2(#sirius6.0.0). Changes in Sirius 6.0.0 diff --git a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html index 2ba0c88a30..8ad64ec096 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html +++ b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.html @@ -1359,7 +1359,8 @@ <em>F2</em>, a slow double click, or by directly starting to enter alpha-numeric text). The only difference between notes and text zones is the visual presentation; notes have a yellow background (by default) and a border which represents a sticky not with a folded top-right corner. </p> <p>A - <em>Representation Link</em> is a special kind of note which references any existing representation in the project. When creating a representation link, a the target representation must be selected from a dialog. The representation link displays the name of the target representation and its icon as the note header. It is possible to navigate to the target representation by double clicking on a representation link. When the targeted representation is deleted, all representation links that reference it are deleted automatically. Just like normal notes, representation links have a text field for free text and can be attached to other elements with the note attachment tool. It is also possible to set a new target representation for an existing representation link by selecting + <em>Representation Link</em> is a special kind of note which references any existing representation in the project. When creating a representation link, a the target representation must be selected from a dialog. The representation link displays the name of the target representation and its icon as the note header. It is possible to navigate to the target representation by double clicking on a representation link. When the targeted representation is deleted, representation links that reference it are + <strong>not</strong> deleted. Instead, such representation links show the text “Broken representation link” in their header, and have a small red cross as their icon. Just like normal notes, representation links have a text field for free text and can be attached to other elements with the note attachment tool. It is also possible to set a new target representation for an existing representation link by selecting <em>Set target representation ...</em> from the representation link’s context menu. </p> <p> diff --git a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile index 494a9f8d07..5407da9bf7 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile +++ b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile @@ -834,7 +834,7 @@ p(#notes). __Notes, Representation Links and Note attachments__. All Sirius diag _Notes_, _Representation Links_ and _Text_ elements are created in a similar way: either a single click somewhere on the diagram (which creates an element with a default size), or a click-drag to create the element with a custom initial size. Once created, one can edit the text inside the note or text zone usual the standard "direct edit" behavior (_F2_, a slow double click, or by directly starting to enter alpha-numeric text). The only difference between notes and text zones is the visual presentation; notes have a yellow background (by default) and a border which represents a sticky not with a folded top-right corner. -A _Representation Link_ is a special kind of note which references any existing representation in the project. When creating a representation link, a the target representation must be selected from a dialog. The representation link displays the name of the target representation and its icon as the note header. It is possible to navigate to the target representation by double clicking on a representation link. When the targeted representation is deleted, all representation links that reference it are deleted automatically. Just like normal notes, representation links have a text field for free text and can be attached to other elements with the note attachment tool. It is also possible to set a new target representation for an existing representation link by selecting _Set target representation ..._ from the representation link's context menu. +A _Representation Link_ is a special kind of note which references any existing representation in the project. When creating a representation link, a the target representation must be selected from a dialog. The representation link displays the name of the target representation and its icon as the note header. It is possible to navigate to the target representation by double clicking on a representation link. When the targeted representation is deleted, representation links that reference it are *not* deleted. Instead, such representation links show the text "Broken representation link" in their header, and have a small red cross as their icon. Just like normal notes, representation links have a text field for free text and can be attached to other elements with the note attachment tool. It is also possible to set a new target representation for an existing representation link by selecting _Set target representation ..._ from the representation link's context menu. _Note attachments_ can be created to link either notes or text zone to diagram elements (including other notes and text attachments). To create an attachment, activate the tool and then click once on the source element and once on the target element. You can also click and drag from the source to the target elements. diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/do_not_migrate/linkNote/linkNote.ecore b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/do_not_migrate/linkNote/linkNote.ecore new file mode 100644 index 0000000000..06f4c23f9d --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/do_not_migrate/linkNote/linkNote.ecore @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="root"> + <eClassifiers xsi:type="ecore:EClass" name="NewEClass1"/> + <eClassifiers xsi:type="ecore:EDataType" name="NewDataType1" instanceTypeName="newDataType1"/> +</ecore:EPackage>
\ No newline at end of file diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/do_not_migrate/linkNote/representations.aird b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/do_not_migrate/linkNote/representations.aird new file mode 100644 index 0000000000..b0a02f5a20 --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/migration/do_not_migrate/linkNote/representations.aird @@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="UTF-8"?> +<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:diagram="http://www.eclipse.org/sirius/diagram/1.1.0" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:notation="http://www.eclipse.org/gmf/runtime/1.0.2/notation" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:viewpoint="http://www.eclipse.org/sirius/1.1.0" xsi:schemaLocation="http://www.eclipse.org/sirius/description/1.1.0 http://www.eclipse.org/sirius/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description http://www.eclipse.org/sirius/diagram/description/style/1.1.0 http://www.eclipse.org/sirius/diagram/1.1.0#//description/style"> + <viewpoint:DAnalysis xmi:id="_VNhyoMxjEeivgLhNuiGgag" selectedViews="_V3NBwMxjEeivgLhNuiGgag" version="12.1.2.201804131029"> + <semanticResources>linkNote.ecore</semanticResources> + <ownedViews xmi:type="viewpoint:DView" xmi:id="_V3NBwMxjEeivgLhNuiGgag"> + <viewpoint xmi:type="description:Viewpoint" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']"/> + <ownedRepresentationDescriptors xmi:type="viewpoint:DRepresentationDescriptor" xmi:id="_V5sVFcxjEeivgLhNuiGgag" name="root package entities" repPath="#_V4I14MxjEeivgLhNuiGgag"> + <description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']"/> + <target xmi:type="ecore:EPackage" href="linkNote.ecore#/"/> + </ownedRepresentationDescriptors> + <ownedRepresentationDescriptors xmi:type="viewpoint:DRepresentationDescriptor" xmi:id="_lQ69xcxjEeivgLhNuiGgag" name="linkTarget" repPath="#_lQQPYMxjEeivgLhNuiGgag"> + <description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']"/> + <target xmi:type="ecore:EPackage" href="linkNote.ecore#/"/> + </ownedRepresentationDescriptors> + </ownedViews> + </viewpoint:DAnalysis> + <diagram:DSemanticDiagram xmi:id="_V5sVEMxjEeivgLhNuiGgag" name="root package entities" uid="_V4I14MxjEeivgLhNuiGgag"> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_V5sVEcxjEeivgLhNuiGgag" source="DANNOTATION_CUSTOMIZATION_KEY"> + <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_V5sVEsxjEeivgLhNuiGgag"/> + </ownedAnnotationEntries> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_V5sVFsxjEeivgLhNuiGgag" source="GMF_DIAGRAMS"> + <data xmi:type="notation:Diagram" xmi:id="_V5sVF8xjEeivgLhNuiGgag" type="Sirius" element="_V5sVEMxjEeivgLhNuiGgag" measurementUnit="Pixel"> + <children xmi:type="notation:Shape" xmi:id="_dS7zgMxjEeivgLhNuiGgag" type="Note" fontName="Segoe UI" description="Text" fillColor="13369343" transparency="0" lineColor="6737151" lineWidth="1"> + <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_dS7zgcxjEeivgLhNuiGgag" source="specificStyles"> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_dS7zgsxjEeivgLhNuiGgag" key="verticalAlignment" value="8"/> + </eAnnotations> + <children xmi:type="notation:BasicDecorationNode" xmi:id="_dS8akMxjEeivgLhNuiGgag" type="DiagramName"> + <element xsi:nil="true"/> + </children> + <children xmi:type="notation:BasicDecorationNode" xmi:id="_dS9BoMxjEeivgLhNuiGgag" type="Description"> + <element xsi:nil="true"/> + </children> + <styles xmi:type="notation:TextStyle" xmi:id="_dS7zg8xjEeivgLhNuiGgag" textAlignment="Center"/> + <styles xmi:type="notation:LineTypeStyle" xmi:id="_dS7zhMxjEeivgLhNuiGgag"/> + <element xsi:nil="true"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_dS7zhcxjEeivgLhNuiGgag" x="48" y="43"/> + </children> + <children xmi:type="notation:Node" xmi:id="_fonRcMxjEeivgLhNuiGgag" type="2003" element="_fnt5kMxjEeivgLhNuiGgag"> + <children xmi:type="notation:Node" xmi:id="_fonRc8xjEeivgLhNuiGgag" type="5007"/> + <children xmi:type="notation:Node" xmi:id="_fonRdMxjEeivgLhNuiGgag" type="7004"> + <styles xmi:type="notation:SortingStyle" xmi:id="_fonRdcxjEeivgLhNuiGgag"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_fonRdsxjEeivgLhNuiGgag"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_fonRccxjEeivgLhNuiGgag" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_fonRcsxjEeivgLhNuiGgag" x="228" y="51"/> + </children> + <children xmi:type="notation:Node" xmi:id="_gL8oAMxjEeivgLhNuiGgag" type="2003" element="_gL2hYMxjEeivgLhNuiGgag"> + <children xmi:type="notation:Node" xmi:id="_gL8oA8xjEeivgLhNuiGgag" type="5007"/> + <children xmi:type="notation:Node" xmi:id="_gL9PEMxjEeivgLhNuiGgag" type="7004"> + <styles xmi:type="notation:SortingStyle" xmi:id="_gL9PEcxjEeivgLhNuiGgag"/> + <styles xmi:type="notation:FilteringStyle" xmi:id="_gL9PEsxjEeivgLhNuiGgag"/> + </children> + <styles xmi:type="notation:ShapeStyle" xmi:id="_gL8oAcxjEeivgLhNuiGgag" fontName="Segoe UI" fontHeight="8"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_gL8oAsxjEeivgLhNuiGgag" x="396" y="36"/> + </children> + <children xmi:type="notation:Shape" xmi:id="_mslqgMxjEeivgLhNuiGgag" type="Note" element="_lQ69xcxjEeivgLhNuiGgag" fontName="Segoe UI" description="Text" fillColor="13369343" transparency="0" lineColor="6737151" lineWidth="1"> + <eAnnotations xmi:type="ecore:EAnnotation" xmi:id="_mslqgcxjEeivgLhNuiGgag" source="specificStyles"> + <details xmi:type="ecore:EStringToStringMapEntry" xmi:id="_mslqgsxjEeivgLhNuiGgag" key="verticalAlignment" value="8"/> + </eAnnotations> + <children xmi:type="notation:BasicDecorationNode" xmi:id="_mslqh8xjEeivgLhNuiGgag" type="DiagramName"/> + <children xmi:type="notation:BasicDecorationNode" xmi:id="_mslqiMxjEeivgLhNuiGgag" type="Description"/> + <styles xmi:type="notation:TextStyle" xmi:id="_mslqg8xjEeivgLhNuiGgag" textAlignment="Center"/> + <styles xmi:type="notation:LineTypeStyle" xmi:id="_mslqhMxjEeivgLhNuiGgag"/> + <layoutConstraint xmi:type="notation:Bounds" xmi:id="_mslqhcxjEeivgLhNuiGgag" x="72" y="180"/> + </children> + <styles xmi:type="notation:DiagramStyle" xmi:id="_V5sVGMxjEeivgLhNuiGgag"/> + </data> + </ownedAnnotationEntries> + <ownedDiagramElements xmi:type="diagram:DNodeList" xmi:id="_fnt5kMxjEeivgLhNuiGgag" name="NewEClass1" tooltipText="root.NewEClass1"> + <target xmi:type="ecore:EClass" href="linkNote.ecore#//NewEClass1"/> + <semanticElements xmi:type="ecore:EClass" href="linkNote.ecore#//NewEClass1"/> + <arrangeConstraints>KEEP_LOCATION</arrangeConstraints> + <arrangeConstraints>KEEP_SIZE</arrangeConstraints> + <arrangeConstraints>KEEP_RATIO</arrangeConstraints> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_fn3qkMxjEeivgLhNuiGgag" borderSize="1" borderSizeComputationExpression="1" backgroundStyle="GradientTopToBottom"> + <description xmi:type="style:FlatContainerStyleDescription" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EClass']"/> + </ownedDiagramElements> + <ownedDiagramElements xmi:type="diagram:DNodeList" xmi:id="_gL2hYMxjEeivgLhNuiGgag" name="NewDataType1"> + <target xmi:type="ecore:EDataType" href="linkNote.ecore#//NewDataType1"/> + <semanticElements xmi:type="ecore:EDataType" href="linkNote.ecore#//NewDataType1"/> + <arrangeConstraints>KEEP_LOCATION</arrangeConstraints> + <arrangeConstraints>KEEP_SIZE</arrangeConstraints> + <arrangeConstraints>KEEP_RATIO</arrangeConstraints> + <ownedStyle xmi:type="diagram:FlatContainerStyle" xmi:id="_gL2hYcxjEeivgLhNuiGgag" borderSize="1" borderSizeComputationExpression="1" backgroundStyle="GradientTopToBottom" backgroundColor="194,239,255" foregroundColor="255,255,255"> + <description xmi:type="style:FlatContainerStyleDescription" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EDataType']/@style"/> + </ownedStyle> + <actualMapping xmi:type="description_1:ContainerMapping" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer/@containerMappings[name='EC%20EDataType']"/> + </ownedDiagramElements> + <description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']"/> + <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_V5sVFMxjEeivgLhNuiGgag"/> + <activatedLayers xmi:type="description_1:Layer" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer"/> + <activatedLayers xmi:type="description_1:AdditionalLayer" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@additionalLayers[name='Package']"/> + <target xmi:type="ecore:EPackage" href="linkNote.ecore#/"/> + </diagram:DSemanticDiagram> + <diagram:DSemanticDiagram xmi:id="_lQ69wMxjEeivgLhNuiGgag" name="linkTarget" uid="_lQQPYMxjEeivgLhNuiGgag"> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_lQ69wcxjEeivgLhNuiGgag" source="DANNOTATION_CUSTOMIZATION_KEY"> + <data xmi:type="diagram:ComputedStyleDescriptionRegistry" xmi:id="_lQ69wsxjEeivgLhNuiGgag"/> + </ownedAnnotationEntries> + <ownedAnnotationEntries xmi:type="description:AnnotationEntry" xmi:id="_lQ7k0MxjEeivgLhNuiGgag" source="GMF_DIAGRAMS"> + <data xmi:type="notation:Diagram" xmi:id="_lQ7k0cxjEeivgLhNuiGgag" type="Sirius" element="_lQ69wMxjEeivgLhNuiGgag" measurementUnit="Pixel"> + <styles xmi:type="notation:DiagramStyle" xmi:id="_lQ7k0sxjEeivgLhNuiGgag"/> + </data> + </ownedAnnotationEntries> + <description xmi:type="description_1:DiagramDescription" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']"/> + <filterVariableHistory xmi:type="diagram:FilterVariableHistory" xmi:id="_lQ69xMxjEeivgLhNuiGgag"/> + <activatedLayers xmi:type="description_1:Layer" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@defaultLayer"/> + <activatedLayers xmi:type="description_1:AdditionalLayer" href="platform:/plugin/org.eclipse.sirius.sample.ecore.design/description/ecore.odesign#//@ownedViewpoints[name='Design']/@ownedRepresentations[name='Entities']/@additionalLayers[name='Package']"/> + <target xmi:type="ecore:EPackage" href="linkNote.ecore#/"/> + </diagram:DSemanticDiagram> +</xmi:XMI> diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java index 1aacc0046d..7495f0513f 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java @@ -149,6 +149,7 @@ import org.eclipse.sirius.tests.unit.diagram.migration.RepairOnLabelHiddenTest; import org.eclipse.sirius.tests.unit.diagram.migration.RepairOnStyleCustomizationsTest; import org.eclipse.sirius.tests.unit.diagram.migration.RepairTest; import org.eclipse.sirius.tests.unit.diagram.migration.RepairWithActivatedFiltersTest; +import org.eclipse.sirius.tests.unit.diagram.migration.RepresentationLinkMigrationParticipantTest; import org.eclipse.sirius.tests.unit.diagram.migration.RgbValuesEDataTypeMigrationTest; import org.eclipse.sirius.tests.unit.diagram.migration.RunRepairTest; import org.eclipse.sirius.tests.unit.diagram.migration.SetVersionTest; @@ -244,6 +245,7 @@ public class AllCommonPluginTests extends TestCase { suite.addTestSuite(DeleteMultipleConnectorStyleMigrationParticipantTest.class); suite.addTestSuite(RepairGMFbendpointsMigrationParticipantTest.class); suite.addTestSuite(TransientLayerMigrationTest.class); + suite.addTestSuite(RepresentationLinkMigrationParticipantTest.class); suite.addTestSuite(TechnicalUidMigrationTest.class); suite.addTestSuite(ViewWithNullElementMigrationParticipantTest.class); diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/RepresentationLinkMigrationParticipantTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/RepresentationLinkMigrationParticipantTest.java new file mode 100644 index 0000000000..e7a069f27a --- /dev/null +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/RepresentationLinkMigrationParticipantTest.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Felix Dorner <felix.dorner@gmail.com> - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.tests.unit.diagram.migration; + +import java.util.Iterator; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EAnnotation; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; +import org.eclipse.gmf.runtime.diagram.core.util.ViewType; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.business.api.query.DViewQuery; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.business.api.refresh.DiagramCreationUtil; +import org.eclipse.sirius.diagram.ui.business.api.query.ViewQuery; +import org.eclipse.sirius.diagram.ui.business.internal.migration.RepresentationLinkMigrationParticipant; +import org.eclipse.sirius.ecore.extender.tool.api.ModelUtils; +import org.eclipse.sirius.tests.SiriusTestsPlugin; +import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; +import org.eclipse.sirius.viewpoint.DAnalysis; +import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; +import org.eclipse.sirius.viewpoint.DView; +import org.osgi.framework.Version; + +import com.google.common.collect.Iterables; + +/** + * Test that all representation links have the special representation link marker annotation key after migration. + * + * @see RepresentationLinkMigrationParticipant + */ +public class RepresentationLinkMigrationParticipantTest extends SiriusDiagramTestCase { + + private static final String REPRESENTATIONS_FILE_PATH = "/data/unit/migration/do_not_migrate/linkNote/"; + + private static final String MODEL_FILE_NAME = "linkNote.ecore"; + + private static final String REPRESENTATIONS_FILE_NAME = "representations.aird"; + + @Override + protected void setUp() throws Exception { + super.setUp(); + genericSetUp(); + copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, REPRESENTATIONS_FILE_PATH, REPRESENTATIONS_FILE_NAME, MODEL_FILE_NAME); + } + + /** + * Test that the model still needs to be migrated + */ + public void testMigrationIsNeededOnData() { + Version migration = RepresentationLinkMigrationParticipant.MIGRATION_VERSION; + URI uri = URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + REPRESENTATIONS_FILE_PATH + REPRESENTATIONS_FILE_NAME, true); + Version loadedVersion = checkRepresentationFileMigrationStatus(uri, true); + assertTrue("The migration must be required on test data.", loadedVersion == null || migration.compareTo(loadedVersion) > 0); + } + + /** + * Test the migration itself. + * + * @throws Exception + */ + public void testMigration() throws Exception { + + ResourceSet set = new ResourceSetImpl(); + + // Just loading the model will automatically trigger the migration ... + DAnalysis analysis = (DAnalysis) ModelUtils.load(URI.createPlatformResourceURI(TEMPORARY_PROJECT_NAME + "/" + REPRESENTATIONS_FILE_NAME, true), set); + + // .. so that the expected results can now be verified + for (DView dView : analysis.getOwnedViews()) { + for (DDiagram dDiagram : Iterables.filter(new DViewQuery(dView).getLoadedRepresentations(), DDiagram.class)) { + DiagramCreationUtil diagramCreationUtil = new DiagramCreationUtil(dDiagram); + if (diagramCreationUtil.findAssociatedGMFDiagram()) { + Diagram gmfDiagram = diagramCreationUtil.getAssociatedGMFDiagram(); + Iterator<EObject> it = gmfDiagram.eAllContents(); + while (it.hasNext()) { + EObject input = it.next(); + if (input instanceof View) { + View view = (View) input; + boolean marked = false; + EAnnotation annot = view.getEAnnotation(ViewQuery.SPECIFIC_STYLES); + if (annot != null) { + marked = annot.getDetails().containsKey(ViewQuery.REPRESENTATION_LINK_NOTE); + } + // The view is marked if and only if it is a link + // note + if (marked) { + assertTrue("View has representation link annotation, but is not a representation link ", isNoteWithDRepresentationDescriptorTarget(view)); + } + if (isNoteWithDRepresentationDescriptorTarget(view)) { + assertTrue("View is a representation link, but has no representation link annotation", marked); + } + } + } + } + } + } + } + + private boolean isNoteWithDRepresentationDescriptorTarget(View view) { + return ViewType.NOTE.equals(view.getType()) && view.getElement() instanceof DRepresentationDescriptor; + } + +} diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NoteCreationTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NoteCreationTest.java index 260a79245d..a2bc44c379 100644 --- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NoteCreationTest.java +++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/NoteCreationTest.java @@ -23,6 +23,9 @@ import org.eclipse.draw2d.geometry.Point; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.draw2d.text.FlowPage; import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.provider.IItemLabelProvider; +import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.gef.EditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.NoteEditPart; @@ -37,6 +40,8 @@ import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeList2EditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusDescriptionCompartmentEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusDiagramNameCompartmentEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.SiriusNoteEditPart; +import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; +import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; import org.eclipse.sirius.diagram.ui.tools.api.preferences.SiriusDiagramUiPreferencesKeys; import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase; import org.eclipse.sirius.tests.swtbot.support.api.business.UIDiagramRepresentation.ZoomLevel; @@ -48,7 +53,9 @@ import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils; import org.eclipse.sirius.ui.business.api.session.SessionEditorInput; import org.eclipse.sirius.viewpoint.DRepresentationDescriptor; import org.eclipse.sirius.viewpoint.description.Viewpoint; +import org.eclipse.swt.graphics.Image; import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditPart; +import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; import org.eclipse.ui.PartInitException; /** @@ -582,6 +589,12 @@ public class NoteCreationTest extends AbstractSiriusSwtBotGefTestCase { bot.activeEditor().close(); } + private Image getIcon(DRepresentationDescriptor descriptor) { + AdapterFactoryEditingDomain domain = (AdapterFactoryEditingDomain) AdapterFactoryEditingDomain.getEditingDomainFor(descriptor); + IItemLabelProvider provider = (IItemLabelProvider) domain.getAdapterFactory().adapt(descriptor, IItemLabelProvider.class); + return ExtendedImageRegistry.INSTANCE.getImage(provider.getImage(descriptor)); + } + private void validateNote(Point expectedLocation, DRepresentationDescriptor link) throws PartInitException { assertNoteAtLocation(MY_NOTE, expectedLocation); @@ -591,7 +604,8 @@ public class NoteCreationTest extends AbstractSiriusSwtBotGefTestCase { if (link != null) { SWTBotGefEditPart note = editor.selectedEditParts().get(0); - validateDiagramNameCompartment(note, link.getName()); + + validateDiagramNameCompartment(note, link.getName(), getIcon(link)); /* Doubleclick must open the target representation */ validateLinkDoubleclick(link); @@ -606,7 +620,7 @@ public class NoteCreationTest extends AbstractSiriusSwtBotGefTestCase { note = editor.getEditPart(MY_NOTE).parent().select(); /* The header must have been updated to the other target name */ - validateDiagramNameCompartment(note, otherLink.getName()); + validateDiagramNameCompartment(note, otherLink.getName(), getIcon(otherLink)); /* Doubleclick must now open the other target */ validateLinkDoubleclick(otherLink); @@ -623,27 +637,68 @@ public class NoteCreationTest extends AbstractSiriusSwtBotGefTestCase { TransactionalEditingDomain ted = localSession.getOpenedSession().getTransactionalEditingDomain(); ted.getCommandStack().execute(new RenameRepresentationCommand(ted, link, LINK_TARGET_NEW_NAME)); assertTrue(note.part().isActive()); - validateDiagramNameCompartment(note, LINK_TARGET_NEW_NAME); + validateDiagramNameCompartment(note, LINK_TARGET_NEW_NAME, getIcon(link)); /* - * Delete the target representation, this should delete the note + * When the target representation is deleted, the note label and icon should reflect this. In particular, + * the note is no longer deleted automatically, to avoid locks in collab and to give the user a chance to + * decide what to do with the note text. See also https://bugs.eclipse.org/bugs/show_bug.cgi?id=535648 */ ted.getCommandStack().execute(new DeleteRepresentationCommand(localSession.getOpenedSession(), Collections.singleton(link))); - assertNull(note.part().getParent()); + + validateDiagramNameCompartment(note, DiagramUIPlugin.getPlugin().getString("palettetool.linkNote.deletedLabel"), + DiagramUIPlugin.getPlugin().getImage(DiagramUIPlugin.Implementation.getBundledImageDescriptor(DiagramImagesPath.DELETED_DIAG_ELEM_DECORATOR_ICON))); + + /* + * When the deletion is undone, the note label and icon should flip back to the old state + */ + ted.getCommandStack().undo(); + validateDiagramNameCompartment(note, LINK_TARGET_NEW_NAME, getIcon(link)); } } - private void validateDiagramNameCompartment(SWTBotGefEditPart note, String expectedLabel) { - SiriusDiagramNameCompartmentEditPart namePart = null; + private void validateDiagramNameCompartment(SWTBotGefEditPart note, String expectedLabel, Image expectedIcon) { + + SWTBotGefEditPart namePartBot = null; for (SWTBotGefEditPart child : note.children()) { if (child.part() instanceof SiriusDiagramNameCompartmentEditPart) { - namePart = (SiriusDiagramNameCompartmentEditPart) child.part(); + namePartBot = child; } } - assertNotNull("No name compartment edit part found", namePart); - assertEquals(expectedLabel, namePart.getLabelDelegate().getText()); + + assertNotNull("No name compartment edit part found", namePartBot); + SiriusDiagramNameCompartmentEditPart namePart = (SiriusDiagramNameCompartmentEditPart) namePartBot.part(); + + if (expectedLabel != null) { + bot.waitUntil(new DefaultCondition() { + @Override + public boolean test() throws Exception { + return expectedLabel.equals(namePart.getLabelDelegate().getText()); + } + + @Override + public String getFailureMessage() { + return "LinkNote name label expected: '" + expectedLabel + "' Was: '" + namePart.getLabelDelegate().getText() + "'"; + } + }); + } + + if (expectedIcon != null) { + bot.waitUntil(new DefaultCondition() { + + @Override + public boolean test() throws Exception { + return expectedIcon.equals(namePart.getLabelDelegate().getIcon(0)); + } + + @Override + public String getFailureMessage() { + return "LinkNote name icon expected: '" + expectedIcon + "' Was: '" + namePart.getLabelDelegate().getIcon(0) + "'"; + } + }); + } } private DRepresentationDescriptor getDiagramLinkTarget() { diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java index 1218e986d2..e042d6ea99 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java @@ -30,6 +30,7 @@ import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.sirius.business.api.helper.SiriusUtil; import org.eclipse.sirius.business.api.helper.task.AbstractCommandTask; import org.eclipse.sirius.business.api.query.EObjectQuery; @@ -201,7 +202,7 @@ public abstract class AbstractRepresentationDialectServices implements DialectSe if (isSupported(representationDescriptor)) { DRepresentation representation = representationDescriptor.getRepresentation(); Optional<Resource> resOpt = Optional.ofNullable(representation).map(EObject::eResource); - SiriusUtil.delete(representationDescriptor, session); + EcoreUtil.remove(representationDescriptor); if (representation != null) { SiriusUtil.delete(representation, session); } |
