Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Le Menez2015-06-10 14:16:23 +0000
committerCamille Letavernier2015-06-10 16:49:37 +0000
commita1fbe82759f4287b5f6f0df9ad86625eb331a13c (patch)
tree8e5113a12608a9a014591465d26ab83e22954c26
parentbaf3e23fe043af3b1b691ef18ce61d3d12809283 (diff)
downloadorg.eclipse.papyrus-a1fbe82759f4287b5f6f0df9ad86625eb331a13c.tar.gz
org.eclipse.papyrus-a1fbe82759f4287b5f6f0df9ad86625eb331a13c.tar.xz
org.eclipse.papyrus-a1fbe82759f4287b5f6f0df9ad86625eb331a13c.zip
Bug 469830: [Profiles] Mars Regression - Do not rename selected/named
profile package to RootElement on profile model creation https://bugs.eclipse.org/bugs/show_bug.cgi?id=469830 - added a default root naming when creating a new profile from an existing model of the workspace - disabled the selectRootElementPage - fix the NPEs resulting from the disabled page Change-Id: Icea1094e5d7fac4d333e7d42af9f6926ef0cddba Signed-off-by: Quentin Le Menez <quentin.lemenez@cea.fr> Also-by: Camille Letavernier <camille.letavernier@cea.fr> Reviewed-on: https://git.eclipse.org/r/49925 Reviewed-by: Camille Letavernier <camille.letavernier@cea.fr> Tested-by: Camille Letavernier <camille.letavernier@cea.fr>
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties8
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramKindPage.java49
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java54
4 files changed, 86 insertions, 27 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java
index 88301b63cc7..e13519810b3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/Messages.java
@@ -130,6 +130,8 @@ public class Messages extends NLS {
/** The Select diagram kind page_select_kind_group. */
public static String SelectDiagramKindPage_select_kind_group;
+ public static String SelectDiagramKindPage_Set_Root_Name_Error;
+
/** The Select root element page_select_root_element_desc. */
public static String SelectRootElementPage_select_root_element_desc;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties
index c3db50ee148..80954722255 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/messages/messages.properties
@@ -43,11 +43,13 @@ NewModelFilePage_default_diagram_name=model
NewModelFilePage_diagram_file_was_renamed=Thus, the diagram file has been renamed from {0} to {1}
NewModelFilePage_new_diagram_category_needs_specific_extension=The new diagram category requires a specific diagram file extension.
NewModelFilePage_page_desc=Create a new {0} model
-NewModelFilePage_page_same_case_desc=There already is a model with this name:
+NewModelFilePage_page_same_case_desc=There already is a model with this name:
+
SelectDiagramCategoryPage_cannot_find_category=Could not find DiagramCategory for {0}
SelectDiagramCategoryPage_diagram_language_group=Diagram Language:
SelectDiagramCategoryPage_select_language=Select the language of the new diagrams
SelectDiagramCategoryPage_select_one_category=Please select at least one category
+
SelectDiagramKindPage_0=Choose a profile to apply
SelectDiagramKindPage_default_diagram_name=RootElement
SelectDiagramKindPage_diagram_name_group=Root model element name :
@@ -58,8 +60,11 @@ SelectDiagramKindPage_page_title=Initialization information
SelectDiagramKindPage_remember_current_selection_text=Remember current selection
SelectDiagramKindPage_remember_current_selection_tooltip=The current selection will be used when you open the wizard next time
SelectDiagramKindPage_select_kind_group=Select a Diagram Kind:
+SelectDiagramKindPage_Set_Root_Name_Error=The Root model element name cannot be deduced from the current workspace selection
+
SelectRootElementPage_select_root_element_desc=Select the root element
SelectRootElementPage_select_root_element_title=Select the root element
+
SelectStorageProviderPage_0=Model Storage
SelectStorageProviderPage_1=Select the kind of storage for the new model.
SelectStorageProviderPage_2=Where would you like to store the new model?
@@ -73,6 +78,7 @@ ModelCopyWizard_CopyModel=Copy model
ModelCopyWizard_CreatePapyrusExample=Create Papyrus example
ModelCopyWizard_DoNotChangeFileName=Do not change file name (will be ignored)
ModelCopyWizard_SelectParentFolder=Select parent folder for example "%s"
+
PapyrusProjectCreationPage_0=Model file name :
PapyrusProjectCreationPage_1=model
PapyrusProjectCreationPage_3=Set model file name
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramKindPage.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramKindPage.java
index afc635ab9d4..a9f800ca47c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramKindPage.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/pages/SelectDiagramKindPage.java
@@ -15,12 +15,22 @@ package org.eclipse.papyrus.uml.diagram.wizards.pages;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.papyrus.commands.CreationCommandRegistry;
import org.eclipse.papyrus.commands.ICreationCommandRegistry;
import org.eclipse.papyrus.infra.viewpoints.configuration.Category;
import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.uml.diagram.wizards.Activator;
import org.eclipse.papyrus.uml.diagram.wizards.kind.DiagramKindComposite;
import org.eclipse.papyrus.uml.diagram.wizards.kind.DiagramKindLabelProvider;
import org.eclipse.papyrus.uml.diagram.wizards.messages.Messages;
@@ -36,6 +46,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.uml2.uml.NamedElement;
/**
* This WizardPage to select the kind of Papyrus Diagram. List all kind of diagrams registered with
@@ -69,6 +80,8 @@ public class SelectDiagramKindPage extends WizardPage {
private FileChooser filechooser;
+ private static EObject modelRoot;
+
/** The Constant DEFAULT_CREATION_COMMAND_REGISTRY. */
public static final ICreationCommandRegistry DEFAULT_CREATION_COMMAND_REGISTRY = CreationCommandRegistry.getInstance(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
@@ -141,7 +154,7 @@ public class SelectDiagramKindPage extends WizardPage {
/**
* Create the filechooser composite
- *
+ *
* @param parent
*/
private void createProfileFileChooser(Composite parent) {
@@ -342,6 +355,37 @@ public class SelectDiagramKindPage extends WizardPage {
nameText = new Text(group, SWT.BORDER);
nameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
nameText.setText(Messages.SelectDiagramKindPage_default_diagram_name);
+
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ if (selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() > 0) {
+ IStructuredSelection sSelection = (IStructuredSelection) selection;
+ Object selectedObject = sSelection.getFirstElement();
+
+ // Should not be otherwise, but just in case
+ if (selectedObject instanceof IAdaptable) {
+ IFile selectedIFile = ((IAdaptable) selectedObject).getAdapter(IFile.class);
+ if (selectedIFile != null) {
+ try {
+ // Load the resource associated with the selected object
+ ResourceSet resourceSet = new ResourceSetImpl();
+ Resource resource = resourceSet.getResource(URI.createURI(selectedIFile.getLocationURI().toString()), true);
+ if (resource.getContents().size() > 0) {
+ modelRoot = resource.getContents().get(0);
+ if (modelRoot instanceof NamedElement) {
+ NamedElement element = (NamedElement) modelRoot;
+ nameText.setText(element.getName());
+ } else {
+ modelRoot = null;
+ }
+ }
+ } catch (Exception e) {
+ this.setErrorMessage(Messages.SelectDiagramKindPage_Set_Root_Name_Error);
+ Activator.log.error(e);
+ }
+ }
+ }
+ }
+
nameText.addModifyListener(new ModifyListener() {
@Override
@@ -351,6 +395,9 @@ public class SelectDiagramKindPage extends WizardPage {
});
}
+ public static EObject getModelRoot() {
+ return modelRoot;
+ }
/**
* Validate page.
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java
index f4ce22bb98c..c76211cd3bb 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/wizards/InitModelWizard.java
@@ -54,9 +54,9 @@ public class InitModelWizard extends CreateModelWizard {
* Inits the.
*
* @param workbench
- * the workbench
+ * the workbench
* @param selection
- * the selection {@inheritDoc}
+ * the selection {@inheritDoc}
*/
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
@@ -64,7 +64,7 @@ public class InitModelWizard extends CreateModelWizard {
isInitFromExistingDomainModel = isSupportedDomainModelResource(uri);
super.init(workbench, selection);
selectRootElementPage = createSelectRootElementPage(selection);
- if(isCreateFromExistingDomainModel()) {
+ if (isCreateFromExistingDomainModel()) {
// Init Model not Create a new one
setWindowTitle(Messages.InitModelWizard_init_papyrus_diagram);
}
@@ -74,11 +74,11 @@ public class InitModelWizard extends CreateModelWizard {
* Creates the select root element page.
*
* @param selection
- * the initial workbench selection
+ * the initial workbench selection
* @return the select root element page
*/
protected SelectRootElementPage createSelectRootElementPage(IStructuredSelection selection) {
- if(!isCreateFromExistingDomainModel()) {
+ if (!isCreateFromExistingDomainModel()) {
// create model - nothing to choose from
return null;
}
@@ -92,15 +92,17 @@ public class InitModelWizard extends CreateModelWizard {
*/
@Override
protected SelectDiagramKindPage createSelectDiagramKindPage() {
- if(isCreateFromExistingDomainModel()) {
+ if (isCreateFromExistingDomainModel()) {
return new SelectDiagramKindPage(false, new CategoryProvider() {
+ @Override
public String[] getCurrentCategories() {
return getDiagramCategoryIds();
}
}, SelectDiagramKindPage.DEFAULT_CREATION_COMMAND_REGISTRY);
- };
+ }
+ ;
return super.createSelectDiagramKindPage();
}
@@ -112,19 +114,20 @@ public class InitModelWizard extends CreateModelWizard {
@Override
public void addPages() {
super.addPages();
- addPageIfNotNull(selectRootElementPage);
+ // remove the page from the view
+ // addPageIfNotNull(selectRootElementPage);
};
/**
* Returns true is the file can be served as a model model for the diagram.
*
* @param file
- * the file
+ * the file
* @return true, if is supported domain model file
*/
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");}
+ // 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));
}
@@ -132,7 +135,7 @@ public class InitModelWizard extends CreateModelWizard {
* Returns true if the resource can be served as a model model for the diagram.
*
* @param uri
- * the resource's URI
+ * the resource's URI
* @return true, if is supported domain model resource
*/
public static boolean isSupportedDomainModelResource(URI uri) {
@@ -143,7 +146,7 @@ public class InitModelWizard extends CreateModelWizard {
* Checks if is supported domain model file.
*
* @param sselection
- * the sselection
+ * the sselection
* @return true, if is supported domain model file
*/
public static boolean isSupportedDomainModelFile(IStructuredSelection sselection) {
@@ -155,13 +158,13 @@ public class InitModelWizard extends CreateModelWizard {
* Creates the papyrus models.
*
* @param diResourceSet
- * the di resource set
+ * the di resource set
* @param newURI
- * the URI of the new model's principal resource
+ * the URI of the new model's principal resource
*/
@Override
protected void createPapyrusModels(ModelSet modelSet, URI newURI) {
- if(isCreateFromExistingDomainModel()) {
+ if (isCreateFromExistingDomainModel()) {
RecordingCommand command = new PapyrusModelFromExistingDomainModelCommand(modelSet, newURI, getRoot());
getCommandStack(modelSet).execute(command);
} else {
@@ -173,15 +176,15 @@ public class InitModelWizard extends CreateModelWizard {
* Inits the domain model.
*
* @param diResourceSet
- * the di resource set
+ * the di resource set
* @param newURI
- * the URI of the new model's principal resource
+ * the URI of the new model's principal resource
* @param diagramCategoryId
- * the diagram category id {@inheritDoc}
+ * the diagram category id {@inheritDoc}
*/
@Override
protected void initDomainModel(ModelSet modelSet, final URI newURI, String diagramCategoryId) {
- if(isCreateFromExistingDomainModel()) {
+ if (isCreateFromExistingDomainModel()) {
// do nothing
} else {
super.initDomainModel(modelSet, newURI, diagramCategoryId);
@@ -192,9 +195,9 @@ public class InitModelWizard extends CreateModelWizard {
* Inits the diagrams.
*
* @param diResourceSet
- * the di resource set
+ * the di resource set
* @param categoryId
- * the category id {@inheritDoc}
+ * the category id {@inheritDoc}
*/
@Override
protected void initDiagrams(ModelSet modelSet, String categoryId) {
@@ -212,7 +215,7 @@ public class InitModelWizard extends CreateModelWizard {
@Override
public String getDiagramFileExtension(String diagramCategoryId) {
- if(isCreateFromExistingDomainModel()) {
+ if (isCreateFromExistingDomainModel()) {
return NewModelFilePage.DEFAULT_DIAGRAM_EXTENSION;
}
return super.getDiagramFileExtension(diagramCategoryId);
@@ -224,8 +227,9 @@ public class InitModelWizard extends CreateModelWizard {
* @return the root
*/
private EObject getRoot() {
- if(selectRootElementPage != null) {
- return selectRootElementPage.getModelElement();
+ if (selectRootElementPage != null) {
+ // return selectRootElementPage.getModelElement();
+ return SelectDiagramKindPage.getModelRoot();
}
return null;
}

Back to the top