View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  
23  
24  package zeus.agentviewer.acquaintances;
25  
26  import javax.swing.table.*;
27  import javax.swing.*;
28  import java.util.*;
29  import zeus.actors.OrganisationDb;
30  import zeus.util.OrderedHashtable;
31  
32  import zeus.actors.event.*;
33  import zeus.actors.*;
34  import zeus.concepts.*;
35  
36  
37  
38  
39  public class RelationsTableModel  extends AbstractTableModel implements RelationMonitor{
40  
41        private String   AGENT        = "Agent";
42        private String   RELATION     = "Relation";
43  
44        private String[] header = {AGENT,RELATION};
45        private OrderedHashtable   data;
46        private OrganisationDb organisationDb;
47  //------------------------------------------------------------------------------
48        public RelationsTableModel(AgentContext context){
49            data = new OrderedHashtable();
50            organisationDb = context.OrganisationDb();
51            organisationDb.addRelationMonitor(this,
52               RelationEvent.ADD_MASK | RelationEvent.DELETE_MASK |
53               RelationEvent.MODIFY_MASK, true );
54        }
55  //------------------------------------------------------------------------------
56         public int getRowCount() {
57             return data.size();
58         }
59  //------------------------------------------------------------------------------
60         public int getColumnCount(){
61             return header.length;
62         }
63  //------------------------------------------------------------------------------
64         public boolean isCellEditable(int row, int col) {
65            return false;
66         }
67  //------------------------------------------------------------------------------
68         public void setValueAt(Object value, int row, int col) {
69         }
70  //------------------------------------------------------------------------------
71         public Object getValueAt(int row, int col) {
72              String name = (String) data.getKeyAt(row);
73  
74              if (getColumnName(col).equals(AGENT))  {
75                  return  (name);
76               }
77               else if (getColumnName(col).equals(RELATION))  {
78                  return   (String) data.get(name);
79               }
80               else return new String("Error in AgentRelationTableModel at getValueAt");
81  
82         }
83  //------------------------------------------------------------------------------
84         public String getColumnName(int col) {
85              return  header[col];
86         }
87  //------------------------------------------------------------------------------
88         public void AddRelation(String name, String rel){
89            data.put(name,rel);
90            fireTableDataChanged();
91         }
92  //------------------------------------------------------------------------------
93         public void ModifyRelation(String name, String newRelation){
94               data.put(name,newRelation);
95               fireTableDataChanged();
96         }
97  
98  //------------------------------------------------------------------------------
99         public void removeRelation(String rel){
100           data.remove(rel);
101           fireTableDataChanged();
102        }
103 
104 //------------------------------------------------------------------------------
105        public String getName(int row){
106           return (String) data.getKeyAt(row);
107        }
108 //------------------------------------------------------------------------------
109        public void relationAddedEvent(RelationEvent event) {
110          AddRelation(event.getAgent(),event.getRelation());
111        }
112 //------------------------------------------------------------------------------
113        public void relationModifiedEvent(RelationEvent event) {
114          ModifyRelation(event.getAgent(),event.getRelation());
115        }
116 //------------------------------------------------------------------------------
117        public void relationDeletedEvent(RelationEvent event) {
118          removeRelation(event.getAgent());
119        }
120 //------------------------------------------------------------------------------
121        public void relationAccessedEvent(RelationEvent event) {}
122 //------------------------------------------------------------------------------
123        public void removeZeusEventMonitors(){
124          organisationDb.removeRelationMonitor(this,
125             RelationEvent.ADD_MASK | RelationEvent.DELETE_MASK |
126             RelationEvent.MODIFY_MASK);
127        }
128 
129 }