Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkgilmer2006-04-25 02:56:47 +0000
committerkgilmer2006-04-25 02:56:47 +0000
commitfa6402876d07313ad595e54bf4b62d867fc43ab5 (patch)
tree4ba6fc4d11ad0d0efbf84370c5a471097bd6dc68
parent001a79e983136ddb655de652f850c4cee3fa8aeb (diff)
downloadorg.eclipse.ecf-fa6402876d07313ad595e54bf4b62d867fc43ab5.tar.gz
org.eclipse.ecf-fa6402876d07313ad595e54bf4b62d867fc43ab5.tar.xz
org.eclipse.ecf-fa6402876d07313ad595e54bf4b62d867fc43ab5.zip
Recheckin after accidental deletion.
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/.classpath7
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/.project28
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/META-INF/MANIFEST.MF23
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/build.properties6
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/icons/sample.gifbin0 -> 983 bytes
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml66
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/Activator.java148
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/EditChannelListener.java90
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/EditorListener.java117
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/PresenceChannelListener.java79
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/ShareEditorAction.java48
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/actions/InitiateSharedSessionAction.java85
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/EditorChangeMessage.java31
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionList.java17
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionListRequest.java9
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/preferences/ClientPreferencePage.java57
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizard.java167
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizardPage.java340
18 files changed, 1318 insertions, 0 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/.classpath b/examples/bundles/org.eclipse.ecf.example.collab.editor/.classpath
new file mode 100644
index 000000000..751c8f2e5
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.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.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/.project b/examples/bundles/org.eclipse.ecf.example.collab.editor/.project
new file mode 100644
index 000000000..8c618eb20
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.ecf.example.collab.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.collab.editor/META-INF/MANIFEST.MF b/examples/bundles/org.eclipse.ecf.example.collab.editor/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..2e313906a
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: ECF Shared Editor Plug-in
+Bundle-SymbolicName: org.eclipse.ecf.example.collab.editor; singleton:=true
+Bundle-Version: 1.0.1
+Bundle-Activator: org.eclipse.ecf.example.collab.editor.Activator
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.jface.text,
+ org.eclipse.ui.workbench.texteditor,
+ org.eclipse.ecf,
+ org.eclipse.ecf.datashare,
+ org.eclipse.ecf.presence,
+ org.eclipse.ecf.provider,
+ org.eclipse.ecf.provider.datashare,
+ org.eclipse.ecf.ui,
+ org.eclipse.core.resources,
+ org.eclipse.ui.editors,
+ org.eclipse.jdt,
+ org.eclipse.jdt.ui,
+ org.eclipse.ui.ide
+Eclipse-LazyStart: true
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/build.properties b/examples/bundles/org.eclipse.ecf.example.collab.editor/build.properties
new file mode 100644
index 000000000..0d3d3a745
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/icons/sample.gif b/examples/bundles/org.eclipse.ecf.example.collab.editor/icons/sample.gif
new file mode 100644
index 000000000..34fb3c9d8
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/icons/sample.gif
Binary files differ
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml b/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml
new file mode 100644
index 000000000..4c3d08131
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.actionSets">
+ <actionSet
+ label="Sample Action Set"
+ visible="true"
+ id="org.eclipse.ecf.example.collab.editor.actionSet">
+ <menu
+ label="Sample &amp;Menu"
+ id="sampleMenu">
+ <separator
+ name="sampleGroup">
+ </separator>
+ </menu>
+ <action
+ label="&amp;Sample Action"
+ icon="icons/sample.gif"
+ class="org.eclipse.ecf.example.collab.editor.ShareEditorAction"
+ tooltip="Hello, Eclipse world"
+ menubarPath="sampleMenu/sampleGroup"
+ toolbarPath="sampleGroup"
+ id="org.eclipse.ecf.example.collab.editor.ShareEditorAction">
+ </action>
+ </actionSet>
+ </extension>
+ <extension
+ point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ adaptable="false"
+ id="org.eclipse.ecf.example.collab.editor.objectContribution"
+ objectClass="org.eclipse.core.resources.IFile">
+ <action
+ class="org.eclipse.ecf.example.collab.editor.actions.InitiateSharedSessionAction"
+ icon="icons/sample.gif"
+ id="org.eclipse.ecf.example.collab.editor.initiateSharedEditorAction"
+ label="Initiate Shared Editor"
+ menubarPath="team.main/group3"
+ tooltip="Share this file and allow others to make changes."/>
+ </objectContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ category="org.eclipse.team.ui.TeamPreferences"
+ class="org.eclipse.ecf.example.collab.editor.preferences.ClientPreferencePage"
+ id="org.eclipse.ecf.example.collab.editor.page"
+ name="ECF Editor Sharing"/>
+ </extension>
+ <extension
+ point="org.eclipse.ui.newWizards">
+ <category
+ id="org.eclipse.ecf.example.collab.editor"
+ name="Collaboration"/>
+ <wizard
+ category="org.eclipse.ecf.example.collab.editor"
+ class="org.eclipse.ecf.example.collab.editor.wizards.NewSharedSessionWizard"
+ hasPages="true"
+ icon="icons/sample.gif"
+ id="org.eclipse.ecf.example.collab.editor.wizards.NewSessionWizard"
+ name="Shared Editor Session"/>
+ </extension>
+
+</plugin>
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/Activator.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/Activator.java
new file mode 100644
index 000000000..e5c9c009d
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/Activator.java
@@ -0,0 +1,148 @@
+package org.eclipse.ecf.example.collab.editor;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.datashare.IChannel;
+import org.eclipse.ecf.datashare.IChannelContainer;
+import org.eclipse.ecf.datashare.IChannelListener;
+import org.eclipse.ecf.example.collab.editor.message.SharedEditorSessionList;
+import org.eclipse.ecf.example.collab.editor.preferences.ClientPreferencePage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The shared instance.
+ private static Activator plugin;
+
+ private static boolean listenerActive = true;
+
+ private List sessionNames;
+
+ private IChannelListener presenceChannelListener = null;
+
+ private IChannel presenceChannel;
+
+ private IContainer presenceContainer = null;
+
+ /**
+ * The constructor.
+ */
+ public Activator() {
+ plugin = this;
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+
+ // Make sure the defaults get created.
+ ClientPreferencePage p = new ClientPreferencePage();
+ p.initializeDefaults();
+
+ sessionNames = new ArrayList();
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ plugin = null;
+ }
+
+ /**
+ * Returns the shared instance.
+ *
+ * @return the shared instance.
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in
+ * relative path.
+ *
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.ecf.example.collab.editor", path);
+ }
+
+ public boolean isListenerActive() {
+ return listenerActive;
+ }
+
+ synchronized void setListenerActive(boolean active) {
+ listenerActive = active;
+ }
+
+ /*
+ * public List getSessionNames() { return sessionNames; }
+ */
+
+ public void addSession(String sessionName) {
+ sessionNames.add(sessionName);
+
+ if (presenceChannel != null) {
+ // Tell everyone there is a new shared editor.
+ try {
+ presenceChannel.sendMessage(PresenceChannelListener.createMessage(new SharedEditorSessionList(sessionNames)));
+ } catch (ECFException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public IChannelListener getPresenceChannelListener() {
+ return presenceChannelListener;
+ }
+
+ public IChannel intializePresenceSession(IChannelListener clistener) throws ECFException {
+ presenceContainer = ContainerFactory.getDefault().createContainer(
+ Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.CONTAINER_TYPE));
+
+ IChannelContainer channelContainer = (IChannelContainer) presenceContainer.getAdapter(IChannelContainer.class);
+
+ final ID channelID = IDFactory.getDefault().createID(channelContainer.getChannelNamespace(),
+ Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.CHANNEL_ID + ".presence"));
+
+ presenceChannel = channelContainer.createChannel(channelID, clistener, new HashMap());
+
+ this.presenceChannelListener = clistener;
+
+ presenceContainer.connect(IDFactory.getDefault().createID(presenceContainer.getConnectNamespace(),
+ Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.TARGET_SERVER)), null);
+
+ return presenceChannel;
+ }
+
+ public IChannel getPresenceChannel() {
+ return presenceChannel;
+ }
+
+ public List getSessionNames() {
+ return sessionNames;
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/EditChannelListener.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/EditChannelListener.java
new file mode 100644
index 000000000..a1ec24efd
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/EditChannelListener.java
@@ -0,0 +1,90 @@
+package org.eclipse.ecf.example.collab.editor;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+
+import org.eclipse.ecf.datashare.IChannelListener;
+import org.eclipse.ecf.datashare.events.IChannelEvent;
+import org.eclipse.ecf.datashare.events.IChannelMessageEvent;
+import org.eclipse.ecf.example.collab.editor.message.EditorChangeMessage;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
+public class EditChannelListener implements IChannelListener {
+
+ private IDocument document;
+
+ private AbstractTextEditor editor;
+
+ private StyledText textControl;
+
+ public EditChannelListener(IDocument document, AbstractTextEditor editor) {
+ this.document = document;
+ this.editor = editor;
+ textControl = (StyledText) editor.getAdapter(Control.class);
+ }
+
+ public void handleChannelEvent(IChannelEvent event) {
+ if (event instanceof IChannelMessageEvent) {
+ setEditorEditable(false);
+ Activator.getDefault().setListenerActive(false);
+ System.out.println("Setting events off");
+ IChannelMessageEvent msg = (IChannelMessageEvent) event;
+
+ ByteArrayInputStream bins = new ByteArrayInputStream(msg.getData());
+ ObjectInputStream ois;
+ try {
+ ois = new ObjectInputStream(bins);
+ EditorChangeMessage message = (EditorChangeMessage) ois.readObject();
+
+ // Append text from remote to end of document
+ appendLocallyFromRemote(message);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ setEditorEditable(true);
+ Activator.getDefault().setListenerActive(true);
+ System.out.println("Setting events on");
+ }
+ }
+ }
+
+ protected void appendLocallyFromRemote(final EditorChangeMessage message) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ // Crude way of ignoring duplicate messages
+ if (message.getDocument().equals(document.get())) {
+ return;
+ }
+
+ ISelection selection = editor.getSelectionProvider().getSelection();
+ if (selection instanceof TextSelection) {
+ TextSelection textSelection = (TextSelection) selection;
+ document.set(message.getDocument());
+ editor.selectAndReveal(textSelection.getOffset(), 0);
+ }
+ }
+ });
+ }
+
+ private void setEditorEditable(final boolean editable) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ textControl.setEditable(editable);
+ }
+ });
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/EditorListener.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/EditorListener.java
new file mode 100644
index 000000000..a4423003e
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/EditorListener.java
@@ -0,0 +1,117 @@
+package org.eclipse.ecf.example.collab.editor;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.datashare.IChannel;
+import org.eclipse.ecf.datashare.IChannelContainer;
+import org.eclipse.ecf.datashare.IChannelListener;
+import org.eclipse.ecf.example.collab.editor.message.EditorChangeMessage;
+import org.eclipse.ecf.example.collab.editor.preferences.ClientPreferencePage;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
+public class EditorListener implements IDocumentListener {
+ private IDocument document;
+
+ private AbstractTextEditor editor;
+
+ private IChannel channel;
+
+ private IContainer container = null;
+
+ private IChannelListener channelListener;
+
+
+
+ private String sessionID;
+
+ public EditorListener(IDocument document, AbstractTextEditor textEditor) {
+ this.document = document;
+ this.editor = textEditor;
+
+ try {
+ intializeEditorSession();
+
+ if (Activator.getDefault().getPresenceChannelListener() == null) {
+ Activator.getDefault().intializePresenceSession(new PresenceChannelListener());
+ }
+ } catch (ECFException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public void documentAboutToBeChanged(DocumentEvent event) {
+
+ }
+
+ public void documentChanged(DocumentEvent event) {
+ if (!Activator.getDefault().isListenerActive()) {
+ return;
+ }
+
+ try {
+ IDocument newDocument = event.getDocument();
+
+ if (channel == null) {
+ // Communication error has occured. Stop listening to
+ // document.
+ document.removeDocumentListener(this);
+ }
+
+ channel.sendMessage(createMessageFromEvent(event));
+
+ this.document = newDocument;
+ } catch (ECFException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private byte[] createMessageFromEvent(DocumentEvent event) throws IOException, ECFException {
+ ByteArrayOutputStream bouts = new ByteArrayOutputStream();
+ ObjectOutputStream douts = new ObjectOutputStream(bouts);
+ douts.writeObject(new EditorChangeMessage(event.getDocument().get()));
+ return bouts.toByteArray();
+ }
+
+ public void intializeEditorSession() throws ECFException {
+ container = ContainerFactory.getDefault().createContainer(
+ Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.CONTAINER_TYPE));
+
+ IChannelContainer channelContainer = (IChannelContainer) container.getAdapter(IChannelContainer.class);
+
+ sessionID = Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.CHANNEL_ID) + "_" + editor.getTitle();
+
+ Activator.getDefault().addSession(sessionID);
+
+ final ID channelID = IDFactory.getDefault().createID(channelContainer.getChannelNamespace(), sessionID);
+
+ channelListener = new EditChannelListener(document, editor);
+
+ channel = channelContainer.createChannel(channelID, channelListener, new HashMap());
+
+ container.connect(IDFactory.getDefault().createID(container.getConnectNamespace(),
+ Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.TARGET_SERVER)), null);
+ }
+
+
+
+ public String getSessionID() {
+ return sessionID;
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/PresenceChannelListener.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/PresenceChannelListener.java
new file mode 100644
index 000000000..85ac7e471
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/PresenceChannelListener.java
@@ -0,0 +1,79 @@
+package org.eclipse.ecf.example.collab.editor;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.datashare.IChannel;
+import org.eclipse.ecf.datashare.IChannelListener;
+import org.eclipse.ecf.datashare.events.IChannelEvent;
+import org.eclipse.ecf.datashare.events.IChannelMessageEvent;
+import org.eclipse.ecf.example.collab.editor.message.EditorChangeMessage;
+import org.eclipse.ecf.example.collab.editor.message.SharedEditorSessionList;
+import org.eclipse.ecf.example.collab.editor.message.SharedEditorSessionListRequest;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+
+public class PresenceChannelListener implements IChannelListener {
+
+ private IChannel channel;
+
+ public PresenceChannelListener() {
+ }
+
+ public void handleChannelEvent(IChannelEvent event) {
+ if (channel == null) {
+ channel = Activator.getDefault().getPresenceChannel();
+ }
+
+ if (event instanceof IChannelMessageEvent) {
+
+ IChannelMessageEvent msg = (IChannelMessageEvent) event;
+
+ ByteArrayInputStream bins = new ByteArrayInputStream(msg.getData());
+ ObjectInputStream ois;
+ try {
+ ois = new ObjectInputStream(bins);
+ Object o = ois.readObject();
+
+ if (o instanceof SharedEditorSessionListRequest) {
+ channel.sendMessage(createMessage(new SharedEditorSessionList(Activator.getDefault().getSessionNames())));
+ }
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ECFException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ Activator.getDefault().setListenerActive(true);
+ System.out.println("Setting events on");
+ }
+ }
+ }
+
+ public static byte[] createMessage(Object obj) throws IOException, ECFException {
+ ByteArrayOutputStream bouts = new ByteArrayOutputStream();
+
+ ObjectOutputStream douts = new ObjectOutputStream(bouts);
+ douts.writeObject(obj);
+
+ return bouts.toByteArray();
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/ShareEditorAction.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/ShareEditorAction.java
new file mode 100644
index 000000000..5463e0ed8
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/ShareEditorAction.java
@@ -0,0 +1,48 @@
+package org.eclipse.ecf.example.collab.editor;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.ui.texteditor.DocumentProviderRegistry;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+
+public class ShareEditorAction implements IWorkbenchWindowActionDelegate {
+
+ public ShareEditorAction() {
+ }
+
+ public void run(IAction action) {
+ IWorkbenchPage page = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage();
+
+ IEditorPart editorPart = page.getActiveEditor();
+
+ if (editorPart instanceof AbstractTextEditor) {
+ IDocumentProvider dp = DocumentProviderRegistry.getDefault()
+ .getDocumentProvider(editorPart.getEditorInput());
+ AbstractTextEditor textEditor = (AbstractTextEditor) editorPart;
+
+ IDocument document = dp.getDocument(editorPart.getEditorInput());
+
+ if (document != null) {
+ EditorListener listener = new EditorListener(document, textEditor);
+ document.addDocumentListener(listener);
+ }
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ }
+
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ }
+} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/actions/InitiateSharedSessionAction.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/actions/InitiateSharedSessionAction.java
new file mode 100644
index 000000000..745caa1e2
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/actions/InitiateSharedSessionAction.java
@@ -0,0 +1,85 @@
+package org.eclipse.ecf.example.collab.editor.actions;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ecf.example.collab.editor.Activator;
+import org.eclipse.ecf.example.collab.editor.EditorListener;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IViewActionDelegate;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.ui.texteditor.DocumentProviderRegistry;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+
+public class InitiateSharedSessionAction extends Action implements IObjectActionDelegate, IViewActionDelegate {
+
+ private IFile file;
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+ */
+ public void run(IAction action) {
+ IWorkbench workbench = Activator.getDefault().getWorkbench();
+ final IEditorDescriptor editorDescriptor = workbench.getEditorRegistry().getDefaultEditor(file.getName());
+
+ if (workbench != null) {
+ final IWorkbenchPage page = workbench.getWorkbenchWindows()[0].getActivePage();
+
+ workbench.getDisplay().asyncExec(new Runnable() {
+ IEditorPart part;
+
+ public void run() {
+ try {
+ //Open the default editor for the selected file.
+ IEditorPart editorPart = page.openEditor(new FileEditorInput(file), editorDescriptor.getId());
+
+ //Create ECF infrastructre and begin sharing.
+ if (editorPart instanceof AbstractTextEditor) {
+ IDocumentProvider dp = DocumentProviderRegistry.getDefault().getDocumentProvider(editorPart.getEditorInput());
+ AbstractTextEditor textEditor = (AbstractTextEditor) editorPart;
+
+ IDocument document = dp.getDocument(editorPart.getEditorInput());
+
+ if (document != null) {
+ EditorListener listener = new EditorListener(document, textEditor);
+ document.addDocumentListener(listener);
+ }
+ }
+
+ } catch (PartInitException e) {
+ e.printStackTrace();
+ }
+ }
+
+ });
+ }
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (selection instanceof TreeSelection) {
+ TreeSelection ts = (TreeSelection) selection;
+
+ file = (IFile) ts.getFirstElement();
+ }
+ }
+
+ public void init(IViewPart view) {
+ System.out.println("init: " + view.getTitle());
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/EditorChangeMessage.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/EditorChangeMessage.java
new file mode 100644
index 000000000..b788d9ace
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/EditorChangeMessage.java
@@ -0,0 +1,31 @@
+package org.eclipse.ecf.example.collab.editor.message;
+
+import java.io.Serializable;
+
+public class EditorChangeMessage implements Serializable {
+ private static final long serialVersionUID = -8142516068285829708L;
+ private String document;
+
+ public EditorChangeMessage() {
+
+ }
+
+ public EditorChangeMessage(String document) {
+ this.document = document;
+ }
+
+ public String toString() {
+
+ return "Text Length: " + document.length();
+ }
+
+ public String getDocument() {
+ return document;
+ }
+
+ public void setDocument(String document) {
+ this.document = document;
+ }
+
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionList.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionList.java
new file mode 100644
index 000000000..a9b88cd3f
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionList.java
@@ -0,0 +1,17 @@
+package org.eclipse.ecf.example.collab.editor.message;
+
+import java.io.Serializable;
+import java.util.List;
+
+public class SharedEditorSessionList implements Serializable {
+ private static final long serialVersionUID = 4337027955521207775L;
+ private List sessionNames;
+
+ public SharedEditorSessionList(List names) {
+ sessionNames = names;
+ }
+
+ public List getNames() {
+ return sessionNames;
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionListRequest.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionListRequest.java
new file mode 100644
index 000000000..e0b41d786
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionListRequest.java
@@ -0,0 +1,9 @@
+package org.eclipse.ecf.example.collab.editor.message;
+
+import java.io.Serializable;
+
+public class SharedEditorSessionListRequest implements Serializable {
+ private static final long serialVersionUID = 2096909220585200273L;
+
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/preferences/ClientPreferencePage.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/preferences/ClientPreferencePage.java
new file mode 100644
index 000000000..0f85251c9
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/preferences/ClientPreferencePage.java
@@ -0,0 +1,57 @@
+/****************************************************************************
+ * Copyright (c) 2004 Composent, Inc. and others.
+ * 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:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.example.collab.editor.preferences;
+
+import org.eclipse.ecf.example.collab.editor.Activator;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.jface.preference.StringFieldEditor;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class ClientPreferencePage extends FieldEditorPreferencePage implements
+ IWorkbenchPreferencePage {
+
+
+ public static final String CONTAINER_TYPE = "CONTAINER_TYPE";
+ public static final String TARGET_SERVER = "TARGET_SERVER";
+ public static final String CHANNEL_ID = "CHANNEL_ID";
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
+ */
+ protected void performDefaults() {
+ super.performDefaults();
+
+ getPreferenceStore().setDefault(CONTAINER_TYPE, "ecf.generic.channel");
+ getPreferenceStore().setDefault(TARGET_SERVER, "ecftcp://localhost:3282/server");
+ getPreferenceStore().setDefault(CHANNEL_ID, "collab.editor");
+ }
+
+ public ClientPreferencePage() {
+ super(GRID);
+ setPreferenceStore(Activator.getDefault().getPreferenceStore());
+ }
+
+ public void createFieldEditors() {
+ addField(new StringFieldEditor(CONTAINER_TYPE, "Container Type:", this.getFieldEditorParent()));
+ addField(new StringFieldEditor(TARGET_SERVER, "ECF Server URL:", this.getFieldEditorParent()));
+ addField(new StringFieldEditor(CHANNEL_ID, "Channel (Group) Name:", this.getFieldEditorParent()));
+ }
+
+ public void init(IWorkbench workbench) {
+
+ }
+
+ public void initializeDefaults() {
+ performDefaults();
+ }
+} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizard.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizard.java
new file mode 100644
index 000000000..53a580158
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizard.java
@@ -0,0 +1,167 @@
+package org.eclipse.ecf.example.collab.editor.wizards;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.INewWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.core.runtime.*;
+import org.eclipse.jface.operation.*;
+import java.lang.reflect.InvocationTargetException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.ecf.example.collab.editor.EditorListener;
+
+import java.io.*;
+import org.eclipse.ui.*;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
+import org.eclipse.ui.texteditor.DocumentProviderRegistry;
+import org.eclipse.ui.texteditor.IDocumentProvider;
+
+/**
+ * This is a sample new wizard. Its role is to create a new file resource in the
+ * provided container. If the container resource (a folder or a project) is
+ * selected in the workspace when the wizard is opened, it will accept it as the
+ * target container. The wizard creates one file with the extension "mpe". If a
+ * sample multi-page editor (also available as a template) is registered for the
+ * same extension, it will be able to open it.
+ */
+
+public class NewSharedSessionWizard extends Wizard implements INewWizard {
+ private NewSharedSessionWizardPage page;
+
+ private ISelection selection;
+
+ /**
+ * Constructor for SampleNewWizard.
+ */
+ public NewSharedSessionWizard() {
+ super();
+ setNeedsProgressMonitor(true);
+ }
+
+ /**
+ * Adding the page to the wizard.
+ */
+
+ public void addPages() {
+ page = new NewSharedSessionWizardPage(selection);
+ addPage(page);
+ }
+
+ /**
+ * This method is called when 'Finish' button is pressed in the wizard. We
+ * will create an operation and run it using wizard as execution context.
+ */
+ public boolean performFinish() {
+ final String containerName = page.getContainerName();
+ final String fileName = page.getFileName();
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ try {
+ doFinish(containerName, fileName, monitor);
+ } catch (CoreException e) {
+ throw new InvocationTargetException(e);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+ try {
+ getContainer().run(true, false, op);
+ } catch (InterruptedException e) {
+ return false;
+ } catch (InvocationTargetException e) {
+ Throwable realException = e.getTargetException();
+ MessageDialog.openError(getShell(), "Error", realException.getMessage());
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * The worker method. It will find the container, create the file if missing
+ * or just replace its contents, and open the editor on the newly created
+ * file.
+ */
+
+ private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException {
+ // create a sample file
+ monitor.beginTask("Creating " + fileName, 2);
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ IResource resource = root.findMember(new Path(containerName));
+ if (!resource.exists() || !(resource instanceof IContainer)) {
+ throwCoreException("Container \"" + containerName + "\" does not exist.");
+ }
+ IContainer container = (IContainer) resource;
+ final IFile file = container.getFile(new Path(fileName));
+ try {
+ InputStream stream = openContentStream();
+ if (file.exists()) {
+ file.setContents(stream, true, true, monitor);
+ } else {
+ file.create(stream, true, monitor);
+ }
+
+ stream.close();
+ } catch (IOException e) {
+ }
+ monitor.worked(1);
+ monitor.setTaskName("Opening file for editing...");
+ getShell().getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ try {
+
+// Open the default editor for the selected file.
+ IEditorPart editorPart = IDE.openEditor(page, file, true);
+
+ //Create ECF infrastructre and begin sharing.
+ if (editorPart instanceof AbstractTextEditor) {
+ IDocumentProvider dp = DocumentProviderRegistry.getDefault().getDocumentProvider(editorPart.getEditorInput());
+ AbstractTextEditor textEditor = (AbstractTextEditor) editorPart;
+
+ IDocument document = dp.getDocument(editorPart.getEditorInput());
+
+ if (document != null) {
+ EditorListener listener = new EditorListener(document, textEditor);
+ document.addDocumentListener(listener);
+ }
+ }
+
+ } catch (PartInitException e) {
+ }
+ }
+ });
+ monitor.worked(1);
+ }
+
+ /**
+ * We will initialize file contents with a sample text.
+ */
+
+ private InputStream openContentStream() {
+ String contents = "";
+ return new ByteArrayInputStream(contents.getBytes());
+ }
+
+ private void throwCoreException(String message) throws CoreException {
+ IStatus status = new Status(IStatus.ERROR, "org.eclipse.ecf.example.collab.editor", IStatus.OK, message, null);
+ throw new CoreException(status);
+ }
+
+ /**
+ * We will accept the selection in the workbench to see if we can initialize
+ * from it.
+ *
+ * @see IWorkbenchWizard#init(IWorkbench, IStructuredSelection)
+ */
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ this.selection = selection;
+ }
+} \ No newline at end of file
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizardPage.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizardPage.java
new file mode 100644
index 000000000..858ccf1f1
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizardPage.java
@@ -0,0 +1,340 @@
+package org.eclipse.ecf.example.collab.editor.wizards;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.datashare.IChannel;
+import org.eclipse.ecf.datashare.IChannelListener;
+import org.eclipse.ecf.datashare.events.IChannelEvent;
+import org.eclipse.ecf.datashare.events.IChannelMessageEvent;
+import org.eclipse.ecf.example.collab.editor.Activator;
+import org.eclipse.ecf.example.collab.editor.EditorListener;
+import org.eclipse.ecf.example.collab.editor.message.SharedEditorSessionList;
+import org.eclipse.ecf.example.collab.editor.message.SharedEditorSessionListRequest;
+import org.eclipse.jface.viewers.IBaseLabelProvider;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ContainerSelectionDialog;
+
+/**
+ * The "New" wizard page allows setting the container for the new file as well
+ * as the file name. The page will only accept file name without the extension
+ * OR with the extension that matches the expected one (mpe).
+ */
+
+public class NewSharedSessionWizardPage extends WizardPage {
+ private Text containerText;
+
+ // private Text fileText;
+
+ private ISelection selection;
+
+ private TableViewer sessionViewer;
+
+ private List sessions;
+
+ /**
+ * Constructor for SampleNewWizardPage.
+ *
+ * @param pageName
+ */
+ public NewSharedSessionWizardPage(ISelection selection) {
+ super("wizardPage");
+ setTitle("Shared Editor");
+ setDescription("Connect to a live shared editor session.");
+ this.selection = selection;
+ sessions = new ArrayList();
+ }
+
+ /**
+ * @see IDialogPage#createControl(Composite)
+ */
+ public void createControl(Composite parent) {
+ Composite main = new Composite(parent, SWT.NONE);
+ main.setLayout(new GridLayout(2, false));
+ main.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ /*
+ * Composite container = new Composite(main, SWT.NULL); GridLayout
+ * layout = new GridLayout(); container.setLayout(layout);
+ * layout.numColumns = 3; layout.verticalSpacing = 9;
+ */
+ Label label = new Label(main, SWT.NULL);
+ label.setText("&Project:");
+
+ Composite c = new Composite(main, SWT.None);
+ c.setLayout(new GridLayout(2, false));
+ c.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ containerText = new Text(c, SWT.BORDER | SWT.SINGLE);
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ containerText.setLayoutData(gd);
+ containerText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ dialogChanged();
+ }
+ });
+
+ Button button = new Button(c, SWT.PUSH);
+ button.setText("Browse...");
+ button.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ handleBrowse();
+ }
+ });
+
+ Label label2 = new Label(main, SWT.NULL);
+ label2.setText("&Shared File:");
+ label2.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
+
+ sessionViewer = new TableViewer(main, SWT.BORDER);
+ sessionViewer.setContentProvider(new ListContentProvider());
+ sessionViewer.setLabelProvider(new SessionNameLabelProvider());
+ sessionViewer.setInput(sessions);
+ sessionViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
+ sessionViewer.addSelectionChangedListener(new ISelectionChangedListener() {
+ public void selectionChanged(SelectionChangedEvent event) {
+ dialogChanged();
+ }
+
+ });
+
+ initialize();
+ dialogChanged();
+ setControl(main);
+ }
+
+ private class ListContentProvider implements IStructuredContentProvider {
+
+ public Object[] getElements(Object inputElement) {
+
+ return ((List) inputElement).toArray();
+ }
+
+ public void dispose() {
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+ }
+
+ private class SessionNameLabelProvider implements ITableLabelProvider {
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ String s = (String) element;
+
+ // Assumption that '_' is delimeter character seperating shared
+ // group name from file name.
+ return s.split("_")[1];
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+ /**
+ * Tests if the current workbench selection is a suitable container to use.
+ */
+
+ private void initialize() {
+ if (selection != null && selection.isEmpty() == false && selection instanceof IStructuredSelection) {
+ IStructuredSelection ssel = (IStructuredSelection) selection;
+ if (ssel.size() > 1)
+ return;
+ Object obj = ssel.getFirstElement();
+ if (obj instanceof IResource) {
+ IContainer container;
+ if (obj instanceof IContainer)
+ container = (IContainer) obj;
+ else
+ container = ((IResource) obj).getParent();
+
+ containerText.setText(container.getFullPath().toString());
+ }
+ }
+
+ try {
+ IChannel channel = Activator.getDefault().intializePresenceSession(new SessionResponseListener());
+ channel.sendMessage(createMessage(new SharedEditorSessionListRequest()));
+ } catch (ECFException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private class SessionResponseListener implements IChannelListener {
+
+ public void handleChannelEvent(IChannelEvent event) {
+ if (event instanceof IChannelMessageEvent) {
+
+ IChannelMessageEvent msg = (IChannelMessageEvent) event;
+
+ ByteArrayInputStream bins = new ByteArrayInputStream(msg.getData());
+ ObjectInputStream ois;
+ try {
+ ois = new ObjectInputStream(bins);
+ Object o = ois.readObject();
+
+ if (o instanceof SharedEditorSessionList) {
+ SharedEditorSessionList l = (SharedEditorSessionList) o;
+
+ sessions.addAll(l.getNames());
+ PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
+
+ public void run() {
+ if (!sessionViewer.getTable().isDisposed()) {
+ sessionViewer.refresh();
+ }
+ }
+
+ });
+
+ }
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private byte[] createMessage(Object obj) throws IOException, ECFException {
+ ByteArrayOutputStream bouts = new ByteArrayOutputStream();
+
+ ObjectOutputStream douts = new ObjectOutputStream(bouts);
+ douts.writeObject(obj);
+
+ return bouts.toByteArray();
+ }
+
+ /**
+ * Uses the standard container selection dialog to choose the new value for
+ * the container field.
+ */
+
+ private void handleBrowse() {
+ ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
+ "Select new file container");
+ if (dialog.open() == ContainerSelectionDialog.OK) {
+ Object[] result = dialog.getResult();
+ if (result.length == 1) {
+ containerText.setText(((Path) result[0]).toString());
+ }
+ }
+ }
+
+ /**
+ * Ensures that both text fields are set.
+ */
+
+ private void dialogChanged() {
+ IResource container = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(getContainerName()));
+ String fileName = getFileName();
+
+ if (getContainerName().length() == 0) {
+ updateStatus("File container must be specified");
+ return;
+ }
+ if (container == null || (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
+ updateStatus("File container must exist");
+ return;
+ }
+ if (!container.isAccessible()) {
+ updateStatus("Project must be writable");
+ return;
+ }
+ if (fileName == null || fileName.length() == 0) {
+ updateStatus("File name must be specified");
+ return;
+ }
+ if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
+ updateStatus("File name must be valid");
+ return;
+ }
+
+ updateStatus(null);
+ }
+
+ private void updateStatus(String message) {
+ setErrorMessage(message);
+ setPageComplete(message == null);
+ }
+
+ public String getContainerName() {
+ return containerText.getText();
+ }
+
+ public String getFileName() {
+ if (!sessionViewer.getSelection().isEmpty()) {
+ StructuredSelection s = (StructuredSelection) sessionViewer.getSelection();
+
+ return ((String) s.getFirstElement()).split("_")[1];
+ }
+
+ return null;
+ }
+
+} \ No newline at end of file

Back to the top