Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-08-02 13:36:42 +0000
committercletavernie2012-08-02 13:36:42 +0000
commitdb5fbfa853642ddce82f99759148ec70e0cc9df3 (patch)
tree6026aef80492a5aedc788509339681761dc9d9e0 /plugins
parent8977b104b2ba82014a59f77bcdda0dbd6952857e (diff)
downloadorg.eclipse.papyrus-db5fbfa853642ddce82f99759148ec70e0cc9df3.tar.gz
org.eclipse.papyrus-db5fbfa853642ddce82f99759148ec70e0cc9df3.tar.xz
org.eclipse.papyrus-db5fbfa853642ddce82f99759148ec70e0cc9df3.zip
386492: [Libraries - Profiles] All Libraries and Profiles should be loaded in read-only mode
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386492
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/plugin.xml4
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/Activator.java4
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/EMFReadOnlyHandler.java23
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/FSReadOnlyHandler.java25
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/IReadOnlyHandler.java6
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java1
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManager.java52
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyTester.java2
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/handlers/EnableWriteHandler.java20
-rw-r--r--plugins/team/org.eclipse.papyrus.team.svn/src/org/eclipse/papyrus/team/svn/SVNLockHandler.java27
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF1
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/plugin.xml7
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/readonly/AppliedProfileReadOnlyHandler.java70
14 files changed, 206 insertions, 39 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF
index e747f7e5dc3..50c67dd5b3e 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/META-INF/MANIFEST.MF
@@ -6,7 +6,8 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="0.9.0",
org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.emf.transaction;bundle-version="1.4.0",
org.eclipse.emf.workspace;bundle-version="1.4.0",
- org.eclipse.gmf.runtime.common.core;bundle-version="1.4.1"
+ org.eclipse.gmf.runtime.common.core;bundle-version="1.4.1",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.9.0"
Export-Package: org.eclipse.papyrus.infra.emf.readonly,
org.eclipse.papyrus.infra.emf.readonly.handlers
Bundle-Vendor: %providerName
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/plugin.xml b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/plugin.xml
index 4f54e16f2bf..58a13953003 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/plugin.xml
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/plugin.xml
@@ -8,6 +8,10 @@
class="org.eclipse.papyrus.infra.emf.readonly.FSReadOnlyHandler"
priority="10">
</readOnlyHandler>
+ <readOnlyHandler
+ class="org.eclipse.papyrus.infra.emf.readonly.EMFReadOnlyHandler"
+ priority="5">
+ </readOnlyHandler>
</extension>
<extension
point="org.eclipse.ui.handlers">
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/Activator.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/Activator.java
index c7d6ffadf06..e8a950a80b2 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/Activator.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/Activator.java
@@ -13,6 +13,7 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.emf.readonly;
+import org.eclipse.papyrus.infra.core.log.LogHelper;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -20,6 +21,8 @@ public class Activator implements BundleActivator {
private static BundleContext context;
+ public static LogHelper log;
+
static BundleContext getContext() {
return context;
}
@@ -31,6 +34,7 @@ public class Activator implements BundleActivator {
*/
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
+ log = new LogHelper();
}
/*
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/EMFReadOnlyHandler.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/EMFReadOnlyHandler.java
new file mode 100644
index 00000000000..bf5f5ff756d
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/EMFReadOnlyHandler.java
@@ -0,0 +1,23 @@
+package org.eclipse.papyrus.infra.emf.readonly;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.edit.domain.EditingDomain;
+
+
+public class EMFReadOnlyHandler implements IReadOnlyHandler {
+
+ public boolean isReadOnly(URI[] uris, EditingDomain editingDomain) {
+ for(URI uri : uris) {
+ if(!uri.isPlatformResource()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean enableWrite(URI[] uris, EditingDomain editingDomain) {
+ return false; //We cannot change the read-only status
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/FSReadOnlyHandler.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/FSReadOnlyHandler.java
index d44a15261de..84ff0d28905 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/FSReadOnlyHandler.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/FSReadOnlyHandler.java
@@ -17,29 +17,43 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourceAttributes;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
public class FSReadOnlyHandler implements IReadOnlyHandler {
- public boolean isReadOnly(IFile[] files, EditingDomain editingDomain) {
- for(IFile file : files) {
+ public boolean isReadOnly(URI[] uris, EditingDomain editingDomain) {
+ for(URI uri : uris) {
+
+ IFile file = getFile(uri);
if(file != null && file.isReadOnly()) {
return true;
}
}
+
return false;
}
- public boolean enableWrite(final IFile[] files, EditingDomain editingDomain) {
+ private static IFile getFile(URI uri) {
+ if(uri.isPlatform()) {
+ return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
+ }
+ return null;
+ }
+
+ public boolean enableWrite(final URI[] uris, EditingDomain editingDomain) {
final AtomicBoolean doEnableWrite = new AtomicBoolean();
Display.getCurrent().syncExec(new Runnable() {
public void run() {
String message = "Do you want to remove read only flag on those files ?\n\n";
- for(IFile file : files) {
+ for(URI uri : uris) {
+ IFile file = getFile(uri);
if(file != null && file.isReadOnly()) {
message += file.getName() + "\n";
}
@@ -50,7 +64,8 @@ public class FSReadOnlyHandler implements IReadOnlyHandler {
if(doEnableWrite.get()) {
boolean ok = true;
- for(IFile file : files) {
+ for(URI uri : uris) {
+ IFile file = getFile(uri);
if(file != null && file.isReadOnly()) {
try {
ResourceAttributes att = file.getResourceAttributes();
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/IReadOnlyHandler.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/IReadOnlyHandler.java
index bbe6d16a869..63973341a95 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/IReadOnlyHandler.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/IReadOnlyHandler.java
@@ -13,7 +13,7 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.emf.readonly;
-import org.eclipse.core.resources.IFile;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.edit.domain.EditingDomain;
public interface IReadOnlyHandler {
@@ -26,7 +26,7 @@ public interface IReadOnlyHandler {
* @param files
* @return
*/
- boolean isReadOnly(IFile[] files, EditingDomain editingDomain);
+ boolean isReadOnly(URI[] uris, EditingDomain editingDomain);
/**
* Try to enable write access on a set of files.
@@ -34,5 +34,5 @@ public interface IReadOnlyHandler {
* @param files
* @return false if it fails to get write access.
*/
- boolean enableWrite(IFile[] files, EditingDomain editingDomain);
+ boolean enableWrite(URI[] uris, EditingDomain editingDomain);
}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java
index 5848edf1f67..47e6b9af11b 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/PapyrusROTransactionalEditingDomain.java
@@ -21,6 +21,7 @@ import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl;
public class PapyrusROTransactionalEditingDomain extends TransactionalEditingDomainImpl {
+
public PapyrusROTransactionalEditingDomain(AdapterFactory adapterFactory, TransactionalCommandStack stack, ResourceSet resourceSet) {
super(adapterFactory, stack, resourceSet);
}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManager.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManager.java
index 87b07010a9c..e5bf12d80b9 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManager.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManager.java
@@ -18,10 +18,9 @@ import java.util.LinkedList;
import java.util.List;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
@@ -47,7 +46,7 @@ public class ReadOnlyManager {
}
static {
- IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.papyrus.readonly", "readOnlyHandler");
+ IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.papyrus.infra.emf.readonly", "readOnlyHandler");
List<HandlerPriorityPair> handlerPriorityPairs = new LinkedList<HandlerPriorityPair>();
for(IConfigurationElement elem : configElements) {
@@ -59,6 +58,7 @@ public class ReadOnlyManager {
handlerPriorityPairs.add(handlerPriorityPair);
} catch (Exception e) {
+ Activator.log.error(e);
}
}
}
@@ -73,34 +73,46 @@ public class ReadOnlyManager {
}
public static boolean isReadOnly(Resource resource, EditingDomain editingDomain) {
- IFile file = null;
+ URI uri = null;
if(resource != null && resource.getURI() != null) {
- if (resource.getURI().isPlatform()) {
- file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(resource.getURI().toPlatformString(true)));
- }
+
+ uri = resource.getURI();
}
- return isReadOnly(file, editingDomain);
+ return isReadOnly(uri, editingDomain);
+ }
+
+ private static URI getURI(IFile iFile) {
+ return URI.createPlatformResourceURI(iFile.getFullPath().toString(), true);
}
- public static boolean isReadOnly(IFile file, EditingDomain editingDomain) {
- IFile[] files = file != null ? new IFile[]{ file } : new IFile[]{};
- return isReadOnly(files, editingDomain);
+ private static URI[] getURIs(IFile[] iFiles) {
+ URI[] uris = new URI[iFiles.length];
+ int i = 0;
+ for(IFile iFile : iFiles) {
+ uris[i++] = getURI(iFile);
+ }
+ return uris;
}
- public static boolean isReadOnly(IFile[] files, EditingDomain editingDomain) {
+ public static boolean isReadOnly(URI uri, EditingDomain editingDomain) {
+ URI[] uris = uri != null ? new URI[]{ uri } : new URI[]{};
+ return isReadOnly(uris, editingDomain);
+ }
+
+ public static boolean isReadOnly(URI[] uris, EditingDomain editingDomain) {
for(int i = 0; i < orderedHandlersArray.length; i++) {
- if(orderedHandlersArray[i].isReadOnly(files, editingDomain)) {
+ if(orderedHandlersArray[i].isReadOnly(uris, editingDomain)) {
return true;
}
}
return false;
}
- public static boolean enableWrite(IFile[] files, EditingDomain editingDomain) {
+ public static boolean enableWrite(URI[] uris, EditingDomain editingDomain) {
for(int i = 0; i < orderedHandlersArray.length; i++) {
- if(orderedHandlersArray[i].isReadOnly(files, editingDomain)) {
- boolean ok = orderedHandlersArray[i].enableWrite(files, editingDomain);
+ if(orderedHandlersArray[i].isReadOnly(uris, editingDomain)) {
+ boolean ok = orderedHandlersArray[i].enableWrite(uris, editingDomain);
if(!ok) {
return false;
}
@@ -109,4 +121,12 @@ public class ReadOnlyManager {
return true;
}
+
+ public static boolean isReadOnly(IFile[] iFiles, EditingDomain editingDomain) {
+ return isReadOnly(getURIs(iFiles), editingDomain);
+ }
+
+ public static boolean enableWrite(IFile[] iFiles, EditingDomain editingDomain) {
+ return enableWrite(getURIs(iFiles), editingDomain);
+ }
}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyTester.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyTester.java
index 84131173509..908a105d506 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyTester.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyTester.java
@@ -36,7 +36,7 @@ public class ReadOnlyTester extends PropertyTester {
Object businessObject = BusinessModelResolver.getInstance().getBusinessModel(obj);
if(businessObject instanceof EObject) {
Resource resource = ((EObject)businessObject).eResource();
- if (resource != null && resource.getResourceSet() != null) {
+ if(resource != null && resource.getResourceSet() != null) {
return ReadOnlyManager.isReadOnly(resource, WorkspaceEditingDomainFactory.INSTANCE.getEditingDomain(resource.getResourceSet()));
}
}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/handlers/EnableWriteHandler.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/handlers/EnableWriteHandler.java
index 1d69c09f255..2dd6cd10c81 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/handlers/EnableWriteHandler.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/handlers/EnableWriteHandler.java
@@ -28,17 +28,19 @@ public class EnableWriteHandler extends AbstractHandler {
Resource res = elem.eResource();
ResourceSet rs = res.getResourceSet();
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(res.getURI().toPlatformString(true)));
- IPapyrusFile papFile = PapyrusModelHelper.getPapyrusModelFactory().createIPapyrusFile(file);
- IFile[] associatedFiles = OneFileUtils.getAssociatedFiles(papFile);
+ if(res.getURI() != null && res.getURI().isPlatformResource()) {
+ IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(res.getURI().toPlatformString(true)));
+ IPapyrusFile papFile = PapyrusModelHelper.getPapyrusModelFactory().createIPapyrusFile(file);
+ IFile[] associatedFiles = OneFileUtils.getAssociatedFiles(papFile);
- ReadOnlyManager.enableWrite(associatedFiles, WorkspaceEditingDomainFactory.INSTANCE.getEditingDomain(rs));
+ ReadOnlyManager.enableWrite(associatedFiles, WorkspaceEditingDomainFactory.INSTANCE.getEditingDomain(rs));
- for(IFile associatedFile : associatedFiles) {
- URI associatedUri = URI.createPlatformResourceURI(associatedFile.getFullPath().toString(), true);
- Resource associatedResource = rs.getResource(associatedUri, true);
- if(associatedResource != null) {
- associatedResource.setModified(true);
+ for(IFile associatedFile : associatedFiles) {
+ URI associatedUri = URI.createPlatformResourceURI(associatedFile.getFullPath().toString(), true);
+ Resource associatedResource = rs.getResource(associatedUri, true);
+ if(associatedResource != null) {
+ associatedResource.setModified(true);
+ }
}
}
}
diff --git a/plugins/team/org.eclipse.papyrus.team.svn/src/org/eclipse/papyrus/team/svn/SVNLockHandler.java b/plugins/team/org.eclipse.papyrus.team.svn/src/org/eclipse/papyrus/team/svn/SVNLockHandler.java
index ee73a06fedc..39ab94d4424 100644
--- a/plugins/team/org.eclipse.papyrus.team.svn/src/org/eclipse/papyrus/team/svn/SVNLockHandler.java
+++ b/plugins/team/org.eclipse.papyrus.team.svn/src/org/eclipse/papyrus/team/svn/SVNLockHandler.java
@@ -15,8 +15,11 @@ package org.eclipse.papyrus.team.svn;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.resources.team.FileModificationValidationContext;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.papyrus.infra.emf.readonly.IReadOnlyHandler;
import org.eclipse.team.svn.core.IStateFilter;
@@ -28,9 +31,9 @@ public class SVNLockHandler implements IReadOnlyHandler {
SVNTeamModificationValidator validator = new SVNTeamModificationValidator();
- public boolean isReadOnly(IFile[] files, EditingDomain editingDomain) {
+ public boolean isReadOnly(URI[] uris, EditingDomain editingDomain) {
- IResource[] needsLockResources = FileUtility.filterResources(files, IStateFilter.SF_NEEDS_LOCK, IResource.DEPTH_ZERO);
+ IResource[] needsLockResources = FileUtility.filterResources(getIFiles(uris), IStateFilter.SF_NEEDS_LOCK, IResource.DEPTH_ZERO);
for(IResource needsLockResource : needsLockResources) {
if(!SVNRemoteStorage.instance().asLocalResource(needsLockResource).isLocked()) {
return true;
@@ -40,9 +43,25 @@ public class SVNLockHandler implements IReadOnlyHandler {
return false;
}
- public boolean enableWrite(IFile[] files, EditingDomain editingDomain) {
+ private IFile[] getIFiles(URI[] uris) {
+ IFile[] iFiles = new IFile[uris.length];
+ int i = 0;
+ for(URI uri : uris) {
+ iFiles[i++] = getFile(uri);
+ }
+ return iFiles;
+ }
+
+ private static IFile getFile(URI uri) {
+ if(uri.isPlatform()) {
+ return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
+ }
+ return null;
+ }
+
+ public boolean enableWrite(URI[] uris, EditingDomain editingDomain) {
- IStatus result = validator.validateEdit(files, FileModificationValidationContext.VALIDATE_PROMPT);
+ IStatus result = validator.validateEdit(getIFiles(uris), FileModificationValidationContext.VALIDATE_PROMPT);
return result.isOK();
}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF b/plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF
index e075ca0bc9d..add00c9dab8 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@ Require-Bundle: org.eclipse.uml2.uml.editor,
org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.200",
org.eclipse.papyrus.infra.widgets;bundle-version="0.9.0",
org.eclipse.papyrus.uml.tools;bundle-version="0.9.0",
+ org.eclipse.papyrus.infra.emf.readonly;bundle-version="0.9.0",
org.eclipse.papyrus.infra.services.validation;bundle-version="0.9.0"
Export-Package: org.eclipse.papyrus.uml.profile,
org.eclipse.papyrus.uml.profile.constraints,
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/plugin.xml b/plugins/uml/org.eclipse.papyrus.uml.profile/plugin.xml
index 561063490e7..ad2e49030c5 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.profile/plugin.xml
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/plugin.xml
@@ -117,6 +117,13 @@
</modelSetSnippet>
</extension>
<extension
+ point="org.eclipse.papyrus.infra.emf.readonly.readOnlyHandler">
+ <readOnlyHandler
+ class="org.eclipse.papyrus.uml.profile.readonly.AppliedProfileReadOnlyHandler"
+ priority="15">
+ </readOnlyHandler>
+ </extension>
+ <extension
point="org.eclipse.emf.validation.constraintBindings">
<clientContext
id="org.eclipse.papyrus.uml.profile.clientContext">
diff --git a/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/readonly/AppliedProfileReadOnlyHandler.java b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/readonly/AppliedProfileReadOnlyHandler.java
new file mode 100644
index 00000000000..b15e6f44031
--- /dev/null
+++ b/plugins/uml/org.eclipse.papyrus.uml.profile/src/org/eclipse/papyrus/uml/profile/readonly/AppliedProfileReadOnlyHandler.java
@@ -0,0 +1,70 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.profile.readonly;
+
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.core.resource.uml.UmlModel;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.readonly.IReadOnlyHandler;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.uml2.uml.Profile;
+
+
+public class AppliedProfileReadOnlyHandler implements IReadOnlyHandler {
+
+ public boolean isReadOnly(URI[] uris, EditingDomain editingDomain) {
+ for(URI uri : uris) {
+ Resource resource = editingDomain.getResourceSet().getResource(uri, false);
+ if(isProfileResource(resource)) {
+ try {
+ ModelSet modelSet = ServiceUtilsForResource.getInstance().getModelSet(resource);
+ UmlModel umlModel = (UmlModel)modelSet.getModel(UmlModel.MODEL_ID);
+ if(umlModel != null) {
+ Resource mainResource = umlModel.getResource();
+ if(mainResource != resource) {
+ return true;
+ }
+ }
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ private boolean isProfileResource(Resource resource) {
+ if(resource == null) {
+ return false;
+ }
+
+ for(EObject rootElement : resource.getContents()) {
+ if(rootElement instanceof Profile) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean enableWrite(URI[] uris, EditingDomain editingDomain) {
+ return false; //Applied profiles should remain read-only
+ }
+
+}

Back to the top