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  * UtilityPanel.java
26  *
27  *
28  ***************************************************************************/
29  
30  package zeus.generator.code;
31  
32  import java.util.*;
33  import java.awt.*;
34  import java.awt.event.*;
35  import javax.swing.*;
36  import javax.swing.border.*;
37  import javax.swing.table.*;
38  import javax.swing.event.*;
39  
40  import zeus.util.*;
41  import zeus.gui.help.*;
42  import zeus.gui.editors.*;
43  import zeus.gui.fields.*;
44  
45  public class UtilityPanel extends JPanel {
46    static final String[] ERROR_MESSAGE = {
47       /* 0 */ "Please select a row before\ncalling this operation"
48    };
49  
50    protected GenerationPlan   genplan;
51    protected NameserverModel  nameserverModel;
52    protected JTable           nameserverTable;
53    protected FacilitatorModel facilitatorModel;
54    protected JTable           facilitatorTable;
55    protected VisualiserModel  visualiserModel;
56    protected JTable           visualiserTable;
57    protected DbProxyModel     dbProxyModel;
58    protected JTable           dbProxyTable;
59  
60    public UtilityPanel(GenerationPlan genplan) {
61       this.genplan = genplan;
62  
63       GridBagLayout gridBagLayout = new GridBagLayout();
64       GridBagConstraints gbc = new GridBagConstraints();
65       setLayout(gridBagLayout);
66       setBackground(Color.lightGray);
67  
68       setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
69  
70       // Add the panel containing the nameservers to this panel.
71       JPanel nameserverPanel = new JPanel();
72       gbc.anchor = GridBagConstraints.NORTHWEST;
73       gbc.fill = GridBagConstraints.BOTH;
74       gbc.gridwidth = GridBagConstraints.REMAINDER;
75       gbc.weightx = gbc.weighty = 1;
76       gbc.insets = new Insets(8,8,8,8);
77       gridBagLayout.setConstraints(nameserverPanel,gbc);
78       add(nameserverPanel);
79  
80       // Add the panel containing the facilitators to this panel.
81       JPanel facilitatorPanel = new JPanel();
82       gbc.anchor = GridBagConstraints.NORTHWEST;
83       gbc.fill = GridBagConstraints.BOTH;
84       gbc.weightx = gbc.weighty = 1;
85       gbc.insets = new Insets(8,8,8,8);
86       gridBagLayout.setConstraints(facilitatorPanel,gbc);
87       add(facilitatorPanel);
88  
89       // Add the panel containing the visualisers to this panel.
90       JPanel visualiserPanel = new JPanel();
91       gbc.anchor = GridBagConstraints.NORTHWEST;
92       gbc.fill = GridBagConstraints.BOTH;
93       gbc.weightx = gbc.weighty = 1;
94       gbc.insets = new Insets(8,8,8,8);
95       gridBagLayout.setConstraints(visualiserPanel,gbc);
96       add(visualiserPanel);
97  
98       // Add the panel containing the dbProxysto this panel.
99       JPanel dbProxyPanel = new JPanel();
100      gbc.anchor = GridBagConstraints.NORTHWEST;
101      gbc.fill = GridBagConstraints.BOTH;
102      gbc.weightx = gbc.weighty = 1;
103      gbc.insets = new Insets(8,8,8,8);
104      gridBagLayout.setConstraints(dbProxyPanel,gbc);
105      add(dbProxyPanel);
106 
107 
108      // Create Nameserver info
109      nameserverModel = new NameserverModel(genplan);
110 
111      TableColumnModel tm = new DefaultTableColumnModel();
112      TableColumn column;
113      JCheckBox checkbox = new JCheckBox();
114      checkbox.setHorizontalAlignment(JCheckBox.CENTER);
115      DefaultCellEditor cellEditor = new DefaultCellEditor(checkbox);
116 
117      column = new TableColumn(NameserverModel.NAME,24,
118         new DefaultTableCellRenderer(),
119 	new DefaultCellEditor(new NameField()));
120      column.setHeaderValue(nameserverModel.getColumnName(NameserverModel.NAME));
121      tm.addColumn(column);
122 
123      column = new TableColumn(NameserverModel.HOST,24);
124      column.setHeaderValue(nameserverModel.getColumnName(NameserverModel.HOST));
125      tm.addColumn(column);
126 
127      column = new TableColumn(NameserverModel.IS_ROOT,8,
128         new CheckBoxCellRenderer(), cellEditor);
129      column.setHeaderValue(nameserverModel.getColumnName(NameserverModel.IS_ROOT));
130      tm.addColumn(column);
131 
132      column = new TableColumn(NameserverModel.TIME,24,
133         new DefaultTableCellRenderer(),
134 	new DefaultCellEditor(new RealNumberField(0,1000)));
135      column.setHeaderValue(nameserverModel.getColumnName(NameserverModel.TIME));
136      tm.addColumn(column);
137 
138      column = new TableColumn(NameserverModel.SERVER_FILE,24);
139      column.setHeaderValue(nameserverModel.getColumnName(NameserverModel.SERVER_FILE));
140      tm.addColumn(column);
141 
142      column = new TableColumn(NameserverModel.OUT_FILE,24);
143      column.setHeaderValue(nameserverModel.getColumnName(NameserverModel.OUT_FILE));
144      tm.addColumn(column);
145 /*
146      column = new TableColumn(NameserverModel.HAS_GUI,24,
147         new CheckBoxCellRenderer(), cellEditor);
148      column.setHeaderValue(nameserverModel.getColumnName(NameserverModel.HAS_GUI));
149      tm.addColumn(column);
150 
151      column = new TableColumn(NameserverModel.EXTERNAL,24);
152      column.setHeaderValue(nameserverModel.getColumnName(NameserverModel.EXTERNAL));
153      tm.addColumn(column);
154 */
155      nameserverTable = new JTable(nameserverModel,tm);
156      nameserverTable.getTableHeader().setReorderingAllowed(false);
157      nameserverTable.setColumnSelectionAllowed(false);
158 
159      TitledBorder border = BorderFactory.createTitledBorder("Nameservers");
160      border.setTitlePosition(TitledBorder.TOP);
161      border.setTitleJustification(TitledBorder.RIGHT);
162      border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
163      border.setTitleColor(Color.blue);
164      nameserverPanel.setBorder(border);
165 
166      gridBagLayout = new GridBagLayout();
167      nameserverPanel.setLayout(gridBagLayout);
168      nameserverPanel.setBackground(Color.lightGray);
169 
170      JToolBar toolbar = new UtilityToolBar(nameserverTable,nameserverModel,
171         "Generation Plan: Nameservers");
172      gbc = new GridBagConstraints();
173      gbc.anchor = GridBagConstraints.NORTHWEST;
174      gbc.fill = GridBagConstraints.NONE;
175      gbc.gridwidth = GridBagConstraints.REMAINDER;
176      gbc.insets = new Insets(0,8,0,0);
177      gridBagLayout.setConstraints(toolbar,gbc);
178      nameserverPanel.add(toolbar);
179 
180      JScrollPane scrollPane = new JScrollPane(nameserverTable);
181      scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
182      scrollPane.setPreferredSize(new Dimension(200,80));
183      nameserverTable.setBackground(Color.white);
184 
185      gbc = new GridBagConstraints();
186      gbc.gridwidth = GridBagConstraints.REMAINDER;
187      gbc.anchor = GridBagConstraints.NORTHWEST;
188      gbc.fill = GridBagConstraints.BOTH;
189      gbc.weightx = gbc.weighty = 1;
190      gbc.insets = new Insets(8,8,8,8);
191      gridBagLayout.setConstraints(scrollPane,gbc);
192      nameserverPanel.add(scrollPane);
193 
194      // Create facilitator panel info
195      facilitatorModel = new FacilitatorModel(genplan);
196 
197      gridBagLayout = new GridBagLayout();
198      facilitatorPanel.setLayout(gridBagLayout);
199      facilitatorPanel.setBackground(Color.lightGray);
200 
201      tm = new DefaultTableColumnModel();
202      checkbox = new JCheckBox();
203      checkbox.setHorizontalAlignment(JCheckBox.CENTER);
204      cellEditor = new DefaultCellEditor(checkbox);
205 
206      column = new TableColumn(FacilitatorModel.NAME,24,
207         new DefaultTableCellRenderer(),
208 	new DefaultCellEditor(new NameField()));
209      column.setHeaderValue(facilitatorModel.getColumnName(FacilitatorModel.NAME));
210      tm.addColumn(column);
211 
212      column = new TableColumn(FacilitatorModel.HOST,24);
213      column.setHeaderValue(facilitatorModel.getColumnName(FacilitatorModel.HOST));
214      tm.addColumn(column);
215 
216      column = new TableColumn(FacilitatorModel.SERVER_FILE,24);
217      column.setHeaderValue(facilitatorModel.getColumnName(FacilitatorModel.SERVER_FILE));
218      tm.addColumn(column);
219 /*
220      column = new TableColumn(FacilitatorModel.HAS_GUI,24,
221         new CheckBoxCellRenderer(), cellEditor);
222      column.setHeaderValue(facilitatorModel.getColumnName(FacilitatorModel.HAS_GUI));
223      tm.addColumn(column);
224 
225      column = new TableColumn(FacilitatorModel.EXTERNAL,24);
226      column.setHeaderValue(facilitatorModel.getColumnName(FacilitatorModel.EXTERNAL));
227      tm.addColumn(column);
228 */
229      column = new TableColumn(FacilitatorModel.PERIOD,24,
230         new DefaultTableCellRenderer(),
231 	new DefaultCellEditor(new RealNumberField(0,1000)));
232      column.setHeaderValue(facilitatorModel.getColumnName(FacilitatorModel.PERIOD));
233      tm.addColumn(column);
234 
235 
236      facilitatorTable = new JTable(facilitatorModel,tm);
237      facilitatorTable.getTableHeader().setReorderingAllowed(false);
238      facilitatorTable.setColumnSelectionAllowed(false);
239 
240      scrollPane = new JScrollPane(facilitatorTable);
241      scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
242      scrollPane.setPreferredSize(new Dimension(200,80));
243      facilitatorTable.setBackground(Color.white);
244 
245      border = (BorderFactory.createTitledBorder("Facilitators"));
246      border.setTitlePosition(TitledBorder.TOP);
247      border.setTitleJustification(TitledBorder.RIGHT);
248      border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
249      border.setTitleColor(Color.blue);
250      facilitatorPanel.setBorder(border);
251 
252      gbc = new GridBagConstraints();
253      toolbar = new UtilityToolBar(facilitatorTable,facilitatorModel,
254         "Generation Plan: Facilitators");
255 
256      gbc.gridwidth = GridBagConstraints.REMAINDER;
257      gbc.anchor = GridBagConstraints.WEST;
258      gbc.fill = GridBagConstraints.NONE;
259      gbc.weightx = gbc.weighty = 0;
260      gbc.insets = new Insets(0,8,0,0);
261      gridBagLayout.setConstraints(toolbar,gbc);
262      facilitatorPanel.add(toolbar);
263 
264      gbc.gridwidth = GridBagConstraints.REMAINDER;
265      gbc.anchor = GridBagConstraints.WEST;
266      gbc.fill = GridBagConstraints.BOTH;
267      gbc.weightx = gbc.weighty = 1;
268      gbc.insets = new Insets(8,8,8,8);
269      gridBagLayout.setConstraints(scrollPane,gbc);
270      facilitatorPanel.add(scrollPane);
271 
272      // Create visualisers panel info
273      visualiserModel = new VisualiserModel(genplan);
274 
275      gridBagLayout = new GridBagLayout();
276      visualiserPanel.setLayout(gridBagLayout);
277      visualiserPanel.setBackground(Color.lightGray);
278 
279      tm = new DefaultTableColumnModel();
280      checkbox = new JCheckBox();
281      checkbox.setHorizontalAlignment(JCheckBox.CENTER);
282      cellEditor = new DefaultCellEditor(checkbox);
283 
284      column = new TableColumn(VisualiserModel.NAME,24,
285         new DefaultTableCellRenderer(),
286 	new DefaultCellEditor(new NameField()));
287      column.setHeaderValue(visualiserModel.getColumnName(VisualiserModel.NAME));
288      tm.addColumn(column);
289 
290      column = new TableColumn(VisualiserModel.HOST,24);
291      column.setHeaderValue(visualiserModel.getColumnName(VisualiserModel.HOST));
292      tm.addColumn(column);
293 
294      column = new TableColumn(VisualiserModel.SERVER_FILE,24);
295      column.setHeaderValue(visualiserModel.getColumnName(VisualiserModel.SERVER_FILE));
296      tm.addColumn(column);
297 /*
298      column = new TableColumn(VisualiserModel.HAS_GUI,24,
299         new CheckBoxCellRenderer(), cellEditor);
300      column.setHeaderValue(visualiserModel.getColumnName(VisualiserModel.HAS_GUI));
301      tm.addColumn(column);
302 
303      column = new TableColumn(VisualiserModel.EXTERNAL,24);
304      column.setHeaderValue(visualiserModel.getColumnName(VisualiserModel.EXTERNAL));
305      tm.addColumn(column);
306 */
307      visualiserTable = new JTable(visualiserModel,tm);
308      visualiserTable.getTableHeader().setReorderingAllowed(false);
309      visualiserTable.setColumnSelectionAllowed(false);
310 
311      scrollPane = new JScrollPane(visualiserTable);
312      scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
313      scrollPane.setPreferredSize(new Dimension(200,80));
314      visualiserTable.setBackground(Color.white);
315 
316      border = (BorderFactory.createTitledBorder("Visualisers"));
317      border.setTitlePosition(TitledBorder.TOP);
318      border.setTitleJustification(TitledBorder.RIGHT);
319      border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
320      border.setTitleColor(Color.blue);
321      visualiserPanel.setBorder(border);
322 
323      gbc = new GridBagConstraints();
324      toolbar = new UtilityToolBar(visualiserTable,visualiserModel,
325         "Generation Plan: Visualisers");
326 
327      gbc.gridwidth = GridBagConstraints.REMAINDER;
328      gbc.anchor = GridBagConstraints.WEST;
329      gbc.fill = GridBagConstraints.NONE;
330      gbc.weightx = gbc.weighty = 0;
331      gbc.insets = new Insets(0,8,0,0);
332      gridBagLayout.setConstraints(toolbar,gbc);
333      visualiserPanel.add(toolbar);
334 
335      gbc.gridwidth = GridBagConstraints.REMAINDER;
336      gbc.anchor = GridBagConstraints.WEST;
337      gbc.fill = GridBagConstraints.BOTH;
338      gbc.weightx = gbc.weighty = 1;
339      gbc.insets = new Insets(8,8,8,8);
340      gridBagLayout.setConstraints(scrollPane,gbc);
341      visualiserPanel.add(scrollPane);
342 
343      // Create dbproxyspanel info
344      dbProxyModel = new DbProxyModel(genplan);
345 
346      gridBagLayout = new GridBagLayout();
347      dbProxyPanel.setLayout(gridBagLayout);
348      dbProxyPanel.setBackground(Color.lightGray);
349 
350      tm = new DefaultTableColumnModel();
351      checkbox = new JCheckBox();
352      checkbox.setHorizontalAlignment(JCheckBox.CENTER);
353      cellEditor = new DefaultCellEditor(checkbox);
354 
355      column = new TableColumn(DbProxyModel.NAME,24,
356         new DefaultTableCellRenderer(),
357 	new DefaultCellEditor(new NameField()));
358      column.setHeaderValue(dbProxyModel.getColumnName(DbProxyModel.NAME));
359      tm.addColumn(column);
360 
361      column = new TableColumn(DbProxyModel.HOST,24);
362      column.setHeaderValue(dbProxyModel.getColumnName(DbProxyModel.HOST));
363      tm.addColumn(column);
364 
365      column = new TableColumn(DbProxyModel.PATH,24);
366      column.setHeaderValue(dbProxyModel.getColumnName(DbProxyModel.PATH));
367      tm.addColumn(column);
368 
369      column = new TableColumn(DbProxyModel.SERVER_FILE,24);
370      column.setHeaderValue(dbProxyModel.getColumnName(DbProxyModel.SERVER_FILE));
371      tm.addColumn(column);
372 /*
373      column = new TableColumn(DbProxyModel.HAS_GUI,24,
374         new CheckBoxCellRenderer(), cellEditor);
375      column.setHeaderValue(dbProxyModel.getColumnName(DbProxyModel.HAS_GUI));
376      tm.addColumn(column);
377 
378      column = new TableColumn(DbProxyModel.EXTERNAL,24);
379      column.setHeaderValue(dbProxyModel.getColumnName(DbProxyModel.EXTERNAL));
380      tm.addColumn(column);
381 */
382      dbProxyTable = new JTable(dbProxyModel,tm);
383      dbProxyTable.getTableHeader().setReorderingAllowed(false);
384      dbProxyTable.setColumnSelectionAllowed(false);
385 
386      scrollPane = new JScrollPane(dbProxyTable);
387      scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
388      scrollPane.setPreferredSize(new Dimension(200,80));
389      dbProxyTable.setBackground(Color.white);
390 
391      border = (BorderFactory.createTitledBorder("Database Proxys"));
392      border.setTitlePosition(TitledBorder.TOP);
393      border.setTitleJustification(TitledBorder.RIGHT);
394      border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
395      border.setTitleColor(Color.blue);
396      dbProxyPanel.setBorder(border);
397 
398      gbc = new GridBagConstraints();
399      toolbar = new UtilityToolBar(dbProxyTable,dbProxyModel,
400         "Generation Plan: Database Proxys");
401 
402      gbc.gridwidth = GridBagConstraints.REMAINDER;
403      gbc.anchor = GridBagConstraints.WEST;
404      gbc.fill = GridBagConstraints.NONE;
405      gbc.weightx = gbc.weighty = 0;
406      gbc.insets = new Insets(0,8,0,0);
407      gridBagLayout.setConstraints(toolbar,gbc);
408      dbProxyPanel.add(toolbar);
409 
410      gbc.gridwidth = GridBagConstraints.REMAINDER;
411      gbc.anchor = GridBagConstraints.WEST;
412      gbc.fill = GridBagConstraints.BOTH;
413      gbc.weightx = gbc.weighty = 1;
414      gbc.insets = new Insets(8,8,8,8);
415      gridBagLayout.setConstraints(scrollPane,gbc);
416      dbProxyPanel.add(scrollPane);
417 
418   }
419 
420   protected class CheckBoxCellRenderer extends JCheckBox
421                                        implements TableCellRenderer,
422                                        java.io.Serializable {
423 
424      public CheckBoxCellRenderer() {
425         setHorizontalAlignment(JCheckBox.CENTER);
426      }
427 
428      public Component getTableCellRendererComponent(JTable table,
429         Object value, boolean isSelected, boolean hasFocus,
430         int row, int column) {
431 
432         if ( value != null )
433            this.setSelected(((Boolean)value).booleanValue());
434         return this;
435      }
436   }
437 
438   protected class UtilityToolBar extends JToolBar
439                                  implements ActionListener {
440 
441      protected JToggleButton helpBtn;
442      protected JButton       newBtn;
443      protected JButton       deleteBtn;
444      protected HelpWindow    helpWin;
445      protected JTable        table;
446      protected String        help_page;
447      protected UtilityModel  model;
448 
449      public UtilityToolBar(JTable table, UtilityModel model, String help_page) {
450         this.model = model;
451         this.table = table;
452         this.help_page = help_page;
453 
454         setBackground(Color.lightGray);
455         setBorder( new BevelBorder(BevelBorder.LOWERED ) );
456         setFloatable(false);
457         String path = SystemProps.getProperty("gif.dir") + "generator" +
458            System.getProperty("file.separator");
459 
460         // clear Button
461         newBtn = new JButton(new ImageIcon(path + "new1.gif" ));
462 	newBtn.setMargin(new Insets(0,0,0,0));
463         add(newBtn);
464         newBtn.setToolTipText("New entry");
465         newBtn.addActionListener(this);
466 
467         // All Button
468         deleteBtn = new JButton(new ImageIcon(path + "delete1.gif"));
469 	deleteBtn.setMargin(new Insets(0,0,0,0));
470         add(deleteBtn);
471         deleteBtn.setToolTipText("Delete selected entries");
472         deleteBtn.addActionListener(this);
473 
474         addSeparator();
475 
476         // Help Button
477         helpBtn = new JToggleButton(new ImageIcon(path + "help.gif"));
478 	helpBtn.setMargin(new Insets(0,0,0,0));
479         add(helpBtn);
480         helpBtn.setToolTipText("Help");
481         helpBtn.addActionListener(this);
482      }
483 
484      public void actionPerformed(ActionEvent e) {
485         Object src = e.getSource();
486         if ( src == newBtn )
487            model.addNewRow();
488         else if ( src == deleteBtn ) {
489            if ( table.getSelectedRow() == -1 ) {
490               errorMsg(0);
491               return;
492            }
493            else {
494               model.removeRows(table.getSelectedRows());
495               table.clearSelection();
496            }
497         }
498         else if ( src == helpBtn ) {
499            if ( helpBtn.isSelected() ) {
500               Point dispos = getLocation();
501               helpWin = new HelpWindow(SwingUtilities.getRoot(this),
502                                        dispos, "generator", help_page);
503               helpWin.setSource(helpBtn);
504            }
505            else {
506               helpWin.dispose();
507            }
508         }
509      }
510   }
511 
512   protected void errorMsg(int tag) {
513      JOptionPane.showMessageDialog(this,ERROR_MESSAGE[tag],
514                                    "Error", JOptionPane.ERROR_MESSAGE);
515   }
516 }