[sip-comm-cvs] CVS update: /sip-communicator/src/net/java/sip/communicator/sip/simple/

emcho at dev.java.net emcho at dev.java.net
Wed May 26 11:08:46 CEST 2004


User: emcho   
Date: 04/05/26 02:08:46

Modified:
 /sip-communicator/src/net/java/sip/communicator/sip/simple/
  Contact.java, ContactGroup.java, ContactListController.java

Log:
 Ongoing work on simple

File Changes:

Directory: /sip-communicator/src/net/java/sip/communicator/sip/simple/
======================================================================

File [changed]: Contact.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/sip/simple/Contact.java?r1=1.5&r2=1.6
Delta lines:  +24 -5
--------------------
--- Contact.java	16 Apr 2004 08:52:33 -0000	1.5
+++ Contact.java	26 May 2004 09:08:43 -0000	1.6
@@ -71,7 +71,7 @@
     protected String displayName         = null;
     private   PresenceTuple statusTuple  = null;
     protected GenericURI presenceUri     = null;
-
+    private   String        notes          = null;
 
     public Contact()
     {
@@ -165,6 +165,15 @@
     }
 
     /**
+     * Sets a String containing any user comments on this contact.
+     * @param notes a String containing any user comments on this contact.
+     */
+    public String getNotes()
+    {
+        return notes;
+    }
+
+    /**
      * Sets the presence URI that uniquely identifies this contact in the
      * contact list.
      * @param presenceUri the presence URI that uniquely identifies this contact in the
@@ -173,5 +182,15 @@
     public void setPresenceUri(GenericURI presenceUri)
     {
         this.presenceUri = presenceUri;
+    }
+
+
+    /**
+     * Sets a String containing any user comments on this contact.
+     * @param notes a String containing any user comments on this contact.
+     */
+    public void setNotes(String notes)
+    {
+        this.notes = notes;
     }
 }

File [changed]: ContactGroup.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/sip/simple/ContactGroup.java?r1=1.5&r2=1.6
Delta lines:  +71 -1
--------------------
--- ContactGroup.java	16 Apr 2004 08:52:34 -0000	1.5
+++ ContactGroup.java	26 May 2004 09:08:43 -0000	1.6
@@ -70,13 +70,22 @@
 
 public class ContactGroup extends Contact
 {
+    private String sourceLocation = null;
+
     private Vector contacts = new Vector();
 
     public ContactGroup()
     {
     }
 
-    public void addContact(Contact contact)
+    /**
+     * Adds a (existing) contact to this group.
+     * The method should not be accessed outside the sip package and adding new
+     * contacts to the group must be handled by the <code>ContactListController</code>.
+     * @param contact the contact to add to the group.
+     * @return the index where the contact was added
+     */
+    public int addContact(Contact contact)
     {
         String displayName = contact.getDisplayName();
         int index = 0;
@@ -92,8 +101,32 @@
                 break;
         }
         contacts.add(index, contact);
+        return index;
+    }
+
+    /**
+     * Removes the specified contact from this group
+     * @param contact the contact to remove
+     */
+    public void removeContact(Contact contact)
+    {
+        contacts.remove(contact);
     }
 
+    /**
+     * Removes the contact that is on the specified position
+     * @param index the index of the contact to remove.
+     */
+    public void removeContact(int index)
+    {
+        contacts.remove(index);
+    }
+
+    /**
+     * Returns the node at the specified position.
+     * @param index the index of the node to return
+     * @return the contact (or ContactGroup) that is at the specified position
+     */
     public Contact getChild(int index)
     {
         return (Contact)contacts.get(index);
@@ -214,6 +247,43 @@
                return i;
        }
        return -1;
+   }
+
+   /**
+    * Sets a String pointing to the location where this group got loaded from.
+    * The field should only be used in the case of a root ContactGroup
+    * (the contact list itself)
+    * @param sourceLocation a String pointing to the location where this group
+    * got loaded from.
+    */
+   void setSourceLocation(String sourceLocation)
+   {
+       this.sourceLocation = sourceLocation;
+   }
+
+   /**
+   * Returns a String pointing to the location where this group got loaded from.
+   * The field should only be used in the case of a root ContactGroup
+   * (the contact list itself)
+   * @return a String pointing to the location where this group
+   * got loaded from.
+   */
+   String getSourceLocation()
+   {
+       return sourceLocation;
+   }
+
+   /**
+    * Searches for the first occurence of the given contact, testing for equality
+    * using the equals method.
+    * @param contact the contact to look for.
+    * @return he index of the first occurrence of the argument in this vector,
+    * that is, the smallest value k such that elem.equals(elementData[k]) is
+    * true; returns -1 if the object is not found.
+    */
+   public int indexOf(Contact contact)
+   {
+           return contacts.indexOf(contact);
    }
 
 }

File [changed]: ContactListController.java
Url: https://sip-communicator.dev.java.net/source/browse/sip-communicator/src/net/java/sip/communicator/sip/simple/ContactListController.java?r1=1.3&r2=1.4
Delta lines:  +139 -3
---------------------
--- ContactListController.java	16 Apr 2004 08:52:34 -0000	1.3
+++ ContactListController.java	26 May 2004 09:08:43 -0000	1.4
@@ -106,6 +106,11 @@
        try{
            if(contactList == null)
                contactList = ContactListSerializer.loadList(url);
+
+           //save the location we loaded the list from so that we know where to
+           //store it incase it gets modified.
+           contactList.setSourceLocation(url);
+
            return contactList;
        }
        catch(IOException exc)
@@ -213,7 +218,7 @@
      *
      * @param l the listener to add
      */
