diff options
author | pnehrer | 2005-01-31 14:48:56 +0000 |
---|---|---|
committer | pnehrer | 2005-01-31 14:48:56 +0000 |
commit | 8c996b06a1ebf617c38c60755e406dcb149e0ae6 (patch) | |
tree | 7a101655676559e4a3cf274cd02afd6f1c9c0a62 | |
parent | 58a750f4fee11ee4d9b019acfc475a088de5d3c9 (diff) | |
download | org.eclipse.ecf-8c996b06a1ebf617c38c60755e406dcb149e0ae6.tar.gz org.eclipse.ecf-8c996b06a1ebf617c38c60755e406dcb149e0ae6.tar.xz org.eclipse.ecf-8c996b06a1ebf617c38c60755e406dcb149e0ae6.zip |
Initial check-in.
10 files changed, 410 insertions, 0 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/.classpath b/examples/bundles/org.eclipse.ecf.example.sdo.editor/.classpath new file mode 100644 index 000000000..065ac06e1 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/.project b/examples/bundles/org.eclipse.ecf.example.sdo.editor/.project new file mode 100644 index 000000000..357e886d3 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.ecf.example.sdo.editor</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> 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 new file mode 100644 index 000000000..dc9ab3365 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-Name: Shareable SDO Editor Plug-in +Bundle-SymbolicName: org.eclipse.ecf.example.sdo.editor +Bundle-Version: 1.0.0 +Bundle-ClassPath: editor.jar +Bundle-Activator: org.eclipse.ecf.example.sdo.editor.EditorPlugin +Bundle-Vendor: Eclipse.org +Bundle-Localization: plugin +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.resources, + org.eclipse.ecf, + org.eclipse.ecf.sdo, + org.eclipse.emf.ecore.sdo.editor, + org.eclipse.ecf.test.provider +Eclipse-AutoStart: true diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/build.properties b/examples/bundles/org.eclipse.ecf.example.sdo.editor/build.properties new file mode 100644 index 000000000..5d7f3f2f0 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/build.properties @@ -0,0 +1,5 @@ +source.editor.jar = src/ +output.editor.jar = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + editor.jar diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/ctool16/NewSDO.gif b/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/ctool16/NewSDO.gif Binary files differnew file mode 100644 index 000000000..1d4d007be --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/ctool16/NewSDO.gif diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/obj16/SDOModelFile.gif b/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/obj16/SDOModelFile.gif Binary files differnew file mode 100644 index 000000000..31fb2b5fd --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/obj16/SDOModelFile.gif diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/wizban/NewSDO.gif b/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/wizban/NewSDO.gif Binary files differnew file mode 100644 index 000000000..fa6ebe99f --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/icons/full/wizban/NewSDO.gif diff --git a/examples/bundles/org.eclipse.ecf.example.sdo.editor/plugin.xml b/examples/bundles/org.eclipse.ecf.example.sdo.editor/plugin.xml new file mode 100644 index 000000000..01c1b067d --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/plugin.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.0"?> +<plugin> + <extension + point="org.eclipse.ui.editors"> + <editor + class="org.eclipse.ecf.example.sdo.editor.SharedSDOEditor" + icon="icons/full/obj16/SDOModelFile.gif" + default="false" + name="Shared Data Graph Editor" + contributorClass="org.eclipse.emf.ecore.sdo.presentation.SDOActionBarContributor" + id="org.eclipse.ecf.example.sdo.editor.SharedSDOEditor" + extensions="datagraph"/> + </extension> + +</plugin> 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 new file mode 100644 index 000000000..319e76b91 --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/EditorPlugin.java @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2004 Peter Nehrer and Composent, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Nehrer - initial API and implementation + *******************************************************************************/ +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.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; + +import commonj.sdo.DataGraph; + +/** + * The main plugin class to be used in the desktop. + * + * @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 (IDInstantiationException 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 (IDInstantiationException 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); + } +}
\ 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 new file mode 100644 index 000000000..d1c65badd --- /dev/null +++ b/examples/bundles/org.eclipse.ecf.example.sdo.editor/src/org/eclipse/ecf/example/sdo/editor/SharedSDOEditor.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2004 Peter Nehrer and Composent, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Peter Nehrer - initial API and implementation + *******************************************************************************/ +package org.eclipse.ecf.example.sdo.editor; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Status; +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.core.util.ECFException; +import org.eclipse.ecf.sdo.ISharedDataGraph; +import org.eclipse.ecf.sdo.IUpdateConsumer; +import org.eclipse.ecf.sdo.SubscriptionBlocker; +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.IFileEditorInput; + +import commonj.sdo.ChangeSummary; +import commonj.sdo.DataGraph; + +/** + * @author pnehrer + */ +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; + } + + public void updateFailed(ISharedDataGraph graph, ID containerID) { + EditorPlugin.getDefault().log( + new CoreException(new Status(Status.ERROR, EditorPlugin + .getDefault().getBundle().getSymbolicName(), 0, + "Data graph upate failed.", null))); + } + } + + private ISharedDataGraph sharedDataGraph; + + private String path; + + /* + * (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)) { + SubscriptionBlocker mutex = new SubscriptionBlocker(); + try { + sharedDataGraph = EditorPlugin.getDefault().subscribe(path, + mutex, new UpdateConsumer()); + } catch (CoreException e) { + sharedDataGraph = null; + EditorPlugin.getDefault().log(e); + return; + } + + boolean subscribed; + try { + subscribed = mutex.waitForSubscription(1000); + } catch (InterruptedException e) { + subscribed = false; + } + + if (!subscribed) { + EditorPlugin.getDefault().log( + new CoreException(new Status(Status.ERROR, EditorPlugin + .getDefault().getBundle().getSymbolicName(), 0, + "Failed to subscribe.", null))); + return; + } + + 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#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(); + } +}
\ No newline at end of file |