KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > gui > ClusterDetailsPanel


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * ClusterDetailsPanel.java
26  *
27  * Created on May 27, 2004, 5:22 PM
28  */

29
30 package com.sun.enterprise.tools.upgrade.gui;
31
32 /**
33  *
34  * @author prakash
35  */

36
37 import com.sun.enterprise.tools.upgrade.gui.util.*;
38 import java.util.logging.*;
39 import com.sun.enterprise.util.i18n.StringManager;
40 import com.sun.enterprise.tools.upgrade.common.*;
41 import com.sun.enterprise.tools.upgrade.logging.*;
42 import javax.swing.*;
43 import java.util.*;
44
45 public class ClusterDetailsPanel extends javax.swing.JPanel JavaDoc {
46     
47     private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui");
48     private ClusterFilesTableModel clusterFilesTableModel= null;
49     private JTable clusterFilesTable = null;
50     private JScrollPane clusterFilesTableScrollPane = null;
51     private JPanel clusterFilesPanel = null;
52     private JPanel addRemoveEditHomeInterfacePanel = null;
53     private JButton addClusterFileButton = null;
54     private JButton removeClusterFileButton = null;
55     
56     private JFileChooser fileChooser = null;
57     
58     private java.util.Vector JavaDoc dialogListeners = new java.util.Vector JavaDoc();
59
60     /** Creates a new instance of ClusterDetailsPanel */
61     public ClusterDetailsPanel() {
62         this.initComponents();
63     }
64     private void initComponents(){
65         this.setLayout(new java.awt.GridBagLayout JavaDoc());
66         
67         java.awt.GridBagConstraints JavaDoc constraints = new java.awt.GridBagConstraints JavaDoc();
68         constraints.gridx = 0; constraints.gridy = 0;
69         constraints.gridwidth = 1;
70         constraints.fill = java.awt.GridBagConstraints.BOTH;
71         constraints.weightx = 1.0;
72         constraints.weighty = 1.0;
73         constraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 0);
74         this.add(getClusterFilesPanel(), constraints);
75         
76         getClusterFilesTableScrollPane().setViewportView(getClusterFilesTable());
77         
78         getClusterFilesTable().setModel(this.getClusterFilesTableModel());
79         getClusterFilesTable().createDefaultColumnsFromModel();
80         
81     }
82     private javax.swing.JPanel JavaDoc getClusterFilesPanel() {
83     if (clusterFilesPanel == null) {
84             clusterFilesPanel = new javax.swing.JPanel JavaDoc();
85             clusterFilesPanel.setName("clusterFilesPanel");
86             clusterFilesPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
87                         
88             JLabel tableTitleLabel = new JLabel();
89             tableTitleLabel.setText(stringManager.getString("upgrade.gui.clusterPanel.tableTitleName"));
90             java.awt.GridBagConstraints JavaDoc labelConstraints = new java.awt.GridBagConstraints JavaDoc();
91             labelConstraints.gridx = 0; labelConstraints.gridy = 0;
92             labelConstraints.gridwidth = 3;
93             labelConstraints.fill = java.awt.GridBagConstraints.NONE;
94             labelConstraints.insets = new java.awt.Insets JavaDoc(10, 10, 5, 0);
95             clusterFilesPanel.add(tableTitleLabel, labelConstraints);
96             
97             java.awt.GridBagConstraints JavaDoc constraintsClusterScrollPane1 = new java.awt.GridBagConstraints JavaDoc();
98             constraintsClusterScrollPane1.gridx = 0; constraintsClusterScrollPane1.gridy = 1;
99             constraintsClusterScrollPane1.gridwidth = 2;
100             constraintsClusterScrollPane1.fill = java.awt.GridBagConstraints.BOTH;
101             constraintsClusterScrollPane1.weightx = 1.0;
102             constraintsClusterScrollPane1.weighty = 1.0;
103             constraintsClusterScrollPane1.insets = new java.awt.Insets JavaDoc(5, 10, 5, 0);
104             clusterFilesPanel.add(getClusterFilesTableScrollPane(), constraintsClusterScrollPane1);
105             
106             java.awt.GridBagConstraints JavaDoc constraintsaddRemoveEditHomeInterfacePanel1 = new java.awt.GridBagConstraints JavaDoc();
107             constraintsaddRemoveEditHomeInterfacePanel1.gridx = 2; constraintsaddRemoveEditHomeInterfacePanel1.gridy = 1;
108             constraintsaddRemoveEditHomeInterfacePanel1.fill = java.awt.GridBagConstraints.VERTICAL;
109             constraintsaddRemoveEditHomeInterfacePanel1.weighty = 1.0;
110             constraintsaddRemoveEditHomeInterfacePanel1.insets = new java.awt.Insets JavaDoc(5, 0, 5, 0);
111             clusterFilesPanel.add(getaddRemoveEditHomeInterfacePanel(), constraintsaddRemoveEditHomeInterfacePanel1);
112         }
113     return clusterFilesPanel;
114     }
115     private javax.swing.JTable JavaDoc getClusterFilesTable() {
116         if (clusterFilesTable == null) {
117             clusterFilesTable = new javax.swing.JTable JavaDoc();
118             clusterFilesTable.setName("clusterFilesTable");
119             getClusterFilesTableScrollPane().setColumnHeaderView(clusterFilesTable.getTableHeader());
120             getClusterFilesTableScrollPane().getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
121             clusterFilesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
122             clusterFilesTable.setAutoCreateColumnsFromModel(true);
123             clusterFilesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
124             clusterFilesTable.setAutoCreateColumnsFromModel(true);
125             
126             ListSelectionModel rowSM = clusterFilesTable.getSelectionModel();
127             rowSM.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
128                 public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc e) {
129                     //Ignore extra messages.
130
if (e.getValueIsAdjusting()) return;
131                     
132                     ListSelectionModel lsm = (ListSelectionModel)e.getSource();
133                     enableDisableRemoveButton(clusterFilesTable,getremoveClusterFileButton());
134                 }
135             });
136             final DefaultCellEditor editor = (DefaultCellEditor)clusterFilesTable.getDefaultEditor(String JavaDoc.class);
137             editor.getComponent().addKeyListener(new java.awt.event.KeyAdapter JavaDoc(){
138                 public void keyReleased(java.awt.event.KeyEvent JavaDoc ke){
139                     try{
140                         getClusterFilesTableModel().setValueAt(((JTextField)editor.getComponent()).getText().trim(),clusterFilesTable.getEditingRow(),0);
141                     }catch(Exception JavaDoc e){
142                     }
143                 }
144                 
145             });
146             
147         }
148         return clusterFilesTable;
149     }
150     private javax.swing.JScrollPane JavaDoc getClusterFilesTableScrollPane() {
151         if (clusterFilesTableScrollPane == null) {
152             clusterFilesTableScrollPane = new javax.swing.JScrollPane JavaDoc();
153             clusterFilesTableScrollPane.setName("getClusterFilesTable");
154             clusterFilesTableScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
155             clusterFilesTableScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
156             clusterFilesTableScrollPane.setMaximumSize(new java.awt.Dimension JavaDoc(21, 20));
157             clusterFilesTableScrollPane.setPreferredSize(new java.awt.Dimension JavaDoc(21, 20));
158             clusterFilesTableScrollPane.setMinimumSize(new java.awt.Dimension JavaDoc(21, 20));
159             clusterFilesTableScrollPane.setViewportView(getClusterFilesTable());
160         }
161         return clusterFilesTableScrollPane;
162     }
163     private javax.swing.JPanel JavaDoc getaddRemoveEditHomeInterfacePanel() {
164         if (addRemoveEditHomeInterfacePanel == null) {
165             addRemoveEditHomeInterfacePanel = new javax.swing.JPanel JavaDoc();
166             addRemoveEditHomeInterfacePanel.setName("addRemoveEditHomeInterfacePanel");
167             addRemoveEditHomeInterfacePanel.setLayout(new java.awt.GridBagLayout JavaDoc());
168             
169             java.awt.GridBagConstraints JavaDoc constraintsaddClusterFileButton = new java.awt.GridBagConstraints JavaDoc();
170             constraintsaddClusterFileButton.gridx = 0; constraintsaddClusterFileButton.gridy = 0;
171             constraintsaddClusterFileButton.insets = new java.awt.Insets JavaDoc(10, 5, 5, 5);
172             addRemoveEditHomeInterfacePanel.add(getaddClusterFileButton(), constraintsaddClusterFileButton);
173             
174             java.awt.GridBagConstraints JavaDoc constraintsremoveClusterFileButton = new java.awt.GridBagConstraints JavaDoc();
175             constraintsremoveClusterFileButton.gridx = 0; constraintsremoveClusterFileButton.gridy = 1;
176             constraintsremoveClusterFileButton.insets = new java.awt.Insets JavaDoc(5, 5, 5, 5);
177             addRemoveEditHomeInterfacePanel.add(getremoveClusterFileButton(), constraintsremoveClusterFileButton);
178         }
179         return addRemoveEditHomeInterfacePanel;
180     }
181     private javax.swing.JButton JavaDoc getaddClusterFileButton() {
182         if (addClusterFileButton == null) {
183             addClusterFileButton = new javax.swing.JButton JavaDoc();
184             addClusterFileButton.setName("addClusterFileButton");
185             addClusterFileButton.setText(stringManager.getString("upgrade.gui.clusterPanel.addButtonText"));
186             addClusterFileButton.addActionListener(new java.awt.event.ActionListener JavaDoc(){
187                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
188                     addClusterFileAction();
189                 }
190             });
191         }
192         return addClusterFileButton;
193     }
194     private javax.swing.JButton JavaDoc getremoveClusterFileButton() {
195         if (removeClusterFileButton == null) {
196             removeClusterFileButton = new javax.swing.JButton JavaDoc();
197             removeClusterFileButton.setName("removeClusterFileButton");
198             removeClusterFileButton.setText(stringManager.getString("upgrade.gui.clusterPanel.deleteButtonText"));
199             removeClusterFileButton.addActionListener(new java.awt.event.ActionListener JavaDoc(){
200                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
201                     removeClusterFileAction();
202                 }
203             });
204         }
205         return removeClusterFileButton;
206     }
207     public ClusterFilesTableModel getClusterFilesTableModel(){
208     if(this.clusterFilesTableModel == null){
209         clusterFilesTableModel = new ClusterFilesTableModel(this);
210     }
211     return clusterFilesTableModel;
212     }
213     public void addClusterFileAction() {
214         int returnedValue = getfileChooser().showOpenDialog(this);
215         if(returnedValue == javax.swing.JFileChooser.APPROVE_OPTION){
216             getClusterFilesTableModel().addClusterFile(String.valueOf(getfileChooser().getSelectedFile()));
217         }
218     }
219     private javax.swing.JFileChooser JavaDoc getfileChooser() {
220         if (fileChooser == null) {
221             fileChooser = new javax.swing.JFileChooser JavaDoc();
222             fileChooser.setName("fileChooser");
223             fileChooser.setBounds(668, 49, 500, 300);
224             fileChooser.setDialogTitle(stringManager.getString("upgrade.gui.certpanel.chooseFile"));
225         }
226         return fileChooser;
227     }
228     public void removeClusterFileAction() {
229     
230     int rows[] = getClusterFilesTable().getSelectedRows();
231     String JavaDoc[] rowPropNames = new String JavaDoc[rows.length];
232     int option =
233         javax.swing.JOptionPane.showConfirmDialog(
234                               this,
235                               stringManager.getString("upgrade.gui.clusterPanel.removeConfirmMsg"),
236                                                       stringManager.getString("upgrade.gui.clusterPanel.removeConfirmTitle"),
237                               javax.swing.JOptionPane.YES_NO_OPTION,
238                               javax.swing.JOptionPane.QUESTION_MESSAGE);
239     if (option == javax.swing.JOptionPane.NO_OPTION) {
240         return;
241     }
242
243     for (int i = 0; i < rows.length; i++) {
244         rowPropNames[i] =
245         (String JavaDoc)getClusterFilesTableModel().getClusterFile(rows[i]);
246     }
247     for (int i = 0; i < rows.length; i++) {
248         getClusterFilesTableModel().removeClusterFile(rowPropNames[i]);
249     }
250     // Un select items rows in table.
251
getClusterFilesTable().clearSelection();
252     enableDisableRemoveButton(getClusterFilesTable(), getremoveClusterFileButton());
253     }
254
255     class ClusterFilesTableModel extends javax.swing.table.AbstractTableModel JavaDoc {
256         private Vector clusterFiles = new Vector(0);
257     private String JavaDoc columnNames[] = null;
258         private ClusterDetailsPanel clusterDetailsPanel;
259         
260         private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui");
261     public ClusterFilesTableModel(ClusterDetailsPanel cdp) {
262         super();
263             this.clusterDetailsPanel = cdp;
264             columnNames = new String JavaDoc[]{stringManager.getString("upgrade.gui.clusterPanel.tableColumnName")};
265     }
266     public int getColumnCount() {
267         return columnNames.length;
268     }
269     public java.lang.String JavaDoc getColumnName(int column) {
270         return columnNames[column];
271     }
272         public int getRowCount() {
273         return clusterFiles.size();
274     }
275     public boolean isCellEditable(int row, int col) {
276         //Note that the data/cell address is constant,
277
//no matter where the cell appears onscreen.
278
if (col == 0) {
279         return true;
280         } else {
281         return false;
282         }
283     }
284     public void setValueAt(Object JavaDoc value, int row, int col) {
285             
286         if ( value instanceof String JavaDoc) {
287         if(row < clusterFiles.size())
288             clusterFiles.setElementAt(value,row);
289         }
290     }
291     public Class JavaDoc getColumnClass(int c) {
292         return getValueAt(0, c).getClass();
293     }
294     public Object JavaDoc getValueAt(int row, int col) {
295         //System.out.println("in getValueAt row="+row+" col="+col);
296
String JavaDoc rowEle = (String JavaDoc) clusterFiles.elementAt(row);
297         String JavaDoc ret = "";
298         switch (col) {
299         case 0:
300         // Column 0 is the filename
301
ret = rowEle;
302         break;
303                 
304         }
305         return ret;
306             
307     }
308     public Vector getClusterFiles(){
309         return this.clusterFiles;
310     }
311     public void setClusterFiles(Vector v){
312         this.clusterFiles=v;
313     }
314     public void addClusterFile(String JavaDoc ele){
315         if(ele != null){
316         if(getClusterFile(ele) == null)
317             this.clusterFiles.addElement(ele);
318         }
319         fireTableDataChanged();
320             clusterDetailsPanel.processDialogEvent();
321     }
322     public void removeClusterFile(String JavaDoc ele){
323         if(ele != null){
324         this.clusterFiles.removeElement(ele);
325         }
326         fireTableDataChanged();
327             clusterDetailsPanel.processDialogEvent();
328     }
329     public String JavaDoc getClusterFile(int rowNo){
330         if(rowNo < clusterFiles.size()){
331         return (String JavaDoc)clusterFiles.elementAt(rowNo);
332         }
333         else return null;
334     }
335     public String JavaDoc getClusterFile(String JavaDoc propName){
336         String JavaDoc ele1 = null;
337         boolean found = false;
338         if(propName != null){
339         for(int i=0; i<clusterFiles.size(); i++){
340             ele1 = (String JavaDoc)clusterFiles.elementAt(i);
341             if(propName.equals(ele1)){
342             found = true;
343             break;
344             }
345         }
346             }
347         if(found)
348         return ele1;
349         else
350         return null;
351     }
352
353     }
354     public void enableDisableRemoveButton(JTable table,JButton removeButton) {
355     if (table.getSelectionModel().isSelectionEmpty()) {
356         //no rows are selected
357
// Need to remove disable remove and edit buttons.
358
removeButton.setEnabled(false);
359         
360     } else {
361         //int selectedRow = lsm.getMinSelectionIndex();
362
if (table.getSelectedRowCount() > 1) {
363         //editButton.setEnabled(false);
364
} else {
365         removeButton.setEnabled(true);
366         //editButton.setEnabled(true);
367
}
368
369         //selectedRow is selected
370
}
371     }
372     public void addDialogListener(DialogListener listener){
373         this.dialogListeners.addElement(listener);
374     }
375     public void removeDialogListener(DialogListener listener){
376         this.dialogListeners.removeElement(listener);
377     }
378     private void processDialogEvent(){
379         DialogEvent de = new DialogEvent(this, DialogEvent.CHANGE_ACTION);
380         for(int i=0 ; i<this.dialogListeners.size(); i++){
381             ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
382         }
383     }
384
385 }
386
Popular Tags