Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2013-04-04 17:48:58 +0000
committercletavernie2013-04-04 17:48:58 +0000
commit51518784b0995b2f15bff5982cd1421be3fe6910 (patch)
treeca67dd1a845011a095000207f76d7ebda1dde7b7
parentc3cf9c9a76ca1a10c30948e0e11dcda88c061380 (diff)
downloadorg.eclipse.papyrus-51518784b0995b2f15bff5982cd1421be3fe6910.tar.gz
org.eclipse.papyrus-51518784b0995b2f15bff5982cd1421be3fe6910.tar.xz
org.eclipse.papyrus-51518784b0995b2f15bff5982cd1421be3fe6910.zip
404922: Creating a new model gives a NullPointerException if the current context is not what Papyrus expects
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404922
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/WorkspaceNewModelStorageProvider.java57
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/WizardsHelper.java47
2 files changed, 48 insertions, 56 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/WorkspaceNewModelStorageProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/WorkspaceNewModelStorageProvider.java
index 5a3e1e2f488..6f5a12959af 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/WorkspaceNewModelStorageProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/WorkspaceNewModelStorageProvider.java
@@ -12,7 +12,6 @@
package org.eclipse.papyrus.uml.diagram.wizards;
import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.adapt;
-import static org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper.getSelectedFile;
import java.util.Arrays;
import java.util.Collections;
@@ -26,12 +25,12 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.papyrus.uml.diagram.wizards.InitModelWizard.NewDiagramForExistingModelPage;
import org.eclipse.papyrus.uml.diagram.wizards.pages.NewModelFilePage;
+import org.eclipse.papyrus.uml.diagram.wizards.utils.WizardsHelper;
/**
* This is the WorkspaceNewModelStorageProvider type. Enjoy.
*/
-public class WorkspaceNewModelStorageProvider
- extends AbstractNewModelStorageProvider {
+public class WorkspaceNewModelStorageProvider extends AbstractNewModelStorageProvider {
private CreateModelWizard wizard;
@@ -45,8 +44,8 @@ public class WorkspaceNewModelStorageProvider
public boolean canHandle(IStructuredSelection initialSelection) {
boolean result = false;
- for (Object next : initialSelection.toList()) {
- if (adapt(next, IResource.class) != null) {
+ for(Object next : initialSelection.toList()) {
+ if(adapt(next, IResource.class) != null) {
result = true;
break;
}
@@ -55,6 +54,7 @@ public class WorkspaceNewModelStorageProvider
return result;
}
+ @Override
public void init(CreateModelWizard wizard, IStructuredSelection selection) {
super.init(wizard, selection);
@@ -63,23 +63,21 @@ public class WorkspaceNewModelStorageProvider
}
public List<? extends IWizardPage> createPages() {
- if (newModelFilePage == null) {
+ if(newModelFilePage == null) {
return Collections.emptyList();
}
return Arrays.asList(newModelFilePage);
}
+ @Override
public IStatus validateDiagramCategories(String... newCategories) {
- if (newModelFilePage != null) {
- String firstCategory = newCategories.length > 0
- ? newCategories[0]
- : null;
- if (newCategories.length > 0) {
+ if(newModelFilePage != null) {
+ String firstCategory = newCategories.length > 0 ? newCategories[0] : null;
+ if(newCategories.length > 0) {
// 316943 - [Wizard] Wrong suffix for file name when creating a
// profile model
- return newModelFilePage.diagramExtensionChanged(wizard
- .getDiagramFileExtension(firstCategory));
+ return newModelFilePage.diagramExtensionChanged(wizard.getDiagramFileExtension(firstCategory));
}
}
@@ -90,25 +88,22 @@ public class WorkspaceNewModelStorageProvider
* Creates the new model file page, if required.
*
* @param selection
- * the selection
+ * the selection
*
* @return the new model file page, or {@code null} if none
*/
- protected NewModelFilePage createNewModelFilePage(
- IStructuredSelection selection) {
+ protected NewModelFilePage createNewModelFilePage(IStructuredSelection selection) {
- if (wizard.isCreateProjectWizard()
- || wizard.isCreateMultipleModelsWizard()) {
+ if(wizard.isCreateProjectWizard() || wizard.isCreateMultipleModelsWizard()) {
return null;
}
- if (isCreateFromExistingDomainModel()) {
- return new NewDiagramForExistingModelPage(
- selection,
- wizard.getModelKindName(),
- getDiagramFileName(getSelectedFile(selection))
- + "." + wizard.getDiagramFileExtension(null), wizard.getDiagramFileExtension(null)); //$NON-NLS-1$
+ // IFile selectedFile = getSelectedFile(selection);
+ URI selectedResourceURI = WizardsHelper.getSelectedResourceURI(selection);
+
+ if(isCreateFromExistingDomainModel() && selectedResourceURI != null) {
+ return new NewDiagramForExistingModelPage(selection, wizard.getModelKindName(), getDiagramFileName(selectedResourceURI) + "." + wizard.getDiagramFileExtension(null), wizard.getDiagramFileExtension(null)); //$NON-NLS-1$
}
return new NewModelFilePage(selection, wizard.getModelKindName());
@@ -119,24 +114,20 @@ public class WorkspaceNewModelStorageProvider
* extension.
*
* @param domainModel
- * the domain model
+ * the domain model
* @return the diagram file name
*/
- protected String getDiagramFileName(IFile domainModel) {
- return domainModel.getLocation().removeFileExtension().lastSegment();
+ protected String getDiagramFileName(URI domainModelURI) {
+ return domainModelURI.trimFileExtension().lastSegment();
}
protected boolean isCreateFromExistingDomainModel() {
- return wizard.isInitModelWizard()
- && ((InitModelWizard) wizard).isCreateFromExistingDomainModel();
+ return wizard.isInitModelWizard() && ((InitModelWizard)wizard).isCreateFromExistingDomainModel();
}
public URI createNewModelURI(String categoryId) {
IFile newFile = newModelFilePage.createNewFile();
- return (newFile == null)
- ? null
- : URI.createPlatformResourceURI(newFile.getFullPath().toString(),
- true);
+ return (newFile == null) ? null : URI.createPlatformResourceURI(newFile.getFullPath().toString(), true);
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/WizardsHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/WizardsHelper.java
index e88f0928917..294a42728b3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/WizardsHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.wizards/src/org/eclipse/papyrus/uml/diagram/wizards/utils/WizardsHelper.java
@@ -17,8 +17,6 @@ package org.eclipse.papyrus.uml.diagram.wizards.utils;
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.jface.viewers.IStructuredSelection;
/**
@@ -30,15 +28,15 @@ public class WizardsHelper {
* Gets the file name without extension.
*
* @param path
- * the path of the file
+ * the path of the file
* @return the file name without extension
*/
public static String getFileNameWithoutExtension(String path) {
- if (path != null) {
+ if(path != null) {
String[] pathParts = path.split("/"); //$NON-NLS-1$
String fileName = pathParts[pathParts.length - 1];
int index = fileName.lastIndexOf('.');
- if (index > 0 && index <= fileName.length() - 2) {
+ if(index > 0 && index <= fileName.length() - 2) {
// System.out.println("Filename without Extension: "
// + fileName.substring(0, index));
return fileName.substring(0, index);
@@ -50,11 +48,11 @@ public class WizardsHelper {
public static <T> T adapt(Object obj, Class<T> type) {
T result = null;
- if (type.isInstance(obj)) {
+ if(type.isInstance(obj)) {
result = type.cast(obj);
- } else if (obj instanceof IAdaptable) {
- Object adapter = ((IAdaptable) obj).getAdapter(type);
- if (type.isInstance(adapter)) {
+ } else if(obj instanceof IAdaptable) {
+ Object adapter = ((IAdaptable)obj).getAdapter(type);
+ if(type.isInstance(adapter)) {
result = type.cast(adapter);
}
}
@@ -70,7 +68,7 @@ public class WizardsHelper {
* @return the selected file
*/
public static IFile getSelectedFile(IStructuredSelection selection) {
- if ((selection != null) && !selection.isEmpty()) {
+ if((selection != null) && !selection.isEmpty()) {
return adapt(selection.getFirstElement(), IFile.class);
}
return null;
@@ -84,22 +82,25 @@ public class WizardsHelper {
* @return the URI of the selected resource
*/
public static URI getSelectedResourceURI(IStructuredSelection selection) {
- if ((selection != null) && !selection.isEmpty()) {
+ if((selection != null) && !selection.isEmpty()) {
IFile file = adapt(selection.getFirstElement(), IFile.class);
- if (file != null) {
+ if(file != null) {
return URI.createPlatformResourceURI(file.getFullPath().toString(), true);
}
- Resource resource = adapt(selection.getFirstElement(), Resource.class);
- if (resource == null) {
- EObject object = adapt(selection.getFirstElement(), EObject.class);
- if (object != null) {
- resource = object.eResource();
- }
- }
-
- if (resource != null) {
- return resource.getURI();
- }
+
+ //FIXME: See bug 404922. Disable the resource resolution support until the wizard forces the target folder for the di model.
+
+ // Resource resource = adapt(selection.getFirstElement(), Resource.class);
+ // if(resource == null) {
+ // EObject object = adapt(selection.getFirstElement(), EObject.class);
+ // if(object != null) {
+ // resource = object.eResource();
+ // }
+ // }
+ //
+ // if(resource != null) {
+ // return resource.getURI();
+ // }
}
return null;
}

Back to the top