diff options
author | Martin Fluegge | 2010-12-29 18:51:28 +0000 |
---|---|---|
committer | Martin Fluegge | 2010-12-29 18:51:28 +0000 |
commit | 516b3e1d53e30274c53c95bb393daed418efd000 (patch) | |
tree | 5ebfeed003cf3b6704fcd3a61d38dd830be10217 | |
parent | 023b6362edd531cf241e5ffeb792944108df615a (diff) | |
download | cdo-516b3e1d53e30274c53c95bb393daed418efd000.tar.gz cdo-516b3e1d53e30274c53c95bb393daed418efd000.tar.xz cdo-516b3e1d53e30274c53c95bb393daed418efd000.zip |
[333291] [Dawn] Provide extension for Ecore Editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=333291
7 files changed, 318 insertions, 10 deletions
diff --git a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/AbstractDawnUITest.java b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/AbstractDawnUITest.java index 0e97ce089f..8fa25d3b0b 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/AbstractDawnUITest.java +++ b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/AbstractDawnUITest.java @@ -46,7 +46,7 @@ public abstract class AbstractDawnUITest<T extends SWTWorkbenchBot> extends Abst SWTBotPreferences.SCREENSHOTS_DIR = DawnTestPlatform.instance.getTestFolder(); resetWorkbench(); DawnSWTBotUtil.initTest(getBot()); - getBot().viewByTitle("CDO Sessions").close(); + // getBot().viewByTitle("CDO Sessions").close(); } /** diff --git a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/AllTestsDawnUISWTBot.java b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/AllTestsDawnUISWTBot.java index 92104fbbbf..d64d326866 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/AllTestsDawnUISWTBot.java +++ b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/AllTestsDawnUISWTBot.java @@ -11,6 +11,7 @@ package org.eclipse.emf.cdo.dawn.tests; import org.eclipse.emf.cdo.dawn.tests.bugzillas.Bugzilla_321024_Test; +import org.eclipse.emf.cdo.dawn.tests.bugzillas.Bugzilla_333291_Test; import org.eclipse.emf.cdo.dawn.tests.ui.DawnPreferencesTest; import org.eclipse.emf.cdo.dawn.tests.ui.DawnProjectExplorerTest; import org.eclipse.emf.cdo.dawn.tests.ui.emf.DawnEMFCreationWizardTest; @@ -44,7 +45,7 @@ public class AllTestsDawnUISWTBot extends ConfigTestSuite { addScenario(parent, COMBINED, MEM, TCP, NATIVE); addScenario(parent, COMBINED, MEM_BRANCHES, TCP, NATIVE); - addScenario(parent, COMBINED, MEM_BRANCHES, TCP, LEGACY); + addScenario(parent, COMBINED, MEM, TCP, LEGACY); addScenario(parent, COMBINED, MEM_BRANCHES, TCP, LEGACY); } @@ -68,5 +69,6 @@ public class AllTestsDawnUISWTBot extends ConfigTestSuite /******************** Bugzilla **********************/ testClasses.add(Bugzilla_321024_Test.class); + testClasses.add(Bugzilla_333291_Test.class); } } diff --git a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/bugzillas/Bugzilla_333291_Test.java b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/bugzillas/Bugzilla_333291_Test.java new file mode 100644 index 0000000000..c83aa0433d --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/bugzillas/Bugzilla_333291_Test.java @@ -0,0 +1,140 @@ +/** + * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others. + * 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.tests.bugzillas; + +import org.eclipse.emf.cdo.dawn.preferences.PreferenceConstants; +import org.eclipse.emf.cdo.dawn.tests.AbstractDawnEMFTest; +import org.eclipse.emf.cdo.dawn.tests.ui.util.DawnEMFEditorBot; +import org.eclipse.emf.cdo.dawn.tests.ui.util.DawnEcoreTestUtil; +import org.eclipse.emf.cdo.dawn.tests.ui.util.DawnSWTBotEMFEditor; +import org.eclipse.emf.cdo.dawn.tests.ui.util.DawnSWTBotUtil; +import org.eclipse.emf.cdo.dawn.util.connection.CDOConnectionUtil; +import org.eclipse.emf.cdo.eresource.CDOResource; +import org.eclipse.emf.cdo.session.CDOSession; +import org.eclipse.emf.cdo.transaction.CDOTransaction; +import org.eclipse.emf.cdo.view.CDOView; + +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.EcoreFactory; + +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; + +import org.junit.Before; +import org.junit.runner.RunWith; + +/** + * @author Martin Fluegge + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class Bugzilla_333291_Test extends AbstractDawnEMFTest +{ + @Override + @Before + public void setUp() throws Exception + { + setBot(new DawnEMFEditorBot()); + DawnSWTBotUtil.initTest(getBot()); + super.setUp(); + } + + public void testCreateNewDawnEcoreEditor() throws Exception + { + SWTBotEditor editor = DawnEcoreTestUtil.openNewEcoreEMFEditor("default.ecore", getBot()); + assertNotNull(editor); + editor.close(); + { + assertEquals(true, resourceExists("/default.ecore")); + } + } + + public void testOpenExistingResource() throws Exception + { + { + CDOSession session = openSession(); + CDOTransaction transaction = session.openTransaction(); + CDOResource resource = transaction.createResource("/default.ecore"); + EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage(); + ePackage.setName("myPackage"); + ePackage.setNsPrefix("prefix"); + ePackage.setNsURI("http://testURI/2010"); + resource.getContents().add(ePackage); + + EClass aClass = EcoreFactory.eINSTANCE.createEClass(); + aClass.setName("MyClass"); + + ePackage.getEClassifiers().add(aClass); + + transaction.commit(); + transaction.close(); + session.close(); + } + + CDOConnectionUtil.instance.init(PreferenceConstants.getRepositoryName(), PreferenceConstants.getProtocol(), + PreferenceConstants.getServerName()); + CDOConnectionUtil.instance.openSession(); + DawnSWTBotEMFEditor editor = DawnEcoreTestUtil.openEcoreEMFEditor(URI.createURI("cdo://repo1/default.ecore"), + getBot()); + assertNotNull(editor); + SWTBotTree tree = editor.getSelectionPageTree(); + + sleep(1000); + + SWTBotTreeItem treeItem = tree.getTreeItem("cdo://repo1/default.ecore"); + treeItem.expand(); + + SWTBotTreeItem root = treeItem.getItems()[0]; + assertEquals("myPackage", root.getText()); + root.expand(); + + SWTBotTreeItem swtBotTreeItem1 = root.getItems()[0]; + assertEquals("MyClass", swtBotTreeItem1.getText()); + + editor.save(); + + editor.close(); + } + + public void testCreateNewPackage() throws Exception + { + DawnSWTBotEMFEditor editor = DawnEcoreTestUtil.openNewEcoreEMFEditor("default.ecore", getBot()); + assertNotNull(editor); + + SWTBotTree tree = editor.getSelectionPageTree(); + + SWTBotTreeItem item = selectFolder(tree.getAllItems(), "", true); + + editor.clickContextMenu(tree.widget, "EClass"); + editor.clickContextMenu(tree.widget, "EData Type"); + editor.clickContextMenu(tree.widget, "EAnnotation"); + editor.clickContextMenu(tree.widget, "EPackage"); + editor.save(); + + { + CDOSession session = openSession(); + CDOView view = session.openView(); + CDOResource resource = view.getResource("/default.ecore"); + EPackage ePackage = (EPackage)resource.getContents().get(0); + + assertEquals(2, ePackage.getEClassifiers().size()); + assertEquals(1, ePackage.getESubpackages().size()); + } + + editor.close(); + { + assertEquals(true, resourceExists("/default.ecore")); + } + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/emf/DawnEMFCreationWizardTest.java b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/emf/DawnEMFCreationWizardTest.java index 34c3d9ab81..94ef54836a 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/emf/DawnEMFCreationWizardTest.java +++ b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/emf/DawnEMFCreationWizardTest.java @@ -46,7 +46,7 @@ public class DawnEMFCreationWizardTest extends AbstractDawnEMFTest SWTBotShell shell = getBot().shell("New"); shell.activate(); - getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATTION_WIZARD_NAME_EMF); + getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF); getBot().button("Next >").click(); getBot().button("Next >").click(); @@ -76,7 +76,7 @@ public class DawnEMFCreationWizardTest extends AbstractDawnEMFTest SWTBotShell shell = getBot().shell("New"); shell.activate(); - getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATTION_WIZARD_NAME_EMF); + getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF); getBot().button("Next >").click(); shell = getBot().shell("New"); @@ -106,7 +106,7 @@ public class DawnEMFCreationWizardTest extends AbstractDawnEMFTest SWTBotShell shell = getBot().shell("New"); shell.activate(); - getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATTION_WIZARD_NAME_EMF); + getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF); getBot().button("Next >").click(); shell = getBot().shell("New"); @@ -140,7 +140,7 @@ public class DawnEMFCreationWizardTest extends AbstractDawnEMFTest SWTBotShell shell = getBot().shell("New"); shell.activate(); - getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATTION_WIZARD_NAME_EMF); + getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF); getBot().button("Next >").click(); shell = getBot().shell("New"); @@ -187,7 +187,7 @@ public class DawnEMFCreationWizardTest extends AbstractDawnEMFTest SWTBotShell shell = getBot().shell("New"); shell.activate(); - getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATTION_WIZARD_NAME_EMF); + getBot().tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF); getBot().button("Next >").click(); shell = getBot().shell("New"); diff --git a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnAcoreTestUtil.java b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnAcoreTestUtil.java index 92ab272e2b..cf6c8d690c 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnAcoreTestUtil.java +++ b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnAcoreTestUtil.java @@ -75,9 +75,9 @@ public class DawnAcoreTestUtil public static final String CONNECTION_COMPOSITION = "composition"; - public static final String CREATTION_WIZARD_NAME_GMF = "Dawn Acore Diagram"; + public static final String CREATION_WIZARD_NAME_GMF = "Dawn Acore Diagram"; - public static final String CREATTION_WIZARD_NAME_EMF = "Dawn Acore Model"; + public static final String CREATION_WIZARD_NAME_EMF = "Dawn Acore Model"; private static IViewProvider viewProvider = new AcoreViewProvider(); @@ -126,7 +126,7 @@ public class DawnAcoreTestUtil SWTBotShell shell = bot.shell("New"); shell.activate(); - bot.tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATTION_WIZARD_NAME_EMF); + bot.tree().expandNode("Dawn Examples").select(DawnAcoreTestUtil.CREATION_WIZARD_NAME_EMF); bot.button("Next >").click(); shell = bot.shell("New"); diff --git a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnEcoreTestUtil.java b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnEcoreTestUtil.java new file mode 100644 index 0000000000..e39de47dd3 --- /dev/null +++ b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnEcoreTestUtil.java @@ -0,0 +1,149 @@ +/** + * Copyright (c) 2010 Martin Fluegge (Berlin, Germany) and others. + * 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: + * Martin Fluegge - initial API and implementation + */ +package org.eclipse.emf.cdo.dawn.tests.ui.util; + +import org.eclipse.emf.cdo.dawn.appearance.DawnAppearancer; +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AClassEditPart; +import org.eclipse.emf.cdo.dawn.examples.acore.diagram.edit.parts.AInterfaceEditPart; +import org.eclipse.emf.cdo.dawn.ui.DawnEditorInput; +import org.eclipse.emf.cdo.dawn.ui.helper.EditorDescriptionHelper; + +import org.eclipse.emf.common.util.URI; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.LineBorder; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.swtbot.eclipse.gef.finder.SWTGefBot; +import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefEditor; +import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; +import org.eclipse.swtbot.swt.finder.results.VoidResult; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +/** + * @author Martin Fluegge + */ +public class DawnEcoreTestUtil +{ + public static final String CREATION_WIZARD_NAME_GMF = "Dawn Ecore Diagram"; + + public static final String CREATION_WIZARD_NAME_EMF = "Dawn Ecore Model"; + + public static SWTBotGefEditor openNewEcoreGMFEditor(String diagramResourceName, SWTGefBot bot) + { + bot.menu("File").menu("New").menu("Other...").click(); + + SWTBotShell shell = bot.shell("New"); + shell.activate(); + bot.tree().expandNode("Dawn Examples").select(CREATION_WIZARD_NAME_GMF); + bot.button("Next >").click(); + bot.button("Finish").click(); + SWTBotGefEditor editor = bot.gefEditor(diagramResourceName); + return editor; + } + + public static DawnSWTBotEMFEditor openEcoreEMFEditor(URI resourceURI, DawnEMFEditorBot bot) + { + String resourceName = resourceURI.lastSegment(); + final String editorID = EditorDescriptionHelper.getEditorIdForDawnEditor(resourceName); + + final DawnEditorInput editorInput = new DawnEditorInput(resourceURI); + + UIThreadRunnable.asyncExec(new VoidResult() + { + public void run() + { + try + { + PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite().getPage() + .openEditor(editorInput, editorID); + } + catch (PartInitException ex) + { + throw new RuntimeException(ex); + } + } + }); + + return bot.emfEditor(resourceName); + } + + public static DawnSWTBotEMFEditor openNewEcoreEMFEditor(String resourceName, DawnEMFEditorBot bot) + { + bot.menu("File").menu("New").menu("Other...").click(); + + SWTBotShell shell = bot.shell("New"); + shell.activate(); + bot.tree().expandNode("Dawn Examples").select(DawnEcoreTestUtil.CREATION_WIZARD_NAME_EMF); + bot.button("Next >").click(); + + shell = bot.shell("New"); + shell.activate(); + + SWTBotText fileSemanticNameLabel = bot.textWithLabel("File name:"); + fileSemanticNameLabel.setText(resourceName); + + bot.button("Next >").click(); + + SWTBotCombo comboBox = bot.comboBox(0);// bot.ccomboBox(0); + comboBox.setFocus(); + comboBox.setSelection("EPackage"); + + bot.button("Finish").click(); + + return bot.emfEditor(resourceName); + } + + // public static List<SWTBotGefEditPart> getEClassEditParts(SWTBotGefEditor editor) + // { + // List<SWTBotGefEditPart> editParts = editor.editParts(new AbstractMatcher<EClassEditPart>() + // { + // @Override + // protected boolean doMatch(Object item) + // { + // return item instanceof AClassEditPart; + // } + // + // public void describeTo(Description description) + // { + // } + // }); + // return editParts; + // } + + public static void sleep(int seconds) + { + try + { + Thread.sleep(seconds); + } + catch (InterruptedException ex) + { + throw new RuntimeException(ex); + } + } + + public static boolean showsConflict(EditPart editPart) + { + if (editPart instanceof AClassEditPart || editPart instanceof AInterfaceEditPart) + { + GraphicalEditPart e = (GraphicalEditPart)editPart; + + IFigure figure = e.getFigure(); + return ((LineBorder)figure.getBorder()).getColor().equals(DawnAppearancer.COLOR_DELETE_CONFLICT); + } + return false; + } +} diff --git a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnSWTBotEMFEditor.java b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnSWTBotEMFEditor.java index 65230df066..2f41028098 100644 --- a/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnSWTBotEMFEditor.java +++ b/plugins/org.eclipse.emf.cdo.dawn.tests/src/org/eclipse/emf/cdo/dawn/tests/ui/util/DawnSWTBotEMFEditor.java @@ -13,11 +13,13 @@ package org.eclipse.emf.cdo.dawn.tests.ui.util; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; import org.eclipse.swtbot.eclipse.gef.finder.widgets.SWTBotGefContextMenu; import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; 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.part.MultiPageEditorPart; @@ -241,4 +243,19 @@ public class DawnSWTBotEMFEditor extends SWTBotEditor } return method; } + + public void setText(final SWTBotTreeItem item, final String text) + { + MultiPageEditorPart editor = (MultiPageEditorPart)getReference().getEditor(false); + Display display = editor.getEditorSite().getShell().getDisplay(); + + display.asyncExec(new Runnable() + { + + public void run() + { + item.widget.setData(text); + } + }); + } } |