KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > dialogs > AddNavigationCaseDialog


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.jsf.dialogs;
21
22 import java.util.Collection JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import javax.swing.DefaultComboBoxModel JavaDoc;
25 import javax.swing.text.JTextComponent JavaDoc;
26 import org.netbeans.modules.web.jsf.JSFConfigDataObject;
27 import org.netbeans.modules.web.jsf.JSFConfigUtilities;
28 import org.netbeans.modules.web.jsf.api.ConfigurationUtils;
29 import org.netbeans.modules.web.jsf.api.facesmodel.FacesConfig;
30 import org.netbeans.modules.web.jsf.api.facesmodel.NavigationCase;
31 import org.netbeans.modules.web.jsf.api.facesmodel.NavigationRule;
32 import org.openide.ErrorManager;
33 import org.openide.util.NbBundle;
34
35 /**
36  *
37  * @author radko
38  */

39 public class AddNavigationCaseDialog extends javax.swing.JPanel JavaDoc implements ValidatingPanel{
40     private JSFConfigDataObject config;
41     /** Creates new form AddNavigationCaseDialog */
42     public AddNavigationCaseDialog(JSFConfigDataObject config, String JavaDoc rule) {
43         initComponents();
44         this.config = config;
45         FacesConfig facesConfig = ConfigurationUtils.getConfigModel(config.getPrimaryFile(), false).getRootComponent();
46         
47         DefaultComboBoxModel JavaDoc modelF = (DefaultComboBoxModel JavaDoc)jComboBoxFromView.getModel();
48         DefaultComboBoxModel JavaDoc modelT = (DefaultComboBoxModel JavaDoc)jComboBoxToView.getModel();
49         modelF.addElement("");
50         modelT.addElement("");
51         Iterator JavaDoc iter = facesConfig.getNavigationRules().iterator();
52         while (iter.hasNext()) {
53             String JavaDoc fromViewID=((NavigationRule)iter.next()).getFromViewId();
54             modelF.addElement(fromViewID);
55             modelT.addElement(fromViewID);
56         }
57         if (rule != null)
58             jComboBoxFromView.setSelectedItem(rule);
59     }
60     
61     public javax.swing.text.JTextComponent JavaDoc[] getDocumentChangeComponents() {
62         return new javax.swing.text.JTextComponent JavaDoc[]{(JTextComponent JavaDoc)jComboBoxFromView.getEditor().getEditorComponent(),
63         (JTextComponent JavaDoc) jComboBoxToView.getEditor().getEditorComponent(), jTextFieldFromAction, jTextFieldFromOutcome};
64     }
65     
66     public javax.swing.AbstractButton JavaDoc[] getStateChangeComponents() {
67         return new javax.swing.AbstractButton JavaDoc[]{ };
68     }
69     
70     public String JavaDoc validatePanel() {
71         if (getRule().length()==0)
72             return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_EmptyRule");
73         if (getToView().length()==0)
74             return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_EmptyToView");
75         if (getFromAction().length() == 0 && getFromOutcome().length() == 0)
76             return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_EmptyFromActionOutcome");
77         NavigationRule rule = JSFConfigUtilities.findNavigationRule(config, getRule());
78         //if the rule exist, check whether doesn't already indlclude the case
79
if (rule != null){
80             
81             Collection JavaDoc<NavigationCase> cases = rule.getNavigationCases();
82             String JavaDoc from;
83             for (Iterator JavaDoc<NavigationCase> it = cases.iterator(); it.hasNext();) {
84                 NavigationCase navigationCase = it.next();
85                 from = navigationCase.getFromAction();
86                 if (from != null && from.equals(getFromAction()))
87                     return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_FromActionExist");
88                 from = navigationCase.getFromOutcome();
89                 if (from != null && from.equals(getFromOutcome()))
90                     return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationCase_FromOutcomeExist");
91             }
92         }
93         return null;
94     }
95     
96     /** This method is called from within the constructor to
97      * initialize the form.
98      * WARNING: Do NOT modify this code. The content of this method is
99      * always regenerated by the Form Editor.
100      */

101     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
102
private void initComponents() {
103         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
104
105         jLabelFromView = new javax.swing.JLabel JavaDoc();
106         jComboBoxFromView = new javax.swing.JComboBox JavaDoc();
107         jButtonFromView = new javax.swing.JButton JavaDoc();
108         jLabelFromAction = new javax.swing.JLabel JavaDoc();
109         jTextFieldFromAction = new javax.swing.JTextField JavaDoc();
110         jLabelFromOutcome = new javax.swing.JLabel JavaDoc();
111         jTextFieldFromOutcome = new javax.swing.JTextField JavaDoc();
112         jLabelToView = new javax.swing.JLabel JavaDoc();
113         jButtonToView = new javax.swing.JButton JavaDoc();
114         jCheckBoxRedirect = new javax.swing.JCheckBox JavaDoc();
115         jLabelDesc = new javax.swing.JLabel JavaDoc();
116         jScrollPaneDesc = new javax.swing.JScrollPane JavaDoc();
117         jTextAreaDesc = new javax.swing.JTextArea JavaDoc();
118         jSeparator1 = new javax.swing.JSeparator JavaDoc();
119         jComboBoxToView = new javax.swing.JComboBox JavaDoc();
120
121         setLayout(new java.awt.GridBagLayout JavaDoc());
122
123         getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_AddNavigationCaseDialog"));
124         jLabelFromView.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_FromView").charAt(0));
125         jLabelFromView.setLabelFor(jComboBoxFromView);
126         jLabelFromView.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_CaseFromView"));
127         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
128         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
129         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 5, 12);
130         add(jLabelFromView, gridBagConstraints);
131
132         jComboBoxFromView.setEditable(true);
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
135         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 5, 0);
136         add(jComboBoxFromView, gridBagConstraints);
137         jComboBoxFromView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_FromView"));
138
139         jButtonFromView.setMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_Browse").charAt(0));
140         jButtonFromView.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_Browse"));
141         jButtonFromView.addActionListener(new java.awt.event.ActionListener JavaDoc() {
142             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
143                 jButtonFromViewActionPerformed(evt);
144             }
145         });
146
147         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
149         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 5, 11);
150         add(jButtonFromView, gridBagConstraints);
151         jButtonFromView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_BrowseFromView"));
152
153         jLabelFromAction.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_FromAction").charAt(0));
154         jLabelFromAction.setLabelFor(jTextFieldFromAction);
155         jLabelFromAction.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_FromAction"));
156         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 0;
158         gridBagConstraints.gridy = 2;
159         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
160         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 12);
161         add(jLabelFromAction, gridBagConstraints);
162
163         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridx = 1;
165         gridBagConstraints.gridy = 2;
166         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
167         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
168         add(jTextFieldFromAction, gridBagConstraints);
169         jTextFieldFromAction.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_FromAction"));
170
171         jLabelFromOutcome.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_FromOutcome").charAt(0));
172         jLabelFromOutcome.setLabelFor(jTextFieldFromOutcome);
173         jLabelFromOutcome.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_FromOutcome"));
174         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 0;
176         gridBagConstraints.gridy = 3;
177         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
178         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 12);
179         add(jLabelFromOutcome, gridBagConstraints);
180
181         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
182         gridBagConstraints.gridx = 1;
183         gridBagConstraints.gridy = 3;
184         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
185         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
186         add(jTextFieldFromOutcome, gridBagConstraints);
187         jTextFieldFromOutcome.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_FromOutcome"));
188
189         jLabelToView.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_ToView").charAt(0));
190         jLabelToView.setLabelFor(jComboBoxToView);
191         jLabelToView.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_ToView"));
192         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridx = 0;
194         gridBagConstraints.gridy = 4;
195         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
196         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 12);
197         add(jLabelToView, gridBagConstraints);
198
199         jButtonToView.setMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_BrowseToView").charAt(0));
200         jButtonToView.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_Browse"));
201         jButtonToView.addActionListener(new java.awt.event.ActionListener JavaDoc() {
202             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
203                 jButtonToViewActionPerformed(evt);
204             }
205         });
206
207         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
208         gridBagConstraints.gridx = 2;
209         gridBagConstraints.gridy = 4;
210         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
211         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 11);
212         add(jButtonToView, gridBagConstraints);
213         jButtonToView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_BrowseToView"));
214
215         jCheckBoxRedirect.setMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_Redirect").charAt(0));
216         jCheckBoxRedirect.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_Redirect"));
217         jCheckBoxRedirect.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
218         jCheckBoxRedirect.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
219         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
220         gridBagConstraints.gridx = 0;
221         gridBagConstraints.gridy = 5;
222         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
223         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
224         add(jCheckBoxRedirect, gridBagConstraints);
225         jCheckBoxRedirect.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_Redirect"));
226
227         jLabelDesc.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "MNE_BeanDescription").charAt(0));
228         jLabelDesc.setLabelFor(jTextAreaDesc);
229         jLabelDesc.setText(org.openide.util.NbBundle.getMessage(AddNavigationCaseDialog.class, "LBL_RuleDescription"));
230         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
231         gridBagConstraints.gridx = 0;
232         gridBagConstraints.gridy = 6;
233         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
234         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
235         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 11, 12);
236         add(jLabelDesc, gridBagConstraints);
237
238         jTextAreaDesc.setColumns(20);
239         jTextAreaDesc.setRows(5);
240         jScrollPaneDesc.setViewportView(jTextAreaDesc);
241         jTextAreaDesc.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_CaseDescription"));
242
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
244         gridBagConstraints.gridx = 1;
245         gridBagConstraints.gridy = 6;
246         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
247         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
248         gridBagConstraints.weightx = 1.0;
249         gridBagConstraints.weighty = 1.0;
250         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
251         add(jScrollPaneDesc, gridBagConstraints);
252
253         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
254         gridBagConstraints.gridx = 0;
255         gridBagConstraints.gridy = 1;
256         gridBagConstraints.gridwidth = 3;
257         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
258         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 6, 11);
259         add(jSeparator1, gridBagConstraints);
260
261         jComboBoxToView.setEditable(true);
262         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
263         gridBagConstraints.gridx = 1;
264         gridBagConstraints.gridy = 4;
265         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
266         add(jComboBoxToView, gridBagConstraints);
267         jComboBoxToView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_ToViewSelect"));
268
269     }
270     // </editor-fold>//GEN-END:initComponents
271

