Reverts changes from 160bccf16f , dfac8a056e and 79214016b4 .

cusax-fix 4985
hristoterezov 12 years ago
parent 8d83cfb5be
commit 2a368ae593

@ -36,36 +36,31 @@ public String getDisplayName()
}
/**
* Creates query for the given <tt>searchString</tt>.
* Queries this contact source for the given <tt>searchString</tt>.
* @param queryString the string to search for
* @param listener the listener that receives the found contacts
* @return the created query
*/
public ContactQuery createContactQuery(String queryString)
public ContactQuery queryContactSource(String queryString)
{
return createContactQuery(queryString, 50);
return queryContactSource(queryString, 50);
}
/**
* Creates query for the given <tt>searchString</tt>.
* Queries this contact source for the given <tt>searchString</tt>.
* @param queryString the string to search for
* @param contactCount the maximum count of result contacts
* @return the created query
*/
public ContactQuery createContactQuery(String queryString, int contactCount)
public ContactQuery queryContactSource(String queryString, int contactCount)
{
if (queryString != null && queryString.length() > 0)
{
return new CallHistoryContactQuery(
CallHistoryActivator.getCallHistoryService()
.findByPeer(queryString, contactCount));
}
else
{
return new CallHistoryContactQuery(
CallHistoryActivator.getCallHistoryService()
.findLast(contactCount));
}
}
/**
@ -98,11 +93,6 @@ private class CallHistoryContactQuery
* progress.
*/
private int status = QUERY_IN_PROGRESS;
/**
* Iterator for the queried contacts.
*/
Iterator<CallRecord> recordsIter = null;
/**
* Creates an instance of <tt>CallHistoryContactQuery</tt> by specifying
@ -112,7 +102,6 @@ private class CallHistoryContactQuery
*/
public CallHistoryContactQuery(Collection<CallRecord> callRecords)
{
recordsIter = callRecords.iterator();
Iterator<CallRecord> recordsIter = callRecords.iterator();
while (recordsIter.hasNext() && status != QUERY_CANCELED)
@ -127,45 +116,6 @@ public CallHistoryContactQuery(Collection<CallRecord> callRecords)
status = QUERY_COMPLETED;
}
@Override
public void start()
{
if(callHistoryQuery != null)
{
callHistoryQuery.addQueryListener(new CallHistoryQueryListener()
{
public void callRecordReceived(CallRecordEvent event)
{
if (getStatus() == ContactQuery.QUERY_CANCELED)
return;
SourceContact contact = new CallHistorySourceContact(
CallHistoryContactSource.this,
event.getCallRecord());
sourceContacts.add(contact);
fireQueryEvent(contact);
}
public void queryStatusChanged(
CallHistoryQueryStatusEvent event)
{
status = event.getEventType();
fireQueryStatusEvent(status);
}
});
recordsIter = callHistoryQuery.getCallRecords().iterator();
}
while (recordsIter.hasNext())
{
SourceContact contact = new CallHistorySourceContact(
CallHistoryContactSource.this,
recordsIter.next());
sourceContacts.add(contact);
fireQueryEvent(contact);
}
}
/**
* Creates an instance of <tt>CallHistoryContactQuery</tt> based on the
* given <tt>callHistoryQuery</tt>.
@ -175,7 +125,38 @@ public CallHistoryContactQuery(CallHistoryQuery callHistoryQuery)
{
this.callHistoryQuery = callHistoryQuery;
callHistoryQuery.addQueryListener(new CallHistoryQueryListener()
{
public void callRecordReceived(CallRecordEvent event)
{
if (getStatus() == ContactQuery.QUERY_CANCELED)
return;
SourceContact contact = new CallHistorySourceContact(
CallHistoryContactSource.this,
event.getCallRecord());
sourceContacts.add(contact);
fireQueryEvent(contact);
}
public void queryStatusChanged(
CallHistoryQueryStatusEvent event)
{
status = event.getEventType();
fireQueryStatusEvent(status);
}
});
Iterator<CallRecord> callRecords
= callHistoryQuery.getCallRecords().iterator();
while (callRecords.hasNext())
{
SourceContact contact = new CallHistorySourceContact(
CallHistoryContactSource.this,
callRecords.next());
sourceContacts.add(contact);
}
}
/**

@ -135,24 +135,6 @@ public void callback(GoogleContactsEntry entry)
});
}
@Override
public synchronized void start()
{
boolean hasStarted = false;
try
{
super.start();
hasStarted = true;
}
finally
{
if (!hasStarted)
{
getContactSource().removeQuery(this);
}
}
}
/**
* Gets the <tt>contactDetails</tt> to be set on a <tt>SourceContact</tt>.
*

@ -126,49 +126,56 @@ public boolean isGoogleTalk()
}
/**
* Creates query for the given <tt>searchPattern</tt>.
* Queries this search source for the given <tt>searchPattern</tt>.
*
* @param queryPattern the pattern to search for
* @param listener the listener that receives the found contacts
* @return the created query
*/
public ContactQuery createContactQuery(Pattern queryPattern)
public ContactQuery queryContactSource(Pattern queryPattern)
{
return createContactQuery(queryPattern,
return queryContactSource(queryPattern,
GoogleContactsQuery.GOOGLECONTACTS_MAX_RESULTS);
}
/**
* Creates query for the given <tt>searchPattern</tt>.
* Queries this search source for the given <tt>searchPattern</tt>.
*
* @param queryPattern the pattern to search for
* @param count maximum number of contact returned
* @return the created query
*/
public ContactQuery createContactQuery(Pattern queryPattern, int count)
public ContactQuery queryContactSource(Pattern queryPattern, int count)
{
GoogleContactsQuery query = new GoogleContactsQuery(this, queryPattern,
count);
synchronized (queries)
{
queries.add(query);
}
boolean hasStarted = false;
try
{
query.start();
hasStarted = true;
}
finally
{
if (!hasStarted)
{
synchronized (queries)
{
if (queries.remove(query))
queries.notify();
}
}
}
return query;
}
/**
* Removes query from the list of queries.
*
* @param query the query that will be removed.
*/
public synchronized void removeQuery(ContactQuery query)
{
if (queries.remove(query))
queries.notify();
}
/**
* Returns the Google Contacts connection.
*
@ -324,21 +331,21 @@ public int getType()
* @param query the string to search for
* @return the created query
*/
public ContactQuery createContactQuery(String query)
public ContactQuery queryContactSource(String query)
{
return createContactQuery(
return queryContactSource(
query,
GoogleContactsQuery.GOOGLECONTACTS_MAX_RESULTS);
}
/**
*Creates query for the given <tt>queryString</tt>.
* Queries this search source for the given <tt>queryString</tt>.
*
* @param query the string to search for
* @param contactCount the maximum count of result contacts
* @return the created query
*/
public ContactQuery createContactQuery(String query, int contactCount)
public ContactQuery queryContactSource(String query, int contactCount)
{
Pattern pattern = null;
try
@ -353,7 +360,7 @@ public ContactQuery createContactQuery(String query, int contactCount)
if(pattern != null)
{
return createContactQuery(pattern, contactCount);
return queryContactSource(pattern, contactCount);
}
return null;
}

@ -4143,13 +4143,11 @@ private static String resolveContactSource(String peerAddress)
// use the pattern method of (ExtendedContactSourceService)
ContactQuery query
= ((ExtendedContactSourceService)contactSourceService)
.createContactQuery(pattern);
.queryContactSource(pattern);
resolvers.add(
new ResolveAddressToDisplayNameContactQueryListener(
query));
query.start();
}
long startTime = System.currentTimeMillis();

@ -117,6 +117,24 @@ public ChatInviteContactListFilter(ContactList sourceContactList)
}
return true;
}
@Override
protected void addMatching(List<SourceContact> sourceContacts)
{
Iterator<SourceContact> contactsIter = sourceContacts.iterator();
List<SourceContact> matchedContacts = new ArrayList<SourceContact>();
while (contactsIter.hasNext())
{
SourceContact contact = contactsIter.next();
if(!opSetMUC.isPrivateMessagingContact(
contact.getContactAddress()))
{
matchedContacts.add(contact);
}
}
super.addMatching(matchedContacts);
}
}
/**

@ -46,14 +46,14 @@ public void applyFilter(FilterQuery filterQuery)
// We're in a case of call history contact source.
ContactQuery query
= contactSource.getContactSourceService()
.createContactQuery("", 50);
.queryContactSource("", 50);
query.start();
filterQuery.addContactQuery(query);
addMatching(query.getQueryResults(), contactSource);
// Add first available results.
addMatching(query.getQueryResults(),
contactSource);
// We know that this query should be finished here and we do not
// expect any further results from it.
filterQuery.removeQuery(query);
@ -98,6 +98,28 @@ public boolean isMatching(UIGroup uiGroup)
return (uiGroup instanceof NotificationGroup);
}
/**
* Adds matching <tt>sourceContacts</tt> to the result tree model.
*
* @param sourceContacts the list of <tt>SourceContact</tt>s to add
* @param uiSource the <tt>ExternalContactSource</tt>, which contacts
* we're adding
*/
private void addMatching( List<SourceContact> sourceContacts,
UIContactSource uiSource)
{
Iterator<SourceContact> contactsIter = sourceContacts.iterator();
while (contactsIter.hasNext())
{
GuiActivator.getContactList().addContact(
uiSource.createUIContact(contactsIter.next()),
uiSource.getUIGroup(),
false,
true);
}
}
/**
* Adds matching notification contacts to the result tree model.
*
@ -125,26 +147,4 @@ private void addMatching(NotificationContactSource notifSource)
}
}
}
/**
* Adds matching <tt>sourceContacts</tt> to the result tree model.
*
* @param sourceContacts the list of <tt>SourceContact</tt>s to add
* @param uiSource the <tt>ExternalContactSource</tt>, which contacts
* we're adding
*/
private void addMatching( List<SourceContact> sourceContacts,
UIContactSource uiSource)
{
Iterator<SourceContact> contactsIter = sourceContacts.iterator();
while (contactsIter.hasNext())
{
GuiActivator.getContactList().addContact(
uiSource.createUIContact(contactsIter.next()),
uiSource.getUIGroup(),
false,
true);
}
}
}

