Provides a sorted result in all invite and transfer windows, including call transfer, create a conference call, invite to call, etc.

cusax-fix
Yana Stamcheva 13 years ago
parent 162235665f
commit 1826ac329b

@ -367,4 +367,14 @@ public PresenceStatus getPresenceStatus()
{
return null;
}
/**
* Returns the index of this source contact in its parent.
*
* @return the index of this source contact in its parent
*/
public int getIndex()
{
return -1;
}
}

@ -277,10 +277,12 @@ private void addSourceContact(SourceContact sourceContact)
&& (contactSource instanceof ExtendedContactSourceService)
|| isMatching(sourceContact))
{
boolean isSorted = (sourceContact.getIndex() > -1) ? true : false;
sourceContactList.addContact(
sourceUI.createUIContact(sourceContact),
sourceUI.getUIGroup(),
false,
isSorted,
true);
}
else

@ -204,9 +204,11 @@ public void contactReceived(ContactReceivedEvent event)
if((contactSource instanceof ExtendedContactSourceService)
|| currentFilter.isMatching(uiContact))
{
boolean isSorted = (sourceContact.getIndex() > -1) ? true : false;
addContact(event.getQuerySource(),
uiContact,
sourceUI.getUIGroup(), false);
sourceUI.getUIGroup(), isSorted);
}
else
{

@ -22,10 +22,20 @@
public class ProtocolContactSourceServiceImpl
implements ContactSourceService
{
/**
* The protocol provider, providing the contacts.
*/
private final ProtocolProviderService protocolProvider;
/**
* The operation set class, we use to filter the capabilities of the
* contacts.
*/
private final Class<? extends OperationSet> opSetClass;
/**
* The <tt>MetaContactListService</tt>, providing the meta contact list.
*/
MetaContactListService metaContactListService
= GuiActivator.getContactListService();
@ -51,22 +61,45 @@ public ProtocolContactSourceServiceImpl(
this.opSetClass = opSetClass;
}
/**
* Returns the type of this contact source.
*
* @return the type of this contact source
*/
public int getType()
{
return DEFAULT_TYPE;
}
/**
* Returns a user-friendly string that identifies this contact source.
*
* @return the display name of this contact source
*/
public String getDisplayName()
{
return GuiActivator.getResources().getI18NString("service.gui.CONTACTS")
+ " " + protocolProvider.getAccountID().getDisplayName();
}
/**
* Queries this search source for the given <tt>queryString</tt>.
*
* @param queryString the string to search for
* @return the created query
*/
public ContactQuery queryContactSource(String queryString)
{
return queryContactSource(queryString, -1);
}
/**
* 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 queryContactSource( String queryString,
int contactCount)
{
@ -102,18 +135,34 @@ public ContactQuery queryContactSource( String queryString,
return contactQuery;
}
/**
* The <tt>ProtocolCQuery</tt> performing the query for this contact source.
*/
private class ProtocolCQuery
extends AsyncContactQuery<ProtocolContactSourceServiceImpl>
{
/**
* The maximum number of contacts to return as result.
*/
private int contactCount;
/**
* The query string used for filtering the results.
*/
private final String queryString;
/**
* Creates an instance of <tt>ProtocolCQuery</tt>.
*
* @param queryString the query string
* @param contactCount the maximum number of contacts to return as
* result
*/
public ProtocolCQuery(String queryString, int contactCount)
{
super(ProtocolContactSourceServiceImpl.this,
Pattern.compile(queryString, Pattern.CASE_INSENSITIVE
| Pattern.LITERAL));
| Pattern.LITERAL), true);
this.queryString = queryString;
this.contactCount = contactCount;
@ -153,7 +202,8 @@ public void run()
/**
* Adds the result for the given group.
*
* @param group the group
* @param metaContact the metaContact, which child protocol contacts
* we'll be adding to the result
*/
private void addResultContact(MetaContact metaContact)
{
@ -191,8 +241,9 @@ private void addResultContact(MetaContact metaContact)
contactDetails.add(contactDetail);
GenericSourceContact sourceContact
= new GenericSourceContact(
SortedGenericSourceContact sourceContact
= new SortedGenericSourceContact(
this,
ProtocolContactSourceServiceImpl.this,
contactDisplayName,
contactDetails);

@ -111,7 +111,7 @@ public void setParentGroup(UIGroup parentGroup) {}
*/
public int getSourceIndex()
{
return -1;
return sourceContact.getIndex();
}
/**

@ -375,4 +375,14 @@ public void setDetails(List<ContactDetail> details)
contactDetails.addAll(details);
}
}
/**
* Returns the index of this source contact in its parent.
*
* @return the index of this source contact in its parent
*/
public int getIndex()
{
return -1;
}
}

@ -183,4 +183,14 @@ public void addContactDetail(ContactDetail detail)
this.save();
}
}
/**
* Returns the index of this source contact in its parent.
*
* @return the index of this source contact in its parent
*/
public int getIndex()
{
return -1;
}
}