272     private void jButtonToViewActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonToViewActionPerformed
273
try{
274             org.netbeans.api.project.SourceGroup[] groups = JSFConfigUtilities.getDocBaseGroups(config.getPrimaryFile());
275             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
276             if (fo!=null) {
277                 String JavaDoc res = "/"+JSFConfigUtilities.getResourcePath(groups,fo,'/',true);
278                 jComboBoxToView.setSelectedItem(res);
279             }
280         } catch (java.io.IOException JavaDoc ex) {
281             ErrorManager.getDefault().notify(ex);
282         }
283     }//GEN-LAST:event_jButtonToViewActionPerformed
284

285     private void jButtonFromViewActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonFromViewActionPerformed
286
try{
287             org.netbeans.api.project.SourceGroup[] groups = JSFConfigUtilities.getDocBaseGroups(config.getPrimaryFile());
288             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
289             if (fo!=null) {
290                 String JavaDoc res = "/"+JSFConfigUtilities.getResourcePath(groups,fo,'/',true);
291                 jComboBoxFromView.setSelectedItem(res);
292             }
293         } catch (java.io.IOException JavaDoc ex) {
294             ErrorManager.getDefault().notify(ex);
295         }
296     }//GEN-LAST:event_jButtonFromViewActionPerformed
297

