Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpguilet2016-10-13 13:43:50 +0000
committerMaxime Porhel2016-10-24 12:04:22 +0000
commit6244b543d75102602fef55b36c3dc301caf04528 (patch)
treed2ee977dfe107aa4b1cb51c0646639e5e9ace593
parenta9ae7232a4b71319075a0498882ba84342972884 (diff)
downloadorg.eclipse.sirius-6244b543d75102602fef55b36c3dc301caf04528.tar.gz
org.eclipse.sirius-6244b543d75102602fef55b36c3dc301caf04528.tar.xz
org.eclipse.sirius-6244b543d75102602fef55b36c3dc301caf04528.zip
[502053] Add test corresponding to the fix
- Adds a test verifying that opening a DDiagramEditorImpl inside a multi editor part is successful without NPE. Bug: 502053 Change-Id: I0cb08f73aa68f6432258e58ca3b3eb3272c8753e Signed-off-by: pguilet <pierre.guilet@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/icons/sample.gifbin0 -> 983 bytes
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/plugin.xml10
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java4
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/multipageeditor/SiriusMultiPageEditor.java179
-rw-r--r--plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/multipageeditor/SiriusMultiPageEditorTest.java104
6 files changed, 299 insertions, 1 deletions
diff --git a/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
index 7726346cc1..a8237749c8 100644
--- a/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.sirius.tests.junit/META-INF/MANIFEST.MF
@@ -75,7 +75,8 @@ Require-Bundle: org.eclipse.sirius.tests.sample.benchmark,
org.eclipse.sirius.common.acceleo.aql.ide;bundle-version="3.1.0",
org.eclipse.ui.navigator;bundle-version="3.5.200",
org.eclipse.sirius.diagram.formatdata;bundle-version="4.1.0",
- org.eclipse.sirius.ext.emf.edit;bundle-version="4.1.0"
+ org.eclipse.sirius.ext.emf.edit;bundle-version="4.1.0",
+ org.eclipse.ui.editors
Bundle-Activator: org.eclipse.sirius.tests.SiriusTestsPlugin
Eclipse-LazyStart: true
Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.sirius.tests.junit/icons/sample.gif b/plugins/org.eclipse.sirius.tests.junit/icons/sample.gif
new file mode 100644
index 0000000000..34fb3c9d8c
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/icons/sample.gif
Binary files differ
diff --git a/plugins/org.eclipse.sirius.tests.junit/plugin.xml b/plugins/org.eclipse.sirius.tests.junit/plugin.xml
index 8cb2f8f542..daecc1ee14 100644
--- a/plugins/org.eclipse.sirius.tests.junit/plugin.xml
+++ b/plugins/org.eclipse.sirius.tests.junit/plugin.xml
@@ -11,6 +11,16 @@
Obeo - Initial API and implementation
-->
<plugin>
+ <extension
+ point="org.eclipse.ui.editors">
+ <editor
+ name="Sirius Sample Multi-page Editor"
+ extensions="mpe"
+ icon="icons/sample.gif"
+ class="org.eclipse.sirius.tests.unit.multipageeditor.SiriusMultiPageEditor"
+ id="org.eclipse.sirius.tests.unit.SiriusMultiPageEditor">
+ </editor>
+ </extension>
<extension
point="org.eclipse.sirius.componentization">
<component
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
index 613ea92ca0..012c669fa2 100644
--- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/suite/common/AllCommonPluginTests.java
@@ -142,6 +142,7 @@ import org.eclipse.sirius.tests.unit.diagram.migration.RepairWithActivatedFilter
import org.eclipse.sirius.tests.unit.diagram.migration.RgbValuesEDataTypeMigrationTest;
import org.eclipse.sirius.tests.unit.diagram.migration.RunRepairTest;
import org.eclipse.sirius.tests.unit.diagram.migration.SetVersionTest;
+import org.eclipse.sirius.tests.unit.multipageeditor.SiriusMultiPageEditorTest;
import org.eclipse.sirius.tests.unit.perf.common.CommonPreferencesTest;
import org.eclipse.sirius.tests.unit.perf.common.Session1MillionTests;
@@ -339,6 +340,9 @@ public class AllCommonPluginTests extends TestCase {
// one false-negative Gerrit Verification job
suite.addTestSuite(SessionManagerListener2Tests.class);
suite.addTestSuite(RepairWithActivatedFiltersTest.class);
+ // We don't officially handle Sirius editors inside MultiPageEditorPart
+ // so it is not necessary to run it in Gerrit.
+ suite.addTestSuite(SiriusMultiPageEditorTest.class);
}
/**
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/multipageeditor/SiriusMultiPageEditor.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/multipageeditor/SiriusMultiPageEditor.java
new file mode 100644
index 0000000000..b103598315
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/multipageeditor/SiriusMultiPageEditor.java
@@ -0,0 +1,179 @@
+package org.eclipse.sirius.tests.unit.multipageeditor;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.sirius.diagram.ui.part.SiriusDiagramEditor;
+import org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FontDialog;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.part.MultiPageEditorPart;
+
+/**
+ * An example showing how to create a multi-page editor. This example has 3
+ * pages:
+ * <ul>
+ * <li>page 0 contains a nested text editor.
+ * <li>page 1 allows you to change the font used in page 2
+ * <li>page 2 shows the words in page 0 in sorted order
+ * </ul>
+ */
+public class SiriusMultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener {
+
+ /** The text editor used in page 0. */
+ private SiriusDiagramEditor editor;
+
+ /** The font chosen in page 1. */
+ private Font font;
+
+ /** The text widget used in page 2. */
+ private StyledText text;
+
+ /**
+ * Creates a multi-page editor example.
+ */
+ public SiriusMultiPageEditor() {
+ super();
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
+ }
+
+ /**
+ * Creates page 0 of the multi-page editor, which contains a text editor.
+ */
+ void createPage0() {
+ try {
+ editor = new DDiagramEditorImpl();
+ int index = addPage(editor, getEditorInput());
+ setPageText(index, editor.getTitle());
+ editor.setInput(getEditorInput());
+ } catch (PartInitException e) {
+ ErrorDialog.openError(getSite().getShell(), "Error creating nested text editor", null, e.getStatus());
+ }
+ }
+
+ /**
+ * Creates the pages of the multi-page editor.
+ */
+ @Override
+ protected void createPages() {
+ createPage0();
+ }
+
+ /**
+ * The <code>MultiPageEditorPart</code> implementation of this
+ * <code>IWorkbenchPart</code> method disposes all nested editors.
+ * Subclasses may extend.
+ */
+ @Override
+ public void dispose() {
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ super.dispose();
+ }
+
+ /**
+ * Saves the multi-page editor's document.
+ *
+ * @param monitor
+ * used to monitor save progress.
+ */
+ @Override
+ public void doSave(IProgressMonitor monitor) {
+ getEditor(0).doSave(monitor);
+ }
+
+ /**
+ * Saves the multi-page editor's document as another file. Also updates the
+ * text for page 0's tab, and updates this multi-page editor's input to
+ * correspond to the nested editor's.
+ */
+ @Override
+ public void doSaveAs() {
+ IEditorPart editor = getEditor(0);
+ editor.doSaveAs();
+ setPageText(0, editor.getTitle());
+ setInput(editor.getEditorInput());
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IEditorPart
+ */
+ public void gotoMarker(IMarker marker) {
+ setActivePage(0);
+ IDE.gotoMarker(getEditor(0), marker);
+ }
+
+ /**
+ * The <code>MultiPageEditorExample</code> implementation of this method
+ * checks that the input is an instance of <code>IFileEditorInput</code>.
+ */
+ @Override
+ public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
+ super.init(site, editorInput);
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IEditorPart.
+ */
+ @Override
+ public boolean isSaveAsAllowed() {
+ return true;
+ }
+
+ /**
+ * Calculates the contents of page 2 when the it is activated.
+ */
+ @Override
+ protected void pageChange(int newPageIndex) {
+ super.pageChange(newPageIndex);
+ }
+
+ /**
+ * Closes all project files on project close.
+ */
+ @Override
+ public void resourceChanged(final IResourceChangeEvent event) {
+ if (event.getType() == IResourceChangeEvent.PRE_CLOSE) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ IWorkbenchPage[] pages = getSite().getWorkbenchWindow().getPages();
+ for (int i = 0; i < pages.length; i++) {
+ if (((FileEditorInput) editor.getEditorInput()).getFile().getProject().equals(event.getResource())) {
+ IEditorPart editorPart = pages[i].findEditor(editor.getEditorInput());
+ pages[i].closeEditor(editorPart, true);
+ }
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * Sets the font related data to be applied to the text in page 2.
+ */
+ void setFont() {
+ FontDialog fontDialog = new FontDialog(getSite().getShell());
+ fontDialog.setFontList(text.getFont().getFontData());
+ FontData fontData = fontDialog.open();
+ if (fontData != null) {
+ if (font != null)
+ font.dispose();
+ font = new Font(text.getDisplay(), fontData);
+ text.setFont(font);
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/multipageeditor/SiriusMultiPageEditorTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/multipageeditor/SiriusMultiPageEditorTest.java
new file mode 100644
index 0000000000..56a32d24cc
--- /dev/null
+++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/multipageeditor/SiriusMultiPageEditorTest.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2014 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.tests.unit.multipageeditor;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.sirius.business.api.session.CustomDataConstants;
+import org.eclipse.sirius.diagram.tools.api.command.DiagramCommandFactoryService;
+import org.eclipse.sirius.diagram.tools.api.command.IDiagramCommandFactory;
+import org.eclipse.sirius.diagram.ui.tools.internal.editor.DDiagramEditorImpl;
+import org.eclipse.sirius.tests.support.api.SiriusTestCase;
+import org.eclipse.sirius.tools.api.command.ICommandFactory;
+import org.eclipse.sirius.tools.api.command.ui.NoUICallback;
+import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager;
+import org.eclipse.sirius.ui.business.api.session.SessionEditorInput;
+import org.eclipse.sirius.viewpoint.DRepresentation;
+import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.MultiPageEditorPart;
+
+/**
+ * Tests the Sirius editors behavior inside a {@link MultiPageEditorPart} that
+ * is inside an IWorkbenchPartSite with empty id.
+ *
+ * This only test we don't have NPE when the VSM editor is included in a part
+ * not providing id. But we don't officially support this kind of integration.
+ *
+ * See 502053
+ *
+ * @author <a href="mailto:pierre.guilet@obeo.fr">Pierre Guilet</a>
+ *
+ */
+public class SiriusMultiPageEditorTest extends SiriusTestCase {
+ private static final String SIRIUS_MULTI_PAGE_EDITOR_ID = "org.eclipse.sirius.tests.unit.SiriusMultiPageEditor";
+
+ public static final String PATH = "/data/unit/initialization/";
+
+ private static final String SEMANTIC_MODEL_FILENAME = "/org.eclipse.sirius.tests.junit/data/unit/layoutingMode/vp2120.ecore";
+
+ private static final String MODELER_MODEL_FILENAME = "/org.eclipse.sirius.tests.junit/data/unit/layoutingMode/vp2120.odesign";
+
+ private static final String SESSION_PATH = "/org.eclipse.sirius.tests.junit/data/unit/layoutingMode/vp2120.aird";
+
+ private IDiagramCommandFactory commandFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ genericSetUp(SEMANTIC_MODEL_FILENAME, MODELER_MODEL_FILENAME, SESSION_PATH);
+
+ }
+
+ /**
+ * Tests that {@link DDiagramEditorImpl} opens correctly inside a
+ * {@link MultiPageEditorPart} without exceptions. This tests particularly
+ * the behavior of the Sirius editor opening in case it is embedded inside a
+ * part inside a IWorkbenchPartSite that provides empty id. See 502053.
+ *
+ * @throws Exception
+ */
+ public void testDiagramEditorOpeningInsideMultiPageEditor() throws Exception {
+ DRepresentationDescriptor representationDescriptor = getRepresentationDescriptors("LayoutingMode Diagram").iterator().next();
+ DRepresentation representation = representationDescriptor.getRepresentation();
+
+ EObject gmfDiag = session.getServices().getCustomData(CustomDataConstants.GMF_DIAGRAMS, representation).iterator().next();
+ URI uri = EcoreUtil.getURI(gmfDiag);
+ String editorName = DialectUIManager.INSTANCE.getEditorName(representation);
+ final IEditorInput editorInput = new SessionEditorInput(uri, editorName, session);
+ final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ assertFalse(doesAnErrorOccurs());
+ PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ activePage.openEditor(editorInput, SIRIUS_MULTI_PAGE_EDITOR_ID);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ assertFalse("No error should have occurs during opening of the Sirius Diagram editor inside a multi page editor.", doesAnErrorOccurs());
+ }
+
+ @Override
+ protected ICommandFactory getCommandFactory() {
+ if (commandFactory == null) {
+ commandFactory = DiagramCommandFactoryService.getInstance().getNewProvider().getCommandFactory(session.getTransactionalEditingDomain());
+ commandFactory.setUserInterfaceCallBack(new NoUICallback());
+ }
+ return commandFactory;
+ }
+}

Back to the top