Java Code Examples for org.jivesoftware.smack.roster.Roster#getGroups()

The following examples show how to use org.jivesoftware.smack.roster.Roster#getGroups() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MucManager.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
public List<RosterGroup> getGroups(Roster roster) {
    List<RosterGroup> groupList = new ArrayList<RosterGroup>();
    Collection<RosterGroup> rosterGroups = roster.getGroups();
    Iterator<RosterGroup> i = rosterGroups.iterator();
    while (i.hasNext()) {
        groupList.add(i.next());
    }
    return groupList;
}
 
Example 2
Source File: ContactGroupTransferHandler.java    From Spark with Apache License 2.0 4 votes vote down vote up
private void addContactItem(final ContactGroup contactGroup, final ContactItem item) {
     ContactItem newContact = UIComponentRegistry.createContactItem(Res.getString("group.empty"), null, null);
     newContact.setPresence(item.getPresence());
     newContact.setIcon(item.getIcon());
     newContact.getNicknameLabel().setFont(item.getNicknameLabel().getFont());

     if (!PresenceManager.isOnline(item.getJid().asBareJid())) {
         contactGroup.addOfflineContactItem(item.getAlias(), item.getNickname(), item.getJid(), null);
     }
     else {
         contactGroup.addContactItem(newContact);
     }
     contactGroup.clearSelection();
     contactGroup.fireContactGroupUpdated(); //Updating group title

     final ContactGroup oldGroup = getContactGroup(item.getGroupName());

     SwingWorker worker = new SwingWorker() {
         @Override
public Object construct() {
             Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
             RosterEntry entry = roster.getEntry(item.getJid().asBareJid());

             RosterGroup groupFound = null;

             for (RosterGroup group : roster.getGroups()) {
                 if (group.getName().equals(contactGroup.getGroupName())) {
                     try {
                         groupFound = group;
                         group.addEntry(entry);
                     }
                     catch (XMPPException | SmackException | InterruptedException e1) {
                         Log.error(e1);
                         return false;
                     }
                 }
             }

             // This is a new group
             if (groupFound == null) {
                 groupFound = roster.createGroup(contactGroup.getGroupName());
                 try {
                     groupFound.addEntry(entry);
                 }
                 catch (XMPPException | SmackException | InterruptedException e) {
                     Log.error(e);
                 }
             }
             return true;
         }

         @Override
public void finished() {
             if ((Boolean)get()) {
                 // Now try and remove the group from the old one.
                 removeContactItem(oldGroup, item);
             }
         }

     };

     worker.start();
 }
 
Example 3
Source File: ContactGroupTransferHandler.java    From Spark with Apache License 2.0 4 votes vote down vote up
public boolean removeContactItem(ContactGroup contactGroup, ContactItem item) {
    if (contactGroup.isSharedGroup()) {
        return false;
    }

    if (contactGroup.isUnfiledGroup()) {
        contactGroup.removeContactItem(item);
        contactGroup.fireContactGroupUpdated();
        return true;
    }

    // Remove entry from Roster Group
    Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
    RosterEntry entry = roster.getEntry(item.getJid().asBareJid());

    RosterGroup rosterGroup = null;

    for (RosterGroup group : roster.getGroups()) {
        if (group.getName().equals(contactGroup.getGroupName())) {
            try {
                rosterGroup = group;
                group.removeEntry(entry);
            }
            catch (XMPPException | SmackException | InterruptedException e1) {
                return false;
            }
        }
    }

    if (rosterGroup == null) {
        return false;
    }

    if (!rosterGroup.contains(entry)) {
        contactGroup.removeContactItem(item);
        contactGroup.fireContactGroupUpdated(); //Updating group title
        return true;
    }

    return false;
}
 
Example 4
Source File: ContactListAssistantPlugin.java    From Spark with Apache License 2.0 4 votes vote down vote up
/**
 * Copies or moves a new <code>ContactItem</code> into the <code>ContactGroup</code>.
 *
 * @param contactGroup the ContactGroup.
 * @param item         the ContactItem to move.
 * @param move         true if the ContactItem should be moved, otherwise false.
 */
