use of org.eclipse.ecf.datashare.IChannel in project ecf by eclipse.
the class ChannelTest method testCreateChannel.
public void testCreateChannel() throws Exception {
final IChannelContainerAdapter channelContainer = getChannelContainer(0);
final IChannel channel = channelContainer.createChannel(getNewID(CHANNEL_NAME_1), getIChannelListener(getContainerID(0)), null);
assertNotNull(channel);
assertNotNull(channel.getID());
assertNotNull(channel.getListener());
}
use of org.eclipse.ecf.datashare.IChannel in project ecf by eclipse.
the class SendMessageRosterEntryContribution method sendDataToChannel.
private void sendDataToChannel(IRosterEntry rosterEntry) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(new String[] { "Hi " + rosterEntry.getName(), "http://www.eclipse.org/ecf" });
IChannel channel = initializeChannelFor(getContainerForRosterEntry(rosterEntry));
channel.sendMessage(rosterEntry.getUser().getID(), bos.toByteArray());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.eclipse.ecf.datashare.IChannel in project ecf by eclipse.
the class SendMessageRosterEntryContribution method initializeChannelFor.
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;
}
use of org.eclipse.ecf.datashare.IChannel in project ecf by eclipse.
the class SendMessageRosterEntryContribution method dispose.
public void dispose() {
super.dispose();
for (Iterator i = channels.keySet().iterator(); i.hasNext(); ) {
IChannel chan = (IChannel) channels.get(i.next());
chan.dispose();
}
channels.clear();
}
use of org.eclipse.ecf.datashare.IChannel in project ecf by eclipse.
the class SendContextContributionItem method createRosterEntryHandler.
protected AbstractRosterMenuHandler createRosterEntryHandler(final IRosterEntry rosterEntry) {
return new AbstractRosterMenuHandler(rosterEntry) {
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchPart part = HandlerUtil.getActivePart(event);
if (part == null) {
return null;
}
IWorkbenchSite site = part.getSite();
if (site == null) {
return null;
}
ISelectionProvider provider = site.getSelectionProvider();
if (provider == null) {
return null;
}
ISelection selection = provider.getSelection();
if (selection instanceof IStructuredSelection) {
IChannelContainerAdapter icca = (IChannelContainerAdapter) rosterEntry.getRoster().getPresenceContainerAdapter().getAdapter(IChannelContainerAdapter.class);
ID channelID;
try {
channelID = icca.getChannelNamespace().createInstance(new Object[] { Activator.PLUGIN_ID });
} catch (IDCreateException e1) {
return null;
}
final IChannel channel = icca.getChannel(channelID);
if (channel == null) {
return null;
}
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof ITask) {
final ITask task = (ITask) element;
Job job = new Job("Send Task") {
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask("Sending task...", 5);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
TasksUiPlugin.getTaskListManager().getTaskListWriter().writeTask((AbstractTask) task, stream);
monitor.worked(2);
try {
channel.sendMessage(getRosterEntry().getUser().getID(), stream.toByteArray());
monitor.worked(3);
} catch (Exception e) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "An error occurred while sending the task.", e);
} finally {
monitor.done();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
}
return null;
}
};
}
Aggregations