diff options
| author | pnehrer | 2005-02-02 03:22:18 +0000 |
|---|---|---|
| committer | pnehrer | 2005-02-02 03:22:18 +0000 |
| commit | 2b4f099bd5b692101e6818bb4a68c9963c16f9c6 (patch) | |
| tree | 9abaf71fa3310dd645d8ee7a06b8d7c90a9decdf | |
| parent | f52913c9f08ff6d0c5a21aad5f3c094905f49f62 (diff) | |
| download | org.eclipse.ecf-2b4f099bd5b692101e6818bb4a68c9963c16f9c6.tar.gz org.eclipse.ecf-2b4f099bd5b692101e6818bb4a68c9963c16f9c6.tar.xz org.eclipse.ecf-2b4f099bd5b692101e6818bb4a68c9963c16f9c6.zip | |
Refactored to work with example collab client.
4 files changed, 451 insertions, 379 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.example.sdo.editor/META-INF/MANIFEST.MF index 562cd6a2a..8d07a12cd 100644 --- a/examples/bundles/org.eclipse.ecf.example.sdo.editor/META-INF/MANIFEST.MF +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/META-INF/MANIFEST.MF @@ -12,5 +12,6 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ecf, org.eclipse.ecf.sdo, org.eclipse.emf.ecore.sdo.editor, - org.eclipse.ecf.test.provider + org.eclipse.ecf.test.provider, + org.eclipse.ecf.example.collab Eclipse-AutoStart: true diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java index d300db11e..2cfaf2781 100644 --- a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java @@ -10,27 +10,20 @@ *******************************************************************************/ package org.eclipse.ecf.example.sdo.editor; -import java.util.Hashtable; import java.util.MissingResourceException; import java.util.ResourceBundle; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Status; import org.eclipse.ecf.core.ISharedObjectContainer; -import org.eclipse.ecf.core.SharedObjectContainerFactory; -import org.eclipse.ecf.core.SharedObjectContainerInstantiationException; -import org.eclipse.ecf.core.SharedObjectContainerJoinException; -import org.eclipse.ecf.core.SharedObjectCreateException; -import org.eclipse.ecf.core.SharedObjectDescription; import org.eclipse.ecf.core.identity.IDFactory; -import org.eclipse.ecf.core.identity.IDInstantiationException; import org.eclipse.ecf.core.util.ECFException; +import org.eclipse.ecf.example.collab.Client; import org.eclipse.ecf.sdo.ISharedDataGraph; import org.eclipse.ecf.sdo.ISubscriptionCallback; import org.eclipse.ecf.sdo.IUpdateConsumer; import org.eclipse.ecf.sdo.SDOPlugin; import org.eclipse.ecf.sdo.emf.EMFUpdateProvider; -import org.eclipse.ecf.test.EventSpy; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -42,162 +35,125 @@ import commonj.sdo.DataGraph; * @author pnehrer */ public class EditorPlugin extends AbstractUIPlugin { - // The shared instance. - private static EditorPlugin plugin; - - // Resource bundle. - private ResourceBundle resourceBundle; - - private static final String CONTAINER_ID = "org.eclipse.ecf.test.TestContainer"; - - private static final String GROUP_ID = "test.sdo"; - - private final Hashtable published = new Hashtable(); - - /** - * The constructor. - */ - public EditorPlugin() { - super(); - plugin = this; - try { - resourceBundle = ResourceBundle - .getBundle("org.eclipse.ecf.example.sdo.editor.EditorPluginResources"); - } catch (MissingResourceException x) { - resourceBundle = null; - } - } - - /** - * This method is called upon plug-in activation - */ - public void start(BundleContext context) throws Exception { - super.start(context); - } - - /** - * This method is called when the plug-in is stopped - */ - public void stop(BundleContext context) throws Exception { - super.stop(context); - } - - /** - * Returns the shared instance. - */ - public static EditorPlugin getDefault() { - return plugin; - } - - /** - * Returns the string from the plugin's resource bundle, or 'key' if not - * found. - */ - public static String getResourceString(String key) { - ResourceBundle bundle = EditorPlugin.getDefault().getResourceBundle(); - try { - return (bundle != null) ? bundle.getString(key) : key; - } catch (MissingResourceException e) { - return key; - } - } - - /** - * Returns the plugin's resource bundle, - */ - public ResourceBundle getResourceBundle() { - return resourceBundle; - } - - public void log(Throwable t) { - if (t instanceof CoreException) - getLog().log(((CoreException) t).getStatus()); - else - getLog().log( - new Status(Status.ERROR, getBundle().getSymbolicName(), 0, - "An unexpected error occurred.", t)); - } - - private ISharedObjectContainer createContainer(String spyName) - throws CoreException { - ISharedObjectContainer container; - try { - container = SharedObjectContainerFactory - .makeSharedObjectContainer(CONTAINER_ID); - } catch (SharedObjectContainerInstantiationException e) { - throw new CoreException(new Status(Status.ERROR, getBundle() - .getSymbolicName(), 0, - "Could not create container with ID " + CONTAINER_ID + ".", - e)); - } - - try { - container.getSharedObjectManager().createSharedObject( - new SharedObjectDescription( - IDFactory.makeStringID(spyName), EventSpy.class), - null); - } catch (SharedObjectCreateException e) { - log(e); - } catch (IDInstantiationException e) { - log(e); - } - - try { - container.joinGroup(IDFactory.makeStringID(GROUP_ID), null); - } catch (IDInstantiationException e) { - throw new CoreException(new Status(Status.ERROR, getBundle() - .getSymbolicName(), 0, "Could not join group with ID " - + GROUP_ID + ".", e)); - } catch (SharedObjectContainerJoinException e) { - throw new CoreException(new Status(Status.ERROR, getBundle() - .getSymbolicName(), 0, "Could not join group with ID " - + GROUP_ID + ".", e)); - } - - return container; - } - - public ISharedDataGraph subscribe(String path, - ISubscriptionCallback callback, IUpdateConsumer consumer) - throws CoreException { - - ISharedObjectContainer container = createContainer("subscribe"); - try { - return SDOPlugin.getDefault().getDataGraphSharing(container) - .subscribe(IDFactory.makeStringID(path), callback, - new EMFUpdateProvider(), consumer); - } catch (ECFException e) { - throw new CoreException(new Status(Status.ERROR, getBundle() - .getSymbolicName(), 0, - "Could not subscribe to graph with id " + path + ".", e)); - } - } - - public ISharedDataGraph publish(String path, DataGraph dataGraph, - IUpdateConsumer consumer) throws CoreException { - SDOPlugin.getDefault().setDebug(true); - ISharedObjectContainer container = createContainer("publish"); - try { - ISharedDataGraph sdg = SDOPlugin.getDefault().getDataGraphSharing( - container).publish(dataGraph, IDFactory.makeStringID(path), - new EMFUpdateProvider(), consumer); - published.put(path, container); - return sdg; - } catch (ECFException e) { - throw new CoreException(new Status(Status.ERROR, getBundle() - .getSymbolicName(), 0, "Could not publish graph with id " - + path + ".", e)); - } - } - - public void dispose(String path) { - ISharedObjectContainer container = (ISharedObjectContainer) published - .get(path); - if (container != null) - container.dispose(0); - } - - public boolean isPublished(String path) { - return published.contains(path); - } + // The shared instance. + private static EditorPlugin plugin; + + // Resource bundle. + private ResourceBundle resourceBundle; + + private ISharedObjectContainer container; + + private PublishedGraphTracker tracker; + + /** + * The constructor. + */ + public EditorPlugin() { + super(); + plugin = this; + try { + resourceBundle = ResourceBundle + .getBundle("org.eclipse.ecf.example.sdo.editor.EditorPluginResources"); + } catch (MissingResourceException x) { + resourceBundle = null; + } + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + } + + /** + * Returns the shared instance. + */ + public static EditorPlugin getDefault() { + return plugin; + } + + /** + * Returns the string from the plugin's resource bundle, or 'key' if not + * found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = EditorPlugin.getDefault().getResourceBundle(); + try { + return (bundle != null) ? bundle.getString(key) : key; + } catch (MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + return resourceBundle; + } + + public void log(Throwable t) { + if (t instanceof CoreException) + getLog().log(((CoreException) t).getStatus()); + else + getLog().log( + new Status(Status.ERROR, getBundle().getSymbolicName(), 0, + "An unexpected error occurred.", t)); + } + + public synchronized ISharedDataGraph subscribe(String path, + ISubscriptionCallback callback, IUpdateConsumer consumer) + throws ECFException { + initialize(); + return SDOPlugin.getDefault().getDataGraphSharing(container).subscribe( + IDFactory.makeStringID(path), callback, + new EMFUpdateProvider(), consumer); + } + + public synchronized ISharedDataGraph publish(String path, + DataGraph dataGraph, IUpdateConsumer consumer) throws ECFException { + initialize(); + SDOPlugin.getDefault().setDebug(true); + return SDOPlugin.getDefault().getDataGraphSharing(container).publish( + dataGraph, IDFactory.makeStringID(path), + new EMFUpdateProvider(), consumer); + } + + public synchronized boolean isPublished(String path) throws ECFException { + initialize(); + return tracker.isPublished(path); + } + + public synchronized void checkConnected() throws ECFException { + initialize(); + } + + private void initialize() throws ECFException { + if (tracker == null) { + Client client; + try { + client = new Client(); + } catch (Exception e) { + throw new ECFException(e); + } + + container = client.getContainer(); + if (container == null) + throw new ECFException("Not connected."); + + PublishedGraphTracker tracker = new PublishedGraphTracker(); + container.getSharedObjectManager().addSharedObject( + IDFactory.makeStringID(PublishedGraphTracker.class + .getName()), tracker, null, null); + this.tracker = tracker; + } + } }
\ No newline at end of file diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/PublishedGraphTracker.java b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/PublishedGraphTracker.java index 94e45177d..1e823ab16 100644 --- a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/PublishedGraphTracker.java +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/PublishedGraphTracker.java @@ -11,13 +11,18 @@ package org.eclipse.ecf.example.sdo.editor; import java.io.IOException; +import java.util.Arrays; import java.util.HashSet; import java.util.Hashtable; +import java.util.Iterator; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.ecf.core.ISharedObject; import org.eclipse.ecf.core.ISharedObjectConfig; import org.eclipse.ecf.core.SharedObjectInitException; +import org.eclipse.ecf.core.events.ISharedObjectContainerDepartedEvent; +import org.eclipse.ecf.core.events.ISharedObjectContainerJoinedEvent; +import org.eclipse.ecf.core.events.ISharedObjectDeactivatedEvent; import org.eclipse.ecf.core.events.ISharedObjectMessageEvent; import org.eclipse.ecf.core.identity.ID; import org.eclipse.ecf.core.util.ECFException; @@ -28,119 +33,234 @@ import org.eclipse.ecf.core.util.Event; */ class PublishedGraphTracker extends PlatformObject implements ISharedObject { - private ISharedObjectConfig config; - - private final Hashtable paths = new Hashtable(); - - synchronized void add(String path) throws ECFException { - if (config == null) - throw new ECFException("Not connected."); - - try { - config.getContext().sendMessage( - null, - new Object[] { Boolean.TRUE, config.getSharedObjectID(), - path }); - } catch (IOException e) { - throw new ECFException(e); - } - - handleAdded(config.getContext().getLocalContainerID(), path); - } - - synchronized void remove(String path) throws ECFException { - if (config == null) - throw new ECFException("Not connected."); - - try { - config.getContext().sendMessage( - null, - new Object[] { Boolean.FALSE, config.getSharedObjectID(), - path }); - } catch (IOException e) { - throw new ECFException(e); - } - - handleRemoved(config.getContext().getLocalContainerID(), path); - } - - synchronized boolean isPublished(String path) { - synchronized (paths) { - return paths.contains(path); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig) - */ - public synchronized void init(ISharedObjectConfig initData) - throws SharedObjectInitException { - if (config == null) - config = initData; - else - throw new SharedObjectInitException("Already initialized."); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event) - */ - public void handleEvent(Event event) { - if (event instanceof ISharedObjectMessageEvent) { - Object[] data = (Object[]) ((ISharedObjectMessageEvent) event) - .getData(); - if (Boolean.TRUE.equals(data[0])) - handleAdded((ID) data[1], (String) data[2]); - else - handleRemoved((ID) data[1], (String) data[2]); - } - } - - private void handleAdded(ID containerID, String path) { - synchronized (paths) { - HashSet list = (HashSet) paths.get(path); - if (list == null) { - list = new HashSet(); - paths.put(path, list); - } - - list.add(containerID); - } - } - - private void handleRemoved(ID containerID, String path) { - synchronized (paths) { - HashSet list = (HashSet) paths.get(path); - if (list != null) { - list.remove(containerID); - if (list.isEmpty()) - paths.remove(path); - } - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.core.util.Event[]) - */ - public void handleEvents(Event[] events) { - for (int i = 0; i < events.length; ++i) - handleEvent(events[i]); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID) - */ - public synchronized void dispose(ID containerID) { - if (config != null - && config.getContext().getLocalContainerID() - .equals(containerID)) - config = null; - } + private static final String[] NO_PATHS = {}; + + private static final int JOIN = 0; + + private static final int LEAVE = 1; + + private static final int ADD = 2; + + private static final int REMOVE = 3; + + private class Table { + + private final Hashtable paths = new Hashtable(); + + private final Hashtable containers = new Hashtable(); + + public synchronized void add(ID containerID, String[] path) { + HashSet list = (HashSet) paths.get(containerID); + if (list == null) { + list = new HashSet(); + paths.put(containerID, list); + } + + list.addAll(Arrays.asList(path)); + for (int i = 0; i < path.length; ++i) { + list = (HashSet) containers.get(path[i]); + if (list == null) { + list = new HashSet(); + containers.put(path[i], list); + } + + list.add(containerID); + } + } + + public synchronized void remove(ID containerID, String path) { + HashSet list = (HashSet) paths.get(containerID); + if (list != null) { + list.remove(path); + if (list.isEmpty()) + paths.remove(containerID); + } + + list = (HashSet) containers.get(path); + if (list != null) { + list.remove(containerID); + if (list.isEmpty()) + containers.remove(path); + } + } + + public synchronized void remove(ID containerID) { + HashSet list = (HashSet) paths.get(containerID); + if (list != null) { + for (Iterator i = list.iterator(); i.hasNext();) { + String path = (String) i.next(); + list = (HashSet) containers.get(path); + if (list != null) { + list.remove(containerID); + if (list.isEmpty()) + containers.remove(path); + } + } + } + } + + public synchronized boolean contains(String path) { + return containers.contains(path); + } + + public synchronized String[] getPaths(ID containerID) { + HashSet list = (HashSet) paths.get(containerID); + return list == null ? NO_PATHS : (String[]) list + .toArray(new String[list.size()]); + } + } + + private final Table table = new Table(); + + private ISharedObjectConfig config; + + public synchronized void add(String path) throws ECFException { + if (config == null) + throw new ECFException("Not connected."); + + try { + config.getContext().sendMessage(null, + new Object[] { new Integer(ADD), path }); + } catch (IOException e) { + throw new ECFException(e); + } + + handleAdd(config.getContext().getLocalContainerID(), path); + } + + public synchronized void remove(String path) throws ECFException { + if (config == null) + throw new ECFException("Not connected."); + + try { + config.getContext().sendMessage(null, + new Object[] { new Integer(REMOVE), path }); + } catch (IOException e) { + throw new ECFException(e); + } + + handleRemove(config.getContext().getLocalContainerID(), path); + } + + public synchronized boolean isPublished(String path) { + return table.contains(path); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig) + */ + public synchronized void init(ISharedObjectConfig initData) + throws SharedObjectInitException { + if (config == null) + config = initData; + else + throw new SharedObjectInitException("Already initialized."); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObject#handleEvent(org.eclipse.ecf.core.util.Event) + */ + public void handleEvent(Event event) { + if (event instanceof ISharedObjectMessageEvent) { + ISharedObjectMessageEvent e = (ISharedObjectMessageEvent) event; + Object[] data = (Object[]) e.getData(); + Integer type = (Integer) data[0]; + switch (type.intValue()) { + case JOIN: + handleJoin(e.getRemoteContainerID(), (String[]) data[1]); + break; + + case LEAVE: + handleLeave(e.getRemoteContainerID()); + break; + + case ADD: + handleAdd(e.getRemoteContainerID(), (String) data[1]); + break; + + case REMOVE: + handleRemove(e.getRemoteContainerID(), (String) data[1]); + } + } else if (event instanceof ISharedObjectContainerJoinedEvent) { + if (((ISharedObjectContainerJoinedEvent) event) + .getJoinedContainerID().equals( + config.getContext().getLocalContainerID())) + handleJoined(); + } else if (event instanceof ISharedObjectContainerDepartedEvent) { + ISharedObjectContainerDepartedEvent e = (ISharedObjectContainerDepartedEvent) event; + if (!e.getDepartedContainerID().equals( + config.getContext().getLocalContainerID())) + handleLeave(e.getDepartedContainerID()); + } else if (event instanceof ISharedObjectDeactivatedEvent) { + if (((ISharedObjectDeactivatedEvent) event).getDeactivatedID() + .equals(config.getSharedObjectID())) + handleDeactivated(); + } + } + + private void handleJoin(ID containerID, String[] paths) { + table.add(containerID, paths); + } + + private void handleLeave(ID containerID) { + table.remove(containerID); + } + + private void handleAdd(ID containerID, String path) { + table.add(containerID, new String[] { path }); + } + + private void handleRemove(ID containerID, String path) { + table.remove(containerID, path); + } + + private void handleJoined() { + try { + config.getContext().sendMessage( + null, + new Object[] { + new Integer(JOIN), + table.getPaths(config.getContext() + .getLocalContainerID()) }); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + private void handleDeactivated() { + try { + config.getContext().sendMessage(null, + new Object[] { new Integer(LEAVE) }); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObject#handleEvents(org.eclipse.ecf.core.util.Event[]) + */ + public void handleEvents(Event[] events) { + for (int i = 0; i < events.length; ++i) + handleEvent(events[i]); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ecf.core.ISharedObject#dispose(org.eclipse.ecf.core.identity.ID) + */ + public synchronized void dispose(ID containerID) { + if (config != null + && config.getContext().getLocalContainerID() + .equals(containerID)) + config = null; + } } diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/SharedSDOEditor.java b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/SharedSDOEditor.java index 6ab2c24a3..9e224cf01 100644 --- a/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/SharedSDOEditor.java +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/SharedSDOEditor.java @@ -32,109 +32,104 @@ import commonj.sdo.DataGraph; */ public class SharedSDOEditor extends SDOEditor { - private class UpdateConsumer implements IUpdateConsumer { - public boolean consumeUpdate(ISharedDataGraph graph, ID containerID) { - ChangeSummary changeSummary = graph.getDataGraph() - .getChangeSummary(); - changeSummary.endLogging(); - SharedSDOEditor.super.doSave(null); - changeSummary.beginLogging(); - return true; - } + private class UpdateConsumer implements IUpdateConsumer { + public boolean consumeUpdate(ISharedDataGraph graph, ID containerID) { + ChangeSummary changeSummary = graph.getDataGraph() + .getChangeSummary(); + changeSummary.endLogging(); + SharedSDOEditor.super.doSave(null); + changeSummary.beginLogging(); + return true; + } - public void updateFailed(ISharedDataGraph graph, ID containerID, - Throwable cause) { - EditorPlugin.getDefault().log( - new CoreException(new Status(Status.ERROR, EditorPlugin - .getDefault().getBundle().getSymbolicName(), 0, - "Data graph upate failed.", cause))); - } - } + public void updateFailed(ISharedDataGraph graph, ID containerID, + Throwable cause) { + EditorPlugin.getDefault().log( + new CoreException(new Status(Status.ERROR, EditorPlugin + .getDefault().getBundle().getSymbolicName(), 0, + "Data graph upate failed.", cause))); + } + } - private ISharedDataGraph sharedDataGraph; + private ISharedDataGraph sharedDataGraph; - private String path; + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.ecore.sdo.presentation.SDOEditor#createModel() + */ + public void createModel() { + try { + IFileEditorInput modelFile = (IFileEditorInput) getEditorInput(); + String path = modelFile.getFile().getFullPath().toString(); + URI uri = URI.createPlatformResourceURI(modelFile.getFile() + .getFullPath().toString()); + if (EditorPlugin.getDefault().isPublished(path)) { + WaitableSubscriptionCallback mutex = new WaitableSubscriptionCallback(); + sharedDataGraph = EditorPlugin.getDefault().subscribe(path, + mutex, new UpdateConsumer()); + ID containerID = null; + Throwable cause = null; + try { + containerID = mutex.waitForSubscription(1000); + } catch (InterruptedException e) { + cause = e; + } - /* - * (non-Javadoc) - * - * @see org.eclipse.emf.ecore.sdo.presentation.SDOEditor#createModel() - */ - public void createModel() { - IFileEditorInput modelFile = (IFileEditorInput) getEditorInput(); - path = modelFile.getFile().getProjectRelativePath().toString(); - URI uri = URI.createPlatformResourceURI(modelFile.getFile() - .getFullPath().toString()); - if (EditorPlugin.getDefault().isPublished(path)) { - WaitableSubscriptionCallback mutex = new WaitableSubscriptionCallback(); - try { - sharedDataGraph = EditorPlugin.getDefault().subscribe(path, - mutex, new UpdateConsumer()); - } catch (CoreException e) { - sharedDataGraph = null; - EditorPlugin.getDefault().log(e); - return; - } + if (containerID == null) { + EditorPlugin.getDefault().log( + new CoreException(new Status(Status.ERROR, + EditorPlugin.getDefault().getBundle() + .getSymbolicName(), 0, + "Failed to subscribe.", cause))); + return; + } - ID containerID = null; - Throwable cause = null; - try { - containerID = mutex.waitForSubscription(1000); - } catch (InterruptedException e) { - cause = e; - } catch (ECFException e) { - cause = e; - } + EDataGraph dataGraph = (EDataGraph) sharedDataGraph + .getDataGraph(); + dataGraph.getDataGraphResource().setURI(uri); + editingDomain.getResourceSet().getResources().addAll( + dataGraph.getResourceSet().getResources()); + dataGraph.setResourceSet(editingDomain.getResourceSet()); + } else { + Resource resource = editingDomain.loadResource(uri.toString()); + DataGraph dataGraph = (DataGraph) resource.getContents().get(0); + sharedDataGraph = EditorPlugin.getDefault().publish(path, + dataGraph, new UpdateConsumer()); + } + } catch (ECFException e) { + EditorPlugin.getDefault().log(e); + if (sharedDataGraph != null) { + sharedDataGraph.dispose(); + sharedDataGraph = null; + } + } + } - if (containerID == null) { - EditorPlugin.getDefault().log( - new CoreException(new Status(Status.ERROR, EditorPlugin - .getDefault().getBundle().getSymbolicName(), 0, - "Failed to subscribe.", cause))); - return; - } + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.ecore.sdo.presentation.SDOEditor#doSave(org.eclipse.core.runtime.IProgressMonitor) + */ + public void doSave(IProgressMonitor progressMonitor) { + super.doSave(progressMonitor); + if (sharedDataGraph != null) + try { + sharedDataGraph.commit(); + } catch (ECFException e) { + EditorPlugin.getDefault().log(e); + } + } - EDataGraph dataGraph = (EDataGraph) sharedDataGraph.getDataGraph(); - dataGraph.getDataGraphResource().setURI(uri); - editingDomain.getResourceSet().getResources().addAll( - dataGraph.getResourceSet().getResources()); - dataGraph.setResourceSet(editingDomain.getResourceSet()); - } else { - Resource resource = editingDomain.loadResource(uri.toString()); - DataGraph dataGraph = (DataGraph) resource.getContents().get(0); - try { - sharedDataGraph = EditorPlugin.getDefault().publish(path, - dataGraph, new UpdateConsumer()); - } catch (CoreException e) { - EditorPlugin.getDefault().log(e); - } - } - } + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.ecore.sdo.presentation.SDOEditor#dispose() + */ + public void dispose() { + if (sharedDataGraph != null) + sharedDataGraph.dispose(); - /* - * (non-Javadoc) - * - * @see org.eclipse.emf.ecore.sdo.presentation.SDOEditor#doSave(org.eclipse.core.runtime.IProgressMonitor) - */ - public void doSave(IProgressMonitor progressMonitor) { - super.doSave(progressMonitor); - if (sharedDataGraph != null) - try { - sharedDataGraph.commit(); - } catch (ECFException e) { - EditorPlugin.getDefault().log(e); - } - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.emf.ecore.sdo.presentation.SDOEditor#dispose() - */ - public void dispose() { - if (path != null) - EditorPlugin.getDefault().dispose(path); - - super.dispose(); - } + super.dispose(); + } }
\ No newline at end of file |
