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