Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-11-27 13:16:26 -0500
committerslewis2008-11-27 13:16:26 -0500
commitd90b6c1bfef509fd9e325fa00859ba1fcf0d5490 (patch)
tree57f182a86a224699117df840a68804ea4ce92096 /framework/bundles/org.eclipse.ecf.sync
parenta189d6edfc78e85587d61846146eb8e6f3664a92 (diff)
downloadorg.eclipse.ecf-d90b6c1bfef509fd9e325fa00859ba1fcf0d5490.tar.gz
org.eclipse.ecf-d90b6c1bfef509fd9e325fa00859ba1fcf0d5490.tar.xz
org.eclipse.ecf-d90b6c1bfef509fd9e325fa00859ba1fcf0d5490.zip
Added IModelChange.applyToModel(Object) method as per https://bugs.eclipse.org/bugs/show_bug.cgi?id=234142#c32
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.sync')
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF1
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java13
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/ModelUpdateException.java45
-rw-r--r--framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java17
4 files changed, 76 insertions, 0 deletions
diff --git a/framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF
index eb666affa..6e6498e16 100644
--- a/framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.sync/META-INF/MANIFEST.MF
@@ -9,6 +9,7 @@ Bundle-RequiredExecutionEnvironment: J2SE-1.4
Import-Package: org.eclipse.core.runtime,
org.eclipse.ecf.core.identity,
org.eclipse.ecf.core.util,
+ org.eclipse.jface.text,
org.eclipse.osgi.util,
org.osgi.framework,
org.osgi.service.log,
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java
index 400017b41..7d79965f1 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/IModelChange.java
@@ -21,4 +21,17 @@ import org.eclipse.core.runtime.IAdaptable;
*/
public interface IModelChange extends IAdaptable {
+ /**
+ * Apply the change to a model. Clients may use this method
+ * to apply the change to a model of appropriate type (e.g. IDocument
+ * for IDocumentChange).
+ *
+ * @param model the model to apply this change to. Must not be <code>null</code>.
+ * Should be of type appropriate to the model.
+ *
+ * @throws ModelUpdateException thrown if model is <code>null</code>, of incorrect
+ * type, or cannot be changed.
+ */
+ public void applyToModel(Object model) throws ModelUpdateException;
+
}
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/ModelUpdateException.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/ModelUpdateException.java
new file mode 100644
index 000000000..474739a21
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/ModelUpdateException.java
@@ -0,0 +1,45 @@
+package org.eclipse.ecf.sync;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.ecf.core.util.ECFException;
+
+public class ModelUpdateException extends ECFException {
+
+ private static final long serialVersionUID = 6697002759105612786L;
+
+ private IModelChange modelChange;
+ private Object model;
+
+ public ModelUpdateException(String message, IModelChange mc, Object model) {
+ super(message);
+ this.modelChange = mc;
+ this.model = model;
+ }
+
+ public ModelUpdateException(Throwable cause, IModelChange mc, Object model) {
+ super(cause);
+ this.modelChange = mc;
+ this.model = model;
+ }
+
+ public ModelUpdateException(String message, Throwable cause, IModelChange mc, Object model) {
+ super(message, cause);
+ this.modelChange = mc;
+ this.model = model;
+ }
+
+ public ModelUpdateException(IStatus status, IModelChange mc, Object model) {
+ super(status);
+ this.modelChange = mc;
+ this.model = model;
+ }
+
+ public IModelChange getModelChange() {
+ return this.modelChange;
+ }
+
+ public Object getModel() {
+ return this.model;
+ }
+
+}
diff --git a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java
index 8f66142ca..a90643453 100644
--- a/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java
+++ b/framework/bundles/org.eclipse.ecf.sync/src/org/eclipse/ecf/sync/doc/DocumentChangeMessage.java
@@ -22,7 +22,10 @@ import java.io.Serializable;
import org.eclipse.core.runtime.IAdapterManager;
import org.eclipse.ecf.internal.sync.Activator;
import org.eclipse.ecf.sync.IModelChangeMessage;
+import org.eclipse.ecf.sync.ModelUpdateException;
import org.eclipse.ecf.sync.SerializationException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
/**
* Document change message of communicating document change
@@ -138,4 +141,18 @@ public class DocumentChangeMessage implements IDocumentChange, IModelChangeMessa
return manager.loadAdapter(this, adapter.getName());
}
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.sync.IModelChange#applyToModel(java.lang.Object)
+ */
+ public void applyToModel(Object model) throws ModelUpdateException {
+ if (model == null) throw new ModelUpdateException("Model cannot be null",this,null);
+ if (model instanceof IDocument) {
+ try {
+ ((IDocument) model).replace(getOffset(), getLengthOfReplacedText(), getText());
+ } catch (BadLocationException e) {
+ throw new ModelUpdateException("Exception applying change to document",this,model);
+ }
+ } else throw new ModelUpdateException("Incorrect type of model to apply change",this,model);
+ }
+
}

Back to the top