@ -86,6 +86,8 @@ public void applyFilter(FilterQuery filterQuery)
// Add this query to the filterQuery.
filterQuery.addContactQuery(query);
List<ContactQuery> contactQueryList = new ArrayList<ContactQuery>();
for(int cssType : contactSourcePreferences.keySet())
{
Iterator<UIContactSource> filterSources
@ -105,17 +107,12 @@ public void applyFilter(FilterQuery filterQuery)
ContactSourceService sourceService
= filterSource.getContactSourceService();
ContactQuery contactQuery
= sourceService.createContactQuery(null);
ContactQuery contactQuery = sourceService.queryContactSource(null);
contactQueryList.add(contactQuery);
// Add this query to the filterQuery.
filterQuery.addContactQuery(contactQuery);
contactQuery.addContactQueryListener(
GuiActivator.getContactList());
contactQuery.start();
}
}
@ -123,11 +120,21 @@ public void applyFilter(FilterQuery filterQuery)
filterQuery.close();
query.addContactQueryListener(GuiActivator.getContactList());
int resultCount = 0;
addMatching(GuiActivator.getContactListService().getRoot(),
query,
resultCount);
for(ContactQuery contactQuery : contactQueryList)
{
for(SourceContact contact : contactQuery.getQueryResults())
{
addSourceContact(contact);
}
contactQuery.addContactQueryListener(GuiActivator.getContactList());
}
query.fireQueryEvent(
query.isCanceled()
? MetaContactQueryStatusEvent.QUERY_CANCELED
@ -283,7 +290,6 @@ private void addMatching( MetaContactGroup metaGroup,
if(isMatching(metaContact))
{
resultCount++;
if (resultCount <= INITIAL_CONTACT_COUNT)
{
@ -311,36 +317,20 @@ private void addMatching( MetaContactGroup metaGroup,
UIContact newUIContact;
synchronized (metaContact)
{
newUIContact
= MetaContactListSource.getUIContact(metaContact);
if (newUIContact == null)
{
newUIContact = MetaContactListSource
.createUIContact(metaContact);
GuiActivator.getContactList().addContact(
newUIContact,
uiGroup,
true,
true);
}
newUIContact = MetaContactListSource
.createUIContact(metaContact);
}
GuiActivator.getContactList().addContact(
newUIContact,
uiGroup,
true,
true);
query.setInitialResultCount(resultCount);
}
else
{
synchronized (metaContact)
{
if (MetaContactListSource.getUIContact(metaContact)
== null)
{
query.fireQueryEvent(metaContact);
}
}
}
query.fireQueryEvent(metaContact);
}
}
@ -372,4 +362,35 @@ private void addMatching( MetaContactGroup metaGroup,
}
}
}
/**
* Adds the given <tt>sourceContact</tt> to the contact list.
* @param sourceContact the <tt>SourceContact</tt> to add
*/
private void addSourceContact(SourceContact sourceContact)
{
ContactSourceService contactSource
= sourceContact.getContactSource();
TreeContactList sourceContactList = GuiActivator.getContactList();
UIContactSource sourceUI
= sourceContactList .getContactSource(contactSource);
if (sourceUI != null
// ExtendedContactSourceService has already matched the
// SourceContact over the pattern
&& (contactSource instanceof ExtendedContactSourceService)
|| isMatching(sourceContact))
{
boolean isSorted = (sourceContact.getIndex() > -1) ? true : false;
sourceContactList.addContact(
sourceUI.createUIContact(sourceContact),
sourceUI.getUIGroup(),
isSorted,
true);
}
else
sourceUI.removeUIContact(sourceContact);
}
}

