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  Change Log.
23  ----------
24  28/08/00 alterations to include a task external
25  */
26  
27  /******************************************************************************
28  * TaskModel.java
29  *
30  * The underlying model for the Task Table
31  *****************************************************************************/
32  
33  package zeus.generator.code;
34  
35  import java.util.*;
36  import javax.swing.table.*;
37  import javax.swing.event.*;
38  
39  import zeus.util.*;
40  
41  
42  public class TaskModel extends UtilityModel {
43  
44    static final int GENERATE    = 0;
45    static final int STATUS      = 1;
46    static final int NAME        = 2;
47       // 25/08/00 addition by simon
48    static final int EXTERNAL    = 3;
49    protected static final String[] columnNames = {
50         // 25/08/00 addition by simon
51       "Generate", "Status", "Name","External Program"
52    };
53  
54    protected Vector data = new Vector();
55    protected GenerationPlan  genplan;
56  
57    public TaskModel(GenerationPlan genplan) {
58      this.genplan = genplan;
59      genplan.addChangeListener(this);
60      refresh();
61    }
62  
63    public void addNewRow() {
64    }
65    public void removeRows(int[] rows) {
66    }
67    protected void refresh()  {
68      data.removeAllElements();
69     TaskInfo[] info = genplan.getTasks();
70      for(int i = 0; i < info.length; i++ )
71         data.addElement(info[i]);
72      fireTableDataChanged();
73    }
74  
75    public int     getColumnCount()                 { return columnNames.length; }
76    public int     getRowCount()                    { return data.size(); }
77    public String  getColumnName(int col)           { return columnNames[col]; }
78  
79    public boolean isCellEditable(int row, int col) {
80       switch(col) {
81          case GENERATE:
82          {
83               return true; 
84          }
85          case EXTERNAL:{         
86               return true; 
87          }
88  	    case NAME:
89          case STATUS:
90               return false;
91       }
92       return false;
93    }
94  
95    public Object getValueAt(int row, int column) {
96       TaskInfo info = (TaskInfo)data.elementAt(row);
97       switch(column) {
98          case GENERATE:
99               return new Boolean(info.generate);
100 
101 	    case STATUS:
102              return info.status;
103 
104         case NAME:
105              return info.name;
106        
107         case EXTERNAL: 
108             return info.task_external; 
109      }
110      return null;
111   }
112 
113   public void setValueAt(Object aValue, int row, int column) {
114      TaskInfo info = (TaskInfo)data.elementAt(row);
115      switch(column) {
116         case GENERATE:{
117              info.generate = updateBoolean(info.generate,aValue);
118              break;}
119 
120 	    case STATUS:{
121              Core.ERROR(null,1,this);
122              break;}
123 
124         case NAME:{
125              Core.ERROR(null,2,this);
126              break;}
127              
128         case EXTERNAL:{
129              System.out.println ("Setting external value"); 
130              info.task_external = updateString(info.task_external,aValue);
131              if ( changed ) genplan.setTask(info);
132              break;}
133      }
134      if ( changed ) genplan.setTask(info);
135   }
136 }