diff options
author | aradermache | 2010-11-25 13:54:40 +0000 |
---|---|---|
committer | aradermache | 2010-11-25 13:54:40 +0000 |
commit | 6af88ad9df01ef73d661d140e8931ef6dabb9dd1 (patch) | |
tree | 1470d17f7b5320e65b408092490d258a47d01aa9 | |
parent | e31037b494aa84dcb9e087823c820003eabe7855 (diff) | |
download | org.eclipse.papyrus-6af88ad9df01ef73d661d140e8931ef6dabb9dd1.tar.gz org.eclipse.papyrus-6af88ad9df01ef73d661d140e8931ef6dabb9dd1.tar.xz org.eclipse.papyrus-6af88ad9df01ef73d661d140e8931ef6dabb9dd1.zip |
Fix for bug 330831
5 files changed, 107 insertions, 117 deletions
diff --git a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/AbstractPackageImportAction.java b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/AbstractPackageImportAction.java index 2c17f2302d0..33068f290b0 100644 --- a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/AbstractPackageImportAction.java +++ b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/AbstractPackageImportAction.java @@ -10,14 +10,15 @@ * Contributors:
* Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
* Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ * Ansgar Radermacher (CEA LIST) Ansgar.Radermacher@cea.fr - minor modifications
*
*****************************************************************************/
package org.eclipse.papyrus.profile.ui.actions;
import org.eclipse.emf.common.command.CommandStack;
import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
import org.eclipse.jface.action.IAction;
-import org.eclipse.papyrus.core.utils.EditorUtils;
import org.eclipse.ui.IViewPart;
import org.eclipse.uml2.common.edit.command.ChangeCommand;
import org.eclipse.uml2.uml.Package;
@@ -30,17 +31,12 @@ public abstract class AbstractPackageImportAction extends AbstractViewActionDele /** current selection */
protected Package selectedElement;
- /** Editing domain of the viewer given to init() method */
- protected EditingDomain editingDomain;
-
/** stored instance of the command */
protected ChangeCommand command;
@Override
public void init(IViewPart view) {
super.init(view);
- // try to retrieve editing domain
- editingDomain = (EditingDomain)view.getAdapter(EditingDomain.class);
}
/**
@@ -71,6 +67,9 @@ public abstract class AbstractPackageImportAction extends AbstractViewActionDele if(selectedElement instanceof Package) {
this.selectedElement = (Package)selectedElement;
}
+ else {
+ this.selectedElement = null;
+ }
}
/**
@@ -79,7 +78,11 @@ public abstract class AbstractPackageImportAction extends AbstractViewActionDele * @return <code>true</code> if the action can be executed
*/
public boolean canExecute() {
- return getCommand().canExecute();
+ if (selectedElement != null) {
+ EditingDomain editingDomain = TransactionUtil.getEditingDomain(selectedElement);
+ return getCommand(editingDomain).canExecute();
+ }
+ return false;
}
/**
@@ -87,9 +90,11 @@ public abstract class AbstractPackageImportAction extends AbstractViewActionDele */
@Override
public void run(IAction action) {
-
- CommandStack stack = EditorUtils.getTransactionalEditingDomain().getCommandStack ();
- stack.execute (getCommand());
+ if (selectedElement != null) {
+ EditingDomain editingDomain = TransactionUtil.getEditingDomain(selectedElement);
+ CommandStack stack = editingDomain.getCommandStack ();
+ stack.execute (getCommand(editingDomain));
+ }
}
/**
@@ -100,13 +105,4 @@ public abstract class AbstractPackageImportAction extends AbstractViewActionDele * @return the command that is executed by this action
*/
public abstract ChangeCommand getCommand(EditingDomain domain);
-
- /**
- * returns the command that is executed by this action.
- *
- * @return the command that is executed by this action
- */
- public ChangeCommand getCommand() {
- return getCommand(editingDomain);
- }
}
diff --git a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportFromFile.java b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportFromFile.java index 09cb6bd972e..82d35d1dd4a 100644 --- a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportFromFile.java +++ b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportFromFile.java @@ -22,83 +22,113 @@ import org.eclipse.core.resources.ResourcesPlugin; 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.action.IAction; +import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.jface.window.Window; import org.eclipse.papyrus.extensionpoints.uml2.utils.Util; import org.eclipse.papyrus.profile.ui.dialogs.PackageImportTreeSelectionDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.dialogs.ResourceSelectionDialog; +import org.eclipse.uml2.common.edit.command.ChangeCommand; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Package; import org.eclipse.uml2.uml.PackageImport; import org.eclipse.uml2.uml.UMLFactory; -// TODO: Auto-generated Javadoc /** * The Class ImportFromFile. */ -public class ImportFromFile extends AbstractViewActionDelegate { +public class ImportFromFile extends AbstractPackageImportAction { /** - * Run. + * returns the command that is executed by this action. * - * @param action - * the action + * @param domain + * EMF editing domain used by the command + * @return the command that is executed by this action */ @Override - public void run(IAction action) { - // TODO Auto-generated method stub - - // Retrieve shell instance - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - - // Start selection dialog - ResourceSelectionDialog chooseLib = new ResourceSelectionDialog(shell, ResourcesPlugin.getWorkspace().getRoot(), "Select Registered ModelLibrary"); - - chooseLib.open(); - - // User selection - Object[] selection = chooseLib.getResult(); - - if(selection == null) { // Cancel was selected - return; + public ChangeCommand getCommand(EditingDomain domain) { + if(command == null) { + command = new ImportFromFileCommand(domain); } + return command; + } + + /** + * Specific {@link ChangeCommand} that imports libraries from repository + */ + public class ImportFromFileCommand extends ChangeCommand { + + /** + * Creates a new ImportLibraryFromRepositoryCommand + * + * @param editingDomain + * editing domain that manages the changed objects + * @param runnable + * process that executes the modifications + * @param label + * the label of the command + * @param description + * description of the command + */ + public ImportFromFileCommand(EditingDomain editingDomain) { + super(editingDomain, new Runnable() { + + public void run() { + + // Retrieve shell instance + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + + // Start selection dialog + ResourceSelectionDialog chooseLib = new ResourceSelectionDialog(shell, ResourcesPlugin.getWorkspace().getRoot(), "Select Registered ModelLibrary"); + + chooseLib.open(); + + // User selection + Object[] selection = chooseLib.getResult(); + + if(selection == null) { // Cancel was selected + return; + } - ResourceSet resourceSet = Util.getResourceSet(selectedElement); - // Parse selection and add ModelLibrary files - for(int i = 0; i < selection.length; i++) { - - if(selection[i] instanceof IFile) { - - IFile currentFile = (IFile)selection[i]; - - URI modelUri = URI.createURI("platform:/resource" + currentFile.getFullPath()); - Resource modelResource = resourceSet.getResource(modelUri, true); - - PackageImportTreeSelectionDialog eisd = new PackageImportTreeSelectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), ((Package)modelResource.getContents() - .get(0))); - int ret = eisd.open(); - - if(ret == Window.OK) { - ArrayList result = eisd.getResult(); - Iterator resultIter = result.iterator(); - while(resultIter.hasNext()) { - Element element = (Element)resultIter.next(); - PackageImport ei = UMLFactory.eINSTANCE.createPackageImport(); - ei.setImportedPackage((Package)element); - ((Package)selectedElement).getPackageImports().add(ei); + ResourceSet resourceSet = Util.getResourceSet(selectedElement); + // Parse selection and add ModelLibrary files + for(int i = 0; i < selection.length; i++) { + + if(selection[i] instanceof IFile) { + + IFile currentFile = (IFile)selection[i]; + + URI modelUri = URI.createURI("platform:/resource" + currentFile.getFullPath()); + Resource modelResource = resourceSet.getResource(modelUri, true); + + PackageImportTreeSelectionDialog eisd = new PackageImportTreeSelectionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), ((Package)modelResource.getContents() + .get(0))); + int ret = eisd.open(); + + if(ret == Window.OK) { + ArrayList result = eisd.getResult(); + Iterator resultIter = result.iterator(); + while(resultIter.hasNext()) { + Element element = (Element)resultIter.next(); + PackageImport ei = UMLFactory.eINSTANCE.createPackageImport(); + ei.setImportedPackage((Package)element); + ((Package)selectedElement).getPackageImports().add(ei); + } + } + + /* + * 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); + */ + } } } - - /* - * 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); - */ - } + }, "Import Libraries", "Import Libraries from Workspace"); } } } diff --git a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportLibrariesFromRepositoryAction.java b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportLibrariesFromRepositoryAction.java index 8c97e3ae17a..e17ae043910 100644 --- a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportLibrariesFromRepositoryAction.java +++ b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportLibrariesFromRepositoryAction.java @@ -26,7 +26,6 @@ import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.core.utils.EditorUtils; import org.eclipse.papyrus.extensionpoints.uml2.library.FilteredRegisteredLibrariesSelectionDialog; import org.eclipse.papyrus.extensionpoints.uml2.library.RegisteredLibrary; import org.eclipse.papyrus.extensionpoints.uml2.utils.Util; @@ -54,21 +53,12 @@ public class ImportLibrariesFromRepositoryAction extends AbstractPackageImportAc * EMF editing domain used by the command * @return the command that is executed by this action */ - public ImportLibraryFromRepositoryCommand getCommand(EditingDomain domain) { + @Override + public ChangeCommand getCommand(EditingDomain domain) { if(command == null) { command = new ImportLibraryFromRepositoryCommand(domain); } - return (ImportLibraryFromRepositoryCommand)command; - } - - /** - * returns the command that is executed by this action. - * - * @return the command that is executed by this action - */ - public ImportLibraryFromRepositoryCommand getCommand() { - - return getCommand(EditorUtils.getTransactionalEditingDomain ()); + return command; } /** diff --git a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportProfileAction.java b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportProfileAction.java index 5cd80ee950d..d0e425c3e41 100644 --- a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportProfileAction.java +++ b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportProfileAction.java @@ -23,12 +23,8 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.core.editor.IMultiDiagramEditor;
-import org.eclipse.papyrus.core.services.ServiceException;
-import org.eclipse.papyrus.core.utils.ServiceUtils;
import org.eclipse.papyrus.extensionpoints.uml2.profile.FilteredRegisteredProfilesAsLibrarySelectionDialog;
import org.eclipse.papyrus.extensionpoints.uml2.profile.RegisteredProfile;
import org.eclipse.papyrus.extensionpoints.uml2.utils.Util;
@@ -58,38 +54,15 @@ public class ImportProfileAction extends AbstractPackageImportAction { * @return
*/
@Override
- public ImportProfileCommand getCommand(EditingDomain domain) {
+ public ChangeCommand getCommand(EditingDomain domain) {
if(command == null) {
command = new ImportProfileCommand(domain);
}
getAvailableProfiles();
- return (ImportProfileCommand)command;
+ return command;
}
/**
- *
- * @see org.eclipse.papyrus.profile.ui.actions.AbstractPackageImportAction#getCommand()
- *
- * @return
- */
- @Override
- public ImportProfileCommand getCommand() {
- TransactionalEditingDomain domain = null;
- IMultiDiagramEditor editorPart = (IMultiDiagramEditor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
-
- if(editorPart != null) {
- try {
- domain = ServiceUtils.getInstance().getTransactionalEditingDomain(editorPart.getServicesRegistry());
- } catch (ServiceException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return getCommand(domain);
- }
-
-
- /**
* Returns the list of the profiles which are already imported
*
* @return
diff --git a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportProfilesAsLibraryFromRepositoryAction.java b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportProfilesAsLibraryFromRepositoryAction.java index f49295920e7..a6dc0434e46 100644 --- a/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportProfilesAsLibraryFromRepositoryAction.java +++ b/plugins/others/org.eclipse.papyrus.profile/src/org/eclipse/papyrus/profile/ui/actions/ImportProfilesAsLibraryFromRepositoryAction.java @@ -53,11 +53,12 @@ public class ImportProfilesAsLibraryFromRepositoryAction extends AbstractPackage * EMF editing domain used by the command * @return the command that is executed by this action */ - public ImportProfilesAsLibraryFromRepositoryCommand getCommand(EditingDomain domain) { + @Override + public ChangeCommand getCommand(EditingDomain domain) { if(command == null) { command = new ImportProfilesAsLibraryFromRepositoryCommand(domain); } - return (ImportProfilesAsLibraryFromRepositoryCommand)command; + return command; } /** |