Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-02-26 21:20:37 +0000
committerChristian W. Damus2014-02-26 21:20:37 +0000
commitaa0380b7d3b429c472b932411363c7109d829f08 (patch)
tree7bc38c087775f0838d010f5df83eedbde9354d3b /plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse
parentd69dde021ba324b9b1bf017e27a24f12c827e62e (diff)
downloadorg.eclipse.papyrus-aa0380b7d3b429c472b932411363c7109d829f08.tar.gz
org.eclipse.papyrus-aa0380b7d3b429c472b932411363c7109d829f08.tar.xz
org.eclipse.papyrus-aa0380b7d3b429c472b932411363c7109d829f08.zip
323802: [General] Papyrus shall provide a read only mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=323802 Restrict import-package context menu on read-only packages in the Model Explorer and ensure that the operation approver has necessary context to make resources writable, when appropriate.
Diffstat (limited to 'plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse')
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/AbstractImportHandler.java73
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromUserModelHandler.java11
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredPackageHandler.java11
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredProfileHandler.java12
4 files changed, 81 insertions, 26 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/AbstractImportHandler.java b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/AbstractImportHandler.java
index 60be80c483b..a7460a7c343 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/AbstractImportHandler.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/AbstractImportHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
+ * Copyright (c) 2012, 2014 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,13 +8,32 @@
*
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 323802
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.importt.handlers;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.views.modelexplorer.handler.AbstractCommandHandler;
-import org.eclipse.uml2.common.edit.command.ChangeCommand;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageImport;
import org.eclipse.uml2.uml.UMLFactory;
@@ -22,10 +41,17 @@ import org.eclipse.uml2.uml.UMLFactory;
public abstract class AbstractImportHandler extends AbstractCommandHandler {
- protected abstract class AbstractImportCommand extends ChangeCommand {
+ protected abstract class AbstractImportCommand extends AbstractTransactionalCommand {
+ private final Runnable runnable;
+
+ private final String description;
+
protected AbstractImportCommand(Runnable runnable, String label, String description) {
- super(AbstractImportHandler.this.getEditingDomain(), runnable, label, description);
+ super(AbstractImportHandler.this.getEditingDomain(), label, computeAffectedFiles(getSelectedElements()));
+
+ this.runnable = runnable;
+ this.description = description;
}
/**
@@ -43,8 +69,47 @@ public abstract class AbstractImportHandler extends AbstractCommandHandler {
return false;
}
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ runnable.run();
+ return CommandResult.newOKCommandResult();
+ }
+
+ String getDescription() {
+ return description;
+ }
}
+ static List<IFile> computeAffectedFiles(Collection<?> selected) {
+ Set<IFile> unique = new LinkedHashSet<IFile>();
+
+ for (Object next : selected) {
+ EObject object = (next instanceof EObject) ? (EObject)next : null;
+ Resource resource = (object == null) ? null : object.eResource();
+ if (resource != null) {
+ IFile file = WorkspaceSynchronizer.getFile(resource);
+ if (file != null) {
+ unique.add(file);
+ }
+ }
+ }
+
+ return new ArrayList<IFile>(unique);
+ }
+
+ protected Command getCommand() {
+ ICommand command = getGMFCommand();
+ GMFtoEMFCommandWrapper result = new GMFtoEMFCommandWrapper(command);
+
+ if (command instanceof AbstractImportCommand) {
+ result.setDescription(((AbstractImportCommand)command).getDescription());
+ }
+
+ return result;
+ }
+
+ protected abstract ICommand getGMFCommand();
+
/**
* Loads the Package resource into the current resource set
*
diff --git a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromUserModelHandler.java b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromUserModelHandler.java
index 192c60edff1..79be0d74406 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromUserModelHandler.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportPackageFromUserModelHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2011, 2013 CEA LIST.
+ * Copyright (c) 2011, 2014 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,6 +9,7 @@
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO
+ * Christian W. Damus (CEA) - bug 323802
*
*****************************************************************************/
package org.eclipse.papyrus.uml.importt.handlers;
@@ -17,7 +18,7 @@ import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.eclipse.emf.common.command.Command;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.uml.importt.ui.PackageImportDialog;
import org.eclipse.papyrus.uml.profile.ui.dialogs.ElementImportTreeSelectionDialog.ImportSpec;
@@ -29,12 +30,8 @@ import org.eclipse.uml2.uml.Package;
public class ImportPackageFromUserModelHandler extends AbstractImportHandler {
- /**
- *
- * {@inheritDoc}
- */
@Override
- protected Command getCommand() {
+ protected ICommand getGMFCommand() {
return new ImportFromFileCommand();
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredPackageHandler.java b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredPackageHandler.java
index 33a91d17b0a..f672005ea23 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredPackageHandler.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredPackageHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2011, 2013 CEA LIST.
+ * Copyright (c) 2011, 2014 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,6 +9,7 @@
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO
+ * Christian W. Damus (CEA) - bug 323802
*
*****************************************************************************/
package org.eclipse.papyrus.uml.importt.handlers;
@@ -18,10 +19,10 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-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.gmf.runtime.common.core.command.ICommand;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.uml.extensionpoints.library.FilteredRegisteredLibrariesSelectionDialog;
@@ -37,12 +38,8 @@ import org.eclipse.uml2.uml.Package;
public class ImportRegisteredPackageHandler extends AbstractImportHandler {
- /**
- *
- * {@inheritDoc}
- */
@Override
- protected Command getCommand() {
+ protected ICommand getGMFCommand() {
return new ImportLibraryFromRepositoryCommand();
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredProfileHandler.java b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredProfileHandler.java
index 22de25f417f..640960da3ad 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredProfileHandler.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.import/src/org/eclipse/papyrus/uml/importt/handlers/ImportRegisteredProfileHandler.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2011, 2013 CEA LIST.
+ * Copyright (c) 2011, 2014 CEA LIST and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,6 +9,7 @@
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
* Christian W. Damus (CEA) - Refactoring package/profile import/apply UI for CDO
+ * Christian W. Damus (CEA) - bug 323802
*
*****************************************************************************/
package org.eclipse.papyrus.uml.importt.handlers;
@@ -19,10 +20,10 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-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.gmf.runtime.common.core.command.ICommand;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.uml.extensionpoints.profile.FilteredRegisteredProfilesAsLibrarySelectionDialog;
@@ -33,7 +34,6 @@ import org.eclipse.papyrus.uml.profile.ui.dialogs.ElementImportTreeSelectionDial
import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.PackageImport;
import org.eclipse.uml2.uml.Profile;
@@ -43,12 +43,8 @@ import org.eclipse.uml2.uml.UMLFactory;
public class ImportRegisteredProfileHandler extends AbstractImportHandler {
- /**
- *
- * {@inheritDoc}
- */
@Override
- protected Command getCommand() {
+ protected ICommand getGMFCommand() {
return new ImportProfileCommand();
}

Back to the top