summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThibault Le Ouay2014-05-22 11:55:09 (EDT)
committerThibault Le Ouay2014-05-22 11:55:09 (EDT)
commitc09dbd51433930c1175215b2b1ddcd39afd808a6 (patch)
treed099db8e05c785dc5fea10c62f74cfc06974cad1
parent683d23471f2690d3c2383360364c0a5ec2c91a8f (diff)
downloadorg.eclipse.papyrus-c09dbd51433930c1175215b2b1ddcd39afd808a6.zip
org.eclipse.papyrus-c09dbd51433930c1175215b2b1ddcd39afd808a6.tar.gz
org.eclipse.papyrus-c09dbd51433930c1175215b2b1ddcd39afd808a6.tar.bz2
434839: [Wizards] Errors when creating a Papyrus Profile Model based onrefs/changes/23/27123/1
an existing.profile.uml https://bugs.eclipse.org/bugs/show_bug.cgi?id=434839 Fix issue due to other commit + test added Signed-off-by: Thibault Le Ouay <t.leouay@sherpa-eng.com>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/CreateModelWizard.java11
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/InitModelWizard.java63
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/resources/model.model.uml2
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/resources/model.uml2
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/AllTests.java6
-rw-r--r--tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/TestCreateModelFromExistingModelWizard.java175
6 files changed, 216 insertions, 43 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/CreateModelWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/CreateModelWizard.java
index debaef8..4549c75 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/CreateModelWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/CreateModelWizard.java
@@ -588,11 +588,12 @@ public class CreateModelWizard extends Wizard implements INewWizard {
* the category id
*/
protected void initDiagrams(ModelSet resourceSet, EObject root, String categoryId) {
- if (root == null) {
- UmlModel model = (UmlModel)resourceSet.getModel(UmlModel.MODEL_ID);
- EList<EObject> roots = model.getResource().getContents();
- if (!roots.isEmpty())
- root = roots.get(0);
+ //FIXME we cannot properly set the root object
+ UmlModel model = (UmlModel)resourceSet.getModel(UmlModel.MODEL_ID);
+ EList<EObject> roots = model.getResource().getContents();
+ if(!roots.isEmpty()) {
+
+ root = roots.get(0);
}
List<ViewPrototype> creationCommands = getPrototypesFor(categoryId);
String diagramName = selectDiagramKindPage.getDiagramName();
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/InitModelWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/InitModelWizard.java
index 2f1acea..c0d4dae 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/InitModelWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/InitModelWizard.java
@@ -1,7 +1,7 @@
/*****************************************************************************
* Copyright (c) 2010, 2013 CEA LIST.
*
- *
+ *
* 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
@@ -31,7 +31,7 @@ import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.ui.IWorkbench;
/**
- *
+ *
* The New Papyrus Model Wizard.
* If being invoke on the *.uml file - initializes a new Papyrus diagram for the selected domain model.
* If is selected is empty or in not uml - creates a new Papyrus Model.
@@ -48,10 +48,10 @@ public class InitModelWizard extends CreateModelWizard {
public boolean isInitModelWizard() {
return true;
}
-
+
/**
* Inits the.
- *
+ *
* @param workbench
* the workbench
* @param selection
@@ -71,7 +71,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Creates the select root element page.
- *
+ *
* @param selection
* the initial workbench selection
* @return the select root element page
@@ -86,7 +86,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Creates the select diagram kind page.
- *
+ *
* @return the select diagram kind page {@inheritDoc}
*/
@Override
@@ -105,7 +105,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Adds the pages.
- *
+ *
* {@inheritDoc}
*/
@Override
@@ -116,7 +116,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Returns true is the file can be served as a model model for the diagram.
- *
+ *
* @param file
* the file
* @return true, if is supported domain model file
@@ -124,26 +124,23 @@ public class InitModelWizard extends CreateModelWizard {
public static boolean isSupportedDomainModelFile(IFile file) {
// if(file != null && UmlModel.UML_FILE_EXTENSION.equals(file.getFileExtension())){System.err.println("is SupportedDomainModelFile");}
// else {System.err.println("not SupportedDomainModelFile");}
- return file != null
- && isSupportedDomainModelResource(URI.createPlatformResourceURI(
- file.getFullPath().toString(), true));
+ return file != null && isSupportedDomainModelResource(URI.createPlatformResourceURI(file.getFullPath().toString(), true));
}
/**
* Returns true if the resource can be served as a model model for the diagram.
- *
+ *
* @param uri
* the resource's URI
* @return true, if is supported domain model resource
*/
public static boolean isSupportedDomainModelResource(URI uri) {
- return (uri != null)
- && UmlModel.UML_FILE_EXTENSION.equals(uri.fileExtension());
+ return (uri != null) && UmlModel.UML_FILE_EXTENSION.equals(uri.fileExtension());
}
/**
* Checks if is supported domain model file.
- *
+ *
* @param sselection
* the sselection
* @return true, if is supported domain model file
@@ -155,7 +152,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Creates the papyrus models.
- *
+ *
* @param diResourceSet
* the di resource set
* @param newURI
@@ -164,8 +161,7 @@ public class InitModelWizard extends CreateModelWizard {
@Override
protected void createPapyrusModels(ModelSet modelSet, URI newURI) {
if(isCreateFromExistingDomainModel()) {
- RecordingCommand command = new PapyrusModelFromExistingDomainModelCommand(
- modelSet, newURI, getRoot());
+ RecordingCommand command = new PapyrusModelFromExistingDomainModelCommand(modelSet, newURI, getRoot());
getCommandStack(modelSet).execute(command);
} else {
super.createPapyrusModels(modelSet, newURI);
@@ -174,7 +170,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Inits the domain model.
- *
+ *
* @param diResourceSet
* the di resource set
* @param newURI
@@ -185,7 +181,8 @@ public class InitModelWizard extends CreateModelWizard {
@Override
protected void initDomainModel(ModelSet modelSet, final URI newURI, String diagramCategoryId) {
if(isCreateFromExistingDomainModel()) {
- // do nothing
+ //We force the creation of the di file
+ modelSet.createResource(newURI);
} else {
super.initDomainModel(modelSet, newURI, diagramCategoryId);
}
@@ -193,7 +190,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Inits the diagrams.
- *
+ *
* @param diResourceSet
* the di resource set
* @param categoryId
@@ -206,7 +203,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Checks if is creates the from existing domain model.
- *
+ *
* @return true, if is creates the from existing domain model
*/
public boolean isCreateFromExistingDomainModel() {
@@ -223,7 +220,7 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Gets the root.
- *
+ *
* @return the root
*/
private EObject getRoot() {
@@ -243,23 +240,21 @@ public class InitModelWizard extends CreateModelWizard {
/**
* Instantiates a new new diagram for existing model page.
- *
+ *
* @param selection
- * the selection
+ * the selection
* @param defaultFileName
- * the default file name
+ * the default file name
* @param modelKindName
- * the user-presentable (translatable) name of the kind of
- * model to create
+ * the user-presentable (translatable) name of the kind of
+ * model to create
* @param diagramExtension
- * the diagram extension
+ * the diagram extension
*/
- public NewDiagramForExistingModelPage(IStructuredSelection selection,
- String modelKindName, String defaultFileName,
- String diagramExtension) {
-
+ public NewDiagramForExistingModelPage(IStructuredSelection selection, String modelKindName, String defaultFileName, String diagramExtension) {
+
super(selection, modelKindName);
-
+
myDiagramFileName = defaultFileName;
setFileName(defaultFileName);
setFileExtension(diagramExtension);
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/resources/model.model.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/resources/model.model.uml
new file mode 100644
index 0000000..45c6c36
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/resources/model.model.uml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_AuibwODoEeOahKUgtNrIYg" name="model"/>
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/resources/model.uml b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/resources/model.uml
new file mode 100644
index 0000000..45c6c36
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/resources/model.uml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<uml:Model xmi:version="20131001" xmlns:xmi="http://www.omg.org/spec/XMI/20131001" xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_AuibwODoEeOahKUgtNrIYg" name="model"/>
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/AllTests.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/AllTests.java
index 09a5cd0..25a3d9e 100644
--- a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/AllTests.java
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/AllTests.java
@@ -1,6 +1,6 @@
/*****************************************************************************
* Copyright (c) 2010 CEA LIST.
- *
+ *
* 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
@@ -20,9 +20,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
// {oep}.uml.diagram.wizards
-TestCreateModelWizard.class, TestCreateSysMLModelWizard.class, TestInitModelWizard.class,
-TestNewProjectWizard.class, TestNewSysMLProjectWizard.class
-})
+TestCreateModelWizard.class, TestCreateSysMLModelWizard.class, TestInitModelWizard.class, TestNewProjectWizard.class, TestNewSysMLProjectWizard.class, TestCreateModelFromExistingModelWizard.class })
/**
* Suite Class for all tests in the plugin
*/
diff --git a/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/TestCreateModelFromExistingModelWizard.java b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/TestCreateModelFromExistingModelWizard.java
new file mode 100644
index 0000000..861d204
--- /dev/null
+++ b/tests/junit/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards.tests/test/org/eclipse/papyrus/uml/diagram/wizards/TestCreateModelFromExistingModelWizard.java
@@ -0,0 +1,175 @@
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Thibault Le Ouay (Sherpa Engineering) t.leouay@sherpa-eng.com - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.wizards;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+
+import java.io.IOException;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.junit.utils.PapyrusProjectUtils;
+import org.eclipse.papyrus.junit.utils.ProjectUtils;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramCategoryPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectDiagramKindPage;
+import org.eclipse.papyrus.uml.diagram.wizards.pages.SelectRootElementPage;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+
+public class TestCreateModelFromExistingModelWizard extends TestNewModelWizardBase {
+
+ //This test only covers the creation of the wizard and check if the first page contain the expected file name
+ private static IProject createProject;
+
+ private static IFile file, fileWithDot;
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.wizards.TestNewModelWizardBase#createWizard()
+ *
+ * @return
+ */
+
+ @BeforeClass
+ public static void init() {
+ try {
+ createProject = ProjectUtils.createProject("UMLOnlyTest");
+ } catch (CoreException e) {
+ Assert.fail(e.getMessage());
+ }
+
+ try {
+ file = PapyrusProjectUtils.copyIFile("/resources/model.uml", Platform.getBundle("org.eclipse.papyrus.uml.diagram.wizards.tests"), createProject, "model.uml");
+ fileWithDot = PapyrusProjectUtils.copyIFile("/resources/model.model.uml", Platform.getBundle("org.eclipse.papyrus.uml.diagram.wizards.tests"), createProject, "model.model.uml");
+
+ } catch (CoreException e) {
+ Assert.fail(e.getMessage());
+ } catch (IOException e) {
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ @Override
+ protected IWorkbenchWizard createWizard() {
+ return new InitModelWizard() {
+
+ private boolean isInitFromExistingDomainModel;
+
+ private SelectRootElementPage selectRootElementPage;
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
+ isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
+ super.init(workbench, selection);
+ selectRootElementPage = createSelectRootElementPage(selection);
+ if(isCreateFromExistingDomainModel()) {
+ // Init Model not Create a new one
+ setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
+ }
+ }
+
+ @Override
+ public boolean isCreateFromExistingDomainModel() {
+ return true;
+ }
+
+ };
+
+ }
+
+
+ @Test
+ public void testOrderOfPages() {
+ Class<?>[] expectedPages = new Class[]{ NewModelFilePage.class, SelectDiagramCategoryPage.class, SelectDiagramKindPage.class, SelectRootElementPage.class };
+
+ IWorkbenchWizard wizard = initWizardDialog();
+ testOrderOfPages(wizard, expectedPages);
+ }
+
+ @Test
+ public void testForSimpleModel() {
+ InitModelWizard wizard = new InitModelWizard() {
+
+ private boolean isInitFromExistingDomainModel;
+
+ private SelectRootElementPage selectRootElementPage;
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
+ isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
+ super.init(workbench, selection);
+ selectRootElementPage = createSelectRootElementPage(selection);
+ if(isCreateFromExistingDomainModel()) {
+ // Init Model not Create a new one
+ setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
+ }
+ }
+
+ @Override
+ public boolean isCreateFromExistingDomainModel() {
+ return true;
+ }
+
+ };
+ initWizardDialog(wizard);
+ NewModelFilePage page = getPage(wizard, NewModelFilePage.class);
+ assertEquals("model.di", page.getFileName());
+
+ }
+
+ @Test
+ public void testForModelWithDot() {
+ InitModelWizard wizard = new InitModelWizard() {
+
+ private boolean isInitFromExistingDomainModel;
+
+ private SelectRootElementPage selectRootElementPage;
+
+ @Override
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ URI uri = URI.createPlatformResourceURI(fileWithDot.getFullPath().toString(), true);
+ isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
+ super.init(workbench, selection);
+ selectRootElementPage = createSelectRootElementPage(selection);
+ if(isCreateFromExistingDomainModel()) {
+ // Init Model not Create a new one
+ setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
+ }
+ }
+
+ @Override
+ public boolean isCreateFromExistingDomainModel() {
+ return true;
+ }
+ };
+ initWizardDialog(wizard);
+ NewModelFilePage page = getPage(wizard, NewModelFilePage.class);
+ assertNotSame("model.model.di", page.getFileName());
+ //this should be fixed in the wizard to have the right name from the begining if the name contain a dot
+
+
+ }
+
+
+}