KickJava   Java API By Example, From Geeks To Geeks.

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


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.DefaultComboBoxModel JavaDoc;
25 import org.netbeans.modules.web.api.webmodule.WebModule;
26 import org.netbeans.modules.web.struts.StrutsConfigDataObject;
27 import org.netbeans.modules.web.struts.StrutsConfigUtilities;
28 import org.netbeans.modules.web.struts.config.model.Action;
29 import org.openide.util.NbBundle;
30
31 /**
32  *
33  * @author petr
34  */

35 public class AddFIActionPanel extends javax.swing.JPanel JavaDoc implements ValidatingPanel {
36     private StrutsConfigDataObject config;
37     /** Creates new form AddFIActionPanel */
38     public AddFIActionPanel(StrutsConfigDataObject dObject) {
39         config = dObject;
40         initComponents();
41         List JavaDoc actions = StrutsConfigUtilities.getAllActionsInModule(config);
42         DefaultComboBoxModel JavaDoc model = (DefaultComboBoxModel JavaDoc)cbAction.getModel();
43         //model.removeAllElements();
44
Iterator JavaDoc iter = actions.iterator();
45         while (iter.hasNext())
46             model.addElement(((Action)iter.next()).getAttributeValue("path"));
47     }
48
49     public String JavaDoc validatePanel() {
50         String JavaDoc actionPath = getActionPath();
51         if (actionPath==null || actionPath.equals("/")) //NOI18N
52
return NbBundle.getMessage(AddFIActionPanel.class,"MSG_EmptyActionPath");
53         if (!actionPath.startsWith("/") ) //NOI18N
54
return NbBundle.getMessage(AddFIActionPanel.class,"MSG_IncorrectActionPath", actionPath);
55         if (containsActionPath(actionPath)) //NOI18N
56
return NbBundle.getMessage(AddFIActionPanel.class,"MSG_DupliciteActionPath",actionPath);
57         if (rbResourceFile.isSelected() && tResourceFile.getText().trim().length()==0) {
58             return NbBundle.getMessage(AddFIActionPanel.class,"MSG_EmptyResourceFile");
59         } else if (rbAction.isSelected() && cbAction.getSelectedItem()==null) {
60             return NbBundle.getMessage(AddFIActionPanel.class,"MSG_EmptyAction");
61         } else return null;
62     }
63
64     public javax.swing.AbstractButton JavaDoc[] getStateChangeComponents() {
65         return new javax.swing.AbstractButton JavaDoc[]{ rbResourceFile };
66     }
67
68     public javax.swing.text.JTextComponent JavaDoc[] getDocumentChangeComponents() {
69         return new javax.swing.text.JTextComponent JavaDoc[]{jTextFieldPath, tResourceFile};
70     }
71     
72     /** This method is called from within the constructor to
73      * initialize the form.
74      * WARNING: Do NOT modify this code. The content of this method is
75      * always regenerated by the Form Editor.
76      */

77     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
78
private void initComponents() {
79         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
80
81         bgActionType = new javax.swing.ButtonGroup JavaDoc();
82         bgCall = new javax.swing.ButtonGroup JavaDoc();
83         jPopupMenu1 = new javax.swing.JPopupMenu JavaDoc();
84         lActionType = new javax.swing.JLabel JavaDoc();
85         rbIncludeAction = new javax.swing.JRadioButton JavaDoc();
86         rbForwardAction = new javax.swing.JRadioButton JavaDoc();
87         lCall = new javax.swing.JLabel JavaDoc();
88         rbResourceFile = new javax.swing.JRadioButton JavaDoc();
89         rbAction = new javax.swing.JRadioButton JavaDoc();
90         tResourceFile = new javax.swing.JTextField JavaDoc();
91         bBrowse = new javax.swing.JButton JavaDoc();
92         cbAction = new javax.swing.JComboBox JavaDoc();
93         jLabelPath = new javax.swing.JLabel JavaDoc();
94         jTextFieldPath = new javax.swing.JTextField JavaDoc();
95
96         setLayout(new java.awt.GridBagLayout JavaDoc());
97
98         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 11, 11));
99         getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_AddFIActionPanel"));
100         lActionType.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_ActionType"));
101         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
102         gridBagConstraints.gridx = 0;
103         gridBagConstraints.gridy = 1;
104         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
105         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
106         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
107         add(lActionType, gridBagConstraints);
108
109         bgActionType.add(rbIncludeAction);
110         rbIncludeAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Include_mnem").charAt(0));
111         rbIncludeAction.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Include"));
112         rbIncludeAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
113         rbIncludeAction.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
114         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
115         gridBagConstraints.gridx = 0;
116         gridBagConstraints.gridy = 3;
117         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
118         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 20, 0, 0);
119         add(rbIncludeAction, gridBagConstraints);
120         rbIncludeAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_rbIncudeAction"));
121
122         bgActionType.add(rbForwardAction);
123         rbForwardAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Forward_mnem").charAt(0));
124         rbForwardAction.setSelected(true);
125         rbForwardAction.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Forward"));
126         rbForwardAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
127         rbForwardAction.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
128         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
129         gridBagConstraints.gridx = 0;
130         gridBagConstraints.gridy = 2;
131         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
132         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 20, 0, 0);
133         add(rbForwardAction, gridBagConstraints);
134         rbForwardAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_rbForwardAction"));
135
136         lCall.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_Call"));
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.gridx = 0;
139         gridBagConstraints.gridy = 4;
140         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
141         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
142         add(lCall, gridBagConstraints);
143
144         bgCall.add(rbResourceFile);
145         rbResourceFile.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_ResourceFile_mnem").charAt(0));
146         rbResourceFile.setSelected(true);
147         rbResourceFile.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_ResourceFile"));
148         rbResourceFile.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
149         rbResourceFile.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
150         rbResourceFile.addItemListener(new java.awt.event.ItemListener JavaDoc() {
151             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
152                 rbResourceFileItemStateChanged(evt);
153             }
154         });
155
156         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 0;
158         gridBagConstraints.gridy = 5;
159         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
160         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 20, 0, 0);
161         add(rbResourceFile, gridBagConstraints);
162         rbResourceFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_rbResourceFile2"));
163
164         bgCall.add(rbAction);
165         rbAction.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Action_mnem").charAt(0));
166         rbAction.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "RB_Action"));
167         rbAction.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
168         rbAction.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
169         rbAction.addItemListener(new java.awt.event.ItemListener JavaDoc() {
170             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
171                 rbActionItemStateChanged(evt);
172             }
173         });
174
175         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
176         gridBagConstraints.gridx = 0;
177         gridBagConstraints.gridy = 6;
178         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
179         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 20, 0, 0);
180         add(rbAction, gridBagConstraints);
181         rbAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_rbAction"));
182
183         tResourceFile.setMinimumSize(new java.awt.Dimension JavaDoc(200, 24));
184         tResourceFile.setPreferredSize(new java.awt.Dimension JavaDoc(200, 24));
185         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
186         gridBagConstraints.gridx = 1;
187         gridBagConstraints.gridy = 5;
188         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189         gridBagConstraints.weightx = 1.0;
190         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 0, 0);
191         add(tResourceFile, gridBagConstraints);
192         tResourceFile.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_tResourceFile"));
193         tResourceFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_tResourceFile"));
194
195         bBrowse.setMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_Browse_mnem").charAt(0));
196         bBrowse.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_BrowseButton"));
197         bBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
198             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
199                 bBrowseActionPerformed(evt);
200             }
201         });
202
203         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
204         gridBagConstraints.gridx = 2;
205         gridBagConstraints.gridy = 5;
206         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 0, 0);
207         add(bBrowse, gridBagConstraints);
208         bBrowse.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_bBrowse"));
209
210         cbAction.setEnabled(false);
211         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
212         gridBagConstraints.gridx = 1;
213         gridBagConstraints.gridy = 6;
214         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
215         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 0, 0);
216         add(cbAction, gridBagConstraints);
217         cbAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_cbAction"));
218
219         jLabelPath.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_ActionPath_mnem").charAt(0));
220         jLabelPath.setLabelFor(jTextFieldPath);
221         jLabelPath.setText(org.openide.util.NbBundle.getMessage(AddFIActionPanel.class, "LBL_ActionPath"));
222         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
223         gridBagConstraints.gridx = 0;
224         gridBagConstraints.gridy = 0;
225         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
226         add(jLabelPath, gridBagConstraints);
227
228         jTextFieldPath.setColumns(30);
229         jTextFieldPath.setText("/");
230         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
231         gridBagConstraints.gridx = 1;
232         gridBagConstraints.gridy = 0;
233         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
234         gridBagConstraints.weightx = 1.0;
235         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
236         add(jTextFieldPath, gridBagConstraints);
237         jTextFieldPath.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/dialogs/Bundle").getString("ACSD_jTextFieldPath"));
238
239     }
240     // </editor-fold>//GEN-END:initComponents
241

