Search in sources :

Example 1 with IRosterGroup

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

the class XMPPContainerPresenceHelper method updatePresence.

private void updatePresence(XMPPID fromID, IPresence newPresence) {
    final Collection rosterItems = roster.getItems();
    List newEntrys = new ArrayList();
    synchronized (rosterItems) {
        for (final Iterator i = roster.getItems().iterator(); i.hasNext(); ) {
            final IRosterItem item = (IRosterItem) i.next();
            if (item instanceof IRosterGroup) {
                AdditionalClientRosterEntry[] es = updatePresenceInGroup((IRosterGroup) item, fromID, newPresence);
                for (int j = 0; j < es.length; j++) {
                    newEntrys.add(es[j]);
                }
            } else if (item instanceof org.eclipse.ecf.presence.roster.RosterEntry) {
                AdditionalClientRosterEntry entry = updatePresenceForMatchingEntry((org.eclipse.ecf.presence.roster.RosterEntry) item, fromID, newPresence);
                if (entry != null)
                    newEntrys.add(entry);
            }
        }
    }
    AdditionalClientRosterEntry[] entrys = (AdditionalClientRosterEntry[]) newEntrys.toArray(new AdditionalClientRosterEntry[] {});
    if (entrys.length > 0) {
        for (int i = 0; i < entrys.length; i++) {
            if (entrys[i].add) {
                IRosterEntry entry = new org.eclipse.ecf.presence.roster.RosterEntry(entrys[i].parent, entrys[i].user, entrys[i].presence);
                addUniqueToRoster(new IRosterItem[] { entry });
                fireSetRosterEntry(false, entry);
            } else {
                removeItemFromRoster(rosterItems, fromID);
            }
        }
    }
}
Also used : IRosterItem(org.eclipse.ecf.presence.roster.IRosterItem) ArrayList(java.util.ArrayList) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) Iterator(java.util.Iterator) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry) RosterEntry(org.jivesoftware.smack.RosterEntry) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry)

Example 2 with IRosterGroup

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

the class RosterWriterHelper method showRosterItems.

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());
    }
}
Also used : IRosterItem(org.eclipse.ecf.presence.roster.IRosterItem) IRoster(org.eclipse.ecf.presence.roster.IRoster) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) Iterator(java.util.Iterator) Collection(java.util.Collection) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry)

Example 3 with IRosterGroup

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

the class XMPPContainerPresenceHelper method createRosterEntry.

protected IRosterEntry createRosterEntry(ID userID, String name, Iterator grps) {
    final List groups = new ArrayList();
    for (; grps.hasNext(); ) {
        final Object o = grps.next();
        final String groupName = (o instanceof String) ? (String) o : ((RosterGroup) o).getName();
        final IRosterGroup localGrp = new org.eclipse.ecf.presence.roster.RosterGroup(roster, groupName);
        groups.add(localGrp);
    }
    final IUser user = new User(userID, name);
    IRosterEntry newEntry = null;
    if (groups.size() == 0)
        return new org.eclipse.ecf.presence.roster.RosterEntry(roster, user, new org.eclipse.ecf.presence.Presence(IPresence.Type.UNAVAILABLE, IPresence.Type.UNAVAILABLE.toString(), IPresence.Mode.AWAY));
    else
        for (int i = 0; i < groups.size(); i++) {
            final IRosterGroup grp = (IRosterGroup) groups.get(i);
            if (i == 0)
                newEntry = new org.eclipse.ecf.presence.roster.RosterEntry(grp, user, null);
            else {
                grp.getEntries().add(newEntry);
                newEntry.getGroups().add(grp);
            }
        }
    return newEntry;
}
Also used : User(org.eclipse.ecf.core.user.User) IUser(org.eclipse.ecf.core.user.IUser) ArrayList(java.util.ArrayList) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) RosterGroup(org.eclipse.ecf.presence.roster.RosterGroup) IRosterGroup(org.eclipse.ecf.presence.roster.IRosterGroup) IUser(org.eclipse.ecf.core.user.IUser) IPresence(org.eclipse.ecf.presence.IPresence) Presence(org.jivesoftware.smack.packet.Presence) List(java.util.List) ArrayList(java.util.ArrayList) ISharedObject(org.eclipse.ecf.core.sharedobject.ISharedObject) IRosterEntry(org.eclipse.ecf.presence.roster.IRosterEntry)

Aggregations

IRosterEntry (org.eclipse.ecf.presence.roster.IRosterEntry)3 IRosterGroup (org.eclipse.ecf.presence.roster.IRosterGroup)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 List (java.util.List)2 IRosterItem (org.eclipse.ecf.presence.roster.IRosterItem)2 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)1 IUser (org.eclipse.ecf.core.user.IUser)1 User (org.eclipse.ecf.core.user.User)1 IPresence (org.eclipse.ecf.presence.IPresence)1 IRoster (org.eclipse.ecf.presence.roster.IRoster)1 RosterGroup (org.eclipse.ecf.presence.roster.RosterGroup)1 RosterEntry (org.jivesoftware.smack.RosterEntry)1 Presence (org.jivesoftware.smack.packet.Presence)1