KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > struts > dialogs > AddForwardDialogPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.struts.dialogs;
21
22 import java.util.Iterator JavaDoc;
23 import java.util.List JavaDoc;
24 import javax.swing.AbstractButton JavaDoc;
25 import javax.swing.DefaultComboBoxModel JavaDoc;
26 import javax.swing.text.JTextComponent JavaDoc;
27 import org.netbeans.modules.web.api.webmodule.WebModule;
28 import org.netbeans.modules.web.struts.StrutsConfigDataObject;
29 import org.netbeans.modules.web.struts.StrutsConfigUtilities;
30 import org.netbeans.modules.web.struts.config.model.Action;
31 import org.openide.util.NbBundle;
32
33 /**
34  *
35  * @author radko
36  */

37 public class AddForwardDialogPanel extends javax.swing.JPanel JavaDoc implements ValidatingPanel {
38     StrutsConfigDataObject config;
39     /** Creates new form AddForwardDialog */
40     public AddForwardDialogPanel(StrutsConfigDataObject config, String JavaDoc targetActionPath) {
41         this.config=config;
42         initComponents();
43         List JavaDoc actions = StrutsConfigUtilities.getAllActionsInModule(config);
44         DefaultComboBoxModel JavaDoc model = (DefaultComboBoxModel JavaDoc)jComboBoxFwdAction.getModel();
45         DefaultComboBoxModel JavaDoc model1 = (DefaultComboBoxModel JavaDoc)jComboBoxLocationAction.getModel();
46         Iterator JavaDoc iter = actions.iterator();
47         while (iter.hasNext()) {
48             String JavaDoc actionPath=((Action)iter.next()).getAttributeValue("path"); //NOI18N
49
model.addElement(actionPath);
50             model1.addElement(actionPath);
51         }
52         if (targetActionPath != null) {
53             jRadioButtonLocationAction.setSelected(true);
54             jComboBoxLocationAction.setSelectedItem(targetActionPath);
55         }
56     }
57     public AddForwardDialogPanel(StrutsConfigDataObject config) {
58         this(config,null);
59     }
60
61     public String JavaDoc validatePanel() {
62         if (getForwardName().length()==0)
63             return NbBundle.getMessage(AddActionPanel.class,"MSG_EmptyForwardName");
64         if (jRadioButtonResFile.isSelected()) {
65             String JavaDoc resourceFile = jTextFieldResFile.getText().trim();
66             if (resourceFile.length()==0 || resourceFile.equals("/")) //NOI18N
67
return NbBundle.getMessage(AddActionPanel.class,"MSG_EmptyResourceFile");
68         } else if (jComboBoxFwdAction.getSelectedItem()==null) {
69             return NbBundle.getMessage(AddActionPanel.class,"MSG_EmptyAction");
70         }
71         if (jRadioButtonLocationAction.isSelected() && jComboBoxLocationAction.getSelectedItem()==null) {
72             return NbBundle.getMessage(AddActionPanel.class,"MSG_EmptyAction");
73         }
74         return null;
75     }
76
77     public AbstractButton JavaDoc[] getStateChangeComponents() {
78         return new AbstractButton JavaDoc[] {jRadioButtonResFile, jRadioButtonGlobal};
79     }
80
81     public JTextComponent JavaDoc[] getDocumentChangeComponents() {
82         return new JTextComponent JavaDoc[]{jTextFieldFwdName, jTextFieldResFile};
83     }
84     
85     /** This method is called from within the constructor to
86      * initialize the form.
87      * WARNING: Do NOT modify this code. The content of this method is
88      * always regenerated by the Form Editor.
89      */

90     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
91
private void initComponents() {
92         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
93
94         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
95         buttonGroup2 = new javax.swing.ButtonGroup JavaDoc();
96         jLabelFwdName = new javax.swing.JLabel JavaDoc();
97         jTextFieldFwdName = new javax.swing.JTextField JavaDoc();
98         jLabelFwdTo = new javax.swing.JLabel JavaDoc();
99         jRadioButtonResFile = new javax.swing.JRadioButton JavaDoc();
100         jTextFieldResFile = new javax.swing.JTextField JavaDoc();
101         jButtonBrowse = new javax.swing.JButton JavaDoc();
102         jRadioButtonFwdAction = new javax.swing.JRadioButton JavaDoc();
103         jComboBoxFwdAction = new javax.swing.JComboBox JavaDoc();
104         jCheckBoxRedirect = new javax.swing.JCheckBox JavaDoc();
105         jLabelLocation = new javax.swing.JLabel JavaDoc();
106         jRadioButtonGlobal = new javax.swing.JRadioButton JavaDoc();
107         jRadioButtonLocationAction = new javax.swing.JRadioButton JavaDoc();
108         jComboBoxLocationAction = new javax.swing.JComboBox JavaDoc();
109
110         setLayout(new java.awt.GridBagLayout JavaDoc());
111
112         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
113         getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_AddForwardDialog"));
114         jLabelFwdName.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_FwdName").charAt(0));
115         jLabelFwdName.setLabelFor(jTextFieldFwdName);
116         jLabelFwdName.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_ForwardName"));
117         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
118         gridBagConstraints.gridx = 0;
119         gridBagConstraints.gridy = 0;
120         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
121         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 12);
122         add(jLabelFwdName, gridBagConstraints);
123
124         jTextFieldFwdName.setColumns(30);
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.gridx = 1;
127         gridBagConstraints.gridy = 0;
128         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
129         gridBagConstraints.weightx = 1.0;
130         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
131         add(jTextFieldFwdName, gridBagConstraints);
132         jTextFieldFwdName.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jTextFieldFwdName"));
133
134         jLabelFwdTo.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_ForwardTo"));
135         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
136         gridBagConstraints.gridx = 0;
137         gridBagConstraints.gridy = 1;
138         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
139         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
141         add(jLabelFwdTo, gridBagConstraints);
142
143         buttonGroup1.add(jRadioButtonResFile);
144         jRadioButtonResFile.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_ResFile").charAt(0));
145         jRadioButtonResFile.setSelected(true);
146         jRadioButtonResFile.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "RB_ResourceFile"));
147         jRadioButtonResFile.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
148         jRadioButtonResFile.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
149         jRadioButtonResFile.addItemListener(new java.awt.event.ItemListener JavaDoc() {
150             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
151                 jRadioButtonResFileItemStateChanged(evt);
152             }
153         });
154
155         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
156         gridBagConstraints.gridx = 0;
157         gridBagConstraints.gridy = 2;
158         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
159         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 12);
160         add(jRadioButtonResFile, gridBagConstraints);
161         jRadioButtonResFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jRadioButtonResFile_Forward"));
162
163         jTextFieldResFile.setColumns(30);
164         jTextFieldResFile.setText("/");
165         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridx = 1;
167         gridBagConstraints.gridy = 2;
168         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
169         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
170         add(jTextFieldResFile, gridBagConstraints);
171         jTextFieldResFile.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSN_jTextFieldResFile"));
172         jTextFieldResFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jTextFieldResFile_F"));
173
174         jButtonBrowse.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_Browse").charAt(0));
175         jButtonBrowse.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_BrowseButton"));
176         jButtonBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
177             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
178                 jButtonBrowseActionPerformed(evt);
179             }
180         });
181
182         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
183         gridBagConstraints.gridx = 2;
184         gridBagConstraints.gridy = 2;
185         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
186         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
187         add(jButtonBrowse, gridBagConstraints);
188         jButtonBrowse.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jButtonBrowse"));
189
190         buttonGroup1.add(jRadioButtonFwdAction);
191         jRadioButtonFwdAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_FwdAction").charAt(0));
192         jRadioButtonFwdAction.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "RB_Action"));
193         jRadioButtonFwdAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
194         jRadioButtonFwdAction.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
195         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
196         gridBagConstraints.gridx = 0;
197         gridBagConstraints.gridy = 3;
198         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
199         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 12, 12);
200         add(jRadioButtonFwdAction, gridBagConstraints);
201         jRadioButtonFwdAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jRadioButtonFwdAction"));
202
203         jComboBoxFwdAction.setEditable(true);
204         jComboBoxFwdAction.setEnabled(false);
205         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
206         gridBagConstraints.gridx = 1;
207         gridBagConstraints.gridy = 3;
208         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
209         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
210         add(jComboBoxFwdAction, gridBagConstraints);
211         jComboBoxFwdAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jComboBoxFwdAction"));
212
213         jCheckBoxRedirect.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_Redirect").charAt(0));
214         jCheckBoxRedirect.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_Redirect"));
215         jCheckBoxRedirect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
216         jCheckBoxRedirect.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
217         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
218         gridBagConstraints.gridx = 0;
219         gridBagConstraints.gridy = 4;
220         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
221         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
222         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
223         add(jCheckBoxRedirect, gridBagConstraints);
224         jCheckBoxRedirect.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jCheckBoxRedirect"));
225
226         jLabelLocation.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_Location"));
227         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
228         gridBagConstraints.gridx = 0;
229         gridBagConstraints.gridy = 5;
230         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
231         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
232         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
233         add(jLabelLocation, gridBagConstraints);
234
235         buttonGroup2.add(jRadioButtonGlobal);
236         jRadioButtonGlobal.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_Global").charAt(0));
237         jRadioButtonGlobal.setSelected(true);
238         jRadioButtonGlobal.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "LBL_AddFwdDialog_Global"));
239         jRadioButtonGlobal.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
240         jRadioButtonGlobal.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
241         jRadioButtonGlobal.addItemListener(new java.awt.event.ItemListener JavaDoc() {
242             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
243                 jRadioButtonGlobalItemStateChanged(evt);
244             }
245         });
246
247         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
248         gridBagConstraints.gridx = 0;
249         gridBagConstraints.gridy = 6;
250         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
251         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
252         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
253         add(jRadioButtonGlobal, gridBagConstraints);
254         jRadioButtonGlobal.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jRadioButtonGlobal"));
255
256         buttonGroup2.add(jRadioButtonLocationAction);
257         jRadioButtonLocationAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "MNE_AddFwdDialog_LocationAction").charAt(0));
258         jRadioButtonLocationAction.setText(org.openide.util.NbBundle.getMessage(AddForwardDialogPanel.class, "RB_Action"));
259         jRadioButtonLocationAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
260         jRadioButtonLocationAction.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
261         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
262         gridBagConstraints.gridx = 0;
263         gridBagConstraints.gridy = 7;
264         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
265         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
266         add(jRadioButtonLocationAction, gridBagConstraints);
267         jRadioButtonLocationAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jRadioButtonLocationAction"));
268
269         jComboBoxLocationAction.setEnabled(false);
270         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
271         gridBagConstraints.gridx = 1;
272         gridBagConstraints.gridy = 7;
273         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
274         add(jComboBoxLocationAction, gridBagConstraints);
275         jComboBoxLocationAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jComboBoxLocationAction"));
276
277     }
278     // </editor-fold>//GEN-END:initComponents
279

