[548847] Allow activation of extra filters/layers through hyperlinks
Bug: 548847
Change-Id: Iba6ed77f726bfa080366e886674a9d0fbead434c
Signed-off-by: Felix Dorner <felix.dorner@gmail.com>
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/.classpath b/plugins/org.eclipse.amalgam.explorer.activity.ui/.classpath
index 88cb07a..2bd75f1 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/.classpath
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/.classpath
@@ -1,11 +1,11 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
- <accessrules>
- <accessrule kind="accessible" pattern="org/eclipse/sirius/**/internal/**"/>
- </accessrules>
- </classpathentry>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
+ <accessrules>
+ <accessrule kind="accessible" pattern="org/eclipse/sirius/**/internal/**"/>
+ </accessrules>
+ </classpathentry>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.amalgam.explorer.activity.ui/.settings/org.eclipse.jdt.core.prefs
index c537b63..0c68a61 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/.settings/org.eclipse.jdt.core.prefs
@@ -1,7 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
-org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.6
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.amalgam.explorer.activity.ui/META-INF/MANIFEST.MF
index 2e86e5a..0814658 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/META-INF/MANIFEST.MF
@@ -21,7 +21,7 @@
org.eclipse.sirius.ext.base,
org.eclipse.sirius.diagram,
org.eclipse.sirius.diagram.ui
-Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.amalgam.explorer.activity.ui,
org.eclipse.amalgam.explorer.activity.ui.api.actions,
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/hyperlinkadapter/AbstractNewDiagramHyperlinkAdapter.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/hyperlinkadapter/AbstractNewDiagramHyperlinkAdapter.java
index c8ea192..d10bb51 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/hyperlinkadapter/AbstractNewDiagramHyperlinkAdapter.java
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/api/hyperlinkadapter/AbstractNewDiagramHyperlinkAdapter.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.amalgam.explorer.activity.ui.api.hyperlinkadapter;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
@@ -23,6 +24,10 @@
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.sirius.business.api.dialect.DialectManager;
import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.diagram.business.api.componentization.DiagramComponentizationManager;
+import org.eclipse.sirius.diagram.description.DiagramDescription;
+import org.eclipse.sirius.diagram.description.Layer;
+import org.eclipse.sirius.diagram.description.filter.FilterDescription;
import org.eclipse.sirius.viewpoint.description.RepresentationDescription;
import org.eclipse.sirius.viewpoint.description.Viewpoint;
import org.eclipse.ui.forms.events.HyperlinkEvent;
@@ -58,12 +63,15 @@
EObject modelElement = project;
RepresentationDescription diagramRepresentation = getDiagramRepresentation(session, modelElement);
// Preconditions
+
if ((null == diagramRepresentation)
|| !DialectManager.INSTANCE.canCreate(modelElement, diagramRepresentation)) {
flag[0] = false;
} else {
+ Collection<Layer> layers = getExtraLayers(session, diagramRepresentation);
+ Collection<FilterDescription> filters = getExtraFilters(session, diagramRepresentation);
NewRepresentationAction newDiagramAction = new NewRepresentationAction(diagramRepresentation,
- modelElement, session);
+ modelElement, session, false, true, layers, filters);
newDiagramAction.run();
}
}
@@ -137,6 +145,46 @@
*/
public abstract String getRepresentationName();
+ private Collection<Layer> getExtraLayers(Session session, RepresentationDescription desc){
+ Collection<Layer> extra = new ArrayList<>();
+ if (desc instanceof DiagramDescription)
+ for (Layer l : new DiagramComponentizationManager().getAllLayers(session.getSelectedViewpoints(false), (DiagramDescription) desc)) {
+ if(getExtraLayerNames().contains(l.getName())){
+ extra.add(l);
+ }
+ }
+ return extra;
+ }
+
+ private Collection<FilterDescription> getExtraFilters(Session session,
+ RepresentationDescription desc) {
+ Collection<FilterDescription> extra = new ArrayList<>();
+ if (desc instanceof DiagramDescription) {
+ for (FilterDescription d : ((DiagramDescription) desc).getFilters()) {
+ if(getExtraFilterNames().contains(d.getName())){
+ extra.add(d);
+ }
+ }
+ }
+ return extra;
+ }
+
+ /**
+ * A collection of layer names that should be activated on the new diagram, in addition to the default layers.
+ * @return
+ */
+ protected Collection<String> getExtraLayerNames(){
+ return Collections.emptyList();
+ }
+
+ /**
+ * A collection of filter names that should be activated on the new diagram, in addition to the default filters.
+ * @return
+ */
+ protected Collection<String> getExtraFilterNames(){
+ return Collections.emptyList();
+ }
+
/**
* @see org.eclipse.amalgam.explorer.activity.ui.api.hyperlinkadapter.IRepresentationProvider#getRepresentationNames()
*/
diff --git a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/viewer/diagram/actions/NewRepresentationAction.java b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/viewer/diagram/actions/NewRepresentationAction.java
index 9a65e67..aff1cea 100644
--- a/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/viewer/diagram/actions/NewRepresentationAction.java
+++ b/plugins/org.eclipse.amalgam.explorer.activity.ui/src/org/eclipse/amalgam/explorer/activity/ui/internal/viewer/diagram/actions/NewRepresentationAction.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.eclipse.amalgam.explorer.activity.ui.internal.viewer.diagram.actions;
+import java.util.Collection;
+import java.util.Collections;
+
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.ecore.EObject;
@@ -24,6 +27,9 @@
import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
import org.eclipse.sirius.common.tools.api.util.StringUtil;
+import org.eclipse.sirius.diagram.DDiagram;
+import org.eclipse.sirius.diagram.description.Layer;
+import org.eclipse.sirius.diagram.description.filter.FilterDescription;
import org.eclipse.sirius.table.metamodel.table.description.CrossTableDescription;
import org.eclipse.sirius.table.metamodel.table.description.EditionTableDescription;
import org.eclipse.sirius.table.metamodel.table.provider.TableUIPlugin;
@@ -50,6 +56,8 @@
protected boolean forceDefaultName;
protected boolean openRepresentation;
+ protected final Collection<Layer> extraLayers;
+ private Collection<FilterDescription> extraFilters;
/**
* Constructs an action allowing to create new representations.
@@ -65,6 +73,11 @@
this(description, selectedEObject, session, false, true);
}
+ public NewRepresentationAction(RepresentationDescription description, EObject selectedEObject,
+ Session session, boolean forceDefaultName, boolean openRepresentation) {
+ this(description, selectedEObject, session, forceDefaultName, openRepresentation, Collections.emptyList(), Collections.emptyList());
+ }
+
/**
* Constructs an action allowing to create new representations.
*
@@ -76,9 +89,11 @@
* The current session.
* @param forceDefaultName
* @param openRepresentation
+ * @param extraLayers
+ * @param extraFilters
*/
public NewRepresentationAction(RepresentationDescription description, EObject selectedEObject,
- Session session, boolean forceDefaultName, boolean openRepresentation) {
+ Session session, boolean forceDefaultName, boolean openRepresentation, Collection<Layer> extraLayers, Collection<FilterDescription> extraFilters) {
super(description.getName());
String label = description.getLabel();
if ((null != label) && (label.length() > 1)) {
@@ -108,6 +123,8 @@
this.session = session;
this.forceDefaultName = forceDefaultName;
this.openRepresentation = openRepresentation;
+ this.extraLayers = extraLayers;
+ this.extraFilters = extraFilters;
}
/**
@@ -141,7 +158,7 @@
// Do not call ToggleCanonicalRefresh anymore since DoReMi 4.18.
// Executes the NewRepresentationCommand.
NewRepresentationCommand command = new NewRepresentationCommand(defaultName, selectedEObject, description,
- session);
+ session, extraLayers, extraFilters);
TransactionUtil.getEditingDomain(selectedEObject).getCommandStack().execute(command);
if (null != command.getRepresentation()) {
@@ -188,6 +205,8 @@
private EObject eObject;
private RepresentationDescription repDescription;
private Session currentSession;
+ private Collection<Layer> extraLayers;
+ private Collection<FilterDescription> extraFilters;
/**
* Constructs the command allowing to create a new representation.
@@ -200,14 +219,18 @@
* The current representation description.
* @param session
* The current session.
+ * @param extraLayers
+ * Extra layers to activate on the new representation
*/
public NewRepresentationCommand(String newName, EObject eObject,
- RepresentationDescription repDescription, Session session) {
+ RepresentationDescription repDescription, Session session, Collection<Layer> extraLayers, Collection<FilterDescription> extraFilters) {
super(TransactionUtil.getEditingDomain(eObject));
this.newName = newName;
this.eObject = eObject;
this.repDescription = repDescription;
this.currentSession = session;
+ this.extraLayers = extraLayers;
+ this.extraFilters = extraFilters;
}
/**
@@ -249,6 +272,12 @@
representation = DialectManager.INSTANCE.createRepresentation(newName, eObject, repDescription,
currentSession, monitor);
+
+ if (representation instanceof DDiagram) {
+ ((DDiagram) representation).getActivatedLayers().addAll(extraLayers);
+ ((DDiagram) representation).getActivatedFilters().addAll(extraFilters);
+ }
+
}
}
}
\ No newline at end of file