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  * GenTableModel.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 GenerationTableModel extends AbstractTableModel
40                                    implements ChangeListener {
41  
42    static final int AGENT_FILTER   = 1;
43    static final int TASK_FILTER    = 2;
44    static final int UTILITY_FILTER = 3;
45  
46    protected static final String[] columnNames = {
47       "Name", "Type", "Command Line"
48    };
49  
50    protected Vector data = new Vector();
51  
52    protected boolean hideAgents = false;
53    protected boolean hideTasks = false;
54    protected boolean hideUtilities = false;
55  
56    protected GenerationPlan  genplan;
57  
58    public GenerationTableModel(GenerationPlan genplan) {
59      this.genplan = genplan;
60      genplan.addChangeListener(this);
61      refresh();
62    }
63  
64    public void setFilter(int f) {
65      if      (f == AGENT_FILTER)    hideAgents = !hideAgents;
66      else if (f == TASK_FILTER)     hideTasks = !hideTasks;
67      else if (f == UTILITY_FILTER)  hideUtilities = !hideUtilities;
68      refresh();
69    }
70  
71    public void removeRows(int[] rows) {
72       for(int i = 0; i < rows.length; i++ ) {
73          String[] entry = (String[])data.elementAt(rows[i]-i);
74          genplan.removeEntry(entry[GenerationInfo.TYPE],
75  	                    entry[GenerationInfo.ID]);
76       }
77    }
78  
79    protected synchronized void refresh()  {
80      int p_size = data.size();
81      data.removeAllElements();
82      String[][] entry;
83  
84      if ( !hideUtilities ) {
85         entry = genplan.summarizeNameservers();
86         for(int i = 0; i < entry.length; i++ )
87            data.addElement(entry[i]);
88  
89         entry = genplan.summarizeFacilitators();
90         for(int i = 0; i < entry.length; i++ )
91            data.addElement(entry[i]);
92  
93         entry = genplan.summarizeVisualisers();
94         for(int i = 0; i < entry.length; i++ )
95            data.addElement(entry[i]);
96  
97         entry = genplan.summarizeDbProxys();
98         for(int i = 0; i < entry.length; i++ )
99            data.addElement(entry[i]);
100     }
101 
102     if ( !hideAgents ) {
103        entry = genplan.summarizeSelectedAgents();
104        for(int i = 0; i < entry.length; i++ )
105           data.addElement(entry[i]);
106     }
107 
108     if ( !hideTasks ) {
109        entry = genplan.summarizeSelectedTasks();
110        for(int i = 0; i < entry.length; i++ )
111           data.addElement(entry[i]);
112     }
113     if ( p_size > 0 ) fireTableRowsDeleted(0,p_size-1);
114     int c_size = data.size();
115     if ( c_size > 0 ) fireTableRowsInserted(0,c_size-1);
116   }
117 
118   public int     getColumnCount()                 { return columnNames.length; }
119   public int     getRowCount()                    { return data.size(); }
120   public boolean isCellEditable(int row, int col) { return false;}
121   public String  getColumnName(int col)           { return columnNames[col]; }
122 
123   public Object getValueAt(int row, int column) {
124     try {
125        String[] entry = (String[])data.elementAt(row);
126        return entry[column];
127     }
128     catch(ArrayIndexOutOfBoundsException e) {
129        return null;
130     }
131   }
132 
133   public void setValueAt(Object aValue, int row, int column) {
134   }
135 
136   public void stateChanged(ChangeEvent e) {
137     // generationPlan state changed recompute all entries;
138     refresh();
139   }
140 }