Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-07-24 20:52:17 +0000
committerslewis2007-07-24 20:52:17 +0000
commitd4bd4b7b0e5ff676b9019e61756b088e0e05fa01 (patch)
tree828c44fb9951984169b5d698494bd30a10860c94 /examples/bundles/org.eclipse.ecf.examples.webinar
parentde610107980f0260b76f4fd3fa1eb1cc0c24328d (diff)
downloadorg.eclipse.ecf-d4bd4b7b0e5ff676b9019e61756b088e0e05fa01.tar.gz
org.eclipse.ecf-d4bd4b7b0e5ff676b9019e61756b088e0e05fa01.tar.xz
org.eclipse.ecf-d4bd4b7b0e5ff676b9019e61756b088e0e05fa01.zip
Refactored and added code for example.
Diffstat (limited to 'examples/bundles/org.eclipse.ecf.examples.webinar')
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/.project2
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/plugin.xml29
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/Activator.java26
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/dnd/RosterViewerDropTarget1.java (renamed from examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterViewerDropTarget1.java)2
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/RosterWriter.java79
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/roster/RosterContributionItem1.java33
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterentry/RosterEntryContributionItem1.java (renamed from examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterEntryContributionItem1.java)12
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterentry/RosterEntryContributionItem2.java (renamed from examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterEntryContributionItem2.java)70
-rw-r--r--examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterview/RosterViewContributionItem1.java44
9 files changed, 245 insertions, 52 deletions
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/.project b/examples/bundles/org.eclipse.ecf.examples.webinar/.project
index 38f52137e..7d980e850 100644
--- a/examples/bundles/org.eclipse.ecf.examples.webinar/.project
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/.project
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>org.eclipse.ecf.internal.examples.webinar</name>
+ <name>org.eclipse.ecf.internal.examples.webinar.util</name>
<comment></comment>
<projects>
</projects>
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/plugin.xml b/examples/bundles/org.eclipse.ecf.examples.webinar/plugin.xml
index add8b12bf..a69921d18 100644
--- a/examples/bundles/org.eclipse.ecf.examples.webinar/plugin.xml
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/plugin.xml
@@ -6,7 +6,7 @@
<menuContribution
locationURI="popup:org.eclipse.ecf.presence.ui.MultiRosterView?before=additions">
<dynamic
- class="org.eclipse.ecf.internal.examples.webinar.RosterEntryContributionItem1"
+ class="org.eclipse.ecf.internal.examples.webinar.util.rosterentry.RosterEntryContributionItem1"
id="org.eclipse.ecf.examples.webinar.dynamic1">
</dynamic>
</menuContribution>
@@ -17,15 +17,38 @@
<menuContribution
locationURI="popup:org.eclipse.ecf.presence.ui.MultiRosterView?before=additions">
<dynamic
- class="org.eclipse.ecf.internal.examples.webinar.RosterEntryContributionItem2"
+ class="org.eclipse.ecf.internal.examples.webinar.util.rosterentry.RosterEntryContributionItem2"
id="org.eclipse.ecf.examples.webinar.dynamic2">
</dynamic>
</menuContribution>
</extension>
+
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="popup:org.eclipse.ecf.presence.ui.MultiRosterView?before=additions">
+ <dynamic
+ class="org.eclipse.ecf.internal.examples.webinar.util.roster.RosterContributionItem1"
+ id="org.eclipse.ecf.examples.webinar.dynamic3">
+ </dynamic>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="menu:org.eclipse.ecf.presence.ui.MultiRosterView?after=additions">
+ <dynamic
+ class="org.eclipse.ecf.internal.examples.webinar.util.rosterview.RosterViewContributionItem1"
+ id="org.eclipse.ecf.examples.webinar.dynamic4">
+ </dynamic>
+ </menuContribution>
+ </extension>
+
<extension
point="org.eclipse.ecf.presence.ui.rosterViewerDropTarget">
<dropTarget
- class="org.eclipse.ecf.internal.examples.webinar.RosterViewerDropTarget1">
+ class="org.eclipse.ecf.internal.examples.webinar.dnd.RosterViewerDropTarget1">
</dropTarget>
</extension>
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/Activator.java b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/Activator.java
index 64df2b6bf..0404eb469 100644
--- a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/Activator.java
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/Activator.java
@@ -1,7 +1,10 @@
package org.eclipse.ecf.internal.examples.webinar;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.IContainerManager;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
/**
* The activator class controls the plug-in life cycle
@@ -9,11 +12,13 @@ import org.osgi.framework.BundleContext;
public class Activator extends AbstractUIPlugin {
// The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.ecf.internal.examples.webinar";
+ public static final String PLUGIN_ID = "org.eclipse.ecf.internal.examples.webinar.util";
// The shared instance
private static Activator plugin;
-
+
+ private BundleContext context;
+
/**
* The constructor
*/
@@ -22,29 +27,44 @@ public class Activator extends AbstractUIPlugin {
/*
* (non-Javadoc)
+ *
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
+ this.context = context;
plugin = this;
}
/*
* (non-Javadoc)
+ *
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
+ this.context = null;
}
/**
* Returns the shared instance
- *
+ *
* @return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
+ /**
+ *
+ */
+ public IContainer[] getContainers() {
+ ServiceTracker tracker = new ServiceTracker(context,
+ IContainerManager.class.getName(), null);
+ tracker.open();
+ return (IContainer[]) ((IContainerManager) tracker.getService())
+ .getAllContainers();
+ }
+
}
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterViewerDropTarget1.java b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/dnd/RosterViewerDropTarget1.java
index 4631cb592..259c6177a 100644
--- a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterViewerDropTarget1.java
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/dnd/RosterViewerDropTarget1.java
@@ -1,4 +1,4 @@
-package org.eclipse.ecf.internal.examples.webinar;
+package org.eclipse.ecf.internal.examples.webinar.dnd;
import org.eclipse.ecf.presence.roster.IRosterEntry;
import org.eclipse.ecf.presence.roster.IRosterItem;
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/RosterWriter.java b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/RosterWriter.java
new file mode 100644
index 000000000..a5c22c352
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/RosterWriter.java
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * 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.internal.examples.webinar.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.internal.examples.webinar.Activator;
+import org.eclipse.ecf.presence.IPresenceContainerAdapter;
+import org.eclipse.ecf.presence.roster.IRoster;
+import org.eclipse.ecf.presence.roster.IRosterEntry;
+import org.eclipse.ecf.presence.roster.IRosterGroup;
+import org.eclipse.ecf.presence.roster.IRosterItem;
+
+/**
+ *
+ */
+public class RosterWriter {
+
+ private IContainer[] getContainers() {
+ return Activator.getDefault().getContainers();
+ }
+
+ private Object [] getConnectedContainerAdapters(Class adapterType) {
+ IContainer [] containers = getContainers();
+ List l = new ArrayList();
+ for(int i=0; i < containers.length; i++) {
+ // Make sure connected
+ if (containers[i].getConnectedID() != null) {
+ Object o = containers[i].getAdapter(adapterType);
+ if (o != null) l.add(o);
+ }
+ }
+ return (Object []) l.toArray();
+ }
+
+ public void showAllRosters() {
+ Object [] adapters = getConnectedContainerAdapters(IPresenceContainerAdapter.class);
+ for(int i=0; i < adapters.length; i++) {
+ IPresenceContainerAdapter presenceAdapter = (IPresenceContainerAdapter) adapters[i];
+ showRosterItems(presenceAdapter.getRosterManager().getRoster());
+ }
+ }
+
+ public void showRoster(IRoster roster) {
+ showRosterItems(roster);
+ }
+
+ private void showRosterItems(IRosterItem rosterItem) {
+ if (rosterItem == null) return;
+ Collection children = null;
+ if (rosterItem instanceof IRoster) {
+ System.out.println("Roster: "+rosterItem.getName());
+ children = ((IRoster)rosterItem).getItems();
+ } else if (rosterItem instanceof IRosterGroup) {
+ System.out.println(" Group: "+rosterItem.getName());
+ children = ((IRosterGroup)rosterItem).getEntries();
+ } else if (rosterItem instanceof IRosterEntry) {
+ System.out.println(" Entry: "+rosterItem.getName());
+ System.out.println(" Type: "+((IRosterEntry)rosterItem).getPresence().getType());
+ children = null;
+ }
+ if (children != null) {
+ for(Iterator i=children.iterator(); i.hasNext(); ) showRosterItems((IRosterItem) i.next());
+ }
+ }
+}
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/roster/RosterContributionItem1.java b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/roster/RosterContributionItem1.java
new file mode 100644
index 000000000..882a103b6
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/roster/RosterContributionItem1.java
@@ -0,0 +1,33 @@
+package org.eclipse.ecf.internal.examples.webinar.util.roster;
+
+import org.eclipse.ecf.internal.examples.webinar.util.RosterWriter;
+import org.eclipse.ecf.presence.roster.IRoster;
+import org.eclipse.ecf.presence.ui.roster.AbstractRosterContributionItem;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+public class RosterContributionItem1 extends AbstractRosterContributionItem {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ecf.presence.ui.roster.AbstractPresenceContributionItem#makeActions()
+ */
+ protected IAction[] makeActions() {
+ final IRoster roster = getSelectedRoster();
+ if (roster != null) {
+ IAction action = new Action() {
+ public void run() {
+ RosterWriter accessor = new RosterWriter();
+ accessor.showRoster(roster);
+ }
+ };
+ action.setText("Show this roster on console");
+ action.setImageDescriptor(PlatformUI.getWorkbench()
+ .getSharedImages().getImageDescriptor(
+ ISharedImages.IMG_DEF_VIEW));
+ return new IAction[] { action };
+ } else return null;
+ }
+
+}
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterEntryContributionItem1.java b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterentry/RosterEntryContributionItem1.java
index 8e9a76bf0..85e1f7a7a 100644
--- a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterEntryContributionItem1.java
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterentry/RosterEntryContributionItem1.java
@@ -1,4 +1,4 @@
-package org.eclipse.ecf.internal.examples.webinar;
+package org.eclipse.ecf.internal.examples.webinar.util.rosterentry;
import org.eclipse.ecf.presence.roster.IRosterEntry;
import org.eclipse.ecf.presence.ui.roster.AbstractRosterEntryContributionItem;
@@ -13,16 +13,14 @@ public class RosterEntryContributionItem1 extends AbstractRosterEntryContributio
* @see org.eclipse.ecf.presence.ui.roster.AbstractPresenceContributionItem#makeActions()
*/
protected IAction[] makeActions() {
- IAction action = null;
- IRosterEntry entry = getSelectedRosterEntry();
+ final IRosterEntry entry = getSelectedRosterEntry();
if (entry != null) {
- action = new Action() {
+ IAction action = new Action() {
public void run() {
- IRosterEntry rosterEntry = getSelectedRosterEntry();
- System.out.println("running action for roster entry "+rosterEntry.getName());
+ System.out.println("running action for "+entry.getName());
}
};
- action.setText("Send info to "+getSelectedRosterEntry().getName());
+ action.setText("Super duper addon");
action.setImageDescriptor(PlatformUI.getWorkbench()
.getSharedImages().getImageDescriptor(
ISharedImages.IMG_DEF_VIEW));
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterEntryContributionItem2.java b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterentry/RosterEntryContributionItem2.java
index e1f6e98ff..cff764f81 100644
--- a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/RosterEntryContributionItem2.java
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterentry/RosterEntryContributionItem2.java
@@ -1,4 +1,4 @@
-package org.eclipse.ecf.internal.examples.webinar;
+package org.eclipse.ecf.internal.examples.webinar.util.rosterentry;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -31,36 +31,6 @@ import org.eclipse.ui.browser.IWorkbenchBrowserSupport;
public class RosterEntryContributionItem2 extends
AbstractRosterEntryContributionItem {
- private static Map channels = new HashMap();
-
- public RosterEntryContributionItem2() {
- super();
- }
-
- private IChannel initializeChannelFor(IContainer container) {
- if (container == null) return null;
- ID containerID = container.getID();
- IChannel chan = (IChannel) channels.get(containerID);
- if (chan == null) {
- IChannelContainerAdapter adapter = (IChannelContainerAdapter) container
- .getAdapter(IChannelContainerAdapter.class);
- if (adapter != null) {
- chan = createChannel(adapter);
- channels.put(containerID,chan);
- }
- }
- return chan;
- }
-
- public void dispose() {
- super.dispose();
- for(Iterator i=channels.keySet().iterator(); i.hasNext(); ) {
- IChannel chan = (IChannel) channels.get(i.next());
- chan.dispose();
- }
- channels.clear();
- }
-
/*
* (non-Javadoc)
*
@@ -68,17 +38,16 @@ public class RosterEntryContributionItem2 extends
*/
protected IAction[] makeActions() {
IAction action = null;
- IRosterEntry rosterEntry = getSelectedRosterEntry();
+ final IRosterEntry rosterEntry = getSelectedRosterEntry();
if (rosterEntry != null) {
if (initializeChannelFor(getContainerForRosterEntry(rosterEntry)) != null) {
action = new Action() {
public void run() {
- sendDataToChannel(getSelectedRosterEntry());
+ sendDataToChannel(rosterEntry);
}
};
- action
- .setText("Send Object Array");
+ action.setText("Send Message and URL");
action.setImageDescriptor(PlatformUI.getWorkbench()
.getSharedImages().getImageDescriptor(
ISharedImages.IMG_DEF_VIEW));
@@ -109,7 +78,7 @@ public class RosterEntryContributionItem2 extends
ByteArrayInputStream bins = new ByteArrayInputStream(data);
ObjectInputStream oos = new ObjectInputStream(bins);
String[] received = (String[]) oos.readObject();
- show(received[0], received[1]);
+ showMessageAndURL(received[0], received[1]);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -117,6 +86,33 @@ public class RosterEntryContributionItem2 extends
}
+ private static Map channels = new HashMap();
+
+ private IChannel initializeChannelFor(IContainer container) {
+ if (container == null)
+ return null;
+ ID containerID = container.getID();
+ IChannel chan = (IChannel) channels.get(containerID);
+ if (chan == null) {
+ IChannelContainerAdapter adapter = (IChannelContainerAdapter) container
+ .getAdapter(IChannelContainerAdapter.class);
+ if (adapter != null) {
+ chan = createChannel(adapter);
+ channels.put(containerID, chan);
+ }
+ }
+ return chan;
+ }
+
+ public void dispose() {
+ super.dispose();
+ for (Iterator i = channels.keySet().iterator(); i.hasNext();) {
+ IChannel chan = (IChannel) channels.get(i.next());
+ chan.dispose();
+ }
+ channels.clear();
+ }
+
private IChannel createChannel(IChannelContainerAdapter adapter) {
try {
return adapter.createChannel(IDFactory.getDefault().createStringID(
@@ -136,7 +132,7 @@ public class RosterEntryContributionItem2 extends
return null;
}
- private void show(final String string, final String url) {
+ private void showMessageAndURL(final String string, final String url) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
if (MessageDialog.openConfirm(null, "Received message", string
diff --git a/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterview/RosterViewContributionItem1.java b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterview/RosterViewContributionItem1.java
new file mode 100644
index 000000000..ed61be289
--- /dev/null
+++ b/examples/bundles/org.eclipse.ecf.examples.webinar/src/org/eclipse/ecf/internal/examples/webinar/util/rosterview/RosterViewContributionItem1.java
@@ -0,0 +1,44 @@
+/****************************************************************************
+ * 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.internal.examples.webinar.util.rosterview;
+
+import org.eclipse.ecf.internal.examples.webinar.util.RosterWriter;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.ui.actions.CompoundContributionItem;
+
+/**
+ *
+ */
+public class RosterViewContributionItem1 extends CompoundContributionItem {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems()
+ */
+ protected IContributionItem[] getContributionItems() {
+ return new IContributionItem[] { new ActionContributionItem(getAction()) };
+ }
+
+ private IAction getAction() {
+ IAction action = new Action() {
+ public void run() {
+ System.out.println("showing rosters on console");
+ RosterWriter writer = new RosterWriter();
+ writer.showAllRosters();
+ }
+ };
+ action.setText("show all rosters on console");
+ return action;
+ }
+}

Back to the top