242     private void bBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_bBrowseActionPerformed
243
try{
244         org.netbeans.api.project.SourceGroup[] groups = StrutsConfigUtilities.getDocBaseGroups(config.getPrimaryFile());
245             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
246             if (fo!=null) {
247                 String JavaDoc res = "/"+StrutsConfigUtilities.getResourcePath(groups,fo,'/',true);
248                 tResourceFile.setText(res);
249             }
250         } catch (java.io.IOException JavaDoc ex) {}
251     }//GEN-LAST:event_bBrowseActionPerformed
252

253     private void rbResourceFileItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_rbResourceFileItemStateChanged
254
tResourceFile.setEnabled(true);
255         bBrowse.setEnabled(true);
256         cbAction.setEnabled(false);
257     }//GEN-LAST:event_rbResourceFileItemStateChanged
258

259     private void rbActionItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_rbActionItemStateChanged
260
tResourceFile.setEnabled(false);
261         bBrowse.setEnabled(false);
262         cbAction.setEnabled(true);
263     }//GEN-LAST:event_rbActionItemStateChanged
264

265     
266     // Variables declaration - do not modify//GEN-BEGIN:variables
267
private javax.swing.JButton JavaDoc bBrowse;
268     private javax.swing.ButtonGroup JavaDoc bgActionType;
269     private javax.swing.ButtonGroup JavaDoc bgCall;
270     private javax.swing.JComboBox JavaDoc cbAction;
271     private javax.swing.JLabel JavaDoc jLabelPath;
272     private javax.swing.JPopupMenu JavaDoc jPopupMenu1;
273     private javax.swing.JTextField JavaDoc jTextFieldPath;
274     private javax.swing.JLabel JavaDoc lActionType;
275     private javax.swing.JLabel JavaDoc lCall;
276     private javax.swing.JRadioButton JavaDoc rbAction;
277     private javax.swing.JRadioButton JavaDoc rbForwardAction;
278     private javax.swing.JRadioButton JavaDoc rbIncludeAction;
279     private javax.swing.JRadioButton JavaDoc rbResourceFile;
280     private javax.swing.JTextField JavaDoc tResourceFile;
281     // End of variables declaration//GEN-END:variables
282

283     public String JavaDoc getActionPath() {
284         String JavaDoc path = jTextFieldPath.getText().trim();
285         return path.length()==0?null:path;
286     }
287     
288     public boolean isForward() {
289         return rbForwardAction.isSelected();
290     }
291     
292     public String JavaDoc getResource() {
293         if (rbResourceFile.isSelected()) {
294             String JavaDoc resource=tResourceFile.getText().trim();
295             return resource.length()==0?null:resource;
296         } else {
297             return StrutsConfigUtilities.getActionAsResource(
298                     WebModule.getWebModule(config.getPrimaryFile()),
299                     (String JavaDoc)cbAction.getSelectedItem());
300         }
301     }
302     
303     private boolean containsActionPath(String JavaDoc path) {
304         DefaultComboBoxModel JavaDoc model = (DefaultComboBoxModel JavaDoc)cbAction.getModel();
305         for (int i=0; i<model.getSize(); i++) {
306             if (path.equals(model.getElementAt(i))) return true;
307         }
308         return false;
309     }
310 }
311
Popular Tags