private void addContactItem(final ContactGroup contactGroup, final ContactItem item, final boolean move) {
    ContactItem newContact = UIComponentRegistry.createContactItem(item.getAlias(), item.getNickname(), item.getJid());
    newContact.setPresence(item.getPresence());
    newContact.setIcon(item.getIcon());
    newContact.getNicknameLabel().setFont(item.getNicknameLabel().getFont());
    boolean groupHadAvailableContacts = false;
    
    // Do not copy/move a contact item only if it is not already in the Group.
    if (contactGroup.getContactItemByJID(item.getJid().asBareJid(), true) != null) {
        return;
    }

    if (!PresenceManager.isOnline(item.getJid().asBareJid())) {
        contactGroup.addOfflineContactItem(item.getAlias(), item.getNickname(), item.getJid(), null);
    }
    else {
        groupHadAvailableContacts = contactGroup.hasAvailableContacts();
        contactGroup.addContactItem(newContact);
    }
    contactGroup.clearSelection();
    contactGroup.fireContactGroupUpdated(); //Updating group title

    final ContactGroup oldGroup = getContactGroup(item.getGroupName());

    
    final boolean groupAvailableContacts = groupHadAvailableContacts;
    SwingWorker worker = new SwingWorker() {
        @Override
        public Object construct() {
            Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
            RosterEntry entry = roster.getEntry(item.getJid().asBareJid());

            RosterGroup groupFound = null;

            for (RosterGroup group : roster.getGroups()) {
                if (group.getName().equals(contactGroup.getGroupName())) {
                    try {
                        groupFound = group;
                        if (!groupAvailableContacts)
                        {
                    	SparkManager.getContactList().toggleGroupVisibility(groupFound.getName(), true);
                        }
                        group.addEntry(entry);
                    }
                    catch (XMPPException | SmackException | InterruptedException e1) {
                        Log.error(e1);
                        return false;
                    }
                }
            }

            // This is a new group
            if (groupFound == null) {
                groupFound = roster.createGroup(contactGroup.getGroupName());
                try {
            	groupFound.addEntry(entry);
                    if (!groupAvailableContacts)
                    {
                	SparkManager.getContactList().toggleGroupVisibility(groupFound.getName(), true);
                    }  
                }
                catch (XMPPException | SmackException | InterruptedException e) {
                    Log.error(e);
                }
            }
            return true;
        }

        @Override
        public void finished() {
            if ((Boolean)get()) {
                // Now try and remove the group from the old one.
                if (move) {
                    removeContactItem(oldGroup, item);
                   if (!localPreferences.isEmptyGroupsShown() && !oldGroup.hasAvailableContacts())
                    {
                      SparkManager.getContactList().toggleGroupVisibility(oldGroup.getGroupName(),false);
                    }
                }
            }
        }

    };

    worker.start();
}
 
Example 5
Source File: ContactListAssistantPlugin.java    From Spark with Apache License 2.0 4 votes vote down vote up
public boolean removeContactItem(ContactGroup contactGroup, ContactItem item) {
    if (contactGroup.isSharedGroup()) {
        return false;
    }

    if (contactGroup.isUnfiledGroup()) {
        contactGroup.removeContactItem(item);
        contactGroup.fireContactGroupUpdated();
        return true;
    }

    // Remove entry from Roster Group
    Roster roster = Roster.getInstanceFor( SparkManager.getConnection() );
    RosterEntry entry = roster.getEntry(item.getJid().asBareJid());

    RosterGroup rosterGroup = null;

    for (RosterGroup group : roster.getGroups()) {
        if (group.getName().equals(contactGroup.getGroupName())) {
            try {
                rosterGroup = group;
                group.removeEntry(entry);
            }
            catch (XMPPException | SmackException | InterruptedException e1) {
                return false;
            }
        }
    }

    if (rosterGroup == null) {
        return false;
    }

    if (!rosterGroup.contains(entry)) {
        contactGroup.removeContactItem(item);
        contactGroup.fireContactGroupUpdated(); //Updating group title
        return true;
    }

    return false;
}