Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-08-02 09:36:42 -0400
committercletavernie2012-08-02 09:36:42 -0400
commitdb5fbfa853642ddce82f99759148ec70e0cc9df3 (patch)
tree6026aef80492a5aedc788509339681761dc9d9e0 /plugins/infra
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/infra')
-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
10 files changed, 105 insertions, 35 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);
+ }
}
}
}

Back to the top