Search in sources :

Example 1 with IRosterManager

use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.

the class XMPPHyperlink method openContainer.

/**
 * @param presenceContainerAdapter
 */
private void openContainer(IContainer container) {
    final IPresenceContainerAdapter presenceContainerAdapter = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
    final IChatManager chatManager = presenceContainerAdapter.getChatManager();
    final IRosterManager rosterManager = presenceContainerAdapter.getRosterManager();
    if (chatManager != null && rosterManager != null) {
        try {
            // get local ID
            final XMPPID localID = (XMPPID) rosterManager.getRoster().getUser().getID();
            final Namespace ns = container.getConnectNamespace();
            // create target ID
            final XMPPID targetID = (isXMPPS) ? new XMPPSID(ns, getURI().getAuthority()) : new XMPPID(ns, getURI().getAuthority());
            // If they are same, just tell user and return
            if (localID.equals(targetID)) {
                MessageDialog.openError(null, Messages.XMPPHyperlink_MESSAGING_ERROR_TITLE, Messages.XMPPHyperlink_MESSAGING_ERROR_MESSAGE);
                return;
            } else {
                final String localHost = localID.getHostname();
                final String targetHost = targetID.getHostname();
                // it's pretty obvious that we wish to message to them
                if (localHost.equals(targetHost)) {
                    openMessagesView(chatManager, localID, targetID, targetID.getUsername());
                } else {
                    // Otherwise, ask the user whether messaging, or
                    // connecting is desired
                    final MessageDialog messageDialog = new MessageDialog(null, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_TITLE, null, NLS.bind(Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_MESSAGE, new Object[] { targetHost, localHost, targetID.getName(), localID.getName() }), MessageDialog.QUESTION, new String[] { Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_SEND_MESSAGE, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_CONNECT, Messages.XMPPHyperlink_SELECT_ACTION_DIALOG_BUTTON_CANCEL }, 2);
                    final int selected = messageDialog.open();
                    switch(selected) {
                        case 0:
                            openMessagesView(chatManager, localID, targetID, targetID.getUsername());
                            return;
                        case 1:
                            super.open();
                            return;
                        default:
                            return;
                    }
                }
            }
        } catch (final Exception e) {
            MessageDialog.openError(null, Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_TITLE, NLS.bind(Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_DIALOG_MESSAGE, e.getLocalizedMessage()));
            Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.XMPPHyperlink_ERROR_OPEN_MESSAGE_VIEW_LOG_STATUS_MESSAGE, e));
        }
    }
}
Also used : IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IRosterManager(org.eclipse.ecf.presence.roster.IRosterManager) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID) Namespace(org.eclipse.ecf.core.identity.Namespace) XMPPSID(org.eclipse.ecf.provider.xmpp.identity.XMPPSID)

Example 2 with IRosterManager

use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.

the class ResourcesShareHandler method run.

