Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-09-18 09:09:59 +0000
committercletavernie2012-09-18 09:09:59 +0000
commit7e9c6bd819a0a830cb2c2a99f476b8c6b288366d (patch)
tree884be389a30bfe80a115d909378cec6233f98f62
parent3df21f5a7ec7f5932f1b70a52e453187c5306ef6 (diff)
downloadorg.eclipse.papyrus-7e9c6bd819a0a830cb2c2a99f476b8c6b288366d.tar.gz
org.eclipse.papyrus-7e9c6bd819a0a830cb2c2a99f476b8c6b288366d.tar.xz
org.eclipse.papyrus-7e9c6bd819a0a830cb2c2a99f476b8c6b288366d.zip
389583: [Import libraries] Improve the dialogs to import libraries (e.g. Packages)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=389583
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromWorkspaceHandler.java99
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ElementImportTreeSelectionDialog.java40
2 files changed, 97 insertions, 42 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromWorkspaceHandler.java b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromWorkspaceHandler.java
index 1fa6db25cf3..fc658583f6c 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromWorkspaceHandler.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromWorkspaceHandler.java
@@ -14,18 +14,21 @@ package org.eclipse.papyrus.uml.importt.handlers;
import java.util.List;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.widgets.editors.MultipleValueSelectorDialog;
+import org.eclipse.papyrus.infra.widgets.providers.WorkspaceContentProvider;
+import org.eclipse.papyrus.infra.widgets.selectors.ReferenceSelector;
import org.eclipse.papyrus.uml.extensionpoints.utils.Util;
-import org.eclipse.papyrus.uml.importt.messages.Messages;
import org.eclipse.papyrus.uml.importt.ui.PackageImportDialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ResourceSelectionDialog;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.uml2.uml.Package;
@@ -66,7 +69,18 @@ public class ImportPackageFromWorkspaceHandler extends AbstractImportHandler {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
// Start selection dialog
- ResourceSelectionDialog chooseLib = new ResourceSelectionDialog(shell, ResourcesPlugin.getWorkspace().getRoot(), Messages.ImportPackageFromFileHandler_SelectRegisteredModelLibrary);
+ ReferenceSelector selector = new ReferenceSelector();
+ ILabelProvider labelProvider = WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider();
+ selector.setLabelProvider(labelProvider);
+ selector.setContentProvider(new WorkspaceContentProvider());
+
+ MultipleValueSelectorDialog chooseLib = new MultipleValueSelectorDialog(shell, selector);
+
+ chooseLib.setLabelProvider(WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider());
+ chooseLib.setUnique(true);
+ chooseLib.setTitle("Select the models to import");
+
+ //ResourceSelectionDialog chooseLib = new ResourceSelectionDialog(shell, ResourcesPlugin.getWorkspace().getRoot(), Messages.ImportPackageFromFileHandler_SelectRegisteredModelLibrary);
chooseLib.open();
@@ -79,38 +93,69 @@ public class ImportPackageFromWorkspaceHandler extends AbstractImportHandler {
ResourceSet resourceSet = Util.getResourceSet(getSelectedElement());
// Parse selection and add ModelLibrary files
- for(int i = 0; i < selection.length; i++) {
+ for(Object selectedElement : selection) {
- if(selection[i] instanceof IFile) {
+ //Handle errors:
+ //- The selected is not an IFile
+ //- The selected file is not a valid EMF Model (Error occurs during the resource loading)
+ //- The selected model is empty
+ //- The selected model is not a Package
- IFile currentFile = (IFile)selection[i];
+ if(!(selectedElement instanceof IFile)) {
+ MessageDialog.openWarning(shell, "Selection is not a File", "The selected element is not a File: " + labelProvider.getText(selectedElement));
+ continue;
+ }
- URI modelUri = URI.createURI("platform:/resource" + currentFile.getFullPath()); //$NON-NLS-1$
- Resource modelResource = resourceSet.getResource(modelUri, true);
+ IFile currentFile = (IFile)selectedElement;
- PackageImportDialog dialog = new PackageImportDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), ((Package)modelResource.getContents().get(0)));
+ URI modelUri = URI.createURI("platform:/resource" + currentFile.getFullPath()); //$NON-NLS-1$
- if(dialog.open() == Window.OK) {
- List<?> result = dialog.getResult();
- for(Object resultElement : result) {
- Package selectedPackage = (Package)resultElement;
- if(dialog.isCopy()) {
- handleCopyPackage(selectedPackage);
- } else {
- handleImportPackage(selectedPackage);
- }
- }
+ Resource modelResource;
+ try {
+ modelResource = resourceSet.getResource(modelUri, true);
+ } catch (Exception ex) {
+ MessageDialog.openWarning(shell, "Invalid model", "The selected file is not a valid model: " + labelProvider.getText(selectedElement));
+ //At this point, an empty resource may have been loaded in the resource set. We should clean it.
+ //Remove the resource from the resource set
+ modelResource = resourceSet.getResource(modelUri, false);
+ if(modelResource != null) {
+ resourceSet.getResources().remove(modelResource);
}
+ continue;
+ }
+ if(modelResource.getContents().isEmpty()) {
+ MessageDialog.openWarning(shell, "Model is empty", "The selected model is empty: " + labelProvider.getText(selectedElement));
+ continue;
+ }
+ if(!(modelResource.getContents().get(0) instanceof Package)) {
+ MessageDialog.openWarning(shell, "Model is not a Package", "The selected model is not a valid UML Package: " + labelProvider.getText(selectedElement));
+ continue;
+ }
+
+ PackageImportDialog dialog = new PackageImportDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), ((Package)modelResource.getContents().get(0)));
- /*
- * Element root = (Element) modelResource.getContents().get(0);
- *
- * // Import model library Package libToImport = (Package) root; // create import package PackageImport pi =
- * UMLFactory.eINSTANCE.createPackageImport();
- * pi.setImportedPackage(libToImport); ((Package) selectedElement).getPackageImports().add(pi);
- */
+ if(dialog.open() == Window.OK) {
+ List<?> result = dialog.getResult();
+
+ for(Object resultElement : result) {
+ Package selectedPackage = (Package)resultElement;
+ if(dialog.isCopy()) {
+ handleCopyPackage(selectedPackage);
+ } else {
+ handleImportPackage(selectedPackage);
+ }
+ }
}
+
+ /*
+ * Element root = (Element) modelResource.getContents().get(0);
+ *
+ * // Import model library Package libToImport = (Package) root; // create import package PackageImport pi =
+ * UMLFactory.eINSTANCE.createPackageImport();
+ * pi.setImportedPackage(libToImport); ((Package) selectedElement).getPackageImports().add(pi);
+ */
+
}
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ElementImportTreeSelectionDialog.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ElementImportTreeSelectionDialog.java
index b38c19f7970..30485a1ea95 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ElementImportTreeSelectionDialog.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/ui/dialogs/ElementImportTreeSelectionDialog.java
@@ -47,6 +47,7 @@ import org.eclipse.uml2.uml.Profile;
* this is a dialog to select an element import
*
*/
+//FIXME: This dialog should be moved to another plug-in
public class ElementImportTreeSelectionDialog extends Dialog {
/**
@@ -57,7 +58,7 @@ public class ElementImportTreeSelectionDialog extends Dialog {
protected List<Package> models;
protected boolean subSelection = false;
-
+
/**
*
*/
@@ -107,9 +108,12 @@ public class ElementImportTreeSelectionDialog extends Dialog {
/**
- * @param parent the parent shell
- * @param model the UML model of profile or import library
- * @param subselection true, if the selection of an element automatically selects all sub-elements
+ * @param parent
+ * the parent shell
+ * @param model
+ * the UML model of profile or import library
+ * @param subselection
+ * true, if the selection of an element automatically selects all sub-elements
*/
public ElementImportTreeSelectionDialog(Shell parent, Package model) {
super(parent);
@@ -141,9 +145,14 @@ public class ElementImportTreeSelectionDialog extends Dialog {
*
* @return
*/
+ @Override
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite)super.createDialogArea(parent);
elementTree = new Tree(comp, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL);
+ GridData treeData = new GridData(SWT.FILL, SWT.FILL, true, true);
+ treeData.widthHint = 300;
+ treeData.heightHint = 300;
+ elementTree.setLayoutData(treeData);
if(model != null) {
createTreeItem(model);
@@ -162,13 +171,13 @@ public class ElementImportTreeSelectionDialog extends Dialog {
if(event.detail == SWT.CHECK) {
if(elementsToImport.contains(event.item.getData())) {
elementsToImport.remove(event.item.getData());
- if (subSelection) {
+ if(subSelection) {
remChildSelection((TreeItem)event.item);
}
} else {
elementsToImport.add((Element)event.item.getData());
- if (subSelection) {
+ if(subSelection) {
addChildSelection((TreeItem)event.item);
}
}
@@ -176,6 +185,8 @@ public class ElementImportTreeSelectionDialog extends Dialog {
}
});
+ getShell().setText("Select the elements to import");
+
return comp;
}
@@ -232,8 +243,6 @@ public class ElementImportTreeSelectionDialog extends Dialog {
item.setImage(IMG_PACKAGE);
}
buildImportTreeList(item, _package);
-
- elementTree.setLayoutData(new GridData(300, 300));
}
/**
@@ -256,7 +265,7 @@ public class ElementImportTreeSelectionDialog extends Dialog {
protected void buildImportTreeList(TreeItem elemTree, Package _package) {
Iterator<PackageableElement> elemIter = _package.getPackagedElements().iterator();
while(elemIter.hasNext()) {
- Element elem = (Element)elemIter.next();
+ Element elem = elemIter.next();
if(elem instanceof Package) {
TreeItem item = new TreeItem(elemTree, SWT.NONE);
item.setText(((Package)elem).getName());
@@ -272,18 +281,19 @@ public class ElementImportTreeSelectionDialog extends Dialog {
item.setData(elem);
/* icon setting */
- if(elem instanceof Association)
+ if(elem instanceof Association) {
item.setImage(IMG_ASSOCIATION);
- else if(elem instanceof Enumeration)
+ } else if(elem instanceof Enumeration) {
item.setImage(IMG_ENUM);
- else if(elem instanceof PrimitiveType)
+ } else if(elem instanceof PrimitiveType) {
item.setImage(IMG_PRIMITIVE);
- else if(elem instanceof DataType)
+ } else if(elem instanceof DataType) {
item.setImage(IMG_DATATYPE);
- else if(elem instanceof org.eclipse.uml2.uml.Class)
+ } else if(elem instanceof org.eclipse.uml2.uml.Class) {
item.setImage(IMG_CLASS);
- else if(elem instanceof InstanceSpecification)
+ } else if(elem instanceof InstanceSpecification) {
item.setImage(IMG_INSTANCESPEC);
+ }
}
}
}

Back to the top