Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Le Menez2015-11-16 09:56:28 +0000
committerGerrit Code Review @ Eclipse.org2016-05-23 11:40:25 +0000
commitac4562521fbefe7fa5b7f42233ec14f8435b5c66 (patch)
tree1d65e605c72ebe6d1a9f64d441b8903a08c79380 /plugins/uml
parent82b647275de1c14cfd5769245877964e49464f92 (diff)
downloadorg.eclipse.papyrus-ac4562521fbefe7fa5b7f42233ec14f8435b5c66.tar.gz
org.eclipse.papyrus-ac4562521fbefe7fa5b7f42233ec14f8435b5c66.tar.xz
org.eclipse.papyrus-ac4562521fbefe7fa5b7f42233ec14f8435b5c66.zip
Bug 482249: [Wizard Template] Applying a Template to a newly created model causes an Out of Bound Exception
https://bugs.eclipse.org/bugs/show_bug.cgi?id=482249 - Added conditions checking on both classes (rebase) Change-Id: Ib60dd8d0d3e72d2ff014f6685452fd72913645e8 Signed-off-by: Quentin Le Menez <quentin.lemenez@cea.fr>
Diffstat (limited to 'plugins/uml')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java7
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.templaterepository/build.properties6
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.templaterepository/plugin.xml4
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.templaterepository/resource/ModelWithBasicTypes.uml6
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.templaterepository/resource/ProfileWithBasicTypes.profile.uml9
-rwxr-xr-xplugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypes.java (renamed from plugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypesInModel.java)57
-rwxr-xr-xplugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypesInProfile.java103
7 files changed, 40 insertions, 152 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java
index 64da2dc5b6a..2b27c9b3415 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/CreateModelWizard.java
@@ -46,7 +46,6 @@ import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.papyrus.infra.core.editor.BackboneException;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.infra.core.resource.NotFoundException;
import org.eclipse.papyrus.infra.core.resource.sasheditor.DiModelUtils;
import org.eclipse.papyrus.infra.core.sashwindows.di.service.IPageManager;
import org.eclipse.papyrus.infra.core.services.ExtensionServicesRegistry;
@@ -307,7 +306,11 @@ public class CreateModelWizard extends Wizard implements INewWizard {
initDiagramModel(modelSet, diagramCategoryId);
initProfile(modelSet);
+
initTemplate(modelSet);
+
+ saveDiagram(modelSet);
+
openDiagram(newURI);
} catch (ServiceException e) {
@@ -330,7 +333,6 @@ public class CreateModelWizard extends Wizard implements INewWizard {
boolean isToApplyProfile = selectDiagramKindPage.getProfileURI() != null;
if (isToApplyProfile) {
applyProfile(modelSet);
- saveDiagram(modelSet);
}
}
@@ -624,7 +626,6 @@ public class CreateModelWizard extends Wizard implements INewWizard {
*/
protected void initDiagramModel(ModelSet modelSet, String categoryId) {
initDiagrams(modelSet, categoryId);
- saveDiagram(modelSet);
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/build.properties b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/build.properties
index 2127292eda0..27d1be4c443 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/build.properties
+++ b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/build.properties
@@ -1,6 +1,10 @@
#
#Mon Sep 12 09:30:20 CEST 2011
-bin.includes=META-INF/,.,plugin.xml,resource/,about.html,plugin.properties
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ about.html,\
+ plugin.properties
output..=bin/
src.includes = about.html
source..=src/
diff --git a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/plugin.xml b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/plugin.xml
index 5a3531d5f23..a8d09e1bcb2 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/plugin.xml
+++ b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/plugin.xml
@@ -4,14 +4,14 @@
<extension
point="org.eclipse.papyrus.uml.diagram.wizards.templates">
<transformation
- Transformation="org.eclipse.papyrus.uml.templaterepository.ImportUMLPrimitiveTypesInModel"
+ Transformation="org.eclipse.papyrus.uml.templaterepository.ImportUMLPrimitiveTypes"
id="org.eclipse.papyrus.uml.templaterepository.ImportUMLPrimitiveTypesInModel"
language="uml"
name="A UML model with basic primitive types">
</transformation>
<transformation
- Transformation="org.eclipse.papyrus.uml.templaterepository.ImportUMLPrimitiveTypesInProfile"
+ Transformation="org.eclipse.papyrus.uml.templaterepository.ImportUMLPrimitiveTypes"
id="org.eclipse.papyrus.uml.templaterepository.ImportUMLPrimitiveTypesInProfile"
language="profile"
name="A UML profile with basic primitive types">
diff --git a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/resource/ModelWithBasicTypes.uml b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/resource/ModelWithBasicTypes.uml
deleted file mode 100644
index daea222ff6f..00000000000
--- a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/resource/ModelWithBasicTypes.uml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_xRouMOTjEd6E-IWFQ_MzPA" name="Model">
- <packageImport xmi:id="_F2B_UOTkEd6E-IWFQ_MzPA">
- <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
- </packageImport>
-</uml:Model>
diff --git a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/resource/ProfileWithBasicTypes.profile.uml b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/resource/ProfileWithBasicTypes.profile.uml
deleted file mode 100644
index 77d36c7e0f0..00000000000
--- a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/resource/ProfileWithBasicTypes.profile.uml
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<uml:Profile xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="_J1ZicOTlEd6E-IWFQ_MzPA" name="Profile" metamodelReference="_Wrz0MOTlEd6E-IWFQ_MzPA">
- <packageImport xmi:id="_Wrz0MOTlEd6E-IWFQ_MzPA">
- <importedPackage xmi:type="uml:Model" href="pathmap://UML_METAMODELS/UML.metamodel.uml#_0"/>
- </packageImport>
- <packageImport xmi:id="_cIW8cOTlEd6E-IWFQ_MzPA">
- <importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
- </packageImport>
-</uml:Profile>
diff --git a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypesInModel.java b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypes.java
index 21e52792217..d6ad39b5227 100755
--- a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypesInModel.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypes.java
@@ -11,9 +11,6 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.templaterepository;
-import java.io.IOException;
-import java.util.Collections;
-
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
@@ -21,14 +18,11 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.uml.diagram.wizards.transformation.IGenerator;
-//import org.eclipse.papyrus.uml.tools.model.UmlModel;
import org.eclipse.papyrus.uml.tools.model.UmlUtils;
-import org.eclipse.uml2.uml.PackageImport;
-
-//import org.eclipse.uml2.uml.UMLFactory;
+import org.eclipse.uml2.uml.Package;
-public class ImportUMLPrimitiveTypesInModel implements IGenerator {
+public class ImportUMLPrimitiveTypes implements IGenerator {
// This class is used when the element is checked inside SelectModelTemplateComposite's templateTableViewer
private ModelSet modelSet;
@@ -37,43 +31,50 @@ public class ImportUMLPrimitiveTypesInModel implements IGenerator {
private EObject primitiveTypes;
+ private EObject umlMetamodel;
public void execute() {
- // Get the umlModel from the modelSet
- // UmlModel umlModel = (UmlModel) modelSet.getModel(UmlModel.MODEL_ID);
- // Get its resource
- // Resource umlResource = umlModel.getResource();
Resource umlResource = UmlUtils.getUmlModel(modelSet).getResource();
// Select the root element to add the wanted imports
- rootElement = (org.eclipse.uml2.uml.Model) umlResource.getContents().get(0);
+ if (umlResource.getContents().isEmpty()) {
+ return;
+ }
- // Load the needed libraries. Calling them directly with the path renders the resource folder obsolete ?
- URI primitiveTypesURI = URI.createURI("pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml").appendFragment("_0");
+ // Always required
+ URI primitiveTypesURI = URI.createURI("pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml", true).appendFragment("_0");
primitiveTypes = modelSet.getEObject(primitiveTypesURI, true);
+ rootElement = (Package) umlResource.getContents().get(0);
+
+ if (umlResource.getContents().get(0) instanceof org.eclipse.uml2.uml.Profile) {
+ URI umlMetamodelURI = URI.createURI("pathmap://UML_METAMODELS/UML.metamodel.uml", true).appendFragment("_0");
+ umlMetamodel = modelSet.getEObject(umlMetamodelURI, true);
+ }
// Creates the import packages at the root of the model (elements of type packageImport)
- this.getCommandStack(modelSet).execute(new RecordingCommand(modelSet.getTransactionalEditingDomain()) {
+ this.getCommandStack(modelSet).execute(getImportCommand());
+
+ }
+
+ private RecordingCommand getImportCommand() {
+ return new RecordingCommand(this.modelSet.getTransactionalEditingDomain()) {
@Override
protected void doExecute() {
- // PackageImport packageImport = UMLFactory.eINSTANCE.createPackageImport();
- // packageImport.setImportedPackage((org.eclipse.uml2.uml.Package) ImportUMLPrimitiveTypesInModel.this.primitiveTypes);
- // rootElement.getPackageImports().add(packageImport);
- PackageImport importPrimitivePack = rootElement.createPackageImport((org.eclipse.uml2.uml.Package) primitiveTypes);
- if (!rootElement.getPackageImports().contains(importPrimitivePack)) {
- rootElement.getPackageImports().add(importPrimitivePack);
+ // Creates the import packages at the root of the model (elements of type packageImport)
+ if (!rootElement.getImportedPackages().contains(primitiveTypes)) {
+ rootElement.createPackageImport((org.eclipse.uml2.uml.Package) primitiveTypes);
}
- try {
- rootElement.eResource().save(Collections.EMPTY_MAP);
- } catch (IOException e) {
- Activator.log.error(e);
+ if (umlMetamodel != null) {
+ if (!rootElement.getImportedPackages().contains(umlMetamodel)) {
+ rootElement.createPackageImport((org.eclipse.uml2.uml.Package) umlMetamodel);
+ }
}
- }
- });
+ }
+ };
}
/**
diff --git a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypesInProfile.java b/plugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypesInProfile.java
deleted file mode 100755
index 521bf6d5100..00000000000
--- a/plugins/uml/org.eclipse.papyrus.uml.templaterepository/src/org/eclipse/papyrus/uml/templaterepository/ImportUMLPrimitiveTypesInProfile.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2015 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:
- * Quentin Le Menez quentin.lemenez@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.templaterepository;
-
-import java.io.IOException;
-import java.util.Collections;
-
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.papyrus.infra.core.resource.ModelSet;
-import org.eclipse.papyrus.uml.diagram.wizards.transformation.IGenerator;
-//import org.eclipse.papyrus.uml.tools.model.UmlModel;
-import org.eclipse.papyrus.uml.tools.model.UmlUtils;
-import org.eclipse.uml2.uml.PackageImport;
-
-
-public class ImportUMLPrimitiveTypesInProfile implements IGenerator {
- // This class is used when the element is checked inside SelectModelTemplateComposite's templateTableViewer
-
- private ModelSet modelSet;
-
- private org.eclipse.uml2.uml.Package rootElement;
-
- private EObject primitiveTypes;
-
- private EObject umlMetamodel;
-
- public void execute() {
- // Get the umlModel from the modelSet
- // UmlModel umlModel = (UmlModel) modelSet.getModel(UmlModel.MODEL_ID);
- // Get its resource
- // Resource umlResource = umlModel.getResource();
- Resource umlResource = UmlUtils.getUmlModel(modelSet).getResource();
-
- // Select the root element to add the wanted imports
- rootElement = (org.eclipse.uml2.uml.Profile) umlResource.getContents().get(0);
-
- // Load the needed libraries. Calling them directly with the path renders the resource folder obsolete ?
- URI primitiveTypesURI = URI.createURI("pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml", true).appendFragment("_0");
- primitiveTypes = modelSet.getEObject(primitiveTypesURI, true);
- URI umlMetamodelURI = URI.createURI("pathmap://UML_METAMODELS/UML.metamodel.uml", true).appendFragment("_0");
- umlMetamodel = modelSet.getEObject(umlMetamodelURI, true);
-
- // Creates the import packages at the root of the model (elements of type packageImport)
- this.getCommandStack(modelSet).execute(new RecordingCommand(modelSet.getTransactionalEditingDomain()) {
-
- @Override
- protected void doExecute() {
- // PackageImport packageImport = UMLFactory.eINSTANCE.createPackageImport();
- // packageImport.setImportedPackage((org.eclipse.uml2.uml.Package) ImportUMLPrimitiveTypesInModel.this.primitiveTypes);
- // rootElement.getPackageImports().add(packageImport);
-
- // Creates the import packages at the root of the model (elements of type packageImport)
- PackageImport importPrimitivePack = rootElement.createPackageImport((org.eclipse.uml2.uml.Package) primitiveTypes);
- PackageImport importMetamodelPack = rootElement.createPackageImport((org.eclipse.uml2.uml.Package) umlMetamodel);
-
- if (!rootElement.getPackageImports().contains(importPrimitivePack)) {
- rootElement.getPackageImports().add(importPrimitivePack);
- }
- if (!rootElement.getPackageImports().contains(importMetamodelPack)) {
- rootElement.getPackageImports().add(importMetamodelPack);
- }
-
- try {
- rootElement.eResource().save(Collections.EMPTY_MAP);
- } catch (IOException e) {
- Activator.log.error(e);
- }
- }
- });
-
- }
-
- /**
- * @see org.eclipse.papyrus.uml.diagram.wizards.transformation.IGenerator#setModelSet(org.eclipse.papyrus.uml.diagram.wizards.transformation.ModelSet)
- *
- * @param modelSet
- */
- public void setModelSet(ModelSet modelSet) {
- this.modelSet = modelSet;
- }
-
- protected final CommandStack getCommandStack(ModelSet modelSet) {
- return modelSet.getTransactionalEditingDomain().getCommandStack();
- }
-
- public ModelSet getModelSet() {
- return this.modelSet;
- }
-
-}

Back to the top