diff options
author | kgilmer | 2006-04-26 12:21:22 +0000 |
---|---|---|
committer | kgilmer | 2006-04-26 12:21:22 +0000 |
commit | e3ed1cecf4d90ed16c1bea69a3f4619313add491 (patch) | |
tree | 6af00173f64cd2507bbf0c8ea84808046d4f576c /examples/bundles/org.eclipse.ecf.example.collab.editor | |
parent | 596fa05c2d901d90f6a9c68b7ab9b41ca09a1c8e (diff) | |
download | org.eclipse.ecf-e3ed1cecf4d90ed16c1bea69a3f4619313add491.tar.gz org.eclipse.ecf-e3ed1cecf4d90ed16c1bea69a3f4619313add491.tar.xz org.eclipse.ecf-e3ed1cecf4d90ed16c1bea69a3f4619313add491.zip |
Java editor support.
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.example.collab.editor')
5 files changed, 61 insertions, 14 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml b/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml index a382464f9..3fc78a84b 100644 --- a/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml +++ b/examples/bundles/org.eclipse.ecf.example.collab.editor/plugin.xml @@ -5,7 +5,7 @@ <extension point="org.eclipse.ui.popupMenus"> <objectContribution - adaptable="false" + adaptable="true" id="org.eclipse.ecf.example.collab.editor.objectContribution" objectClass="org.eclipse.core.resources.IFile"> <action 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 index 8e269fe7b..a16b7b659 100644 --- 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 @@ -38,10 +38,13 @@ public class EditChannelListener implements IChannelListener { this.document = document; this.editor = editor; textControl = (StyledText) editor.getAdapter(Control.class); + + System.out.println(textControl.getAlignment()); } public void handleChannelEvent(IChannelEvent event) { if (event instanceof IChannelMessageEvent) { + System.out.println("Receiving"); setEditorEditable(false); Activator.getDefault().setListenerActive(false); 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 index b3b4cf621..3880c81bc 100644 --- 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 @@ -65,21 +65,24 @@ public class EditorListener implements IDocumentListener { } 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; } try { + System.out.println("sending"); 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) { Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, e.getLocalizedMessage(), e)); 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 index 045d9d2d5..c706d99de 100644 --- 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 @@ -9,6 +9,7 @@ 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.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.ecf.example.collab.editor.Activator; @@ -17,8 +18,10 @@ 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.StructuredSelection; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IViewActionDelegate; @@ -27,6 +30,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PartInitException; +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; @@ -66,20 +70,38 @@ public class InitiateSharedSessionAction extends Action implements IObjectAction //Create ECF container and begin sharing. if (editorPart instanceof AbstractTextEditor) { - IDocumentProvider dp = DocumentProviderRegistry.getDefault().getDocumentProvider(editorPart.getEditorInput()); + 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); - document.addDocumentListener(listener); + 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); + 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) { + // TODO Auto-generated catch block + e.printStackTrace(); } } @@ -88,8 +110,8 @@ public class InitiateSharedSessionAction extends Action implements IObjectAction } public void selectionChanged(IAction action, ISelection selection) { - if (selection instanceof TreeSelection) { - TreeSelection ts = (TreeSelection) selection; + if (selection instanceof StructuredSelection) { + StructuredSelection ts = (StructuredSelection) selection; file = (IFile) ts.getFirstElement(); } 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 index 7ab52e920..685da3dc7 100644 --- 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 @@ -24,6 +24,7 @@ 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.EditorListener; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.operation.IRunnableWithProgress; @@ -37,6 +38,7 @@ 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; @@ -124,11 +126,28 @@ public class NewSharedSessionWizard extends Wizard implements INewWizard { if (document != null) { EditorListener listener = new EditorListener(document, textEditor); 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); + 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); |