Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpguilet2017-11-15 13:31:29 +0000
committerPierre Guilet2017-12-22 14:41:35 +0000
commit0258833a4dad378b6d81289e23a198eb5b04c0cb (patch)
treec6b042f2f450039792c1fc8fd3a6c7d7014b9c66
parentcd03e46d980ac53e479321763d54ec9caa07ef31 (diff)
downloadorg.eclipse.sirius-0258833a4dad378b6d81289e23a198eb5b04c0cb.tar.gz
org.eclipse.sirius-0258833a4dad378b6d81289e23a198eb5b04c0cb.tar.xz
org.eclipse.sirius-0258833a4dad378b6d81289e23a198eb5b04c0cb.zip
[517561] Fix double click not opening aird editor for common viewer
- Double click on common viewer's aird files now opens the session editor correctly. - Add tests Bug: 517561 Change-Id: Iba830075674f28538a2c8c09418567568d0d5e69 Signed-off-by: pguilet <pierre.guilet@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF1
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/sessioneditor/SessionEditorOpeningTests.java169
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java3
-rw-r--r--plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java2
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java3
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenEditorDoubleClickListener.java158
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenRepresentationListener.java75
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenRepresentationListenerWithViewpointActivation.java98
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonContentProvider.java27
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/ModelExplorerView.java35
10 files changed, 348 insertions, 223 deletions
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF
index 7d18548b37..6073425e81 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.tests.swtbot/META-INF/MANIFEST.MF
@@ -72,6 +72,7 @@ Export-Package: org.eclipse.sirius.tests.swtbot,
org.eclipse.sirius.tests.swtbot.sequence,
org.eclipse.sirius.tests.swtbot.sequence.condition,
org.eclipse.sirius.tests.swtbot.services,
+ org.eclipse.sirius.tests.swtbot.sessioneditor,
org.eclipse.sirius.tests.swtbot.std,
org.eclipse.sirius.tests.swtbot.suite,
org.eclipse.sirius.tests.swtbot.tabbar,
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/sessioneditor/SessionEditorOpeningTests.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/sessioneditor/SessionEditorOpeningTests.java
new file mode 100644
index 0000000000..346e56c66a
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/sessioneditor/SessionEditorOpeningTests.java
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2017 Obeo
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.tests.swtbot.sessioneditor;
+
+import org.eclipse.sirius.tests.swtbot.Activator;
+import org.eclipse.sirius.tests.swtbot.support.api.AbstractSiriusSwtBotGefTestCase;
+import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource;
+import org.eclipse.sirius.ui.tools.api.views.modelexplorerview.IModelExplorerView;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotPerspective;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Tests that the session editor is opened in various situation.
+ *
+ * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a>
+ *
+ */
+public class SessionEditorOpeningTests extends AbstractSiriusSwtBotGefTestCase {
+
+ private static final String MODEL_FILE = "My.ecore";
+
+ private static final String SESSION_FILE = "My.aird";
+
+ private static final String DATA_UNIT_DIR = "data/unit/edgeCreation/";
+
+ @Override
+ protected void onSetUpBeforeClosingWelcomePage() throws Exception {
+ copyFileToTestProject(Activator.PLUGIN_ID, DATA_UNIT_DIR, MODEL_FILE, SESSION_FILE);
+ sessionAirdResource = new UIResource(designerProject, SESSION_FILE);
+ localSession = designerPerspective.openSessionFromFile(sessionAirdResource, true);
+ }
+
+ /**
+ * Tests that the aird editor is opened when the aird file is double clicked from Model explorer view and when the
+ * project has not the modeling nature.
+ */
+ public void testOpenSessionEditorByDoubleClick() {
+ SWTBotView modelExplorerView = bot.viewById(IModelExplorerView.ID);
+ modelExplorerView.setFocus();
+ SWTBot packageExplorerViewBot = modelExplorerView.bot();
+
+ SWTBotTreeItem expandedNode = packageExplorerViewBot.tree().expandNode("DesignerTestProject", true);
+ SWTBotTreeItem node = expandedNode.getNode("My.aird");
+ node.doubleClick();
+
+ bot.waitUntil(new DefaultCondition() {
+
+ @Override
+ public boolean test() throws Exception {
+ return PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getActiveEditor() != null;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Wrong Active editor is : " + PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getActiveEditor().getEditorSite().getId();
+ }
+ });
+ assertEquals("The session editor has not opened.", "org.eclipse.sirius.ui.editor.session",
+ PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getActiveEditor().getEditorSite().getId());
+ }
+
+ /**
+ * Tests that the aird editor is opened when the aird file is double clicked from Package explorer view and when the
+ * project has not the modeling nature.
+ */
+ public void testOpenSessionEditorByDoubleClick2() {
+ SWTBotPerspective javaPerspective = bot.perspectiveByLabel("Java");
+ javaPerspective.activate();
+ SWTBotView packageExplorerView = bot.viewById("org.eclipse.jdt.ui.PackageExplorer");
+ packageExplorerView.setFocus();
+ SWTBot packageExplorerViewBot = packageExplorerView.bot();
+
+ assertSessionEditorOpened(packageExplorerViewBot);
+ }
+
+ private void assertSessionEditorOpened(SWTBot packageExplorerViewBot) {
+ SWTBotTreeItem expandedNode = packageExplorerViewBot.tree().expandNode("DesignerTestProject", true);
+ SWTBotTreeItem node = expandedNode.getNode("My.aird");
+ node.doubleClick();
+
+ bot.waitUntil(new DefaultCondition() {
+
+ @Override
+ public boolean test() throws Exception {
+ return PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getActiveEditor() != null;
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Wrong Active editor is : " + PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getActiveEditor().getEditorSite().getId();
+ }
+ });
+ assertEquals("The session editor has not opened.", "org.eclipse.sirius.ui.editor.session",
+ PlatformUI.getWorkbench().getWorkbenchWindows()[0].getActivePage().getActiveEditor().getEditorSite().getId());
+ }
+
+ /**
+ * Tests that the aird editor is opened when the aird file is double clicked from Model explorer view and when the
+ * project has the modeling nature.
+ */
+ public void testOpenSessionEditorByDoubleClick3() {
+ designerProject.convertToModelingProject();
+
+ SWTBotView modelExplorerView = bot.viewById(IModelExplorerView.ID);
+ modelExplorerView.setFocus();
+ SWTBot packageExplorerViewBot = modelExplorerView.bot();
+
+ assertSessionEditorOpened(packageExplorerViewBot);
+ }
+
+ /**
+ * Tests that the aird editor is opened when the aird file is double clicked from Package explorer view and when the
+ * project has the modeling nature.
+ */
+ public void testOpenSessionEditorByDoubleClick4() {
+ designerProject.convertToModelingProject();
+
+ SWTBotPerspective javaPerspective = bot.perspectiveByLabel("Java");
+ javaPerspective.activate();
+ SWTBotView packageExplorerView = bot.viewById("org.eclipse.jdt.ui.PackageExplorer");
+ packageExplorerView.setFocus();
+ SWTBot packageExplorerViewBot = packageExplorerView.bot();
+
+ assertSessionEditorOpened(packageExplorerViewBot);
+ }
+
+ /**
+ * Tests that the aird editor is opened when the aird file is double clicked from Project explorer view and when the
+ * project has the modeling nature.
+ */
+ public void testOpenSessionEditorByDoubleClick5() {
+ designerProject.convertToModelingProject();
+
+ Display.getDefault().syncExec(() -> {
+ try {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView("org.eclipse.ui.navigator.ProjectExplorer");
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ });
+
+ SWTBotView packageExplorerView = bot.viewById("org.eclipse.ui.navigator.ProjectExplorer");
+ packageExplorerView.setFocus();
+ SWTBot packageExplorerViewBot = packageExplorerView.bot();
+
+ assertSessionEditorOpened(packageExplorerViewBot);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ sessionAirdResource = null;
+ localSession = null;
+ super.tearDown();
+ }
+}
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
index ac862e48ee..705e7ccbb1 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/suite/AllTestSuite.java
@@ -61,6 +61,7 @@ import org.eclipse.sirius.tests.swtbot.modelexplorer.ProjectsConcurrentCloseTest
import org.eclipse.sirius.tests.swtbot.modelexplorer.PropertyViewOnModelExplorerSelectionTests;
import org.eclipse.sirius.tests.swtbot.modelexplorer.PropertyViewOnModelExplorerSelectionWithLockedObjectTest;
import org.eclipse.sirius.tests.swtbot.modelexplorer.RepresentationVisibilityAfterSessionReloadTest;
+import org.eclipse.sirius.tests.swtbot.sessioneditor.SessionEditorOpeningTests;
import org.eclipse.sirius.tests.swtbot.tabbar.LockedTabBarTest;
import org.eclipse.sirius.tests.swtbot.tabbar.NotInvisibleTabBarTest;
import org.eclipse.sirius.tests.swtbot.tabbar.ResetToDefaultFiltersActionTests;
@@ -415,6 +416,7 @@ public class AllTestSuite extends TestCase {
suite.addTestSuite(ShowTypeActionButtonTest.class);
suite.addTestSuite(ChildrenPositionStabilityAfterParentResizeTest.class);
suite.addTestSuite(VSMEditorPropertiesTest.class);
+ suite.addTestSuite(SessionEditorOpeningTests.class);
// Scenario test cases
suite.addTestSuite(ESEDemoTest.class);
@@ -427,6 +429,7 @@ public class AllTestSuite extends TestCase {
suite.addTestSuite(ControlUncontrolWithOpenedRepresentationTest.class);
suite.addTestSuite(SiriusInternationalizationTest.class);
suite.addTestSuite(DecoratorTest.class);
+
}
/**
diff --git a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
index f689a6438e..a5d89039af 100644
--- a/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
+++ b/plugins/org.eclipse.sirius.ui.editor/src/org/eclipse/sirius/ui/editor/internal/graphicalcomponents/GraphicalSemanticModelsHandler.java
@@ -403,7 +403,7 @@ public class GraphicalSemanticModelsHandler implements SessionListener, SessionM
// setting height hint avoids the composite to grow outside visible
// port when too much item are present.
layoutData.heightHint = 50;
- siriusCommonContentModelProvider = new SiriusCommonContentProvider();
+ siriusCommonContentModelProvider = new SiriusCommonContentProvider(session);
updateViewerInput();
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java
index 2db1bc397a..7827031e45 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/graphicalcomponents/GraphicalRepresentationHandler.java
@@ -62,7 +62,6 @@ import org.eclipse.sirius.ui.tools.internal.views.common.item.RepresentationDesc
import org.eclipse.sirius.ui.tools.internal.views.common.item.RepresentationItemImpl;
import org.eclipse.sirius.ui.tools.internal.views.common.item.ViewpointItemImpl;
import org.eclipse.sirius.ui.tools.internal.views.common.navigator.ManageSessionActionProvider;
-import org.eclipse.sirius.ui.tools.internal.views.common.navigator.OpenRepresentationListenerWithViewpointActivation;
import org.eclipse.sirius.ui.tools.internal.views.common.navigator.SiriusCommonContentProvider;
import org.eclipse.sirius.ui.tools.internal.views.common.navigator.sorter.CommonItemSorter;
import org.eclipse.sirius.ui.tools.internal.views.modelexplorer.DeleteActionHandler;
@@ -784,7 +783,7 @@ public class GraphicalRepresentationHandler implements SessionManagerListener {
if (contentProvider != null) {
contentProviderToUse = contentProvider;
} else {
- siriusCommonContentProvider = new SiriusCommonContentProvider(new OpenRepresentationListenerWithViewpointActivation(session));
+ siriusCommonContentProvider = new SiriusCommonContentProvider(session);
contentProviderToUse = siriusCommonContentProvider;
}
treeViewer.setContentProvider(contentProviderToUse);
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenEditorDoubleClickListener.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenEditorDoubleClickListener.java
new file mode 100644
index 0000000000..fcb86697b9
--- /dev/null
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenEditorDoubleClickListener.java
@@ -0,0 +1,158 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2017 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.sirius.ui.tools.internal.views.common.navigator;
+
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.sirius.business.api.query.FileQuery;
+import org.eclipse.sirius.business.api.query.RepresentationDescriptionQuery;
+import org.eclipse.sirius.business.api.session.Session;
+import org.eclipse.sirius.ui.tools.internal.actions.session.OpenRepresentationsAction;
+import org.eclipse.sirius.ui.tools.internal.viewpoint.ViewpointHelper;
+import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
+import org.eclipse.sirius.viewpoint.description.Viewpoint;
+import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+
+/**
+ * A double click listener which opens either representations in Sirius editors or the session editor regarding the
+ * selection content.
+ *
+ * @author mchauvin
+ */
+public class OpenEditorDoubleClickListener implements IDoubleClickListener {
+ private Session session;
+
+ /**
+ * Constructor.
+ *
+ * @param theSession
+ * the session used for viewpoint activation.
+ */
+ public OpenEditorDoubleClickListener(Session theSession) {
+ this.session = theSession;
+ }
+
+ @Override
+ public void doubleClick(final DoubleClickEvent event) {
+ if (event != null && event.getSelection() instanceof IStructuredSelection) {
+ List<?> selection = ((IStructuredSelection) event.getSelection()).toList();
+ Set<DRepresentationDescriptor> repDescriptorToOpen = getRepresentationDescriptorsToOpen(selection);
+ if (!repDescriptorToOpen.isEmpty()) {
+ activateViewpoints(repDescriptorToOpen);
+ openRepresentations(repDescriptorToOpen);
+ } else if (!selection.isEmpty()) {
+ openSessionEditor(selection);
+ }
+ }
+ }
+
+ /**
+ * Open representation from given {@link DRepresentationDescriptor}.
+ *
+ * @param repDescriptorToOpen
+ * the set containing the {@link DRepresentationDescriptor} that should be opened with Sirius modelers.
+ */
+ protected void openRepresentations(Set<DRepresentationDescriptor> repDescriptorToOpen) {
+ new OpenRepresentationsAction(repDescriptorToOpen).run();
+ }
+
+ /**
+ * Activate all viewpoints associated to the given {@link DRepresentationDescriptor} if such elements exists and
+ * only if they are not already activated.
+ *
+ * @param repDescriptorToOpen
+ * the {@link DRepresentationDescriptor} from which referenced viewpoint should be activated.
+ */
+ private void activateViewpoints(Set<DRepresentationDescriptor> repDescriptorToOpen) {
+ if (session != null) {
+ Set<Viewpoint> viewpointsToActivate = new HashSet<>();
+ repDescriptorToOpen.forEach(repDesc -> {
+ Viewpoint parentViewpoint = ViewpointHelper.getViewpointInVSM(session, new RepresentationDescriptionQuery(repDesc.getDescription()).getParentViewpoint());
+ if (parentViewpoint != null) {
+ boolean activateViewpoint = !ViewpointHelper.isViewpointEnabledInSession(session, parentViewpoint);
+ if (activateViewpoint) {
+ viewpointsToActivate.add(parentViewpoint);
+ }
+ }
+ });
+ if (!viewpointsToActivate.isEmpty()) {
+ ViewpointHelper.handleViewpointActivation(session, viewpointsToActivate, true, false);
+ }
+ }
+ }
+
+ /**
+ * Open the session editor if the given selection contains an aird file.
+ *
+ * @param selectionList
+ * the selection that could contains an aird file.
+ */
+ protected void openSessionEditor(List<?> selectionList) {
+ Object element = selectionList.get(0);
+ if (element instanceof IFile && new FileQuery((IFile) element).isSessionResourceFile()) {
+ IEditorDescriptor defaultEditor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(((IFile) element).getName());
+ FileEditorInput fileEditorInput = new FileEditorInput((IFile) element);
+ if (fileEditorInput != null) {
+ try {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(fileEditorInput, defaultEditor.getId());
+ } catch (PartInitException e) {
+ SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
+ }
+ }
+ }
+ }
+
+ /**
+ * Return the representation descriptor to open from the selection.
+ *
+ * @param selection
+ * the selection from which representation descriptor to open should be returned.
+ * @return the representation descriptor to open from given selection if such element exists.
+ */
+ protected Set<DRepresentationDescriptor> getRepresentationDescriptorsToOpen(List<?> selection) {
+
+ final Set<DRepresentationDescriptor> repDescriptors = new LinkedHashSet<DRepresentationDescriptor>();
+ for (final Object obj : selection) {
+ if (obj instanceof DRepresentationDescriptor)
+ repDescriptors.add((DRepresentationDescriptor) obj);
+ else {
+ DRepresentationDescriptor adapted = adaptToDRepresentationDescriptor(obj);
+ if (adapted != null)
+ repDescriptors.add(adapted);
+ }
+ }
+ return repDescriptors;
+ }
+
+ private DRepresentationDescriptor adaptToDRepresentationDescriptor(Object input) {
+ if (input instanceof IAdaptable) {
+ Object adapter = ((IAdaptable) input).getAdapter(EObject.class);
+ if (adapter instanceof DRepresentationDescriptor)
+ return (DRepresentationDescriptor) adapter;
+ }
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenRepresentationListener.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenRepresentationListener.java
deleted file mode 100644
index fe5951e742..0000000000
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenRepresentationListener.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011, 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.sirius.ui.tools.internal.views.common.navigator;
-
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.sirius.ui.tools.internal.actions.session.OpenRepresentationsAction;
-import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
-/**
- * A double click listener which opens an editor if the clicked element is a representation.
- *
- * @author mchauvin
- */
-public class OpenRepresentationListener implements IDoubleClickListener {
-
- @Override
- public void doubleClick(final DoubleClickEvent event) {
- if (event != null && event.getSelection() instanceof IStructuredSelection) {
- List<?> selection = ((IStructuredSelection) event.getSelection()).toList();
- Iterable<DRepresentationDescriptor> repDescriptorToOpen = getRepresentationDescriptorsToOpen(selection);
- if (!Iterables.isEmpty(repDescriptorToOpen)) {
- new OpenRepresentationsAction(Sets.newLinkedHashSet(repDescriptorToOpen)).run();
- }
- }
- }
-
- /**
- * Return the representation descriptor to open from the selection.
- *
- * @param selection
- * the selection from which representation descriptor to open should be returned.
- * @return the representation descriptor to open from given selection if such element exists.
- */
- protected Iterable<DRepresentationDescriptor> getRepresentationDescriptorsToOpen(List<?> selection) {
-
- final Set<DRepresentationDescriptor> repDescriptors = Sets.newLinkedHashSet();
- for (final Object obj : selection) {
- if (obj instanceof DRepresentationDescriptor)
- repDescriptors.add((DRepresentationDescriptor) obj);
- else {
- DRepresentationDescriptor adapted = adaptToDRepresentationDescriptor(obj);
- if (adapted != null)
- repDescriptors.add(adapted);
- }
- }
- return repDescriptors;
- }
-
- private DRepresentationDescriptor adaptToDRepresentationDescriptor(Object input) {
- if (input instanceof IAdaptable) {
- Object adapter = ((IAdaptable) input).getAdapter(EObject.class);
- if (adapter instanceof DRepresentationDescriptor)
- return (DRepresentationDescriptor) adapter;
- }
- return null;
- }
-}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenRepresentationListenerWithViewpointActivation.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenRepresentationListenerWithViewpointActivation.java
deleted file mode 100644
index eefefd9f0c..0000000000
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/OpenRepresentationListenerWithViewpointActivation.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2017 Obeo
- * 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:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.sirius.ui.tools.internal.views.common.navigator;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.sirius.business.api.query.RepresentationDescriptionQuery;
-import org.eclipse.sirius.business.api.session.Session;
-import org.eclipse.sirius.ui.tools.internal.actions.session.OpenRepresentationsAction;
-import org.eclipse.sirius.ui.tools.internal.viewpoint.ViewpointHelper;
-import org.eclipse.sirius.ui.tools.internal.views.common.item.RepresentationItemImpl;
-import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
-import org.eclipse.sirius.viewpoint.description.Viewpoint;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
-/**
- * A double click listener opening the representation from {@link RepresentationItemImpl} selection in a Sirius Modeler.
- * If corresponding viewpoint is not activated, then it will be before opening the modeler.
- *
- * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a>
- *
- */
-public class OpenRepresentationListenerWithViewpointActivation extends OpenRepresentationListener {
-
- private Session session;
-
- /**
- * Constructor.
- *
- * @param theSession
- * the session used for viewpoint activation.
- */
- public OpenRepresentationListenerWithViewpointActivation(Session theSession) {
- this.session = theSession;
- }
-
- @Override
- public void doubleClick(final DoubleClickEvent event) {
- if (event != null && event.getSelection() instanceof IStructuredSelection) {
- List<?> selection = ((IStructuredSelection) event.getSelection()).toList();
- Iterable<DRepresentationDescriptor> repDescriptorToOpen = getRepresentationDescriptorsToOpen(selection);
- if (!Iterables.isEmpty(repDescriptorToOpen)) {
- activateViewpoints(selection);
- new OpenRepresentationsAction(Sets.newLinkedHashSet(repDescriptorToOpen)).run();
- }
- }
- }
-
- /**
- * Activate all viewpoints associated to the given selection if such elements exists and only if they are not
- * already activated.
- *
- * @param selection
- * the selection from which viewpoints to activate must be identified and activated.
- */
- private void activateViewpoints(List<?> selection) {
- List<RepresentationItemImpl> representationItemList = getRepresentationItems(selection);
- Set<Viewpoint> viewpointsToActivate = new HashSet<>();
- for (RepresentationItemImpl representationItemImpl : representationItemList) {
- Viewpoint parentViewpoint = ViewpointHelper.getViewpointInVSM(session,
- new RepresentationDescriptionQuery(representationItemImpl.getDRepresentationDescriptor().getDescription()).getParentViewpoint());
- if (parentViewpoint != null) {
- boolean activateViewpoint = !ViewpointHelper.isViewpointEnabledInSession(session, parentViewpoint);
- if (activateViewpoint) {
- viewpointsToActivate.add(parentViewpoint);
- }
- }
- }
- if (!viewpointsToActivate.isEmpty()) {
- ViewpointHelper.handleViewpointActivation(session, viewpointsToActivate, true, false);
- }
- }
-
- private List<RepresentationItemImpl> getRepresentationItems(List<?> selection) {
- List<RepresentationItemImpl> representationItemList = new ArrayList<>();
- for (final Object obj : selection) {
- if (obj instanceof RepresentationItemImpl) {
- representationItemList.add((RepresentationItemImpl) obj);
- }
- }
- return representationItemList;
- }
-}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonContentProvider.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonContentProvider.java
index d3331f6614..fd6b22439f 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonContentProvider.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/navigator/SiriusCommonContentProvider.java
@@ -113,21 +113,22 @@ public class SiriusCommonContentProvider implements ICommonContentProvider {
* Constructor.
*/
public SiriusCommonContentProvider() {
- this(new OpenRepresentationListener());
+ this(null);
}
/**
* Constructor.
*
- * @param theDoubleClickListener
- * Listener that should be used instead of the default one that is an {@link OpenRepresentationListener}.
- * This component takes care of disposing the given listener when disposed from associated viewer.
+ * @param session
+ * Listener that should be used instead of the default one that is an
+ * {@link OpenEditorDoubleClickListener}. This component takes care of disposing the given listener when
+ * disposed from associated viewer.
*/
- public SiriusCommonContentProvider(IDoubleClickListener theDoubleClickListener) {
+ public SiriusCommonContentProvider(Session session) {
defaultContentProvider = ViewHelper.INSTANCE.createContentProvider();
initSessionManager();
- doubleClickListener = theDoubleClickListener;
+ doubleClickListener = new OpenEditorDoubleClickListener(session);
initExpandListener();
}
@@ -445,7 +446,7 @@ public class SiriusCommonContentProvider implements ICommonContentProvider {
}
if (viewer != myViewer) {
- removeDoubleClickListener();
+ removeDoubleClickListener(doubleClickListener);
removeExpandListener();
if (linkWithEditorSelectionListener != null) {
linkWithEditorSelectionListener.dispose();
@@ -453,7 +454,7 @@ public class SiriusCommonContentProvider implements ICommonContentProvider {
myViewer = viewer;
- addDoubleClickListener();
+ addDoubleClickListener(doubleClickListener);
addExpandListener();
createLWESelectionListener();
}
@@ -470,15 +471,15 @@ public class SiriusCommonContentProvider implements ICommonContentProvider {
}
}
- private void addDoubleClickListener() {
+ private void addDoubleClickListener(IDoubleClickListener listener) {
if (myViewer instanceof StructuredViewer) {
- ((StructuredViewer) myViewer).addDoubleClickListener(doubleClickListener);
+ ((StructuredViewer) myViewer).addDoubleClickListener(listener);
}
}
- private void removeDoubleClickListener() {
+ private void removeDoubleClickListener(IDoubleClickListener listener) {
if (myViewer instanceof StructuredViewer) {
- ((StructuredViewer) myViewer).removeDoubleClickListener(doubleClickListener);
+ ((StructuredViewer) myViewer).removeDoubleClickListener(listener);
}
}
@@ -506,7 +507,7 @@ public class SiriusCommonContentProvider implements ICommonContentProvider {
*/
@Override
public void dispose() {
- removeDoubleClickListener();
+ removeDoubleClickListener(doubleClickListener);
removeExpandListener();
myViewer = null;
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/ModelExplorerView.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/ModelExplorerView.java
index 1da4430299..e0f3026cbe 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/ModelExplorerView.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/modelexplorer/ModelExplorerView.java
@@ -15,9 +15,7 @@ import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.action.Action;
@@ -57,16 +55,12 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IActionBars;
-import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewSite;
-import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.navigator.CommonNavigator;
import org.eclipse.ui.navigator.CommonViewer;
-import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
@@ -81,11 +75,6 @@ import com.google.common.collect.Sets;
*/
public class ModelExplorerView extends CommonNavigator implements IModelExplorerView, IExpandSelectionTarget, ITabbedPropertySheetPageContributor {
- /**
- * The session editor's id used to open automatically this editor when double clicking on an aird file.
- */
- private static final String SESSION_EDITOR_ID = "org.eclipse.sirius.ui.editor.session"; //$NON-NLS-1$
-
private CTabFolder tabFolder;
private String initialSelection = ""; //$NON-NLS-1$
@@ -353,20 +342,7 @@ public class ModelExplorerView extends CommonNavigator implements IModelExplorer
IStructuredSelection selection = (IStructuredSelection) anEvent.getSelection();
Object element = selection.getFirstElement();
- if (element instanceof IFile && new FileQuery((IFile) element).isSessionResourceFile()) {
- IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
- FileEditorInput fileEditorInput = new FileEditorInput((IFile) element);
- IEditorReference[] airdEditorReferences = activePage.findEditors(fileEditorInput, SESSION_EDITOR_ID, IWorkbenchPage.MATCH_ID);
- try {
- if (canOpenEditor(airdEditorReferences, fileEditorInput)) {
- activePage.openEditor(fileEditorInput, SESSION_EDITOR_ID);
- } else {
- super.handleDoubleClick(anEvent);
- }
- } catch (PartInitException e) {
- SiriusEditPlugin.getPlugin().getLog().log(new Status(IStatus.ERROR, SiriusEditPlugin.ID, e.getLocalizedMessage(), e));
- }
- } else {
+ if (!(element instanceof IFile && new FileQuery((IFile) element).isSessionResourceFile())) {
super.handleDoubleClick(anEvent);
}
// Just after the restart of Eclipse, the listener of the
@@ -395,15 +371,6 @@ public class ModelExplorerView extends CommonNavigator implements IModelExplorer
}
}
- private boolean canOpenEditor(IEditorReference[] airdEditorReferences, FileEditorInput fileEditorInput) throws PartInitException {
- for (IEditorReference iEditorReference : airdEditorReferences) {
- if (((FileEditorInput) iEditorReference.getEditorInput()).getPath().equals(fileEditorInput.getPath())) {
- return false;
- }
- }
- return true;
- }
-
private void hookGlobalActions() {
final IActionBars bars = this.getViewSite().getActionBars();
deleteActionHandler = new DeleteActionHandler(this.getSite().getSelectionProvider());

Back to the top