Search in sources :

Example 16 with IPresenceContainerAdapter

use of org.eclipse.ecf.presence.IPresenceContainerAdapter 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 17 with IPresenceContainerAdapter

use of org.eclipse.ecf.presence.IPresenceContainerAdapter in project ecf by eclipse.

the class AbstractRosterMenuContributionItem method getPresenceContainerAdapters.

protected List getPresenceContainerAdapters() {
    List presenceContainers = new ArrayList();
    IContainerManager containerManager = Activator.getDefault().getContainerManager();
    if (containerManager == null)
        return presenceContainers;
    IContainer[] containers = containerManager.getAllContainers();
    for (int i = 0; i < containers.length; i++) {
        IPresenceContainerAdapter presenceContainerAdapter = (IPresenceContainerAdapter) containers[i].getAdapter(IPresenceContainerAdapter.class);
        if ((containers[i].getConnectedID() != null) && (presenceContainerAdapter != null)) {
            presenceContainers.add(presenceContainerAdapter);
        }
    }
    return presenceContainers;
}
Also used : IPresenceContainerAdapter(org.eclipse.ecf.presence.IPresenceContainerAdapter) IContainerManager(org.eclipse.ecf.core.IContainerManager) IContainer(org.eclipse.ecf.core.IContainer)

Example 18 with IPresenceContainerAdapter

use of org.eclipse.ecf.presence.IPresenceContainerAdapter 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

IPresenceContainerAdapter (org.eclipse.ecf.presence.IPresenceContainerAdapter)18 IContainer (org.eclipse.ecf.core.IContainer)5 IRosterManager (org.eclipse.ecf.presence.roster.IRosterManager)4 IChatManager (org.eclipse.ecf.presence.im.IChatManager)3 Iterator (java.util.Iterator)2 List (java.util.List)2 Namespace (org.eclipse.ecf.core.identity.Namespace)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Entry (java.util.Map.Entry)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1 IContainerListener (org.eclipse.ecf.core.IContainerListener)1 IContainerManager (org.eclipse.ecf.core.IContainerManager)1 IContainerConnectedEvent (org.eclipse.ecf.core.events.IContainerConnectedEvent)1 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)1