1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }