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  /******************************************************************************
25  * AgentTableModel.java
26  *
27  * The underlying model for the Agent Table 
28  *****************************************************************************/
29  
30  package zeus.generator;
31  
32  import java.util.*;
33  import javax.swing.table.*;
34  import javax.swing.event.*;
35  
36  import zeus.util.*;
37  import zeus.concepts.*;
38  
39  public class AgentTableModel extends AbstractTableModel 
40                               implements ChangeListener {
41  
42    static final int AGENT = 0;
43    static final int TASK  = 1;
44    static final int ID    = 2;
45  
46    protected String[]   columnNames = { "Agent", "Tasks" };
47    protected Object[][] data        = null;
48    protected boolean    isEditable  = false;
49  
50    protected GeneratorModel genmodel;
51  
52    public AgentTableModel(GeneratorModel genmodel) {
53      this.genmodel = genmodel;
54      genmodel.addChangeListener(this);
55      data = genmodel.getAgentData();
56    }
57  
58    public void setEditable(boolean isEditable) {
59       this.isEditable = isEditable;
60    }
61  
62    public int     getColumnCount()                 { return columnNames.length; }
63    public int     getRowCount()                    { return data.length; }
64    public boolean isCellEditable(int row, int col) { return isEditable; }
65    public String  getColumnName(int col)           { return columnNames[col]; }
66    public Object  getValueAt(int row, int col)     { return data[row][col]; }
67  
68    public void setValueAt(Object aValue, int row, int column) {
69      switch(column) {
70         case AGENT:
71              if ( aValue == null || aValue.equals("") ) return;
72              if ( data[row][AGENT].equals((String)aValue) ) return;
73              genmodel.renameAgent((String)data[row][ID],(String)aValue);
74              break;
75  
76         case TASK:
77              if ( data[row][TASK].equals((String[])aValue) ) return;
78              genmodel.modifyAgentTasks((String)data[row][ID],(String[])aValue);
79              break;
80      }
81    }
82  
83    public void addNewRow() {
84      genmodel.createNewAgent();
85    }
86    
87    public void stateChanged(ChangeEvent e) {
88      int size = data.length;
89      data = genmodel.getAgentData();
90      if ( size != 0 )
91         fireTableRowsDeleted(0,size-1);
92      fireTableDataChanged();
93    }
94  }