-    public void addNotificationListener(NotificationListener l)
+    public void addNotificationListener(ContactListChangeListener l)
     {
         if(l == null)
             throw new NullPointerException("PresenceStatusListener cannot be null");
@@ -227,7 +232,7 @@
      *
      * @param l the listener to remove
      */
-    public void removeNotificationListener(NotificationListener l)
+    public void removeNotificationListener(ContactListChangeListener l)
     {
         if(l == null)
             return;
@@ -264,11 +269,63 @@
             // Lazily create the event:
             if (e == null)
                 e = new NotificationReceivedEvent(source, sourcePath, newStatus, oldStatus);
-            ((NotificationListener)listenerList.get(i)).notificationReceived(e);
+            ((ContactListChangeListener)listenerList.get(i)).notificationReceived(e);
         }
     }
 
     /**
+     * Notifies all listeners that have registered interest for
+     * notification on this event type.  The event instance
+     * is lazily created using the parameters passed into
+     * the fire method.
+     *
+     * @param source The contact that has been added.
+     * @param sourcePath the location of the contact that has been added.
+     * @param index the index where the child was added
+     */
+    protected void fireContactAdded(Contact        source,
+                                    ContactGroup[] sourcePath,
+                                    int            index)
+    {
+        ContactAddedEvent e = null;
+        // Process the listeners last to first, notifying
+        // those that are interested in this event
+        for (int i = listenerList.size()-1; i>=0; i--) {
+            // Lazily create the event:
+            if (e == null)
+                e = new ContactAddedEvent(source, sourcePath, index);
+            ((ContactListChangeListener)listenerList.get(i)).contactAdded(e);
+        }
+    }
+
+    /**
+     * Notifies all listeners that have registered interest for
+     * notification on this event type.  The event instance
+     * is lazily created using the parameters passed into
+     * the fire method.
+     *
+     * @param source The contact that has been removed.
+     * @param sourcePath the location where the contact got removed from.
+     * @param index the index where the child was before being removed.
+     */
+    protected void fireContactRemoved(Contact        source,
+                                    ContactGroup[] sourcePath,
+                                    int            index)
+    {
+        ContactRemovedEvent e = null;
+        // Process the listeners last to first, notifying
+        // those that are interested in this event
+        for (int i = listenerList.size()-1; i>=0; i--) {
+            // Lazily create the event:
+            if (e == null)
+                e = new ContactRemovedEvent(source, sourcePath, index);
+            ((ContactListChangeListener)listenerList.get(i)).contactRemoved(e);
+        }
+    }
+
+
+
+    /**
      * Starts the subscriber thread which sends SUBSCRIBE requests to all
      * contact-list members.
      * @todo better thread support - avoid race conditiions and make
@@ -452,5 +509,84 @@
             sipManCallback.fireCommunicationsError(ex);
         }
     }
+
+    /**
+     * Adds <code>contact</code> to the ContactList managed by this
+     * ContactListController.
+     *
+     * @param location the location where the new contact should be created.
+     * @param presenceUriStr the presence URI for the new contact
+     * @param displayName a display alias to be saved for the new contact.
+     * @param notes a string containing any user notes for the new contact.
+     * @throws CommunicationsException if we faile to create the new contact.
+     */
+    public void requestContactAddition(ContactGroup[] location,
+                                       String         presenceUriStr,
+                                       String         displayName,
+                                       String         notes)
+        throws CommunicationsException
+    {
+        // create the contact and add it to the specified location
+        GenericURI presenceURI = GenericURI.parseURI(presenceUriStr);
+        Contact newContact = new Contact(presenceURI);
+        newContact.setDisplayName(displayName);
+        newContact.setNotes(notes);
+        newContact.setPresenceUri(presenceURI);
+
+        if(location == null
+           || location.length < 1)
+            throw new CommunicationsException("Invalid location parameter!");
+
+        ContactGroup parent = location[location.length - 1];
+        int index = parent.addContact(newContact);
+
+        //store the list to a file
+        if(contactList.getSourceLocation() == null
+           ||contactList.getSourceLocation().length() == 0)
+          throw new CommunicationsException("No store location was given for the specified contact list!");
+        ContactListSerializer.storeContactList(contactList.getSourceLocation(),
+                                               contactList);
+
+        // trigger an event that would cause the ui refresh the user interface
+        fireContactAdded(newContact, location, index);
+
+    }
+
+    /**
+     * Adds <code>contact</code> to the ContactList managed by this
+     * ContactListController.
+     *
+     * @param location the location where the new contact should be created.
+     * @param presenceUriStr the presence URI for the new contact
+     * @param displayName a display alias to be saved for the new contact.
+     * @param notes a string containing any user notes for the new contact.
+     * @throws CommunicationsException if we faile to create the new contact.
+     */
+    public void requestContactRemoval( ContactGroup[] location,
+                                       Contact        contact)
+        throws CommunicationsException
+    {
+        if (location == null
+            || location.length < 1)
+            throw new CommunicationsException("Invalid location parameter!");
+
+        int index = location[location.length - 1].indexOf(contact);
+
+        location[location.length - 1].removeContact(contact);
+
+
+        //store the list to a file
+        if (contactList.getSourceLocation() == null
+            || contactList.getSourceLocation().length() == 0)
+            throw new CommunicationsException(
+                "No store location was given for the specified contact list!");
+        ContactListSerializer.storeContactList(contactList.getSourceLocation(),
+                                               contactList);
+
+        // trigger an event that would cause the ui refresh the user interface
+        fireContactRemoved(contact, location, index);
+
+    }
+
 
 }




---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: cvs-help at sip-communicator.dev.java.net




More information about the commits mailing list