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  * FacilitatorModel.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 FacilitatorModel extends UtilityModel {
40  
41    static final int NAME        = 0;
42    static final int HOST        = 1;
43    static final int SERVER_FILE = 2;
44    static final int PERIOD      = 3;
45    static final int HAS_GUI     = 4;
46    static final int EXTERNAL    = 5;
47  
48    protected static final String[] columnNames = {
49       "Name", "Host", "DNS file", "Recycle period",
50       "Create GUI?", "External Program"
51    };
52  
53    protected Vector data = new Vector();
54    protected GenerationPlan  genplan;
55  
56    public FacilitatorModel(GenerationPlan genplan) {
57      this.genplan = genplan;
58      genplan.addChangeListener(this);
59      refresh();
60    }
61  
62    public void addNewRow() {
63       genplan.createFacilitator();
64    }
65    public void removeRows(int[] rows) {
66       for(int i = 0; i < rows.length; i++ ) {
67          FacilitatorInfo info = (FacilitatorInfo)data.elementAt(rows[i]-i);
68          genplan.removeFacilitator(info.id);
69       }
70    }
71  
72    protected void refresh()  {
73      data.removeAllElements();
74      FacilitatorInfo[] info = genplan.getFacilitators();
75      for(int i = 0; i < info.length; i++ )
76         data.addElement(info[i]);
77      fireTableDataChanged();
78    }
79  
80    public int     getColumnCount()                 { return columnNames.length - 2; }
81    public int     getRowCount()                    { return data.size(); }
82    public String  getColumnName(int col)           { return columnNames[col]; }
83    public boolean isCellEditable(int row, int col) { return true; }
84  
85    public Object getValueAt(int row, int column) {
86       FacilitatorInfo info = (FacilitatorInfo)data.elementAt(row);
87       switch(column) {
88          case NAME:
89               return info.name;
90  
91          case HOST:
92               return info.host;
93  
94          case HAS_GUI:
95               return new Boolean(info.has_gui);
96  
97          case EXTERNAL:
98               return info.zeus_external;
99  
100         case PERIOD:
101              return info.period;
102 
103         case SERVER_FILE:
104              return info.dns_file;
105      }
106      return null;
107   }
108 
109   public void setValueAt(Object aValue, int row, int column) {
110      FacilitatorInfo info = (FacilitatorInfo)data.elementAt(row);
111      switch(column) {
112         case NAME:
113              info.name = updateString(info.name,aValue,false);
114              break;
115 
116         case HOST:
117              info.host = updateString(info.host,aValue);
118              break;
119 
120         case HAS_GUI:
121              info.has_gui = updateBoolean(info.has_gui,aValue);
122              break;
123 
124 	case EXTERNAL:
125              info.zeus_external = updateString(info.zeus_external,aValue);
126              break;
127 
128 	case PERIOD:
129              info.period = updateString(info.period,aValue);
130              if ( info.period == null )
131                 info.period = FacilitatorInfo.DEFAULT_PERIOD;
132              break;
133 
134         case SERVER_FILE:
135              info.dns_file = updateString(info.dns_file,aValue);
136              break;
137      }
138      if ( changed ) genplan.setFacilitator(info);
139   }
140 }