| /******************************************************************************* |
| * Copyright (c) 2011 Tasktop Technologies. |
| * 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: |
| * Tasktop Technologies - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.mylyn.mft.papyrus.tests; |
| |
| import java.util.List; |
| |
| import org.eclipse.core.resources.IFile; |
| import org.eclipse.core.resources.IProject; |
| import org.eclipse.core.runtime.NullProgressMonitor; |
| import org.eclipse.emf.common.util.TreeIterator; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart; |
| import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; |
| import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil; |
| import org.eclipse.gmf.runtime.notation.Shape; |
| import org.eclipse.jdt.core.IJavaProject; |
| import org.eclipse.jface.viewers.StructuredSelection; |
| import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil; |
| import org.eclipse.mylyn.commons.sdk.util.ResourceTestUtil; |
| import org.eclipse.mylyn.context.core.ContextCore; |
| import org.eclipse.mylyn.context.core.IInteractionElement; |
| import org.eclipse.mylyn.context.sdk.java.WorkspaceSetupHelper; |
| import org.eclipse.mylyn.internal.mft.papyrus.ui.Uml2GmfStructureBridge; |
| import org.eclipse.mylyn.internal.mft.papyrus.ui.Uml2UiBridge; |
| import org.eclipse.mylyn.mft.emf.core.DomainModelContextStructureBridge; |
| import org.eclipse.mylyn.mft.emf.ui.DiagramUiEditingMonitor; |
| import org.eclipse.mylyn.mft.sdk.util.AbstractEmfContextTest; |
| import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.PlatformUI; |
| import org.eclipse.ui.part.FileEditorInput; |
| import org.eclipse.uml2.uml.internal.impl.ClassImpl; |
| |
| /** |
| * @author Miles Parker |
| */ |
| public class PapyrusDiagramEditorTest extends AbstractEmfContextTest { |
| |
| private static final String RESOURCE_URI = "platform:/resource/org.eclipse.mylyn.emf.tests.papyrus/model/model.uml#_xkh2ALJFEeCYupgj-BJj-Q"; //$NON-NLS-1$ |
| |
| protected DomainModelContextStructureBridge structureBridge; |
| |
| private IJavaProject papyrusProject; |
| |
| private DiagramUiEditingMonitor monitor; |
| |
| @Override |
| protected void setUp() throws Exception { |
| super.setUp(); |
| structureBridge = new Uml2GmfStructureBridge(); |
| monitor = new DiagramUiEditingMonitor(structureBridge, Uml2UiBridge.getInstance()); |
| String projectName = "org.eclipse.mylyn.modeling.tests.papyrus"; //$NON-NLS-1$ |
| papyrusProject = WorkspaceSetupHelper.createJavaPluginProjectFromDirectory( |
| CommonTestUtil.getFile(this, "testdata/" + projectName), projectName); //$NON-NLS-1$ |
| papyrusProject.open(new NullProgressMonitor()); |
| } |
| |
| public void testSelection() throws Exception { |
| |
| papyrusProject.open(new NullProgressMonitor()); |
| IProject project = papyrusProject.getProject(); |
| IFile file = project.getFile("model/model.di"); //$NON-NLS-1$ |
| assertNotNull(file); |
| |
| assertTrue(file.exists()); |
| FileEditorInput input = new FileEditorInput(file); |
| |
| IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| |
| PapyrusMultiDiagramEditor ed = (PapyrusMultiDiagramEditor) page.openEditor(input, |
| "org.eclipse.papyrus.infra.core.papyrusEditor"); |
| |
| System.out.println(ContextCore.getContextManager().getActiveContext().getAllElements()); |
| |
| String elemURI = RESOURCE_URI; |
| IInteractionElement element = ContextCore.getContextManager().getElement(elemURI); |
| assertNotNull(element); |
| assertFalse(element.getInterest().isInteresting()); |
| IInteractionElement iInteractionElement = ContextCore.getContextManager().getActiveContext().get(RESOURCE_URI); |
| assertFalse(iInteractionElement.getInterest().isInteresting()); |
| |
| TreeIterator<EObject> children = ed.getEditingDomain().getResourceSet().getResources().get(0).getAllContents(); |
| ClassImpl book = null; |
| while (children.hasNext()) { |
| EObject child = children.next(); |
| if (child instanceof Shape) { |
| ClassImpl candidate = (ClassImpl) ((Shape) child).getElement(); |
| if (candidate.getName().equals("Book")) { |
| book = candidate; |
| } |
| } |
| } |
| if (book == null) { |
| //This isn't a great solution, but we need to do something expedient to get build working and there is no local target that fails to test against. |
| System.err.println("Test-bed failure. (This does not neccessarily indicate an issue with papyrus support.)"); |
| } else { |
| List<?> findEditPartsForElement = ((DiagramEditor) ed.getActiveEditor()).getDiagramGraphicalViewer() |
| .findEditPartsForElement(EMFCoreUtil.getProxyID(book), ShapeEditPart.class); |
| |
| assertEquals(findEditPartsForElement.size(), 1); |
| StructuredSelection selection = new StructuredSelection(findEditPartsForElement); |
| monitor.handleWorkbenchPartSelection(ed, selection, true); |
| |
| Thread.sleep(5000); |
| |
| assertNotNull(element); |
| assertNotNull(element.getInterest()); |
| assertNotNull(iInteractionElement); |
| } |
| } |
| |
| @Override |
| protected void tearDown() throws Exception { |
| super.tearDown(); |
| ResourceTestUtil.deleteProject(papyrusProject.getProject()); |
| } |
| |
| } |