示例#1
0
  /**
   * Adds all contacts contained in the given <tt>MetaContactGroup</tt> matching the current filter
   * and not contained in the contact list.
   *
   * @param metaGroup the <tt>MetaContactGroup</tt>, which matching contacts to add
   * @param query the <tt>MetaContactQuery</tt> that notifies interested listeners of the results of
   *     this matching
   * @param resultCount the initial result count we would insert directly to the contact list
   *     without firing events
   */
  private void addMatching(MetaContactGroup metaGroup, MetaContactQuery query, int resultCount) {
    Iterator<MetaContact> childContacts = metaGroup.getChildContacts();

    while (childContacts.hasNext() && !query.isCanceled()) {
      MetaContact metaContact = childContacts.next();

      if (isMatching(metaContact)) {

        resultCount++;
        if (resultCount <= INITIAL_CONTACT_COUNT) {
          UIGroup uiGroup = null;

          if (!MetaContactListSource.isRootGroup(metaGroup)) {
            synchronized (metaGroup) {
              uiGroup = MetaContactListSource.getUIGroup(metaGroup);
              if (uiGroup == null) uiGroup = MetaContactListSource.createUIGroup(metaGroup);
            }
          }

          if (logger.isDebugEnabled())
            logger.debug("Presence filter contact added: " + metaContact.getDisplayName());

          UIContactImpl newUIContact;
          synchronized (metaContact) {
            newUIContact = MetaContactListSource.getUIContact(metaContact);

            if (newUIContact == null) {
              newUIContact = MetaContactListSource.createUIContact(metaContact);
            }
          }

          GuiActivator.getContactList().addContact(newUIContact, uiGroup, true, true);

          query.setInitialResultCount(resultCount);
        } else {
          query.fireQueryEvent(metaContact);
        }
      }
    }

    // If in the meantime the filtering has been stopped we return here.
    if (query.isCanceled()) return;

    Iterator<MetaContactGroup> subgroups = metaGroup.getSubgroups();
    while (subgroups.hasNext() && !query.isCanceled()) {
      MetaContactGroup subgroup = subgroups.next();

      if (isMatching(subgroup)) {
        UIGroup uiGroup;
        synchronized (subgroup) {
          uiGroup = MetaContactListSource.getUIGroup(subgroup);

          if (uiGroup == null) uiGroup = MetaContactListSource.createUIGroup(subgroup);
        }

        GuiActivator.getContactList().addGroup(uiGroup, true);

        addMatching(subgroup, query, resultCount);
      }
    }
  }
示例#2
0
 /**
  * Returns <tt>true</tt> if offline contacts are shown or if the given <tt>MetaContactGroup</tt>
  * contains online contacts.
  *
  * @param metaGroup the <tt>MetaContactGroup</tt> to check
  * @return <tt>true</tt> if the given <tt>MetaContactGroup</tt> is matching this filter
  */
 private boolean isMatching(MetaContactGroup metaGroup) {
   return isShowOffline
       || (metaGroup.countOnlineChildContacts() > 0)
       || MetaContactListSource.isNewGroup(metaGroup);
 }