Search in sources :

Example 11 with IChannelContainerAdapter

use of org.eclipse.ecf.datashare.IChannelContainerAdapter 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());
}
Also used : IChannel(org.eclipse.ecf.datashare.IChannel) IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter)

Example 12 with IChannelContainerAdapter

use of org.eclipse.ecf.datashare.IChannelContainerAdapter 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;
}
Also used : IChannel(org.eclipse.ecf.datashare.IChannel) IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter) ID(org.eclipse.ecf.core.identity.ID)

Example 13 with IChannelContainerAdapter

use of org.eclipse.ecf.datashare.IChannelContainerAdapter 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;
        }
    };
}
Also used : IWorkbenchSite(org.eclipse.ui.IWorkbenchSite) ITask(org.eclipse.mylyn.tasks.core.ITask) IChannel(org.eclipse.ecf.datashare.IChannel) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) ExecutionException(org.eclipse.core.commands.ExecutionException) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) AbstractRosterMenuHandler(org.eclipse.ecf.presence.ui.menu.AbstractRosterMenuHandler) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter) ID(org.eclipse.ecf.core.identity.ID) Job(org.eclipse.core.runtime.jobs.Job)

Example 14 with IChannelContainerAdapter

use of org.eclipse.ecf.datashare.IChannelContainerAdapter in project ecf by eclipse.

the class ChannelTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    setClientCount(2);
    clients = createClients();
    channelID = IDFactory.getDefault().createStringID(CHANNEL_NAME);
    connectClients();
    for (int i = 0; i < clientCount; i++) {
        final IChannelContainerAdapter channelContainer = getChannelContainer(i);
        channelContainer.createChannel(channelID, getIChannelListener(getContainerID(i)), null);
    }
}
Also used : IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter)

Example 15 with IChannelContainerAdapter

use of org.eclipse.ecf.datashare.IChannelContainerAdapter in project ecf by eclipse.

the class DsClient1 method createChannel.

protected IChannel createChannel(IContainer container) throws ECFException {
    IChannelContainerAdapter channelContainer = (IChannelContainerAdapter) container.getAdapter(IChannelContainerAdapter.class);
    if (channelContainer == null)
        throw new NullPointerException("cannot get channel container adapter");
    ID channelID = IDFactory.getDefault().createID(channelContainer.getChannelNamespace(), "channel1");
    IChannelListener channelListener = new IChannelListener() {

        public void handleChannelEvent(IChannelEvent event) {
            System.out.println("handleChannelEvent(" + event + ")");
        }
    };
    return channelContainer.createChannel(channelID, channelListener, new HashMap());
}
Also used : IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) HashMap(java.util.HashMap) IChannelContainerAdapter(org.eclipse.ecf.datashare.IChannelContainerAdapter) ID(org.eclipse.ecf.core.identity.ID)

Aggregations

IChannelContainerAdapter (org.eclipse.ecf.datashare.IChannelContainerAdapter)19 IContainer (org.eclipse.ecf.core.IContainer)7 ID (org.eclipse.ecf.core.identity.ID)6 IChannel (org.eclipse.ecf.datashare.IChannel)5 IRosterEntry (org.eclipse.ecf.presence.roster.IRosterEntry)4 Action (org.eclipse.jface.action.Action)4 IAction (org.eclipse.jface.action.IAction)4 HashMap (java.util.HashMap)3 IChannelListener (org.eclipse.ecf.datashare.IChannelListener)3 IChannelEvent (org.eclipse.ecf.datashare.events.IChannelEvent)3 IRoster (org.eclipse.ecf.presence.roster.IRoster)3 IChannelMessageEvent (org.eclipse.ecf.datashare.events.IChannelMessageEvent)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 Job (org.eclipse.core.runtime.jobs.Job)1 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 BaseChannelConfig (org.eclipse.ecf.datashare.BaseChannelConfig)1 IChannelConfig (org.eclipse.ecf.datashare.IChannelConfig)1 AbstractRosterMenuHandler (org.eclipse.ecf.presence.ui.menu.AbstractRosterMenuHandler)1