private void run(Shell shell, final ResourcesShare share, final String projectName) {
    final boolean[] ret = { false };
    try {
        ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
        dialog.open();
        dialog.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    monitor.beginTask("Sharing " + projectName, IProgressMonitor.UNKNOWN);
                    monitor.subTask("Sending request...");
                    share.startShare(getRosterEntry().getRoster().getUser().getID(), getRosterEntry().getUser().getID(), projectName);
                    monitor.subTask("Waiting for acknowledgement...");
                    while (true) {
                        if (monitor.isCanceled()) {
                            throw new InterruptedException();
                        }
                        Thread.sleep(50);
                        Boolean response = share.getResponse();
                        if (response != null) {
                            ret[0] = response.booleanValue();
                            return;
                        }
                    }
                } catch (ECFException e) {
                    throw new InvocationTargetException(e);
                } finally {
                    monitor.done();
                }
            }
        });
    } catch (InvocationTargetException e) {
        IStatus status = new Status(IStatus.ERROR, SyncResourcesUI.PLUGIN_ID, "Could not send share request", e.getCause());
        StatusManager.getManager().handle(status);
        SyncResourcesUI.log(status);
    } catch (InterruptedException e) {
        // operation canceled, stop sharing this project
        share.stopSharing(projectName);
        return;
    }
    if (ret[0]) {
        IRosterManager manager = getRosterEntry().getRoster().getPresenceContainerAdapter().getRosterManager();
        manager.addRosterListener(new RosterListener(share, projectName, getRosterEntry()));
    } else {
        MessageDialog.openInformation(shell, null, "Sharing request denied.");
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IRosterManager(org.eclipse.ecf.presence.roster.IRosterManager) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) ECFException(org.eclipse.ecf.core.util.ECFException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 3 with IRosterManager

use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.

the class AbstractAdapterAccessTest method testGetRosterManager.

public void testGetRosterManager() {
    final IPresenceContainerAdapter adapter = getPresenceAdapter();
    assertNotNull(adapter);
    final IRosterManager rosterManager = adapter.getRosterManager();
    assertNotNull(rosterManager);
}
Also used : IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IRosterManager(org.eclipse.ecf.presence.roster.IRosterManager)

Example 4 with IRosterManager

use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.

the class BrowseDialog method fillContentProvider.

/* (non-Javadoc)
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#fillContentProvider(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.AbstractContentProvider, org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.ItemsFilter, org.eclipse.core.runtime.IProgressMonitor)
	 */
protected void fillContentProvider(AbstractContentProvider contentProvider, ItemsFilter itemsFilter, IProgressMonitor progressMonitor) {
    progressMonitor.beginTask(Messages.BrowseDialog_scanning, containers.length);
    // cycle through all the containers and grab entries
    for (int i = 0; i < containers.length; i++) {
        IContainer container = containers[i];
        IPresenceContainerAdapter presenceContainer = (IPresenceContainerAdapter) container.getAdapter(IPresenceContainerAdapter.class);
        if (presenceContainer != null) {
            IRosterManager manager = presenceContainer.getRosterManager();
            if (manager != null) {
                Collection items = manager.getRoster().getItems();
                for (Iterator it = items.iterator(); it.hasNext(); ) {
                    IRosterItem item = (IRosterItem) it.next();
                    addRosterItem(item, contentProvider, itemsFilter);
                }
            }
        }
        progressMonitor.worked(1);
    }
    progressMonitor.done();
}
Also used : IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IRosterManager(org.eclipse.ecf.presence.roster.IRosterManager) IRosterItem(org.eclipse.ecf.presence.roster.IRosterItem) Iterator(java.util.Iterator) Collection(java.util.Collection) IContainer(org.eclipse.ecf.core.IContainer)

Example 5 with IRosterManager

use of org.eclipse.ecf.presence.roster.IRosterManager in project ecf by eclipse.

the class XMPPHyperlink method chooseAccount.

/**
 * @param adapters
 */
private void chooseAccount(final IContainer[] containers) {
    // If there's only one choice then use it
    if (containers.length == 1) {
        openContainer(containers[0]);
        return;
    } else {
        final IPresenceContainerAdapter[] adapters = new IPresenceContainerAdapter[containers.length];
        for (int i = 0; i < containers.length; i++) adapters[i] = (IPresenceContainerAdapter) containers[i].getAdapter(IPresenceContainerAdapter.class);
        final ListDialog dialog = new ListDialog(null);
        dialog.setContentProvider(new IStructuredContentProvider() {

            public Object[] getElements(Object inputElement) {
                return adapters;
            }

            public void dispose() {
            }

            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            }
        });
        dialog.setInput(adapters);
        dialog.setAddCancelButton(true);
        dialog.setBlockOnOpen(true);
        dialog.setTitle(Messages.XMPPHyperlink_SELECT_ACCOUNT_TITLE);
        dialog.setMessage(Messages.XMPPHyperlink_SELECT_ACCOUNT_MESSAGE);
        dialog.setHeightInChars(adapters.length > 4 ? adapters.length : 4);
        dialog.setInitialSelections(new IPresenceContainerAdapter[] { adapters[0] });
        dialog.setLabelProvider(new ILabelProvider() {

            public Image getImage(Object element) {
                return null;
            }

            public String getText(Object element) {
                final IRosterManager manager = ((IPresenceContainerAdapter) element).getRosterManager();
                if (manager == null)
                    return null;
                return manager.getRoster().getUser().getID().getName();
            }

            public void addListener(ILabelProviderListener listener) {
            }

            public void dispose() {
            }

            public boolean isLabelProperty(Object element, String property) {
                return false;
            }

            public void removeListener(ILabelProviderListener listener) {
            }
        });
        final int result = dialog.open();
        if (result == ListDialog.OK) {
            final Object[] res = dialog.getResult();
            if (res.length > 0)
                openContainer((IContainer) res[0]);
        }
    }
}
Also used : Image(org.eclipse.swt.graphics.Image) IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IRosterManager(org.eclipse.ecf.presence.roster.IRosterManager) ListDialog(org.eclipse.ui.dialogs.ListDialog)

Aggregations

IRosterManager (org.eclipse.ecf.presence.roster.IRosterManager)5 IPresenceContainerAdapter (org.eclipse.ecf.presence.IPresenceContainerAdapter)4 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IContainer (org.eclipse.ecf.core.IContainer)1 Namespace (org.eclipse.ecf.core.identity.Namespace)1 ECFException (org.eclipse.ecf.core.util.ECFException)1 IRosterItem (org.eclipse.ecf.presence.roster.IRosterItem)1 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)1 XMPPSID (org.eclipse.ecf.provider.xmpp.identity.XMPPSID)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 Image (org.eclipse.swt.graphics.Image)1 ListDialog (org.eclipse.ui.dialogs.ListDialog)1