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  * TaskTableModel.java
26  *
27  * The underlying model for the Task 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 TaskTableModel extends AbstractTableModel
40                               implements ChangeListener {
41  
42    static final int TASK = 0;
43    static final int TYPE = 1;
44    static final int ID   = 2;
45  
46    protected String[]   columnNames = { "Task", "Type" };
47    protected Object[][] data        = new Object[0][2];
48    protected boolean    isEditable  = false;
49  
50    public void setEditable(boolean isEditable) {
51       this.isEditable = isEditable;
52    }
53  
54    protected GeneratorModel genmodel;
55  
56    public TaskTableModel(GeneratorModel genmodel) {
57      this.genmodel = genmodel;
58      genmodel.addChangeListener(this);
59      data = genmodel.getTaskData();
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 && col == TASK; }
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      // prevents the table being accidently loaded with a null value
70      // current table implementation needs this - possibly because of a bug
71      if (aValue == null || aValue.toString().equals(""))
72         return;
73  
74      switch(column) {
75         case TASK:
76              if ( data[row][TASK].equals((String)aValue) ) return;
77              genmodel.renameTask((String)data[row][ID],(String)aValue);
78              break;
79      }
80    }
81  
82    public void addNewRow(int type) {
83      genmodel.createNewTask(AbstractTask.getTypeName(type));
84    }
85  
86    public void stateChanged(ChangeEvent e) {
87      int size = data.length;
88      data = genmodel.getTaskData();
89      if ( size != 0 )
90         fireTableRowsDeleted(0,size-1);
91  
92      fireTableDataChanged();
93    }
94  }