280     private void jRadioButtonGlobalItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButtonGlobalItemStateChanged
281
// TODO add your handling code here:
282
jComboBoxLocationAction.setEnabled(!jRadioButtonGlobal.isSelected());
283     }//GEN-LAST:event_jRadioButtonGlobalItemStateChanged
284

285     private void jRadioButtonResFileItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButtonResFileItemStateChanged
286
// TODO add your handling code here:
287
boolean selected = jRadioButtonResFile.isSelected();
288         jTextFieldResFile.setEditable(selected);
289         jButtonBrowse.setEnabled(selected);
290         jComboBoxFwdAction.setEnabled(!selected);
291     }//GEN-LAST:event_jRadioButtonResFileItemStateChanged
292

293     private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonBrowseActionPerformed
294
// TODO add your handling code here:
295
try{
296         org.netbeans.api.project.SourceGroup[] groups = StrutsConfigUtilities.getDocBaseGroups(config.getPrimaryFile());
297             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
298             if (fo!=null) {
299                 String JavaDoc res = "/"+StrutsConfigUtilities.getResourcePath(groups,fo,'/',true);
300                 jTextFieldResFile.setText(res);
301             }
302         } catch (java.io.IOException JavaDoc ex) {}
303     }//GEN-LAST:event_jButtonBrowseActionPerformed
304