298     
299     // Variables declaration - do not modify//GEN-BEGIN:variables
300
private javax.swing.JButton JavaDoc jButtonFromView;
301     private javax.swing.JButton JavaDoc jButtonToView;
302     private javax.swing.JCheckBox JavaDoc jCheckBoxRedirect;
303     private javax.swing.JComboBox JavaDoc jComboBoxFromView;
304     private javax.swing.JComboBox JavaDoc jComboBoxToView;
305     private javax.swing.JLabel JavaDoc jLabelDesc;
306     private javax.swing.JLabel JavaDoc jLabelFromAction;
307     private javax.swing.JLabel JavaDoc jLabelFromOutcome;
308     private javax.swing.JLabel JavaDoc jLabelFromView;
309     private javax.swing.JLabel JavaDoc jLabelToView;
310     private javax.swing.JScrollPane JavaDoc jScrollPaneDesc;
311     private javax.swing.JSeparator JavaDoc jSeparator1;
312     private javax.swing.JTextArea JavaDoc jTextAreaDesc;
313     private javax.swing.JTextField JavaDoc jTextFieldFromAction;
314     private javax.swing.JTextField JavaDoc jTextFieldFromOutcome;
315     // End of variables declaration//GEN-END:variables
316

317     public String JavaDoc getRule(){
318         return (String JavaDoc)jComboBoxFromView.getSelectedItem();
319     }
320     
321     public String JavaDoc getFromAction(){
322         return jTextFieldFromAction.getText();
323     }
324     
325     public String JavaDoc getFromOutcome(){
326         return jTextFieldFromOutcome.getText();
327     }
328     
329     public String JavaDoc getToView(){
330         return (String JavaDoc)jComboBoxToView.getEditor().getItem();
331     }
332     
333     public boolean isRedirect(){
334         return jCheckBoxRedirect.isSelected();
335     }
336     
337     public String JavaDoc getDescription(){
338         return jTextAreaDesc.getText();
339     }
340 }
341
Popular Tags