KickJava   Java API By Example, From Geeks To Geeks.

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


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.Hashtable JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import org.netbeans.api.project.SourceGroup;
25 import org.netbeans.modules.web.jsf.JSFConfigDataObject;
26 import org.netbeans.modules.web.jsf.JSFConfigUtilities;
27 import org.netbeans.modules.web.jsf.api.ConfigurationUtils;
28 import org.netbeans.modules.web.jsf.api.facesmodel.FacesConfig;
29 import org.netbeans.modules.web.jsf.api.facesmodel.NavigationRule;
30 import org.openide.ErrorManager;
31 import org.openide.util.NbBundle;
32
33 /**
34  *
35  * @author radko
36  */

37 public class AddNavigationRuleDialog extends javax.swing.JPanel JavaDoc implements ValidatingPanel{
38     private JSFConfigDataObject config;
39     private Hashtable JavaDoc existingRules = null;
40     /** Creates new form AddNavigationRuleDialog */
41     public AddNavigationRuleDialog(JSFConfigDataObject config) {
42         initComponents();
43         this.config = config;
44     }
45
46     public javax.swing.text.JTextComponent JavaDoc[] getDocumentChangeComponents() {
47         return new javax.swing.text.JTextComponent JavaDoc[]{jTextFieldFromView};
48     }
49
50     public javax.swing.AbstractButton JavaDoc[] getStateChangeComponents() {
51         return new javax.swing.AbstractButton JavaDoc[]{ };
52     }
53
54     public String JavaDoc validatePanel() {
55         if (getFromView().length()==0)
56             return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationRule_EmptyFromView");
57         if(existingRules == null){
58             existingRules = new Hashtable JavaDoc();
59             NavigationRule rule;
60             FacesConfig facesConfig = ConfigurationUtils.getConfigModel(config.getPrimaryFile(), true).getRootComponent();
61             
62             Iterator JavaDoc iter = facesConfig.getNavigationRules().iterator();
63             while (iter.hasNext()){
64                 rule = (NavigationRule) iter.next();
65                 if (rule.getFromViewId() != null)
66                     existingRules.put(rule.getFromViewId(), "");
67             }
68         }
69         if (existingRules.get(getFromView())!=null)
70             return NbBundle.getMessage(AddManagedBeanDialog.class,"MSG_AddNavigationRule_RuleExist");
71         return null;
72     }
73     
74     /** This method is called from within the constructor to
75      * initialize the form.
76      * WARNING: Do NOT modify this code. The content of this method is
77      * always regenerated by the Form Editor.
78      */

79     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
80
private void initComponents() {
81         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
82
83         jLabelFromView = new javax.swing.JLabel JavaDoc();
84         jTextFieldFromView = new javax.swing.JTextField JavaDoc();
85         jButtonBrowse = new javax.swing.JButton JavaDoc();
86         jLabelDesc = new javax.swing.JLabel JavaDoc();
87         jScrollPaneDesc = new javax.swing.JScrollPane JavaDoc();
88         jTextAreaDesc = new javax.swing.JTextArea JavaDoc();
89
90         setLayout(new java.awt.GridBagLayout JavaDoc());
91
92         getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_AddNavigationRuleDialog"));
93         jLabelFromView.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "MNE_FromView").charAt(0));
94         jLabelFromView.setLabelFor(jTextFieldFromView);
95         jLabelFromView.setText(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "LBL_FromView"));
96         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
97         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
98         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 5, 12);
99         add(jLabelFromView, gridBagConstraints);
100
101         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
102         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
103         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 5, 0);
104         add(jTextFieldFromView, gridBagConstraints);
105         jTextFieldFromView.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_RuleFromFiew"));
106
107         jButtonBrowse.setMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "MNE_Browse").charAt(0));
108         jButtonBrowse.setText(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "LBL_Browse"));
109         jButtonBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
110             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
111                 jButtonBrowseActionPerformed(evt);
112             }
113         });
114
115         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
116         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
117         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 5, 11);
118         add(jButtonBrowse, gridBagConstraints);
119         jButtonBrowse.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_RuleBrowse"));
120
121         jLabelDesc.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "MNE_BeanDescription").charAt(0));
122         jLabelDesc.setLabelFor(jTextAreaDesc);
123         jLabelDesc.setText(org.openide.util.NbBundle.getMessage(AddNavigationRuleDialog.class, "LBL_RuleDescription"));
124         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
125         gridBagConstraints.gridx = 0;
126         gridBagConstraints.gridy = 1;
127         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
128         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
129         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 12);
130         add(jLabelDesc, gridBagConstraints);
131
132         jTextAreaDesc.setColumns(20);
133         jTextAreaDesc.setRows(5);
134         jScrollPaneDesc.setViewportView(jTextAreaDesc);
135         jTextAreaDesc.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/jsf/dialogs/Bundle").getString("ACSD_RuleDescription"));
136
137         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.gridx = 1;
139         gridBagConstraints.gridy = 1;
140         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
141         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
142         gridBagConstraints.weightx = 1.0;
143         gridBagConstraints.weighty = 1.0;
144         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 11, 0);
145         add(jScrollPaneDesc, gridBagConstraints);
146
147     }
148     // </editor-fold>//GEN-END:initComponents
149

150     private void jButtonBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonBrowseActionPerformed
151
try{
152             org.netbeans.api.project.SourceGroup[] groups = JSFConfigUtilities.getDocBaseGroups(config.getPrimaryFile());
153             org.openide.filesystems.FileObject fo = BrowseFolders.showDialog(groups);
154             if (fo!=null) {
155                 String JavaDoc res = "/"+JSFConfigUtilities.getResourcePath(groups,fo,'/',true);
156                 jTextFieldFromView.setText(res);
157             }
158         } catch (java.io.IOException JavaDoc ex) {
159             ErrorManager.getDefault().notify(ex);
160         }
161     }//GEN-LAST:event_jButtonBrowseActionPerformed
162

163     
164     // Variables declaration - do not modify//GEN-BEGIN:variables
165
private javax.swing.JButton JavaDoc jButtonBrowse;
166     private javax.swing.JLabel JavaDoc jLabelDesc;
167     private javax.swing.JLabel JavaDoc jLabelFromView;
168     private javax.swing.JScrollPane JavaDoc jScrollPaneDesc;
169     private javax.swing.JTextArea JavaDoc jTextAreaDesc;
170     private javax.swing.JTextField JavaDoc jTextFieldFromView;
171     // End of variables declaration//GEN-END:variables
172

173     public String JavaDoc getFromView(){
174         return jTextFieldFromView.getText();
175     }
176     
177     public String JavaDoc getDescription(){
178         return jTextAreaDesc.getText();
179     }
180 }
181
Popular Tags