@ -47,7 +47,7 @@ public PhoneNumberContactQuery( PhoneNumberContactSource contactSource,
{
super(contactSource,
Pattern.compile(queryString, Pattern.CASE_INSENSITIVE
| Pattern.LITERAL));
| Pattern.LITERAL), true);
this.queryString = queryString;
this.contactCount = contactCount;
@ -207,6 +207,7 @@ else if(d instanceof VideoDetail)
PhoneNumberSourceContact numberSourceContact
= new PhoneNumberSourceContact(
this,
getContactSource(),
contact,
contactDetails,

@ -19,7 +19,7 @@
* @author Yana Stamcheva
*/
public class PhoneNumberSourceContact
extends GenericSourceContact
extends SortedGenericSourceContact
{
/**
* The display details of this contact.
@ -29,17 +29,21 @@ public class PhoneNumberSourceContact
/**
* Creates an instance of <tt>PhoneNumberSourceContact</tt>.
*
* @param parentQuery the parent contact query
* @param contactSource the parent contact source
* @param contact the protocol contact corresponding to this source contact
* information about the phone number corresponding to this source contact
* @param contactDetails the list of <tt>ContactDetail</tt>-s
* @param detailDisplayName the display name of the phone number detail
*/
public PhoneNumberSourceContact(PhoneNumberContactSource contactSource,
public PhoneNumberSourceContact(ContactQuery parentQuery,
PhoneNumberContactSource contactSource,
Contact contact,
List<ContactDetail> contactDetails,
String detailDisplayName)
{
super( contactSource,
super( parentQuery,
contactSource,
contact.getDisplayName(),
contactDetails);

@ -45,7 +45,7 @@ public abstract class AsyncContactQuery<T extends ContactSourceService>
/**
* The <tt>SourceContact</tt>s which match {@link #query}.
*/
private final List<SourceContact> queryResults
private Collection<SourceContact> queryResults
= new LinkedList<SourceContact>();
/**
@ -54,6 +54,28 @@ public abstract class AsyncContactQuery<T extends ContactSourceService>
*/
private Thread thread;
/**
* Initializes a new <tt>AsyncContactQuery</tt> instance which is to perform
* a specific <tt>query</tt> on behalf of a specific <tt>contactSource</tt>.
*
* @param contactSource the <tt>ContactSourceService</tt> which is to
* perform the new <tt>ContactQuery</tt> instance
* @param query the <tt>Pattern</tt> for which <tt>contactSource</tt> is
* being queried
* @param isSorted indicates if the results of this query should be sorted
*/
protected AsyncContactQuery(T contactSource,
Pattern query,
boolean isSorted)
{
super(contactSource);
this.query = query;
if (isSorted)
queryResults = new TreeSet<SourceContact>();
}
/**
* Initializes a new <tt>AsyncContactQuery</tt> instance which is to perform
* a specific <tt>query</tt> on behalf of a specific <tt>contactSource</tt>.

@ -246,4 +246,14 @@ public void setPresenceStatus(PresenceStatus presenceStatus)
{
this.presenceStatus = presenceStatus;
}
/**
* Returns the index of this source contact in its parent.
*
* @return the index of this source contact in its parent
*/
public int getIndex()
{
return -1;
}
}

@ -0,0 +1,113 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.contactsource;
import java.util.*;
/**
* The <tt>ProtocolSourceContact</tt> provides a sorted
* <tt>GenericSourceContact</tt>. <tt>SourceContact</tt>-s are sorted
* alphabetically and based on their presence status.
*/
public class SortedGenericSourceContact
extends GenericSourceContact
implements Comparable<SourceContact>
{
/**
* The parent contact query.
*/
private final ContactQuery parentQuery;
/**
* Creates an instance of <tt>ProtocolSourceContact</tt>.
*
* @param parentQuery the parent <tt>ContactQuery</tt>, which generated
* this result contact
* @param cSourceService the parent <tt>ContactSourceService</tt>, of
* which this source contact is part
* @param displayName the display name of the contact
* @param contactDetails the list of contact details
*/
public SortedGenericSourceContact( ContactQuery parentQuery,
ContactSourceService cSourceService,
String displayName,
List<ContactDetail> contactDetails)
{
super( cSourceService,
displayName,
contactDetails);
this.parentQuery = parentQuery;
}
/**
* Compares this contact with the specified object for order. Returns
* a negative integer, zero, or a positive integer as this contact is
* less than, equal to, or greater than the specified object.
* <p>
* The result of this method is calculated the following way:
* <p>
* ( (10 - isOnline) - (10 - targetIsOnline)) * 100000000 <br>
+ getDisplayName()
.compareToIgnoreCase(target.getDisplayName()) * 10000 <br>
+ compareDDetails * 1000 <br>
+ String.valueOf(hashCode())
.compareToIgnoreCase(String.valueOf(o.hashCode()))
* <p>
* Or in other words ordering of source contacts would be first done by
* presence status, then display name, then display details and finally
* (in order to avoid equalities) be the hashCode of the object.
* <p>
* @param o the <code>SourceContact</code> to be compared.
* @return a negative integer, zero, or a positive integer as this
* object is less than, equal to, or greater than the specified object.
*/
public int compareTo(SourceContact o)
{
SourceContact target = (SourceContact) o;
int comparePresence = 0;
if (getPresenceStatus() != null && target.getPresenceStatus() != null)
{
int isOnline
= (getPresenceStatus().isOnline())
? 1
: 0;
int targetIsOnline
= (target.getPresenceStatus().isOnline())
? 1
: 0;
comparePresence = ( (10 - isOnline) - (10 - targetIsOnline));
}
int compareDDetails = 0;
if (getDisplayDetails() != null && target.getDisplayDetails() != null)
{
compareDDetails
= getDisplayDetails()
.compareToIgnoreCase(target.getDisplayDetails());
}
return comparePresence * 100000000
+ getDisplayName()
.compareToIgnoreCase(target.getDisplayName()) * 10000
+ compareDDetails * 100
+ String.valueOf(hashCode())
.compareToIgnoreCase(String.valueOf(o.hashCode()));
}
/**
* Returns the index of this source contact in its parent group.
*
* @return the index of this contact in its parent
*/
public int getIndex()
{
return parentQuery.getQueryResults().indexOf(this);
}
}

@ -137,4 +137,11 @@ public ContactDetail getPreferredContactDetail(
* @return the PresenceStatus representing the state of this source contact.
*/
public PresenceStatus getPresenceStatus();
/**
* Returns the index of this source contact in its parent.
*
* @return the index of this source contact in its parent
*/
public int getIndex();
}

Loading…
Cancel
Save