diff options
| author | pnehrer | 2005-02-17 05:39:32 +0000 |
|---|---|---|
| committer | pnehrer | 2005-02-17 05:39:32 +0000 |
| commit | 5705091d5ef4d81df0dfa52b2ea34f17e334c2ea (patch) | |
| tree | 816ba0b72b2617f4d395ae9d833fb4d084f85062 | |
| parent | bdfb85e43f0cbfe091cb72cbf5cd6c63e121b91b (diff) | |
| download | org.eclipse.ecf-5705091d5ef4d81df0dfa52b2ea34f17e334c2ea.tar.gz org.eclipse.ecf-5705091d5ef4d81df0dfa52b2ea34f17e334c2ea.tar.xz org.eclipse.ecf-5705091d5ef4d81df0dfa52b2ea34f17e334c2ea.zip | |
Refactored to work with containers on per-project basis.
2 files changed, 269 insertions, 228 deletions
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 c76374055..9a2be299d 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 @@ -13,7 +13,10 @@ package org.eclipse.ecf.example.sdo.editor; import java.util.MissingResourceException; import java.util.ResourceBundle; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.ecf.core.ISharedObjectContainer; import org.eclipse.ecf.core.identity.ID; @@ -37,156 +40,169 @@ import commonj.sdo.DataGraph; * @author pnehrer */ public class EditorPlugin extends AbstractUIPlugin { - // 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, - IUpdateConsumer consumer) throws ECFException { - initialize(); - SDOPlugin.getDefault().setDebug(true); - ID id = IDFactory.makeStringID(path); - WaitableSubscriptionCallback mutex = new WaitableSubscriptionCallback(); - ISharedDataGraph result = SDOPlugin.getDefault().getDataGraphSharing( - container).subscribe(id, new EMFUpdateProvider(), consumer, - mutex); - ID containerID = null; - try { - containerID = mutex.waitForSubscription(5000); - } catch (InterruptedException e) { - throw new ECFException(e); - } - - if (containerID == null) - throw new ECFException("Subscription timed out."); - - tracker.add(id); - return result; - } - - public synchronized ISharedDataGraph publish(String path, - DataGraph dataGraph, IUpdateConsumer consumer) throws ECFException { - initialize(); - SDOPlugin.getDefault().setDebug(true); - ID id = IDFactory.makeStringID(path); - WaitablePublicationCallback mutex = new WaitablePublicationCallback(); - ISharedDataGraph result = SDOPlugin.getDefault().getDataGraphSharing( - container).publish(dataGraph, id, new EMFUpdateProvider(), - consumer, mutex); - try { - if (!mutex.waitForPublication(5000)) - throw new ECFException("Publication timed out."); - } catch (InterruptedException e) { - throw new ECFException(e); - } - - tracker.add(id); - return result; - } - - public synchronized boolean isPublished(String path) throws ECFException { - initialize(); - return tracker.isPublished(IDFactory.makeStringID(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."); - - ID id = IDFactory.makeStringID(PublishedGraphTracker.class - .getName()); - PublishedGraphTracker tracker = (PublishedGraphTracker) container - .getSharedObjectManager().getSharedObject(id); - if (tracker == null) { - tracker = new PublishedGraphTracker(); - container.getSharedObjectManager().addSharedObject(id, tracker, - null, null); - } - - this.tracker = tracker; - } - } + // The shared instance. + private static EditorPlugin plugin; + + // Resource bundle. + private ResourceBundle resourceBundle; + + private Client client; + + /** + * 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, + IUpdateConsumer consumer) throws ECFException { + Path p = new Path(path); + ISharedObjectContainer container = getContainer(ResourcesPlugin + .getWorkspace().getRoot().getProject(p.segment(0))); + PublishedGraphTracker tracker = getTracker(container); + + SDOPlugin.getDefault().setDebug(true); + ID id = IDFactory.makeStringID(path); + WaitableSubscriptionCallback mutex = new WaitableSubscriptionCallback(); + ISharedDataGraph result = SDOPlugin.getDefault().getDataGraphSharing( + container).subscribe(id, new EMFUpdateProvider(), consumer, + mutex); + ID containerID = null; + try { + containerID = mutex.waitForSubscription(5000); + } catch (InterruptedException e) { + throw new ECFException(e); + } + + if (containerID == null) + throw new ECFException("Subscription timed out."); + + tracker.add(id); + return result; + } + + public synchronized ISharedDataGraph publish(String path, + DataGraph dataGraph, IUpdateConsumer consumer) throws ECFException { + Path p = new Path(path); + ISharedObjectContainer container = getContainer(ResourcesPlugin + .getWorkspace().getRoot().getProject(p.segment(0))); + PublishedGraphTracker tracker = getTracker(container); + + SDOPlugin.getDefault().setDebug(true); + ID id = IDFactory.makeStringID(path); + WaitablePublicationCallback mutex = new WaitablePublicationCallback(); + ISharedDataGraph result = SDOPlugin.getDefault().getDataGraphSharing( + container).publish(dataGraph, id, new EMFUpdateProvider(), + consumer, mutex); + try { + if (!mutex.waitForPublication(5000)) + throw new ECFException("Publication timed out."); + } catch (InterruptedException e) { + throw new ECFException(e); + } + + tracker.add(id); + return result; + } + + public synchronized boolean isPublished(String path) throws ECFException { + Path p = new Path(path); + ISharedObjectContainer container = getContainer(ResourcesPlugin + .getWorkspace().getRoot().getProject(p.segment(0))); + PublishedGraphTracker tracker = getTracker(container); + return tracker.isPublished(IDFactory.makeStringID(path)); + } + + public synchronized void checkConnected(IProject project) + throws ECFException { + if (getContainer(project) == null) + throw new ECFException("Project " + project.getName() + + " is not connected."); + } + + private ISharedObjectContainer getContainer(IProject project) + throws ECFException { + if (client == null) { + try { + client = new Client(); + } catch (Exception e) { + throw new ECFException(e); + } + } + + // TODO Change to getContainer(project) when API available. + return client.getContainer(); + } + + private PublishedGraphTracker getTracker(ISharedObjectContainer container) + throws ECFException { + ID id = IDFactory.makeStringID(PublishedGraphTracker.class.getName()); + PublishedGraphTracker tracker = (PublishedGraphTracker) container + .getSharedObjectManager().getSharedObject(id); + if (tracker == null) { + tracker = new PublishedGraphTracker(); + container.getSharedObjectManager().addSharedObject(id, tracker, + null, null); + } + + return 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/SharedSDOEditor.java b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/SharedSDOEditor.java index 67e1e1804..060213b01 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 @@ -21,7 +21,10 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.sdo.EDataGraph; import org.eclipse.emf.ecore.sdo.presentation.SDOEditor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.PartInitException; import commonj.sdo.ChangeSummary; import commonj.sdo.DataGraph; @@ -31,86 +34,108 @@ 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; - /* - * (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)) { - sharedDataGraph = EditorPlugin.getDefault().subscribe(path, - new UpdateConsumer()); - 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; - } - } - } + /* + * (non-Javadoc) + * + * @see org.eclipse.emf.ecore.sdo.presentation.SDOEditor#init(org.eclipse.ui.IEditorSite, + * org.eclipse.ui.IEditorInput) + */ + public void init(IEditorSite site, IEditorInput editorInput) + throws PartInitException { + if (editorInput instanceof IFileEditorInput) + try { + EditorPlugin.getDefault() + .checkConnected( + ((IFileEditorInput) editorInput).getFile() + .getProject()); + } catch (ECFException e) { + throw new PartInitException( + "Error while connecting to the group.", e); + } - /* - * (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); - } - } + super.init(site, editorInput); + } - /* - * (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#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)) { + sharedDataGraph = EditorPlugin.getDefault().subscribe(path, + new UpdateConsumer()); + 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; + } + } + } - super.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 (sharedDataGraph != null) + sharedDataGraph.dispose(); + + super.dispose(); + } }
\ No newline at end of file |
