Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsuen2007-05-26 02:21:28 +0000
committerrsuen2007-05-26 02:21:28 +0000
commit4371f5cbb34f150b68161bdbaed5069f03a0a095 (patch)
treee616b31eef65d8fe471f8d6aa3c54dda199d4622 /examples/bundles/org.eclipse.ecf.example.collab.editor
parent6d2c794adf9e8c68463fa3e6bcd6e66bc57b2f97 (diff)
downloadorg.eclipse.ecf-4371f5cbb34f150b68161bdbaed5069f03a0a095.tar.gz
org.eclipse.ecf-4371f5cbb34f150b68161bdbaed5069f03a0a095.tar.xz
org.eclipse.ecf-4371f5cbb34f150b68161bdbaed5069f03a0a095.zip
Code clean-up.
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.example.collab.editor')
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab.editor/src/org/eclipse/ecf/example/collab/editor/actions/InitiateSharedSessionAction.java175
1 files changed, 101 insertions, 74 deletions
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 26d200570..e2076e215 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
@@ -10,6 +10,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.IAdaptable;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.example.collab.editor.Activator;
@@ -18,17 +19,14 @@ 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.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.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.IWorkbenchWindow;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.AbstractTextEditor;
@@ -36,95 +34,124 @@ import org.eclipse.ui.texteditor.DocumentProviderRegistry;
import org.eclipse.ui.texteditor.IDocumentProvider;
/**
- * This action is used to initiate a shared session.
+ * This action is used to initiate a shared session.
*
* @author kgilmer
- *
*/
-public class InitiateSharedSessionAction extends Action implements IObjectActionDelegate, IViewActionDelegate {
+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)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
- final IWorkbench workbench = Activator.getDefault().getWorkbench();
-
- if (workbench != null) {
- final IWorkbenchPage page = workbench.getWorkbenchWindows()[0].getActivePage();
-
- workbench.getDisplay().asyncExec(new Runnable() {
- public void run() {
- try {
- 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 = page.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;
- } 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));
- }
+ 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 (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)); }
+ 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 StructuredSelection) {
- StructuredSelection ts = (StructuredSelection) selection;
-
- file = (IFile) ts.getFirstElement();
+ 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);
+ }
}
}
- public void init(IViewPart view) {
- }
-
}

Back to the top