305     
306     // Variables declaration - do not modify//GEN-BEGIN:variables
307
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
308     private javax.swing.ButtonGroup JavaDoc buttonGroup2;
309     private javax.swing.JButton JavaDoc jButtonBrowse;
310     private javax.swing.JCheckBox JavaDoc jCheckBoxRedirect;
311     private javax.swing.JComboBox JavaDoc jComboBoxFwdAction;
312     private javax.swing.JComboBox JavaDoc jComboBoxLocationAction;
313     private javax.swing.JLabel JavaDoc jLabelFwdName;
314     private javax.swing.JLabel JavaDoc jLabelFwdTo;
315     private javax.swing.JLabel JavaDoc jLabelLocation;
316     private javax.swing.JRadioButton JavaDoc jRadioButtonFwdAction;
317     private javax.swing.JRadioButton JavaDoc jRadioButtonGlobal;
318     private javax.swing.JRadioButton JavaDoc jRadioButtonLocationAction;
319     private javax.swing.JRadioButton JavaDoc jRadioButtonResFile;
320     private javax.swing.JTextField JavaDoc jTextFieldFwdName;
321     private javax.swing.JTextField JavaDoc jTextFieldResFile;
322     // End of variables declaration//GEN-END:variables
323

324     public String JavaDoc getForwardName() {
325         return jTextFieldFwdName.getText().trim();
326     }
327     
328     public boolean isGlobal() {
329         return jRadioButtonGlobal.isSelected();
330     }
331     
332     public String JavaDoc getRedirect() {
333         return (jCheckBoxRedirect.isSelected()?"true":null);
334     }
335     
336     public String JavaDoc getForwardTo() {
337         if (jRadioButtonResFile.isSelected()) {
338             return jTextFieldResFile.getText().trim();
339         } else {
340             return StrutsConfigUtilities.getActionAsResource(
341                     WebModule.getWebModule(config.getPrimaryFile()),
342                     (String JavaDoc)jComboBoxFwdAction.getSelectedItem());
343         }
344     }
345
346     public String JavaDoc getLocationAction() {
347         return (String JavaDoc)jComboBoxLocationAction.getSelectedItem();
348     }
349 }
350
Popular Tags