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  * NameserverModel.java
26  *
27  * The underlying model for the Generator 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 NameserverModel extends UtilityModel {
40  
41    static final int NAME        = 0;
42    static final int HOST        = 1;
43    static final int IS_ROOT     = 2;
44    static final int TIME        = 3;
45    static final int SERVER_FILE = 4;
46    static final int OUT_FILE    = 5;
47    static final int HAS_GUI     = 6;
48    static final int EXTERNAL    = 7;
49  
50    protected static final String[] columnNames = {
51       "Name", "Host", "Is root", "Time grain", "DNS file",
52       "Address File", "Create GUI?", "External Program"
53    };
54  
55    protected Vector data = new Vector();
56    protected GenerationPlan  genplan;
57  
58    public NameserverModel(GenerationPlan genplan) {
59      this.genplan = genplan;
60      genplan.addChangeListener(this);
61      refresh();
62    }
63  
64    public void addNewRow() {
65       genplan.createNameserver();
66    }
67    public void removeRows(int[] rows) {
68       for(int i = 0; i < rows.length; i++ ) {
69          NameserverInfo info = (NameserverInfo)data.elementAt(rows[i]-i);
70          genplan.removeNameserver(info.id);
71       }
72    }
73  
74    protected void refresh()  {
75       data.removeAllElements();
76       NameserverInfo[] info = genplan.getNameservers();
77       for(int i = 0; i < info.length; i++ )
78          data.addElement(info[i]);
79       fireTableDataChanged();
80    }
81  
82    public int     getColumnCount()       { return columnNames.length - 2; }
83    public int     getRowCount()          { return data.size(); }
84    public String  getColumnName(int col) { return columnNames[col]; }
85  
86    public boolean isCellEditable(int row, int col) {
87       NameserverInfo info = (NameserverInfo)data.elementAt(row);
88       switch(col) {
89          case NAME:
90          case HOST:
91          case IS_ROOT:
92          case HAS_GUI:
93          case EXTERNAL:
94          case OUT_FILE:
95               return true;
96  
97          case TIME:
98               return info.is_root;
99  
100         case SERVER_FILE:
101              return !info.is_root;
102      }
103      return false;
104   }
105 
106   public Object getValueAt(int row, int column) {
107      NameserverInfo info = (NameserverInfo)data.elementAt(row);
108      switch(column) {
109         case NAME:
110              return info.name;
111 
112         case HOST:
113              return info.host;
114 
115         case IS_ROOT:
116              return new Boolean(info.is_root);
117 
118         case HAS_GUI:
119              return new Boolean(info.has_gui);
120 
121         case EXTERNAL:
122              return info.zeus_external;
123 
124         case OUT_FILE:
125              return info.address_output_file;
126 
127         case TIME:
128              return info.time_grain;
129 
130         case SERVER_FILE:
131              return info.dns_file;
132      }
133      return null;
134   }
135 
136   public void setValueAt(Object aValue, int row, int column) {
137      NameserverInfo info = (NameserverInfo)data.elementAt(row);
138      switch(column) {
139         case NAME:
140              info.name = updateString(info.name,aValue,false);
141              break;
142 
143         case HOST:
144              info.host = updateString(info.host,aValue);
145              break;
146 
147 	case IS_ROOT:
148              info.is_root = updateBoolean(info.is_root,aValue);
149              if ( info.is_root ) {
150                 info.dns_file = null;
151                 if ( info.time_grain == null )
152                    info.time_grain = NameserverInfo.DEFAULT_PERIOD;
153              }
154              else
155                 info.time_grain = null;
156              break;
157 
158         case HAS_GUI:
159              info.has_gui = updateBoolean(info.has_gui,aValue);
160              break;
161 
162 	case EXTERNAL:
163              info.zeus_external = updateString(info.zeus_external,aValue);
164              break;
165 
166         case OUT_FILE:
167              info.address_output_file = updateString(info.address_output_file,aValue);
168              break;
169 
170 	case TIME:
171              info.time_grain = updateString(info.time_grain,aValue);
172              if ( info.time_grain == null )
173                 info.time_grain = NameserverInfo.DEFAULT_PERIOD;
174              break;
175 
176         case SERVER_FILE:
177              info.dns_file = updateString(info.dns_file,aValue);
178              break;
179      }
180      if ( changed ) genplan.setNameserver(info);
181   }
182 }