@ -104,14 +104,13 @@ public void applyFilter(FilterQuery filterQuery)
if (sourceContactList.getDefaultFilter()
.equals(TreeContactList.presenceFilter))
{
final MetaContactQuery defaultQuery = new MetaContactQuery();
MetaContactQuery defaultQuery
= mclSource.queryMetaContactSource(filterPattern);
defaultQuery.addContactQueryListener(sourceContactList);
// First add the MetaContactListSource
filterQuery.addContactQuery(defaultQuery);
mclSource.startQuery(defaultQuery, filterPattern);
}
else if (sourceContactList.getDefaultFilter()
.equals(TreeContactList.historyFilter))
@ -156,7 +155,10 @@ else if (sourceContactList.getDefaultFilter()
if (filterQuery.isCanceled())
return;
applyFilter(filterSource, filterQuery);
ContactQuery query = applyFilter(filterSource);
if (query.getStatus() == ContactQuery.QUERY_IN_PROGRESS)
filterQuery.addContactQuery(query);
}
// Closes this filter to indicate that we finished adding queries to it.
@ -171,11 +173,9 @@ else if (!sourceContactList.isEmpty())
*
* @param contactSource the <tt>ExternalContactSource</tt> to apply the
* filter to
* @param filterQuery the filter query object.
* @return the <tt>ContactQuery</tt> that tracks this filter
*/
protected ContactQuery applyFilter(UIContactSource contactSource,
FilterQuery filterQuery)
protected ContactQuery applyFilter(UIContactSource contactSource)
{
ContactSourceService sourceService
= contactSource.getContactSourceService();
@ -184,19 +184,15 @@ protected ContactQuery applyFilter(UIContactSource contactSource,
if (sourceService instanceof ExtendedContactSourceService)
contactQuery
= ((ExtendedContactSourceService) sourceService)
.createContactQuery(filterPattern);
.queryContactSource(filterPattern);
else
contactQuery = sourceService.createContactQuery(filterString);
contactQuery = sourceService.queryContactSource(filterString);
// Add first available results.
this.addMatching(contactQuery.getQueryResults());
contactQuery.addContactQueryListener(sourceContactList);
if (contactQuery.getStatus() == ContactQuery.QUERY_IN_PROGRESS)
{
filterQuery.addContactQuery(contactQuery);
}
contactQuery.start();
return contactQuery;
}
@ -256,6 +252,19 @@ public void setFilterString(String filter)
| Pattern.UNICODE_CASE);
}
/**
* Checks if the given <tt>contact</tt> is matching the current filter.
* A <tt>SourceContact</tt> would be matching the filter if its display
* name is matching the search string.
* @param contact the <tt>ContactListContactDescriptor</tt> to check
* @return <tt>true</tt> to indicate that the given <tt>contact</tt> is
* matching the current filter, otherwise returns <tt>false</tt>
*/
private boolean isMatching(SourceContact contact)
{
return isMatching(contact.getDisplayName());
}
/**
* Indicates if the given string matches this filter.
* @param text the text to check
@ -269,4 +278,46 @@ private boolean isMatching(String text)
return true;
}
/**
* Adds the list of <tt>sourceContacts</tt> to the contact list.
* @param sourceContacts the list of <tt>SourceContact</tt>s to add
*/
protected void addMatching(List<SourceContact> sourceContacts)
{
Iterator<SourceContact> contactsIter = sourceContacts.iterator();
while (contactsIter.hasNext())
addSourceContact(contactsIter.next());
}
/**
* Adds the given <tt>sourceContact</tt> to the contact list.
* @param sourceContact the <tt>SourceContact</tt> to add
*/
private void addSourceContact(SourceContact sourceContact)
{
ContactSourceService contactSource
= sourceContact.getContactSource();
UIContactSource sourceUI
= sourceContactList.getContactSource(contactSource);
if (sourceUI != null
// ExtendedContactSourceService has already matched the
// SourceContact over the pattern
&& (contactSource instanceof ExtendedContactSourceService)
|| isMatching(sourceContact))
{
boolean isSorted = (sourceContact.getIndex() > -1) ? true : false;
sourceContactList.addContact(
sourceUI.createUIContact(sourceContact),
sourceUI.getUIGroup(),
isSorted,
true);
}
else
sourceUI.removeUIContact(sourceContact);
}
}

