Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Porhel2015-03-06 16:02:10 +0000
committerSteve Monnier2015-03-20 10:25:17 +0000
commitcbba085ccdd7ee74b09ad739dafa8a9b28790f35 (patch)
tree704a4fbdd23ce7f06299c35eeba071008e0a8c2b
parent9e49c0f483a02831a322c6499a5b2e706f626fdb (diff)
downloadorg.eclipse.sirius-cbba085ccdd7ee74b09ad739dafa8a9b28790f35.tar.gz
org.eclipse.sirius-cbba085ccdd7ee74b09ad739dafa8a9b28790f35.tar.xz
org.eclipse.sirius-cbba085ccdd7ee74b09ad739dafa8a9b28790f35.zip
[460351] Correct NPE during navigation from problem marker
When the user clicks on an error marker, this trigger the goto marker mecanism. If the "marked" editor is not opened, the "error editor" is opened during editor initalization but replaced during goto marker navigation. This is done because Eclipse tries to open a Sirius diagram editor using a basic FileEditorInput referencing only the file, with no information on the concrete representation to open. + Addition of a test that opens a diagram using a marker Bug: 460351 Change-Id: Ie5f8fefd3728f4878325cd7a454ba163db4a4b32 Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr> Signed-off-by: Steve Monnier <steve.monnier@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java24
-rw-r--r--plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java59
2 files changed, 74 insertions, 9 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java
index d81865a0b5..541d7c9b51 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java
@@ -97,6 +97,7 @@ import org.eclipse.sirius.business.api.session.SessionManager;
import org.eclipse.sirius.business.api.session.SessionManagerListener;
import org.eclipse.sirius.common.tools.DslCommonPlugin;
import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter;
+import org.eclipse.sirius.common.tools.api.util.StringUtil;
import org.eclipse.sirius.common.ui.tools.api.util.IObjectActionDelegateWrapper;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.DDiagramElement;
@@ -1816,16 +1817,21 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE
// In case the input is based on the DDiagram, we need to updated it to
// use the GMF diagram
IEditorInput updatedEditorInput = input;
- EObject eObject = session.getTransactionalEditingDomain().getResourceSet().getEObject(((SessionEditorInput) input).getURI(), false);
- if (eObject instanceof DDiagram) {
- DDiagram dDiagram = (DDiagram) eObject;
- final DiagramCreationUtil util = new DiagramCreationUtil(dDiagram);
- if (!util.findAssociatedGMFDiagram()) {
- DiagramPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, DiagramPlugin.ID, "The gmf diagram is expected to be created before calling setInput() on the editor"));
- }
- final Diagram gmfDiag = util.getAssociatedGMFDiagram();
- updatedEditorInput = new SessionEditorInput(EcoreUtil.getURI(gmfDiag), dDiagram.getName(), session);
+ if (input instanceof URIEditorInput) {
+ URI uri = ((URIEditorInput) input).getURI();
+ if (uri != null && !StringUtil.isEmpty(uri.fragment())) {
+ EObject eObject = session.getTransactionalEditingDomain().getResourceSet().getEObject(uri, false);
+ if (eObject instanceof DDiagram) {
+ DDiagram dDiagram = (DDiagram) eObject;
+ final DiagramCreationUtil util = new DiagramCreationUtil(dDiagram);
+ if (!util.findAssociatedGMFDiagram()) {
+ DiagramPlugin.getDefault().getLog().log(new Status(IStatus.WARNING, DiagramPlugin.ID, "The gmf diagram is expected to be created before calling setInput() on the editor"));
+ }
+ final Diagram gmfDiag = util.getAssociatedGMFDiagram();
+ updatedEditorInput = new SessionEditorInput(EcoreUtil.getURI(gmfDiag), dDiagram.getName(), session);
+ }
+ }
}
super.setInput(updatedEditorInput);
if (getGraphicalViewer() != null) {
diff --git a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java
index d8ec87793e..183e51661a 100644
--- a/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java
+++ b/plugins/org.eclipse.sirius.tests.swtbot/src/org/eclipse/sirius/tests/swtbot/GoToMarkerTraceabilityWithUserInteractionTest.java
@@ -16,6 +16,7 @@ import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EValidator;
@@ -23,6 +24,7 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+import org.eclipse.gmf.runtime.common.ui.util.WorkbenchPartDescriptor;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
import org.eclipse.gmf.runtime.notation.View;
@@ -31,9 +33,11 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeSelection;
import org.eclipse.sirius.diagram.DDiagram;
import org.eclipse.sirius.diagram.ui.part.SiriusDiagramEditor;
+import org.eclipse.sirius.diagram.ui.part.ValidateAction;
import org.eclipse.sirius.table.metamodel.table.DTable;
import org.eclipse.sirius.tests.swtbot.support.api.business.UILocalSession;
import org.eclipse.sirius.tests.swtbot.support.api.business.UIResource;
+import org.eclipse.sirius.tests.swtbot.support.api.condition.SessionClosedCondition;
import org.eclipse.sirius.tests.swtbot.support.api.editor.SWTBotSiriusDiagramEditor;
import org.eclipse.sirius.tests.swtbot.support.utils.SWTBotUtils;
import org.eclipse.sirius.ui.business.api.dialect.DialectEditor;
@@ -43,8 +47,11 @@ import org.eclipse.sirius.viewpoint.DRepresentationElement;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.VoidResult;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.PlatformUI;
@@ -180,6 +187,58 @@ public class GoToMarkerTraceabilityWithUserInteractionTest extends AbstractScena
}
/**
+ * Ensure that after closing a representation editor having validation
+ * errors, it can be reopened using an error marker from the Problem view.
+ */
+ public void testTraceabilityWithNoOpenedRepresentations() {
+ processEditorOpeningFromMarker(false);
+ }
+
+ /**
+ * Ensure that after closing a session containing a representation having
+ * validation errors, it can be reopened using an error marker from the
+ * Problem view.
+ */
+ public void testTraceabilityWithClosedSession() {
+ processEditorOpeningFromMarker(true);
+ }
+
+ private void processEditorOpeningFromMarker(boolean fromClosedSession) {
+ // Open editor
+ editor = openRepresentation(localSession.getOpenedSession(), REPRESENTATION_EMPTY_DIAGRAM, "emptyDiagram", DDiagram.class);
+
+ // Run validation
+ WorkbenchPartDescriptor workbenchPartDescriptor = new WorkbenchPartDescriptor(editor.getReference().getId(), editor.getReference().getClass(), editor.getReference().getPage());
+ ValidateAction va = new ValidateAction(workbenchPartDescriptor);
+ va.run();
+
+ // Close editor
+ editor.close();
+ SWTBotUtils.waitAllUiEvents();
+
+ if (fromClosedSession) {
+ // Close session
+ SessionClosedCondition sessionClosedCondition = new SessionClosedCondition(localSession.getOpenedSession());
+ localSession.getOpenedSession().close(new NullProgressMonitor());
+ bot.waitUntil(sessionClosedCondition);
+ }
+
+ // Reopen the editor using a marker created during the validation
+ SWTBotView problemsView = bot.viewByTitle("Problems");
+ problemsView.setFocus();
+ SWTBotTree problemsTree = problemsView.bot().tree();
+ problemsTree.getTreeItem("Errors (3 items)").expand();
+
+ // Reopen the editor using a marker created during the validation
+ final SWTBotTreeItem node = problemsTree.getTreeItem("Errors (3 items)").getNode("The namespace URI '' is not well formed");
+ node.select();
+
+ // Double click the error marker to reopen the diagram
+ Assert.assertFalse("An error happened before opening an editor using an error marker", doesAnErrorOccurs());
+ node.doubleClick();
+ Assert.assertFalse("An error happened on opening of an editor using an error marker", doesAnErrorOccurs());
+ }
+ /**
* Ensures that when Traceability ask users to choose the representations
* containing the searched element to open, and user cancel the action, no
* editor are opened.

Back to the top