KickJava   Java API By Example, From Geeks To Geeks.

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


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  * DomainPathSelectionDialog.java
26  *
27  * Created on September 17, 2004, 11:54 AM
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 import java.awt.Insets JavaDoc;
45 import java.awt.GridBagConstraints JavaDoc;
46
47 public class DomainPathSelectionDialog extends javax.swing.JDialog JavaDoc {
48     
49     private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui");
50     private DomainPathTableModel domainPathTableModel= null;
51     private JTable domainPathTable = null;
52     private JScrollPane domainPathTableScrollPane = null;
53     private JPanel domainPathsPanel = null;
54     private JPanel addRemoveButtonsPanel = null;
55     private JButton addDomainPathButton = null;
56     private JButton removeDomainPathButton = null;
57     
58     private JFileChooser fileChooser = null;
59     
60     public static final int OK_ACTION = 2;
61     public static final int CANCEL_ACTION = 1;
62     public static final int HELP_ACTION = 3;
63     public int USER_ACTION = 1;
64     
65     private java.util.Vector JavaDoc dialogListeners = new java.util.Vector JavaDoc();
66     
67     /** Creates a new instance of DomainPathSelectionDialog */
68     public DomainPathSelectionDialog() {
69         this.setTitle(stringManager.getString("upgrade.gui.domainPanel.dialogTitle"));
70         this.initComponents();
71         super.setModal(true);
72     }
73     
74     private void initComponents(){
75         this.getContentPane().setLayout(new java.awt.GridBagLayout JavaDoc());
76         javax.swing.JSeparator JavaDoc separatorPanel = new javax.swing.JSeparator JavaDoc();
77         
78         this.addComponetWithConstraints(getDomainPathsPanel(), this.getContentPane(), 0, 0,1,1, GridBagConstraints.BOTH, new Insets JavaDoc(10, 0, 0, 5), 1.0,1.0);
79         this.addComponetWithConstraints(separatorPanel, this.getContentPane(), 0, 1,1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 0, 5), 1.0,0.0);
80         this.addComponetWithConstraints(getButtonsPanel(), this.getContentPane(), 0, 2,1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 0, 0, 0), 1.0,0.0);
81         getDomainPathTableScrollPane().setViewportView(getDomainPathTable());
82         
83         getDomainPathTable().setModel(this.getDomainPathTableModel());
84         getDomainPathTable().createDefaultColumnsFromModel();
85         
86         this.setSize(500, 350);
87     }
88     private javax.swing.JPanel JavaDoc getDomainPathsPanel() {
89         if (domainPathsPanel == null) {
90             domainPathsPanel = new javax.swing.JPanel JavaDoc();
91             domainPathsPanel.setName("domainPathsPanel");
92             domainPathsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
93             
94             JLabel tableTitleLabel = new JLabel();
95             tableTitleLabel.setText(stringManager.getString("upgrade.gui.domainPanel.tableTitleName"));
96             this.addComponetWithConstraints(tableTitleLabel, domainPathsPanel, 0, 0,3,1, GridBagConstraints.NONE, new Insets JavaDoc(10, 10, 5, 0), 0.0,0.0);
97             this.addComponetWithConstraints(getDomainPathTableScrollPane(), domainPathsPanel, 0, 1,2,1, GridBagConstraints.BOTH, new Insets JavaDoc(5, 10, 5, 0), 1.0,1.0);
98             this.addComponetWithConstraints(getaddRemoveButtonsPanel(), domainPathsPanel, 2, 1,1,1, GridBagConstraints.VERTICAL, new Insets JavaDoc(5, 0, 5, 0), 0.0,1.0);
99         }
100         return domainPathsPanel;
101     }
102     private javax.swing.JTable JavaDoc getDomainPathTable() {
103         if (domainPathTable == null) {
104             domainPathTable = new javax.swing.JTable JavaDoc();
105             domainPathTable.setName("domainPathTable");
106             getDomainPathTableScrollPane().setColumnHeaderView(domainPathTable.getTableHeader());
107             getDomainPathTableScrollPane().getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE);
108             domainPathTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
109             domainPathTable.setAutoCreateColumnsFromModel(true);
110             domainPathTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
111             domainPathTable.setAutoCreateColumnsFromModel(true);
112             
113             ListSelectionModel rowSM = domainPathTable.getSelectionModel();
114             rowSM.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
115                 public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc e) {
116                     //Ignore extra messages.
117
if (e.getValueIsAdjusting()) return;
118                     
119                     ListSelectionModel lsm = (ListSelectionModel)e.getSource();
120                     enableDisableRemoveButton(domainPathTable,getremoveDomainPathButton());
121                 }
122             });
123             final DefaultCellEditor editor = (DefaultCellEditor)domainPathTable.getDefaultEditor(String JavaDoc.class);
124             editor.getComponent().addKeyListener(new java.awt.event.KeyAdapter JavaDoc(){
125                 public void keyReleased(java.awt.event.KeyEvent JavaDoc ke){
126                     try{
127                         getDomainPathTableModel().setValueAt(((JTextField)editor.getComponent()).getText().trim(),domainPathTable.getEditingRow(),0);
128                     }catch(Exception JavaDoc e){
129                     }
130                 }
131                 
132             });
133             
134         }
135         return domainPathTable;
136     }
137     private javax.swing.JScrollPane JavaDoc getDomainPathTableScrollPane() {
138         if (domainPathTableScrollPane == null) {
139             domainPathTableScrollPane = new javax.swing.JScrollPane JavaDoc();
140             domainPathTableScrollPane.setName("getDomainPathTable");
141             domainPathTableScrollPane.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
142             domainPathTableScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
143             domainPathTableScrollPane.setMaximumSize(new java.awt.Dimension JavaDoc(21, 20));
144             domainPathTableScrollPane.setPreferredSize(new java.awt.Dimension JavaDoc(21, 20));
145             domainPathTableScrollPane.setMinimumSize(new java.awt.Dimension JavaDoc(21, 20));
146             domainPathTableScrollPane.setViewportView(getDomainPathTable());
147         }
148         return domainPathTableScrollPane;
149     }
150     private javax.swing.JPanel JavaDoc getaddRemoveButtonsPanel() {
151         if (addRemoveButtonsPanel == null) {
152             addRemoveButtonsPanel = new javax.swing.JPanel JavaDoc();
153             addRemoveButtonsPanel.setName("addRemoveButtonsPanel");
154             addRemoveButtonsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
155             
156             this.addComponetWithConstraints(getaddDomainPathButton(), addRemoveButtonsPanel, 0, 0,1,1, GridBagConstraints.NONE, new Insets JavaDoc(10, 5, 5, 5), 0.0,0.0);
157             this.addComponetWithConstraints(getremoveDomainPathButton(), addRemoveButtonsPanel, 0, 1,1,1, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0.0,0.0);
158         }
159         return addRemoveButtonsPanel;
160     }
161     private javax.swing.JButton JavaDoc getaddDomainPathButton() {
162         if (addDomainPathButton == null) {
163             addDomainPathButton = new javax.swing.JButton JavaDoc();
164             addDomainPathButton.setName("addDomainPathButton");
165             addDomainPathButton.setText(stringManager.getString("upgrade.gui.domainPanel.addButtonText"));
166             addDomainPathButton.addActionListener(new java.awt.event.ActionListener JavaDoc(){
167                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
168                     addDomainPathAction();
169                 }
170             });
171         }
172         return addDomainPathButton;
173     }
174     private javax.swing.JButton JavaDoc getremoveDomainPathButton() {
175         if (removeDomainPathButton == null) {
176             removeDomainPathButton = new javax.swing.JButton JavaDoc();
177             removeDomainPathButton.setName("removeDomainPathButton");
178             removeDomainPathButton.setText(stringManager.getString("upgrade.gui.domainPanel.deleteButtonText"));
179             removeDomainPathButton.addActionListener(new java.awt.event.ActionListener JavaDoc(){
180                 public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
181                     removeDomainPathAction();
182                 }
183             });
184         }
185         return removeDomainPathButton;
186     }
187     private javax.swing.JPanel JavaDoc getButtonsPanel(){
188         javax.swing.JPanel JavaDoc buttonsPanel = new javax.swing.JPanel JavaDoc();
189         javax.swing.JButton JavaDoc okButton = new javax.swing.JButton JavaDoc();
190         javax.swing.JButton JavaDoc cancelButton = new javax.swing.JButton JavaDoc();
191         javax.swing.JButton JavaDoc helpButton = new javax.swing.JButton JavaDoc();
192         buttonsPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
193         
194         okButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.okButtonText"));
195         okButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
196             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
197                 okButtonActionPerformed();
198             }
199         });
200         this.addComponetWithConstraints(okButton, buttonsPanel, 1, 0, 1,1, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 10, 10), 0.0,0.0);
201         
202         cancelButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.cancelButtonText"));
203         cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
204             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
205                 cancelButtonActionPerformed();
206             }
207         });
208         this.addComponetWithConstraints(cancelButton, buttonsPanel, 2, 0, 1,1, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 10, 10), 0.0,0.0);
209         
210         helpButton.setText(stringManager.getString("upgrade.gui.adddomainpanel.helpButtonText"));
211         helpButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
212             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
213                 helpButtonActionPerformed();
214             }
215         });
216         this.addComponetWithConstraints(helpButton, buttonsPanel, 3, 0, 1,1, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 10, 10), 0.0,0.0);
217         this.addComponetWithConstraints(new JPanel(), buttonsPanel, 0, 0, 1,1, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 10, 10), 1.0,0.0);
218         if(Utils.getHelpBroker() != null)
219             Utils.getHelpBroker().enableHelpOnButton(helpButton, "ADD_DOMAIN_DIALOG", null);
220         return buttonsPanel;
221     }
222     private void addComponetWithConstraints(JComponent compo, java.awt.Container JavaDoc parent, int gx, int gy, int gw, int gh, int fill,java.awt.Insets JavaDoc in,
223     double wx, double wy){
224         java.awt.GridBagConstraints JavaDoc gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
225         gridBagConstraints.gridx = gx; gridBagConstraints.gridy = gy;
226         gridBagConstraints.gridwidth = gw; gridBagConstraints.gridheight = gh;
227         gridBagConstraints.fill = fill;
228         gridBagConstraints.insets = in;
229         gridBagConstraints.weightx = wx;
230         gridBagConstraints.weighty = wy;
231         parent.add(compo, gridBagConstraints);
232     }
233     private void helpButtonActionPerformed() {
234         this.USER_ACTION = HELP_ACTION;
235         //this.dispose();
236
/*DialogEvent de = new DialogEvent(this, DialogEvent.HELP_ACTION);
237         for(int i=0 ; i<this.dialogListeners.size(); i++){
238             ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
239         }*/

240     }
241     
242     private void cancelButtonActionPerformed() {
243         this.USER_ACTION = CANCEL_ACTION;
244         this.dispose();
245         /*DialogEvent de = new DialogEvent(this, DialogEvent.CANCEL_ACTION);
246         for(int i=0 ; i<this.dialogListeners.size(); i++){
247             ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
248         }*/

249     }
250     
251     private void okButtonActionPerformed() {
252         this.USER_ACTION = OK_ACTION;
253         this.dispose();
254     }
255     public DomainPathTableModel getDomainPathTableModel(){
256         if(this.domainPathTableModel == null){
257             domainPathTableModel = new DomainPathTableModel(this);
258         }
259         return domainPathTableModel;
260     }
261     public void addDomainPathAction() {
262         int returnedValue = getfileChooser().showOpenDialog(this);
263         if(returnedValue == javax.swing.JFileChooser.APPROVE_OPTION){
264             getDomainPathTableModel().addDomainPath(String.valueOf(getfileChooser().getSelectedFile()));
265         }
266     }
267     private javax.swing.JFileChooser JavaDoc getfileChooser() {
268         if (fileChooser == null) {
269             fileChooser = new javax.swing.JFileChooser JavaDoc();
270             fileChooser.setName("fileChooser");
271             fileChooser.setBounds(668, 49, 500, 300);
272             fileChooser.setDialogTitle(stringManager.getString("upgrade.gui.certpanel.chooseFile"));
273             fileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
274         }
275         return fileChooser;
276     }
277     public void removeDomainPathAction() {
278         
279         int rows[] = getDomainPathTable().getSelectedRows();
280         String JavaDoc[] rowPropNames = new String JavaDoc[rows.length];
281         int option =
282         javax.swing.JOptionPane.showConfirmDialog(
283         this,
284         stringManager.getString("upgrade.gui.domainPanel.removeConfirmMsg"),
285         stringManager.getString("upgrade.gui.domainPanel.removeConfirmTitle"),
286         javax.swing.JOptionPane.YES_NO_OPTION,
287         javax.swing.JOptionPane.QUESTION_MESSAGE);
288         if (option == javax.swing.JOptionPane.NO_OPTION) {
289             return;
290         }
291         
292         for (int i = 0; i < rows.length; i++) {
293             rowPropNames[i] =
294             (String JavaDoc)getDomainPathTableModel().getDomainPath(rows[i]);
295         }
296         for (int i = 0; i < rows.length; i++) {
297             getDomainPathTableModel().removeDomainPath(rowPropNames[i]);
298         }
299         // Un select items rows in table.
300
getDomainPathTable().clearSelection();
301         enableDisableRemoveButton(getDomainPathTable(), getremoveDomainPathButton());
302     }
303     
304     class DomainPathTableModel extends javax.swing.table.AbstractTableModel JavaDoc {
305         private Vector domainPaths = new Vector(0);
306         private String JavaDoc columnNames[] = null;
307         private DomainPathSelectionDialog domainPathSelectionDialog;
308         
309         private StringManager stringManager = StringManager.getManager("com.sun.enterprise.tools.upgrade.gui");
310         public DomainPathTableModel(DomainPathSelectionDialog cdp) {
311             super();
312             this.domainPathSelectionDialog = cdp;
313             columnNames = new String JavaDoc[]{stringManager.getString("upgrade.gui.domainPanel.tableColumnName")};
314         }
315         public int getColumnCount() {
316             return columnNames.length;
317         }
318         public java.lang.String JavaDoc getColumnName(int column) {
319             return columnNames[column];
320         }
321         public int getRowCount() {
322             return domainPaths.size();
323         }
324         public boolean isCellEditable(int row, int col) {
325             //Note that the data/cell address is constant,
326
//no matter where the cell appears onscreen.
327
if (col == 0) {
328                 return true;
329             } else {
330                 return false;
331             }
332         }
333         public void setValueAt(Object JavaDoc value, int row, int col) {
334             
335             if ( value instanceof String JavaDoc) {
336                 if(row < domainPaths.size())
337                     domainPaths.setElementAt(value,row);
338             }
339         }
340         public Class JavaDoc getColumnClass(int c) {
341             return getValueAt(0, c).getClass();
342         }
343         public Object JavaDoc getValueAt(int row, int col) {
344             String JavaDoc rowEle = (String JavaDoc) domainPaths.elementAt(row);
345             String JavaDoc ret = "";
346             switch (col) {
347                 case 0:
348                     // Column 0 is the filename
349
ret = rowEle;
350                     break;
351                     
352             }
353             return ret;
354             
355         }
356         public Vector getDomainPaths(){
357             return this.domainPaths;
358         }
359         public void setDomainPaths(Vector v){
360             this.domainPaths=v;
361         }
362         public void addDomainPath(String JavaDoc ele){
363             if(ele != null){
364                 if(getDomainPath(ele) == null)
365                     this.domainPaths.addElement(ele);
366             }
367             fireTableDataChanged();
368             domainPathSelectionDialog.processDialogEvent();
369         }
370         public void removeDomainPath(String JavaDoc ele){
371             if(ele != null){
372                 this.domainPaths.removeElement(ele);
373             }
374             fireTableDataChanged();
375             domainPathSelectionDialog.processDialogEvent();
376         }
377         public String JavaDoc getDomainPath(int rowNo){
378             if(rowNo < domainPaths.size()){
379                 return (String JavaDoc)domainPaths.elementAt(rowNo);
380             }
381             else return null;
382         }
383         public String JavaDoc getDomainPath(String JavaDoc propName){
384             String JavaDoc ele1 = null;
385             boolean found = false;
386             if(propName != null){
387                 for(int i=0; i<domainPaths.size(); i++){
388                     ele1 = (String JavaDoc)domainPaths.elementAt(i);
389                     if(propName.equals(ele1)){
390                         found = true;
391                         break;
392                     }
393                 }
394             }
395             if(found)
396                 return ele1;
397             else
398                 return null;
399         }
400         
401     }
402     public void enableDisableRemoveButton(JTable table,JButton removeButton) {
403         if (table.getSelectionModel().isSelectionEmpty()) {
404             removeButton.setEnabled(false);
405             
406         } else {
407             if (table.getSelectedRowCount() > 1) {
408                 //editButton.setEnabled(false);
409
} else {
410                 removeButton.setEnabled(true);
411             }
412         }
413     }
414     public void addDialogListener(DialogListener listener){
415         this.dialogListeners.addElement(listener);
416     }
417     public void removeDialogListener(DialogListener listener){
418         this.dialogListeners.removeElement(listener);
419     }
420     private void processDialogEvent(){
421         DialogEvent de = new DialogEvent(this, DialogEvent.CHANGE_ACTION);
422         for(int i=0 ; i<this.dialogListeners.size(); i++){
423             ((DialogListener)dialogListeners.elementAt(i)).dialogProcessed(de);
424         }
425     }
426     
427 }
428
Popular Tags