@ -324,6 +324,7 @@ public void metaContactReceived(MetaContactQueryEvent event)
{
MetaContact metaContact = event.getMetaContact();
MetaContactGroup parentGroup = metaContact.getParentMetaContactGroup();
UIGroup uiGroup = MetaContactListSource
.getUIGroup(parentGroup);
if (!MetaContactListSource.isRootGroup(parentGroup))
@ -569,34 +570,23 @@ private void createMetaUIRootGroup()
{
MetaContactGroup rootGroup
= GuiActivator.getContactListService().getRoot();
UIGroup uiGroup;
synchronized (rootGroup)
{
uiGroup = MetaContactListSource
.getUIGroup(rootGroup);
UIGroup uiGroup = MetaContactListSource
.getUIGroup(rootGroup);
if (uiGroup != null)
return;
if (uiGroup == null)
uiGroup = MetaContactListSource
.createUIGroup(rootGroup);
}
treeModel.getRoot().sortedAddContactGroup((UIGroupImpl)uiGroup);
Iterator<MetaContact> i = rootGroup.getChildContacts();
while (i.hasNext())
{
MetaContact contact = i.next();
UIContact uiContact;
synchronized (contact)
{
uiContact
= MetaContactListSource.getUIContact(contact);
if(uiContact == null)
continue;
removeContact(uiContact);
uiContact = MetaContactListSource.createUIContact(contact);
}
UIContact uiContact
= MetaContactListSource.getUIContact(contact);
removeContact(uiContact);
uiContact = MetaContactListSource.createUIContact(contact);
if (currentFilter.isMatching(uiContact))
addContact(uiContact, uiGroup, true, true);
else
@ -611,16 +601,11 @@ private void removeMetaUIRootGroup()
{
MetaContactGroup rootGroup
= GuiActivator.getContactListService().getRoot();
UIGroup uiGroup;
synchronized (rootGroup)
{
uiGroup = MetaContactListSource
.getUIGroup(rootGroup);
UIGroup uiGroup = MetaContactListSource
.getUIGroup(rootGroup);
if (uiGroup == null)
return;
}
if (uiGroup == null)
return;
GroupNode parentNode = treeModel.getRoot();
@ -628,16 +613,10 @@ private void removeMetaUIRootGroup()
while (i.hasNext())
{
MetaContact contact = i.next();
UIContact uiContact;
synchronized (contact)
{
uiContact
= MetaContactListSource.getUIContact(contact);
if(uiContact == null)
continue;
removeContact(uiContact);
uiContact = MetaContactListSource.createUIContact(contact);
}
UIContact uiContact
= MetaContactListSource.getUIContact(contact);
removeContact(uiContact);
uiContact = MetaContactListSource.createUIContact(contact);
if (currentFilter.isMatching(uiContact))
addContact(uiContact, treeModel.getRoot().getGroupDescriptor(),
true, true);
@ -1957,7 +1936,12 @@ public void setSourceContactImage( String contactString,
if (contactSource instanceof ExtendedContactSourceService)
{
ContactQueryListener queryListener = new ContactQueryListener()
ContactQuery query = ((ExtendedContactSourceService)
contactSource).queryContactSource(filterPattern);
loadedQueries.add(query);
query.addContactQueryListener(new ContactQueryListener()
{
public void queryStatusChanged(ContactQueryStatusEvent event)
{}
@ -2042,14 +2026,7 @@ public void contactChanged(ContactChangedEvent event)
if (contactNode != null)
nodeChanged(contactNode);
}
};
ContactQuery query = ((ExtendedContactSourceService)
contactSource).createContactQuery(filterPattern);
loadedQueries.add(query);
query.start();
});
// If the image search has been canceled from one of the
// previous sources, we return here.

@ -114,6 +114,12 @@ public void addContactQuery(Object contactQuery)
{
ContactQuery externalQuery = (ContactQuery) contactQuery;
List<SourceContact> externalResults
= externalQuery.getQueryResults();
if (externalResults != null && externalResults.size() > 0)
queryResults = new ArrayList<SourceContact>(externalResults);
externalQuery.addContactQueryListener(this);
}
else if (contactQuery instanceof MetaContactQuery)

@ -185,14 +185,17 @@ public static boolean isRootGroup(MetaContactGroup group)
}
/**
* Starts the query.
*
* Filters the <tt>MetaContactListService</tt> to match the given
* <tt>filterPattern</tt> and stores the result in the given
* <tt>treeModel</tt>.
* @param filterPattern the pattern to filter through
* @param query the query to be started
* @return the created <tt>MetaContactQuery</tt> corresponding to the
* query this method does
*/
public void startQuery(final MetaContactQuery query,
final Pattern filterPattern)
public MetaContactQuery queryMetaContactSource(final Pattern filterPattern)
{
final MetaContactQuery query = new MetaContactQuery();
new Thread()
{
@Override
@ -212,6 +215,8 @@ public void run()
MetaContactQueryStatusEvent.QUERY_CANCELED);
}
}.start();
return query;
}
/**
@ -258,40 +263,22 @@ public void queryMetaContactSource(Pattern filterPattern,
}
UIContact newUIContact;
boolean uiContactCreated = false;
synchronized (metaContact)
{
newUIContact
= MetaContactListSource.getUIContact(metaContact);
if (newUIContact == null)
{
newUIContact
= MetaContactListSource
.createUIContact(metaContact);
GuiActivator.getContactList().addContact(
newUIContact,
uiGroup,
true,
true);
}
newUIContact
= MetaContactListSource.createUIContact(metaContact);
}
GuiActivator.getContactList().addContact(
newUIContact,
uiGroup,
true,
true);
query.setInitialResultCount(resultCount);
}
else
{
synchronized (metaContact)
{
if (MetaContactListSource.getUIContact(metaContact)
== null)
{
query.fireQueryEvent(metaContact);
}
}
}
query.fireQueryEvent(metaContact);
}
}

@ -83,24 +83,24 @@ public String getDisplayName()
}
/**
* Creates query for the given <tt>searchPattern</tt>.
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @return the created query
*/
public ContactQuery createContactQuery(String queryString)
public ContactQuery queryContactSource(String queryString)
{
return createContactQuery(queryString, -1);
return queryContactSource(queryString, -1);
}
/**
* Creates query for the given <tt>searchPattern</tt>.
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @param contactCount the maximum count of result contacts
* @return the created query
*/
public ContactQuery createContactQuery( String queryString,
public ContactQuery queryContactSource( String queryString,
int contactCount)
{
if (queryString == null)
@ -108,24 +108,32 @@ public ContactQuery createContactQuery( String queryString,
ProtocolCQuery contactQuery
= new ProtocolCQuery(queryString, contactCount);
synchronized (queries)
{
queries.add(contactQuery);
}
boolean queryHasStarted = false;
try
{
contactQuery.start();
queryHasStarted = true;
}
finally
{
if (!queryHasStarted)
{
synchronized (queries)
{
if (queries.remove(contactQuery))
queries.notify();
}
}
}
return contactQuery;
}
/**
* Removes query from the list.
* @param contactQuery the query
*/
public synchronized void removeQuery(ContactQuery contactQuery)
{
if (queries.remove(contactQuery))
queries.notify();
}
/**
* The <tt>ProtocolCQuery</tt> performing the query for this contact source.
@ -192,26 +200,6 @@ public void run()
setStatus(QUERY_COMPLETED);
}
@Override
public synchronized void start()
{
boolean queryHasStarted = false;
try
{
super.start();
queryHasStarted = true;
}
finally
{
if (!queryHasStarted)
{
getContactSource().removeQuery(this);
}
}
}
/**
* Adds the result for the given group.
*

@ -69,24 +69,24 @@ public String getDisplayName()
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @return the created query
*/
public ContactQuery createContactQuery(String queryString)
public ContactQuery queryContactSource(String queryString)
{
return createContactQuery(queryString, -1);
return queryContactSource(queryString, -1);
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @param contactCount the maximum count of result contacts
* @return the created query
*/
public ContactQuery createContactQuery( String queryString,
public ContactQuery queryContactSource( String queryString,
int contactCount)
{
return new StringQuery(queryString);
@ -120,6 +120,10 @@ public StringQuery(String queryString)
this.queryString = queryString;
this.results = new ArrayList<SourceContact>();
results.add(getSourceContact());
if (getStatus() != QUERY_CANCELED)
setStatus(QUERY_COMPLETED);
}
/**
@ -142,16 +146,6 @@ public List<SourceContact> getQueryResults()
return results;
}
@Override
public void start()
{
SourceContact contact = getSourceContact();
results.add(contact);
fireContactReceived(contact);
if (getStatus() != QUERY_CANCELED)
setStatus(QUERY_COMPLETED);
}
/**
* Returns the source contact corresponding to the query string.
*

@ -69,7 +69,10 @@ public void applyFilter(FilterQuery filterQuery)
if (filterQuery.isCanceled())
return;
applyFilter(filterSource, filterQuery);
ContactQuery query = applyFilter(filterSource);
if (query.getStatus() == ContactQuery.QUERY_IN_PROGRESS)
filterQuery.addContactQuery(query);
}
// Closes this filter to indicate that we finished adding queries to it.

@ -123,24 +123,6 @@ public void ldapEventReceived(LdapEvent evt)
}
}
@Override
public synchronized void start()
{
boolean hasStarted = false;
try
{
super.start();
hasStarted = true;
}
finally
{
if (!hasStarted)
{
getContactSource().removeQuery(this);
}
}
}
/**
* Gets the <tt>contactDetails</tt> to be set on a <tt>SourceContact</tt>.
*

@ -49,47 +49,56 @@ public LdapContactSourceService(LdapDirectory ldapDirectory)
}
/**
* Creates query for the given <tt>searchPattern</tt>.
* Queries this search source for the given <tt>searchPattern</tt>.
*
* @param queryPattern the pattern to search for
* @return the created query
*/
public ContactQuery createContactQuery(Pattern queryPattern)
public ContactQuery queryContactSource(Pattern queryPattern)
{
return createContactQuery(queryPattern,
return queryContactSource(queryPattern,
LdapContactQuery.LDAP_MAX_RESULTS);
}
/**
* Creates query for the given <tt>searchPattern</tt>.
* Queries this search source for the given <tt>searchPattern</tt>.
*
* @param queryPattern the pattern to search for
* @param count maximum number of contact returned
* @return the created query
*/
public ContactQuery createContactQuery(Pattern queryPattern, int count)
public ContactQuery queryContactSource(Pattern queryPattern, int count)
{
LdapContactQuery query = new LdapContactQuery(this, queryPattern,
count);
synchronized (queries)
{
queries.add(query);
}
boolean hasStarted = false;
try
{
query.start();
hasStarted = true;
}
finally
{
if (!hasStarted)
{
synchronized (queries)
{
if (queries.remove(query))
queries.notify();
}
}
}
return query;
}
/**
* Removes a query from the list.
* @param query the query
*/
public synchronized void removeQuery(ContactQuery query)
{
if (queries.remove(query))
queries.notify();
}
/**
* Returns a user-friendly string that identifies this contact source.
* @return the display name of this contact source
@ -111,25 +120,23 @@ public int getType()
}
/**
* Creates query for the given <tt>query</tt>.
* Queries this search source for the given <tt>queryString</tt>.
* @param query the string to search for
* @param listener the listener that receives the found contacts.
* @return the created query
*/
public ContactQuery createContactQuery(String query)
public ContactQuery queryContactSource(String query)
{
return createContactQuery(query, LdapContactQuery.LDAP_MAX_RESULTS);
return queryContactSource(query, LdapContactQuery.LDAP_MAX_RESULTS);
}
/**
* Creates query for the given <tt>query</tt>.
* Queries this search source for the given <tt>queryString</tt>.
*
* @param query the string to search for
* @param contactCount the maximum count of result contacts
* @param listener the listener that receives the found contacts.
* @return the created query
*/
public ContactQuery createContactQuery(String query, int contactCount)
public ContactQuery queryContactSource(String query, int contactCount)
{
Pattern pattern = null;
try
@ -143,7 +150,7 @@ public ContactQuery createContactQuery(String query, int contactCount)
if(pattern != null)
{
return createContactQuery(pattern, contactCount);
return queryContactSource(pattern, contactCount);
}
return null;
}

@ -37,32 +37,35 @@ public String getDisplayName()
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this contact source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @return the created query
*/
@Override
public ContactQuery createContactQuery(String queryString)
public ContactQuery queryContactSource(String queryString)
{
return createContactQuery(queryString, -1);
return queryContactSource(queryString, -1);
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this contact source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @param contactCount the maximum count of result contacts
* @return the created query
*/
@Override
public ContactQuery createContactQuery(String queryString, int contactCount)
public ContactQuery queryContactSource(String queryString, int contactCount)
{
if (queryString == null)
queryString = "";
ChatRoomQuery contactQuery
= new ChatRoomQuery(queryString, this);
contactQuery.start();
return contactQuery;
}

@ -44,32 +44,36 @@ public String getDisplayName()
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this contact source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @return the created query
*/
@Override
public ContactQuery createContactQuery(String queryString)
public ContactQuery queryContactSource(String queryString)
{
return createContactQuery(queryString, -1);
return queryContactSource(queryString, -1);
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this contact source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @param contactCount the maximum count of result contacts
* @return the created query
*/
@Override
public ContactQuery createContactQuery(String queryString, int contactCount)
public ContactQuery queryContactSource(String queryString, int contactCount)
{
if (queryString == null)
queryString = "";
ServerChatRoomQuery contactQuery
= new ServerChatRoomQuery(queryString, this, provider);
contactQuery.start();
return contactQuery;
}

@ -11,6 +11,7 @@
import net.java.sip.communicator.service.contactsource.*;
import net.java.sip.communicator.service.muc.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.util.Logger;
/**
* The <tt>ServerChatRoomQuery</tt> is a query over the

@ -91,7 +91,7 @@ public int getType()
}
/**
* Creates query that searches for <tt>SourceContact</tt>s
* Queries this <tt>ContactSourceService</tt> for <tt>SourceContact</tt>s
* which match a specific <tt>query</tt> <tt>Pattern</tt>.
*
* @param query the <tt>Pattern</tt> which this
@ -102,13 +102,14 @@ public int getType()
* any) will be returned
* @see ExtendedContactSourceService#queryContactSource(Pattern)
*/
public ContactQuery createContactQuery(Pattern query)
public ContactQuery queryContactSource(Pattern query)
{
if(latestQuery != null)
latestQuery.clear();
latestQuery = new MacOSXAddrBookContactQuery(this, query);
latestQuery.start();
return latestQuery;
}

@ -161,7 +161,7 @@ private static native void MAPIInitialize(
public static native int getOutlookVersion();
/**
* Creates query that searches for <tt>SourceContact</tt>s
* Queries this <tt>ContactSourceService</tt> for <tt>SourceContact</tt>s
* which match a specific <tt>query</tt> <tt>Pattern</tt>.
*
* @param query the <tt>Pattern</tt> which this
@ -172,13 +172,14 @@ private static native void MAPIInitialize(
* any) will be returned
* @see ExtendedContactSourceService#queryContactSource(Pattern)
*/
public ContactQuery createContactQuery(Pattern query)
public ContactQuery queryContactSource(Pattern query)
{
if(latestQuery != null)
latestQuery.clear();
latestQuery = new MsOutlookAddrBookContactQuery(this, query);
latestQuery.start();
return latestQuery;
}

@ -94,12 +94,12 @@ public String getDisplayName()
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @return the created query
*/
public ContactQuery createContactQuery(String queryString)
public ContactQuery queryContactSource(String queryString)
{
if (logger.isDebugEnabled())
logger.debug("Demux query contact source: " + contactSource
@ -112,7 +112,7 @@ public ContactQuery createContactQuery(String queryString)
{
return new DemuxContactQuery(
((ExtendedContactSourceService) contactSource)
.createContactQuery(Pattern.compile(
.queryContactSource(Pattern.compile(
Pattern.quote(queryString),
Pattern.MULTILINE
| Pattern.CASE_INSENSITIVE
@ -120,20 +120,20 @@ public ContactQuery createContactQuery(String queryString)
}
else
return new DemuxContactQuery(
contactSource.createContactQuery(queryString));
contactSource.queryContactSource(queryString));
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @param contactCount the maximum count of result contacts
* @return the created query
*/
public ContactQuery createContactQuery(String queryString, int contactCount)
public ContactQuery queryContactSource(String queryString, int contactCount)
{
return new DemuxContactQuery(
contactSource.createContactQuery(queryString, contactCount));
contactSource.queryContactSource(queryString, contactCount));
}
/**
@ -175,6 +175,8 @@ public DemuxContactQuery(ContactQuery sourceQuery)
this.sourceQuery = sourceQuery;
initQueryResults();
sourceQuery.addContactQueryListener(this);
}
@ -202,6 +204,42 @@ public String getQueryString()
return sourceQuery.getQueryString();
}
/**
* Initializes the query results.
*/
public void initQueryResults()
{
List<SourceContact> sourceContacts = sourceQuery.getQueryResults();
if (sourceContacts == null)
return;
Iterator<SourceContact> contactIter = sourceContacts.iterator();
while (contactIter.hasNext())
{
SourceContact sourceContact = contactIter.next();
Iterator<ContactDetail> detailsIter
= sourceContact.getContactDetails().iterator();
while (detailsIter.hasNext())
{
ContactDetail detail = detailsIter.next();
if (preferredProtocolProviders == null
|| isPreferredContactDetail(detail))
{
SortedGenericSourceContact
demuxContact
= (SortedGenericSourceContact)
createSourceContact(sourceContact,
detail);
addContact(demuxContact);
}
}
}
}
/**
* Returns the list of <tt>SourceContact</tt>s returned by this query.
*
@ -220,12 +258,6 @@ public void cancel()
{
sourceQuery.cancel();
}
@Override
public void start()
{
sourceQuery.start();
}
/**
* Returns the status of this query. One of the static constants

@ -41,26 +41,24 @@ public String getDisplayName()
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this contact source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @param listener the listener that receives the found contacts.
* @return the created query
*/
public ContactQuery createContactQuery(String queryString)
public ContactQuery queryContactSource(String queryString)
{
return createContactQuery(queryString, -1);
return queryContactSource(queryString, -1);
}
/**
* Creates query for the given <tt>queryString</tt>.
* Queries this contact source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @param contactCount the maximum count of result contacts
* @param listener the listener that receives the found contacts.
* @return the created query
*/
public ContactQuery createContactQuery( String queryString,
public ContactQuery queryContactSource( String queryString,
int contactCount)
{
if (queryString == null)
@ -69,6 +67,7 @@ public ContactQuery createContactQuery( String queryString,
PhoneNumberContactQuery contactQuery
= new PhoneNumberContactQuery(this, queryString, contactCount);
contactQuery.start();
return contactQuery;
}

@ -141,7 +141,7 @@ public String getDisplayName()
* @see net.java.sip.communicator.service.contactsource
* .ContactSourceService#queryContactSource(java.lang.String)
*/
public ContactQuery createContactQuery(String queryString)
public ContactQuery queryContactSource(String queryString)
{
Pattern pattern = null;
try
@ -157,7 +157,7 @@ public ContactQuery createContactQuery(String queryString)
if(pattern != null)
{
return createContactQuery(pattern);
return queryContactSource(pattern);
}
return null;
}
@ -169,11 +169,11 @@ public ContactQuery createContactQuery(String queryString)
* net.java.sip.communicator.service.contactsource.ContactSourceService#
* queryContactSource(java.lang.String, int)
*/
public ContactQuery createContactQuery(String queryString, int contactCount)
public ContactQuery queryContactSource(String queryString, int contactCount)
{
// XXX: The ThunderbirdContactQuery does not tqke a contactCount
// argument yet. Thus, call the default queryContactSource function.
return createContactQuery(queryString);
return queryContactSource(queryString);
}
/*
@ -183,12 +183,9 @@ public ContactQuery createContactQuery(String queryString, int contactCount)
* net.java.sip.communicator.service.contactsource.ExtendedContactSourceService
* #queryContactSource(java.util.regex.Pattern)
*/
public ContactQuery createContactQuery(Pattern queryPattern)
public ContactQuery queryContactSource(Pattern queryPattern)
{
ThunderbirdContactQuery query
= new ThunderbirdContactQuery(this, queryPattern);
return query;
return new ThunderbirdContactQuery(this, queryPattern);
}
/*

@ -18,26 +18,25 @@ public abstract class AsyncContactSourceService
implements ExtendedContactSourceService
{
/**
* Creates query that searches for <tt>SourceContact</tt>s
* Queries this <tt>ContactSourceService</tt> for <tt>SourceContact</tt>s
* which match a specific <tt>query</tt> <tt>String</tt>.
*
* @param query the <tt>String</tt> which this <tt>ContactSourceService</tt>
* is being queried for
* @param listener the listener that receives the found contacts.
* @return a <tt>ContactQuery</tt> which represents the query of this
* <tt>ContactSourceService</tt> implementation for the specified
* <tt>String</tt> and via which the matching <tt>SourceContact</tt>s (if
* any) will be returned
* @see ContactSourceService#queryContactSource(String)
*/
public ContactQuery createContactQuery(String query)
public ContactQuery queryContactSource(String query)
{
return createContactQuery(
return queryContactSource(
Pattern.compile(query, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
}
/**
* Creates query that searches for <tt>SourceContact</tt>s
* Queries this <tt>ContactSourceService</tt> for <tt>SourceContact</tt>s
* which match a specific <tt>query</tt> <tt>String</tt>.
*
* @param query the <tt>String</tt> which this <tt>ContactSourceService</tt>
@ -49,9 +48,9 @@ public ContactQuery createContactQuery(String query)
* any) will be returned
* @see ContactSourceService#queryContactSource(String)
*/
public ContactQuery createContactQuery(String query, int contactCount)
public ContactQuery queryContactSource(String query, int contactCount)
{
return createContactQuery(
return queryContactSource(
Pattern.compile(query, Pattern.CASE_INSENSITIVE | Pattern.LITERAL));
}

@ -57,11 +57,6 @@ public interface ContactQuery
* @return the list of <tt>SourceContact</tt>s returned by this query
*/
public List<SourceContact> getQueryResults();
/**
* Starts the query.
*/
public void start();
/**
* Cancels this query.

@ -48,25 +48,24 @@ public interface ContactSourceService
* @return the display name of this contact source
*/
public String getDisplayName();
/**
* Creates and returns new <tt>ContactQuery</tt> instance.
*
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
*
* @return new <tt>ContactQuery</tt> instance.
* @return the created query
*/
public ContactQuery createContactQuery(String queryString);
public ContactQuery queryContactSource(String queryString);
/**
* Creates and returns new <tt>ContactQuery</tt> instance.
*
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @param contactCount the maximum count of result contacts
* @return new <tt>ContactQuery</tt> instance.
* @return the created query
*/
public ContactQuery createContactQuery(String queryString,
int contactCount);
public ContactQuery queryContactSource(String queryString,
int contactCount);
/**
* Returns the index of the contact source in the result list.

@ -29,11 +29,11 @@ public interface ExtendedContactSourceService
extends ContactSourceService
{
/**
* Creates query for the given <tt>searchPattern</tt>.
* Queries this search source for the given <tt>searchPattern</tt>.
* @param queryPattern the pattern to search for
* @return the created query
*/
public ContactQuery createContactQuery(Pattern queryPattern);
public ContactQuery queryContactSource(Pattern queryPattern);
/**
* Returns the global phone number prefix to be used when calling contacts

Loading…
Cancel
Save