diff options
author | slewis | 2008-04-27 18:51:00 +0000 |
---|---|---|
committer | slewis | 2008-04-27 18:51:00 +0000 |
commit | def8d9cc8e9540997038425c671cc53f2dc217bc (patch) | |
tree | 01b630059848864c38d5d97b6901a207fbfc9d2f | |
parent | 5bf614d41643d99b0a8eb943c576234d9e3fe690 (diff) | |
download | org.eclipse.ecf-def8d9cc8e9540997038425c671cc53f2dc217bc.tar.gz org.eclipse.ecf-def8d9cc8e9540997038425c671cc53f2dc217bc.tar.xz org.eclipse.ecf-def8d9cc8e9540997038425c671cc53f2dc217bc.zip |
Removed code, extension markup, and icons for this plugin, effectively deprecating this example code.
17 files changed, 2 insertions, 1488 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/build.properties b/examples/bundles/org.eclipse.ecf.example.collab.editor/build.properties index 1faca081f..eece9dc62 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/build.properties +++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/build.properties @@ -2,13 +2,11 @@ bin.includes = .,\ META-INF/,\ icons/,\ about.html,\ - plugin.properties,\ - plugin.xml + plugin.properties src.includes = about.html,\ META-INF/,\ icons/,\ - plugin.properties,\ - plugin.xml + plugin.properties source.. = src/ output.. = bin/ diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/icons/shared_editor.gif b/examples/bundles/org.eclipse.ecf.example.collab.editor/icons/shared_editor.gif Binary files differdeleted file mode 100644 index 9226c4963..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/icons/shared_editor.gif +++ /dev/null diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml b/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml deleted file mode 100644 index eb81ed6bd..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<?eclipse version="3.1"?> -<plugin> -<!-- - <extension - point="org.eclipse.ui.popupMenus"> - <objectContribution - adaptable="true" - 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/shared_editor.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.keywords"> - <keyword - id="org.eclipse.ecf.example.collab.editor.keywords" - label="collab editor share sharing ecf"> - </keyword> - </extension> - <extension - point="org.eclipse.ui.newWizards"> - <wizard - category="org.eclipse.team.ui.newWizards" - class="org.eclipse.ecf.example.collab.editor.wizards.NewSharedSessionWizard" - hasPages="true" - icon="icons/shared_editor.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 index 4a1d8ce7e..5038010c7 100644 --- 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 @@ -9,26 +9,7 @@ package org.eclipse.ecf.example.collab.editor; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Calendar; -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.IChannelContainerAdapter; -import org.eclipse.ecf.datashare.IChannelListener; -import org.eclipse.ecf.example.collab.editor.message.SharedEditorSessionList; -import org.eclipse.ecf.example.collab.editor.model.SessionInstance; -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. @@ -38,16 +19,6 @@ 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; - public static final String PLUGIN_ID = "org.eclipse.ecf.example.collab.editor"; //$NON-NLS-1$ /** @@ -58,31 +29,6 @@ public class Activator extends AbstractUIPlugin { } /** - * This method is called upon plug-in activation - * @param context - * @throws Exception - */ - public void start(BundleContext context) throws Exception { - super.start(context); - - // Make sure the defaults get created. - final ClientPreferencePage p = new ClientPreferencePage(); - p.initializeDefaults(); - - sessionNames = new ArrayList(); - } - - /** - * This method is called when the plug-in is stopped - * @param context - * @throws Exception - */ - public void stop(BundleContext context) throws Exception { - super.stop(context); - plugin = null; - } - - /** * Returns the shared instance. * * @return the shared instance. @@ -91,73 +37,4 @@ public class Activator extends AbstractUIPlugin { 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(PLUGIN_ID, path); - } - - public boolean isListenerActive() { - return listenerActive; - } - - synchronized public void setListenerActive(boolean active) { - listenerActive = active; - } - - /* - * public List getSessionNames() { return sessionNames; } - */ - - public void addSession(String channelID, String sessionName) { - - sessionNames.add(new SessionInstance(channelID, sessionName, getPreferenceStore().getString(ClientPreferencePage.LOCAL_NAME), Calendar.getInstance().getTime())); - - if (presenceChannel != null) { - // Tell everyone there is a new shared editor. - try { - presenceChannel.sendMessage((new SharedEditorSessionList(sessionNames)).toByteArray()); - } catch (final ECFException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (final 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)); - - final IChannelContainerAdapter channelContainer = (IChannelContainerAdapter) presenceContainer.getAdapter(IChannelContainerAdapter.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/actions/InitiateSharedSessionAction.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/actions/InitiateSharedSessionAction.java deleted file mode 100644 index e2076e215..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/actions/InitiateSharedSessionAction.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer. 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ -package org.eclipse.ecf.example.collab.editor.actions; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.ecf.example.collab.editor.Activator; -import org.eclipse.ecf.example.collab.editor.listeners.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.IStructuredSelection; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.editors.text.TextFileDocumentProvider; -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 action is used to initiate a shared session. - * - * @author kgilmer - */ -public class InitiateSharedSessionAction extends Action implements - IObjectActionDelegate { - - private IWorkbenchPart targetPart; - private IFile file; - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - this.targetPart = targetPart; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) - */ - public void run(IAction action) { - targetPart.getSite().getShell().getDisplay().asyncExec(new Runnable() { - public void run() { - try { - IWorkbenchWindow window = targetPart.getSite() - .getWorkbenchWindow(); - IWorkbench workbench = window.getWorkbench(); - IEditorDescriptor editorDescriptor = workbench - .getEditorRegistry().getDefaultEditor( - file.getName()); - - // There is no direct file type association. Use the - // default. - if (editorDescriptor == null) { - editorDescriptor = workbench.getEditorRegistry() - .findEditor("org.eclipse.ui.DefaultTextEditor"); - } - - if (editorDescriptor == null) { - // Give up, can't get an editor. - Activator - .getDefault() - .getLog() - .log( - new Status( - IStatus.ERROR, - Activator.PLUGIN_ID, - 0, - "Failed to get editor for file. Aborting shared editing session.", - null)); - return; - } - - // Open the default editor for the selected file. - IEditorPart editorPart = window.getActivePage() - .openEditor(new FileEditorInput(file), - editorDescriptor.getId()); - - // Create ECF container and begin sharing. - if (editorPart instanceof AbstractTextEditor) { - IEditorInput editorInput = editorPart.getEditorInput(); - IDocumentProvider dp = DocumentProviderRegistry - .getDefault().getDocumentProvider(editorInput); - AbstractTextEditor textEditor = (AbstractTextEditor) editorPart; - - IDocument document = dp.getDocument(editorPart - .getEditorInput()); - - if (document != null) { - EditorListener listener = new EditorListener( - document, textEditor, true); - document.addDocumentListener(listener); - } else { - if (dp instanceof TextFileDocumentProvider) { - ((TextFileDocumentProvider) dp) - .connect(editorPart.getEditorInput()); - document = ((TextFileDocumentProvider) dp) - .getDocument(editorPart - .getEditorInput()); - - if (document != null) { - EditorListener listener = new EditorListener( - document, textEditor, true); - document.addDocumentListener(listener); - return; - } - } - - Activator - .getDefault() - .getLog() - .log( - new Status( - IStatus.ERROR, - Activator.PLUGIN_ID, - 0, - "Unable to get reference to editor's document. Shared session not created.", - null)); - } - } - } catch (CoreException e) { - Activator.getDefault().getLog().log( - new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e - .getLocalizedMessage(), e)); - } - } - }); - } - - public void selectionChanged(IAction action, ISelection selection) { - if (selection instanceof IStructuredSelection) { - IStructuredSelection iss = (IStructuredSelection) selection; - Object obj = iss.getFirstElement(); - if (obj instanceof IFile) { - file = (IFile) obj; - } else if (obj instanceof IAdaptable) { - file = (IFile) ((IAdaptable) obj).getAdapter(IFile.class); - } - } - } - -} diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/listeners/EditChannelListener.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/listeners/EditChannelListener.java deleted file mode 100644 index 09a0746f0..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/listeners/EditChannelListener.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ -package org.eclipse.ecf.example.collab.editor.listeners; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -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.message.EditorChangeMessage; -import org.eclipse.ecf.example.collab.editor.message.EditorUpdateRequest; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.TextSelection; -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.ui.texteditor.AbstractTextEditor; - -public class EditChannelListener implements IChannelListener { - - private IDocument document; - - private AbstractTextEditor editor; - - private StyledText textControl; - - private boolean documentOwner; - - private EditorListener editorListener; - - public EditChannelListener(IDocument document, AbstractTextEditor editor, boolean owner, EditorListener editorListener) { - this.document = document; - this.editor = editor; - this.editorListener = editorListener; - textControl = (StyledText) editor.getAdapter(Control.class); - documentOwner = owner; - - - } - - public void handleChannelEvent(IChannelEvent event) { - if (event instanceof IChannelMessageEvent) { - setEditorEditable(false); - Activator.getDefault().setListenerActive(false); - - IChannelMessageEvent msg = (IChannelMessageEvent) event; - - ByteArrayInputStream bins = new ByteArrayInputStream(msg.getData()); - ObjectInputStream ois; - try { - ois = new ObjectInputStream(bins); - - Object message = ois.readObject(); - - if (message instanceof EditorChangeMessage) { - // Append text from remote to end of document - appendLocallyFromRemote((EditorChangeMessage) message); - } else if (message instanceof EditorUpdateRequest && documentOwner) { - //Respond since I'm the document owner; - editorListener.sendDocumentUpdateMessage(); - } - } catch (IOException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } catch (ClassNotFoundException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } finally { - setEditorEditable(true); - Activator.getDefault().setListenerActive(true); - } - } - } - - 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) { - if (!textControl.isDisposed()) { - 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/listeners/EditorListener.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/listeners/EditorListener.java deleted file mode 100644 index 613f5f94d..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/listeners/EditorListener.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ -package org.eclipse.ecf.example.collab.editor.listeners; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.util.HashMap; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -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.IChannelContainerAdapter; -import org.eclipse.ecf.datashare.IChannelListener; -import org.eclipse.ecf.example.collab.editor.Activator; -import org.eclipse.ecf.example.collab.editor.message.EditorChangeMessage; -import org.eclipse.ecf.example.collab.editor.message.EditorUpdateRequest; -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.texteditor.AbstractTextEditor; - -public class EditorListener implements IDocumentListener { - public static final String SESSION_NAME_DELIMITER = "_"; - - private IDocument document; - - private AbstractTextEditor editor; - - private IChannel channel; - - private IContainer container = null; - - private IChannelListener channelListener; - - private String sessionID; - - private boolean documentOwner; - - public EditorListener(IDocument document, AbstractTextEditor textEditor, boolean owner) { - this.document = document; - this.editor = textEditor; - this.documentOwner = owner; - - try { - intializeEditorSession(); - - if (Activator.getDefault().getPresenceChannelListener() == null) { - Activator.getDefault().intializePresenceSession(new PresenceChannelListener()); - } - } catch (ECFException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } catch (IOException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); } - } - - public void documentAboutToBeChanged(DocumentEvent event) { - - } - - public void documentChanged(DocumentEvent event) { - if (channel == null) { - // Communication error has occured. Stop listening to - // document. - document.removeDocumentListener(this); - return; - } - - if (!Activator.getDefault().isListenerActive()) { - //The local editor is being updated by an remote peer, so we do not - //wish to echo this change. - return; - } - - sendDocumentUpdateMessage(); - } - - public void sendDocumentUpdateMessage() { - try { - - channel.sendMessage(createMessageFromEvent(document)); - - } catch (ECFException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } catch (IOException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } - } - - private byte[] createMessageFromEvent(IDocument document) throws IOException, ECFException { - ByteArrayOutputStream bouts = new ByteArrayOutputStream(); - ObjectOutputStream douts = new ObjectOutputStream(bouts); - douts.writeObject(new EditorChangeMessage(document.get())); - return bouts.toByteArray(); - } - - public void intializeEditorSession() throws ECFException, IOException { - container = ContainerFactory.getDefault().createContainer( - Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.CONTAINER_TYPE)); - - IChannelContainerAdapter channelContainer = (IChannelContainerAdapter) container.getAdapter(IChannelContainerAdapter.class); - - sessionID = Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.CHANNEL_ID) + SESSION_NAME_DELIMITER + editor.getTitle(); - - Activator.getDefault().addSession(sessionID, editor.getTitle()); - - final ID channelID = IDFactory.getDefault().createID(channelContainer.getChannelNamespace(), sessionID); - - channelListener = new EditChannelListener(document, editor, documentOwner, this); - - channel = channelContainer.createChannel(channelID, channelListener, new HashMap()); - - container.connect(IDFactory.getDefault().createID(container.getConnectNamespace(), - Activator.getDefault().getPreferenceStore().getString(ClientPreferencePage.TARGET_SERVER)), null); - - //If we don't own the document, request a fresh copy from the owner. - if (!documentOwner) { - sendEditorUpdateRequest(); - } - } - - - - private void sendEditorUpdateRequest() throws ECFException, IOException { - if (channel != null) { - channel.sendMessage((new EditorUpdateRequest()).toByteArray()); - } - } - - public String getSessionID() { - return sessionID; - } -} diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/listeners/PresenceChannelListener.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/listeners/PresenceChannelListener.java deleted file mode 100644 index 394e4ef41..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/listeners/PresenceChannelListener.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ -package org.eclipse.ecf.example.collab.editor.listeners; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -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.message.SharedEditorSessionList; -import org.eclipse.ecf.example.collab.editor.message.SharedEditorSessionListRequest; - -/** - * This ECF listener waits for requests for information (such as any editor sessions - * that the local client may have open). - * - * @author kg11212 - * - */ -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((new SharedEditorSessionList(Activator.getDefault().getSessionNames())).toByteArray()); - } - - } catch (IOException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } catch (ClassNotFoundException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } catch (ECFException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } finally { - Activator.getDefault().setListenerActive(true); - } - } - } -} diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/AbstractMessage.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/AbstractMessage.java deleted file mode 100644 index 6498ce491..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/AbstractMessage.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer. 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ - -package org.eclipse.ecf.example.collab.editor.message; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.Serializable; - -import org.eclipse.ecf.core.util.ECFException; - -public abstract class AbstractMessage implements Serializable { - - private static final long serialVersionUID = 6948157547330289296L; - - public byte[] toByteArray() throws IOException, ECFException { - final ByteArrayOutputStream bouts = new ByteArrayOutputStream(); - final ObjectOutputStream douts = new ObjectOutputStream(bouts); - douts.writeObject(this); - return bouts.toByteArray(); - } -} 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 deleted file mode 100644 index 1546853b1..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/EditorChangeMessage.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ - -package org.eclipse.ecf.example.collab.editor.message; - -import java.io.Serializable; - -/** - * This message is passed when a document is changed. Currently the ENTIRE document - * is passed upon each successive modification, from the modifiers to all other peers - * in the shared container. - * - * TODO: provide a more efficient way of passing IDocument model changes. - * - * @author kgilmer - * - */ -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/EditorUpdateRequest.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/EditorUpdateRequest.java deleted file mode 100644 index 755a17b93..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/EditorUpdateRequest.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer. 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ - -package org.eclipse.ecf.example.collab.editor.message; - -/** - * A message sent from a joining peer, needing the current editor model. - * This message should be caught by the creator, and respond with a EditorChangeMessage. - * @author kg11212 - * - */ -public class EditorUpdateRequest extends AbstractMessage { - private static final long serialVersionUID = 7307387852689460016L; - -} 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 deleted file mode 100644 index a6e422b24..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionList.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer. 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ - -package org.eclipse.ecf.example.collab.editor.message; - -import java.util.List; - -/** - * This message is passed as a response to a <code>SharedEditorSessionListRequest</code> message. - * The message is passed from peers that have open editor sessions to all others in the shared container. - * - * @author kgilmer - * - */ -public class SharedEditorSessionList extends AbstractMessage { - 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 deleted file mode 100644 index c62f969b2..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/message/SharedEditorSessionListRequest.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer. 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ - -package org.eclipse.ecf.example.collab.editor.message; - - -/** - * This message is passed when a peer wishes to "discover" all available - * shared editing sessions in it's shared container group (as defined by the - * ChannelID). An asynchronous <code>SharedEditorSessionList</code> message - * is expected in return. - * - * @author kgilmer - * - */ -public class SharedEditorSessionListRequest extends AbstractMessage { - private static final long serialVersionUID = 2096909220585200273L; - - -} diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/model/SessionInstance.java b/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/model/SessionInstance.java deleted file mode 100644 index 73effa680..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/model/SessionInstance.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer. 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ -package org.eclipse.ecf.example.collab.editor.model; - -import java.io.Serializable; -import java.util.Date; - -/** - * This model class represents a shared editor session. - * - * @author kg11212 - * - */ -public class SessionInstance implements Serializable { - private static final long serialVersionUID = 4224951859333859979L; - - private String name; - private String owner; - private Date created; - private String channelID; - - public SessionInstance() { - - } - - public SessionInstance(String channelID, String name, String owner, Date created) { - this.channelID = channelID; - this.name = name; - this.owner = owner; - this.created = created; - } - - public boolean equals(Object obj) { - if (obj instanceof SessionInstance) { - SessionInstance si = (SessionInstance) obj; - - if (name.equals(si.getName()) && channelID.equals(si.getChannelID()) && owner.equals(si.getOwner())) { - return true; - } - - return false; - } - return super.equals(obj); - } - - public Date getCreated() { - return created; - } - public void setCreated(Date created) { - this.created = created; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public String getOwner() { - return owner; - } - public void setOwner(String owner) { - this.owner = owner; - } - - public String getChannelID() { - return channelID; - } - - public void setChannelID(String channelID) { - this.channelID = channelID; - } - -} 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 deleted file mode 100644 index 21d035845..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/preferences/ClientPreferencePage.java +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * 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 java.net.Inet4Address; -import java.net.UnknownHostException; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -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"; - public static final String LOCAL_NAME = "LOCAL_NAME"; - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#performDefaults() - */ - protected void performDefaults() { - super.performDefaults(); - - getPreferenceStore().setDefault(CONTAINER_TYPE, "ecf.generic.client"); - getPreferenceStore().setDefault(TARGET_SERVER, "ecftcp://localhost:3282/server"); - getPreferenceStore().setDefault(CHANNEL_ID, "collab.editor"); - try { - getPreferenceStore().setDefault(LOCAL_NAME, Inet4Address.getLocalHost().getHostName()); - } catch (UnknownHostException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } - } - - 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, "ChatRoomTab (Group) Name:", this.getFieldEditorParent())); - addField(new StringFieldEditor(LOCAL_NAME, "Your 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 deleted file mode 100644 index 63a8dcc31..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizard.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer. 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ - -package org.eclipse.ecf.example.collab.editor.wizards; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.ecf.example.collab.editor.Activator; -import org.eclipse.ecf.example.collab.editor.listeners.EditorListener; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.viewers.ISelection; -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.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.editors.text.TextFileDocumentProvider; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.texteditor.AbstractTextEditor; -import org.eclipse.ui.texteditor.DocumentProviderRegistry; -import org.eclipse.ui.texteditor.IDocumentProvider; - -public class NewSharedSessionWizard extends Wizard implements INewWizard { - private NewSharedSessionWizardPage page; - - private ISelection selection; - - public NewSharedSessionWizard() { - super(); - setNeedsProgressMonitor(true); - } - - public void addPages() { - page = new NewSharedSessionWizardPage(selection); - addPage(page); - } - - 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; - } - - 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, false); - document.addDocumentListener(listener); - } else { - if (dp instanceof TextFileDocumentProvider) { - ((TextFileDocumentProvider) dp).connect(editorPart.getEditorInput()); - document = ((TextFileDocumentProvider) dp).getDocument(editorPart.getEditorInput()); - - if (document != null) { - EditorListener listener = new EditorListener(document, textEditor, false); - document.addDocumentListener(listener); - - return; - } else { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Unable to get reference to editor's document. Shared session not created.", null)); - } - } - - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Unable to get reference to editor's document. Shared session not created.", null)); - } - } - - } catch (PartInitException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } catch (CoreException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); } - } - }); - monitor.worked(1); - } - - 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); - } - 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 deleted file mode 100644 index 36adbe93c..000000000 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/wizards/NewSharedSessionWizardPage.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Ken Gilmer. 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: Ken Gilmer - initial API and implementation - ******************************************************************************/ - -package org.eclipse.ecf.example.collab.editor.wizards; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.TimeZone; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -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.message.SharedEditorSessionList; -import org.eclipse.ecf.example.collab.editor.message.SharedEditorSessionListRequest; -import org.eclipse.ecf.example.collab.editor.model.SessionInstance; -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.events.SelectionListener; -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.TableColumn; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.ContainerSelectionDialog; - -public class NewSharedSessionWizardPage extends WizardPage { - private Text containerText; - - // private Text fileText; - - private ISelection selection; - - private TableViewer sessionViewer; - - private List sessions; - - public NewSharedSessionWizardPage(ISelection selection) { - super("wizardPage"); - setTitle("Shared Editor"); - setDescription("Connect to a live shared editor session."); - this.selection = selection; - sessions = new ArrayList(); - } - - public void createControl(Composite parent) { - Composite main = new Composite(parent, SWT.NONE); - main.setLayout(new GridLayout(3, false)); - main.setLayoutData(new GridData(GridData.FILL_BOTH)); - - 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(main, 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(main, SWT.PUSH); - button.setText("Browse..."); - button.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - 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 | SWT.FULL_SELECTION); - sessionViewer.setContentProvider(new ListContentProvider()); - sessionViewer.setLabelProvider(new SessionNameLabelProvider()); - sessionViewer.setInput(sessions); - GridData gData = new GridData(GridData.FILL_HORIZONTAL); - gData.heightHint = 120; - sessionViewer.getTable().setLayoutData(gData); - sessionViewer.getTable().setHeaderVisible(true); - sessionViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - dialogChanged(); - } - - }); - - TableColumn tc = new TableColumn(sessionViewer.getTable(), SWT.NONE); - tc.setText("Filename"); - tc.setWidth(140); - - tc = new TableColumn(sessionViewer.getTable(), SWT.NONE); - tc.setText("Owner"); - tc.setWidth(120); - - tc = new TableColumn(sessionViewer.getTable(), SWT.NONE); - tc.setText("Shared On"); - tc.setWidth(140); - - Button refreshButton = new Button(main, SWT.None); - refreshButton.setText("Refresh"); - refreshButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); - refreshButton.addSelectionListener(new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - } - - public void widgetSelected(SelectionEvent e) { - sendSessionListRequestMessage(); - } - - }); - 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 text; - SessionInstance instance = (SessionInstance) element; - - switch (columnIndex) { - case 0: - text = instance.getName(); - break; - case 1: - text = instance.getOwner(); - break; - case 2: - DateFormat df = DateFormat.getInstance(); - df.setTimeZone(TimeZone.getTimeZone("GMT")); - text = df.format(instance.getCreated()); - break; - default: - text = ""; - } - - return text; - } - - 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 - - } - - } - - 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()); - } - } - - sendSessionListRequestMessage(); - } - - private void sendSessionListRequestMessage() { - try { - IChannel channel = Activator.getDefault().intializePresenceSession(new SessionResponseListener()); - channel.sendMessage((new SharedEditorSessionListRequest()).toByteArray()); - } catch (ECFException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } catch (IOException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } - } - - 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; - - for (Iterator i = l.getNames().iterator(); i.hasNext();) { - Object element = i.next(); - - if (!sessions.contains(element)) { - sessions.add(element); - } - } - //sessions.addAll(l.getNames()); - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - - public void run() { - if (!sessionViewer.getTable().isDisposed()) { - sessionViewer.refresh(); - } - } - - }); - - } - - } catch (IOException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } catch (ClassNotFoundException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); - } - } - } - } - - 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()); - } - } - } - - 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(); - - SessionInstance si = (SessionInstance) s.getFirstElement(); - - return si.getName(); - } - - return null; - } - -}
\ No newline at end of file |