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  * AgentModel.java
26  *
27  * The underlying model for the Agent Table
28  *****************************************************************************/
29  
30  package zeus.generator.code;
31  
32  import java.util.*;
33  import javax.swing.table.*;
34  import javax.swing.event.*;
35  
36  import zeus.util.*;
37  
38  
39  public class AgentModel extends UtilityModel {
40    
41    static final int GENERATE    = 0;
42    static final int STATUS      = 1;
43    static final int NAME        = 2;
44    static final int HOST        = 3;
45    static final int DATABASE    = 4;
46    static final int SERVER_FILE = 5;
47    static final int HAS_GUI     = 6;
48    static final int EXTERNAL    = 7;
49    static final int ICON        = 8;
50  
51    protected static final String[] columnNames = {
52       "Generate", "Status", "Name", "Host", "Database Extension",
53       "DNS file", "Create GUI?", "External Program", "Icon"
54    };
55  
56    protected Vector data = new Vector();
57    protected GenerationPlan  genplan;
58  
59    public AgentModel(GenerationPlan genplan) {
60      this.genplan = genplan;
61      genplan.addChangeListener(this);
62      refresh();
63    }
64  
65    public void addNewRow() {
66    }
67    public void removeRows(int[] rows) {
68    }
69    protected void refresh()  {
70      data.removeAllElements();
71      AgentInfo[] info = genplan.getAgents();
72      for(int i = 0; i < info.length; i++ )
73         data.addElement(info[i]);
74      fireTableDataChanged();
75    }
76  
77    public int     getColumnCount()       { return columnNames.length; }
78    public int     getRowCount()          { return data.size(); }
79    public String  getColumnName(int col) { return columnNames[col]; }
80  
81    public boolean isCellEditable(int row, int col) {
82       switch(col) {
83          case GENERATE:
84          case HOST:
85          case DATABASE:
86          case SERVER_FILE:
87          case HAS_GUI:
88          case EXTERNAL:
89          case ICON:
90               return true;
91  
92  	case NAME:
93          case STATUS:
94               return false;
95       }
96       return false;
97    }
98  
99    public Object getValueAt(int row, int column) {
100      AgentInfo info = (AgentInfo)data.elementAt(row);
101      switch(column) {
102         case GENERATE:
103              return new Boolean(info.generate);
104 
105 	case STATUS:
106              return info.status;
107 
108         case NAME:
109              return info.name;
110 
111         case HOST:
112              return info.host;
113 
114         case DATABASE:
115              return info.database;
116 
117 	    case SERVER_FILE:
118              return info.dns_file;
119 
120         case HAS_GUI:
121              return new Boolean(info.has_gui);
122 
123         case EXTERNAL:
124              return info.zeus_external;
125 
126         case ICON:
127              return info.icon_file;
128      }
129      return null;
130   }
131 
132   public void setValueAt(Object aValue, int row, int column) {
133      AgentInfo info = (AgentInfo)data.elementAt(row);
134      switch(column) {
135         case GENERATE:
136              info.generate = updateBoolean(info.generate,aValue);
137              if ( changed ) genplan.setAgent(info);
138              break;
139 
140 	case STATUS:
141              Core.ERROR(null,1,this);
142              break;
143 
144         case NAME:
145              Core.ERROR(null,2,this);
146              break;
147 
148         case HOST:
149              info.host = updateString(info.host,aValue);
150              if ( changed ) genplan.setAgent(info);
151              break;
152 
153         case DATABASE:
154              info.database = updateString(info.database,aValue);
155              if ( changed ) genplan.setAgent(info);
156              break;
157 
158 	case SERVER_FILE:
159              info.dns_file = updateString(info.dns_file,aValue);
160              if ( changed ) genplan.setAgent(info);
161              break;
162 
163         case HAS_GUI:
164              info.has_gui = updateBoolean(info.has_gui,aValue);
165              if ( changed ) genplan.setAgent(info);
166              break;
167 
168         case EXTERNAL:
169              info.zeus_external = updateString(info.zeus_external,aValue);
170              if ( changed ) genplan.setAgent(info);
171              break;
172 
173         case ICON:
174              info.icon_file = updateString(info.icon_file,aValue);
175              genplan.setAgentIcon(info);
176              break;
177      }
178   }
179 }