Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Fasani2017-06-15 14:11:31 +0000
committerLaurent Fasani2017-07-07 15:50:01 +0000
commita092e6add8148cfeb3998ab7f5a9e31a3fcefccd (patch)
tree79eeafdddd4290432b7e53c5c6ae5236b62b46f5
parentcd18b3692fd9ff990108e17076dcd99d6e02e070 (diff)
downloadorg.eclipse.sirius-a092e6add8148cfeb3998ab7f5a9e31a3fcefccd.tar.gz
org.eclipse.sirius-a092e6add8148cfeb3998ab7f5a9e31a3fcefccd.tar.xz
org.eclipse.sirius-a092e6add8148cfeb3998ab7f5a9e31a3fcefccd.zip
[516669] Simplify code to manage DRepresentationDescriptor
* The code that get DRepresentationDescriptor does not need to rely on dialect specificities. * Consequently the following methods are moved from DialectServices to DialectManager - getRepresentationDescriptors(EObject , Session ) - getAllRepresentationDescriptors(Session ) - getRepresentationDescriptors(RepresentationDescription , Session ) The implementation of these methods in DialectManagerImpl is changed to not rely on DialectServices Bug: 516669 Change-Id: I692a0d414e9997dd999ee9903bb99900de2b813f Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java43
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectManager.java43
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectServices.java33
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/danalysis/DAnalysisSession.java45
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/DialectManagerImpl.java31
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionServicesImpl.java61
6 files changed, 79 insertions, 177 deletions
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 3d9f92304b..c06a89ba8f 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, 2016 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2009, 2017 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
@@ -155,24 +155,6 @@ public abstract class AbstractRepresentationDialectServices implements DialectSe
}
@Override
- public Collection<DRepresentationDescriptor> getRepresentationDescriptors(EObject semantic, Session session) {
- return getRepresentationDescriptors(session, CustomDataConstants.DREPRESENTATION_DESCRIPTOR, semantic);
- }
-
- @Override
- public Collection<DRepresentationDescriptor> getAllRepresentationDescriptors(Session session) {
- return getRepresentationDescriptors(session, CustomDataConstants.DREPRESENTATION_DESCRIPTOR, null);
- }
-
- @Override
- public Collection<DRepresentationDescriptor> getRepresentationDescriptors(RepresentationDescription representationDescription, Session session) {
- return getRepresentationDescriptors(session, CustomDataConstants.DREPRESENTATION_DESCRIPTOR_FROM_DESCRIPTION, representationDescription);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
public boolean canRefresh(DRepresentation representation) {
return isSupported(representation) && areRequiredViewpointsSelected(representation);
}
@@ -321,29 +303,6 @@ public abstract class AbstractRepresentationDialectServices implements DialectSe
}
/**
- * Finds all the supported representation descriptors in a session which have the specified key/value pair in their
- * custom data.
- *
- * @param session
- * the session in which to look for representation descriptors.
- * @param key
- * the key to look for in the representation descriptors' custom data.
- * @param value
- * the value associated to the key in the representation descriptors's custom data.
- * @return all the supported representation descriptors in a session which have the specified key/value pair in
- * their custom data.
- */
- protected Collection<DRepresentationDescriptor> getRepresentationDescriptors(Session session, String key, EObject value) {
- Collection<DRepresentationDescriptor> reps = Lists.newArrayList();
- for (EObject repDescriptor : session.getServices().getCustomData(key, value)) {
- if (repDescriptor instanceof DRepresentationDescriptor && isSupported(((DRepresentationDescriptor) repDescriptor).getRepresentation())) {
- reps.add((DRepresentationDescriptor) repDescriptor);
- }
- }
- return reps;
- }
-
- /**
* Return all RepresentationDescription available in the specified viewpoint the user might use to create a new
* DRepresentation.
*
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectManager.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectManager.java
index 621c2ab4b6..e4748162ee 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectManager.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2014 THALES GLOBAL SERVICES and others.
+ * Copyright (c) 2007, 2017 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
@@ -10,10 +10,17 @@
*******************************************************************************/
package org.eclipse.sirius.business.api.dialect;
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.sirius.business.api.session.Session;
import org.eclipse.sirius.business.internal.dialect.DialectManagerImpl;
+import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
+import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
/**
- * Instance managing the dialects.
+ * Instance managing the dialects. </br>
+ * This interface must not be implemented by clients.
*
* @author cbrun
*
@@ -49,4 +56,36 @@ public interface DialectManager extends DialectServices {
* dialect to disable.
*/
void disableDialect(Dialect dialect);
+
+ /**
+ * Return the representations, of the given session, whose target is the given {@code semantic}.</br>
+ * This methods will load all the targeted representations.
+ *
+ * @param semantic
+ * targeted semantic element.
+ * @param session
+ * the current session.
+ * @return the list of representation descriptors.
+ */
+ Collection<DRepresentationDescriptor> getRepresentationDescriptors(EObject semantic, Session session);
+
+ /**
+ * Return all the representations of the given session.</br>
+ *
+ * @param session
+ * the current session.
+ * @return the list of representation descriptors.
+ */
+ Collection<DRepresentationDescriptor> getAllRepresentationDescriptors(Session session);
+
+ /**
+ * Return the representations, of the given session, from a description.
+ *
+ * @param representationDescription
+ * the representation description instance
+ * @param session
+ * the current session.
+ * @return the list of representation descriptors.
+ */
+ Collection<DRepresentationDescriptor> getRepresentationDescriptors(RepresentationDescription representationDescription, Session session);
}
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 f65cd8277a..b4f9b10b27 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
@@ -116,37 +116,6 @@ public interface DialectServices {
Collection<DRepresentation> getRepresentations(RepresentationDescription representationDescription, Session session);
/**
- * Return the representation descriptors provided by the dialect.
- *
- * @param semantic
- * targeted semantic element.
- * @param session
- * the current session.
- * @return the list of representation descriptors contributed by this dialect.
- */
- Collection<DRepresentationDescriptor> getRepresentationDescriptors(EObject semantic, Session session);
-
- /**
- * Return all the representation descriptors provided by the dialect.
- *
- * @param session
- * the current session.
- * @return the list of representation descriptors contributed by this dialect.
- */
- Collection<DRepresentationDescriptor> getAllRepresentationDescriptors(Session session);
-
- /**
- * Return the representation descriptors provided by the dialect from a description.
- *
- * @param representationDescription
- * the representation description instance
- * @param session
- * the current session.
- * @return the list of representation descriptors contributed by this dialect.
- */
- Collection<DRepresentationDescriptor> getRepresentationDescriptors(RepresentationDescription representationDescription, Session session);
-
- /**
* Refresh the actual representation description used for the specified representation when the context changes.
*
* @param representation
@@ -208,7 +177,7 @@ public interface DialectServices {
* @see DialectServices#getRequiredViewpoints(DRepresentation)
*/
boolean canRefresh(DRepresentation representation);
-
+
/**
* Tell whether the dialect is able to create a representation from the given representation description and the
* semantic object.
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/danalysis/DAnalysisSession.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/danalysis/DAnalysisSession.java
index dadaeed248..af57b70224 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/danalysis/DAnalysisSession.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/danalysis/DAnalysisSession.java
@@ -50,22 +50,17 @@ public interface DAnalysisSession extends Session {
void setAnalysisSelector(DAnalysisSelector selector);
/**
- * Adds the given representation descriptor to the given analysis. The
- * corresponding representation is moved as root object into the resource of
- * the target DAnalysis.
+ * Adds the given representation descriptor to the given analysis. The corresponding representation is moved as root
+ * object into the resource of the target DAnalysis.
* <p>
- * If the given representation descriptor is already in the given analysis
- * then the operation has no effect.
+ * If the given representation descriptor is already in the given analysis then the operation has no effect.
* </p>
- * The models references of the newContainer are updated according to the
- * new representation descriptor.
+ * The models references of the newContainer are updated according to the new representation descriptor.
*
* @param newDAnalysisContainer
- * the new container of the representation descriptor(must not be
- * <code>null</code>).
+ * the new container of the representation descriptor(must not be <code>null</code>).
* @param repDescriptor
- * corresponds to the representation to move (must not be
- * <code>null</code>).
+ * corresponds to the representation to move (must not be <code>null</code>).
*/
void moveRepresentation(DAnalysis newDAnalysisContainer, DRepresentationDescriptor repDescriptor);
@@ -73,8 +68,7 @@ public interface DAnalysisSession extends Session {
* Add a referenced analysis.
*
* <p>
- * If the given analysis is already in the referenced analysis then the
- * operation has no effect.
+ * If the given analysis is already in the referenced analysis then the operation has no effect.
* </p>
* <p>
* The main analysis will reference the given one.
@@ -89,8 +83,7 @@ public interface DAnalysisSession extends Session {
* Add a referenced analysis.
*
* <p>
- * If the given analysis is already in the referenced analysis then the
- * operation has no effect.
+ * If the given analysis is already in the referenced analysis then the operation has no effect.
* </p>
*
*
@@ -98,8 +91,7 @@ public interface DAnalysisSession extends Session {
* the analysis to reference (must not be <code>null</code> ).
*
* @param referencers
- * the analysis on which the reference is added (must not be
- * <code>null</code>).
+ * the analysis on which the reference is added (must not be <code>null</code>).
*/
void addReferencedAnalysis(DAnalysis analysis, Collection<DAnalysis> referencers);
@@ -107,22 +99,19 @@ public interface DAnalysisSession extends Session {
* Remove a referenced analysis.
*
* <p>
- * If the given analysis is not in the referenced analysis then the
- * operation has no effect.
+ * If the given analysis is not in the referenced analysis then the operation has no effect.
* </p>
*
*
* @param analysis
- * the referenced analysis to remove (must not be
- * <code>null</code> ).
+ * the referenced analysis to remove (must not be <code>null</code> ).
*
* @since 0.9.0
*/
void removeReferencedAnalysis(DAnalysis analysis);
/**
- * Clients should call that method when a control action has been applied on
- * a semantic model.
+ * Clients should call that method when a control action has been applied on a semantic model.
*
* @param newControlled
* the newly controlled resource.
@@ -130,8 +119,7 @@ public interface DAnalysisSession extends Session {
void notifyControlledModel(Resource newControlled);
/**
- * Clients should call that method when an uncontrol action has been applied
- * on an EObject.
+ * Clients should call that method when an uncontrol action has been applied on an EObject.
*
* @param uncontrolled
* the uncontrolled element.
@@ -155,4 +143,11 @@ public interface DAnalysisSession extends Session {
* the current analysis.
*/
void removeAdaptersOnAnalysis(DAnalysis analysis);
+
+ /**
+ * Return all valid(i.e. not null) owned and referenced analyses.
+ *
+ * @return all valid(i.e. not null) owned and referenced analyses.
+ */
+ Collection<DAnalysis> allAnalyses();
}
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 ddba79fb20..f35ac0e723 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
@@ -15,10 +15,10 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
@@ -35,8 +35,10 @@ import org.eclipse.sirius.business.api.dialect.description.IInterpretedExpressio
import org.eclipse.sirius.business.api.helper.task.AbstractCommandTask;
import org.eclipse.sirius.business.api.query.EObjectQuery;
import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSession;
import org.eclipse.sirius.business.internal.movida.Movida;
import org.eclipse.sirius.common.tools.api.util.EclipseUtil;
+import org.eclipse.sirius.common.tools.api.util.EqualityHelper;
import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor;
import org.eclipse.sirius.ext.base.Option;
import org.eclipse.sirius.ext.base.Options;
@@ -284,13 +286,11 @@ public class DialectManagerImpl implements DialectManager {
@Override
public Collection<DRepresentationDescriptor> getRepresentationDescriptors(EObject semantic, Session session) {
- final Collection<DRepresentationDescriptor> repDescriptors = new ArrayList<DRepresentationDescriptor>();
+ Collection<DRepresentationDescriptor> repDescriptors = null;
if (semantic != null) {
- return findAllRepresentationDescriptors(semantic, session);
+ repDescriptors = findAllRepresentationDescriptors(semantic, session);
} else {
- for (final Dialect dialect : dialects.values()) {
- repDescriptors.addAll(dialect.getServices().getRepresentationDescriptors(semantic, session));
- }
+ repDescriptors = getAllRepresentationDescriptors(session);
}
return repDescriptors;
}
@@ -309,20 +309,21 @@ public class DialectManagerImpl implements DialectManager {
@Override
public Collection<DRepresentationDescriptor> getAllRepresentationDescriptors(Session session) {
- final Collection<DRepresentationDescriptor> reps = new ArrayList<DRepresentationDescriptor>();
- for (final Dialect dialect : dialects.values()) {
- reps.addAll(dialect.getServices().getAllRepresentationDescriptors(session));
+ List<DRepresentationDescriptor> foundRepDescs = new ArrayList<>();
+ if (session instanceof DAnalysisSession) {
+ foundRepDescs = ((DAnalysisSession) session).allAnalyses().stream().flatMap(a -> a.getOwnedViews().stream()).flatMap(v -> v.getOwnedRepresentationDescriptors().stream())
+ .collect(Collectors.toList());
}
- return reps;
+ return foundRepDescs;
}
@Override
public Collection<DRepresentationDescriptor> getRepresentationDescriptors(RepresentationDescription representationDescription, Session session) {
- final Collection<DRepresentationDescriptor> reps = new LinkedHashSet<DRepresentationDescriptor>();
- for (final Dialect dialect : dialects.values()) {
- reps.addAll(dialect.getServices().getRepresentationDescriptors(representationDescription, session));
- }
- return reps;
+
+ List<DRepresentationDescriptor> repDescriptors = getAllRepresentationDescriptors(session).stream().filter(repDesc -> {
+ return EqualityHelper.areEquals(repDesc.getDescription(), representationDescription);
+ }).collect(Collectors.toList());
+ return repDescriptors;
}
@Override
diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionServicesImpl.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionServicesImpl.java
index 5365791d93..e1ba3e9678 100644
--- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionServicesImpl.java
+++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/session/danalysis/DAnalysisSessionServicesImpl.java
@@ -138,12 +138,8 @@ public class DAnalysisSessionServicesImpl implements SessionService, DAnalysisSe
datas.addAll(getGMFDiagramsData(associatedInstance, resources));
} else if (CustomDataConstants.DREPRESENTATION.equals(key)) {
datas = getRepresentationData(associatedInstance, analysisAndReferenced);
- } else if (CustomDataConstants.DREPRESENTATION_DESCRIPTOR.equals(key)) {
- datas = getRepresentationDescriptorData(associatedInstance, analysisAndReferenced);
} else if (CustomDataConstants.DREPRESENTATION_FROM_DESCRIPTION.equals(key)) {
datas = getRepresentationFromDescData(associatedInstance, analysisAndReferenced);
- } else if (CustomDataConstants.DREPRESENTATION_DESCRIPTOR_FROM_DESCRIPTION.equals(key)) {
- datas = getRepresentationDescriptorsFromDescData(associatedInstance, analysisAndReferenced);
} else if (CustomDataConstants.DFEATUREEXTENSION.equals(key)) {
datas = getFeatureExtensionsData(associatedInstance, resources);
} else {
@@ -209,46 +205,6 @@ public class DAnalysisSessionServicesImpl implements SessionService, DAnalysisSe
return runnable.getResult();
}
- private Collection<EObject> getRepresentationDescriptorData(final EObject associatedInstance, final Collection<DAnalysis> analysisAndReferenced) {
- RunnableWithResult<Collection<EObject>> runnable = new RunnableWithResult.Impl<Collection<EObject>>() {
- @Override
- public void run() {
- Collection<EObject> datas = new ArrayList<EObject>();
- for (DAnalysis analysis : analysisAndReferenced) {
- for (final DView view : analysis.getOwnedViews()) {
- final Iterator<DRepresentationDescriptor> it = view.getOwnedRepresentationDescriptors().iterator();
- while (it.hasNext()) {
- final DRepresentationDescriptor rep = it.next();
- final EObject element = rep.getTarget();
- if (element != null && element == associatedInstance) {
- datas.add(rep);
- } else if (associatedInstance == null) {
- datas.add(rep);
- }
- }
- }
- }
- setResult(datas);
- }
-
- };
- if (associatedInstance != null) {
- TransactionalEditingDomain domain = TransactionUtil.getEditingDomain(associatedInstance);
- if (domain != null) {
- try {
- TransactionUtil.runExclusive(domain, runnable);
- } catch (InterruptedException e) {
- SiriusPlugin.getDefault().error(e.getLocalizedMessage(), e);
- }
- } else {
- runnable.run();
- }
- } else {
- runnable.run();
- }
- return runnable.getResult();
- }
-
private Collection<EObject> getRepresentationFromDescData(final EObject associatedInstance, Collection<DAnalysis> analysisAndReferenced) {
final Collection<EObject> datas = Lists.newArrayList();
for (DAnalysis analysis : analysisAndReferenced) {
@@ -266,23 +222,6 @@ public class DAnalysisSessionServicesImpl implements SessionService, DAnalysisSe
return datas;
}
- private Collection<EObject> getRepresentationDescriptorsFromDescData(final EObject repDescription, Collection<DAnalysis> analysisAndReferenced) {
- final Collection<EObject> datas = Lists.newArrayList();
- for (DAnalysis analysis : analysisAndReferenced) {
- for (final DView view : analysis.getOwnedViews()) {
- final Iterator<DRepresentationDescriptor> it = view.getOwnedRepresentationDescriptors().iterator();
- while (it.hasNext()) {
- final DRepresentationDescriptor repDesc = it.next();
- final RepresentationDescription currentRepresentationDescription = repDesc.getDescription();
- if (EqualityHelper.areEquals(currentRepresentationDescription, repDescription)) {
- datas.add(repDesc);
- }
- }
- }
- }
- return datas;
- }
-
private Collection<EObject> getGMFDiagramsData(final EObject associatedInstance, Collection<Resource> resources) {
final Collection<EObject> datas = Lists.newArrayList();
for (final Resource res : resources) {

Back to the top