| /******************************************************************************* |
| * 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.api.editors; |
| |
| import org.eclipse.core.runtime.NullProgressMonitor; |
| import org.eclipse.emf.ecore.util.EcoreUtil; |
| import org.eclipse.emf.transaction.RecordingCommand; |
| import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart; |
| import org.eclipse.gmf.runtime.notation.Diagram; |
| import org.eclipse.sirius.diagram.DDiagram; |
| import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; |
| import org.eclipse.sirius.tests.support.api.TestsUtil; |
| import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; |
| import org.eclipse.ui.IEditorPart; |
| import org.eclipse.ui.part.IShowInSource; |
| |
| import org.eclipse.sirius.tests.unit.diagram.modeler.ecore.EcoreModeler; |
| |
| /** |
| * Tests on editors. |
| * |
| * @author mchauvin |
| */ |
| public class EditorVariousTests extends SiriusDiagramTestCase implements EcoreModeler { |
| |
| private DDiagram diagram; |
| |
| private IEditorPart editor; |
| |
| @Override |
| protected void setUp() throws Exception { |
| super.setUp(); |
| |
| TestsUtil.emptyEventsFromUIThread(); |
| genericSetUp(TEST_SEMANTIC_MODEL_PATH, MODELER_PATH); |
| initViewpoint(DESIGN_VIEWPOINT_NAME); |
| diagram = (DDiagram) getRepresentations(ENTITIES_DESC_NAME).toArray()[0]; |
| editor = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor()); |
| } |
| |
| public void testNoNpeWhenGetShowInContext() throws Exception { |
| if (editor instanceof IShowInSource) { |
| removeDiagramFromResource(); |
| ((IShowInSource) editor).getShowInContext(); |
| } |
| |
| } |
| |
| private void removeDiagramFromResource() { |
| final IDiagramWorkbenchPart gmfEditor = (IDiagramWorkbenchPart) editor; |
| final Diagram gmfDiagram = gmfEditor.getDiagram(); |
| session.getTransactionalEditingDomain().getCommandStack().execute(new RecordingCommand(session.getTransactionalEditingDomain()) { |
| @Override |
| protected void doExecute() { |
| EcoreUtil.remove(gmfDiagram); |
| } |
| }); |
| } |
| |
| @Override |
| protected void tearDown() throws Exception { |
| DialectUIManager.INSTANCE.closeEditor(editor, false); |
| TestsUtil.synchronizationWithUIThread(); |
| super.tearDown(); |
| } |
| } |