Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2006-06-04 19:18:01 -0400
committerslewis2006-06-04 19:18:01 -0400
commit80af39349a112f7ca590e3786f839afe01b42505 (patch)
tree746f1471cfdf16742e93022807ca8d3fa2a66e15
parent98cae026140556fb9f895066127d865479b220ea (diff)
downloadorg.eclipse.ecf-80af39349a112f7ca590e3786f839afe01b42505.tar.gz
org.eclipse.ecf-80af39349a112f7ca590e3786f839afe01b42505.tar.xz
org.eclipse.ecf-80af39349a112f7ca590e3786f839afe01b42505.zip
Added sendShowView and handler to remotely open Eclipse view using XMPP plugin
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterSharedObject.java90
-rw-r--r--examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/CollabRosterView.java201
2 files changed, 290 insertions, 1 deletions
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterSharedObject.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterSharedObject.java
index ed31dc89e..7e13dfde9 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterSharedObject.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/share/RosterSharedObject.java
@@ -9,6 +9,10 @@ import org.eclipse.ecf.core.sharedobject.SharedObjectMsg;
import org.eclipse.ecf.core.sharedobject.SharedObjectMsgEvent;
import org.eclipse.ecf.core.util.Event;
import org.eclipse.ecf.example.collab.ui.CollabRosterView;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
public class RosterSharedObject extends AbstractSharedObject {
@@ -41,4 +45,90 @@ public class RosterSharedObject extends AbstractSharedObject {
// XXX this should call the view back to display the message/do other things, etc
System.out.println("RosterSharedObject.handleMessage(" + message + ")");
}
+
+
+ /**
+ * Message sender to show a view of given ID to target user. This method sends
+ * a message which the receiver RosterSharedObject is expected to call {@link #handleShowViewWithID(String, String, Integer)}
+ * to handle the message
+ *
+ * @param targetID the ID of the target user to receive the sendShowViewWithID request. Must not be null
+ * @param viewID the String identifying the view to display
+ */
+ public void sendShowViewWithID(ID targetID, String viewID, String secID, Integer mode) {
+ try {
+ SharedObjectMsg m = SharedObjectMsg.createMsg(null,
+ "handleShowViewWithID", viewID, secID, mode);
+ sendSharedObjectMsgTo(targetID,m);
+ sendSharedObjectMsgToSelf(m);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ /**
+ * Message sender to show a view of given ID to target user. This method sends
+ * a message which the receiver RosterSharedObject is expected to call {@link #handleShowView(String)}
+ * to handle the message
+ *
+ * @param targetID the ID of the target user to receive the sendShowView request. Must not be null
+ * @param viewID the String identifying the view to display
+ */
+ public void sendShowView(ID targetID, String viewID) {
+ if (targetID == null) return;
+ try {
+ SharedObjectMsg m = SharedObjectMsg.createMsg(null, "handleShowView",viewID);
+ sendSharedObjectMsgTo(targetID,m);
+ sendSharedObjectMsgToSelf(m);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ /**
+ * Message handler for {@link #sendShowViewWithID(ID, String, String, Integer)} message sender. This message
+ * handler takes the given viewID and opens it on the local Display
+ *
+ * @param viewID the viewID to display
+ */
+ protected void handleShowViewWithID(final String viewID,
+ final String secID, final Integer mode) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ IWorkbenchWindow ww = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ IWorkbenchPage wp = ww.getActivePage();
+ if (wp == null)
+ throw new NullPointerException("showViewWithID(" + viewID + ") "
+ + "workbench page is null");
+ wp.showView(viewID, secID, mode.intValue());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ /**
+ * Message handler for {@link #sendShowView(ID, String)} message sender. This message
+ * handler takes the given viewID and opens it on the local Display
+ *
+ * @param viewID the viewID to display
+ */
+ protected void handleShowView(final String viewID) {
+ Display.getDefault().syncExec(new Runnable() {
+ public void run() {
+ try {
+ IWorkbenchWindow ww = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ IWorkbenchPage wp = ww.getActivePage();
+ if (wp == null)
+ throw new NullPointerException("showView(" + viewID + ") "
+ + "workbench page is null");
+ wp.showView(viewID);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
}
diff --git a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/CollabRosterView.java b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/CollabRosterView.java
index 1f065f87f..c3a987d27 100644
--- a/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/CollabRosterView.java
+++ b/examples/bundles/org.eclipse.ecf.example.collab/src/org/eclipse/ecf/example/collab/ui/CollabRosterView.java
@@ -1,15 +1,44 @@
package org.eclipse.ecf.example.collab.ui;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.ecf.core.ISharedObject;
import org.eclipse.ecf.core.ISharedObjectContainer;
+import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.example.collab.ClientPlugin;
import org.eclipse.ecf.example.collab.share.RosterSharedObject;
+import org.eclipse.ecf.example.collab.share.User;
import org.eclipse.ecf.ui.views.RosterView;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.jface.viewers.ViewerSorter;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
+import org.eclipse.ui.views.IViewCategory;
+import org.eclipse.ui.views.IViewDescriptor;
+import org.eclipse.ui.views.IViewRegistry;
public class CollabRosterView extends RosterView {
+ RosterSharedObject sharedObject = null;
+
/*
* (non-Javadoc)
*
@@ -34,6 +63,15 @@ public class CollabRosterView extends RosterView {
+ treeObject.getId().getName());
sendSOMessageAction.setEnabled(ua.getSharedObject() != null);
manager.add(sendSOMessageAction);
+ Action sendShowViewAction = new Action() {
+ public void run() {
+ sendShowViewRequest(treeObject.getId());
+ }
+ };
+ sendShowViewAction.setText("Open Remote Eclipse View for "
+ + treeObject.getId().getName());
+ sendShowViewAction.setEnabled(ua.getSharedObject() != null);
+ manager.add(sendShowViewAction);
}
}
@@ -47,7 +85,7 @@ public class CollabRosterView extends RosterView {
ISharedObjectContainer container = account.getSOContainer();
if (container != null) {
try {
- ISharedObject sharedObject = new RosterSharedObject(this);
+ sharedObject = new RosterSharedObject(this);
container.getSharedObjectManager().addSharedObject(
IDFactory.getDefault().createStringID(
RosterSharedObject.class.getName()),
@@ -61,4 +99,165 @@ public class CollabRosterView extends RosterView {
return null;
}
+ private void sendShowViewRequest(ID userID) {
+ IWorkbenchWindow ww = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ IWorkbenchPage page = ww.getActivePage();
+ if (page == null)
+ return;
+
+ ElementTreeSelectionDialog dlg = new ElementTreeSelectionDialog(
+ this.getViewSite().getShell(),
+ new LabelProvider() {
+ private HashMap images = new HashMap();
+ public Image getImage(Object element) {
+ ImageDescriptor desc = null;
+ if (element instanceof IViewCategory)
+ desc = PlatformUI.getWorkbench().getSharedImages()
+ .getImageDescriptor(
+ ISharedImages.IMG_OBJ_FOLDER);
+ else if (element instanceof IViewDescriptor)
+ desc = ((IViewDescriptor) element).getImageDescriptor();
+
+ if (desc == null)
+ return null;
+
+ Image image = (Image) images.get(desc);
+ if (image == null) {
+ image = desc.createImage();
+ images.put(desc, image);
+ }
+
+ return image;
+ }
+ public String getText(Object element) {
+ String label;
+ if (element instanceof IViewCategory)
+ label = ((IViewCategory) element).getLabel();
+ else if (element instanceof IViewDescriptor)
+ label = ((IViewDescriptor) element).getLabel();
+ else
+ label = super.getText(element);
+
+ for (
+ int i = label.indexOf('&');
+ i >= 0 && i < label.length() - 1;
+ i = label.indexOf('&', i + 1))
+ if (!Character.isWhitespace(label.charAt(i + 1)))
+ return label.substring(0, i) + label.substring(i + 1);
+
+ return label;
+ }
+ public void dispose() {
+ for (Iterator i = images.values().iterator(); i.hasNext();)
+ ((Image) i.next()).dispose();
+
+ images = null;
+ super.dispose();
+ }
+ },
+ new ITreeContentProvider() {
+ private HashMap parents = new HashMap();
+ public Object[] getChildren(Object element) {
+ if (element instanceof IViewRegistry)
+ return ((IViewRegistry) element).getCategories();
+ else if (element instanceof IViewCategory) {
+ IViewDescriptor[] children =
+ ((IViewCategory) element).getViews();
+ for (int i = 0; i < children.length; ++i)
+ parents.put(children[i], element);
+
+ return children;
+ } else
+ return new Object[0];
+ }
+ public Object getParent(Object element) {
+ if (element instanceof IViewCategory)
+ return PlatformUI.getWorkbench().getViewRegistry();
+ else if (element instanceof IViewDescriptor)
+ return parents.get(element);
+ else
+ return null;
+ }
+ public boolean hasChildren(Object element) {
+ if (element instanceof IViewRegistry
+ || element instanceof IViewCategory)
+ return true;
+ else
+ return false;
+ }
+ public Object[] getElements(Object inputElement) {
+ return getChildren(inputElement);
+ }
+ public void dispose() {
+ parents = null;
+ }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ parents.clear();
+ }
+ });
+ dlg.setTitle(MessageLoader
+ .getString("LineChatClientView.contextmenu.sendShowViewRequest"));
+ dlg.setMessage(MessageLoader
+ .getString("LineChatClientView.contextmenu.sendShowViewRequest.dialog.title"));
+ dlg.addFilter(new ViewerFilter() {
+ public boolean select(Viewer viewer, Object parentElement, Object element) {
+ if (element instanceof IViewDescriptor
+ && "org.eclipse.ui.internal.introview".equals(
+ ((IViewDescriptor) element).getId()))
+ return false;
+ else
+ return true;
+ }});
+ dlg.setSorter(new ViewerSorter());
+ dlg.setValidator(new ISelectionStatusValidator() {
+ public IStatus validate(Object[] selection) {
+ for (int i = 0; i < selection.length; ++i)
+ if (!(selection[i] instanceof IViewDescriptor))
+ return new Status(Status.ERROR, ClientPlugin.getDefault().getBundle().getSymbolicName(), 0, "", null);
+
+ return new Status(Status.OK, ClientPlugin.getDefault().getBundle().getSymbolicName(), 0, "", null);
+ }
+ });
+ IViewRegistry reg = PlatformUI.getWorkbench().getViewRegistry();
+ dlg.setInput(reg);
+ IDialogSettings dlgSettings = ClientPlugin.getDefault().getDialogSettings();
+ final String DIALOG_SETTINGS = "SendShowViewRequestDialog";
+ final String SELECTION_SETTING = "SELECTION";
+ IDialogSettings section = dlgSettings.getSection(DIALOG_SETTINGS);
+ if (section == null)
+ section = dlgSettings.addNewSection(DIALOG_SETTINGS);
+ else {
+ String[] selectedIDs = section.getArray(SELECTION_SETTING);
+ if (selectedIDs != null && selectedIDs.length > 0) {
+ ArrayList list = new ArrayList(selectedIDs.length);
+ for (int i = 0; i < selectedIDs.length; ++i) {
+ IViewDescriptor desc = reg.find(selectedIDs[i]);
+ if (desc != null)
+ list.add(desc);
+ }
+
+ dlg.setInitialElementSelections(list);
+ }
+ }
+
+ dlg.open();
+ if (dlg.getReturnCode() == Window.CANCEL)
+ return;
+
+ Object[] descs = dlg.getResult();
+ if (descs == null)
+ return;
+
+ String[] selectedIDs = new String[descs.length];
+ for (int i = 0; i < descs.length; ++i) {
+ selectedIDs[i] = ((IViewDescriptor)descs[i]).getId();
+ if (sharedObject != null) {
+ sharedObject.sendShowView(userID, selectedIDs[i]);
+ }
+ }
+
+ section.put(SELECTION_SETTING, selectedIDs);
+ }
+
}

Back to the top