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  * DbProxyModel.java
26  *
27  * The underlying model for the DbProxy 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 DbProxyModel 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 PATH        = 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", "Proxy classpath",
50       "Create GUI?", "External Program"
51    };
52  
53    protected Vector data = new Vector();
54    protected GenerationPlan  genplan;
55  
56    public DbProxyModel(GenerationPlan genplan) {
57      this.genplan = genplan;
58      genplan.addChangeListener(this);
59      refresh();
60    }
61  
62    public void addNewRow() {
63       genplan.createDbProxy();
64    }
65    public void removeRows(int[] rows) {
66       for(int i = 0; i < rows.length; i++ ) {
67          DbProxyInfo info = (DbProxyInfo)data.elementAt(rows[i]-i);
68          genplan.removeDbProxy(info.id);
69       }
70    }
71  
72    protected void refresh()  {
73      data.removeAllElements();
74      DbProxyInfo[] info = genplan.getDbProxys();
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  
84    public boolean isCellEditable(int row, int col) { return true; }
85  
86    public Object getValueAt(int row, int column) {
87       DbProxyInfo info = (DbProxyInfo)data.elementAt(row);
88       switch(column) {
89          case NAME:
90               return info.name;
91  
92          case HOST:
93               return info.host;
94  
95          case HAS_GUI:
96               return new Boolean(info.has_gui);
97  
98          case EXTERNAL:
99               return info.zeus_external;
100 
101         case PATH:
102              return info.path;
103 
104         case SERVER_FILE:
105              return info.dns_file;
106      }
107      return null;
108   }
109 
110   public void setValueAt(Object aValue, int row, int column) {
111      DbProxyInfo info = (DbProxyInfo)data.elementAt(row);
112      switch(column) {
113         case NAME:
114              info.name = updateString(info.name,aValue,false);
115              break;
116 
117         case HOST:
118              info.host = updateString(info.host,aValue);
119              break;
120 
121         case HAS_GUI:
122              info.has_gui = updateBoolean(info.has_gui,aValue);
123              break;
124 
125 	case EXTERNAL:
126              info.zeus_external = updateString(info.zeus_external,aValue);
127              break;
128 
129 	case PATH:
130              info.path = updateString(info.path,aValue);
131              break;
132 
133         case SERVER_FILE:
134              info.dns_file = updateString(info.dns_file,aValue);
135              break;
136      }
137      if ( changed ) genplan.setDbProxy(info);
138   }
139 }