diff options
| author | Esteban Dugueperoux | 2016-02-02 14:44:44 +0000 |
|---|---|---|
| committer | Esteban Dugueperoux | 2016-02-05 14:30:18 +0000 |
| commit | 2baba6572dfa7a4b6614402373286ac29d51de65 (patch) | |
| tree | 8ac8ab6afd6635f47d84f7dd26954476b5eccc49 | |
| parent | f8b08dcbc30c7661aa167ec91c66485ee419a913 (diff) | |
| download | org.eclipse.sirius-2baba6572dfa7a4b6614402373286ac29d51de65.tar.gz org.eclipse.sirius-2baba6572dfa7a4b6614402373286ac29d51de65.tar.xz org.eclipse.sirius-2baba6572dfa7a4b6614402373286ac29d51de65.zip | |
[486330] Don't create/refresh a DRepresentation without needed viewpoint
- Don't create/refresh a DRepresentation if some required viewpoints are
missing.
- For tree/table it is simply the viewpoint containing the related
RepresentationDescription, for diagram it is all viewpoints owning
RepresentationDescription providing layer to the diagram to refresh.
- Consequently DialectServices.getRequiredViewpoints(DRepresentation)
API method has been added to know the required viewpoints to refresh a
representation. And AbstractRepresentationDialectServices.
Bug: 486330
Change-Id: Ib024a659895a7f745a9ca7844d0ad226db2c9665
Signed-off-by: Esteban Dugueperoux <esteban.dugueperoux@obeo.fr>
9 files changed, 124 insertions, 20 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java index abfffd8b7d..f0efdbb7d1 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/business/internal/dialect/DiagramDialectUIServices.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2016 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 @@ -55,6 +55,7 @@ import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.sirius.business.api.dialect.DialectManager; import org.eclipse.sirius.business.api.helper.SiriusResourceHelper; import org.eclipse.sirius.business.api.query.EObjectQuery; import org.eclipse.sirius.business.api.query.URIQuery; @@ -222,14 +223,7 @@ public class DiagramDialectUIServices implements DialectUIServices { } private Set<Viewpoint> activateNeededViewpoints(Session session, DDiagram dDiagram, IProgressMonitor monitor) { - List<Layer> activatedLayers = dDiagram.getActivatedLayers(); - Set<Viewpoint> neededViewpoints = new LinkedHashSet<Viewpoint>(); - for (Layer activatedLayer : activatedLayers) { - if (!activatedLayer.eIsProxy() && activatedLayer.eContainer() != null) { - Viewpoint viewpoint = (Viewpoint) activatedLayer.eContainer().eContainer(); - neededViewpoints.add(viewpoint); - } - } + Set<Viewpoint> neededViewpoints = DialectManager.INSTANCE.getRequiredViewpoints(dDiagram); Set<Viewpoint> selectedViewpoints = new LinkedHashSet<Viewpoint>(); for (Viewpoint viewpoint : session.getSelectedViewpoints(false)) { selectedViewpoints.add(SiriusResourceHelper.getCorrespondingViewpoint(session, viewpoint)); diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java index ff3d6636af..bc6de95ae0 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/dialect/DiagramDialectServices.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2016 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 @@ -12,6 +12,8 @@ package org.eclipse.sirius.diagram.business.internal.dialect; import java.text.MessageFormat; import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -120,7 +122,7 @@ public class DiagramDialectServices extends AbstractRepresentationDialectService @Override public boolean canCreate(final EObject semantic, final RepresentationDescription desc) { boolean result = false; - if (semantic != null && isSupported(desc)) { + if (semantic != null && isSupported(desc) && isRelatedViewpointSelected(new EObjectQuery(semantic).getSession(), desc)) { DiagramDescription diagDesc = (DiagramDescription) desc; ModelAccessor accessor = SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(semantic); if (accessor != null) { @@ -173,7 +175,7 @@ public class DiagramDialectServices extends AbstractRepresentationDialectService monitor.subTask(MessageFormat.format(Messages.DiagramDialectServices_createDiagramMsg, name)); diagram = createRepresentation(name, semantic, description, new SubProgressMonitor(monitor, 2)); if (diagram != null) { - refresh(diagram, new SubProgressMonitor(monitor, 26)); + DialectManager.INSTANCE.refresh(diagram, new SubProgressMonitor(monitor, 26)); if (DisplayMode.NORMAL.equals(DisplayServiceManager.INSTANCE.getMode())) { DisplayServiceManager.INSTANCE.getDisplayService().refreshAllElementsVisibility((DDiagram) diagram); monitor.worked(1); @@ -263,6 +265,22 @@ public class DiagramDialectServices extends AbstractRepresentationDialectService } } + @Override + public Set<Viewpoint> getRequiredViewpoints(DRepresentation representation) { + Set<Viewpoint> requiredViewpoints = new LinkedHashSet<Viewpoint>(); + if (representation instanceof DDiagram) { + DDiagram dDiagram = (DDiagram) representation; + List<Layer> activatedLayers = dDiagram.getActivatedLayers(); + for (Layer activatedLayer : activatedLayers) { + if (!activatedLayer.eIsProxy() && activatedLayer.eContainer() != null) { + Viewpoint viewpoint = (Viewpoint) activatedLayer.eContainer().eContainer(); + requiredViewpoints.add(viewpoint); + } + } + } + return requiredViewpoints; + } + /** * {@inheritDoc} */ diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index b21e91e61c..deacec0505 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -134,6 +134,17 @@ <li><span class="label label-success">Added</span> <code>org.eclipse.sirius.tools.api.command.ui.NoUICallback.askForTypedVariable(List<TypedVariable>, List<String>)</code> has been created. </li> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.business.api.dialect.DialectServices.getRequiredViewpoints(DRepresentation)</code> has been added to have mean to get required viewpoints to use a representation. + </li> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.business.api.dialect.AbstractRepresentationDialectServices.getRequiredViewpoints(DRepresentation)</code> has been added to have a default implementation of + <code>DialectServices.getRequiredViewpoints(DRepresentation)</code> method. + </li> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.business.api.dialect.AbstractRepresentationDialectServices.isRelatedViewpointSelected(Session, RepresentationDescription)</code> protected method has been added to check if a + <code>RepresentationDescription</code> is usable in the context of the specified session. + </li> <li><span class="label label-info">Modified</span> <code>org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable</code> now implements <code>org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription</code>. diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index a08924b392..7491fc46aa 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -30,6 +30,9 @@ h4. Changes in @org.eclipse.sirius@ * <span class="label label-success">Added</span> @org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription@ has been created as tag interface for variables that require user interaction to be valued. * <span class="label label-success">Added</span> @org.eclipse.sirius.tools.api.command.ui.UICallBack.askForTypedVariable(List<TypedVariable>, List<String>)@ has been created. * <span class="label label-success">Added</span> @org.eclipse.sirius.tools.api.command.ui.NoUICallback.askForTypedVariable(List<TypedVariable>, List<String>)@ has been created. +* <span class="label label-success">Added</span> @org.eclipse.sirius.business.api.dialect.DialectServices.getRequiredViewpoints(DRepresentation)@ has been added to have mean to get required viewpoints to use a representation. +* <span class="label label-success">Added</span> @org.eclipse.sirius.business.api.dialect.AbstractRepresentationDialectServices.getRequiredViewpoints(DRepresentation)@ has been added to have a default implementation of @DialectServices.getRequiredViewpoints(DRepresentation)@ method. +* <span class="label label-success">Added</span> @org.eclipse.sirius.business.api.dialect.AbstractRepresentationDialectServices.isRelatedViewpointSelected(Session, RepresentationDescription)@ protected method has been added to check if a @RepresentationDescription@ is usable in the context of the specified session. * <span class="label label-info">Modified</span> @org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable@ now implements @org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription@. * <span class="label label-info">Modified</span> @org.eclipse.sirius.viewpoint.description.tool.AbstractVariable@ has been moved to @org.eclipse.sirius.viewpoint.description.AbstractVariable@. * <span class="label label-info">Modified</span> @org.eclipse.sirius.viewpoint.description.tool.SubVariable@ has been moved to @org.eclipse.sirius.viewpoint.description.SubVariable@. diff --git a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/TableDialectServices.java b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/TableDialectServices.java index 5c3c021470..83c558adb8 100644 --- a/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/TableDialectServices.java +++ b/plugins/org.eclipse.sirius.table/src/org/eclipse/sirius/table/business/internal/dialect/TableDialectServices.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2016 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 @@ -29,6 +29,7 @@ import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.sirius.business.api.dialect.AbstractRepresentationDialectServices; import org.eclipse.sirius.business.api.dialect.description.IInterpretedExpressionQuery; import org.eclipse.sirius.business.api.query.DRepresentationElementQuery; +import org.eclipse.sirius.business.api.query.EObjectQuery; import org.eclipse.sirius.business.api.query.IdentifiedElementQuery; import org.eclipse.sirius.business.api.session.CustomDataConstants; import org.eclipse.sirius.business.api.session.Session; @@ -111,7 +112,7 @@ public class TableDialectServices extends AbstractRepresentationDialectServices @Override public boolean canCreate(final EObject semantic, final RepresentationDescription desc) { boolean result = false; - if (semantic != null && isSupported(desc)) { + if (semantic != null && isSupported(desc) && isRelatedViewpointSelected(new EObjectQuery(semantic).getSession(), desc)) { TableDescription tableDesc = (TableDescription) desc; ModelAccessor accessor = SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(semantic); if (accessor != null) { diff --git a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/TreeDialectServices.java b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/TreeDialectServices.java index f5d3340b15..7c863b9a58 100644 --- a/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/TreeDialectServices.java +++ b/plugins/org.eclipse.sirius.tree/src/org/eclipse/sirius/tree/business/internal/dialect/TreeDialectServices.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2016 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 @@ -215,7 +215,7 @@ public class TreeDialectServices extends AbstractRepresentationDialectServices { @Override public boolean canCreate(EObject semantic, RepresentationDescription desc) { boolean result = false; - if (semantic != null && isSupported(desc)) { + if (semantic != null && isSupported(desc) && isRelatedViewpointSelected(new EObjectQuery(semantic).getSession(), desc)) { TreeDescription treeDesc = (TreeDescription) desc; ModelAccessor accessor = SiriusPlugin.getDefault().getModelAccessorRegistry().getModelAccessor(semantic); if (accessor != null) { 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 e603fedb9b..e6d4678654 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 2016 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 @@ -14,6 +14,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; @@ -27,6 +28,8 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.sirius.business.api.dialect.identifier.RepresentationElementIdentifier; 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; +import org.eclipse.sirius.business.api.query.RepresentationDescriptionQuery; import org.eclipse.sirius.business.api.query.ViewpointQuery; import org.eclipse.sirius.business.api.session.CustomDataConstants; import org.eclipse.sirius.business.api.session.Session; @@ -176,7 +179,53 @@ public abstract class AbstractRepresentationDialectServices implements DialectSe */ @Override public boolean canRefresh(DRepresentation representation) { - return isSupported(representation); + return isSupported(representation) && areRequiredViewpointsSelected(representation); + } + + private boolean areRequiredViewpointsSelected(DRepresentation representation) { + boolean areRequiredViewpointsSelected = false; + if (representation != null) { + Collection<Viewpoint> requiredViewpoints = getRequiredViewpoints(representation); + if (!requiredViewpoints.isEmpty()) { + Session session = new EObjectQuery(representation).getSession(); + if (session != null) { + areRequiredViewpointsSelected = session.getSelectedViewpoints(false).containsAll(requiredViewpoints); + } + } + } + return areRequiredViewpointsSelected; + } + + /** + * Tell if the {@link Viewpoint} owner of the + * {@link RepresentationDescription} is enabled on {@link Session}. + * + * @param session + * the {@link Session} + * @param representationDescription + * a {@link RepresentationDescription} in the context of the + * {@link Session} + * @return true if the {@link Viewpoint} owner of the + * {@link RepresentationDescription} is enabled on {@link Session} + */ + protected boolean isRelatedViewpointSelected(Session session, RepresentationDescription representationDescription) { + boolean isRelatedViewpointSelected = false; + Viewpoint parentViewpoint = new RepresentationDescriptionQuery(representationDescription).getParentViewpoint(); + isRelatedViewpointSelected = session != null && parentViewpoint != null && session.getSelectedViewpoints(false).contains(parentViewpoint); + return isRelatedViewpointSelected; + } + + @Override + public Set<Viewpoint> getRequiredViewpoints(DRepresentation representation) { + Set<Viewpoint> requiredViewpoints = new LinkedHashSet<Viewpoint>(); + RepresentationDescription representationDescription = getDescription(representation); + if (representationDescription != null) { + Viewpoint parentViewpoint = new RepresentationDescriptionQuery(representationDescription).getParentViewpoint(); + if (parentViewpoint != null) { + requiredViewpoints.add(parentViewpoint); + } + } + return requiredViewpoints; } /** diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectServices.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectServices.java index f527947fea..05d7a51441 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectServices.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectServices.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2016 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 @@ -12,6 +12,7 @@ package org.eclipse.sirius.business.api.dialect; import java.util.Collection; import java.util.Map; +import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.common.notify.Notification; @@ -354,4 +355,18 @@ public interface DialectServices { * @since 1.0.0 M6 */ boolean allowsEStructuralFeatureCustomization(EObject element); + + /** + * Tell which {@link Viewpoint viewpoints} are required to do a refresh of + * the specified <code>representation</code>. + * + * NOTE: only available viewpoints are returned. In some cases, the + * Viewpoint of a selected layer might not be available: for example if it + * is not installed. + * + * @param representation + * the specified {@link DRepresentation} + * @return the collection of required {@link Viewpoint viewpoints} + */ + Set<Viewpoint> getRequiredViewpoints(DRepresentation representation); } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/DialectManagerImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/DialectManagerImpl.java index f8fbb32703..d2121dbb9d 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/DialectManagerImpl.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/DialectManagerImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2016 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,6 +17,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; @@ -592,4 +593,16 @@ public class DialectManagerImpl implements DialectManager { } return customizationAllowed; } + + @Override + public Set<Viewpoint> getRequiredViewpoints(DRepresentation representation) { + Set<Viewpoint> requiredViewpoints = null; + for (Dialect dialect : dialects.values()) { + if (dialect.getServices().handles(getDescription(representation))) { + requiredViewpoints = dialect.getServices().getRequiredViewpoints(representation); + break; + } + } + return requiredViewpoints; + } } |
