Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2014-03-11 20:54:40 +0000
committerChristian W. Damus2014-03-11 20:54:40 +0000
commit6c21353faf0dbb249e8c42d0ef3a6c23ff1120ef (patch)
tree35b3b0404025103c63f1aa4d197cefa53b03c139 /plugins/infra
parent1b5e1fc50200467c3a1bc3dd6614c78a1df293cf (diff)
downloadorg.eclipse.papyrus-6c21353faf0dbb249e8c42d0ef3a6c23ff1120ef.tar.gz
org.eclipse.papyrus-6c21353faf0dbb249e8c42d0ef3a6c23ff1120ef.tar.xz
org.eclipse.papyrus-6c21353faf0dbb249e8c42d0ef3a6c23ff1120ef.zip
429826: [Read-Only] Orthogonal Classification of Read-Only Concerns
https://bugs.eclipse.org/bugs/show_bug.cgi?id=429826 Add affinity with specified read-only axes to the extension metadata for read-only handlers and use this to partition the queries for read-only state by axis in the ReadOnlyManager. A new JUnit test demonstrates that this fixes the problem of read-only *.sash/*.di resources being mistaken as writable because of the SashModelReadOnlyHandler. Because this handler depends on the ModelSet, the JUnit test fixture is updated to use a ModelSet instead of a simple ResourceSet. The FSReadOnlyHandler is updated to report read-only state of file: scheme URIs and the EMFReadOnlyHandler accepts these URIs in addition to platform:/resource URIs.
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ReadOnlyAxis.java16
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/plugin.xml15
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/schema/readOnlyHandler.exsd260
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/EMFReadOnlyHandler.java2
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/FSReadOnlyHandler.java47
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/src/org/eclipse/papyrus/infra/emf/readonly/ReadOnlyManager.java187
6 files changed, 362 insertions, 165 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ReadOnlyAxis.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ReadOnlyAxis.java
index c404a86a125..bde0a900c44 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ReadOnlyAxis.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ReadOnlyAxis.java
@@ -45,6 +45,22 @@ public enum ReadOnlyAxis {
private static final Set<ReadOnlyAxis> DISCRETION_AXES = Collections.singleton(DISCRETION);
/**
+ * Efficiently obtains me as a singleton set.
+ *
+ * @return a singleton set containing me only
+ */
+ public Set<ReadOnlyAxis> singleton() {
+ switch(this) {
+ case PERMISSION:
+ return PERMISSION_AXES;
+ case DISCRETION:
+ return DISCRETION_AXES;
+ default:
+ throw new IllegalStateException("Impossible enumeration value: " + this); //$NON-NLS-1$
+ }
+ }
+
+ /**
* The set of axes for queries pertaining to any axis. That is to say, the complete set of all axes.
*/
public static Set<ReadOnlyAxis> anyAxis() {
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 0306ae0a75a..6232c1f3e44 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,20 +8,33 @@
class="org.eclipse.papyrus.infra.emf.readonly.ReferencedModelReadOnlyHandler"
id="org.eclipse.papyrus.infra.emf.readonly.ReferencedModelReadOnlyHandler"
priority="15">
+ <affinity
+ axis="discretion">
+ </affinity>
</readOnlyHandler>
<readOnlyHandler
class="org.eclipse.papyrus.infra.emf.readonly.FSReadOnlyHandler"
id="org.eclipse.papyrus.infra.emf.readonly.FSReadOnlyHandler"
priority="10">
+ <affinity
+ axis="permission">
+ </affinity>
</readOnlyHandler>
<readOnlyHandler
class="org.eclipse.papyrus.infra.emf.readonly.EMFReadOnlyHandler"
id="org.eclipse.papyrus.infra.emf.readonly.EMFReadOnlyHandler"
priority="5">
+ <affinity
+ axis="permission">
+ </affinity>
</readOnlyHandler>
<readOnlyHandler
class="org.eclipse.papyrus.infra.emf.readonly.SashModelReadOnlyHandler"
- priority="20"></readOnlyHandler>
+ priority="20">
+ <affinity
+ axis="discretion">
+ </affinity>
+ </readOnlyHandler>
</extension>
<extension
point="org.eclipse.ui.handlers">
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/schema/readOnlyHandler.exsd b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/schema/readOnlyHandler.exsd
index f6e1fa72735..cc704afdf94 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/schema/readOnlyHandler.exsd
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf.readonly/schema/readOnlyHandler.exsd
@@ -1,116 +1,144 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.papyrus.infra.emf.readonly" xmlns="http://www.w3.org/2001/XMLSchema">
-<annotation>
- <appinfo>
- <meta.schema plugin="org.eclipse.papyrus.infra.emf.readonly" id="readOnly" name="readOnly"/>
- </appinfo>
- <documentation>
- [Enter description of this extension point.]
- </documentation>
- </annotation>
-
- <element name="extension">
- <annotation>
- <appinfo>
- <meta.element />
- </appinfo>
- </annotation>
- <complexType>
- <sequence>
- <element ref="readOnlyHandler" minOccurs="0" maxOccurs="unbounded"/>
- </sequence>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute translatable="true"/>
- </appinfo>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="readOnlyHandler">
- <complexType>
- <attribute name="class" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appinfo>
- <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.infra.core.resource.IReadOnlyHandler"/>
- </appinfo>
- </annotation>
- </attribute>
- <attribute name="priority" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
- optional id that can be used if this read only handler can be overriden.
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appinfo>
- <meta.section type="since"/>
- </appinfo>
- <documentation>
- [Enter the first release in which this extension point appears.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="examples"/>
- </appinfo>
- <documentation>
- [Enter extension point usage example here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="apiinfo"/>
- </appinfo>
- <documentation>
- [Enter API information here.]
- </documentation>
- </annotation>
-
- <annotation>
- <appinfo>
- <meta.section type="implementation"/>
- </appinfo>
- <documentation>
- [Enter information about supplied implementation of this extension point.]
- </documentation>
- </annotation>
-
-
-</schema>
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.papyrus.infra.emf.readonly" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.papyrus.infra.emf.readonly" id="readOnly" name="readOnly"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="readOnlyHandler" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="readOnlyHandler">
+ <complexType>
+ <sequence>
+ <element ref="affinity" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="class" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.papyrus.infra.core.resource.IReadOnlyHandler"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ <attribute name="priority" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+ optional id that can be used if this read only handler can be overriden.
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="affinity">
+ <annotation>
+ <documentation>
+ Declaration of a handler&apos;s affinity with a particular read-only axis.
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="axis" use="required">
+ <annotation>
+ <documentation>
+ The read-only axis (as enumerated in the &lt;tt&gt;ReadOnlyAxis&lt;/tt&gt; type) to which handler is applicable.
+ </documentation>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="discretion">
+ </enumeration>
+ <enumeration value="permission">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiinfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
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
index e116936ea58..dd3fd1226ca 100644
--- 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
@@ -34,7 +34,7 @@ public class EMFReadOnlyHandler extends AbstractReadOnlyHandler {
public Optional<Boolean> anyReadOnly(Set<ReadOnlyAxis> axes, URI[] uris) {
if(axes.contains(ReadOnlyAxis.PERMISSION)) {
for(URI uri : uris) {
- if(!uri.isPlatformResource()) {
+ if(!(uri.isPlatformResource() || uri.isFile())) {
return Optional.of(Boolean.TRUE);
}
}
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 c279d378bbc..5df8b04d757 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
@@ -15,6 +15,7 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.emf.readonly;
+import java.io.File;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
@@ -44,45 +45,59 @@ public class FSReadOnlyHandler extends AbstractReadOnlyHandler {
}
public Optional<Boolean> anyReadOnly(Set<ReadOnlyAxis> axes, URI[] uris) {
- if (axes.contains(ReadOnlyAxis.PERMISSION)) {
+ if(axes.contains(ReadOnlyAxis.PERMISSION)) {
for(URI uri : uris) {
- IFile file = getFile(uri);
- if(file != null && file.isReadOnly()) {
- return Optional.of(Boolean.TRUE);
+ IFile ifile = getIFile(uri);
+ if(ifile != null) {
+ if(ifile.isReadOnly()) {
+ return Optional.of(Boolean.TRUE);
+ }
+ } else {
+ File file = getFile(uri);
+ if((file != null) && file.exists() && !file.canWrite()) {
+ return Optional.of(Boolean.TRUE);
+ }
}
}
}
-
+
return Optional.absent();
}
- private static IFile getFile(URI uri) {
+ private static IFile getIFile(URI uri) {
if(uri.isPlatform()) {
return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uri.toPlatformString(true)));
}
return null;
}
+ private static File getFile(URI uri) {
+ if(uri.isFile()) {
+ return new File(uri.toFileString());
+ }
+ return null;
+ }
+
public Optional<Boolean> makeWritable(Set<ReadOnlyAxis> axes, final URI[] uris) {
- if (!axes.contains(ReadOnlyAxis.PERMISSION)) {
+ if(!axes.contains(ReadOnlyAxis.PERMISSION)) {
return Optional.absent();
}
-
+
final AtomicBoolean doEnableWrite = new AtomicBoolean();
-
+
// We can't make a file writable if it already is (there are read-only handlers that treat files that
// are filesystem-writable as read-only for other reasons)
final Map<IFile, URI> readOnlyFiles = new LinkedHashMap<IFile, URI>();
for(int i = 0; i < uris.length; i++) {
- IFile file = getFile(uris[i]);
+ IFile file = getIFile(uris[i]);
if((file != null) && file.isReadOnly()) {
readOnlyFiles.put(file, uris[i]);
}
}
-
- if (!readOnlyFiles.isEmpty()) {
+
+ if(!readOnlyFiles.isEmpty()) {
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 : readOnlyFiles.keySet()) {
@@ -92,7 +107,7 @@ public class FSReadOnlyHandler extends AbstractReadOnlyHandler {
}
});
}
-
+
if(doEnableWrite.get()) {
Boolean ok = true;
for(Map.Entry<IFile, URI> next : readOnlyFiles.entrySet()) {
@@ -101,7 +116,7 @@ public class FSReadOnlyHandler extends AbstractReadOnlyHandler {
ResourceAttributes att = file.getResourceAttributes();
att.setReadOnly(false);
file.setResourceAttributes(att);
-
+
fireReadOnlyStateChanged(ReadOnlyAxis.PERMISSION, next.getValue(), true);
} catch (CoreException e) {
ok = false;
@@ -130,7 +145,7 @@ public class FSReadOnlyHandler extends AbstractReadOnlyHandler {
}
}
}
-
+
return result;
}
}
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 e082c0a0f14..9e849a4120a 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
@@ -21,7 +21,10 @@ import static org.eclipse.papyrus.infra.core.resource.ReadOnlyAxis.permissionAxe
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -71,6 +74,8 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
public Class<?> handlerClass;
public int priority;
+
+ public Set<ReadOnlyAxis> axes;
public int compareTo(HandlerPriorityPair o) {
if(o.priority > priority) {
@@ -83,7 +88,7 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
}
}
- protected static final Class<?>[] orderedHandlerClassesArray;
+ protected static final Map<Class<?>, Set<ReadOnlyAxis>> orderedHandlerClasses;
static {
IConfigurationElement[] configElements = Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.papyrus.infra.emf.readonly", "readOnlyHandler");
@@ -99,6 +104,18 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
handlerPriorityPair.handlerClass = Platform.getBundle(elem.getContributor().getName()).loadClass(className);
handlerPriorityPair.priority = Integer.parseInt(elem.getAttribute("priority"));
+
+ IConfigurationElement[] affinities = elem.getChildren("affinity");
+ if ((affinities == null) || (affinities.length == 0)) {
+ // implicit affinity is with any axis
+ handlerPriorityPair.axes = ReadOnlyAxis.anyAxis();
+ } else {
+ handlerPriorityPair.axes = EnumSet.noneOf(ReadOnlyAxis.class);
+ for (IConfigurationElement next : affinities) {
+ handlerPriorityPair.axes.add(ReadOnlyAxis.valueOf(next.getAttribute("axis").toUpperCase()));
+ }
+ }
+
String id = elem.getAttribute("id");
if(id != null) {
//if any then the handler could be overrided by another registration
@@ -126,10 +143,10 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
Collections.sort(handlerPriorityPairs);
- orderedHandlerClassesArray = new Class<?>[handlerPriorityPairs.size()];
+ orderedHandlerClasses = new LinkedHashMap<Class<?>, Set<ReadOnlyAxis>>();
- for(int i = 0; i < orderedHandlerClassesArray.length; i++) {
- orderedHandlerClassesArray[i] = handlerPriorityPairs.get(i).handlerClass;
+ for(HandlerPriorityPair next : handlerPriorityPairs) {
+ orderedHandlerClasses.put(next.handlerClass, next.axes);
}
}
@@ -166,25 +183,58 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
return null;
}
- protected IReadOnlyHandler2[] orderedHandlersArray;
+ protected Map<ReadOnlyAxis, IReadOnlyHandler2[]> orderedHandlersByAxis;
public ReadOnlyManager(EditingDomain editingDomain) {
- ArrayList<IReadOnlyHandler2> handlers = new ArrayList<IReadOnlyHandler2>();
- for(Class<?> roClass : orderedHandlerClassesArray) {
- IReadOnlyHandler2 h = create(roClass, editingDomain);
+ Map<ReadOnlyAxis, List<IReadOnlyHandler2>> handlers = new EnumMap<ReadOnlyAxis, List<IReadOnlyHandler2>>(ReadOnlyAxis.class);
+ for(Map.Entry<Class<?>, Set<ReadOnlyAxis>> roClass : orderedHandlerClasses.entrySet()) {
+ IReadOnlyHandler2 h = create(roClass.getKey(), editingDomain);
if(h != null) {
- handlers.add(h);
h.addReadOnlyListener(getForwardingListener());
+
+ for (ReadOnlyAxis axis : roClass.getValue()) {
+ List<IReadOnlyHandler2> list = handlers.get(axis);
+ if (list == null) {
+ list = new ArrayList<IReadOnlyHandler2>();
+ handlers.put(axis, list);
+ }
+ list.add(h);
+ }
+ }
+ }
+
+ // Iterate the enumeration to make sure all axes are represented (even if only by an empty array)
+ orderedHandlersByAxis = new EnumMap<ReadOnlyAxis, IReadOnlyHandler2[]>(ReadOnlyAxis.class);
+ for(ReadOnlyAxis axis : ReadOnlyAxis.values()) {
+ List<IReadOnlyHandler2> list = handlers.get(axis);
+ if(list == null) {
+ orderedHandlersByAxis.put(axis, new IReadOnlyHandler2[0]);
+ } else {
+ orderedHandlersByAxis.put(axis, list.toArray(new IReadOnlyHandler2[list.size()]));
}
}
- orderedHandlersArray = handlers.toArray(new IReadOnlyHandler2[handlers.size()]);
}
public Optional<Boolean> anyReadOnly(Set<ReadOnlyAxis> axes, URI[] uris) {
Optional<Boolean> result = Optional.absent();
- for(int i = 0; (i < orderedHandlersArray.length) && !result.isPresent(); i++) {
- result = orderedHandlersArray[i].anyReadOnly(axes, uris);
+ ReadOnlyAxis[] all = ReadOnlyAxis.values();
+ for(int i = 0; (i < all.length) && !result.or(Boolean.FALSE); i++) {
+ if(axes.contains(all[i])) {
+ result = anyReadOnly(all[i], uris);
+ }
+ }
+
+ return result.isPresent() ? result : Optional.of(Boolean.FALSE);
+ }
+
+ private Optional<Boolean> anyReadOnly(ReadOnlyAxis axis, URI[] uris) {
+ Set<ReadOnlyAxis> axes = axis.singleton();
+ Optional<Boolean> result = Optional.absent();
+
+ IReadOnlyHandler2[] orderedHandlers = orderedHandlersByAxis.get(axis);
+ for(int i = 0; (i < orderedHandlers.length) && !result.isPresent(); i++) {
+ result = orderedHandlers[i].anyReadOnly(axes, uris);
}
return result.isPresent() ? result : Optional.of(Boolean.FALSE);
@@ -193,8 +243,23 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
public Optional<Boolean> isReadOnly(Set<ReadOnlyAxis> axes, EObject eObject) {
Optional<Boolean> result = Optional.absent();
- for(int i = 0; (i < orderedHandlersArray.length) && !result.isPresent(); i++) {
- result = orderedHandlersArray[i].isReadOnly(axes, eObject);
+ ReadOnlyAxis[] all = ReadOnlyAxis.values();
+ for(int i = 0; (i < all.length) && !result.or(Boolean.FALSE); i++) {
+ if(axes.contains(all[i])) {
+ result = isReadOnly(all[i], eObject);
+ }
+ }
+
+ return result.isPresent() ? result : Optional.of(Boolean.FALSE);
+ }
+
+ private Optional<Boolean> isReadOnly(ReadOnlyAxis axis, EObject eObject) {
+ Set<ReadOnlyAxis> axes = axis.singleton();
+ Optional<Boolean> result = Optional.absent();
+
+ IReadOnlyHandler2[] orderedHandlers = orderedHandlersByAxis.get(axis);
+ for(int i = 0; (i < orderedHandlers.length) && !result.isPresent(); i++) {
+ result = orderedHandlers[i].isReadOnly(axes, eObject);
}
return result.isPresent() ? result : Optional.of(Boolean.FALSE);
@@ -203,10 +268,25 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
public Optional<Boolean> makeWritable(Set<ReadOnlyAxis> axes, URI[] uris) {
Boolean finalResult = true;
- for(int i = 0; (i < orderedHandlersArray.length); i++) {
- Optional<Boolean> isRO = orderedHandlersArray[i].anyReadOnly(axes, uris);
+ ReadOnlyAxis[] all = ReadOnlyAxis.values();
+ for(int i = 0; (i < all.length) && finalResult; i++) {
+ if(axes.contains(all[i])) {
+ finalResult = makeWritable(all[i], uris);
+ }
+ }
+
+ return Optional.of(finalResult);
+ }
+
+ private Boolean makeWritable(ReadOnlyAxis axis, URI[] uris) {
+ Set<ReadOnlyAxis> axes = axis.singleton();
+ Boolean finalResult = true;
+
+ IReadOnlyHandler2[] orderedHandlers = orderedHandlersByAxis.get(axis);
+ for(int i = 0; (i < orderedHandlers.length); i++) {
+ Optional<Boolean> isRO = orderedHandlers[i].anyReadOnly(axes, uris);
if(isRO.or(Boolean.FALSE)) {
- Optional<Boolean> result = orderedHandlersArray[i].makeWritable(axes, uris);
+ Optional<Boolean> result = orderedHandlers[i].makeWritable(axes, uris);
// makeWritable should provide an answer since anyReadOnly returned a positive value.
// If no answer consider it a failure
if(!result.or(Boolean.FALSE)) {
@@ -216,16 +296,31 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
}
}
- return Optional.of(finalResult);
+ return finalResult;
}
public Optional<Boolean> makeWritable(Set<ReadOnlyAxis> axes, EObject eObject) {
Boolean finalResult = true;
- for(int i = 0; (i < orderedHandlersArray.length); i++) {
- Optional<Boolean> isRO = orderedHandlersArray[i].isReadOnly(axes, eObject);
+ ReadOnlyAxis[] all = ReadOnlyAxis.values();
+ for(int i = 0; (i < all.length) && finalResult; i++) {
+ if(axes.contains(all[i])) {
+ finalResult = makeWritable(all[i], eObject);
+ }
+ }
+
+ return Optional.of(finalResult);
+ }
+
+ private Boolean makeWritable(ReadOnlyAxis axis, EObject eObject) {
+ Set<ReadOnlyAxis> axes = axis.singleton();
+ Boolean finalResult = true;
+
+ IReadOnlyHandler2[] orderedHandlers = orderedHandlersByAxis.get(axis);
+ for(int i = 0; (i < orderedHandlers.length); i++) {
+ Optional<Boolean> isRO = orderedHandlers[i].isReadOnly(axes, eObject);
if(isRO.or(Boolean.FALSE)) {
- Optional<Boolean> result = orderedHandlersArray[i].makeWritable(axes, eObject);
+ Optional<Boolean> result = orderedHandlers[i].makeWritable(axes, eObject);
// makeWritable should provide an answer since anyReadOnly returned a positive value
// if no answer consider it a failure
if(!result.or(Boolean.FALSE)) {
@@ -235,16 +330,31 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
}
}
- return Optional.of(finalResult);
+ return finalResult;
}
public Optional<Boolean> canMakeWritable(Set<ReadOnlyAxis> axes, URI[] uris) {
Boolean result = false;
- for(int i = 0; (i < orderedHandlersArray.length); i++) {
- if(orderedHandlersArray[i].anyReadOnly(axes, uris).or(false)) {
+ ReadOnlyAxis[] all = ReadOnlyAxis.values();
+ for(int i = 0; (i < all.length) && !result; i++) {
+ if(axes.contains(all[i])) {
+ result = canMakeWritable(all[i], uris);
+ }
+ }
+
+ return Optional.of(result);
+ }
+
+ private Boolean canMakeWritable(ReadOnlyAxis axis, URI[] uris) {
+ Set<ReadOnlyAxis> axes = axis.singleton();
+ Boolean result = false;
+
+ IReadOnlyHandler2[] orderedHandlers = orderedHandlersByAxis.get(axis);
+ for(int i = 0; (i < orderedHandlers.length); i++) {
+ if(orderedHandlers[i].anyReadOnly(axes, uris).or(false)) {
// Only ask a handler about making writable what it considers to be read-only
- Optional<Boolean> canMakeWritable = orderedHandlersArray[i].canMakeWritable(axes, uris);
+ Optional<Boolean> canMakeWritable = orderedHandlers[i].canMakeWritable(axes, uris);
if(canMakeWritable.isPresent()) {
result = canMakeWritable.get();
break;
@@ -252,16 +362,31 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
}
}
- return Optional.of(result);
+ return result;
}
public Optional<Boolean> canMakeWritable(Set<ReadOnlyAxis> axes, EObject object) {
Boolean result = false;
- for(int i = 0; (i < orderedHandlersArray.length); i++) {
- if(orderedHandlersArray[i].isReadOnly(axes, object).or(false)) {
+ ReadOnlyAxis[] all = ReadOnlyAxis.values();
+ for(int i = 0; (i < all.length) && !result; i++) {
+ if(axes.contains(all[i])) {
+ result = canMakeWritable(all[i], object);
+ }
+ }
+
+ return Optional.of(result);
+ }
+
+ private Boolean canMakeWritable(ReadOnlyAxis axis, EObject object) {
+ Set<ReadOnlyAxis> axes = axis.singleton();
+ Boolean result = false;
+
+ IReadOnlyHandler2[] orderedHandlers = orderedHandlersByAxis.get(axis);
+ for(int i = 0; (i < orderedHandlers.length); i++) {
+ if(orderedHandlers[i].isReadOnly(axes, object).or(false)) {
// Only ask a handler about making writable what it considers to be read-only
- Optional<Boolean> canMakeWritable = orderedHandlersArray[i].canMakeWritable(axes, object);
+ Optional<Boolean> canMakeWritable = orderedHandlers[i].canMakeWritable(axes, object);
if(canMakeWritable.isPresent()) {
result = canMakeWritable.get();
break;
@@ -269,7 +394,7 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
}
}
- return Optional.of(result);
+ return result;
}
public void addReadOnlyListener(IReadOnlyListener listener) {
@@ -375,4 +500,4 @@ public class ReadOnlyManager implements IReadOnlyHandler2 {
return delegateResult ? Optional.<Boolean> absent() : Optional.of(Boolean.FALSE);
}
}
-}
+} \ No newline at end of file

Back to the top