Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Fasani2017-06-15 15:20:44 +0000
committerLaurent Fasani2017-07-07 15:54:41 +0000
commitac13ee639a074d0b222debb73c252e28a92a95ba (patch)
tree85fc1311912aa499988f0cdb8acec5f466c552e8
parenta092e6add8148cfeb3998ab7f5a9e31a3fcefccd (diff)
downloadorg.eclipse.sirius-ac13ee639a074d0b222debb73c252e28a92a95ba.tar.gz
org.eclipse.sirius-ac13ee639a074d0b222debb73c252e28a92a95ba.tar.xz
org.eclipse.sirius-ac13ee639a074d0b222debb73c252e28a92a95ba.zip
[516669] Simplify code to manage DRepresentation
* The code that get DRepresentation does not need to rely on dialect specificities. * Consequently the following methods are moved from DialectServices to DialectManager - getRepresentations(EObject , Session ) - getAllRepresentations(Session ) - getRepresentations(RepresentationDescription , Session ) The implementation of these methods in DialectManagerImpl is changed to not rely on DialectServices Bug: 516669 Change-Id: Ifc48b8f8f1bdcf2b50c5af860629bf5074a44fa9 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/AbstractRepresentationDialectServices.java38
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectManager.java34
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectServices.java31
-rw-r--r--plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/DialectManagerImpl.java22
4 files changed, 42 insertions, 83 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 c06a89ba8f..9c8976ad8c 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
@@ -140,21 +140,6 @@ public abstract class AbstractRepresentationDialectServices implements DialectSe
}
@Override
- public Collection<DRepresentation> getRepresentations(EObject semantic, Session session) {
- return getRepresentations(session, CustomDataConstants.DREPRESENTATION, semantic);
- }
-
- @Override
- public Collection<DRepresentation> getAllRepresentations(Session session) {
- return getRepresentations(session, CustomDataConstants.DREPRESENTATION, null);
- }
-
- @Override
- public Collection<DRepresentation> getRepresentations(RepresentationDescription representationDescription, Session session) {
- return getRepresentations(session, CustomDataConstants.DREPRESENTATION_FROM_DESCRIPTION, representationDescription);
- }
-
- @Override
public boolean canRefresh(DRepresentation representation) {
return isSupported(representation) && areRequiredViewpointsSelected(representation);
}
@@ -280,29 +265,6 @@ public abstract class AbstractRepresentationDialectServices implements DialectSe
}
/**
- * Finds all the supported representations in a session which have the specified key/value pair in their custom
- * data.
- *
- * @param session
- * the session in which to look for representations.
- * @param key
- * the key to look for in the representations' custom data.
- * @param value
- * the value associated to the key in the representations' custom data.
- * @return all the supported representations in a session which have the specified key/value pair in their custom
- * data.
- */
- protected Collection<DRepresentation> getRepresentations(Session session, String key, EObject value) {
- Collection<DRepresentation> reps = Lists.newArrayList();
- for (EObject representation : session.getServices().getCustomData(key, value)) {
- if (representation instanceof DRepresentation && isSupported((DRepresentation) representation)) {
- reps.add((DRepresentation) representation);
- }
- }
- 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 e4748162ee..8a16978078 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
@@ -15,6 +15,7 @@ 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.DRepresentation;
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
@@ -88,4 +89,37 @@ public interface DialectManager extends DialectServices {
* @return the list of representation descriptors.
*/
Collection<DRepresentationDescriptor> getRepresentationDescriptors(RepresentationDescription representationDescription, Session session);
+
+ /**
+ * 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 representations.
+ */
+ Collection<DRepresentation> getRepresentations(EObject semantic, Session session);
+
+ /**
+ * Return all the representations of the given session.</br>
+ * This methods will load all the representations.
+ *
+ * @param session
+ * the current session.
+ * @return the list of representations.
+ */
+ Collection<DRepresentation> getAllRepresentations(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 representations.
+ */
+ Collection<DRepresentation> getRepresentations(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 b4f9b10b27..2414a3bdf6 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
@@ -85,37 +85,6 @@ public interface DialectServices {
DRepresentation copyRepresentation(DRepresentation representation, String name, Session session, IProgressMonitor monitor);
/**
- * Return the representations provided by the dialect.
- *
- * @param semantic
- * targeted semantic element.
- * @param session
- * the current session.
- * @return the list of representations contributed by this dialect.
- */
- Collection<DRepresentation> getRepresentations(EObject semantic, Session session);
-
- /**
- * Return all the representations provided by the dialect.
- *
- * @param session
- * the current session.
- * @return the list of representations contributed by this dialect.
- */
- Collection<DRepresentation> getAllRepresentations(Session session);
-
- /**
- * Return the representations provided by the dialect from a description.
- *
- * @param representationDescription
- * the representation description instance
- * @param session
- * the current session.
- * @return the list of representations contributed by this dialect.
- */
- Collection<DRepresentation> getRepresentations(RepresentationDescription representationDescription, Session session);
-
- /**
* Refresh the actual representation description used for the specified representation when the context changes.
*
* @param 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 f35ac0e723..ae326ac202 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
@@ -17,6 +17,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@@ -244,15 +245,13 @@ public class DialectManagerImpl implements DialectManager {
@Override
public synchronized Collection<DRepresentation> getRepresentations(final EObject semantic, final Session session) {
+ Collection<DRepresentation> reps = null;
if (semantic != null) {
- return findAllRepresentations(semantic, session);
+ reps = findAllRepresentations(semantic, session);
} else {
- final Collection<DRepresentation> reps = new ArrayList<DRepresentation>();
- for (final Dialect dialect : dialects.values()) {
- reps.addAll(dialect.getServices().getRepresentations(semantic, session));
- }
- return reps;
+ reps = getAllRepresentations(session);
}
+ return reps;
}
private Collection<DRepresentation> findAllRepresentations(EObject semantic, Session session) {
@@ -268,19 +267,14 @@ public class DialectManagerImpl implements DialectManager {
@Override
public Collection<DRepresentation> getRepresentations(final RepresentationDescription representationDescription, final Session session) {
- final Collection<DRepresentation> reps = new ArrayList<DRepresentation>();
- for (final Dialect dialect : dialects.values()) {
- reps.addAll(dialect.getServices().getRepresentations(representationDescription, session));
- }
+ Collection<DRepresentation> reps = getRepresentationDescriptors(representationDescription, session).stream().map(repDesc -> repDesc.getRepresentation()).filter(Objects::nonNull)
+ .collect(Collectors.toList());
return reps;
}
@Override
public Collection<DRepresentation> getAllRepresentations(final Session session) {
- final Collection<DRepresentation> reps = new ArrayList<DRepresentation>();
- for (final Dialect dialect : dialects.values()) {
- reps.addAll(dialect.getServices().getAllRepresentations(session));
- }
+ Collection<DRepresentation> reps = getAllRepresentationDescriptors(session).stream().map(repDesc -> repDesc.getRepresentation()).filter(Objects::nonNull).collect(Collectors.toList());
return reps;
}

Back to the top