KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > struts > wizards > ActionPanelVisual


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.wizards;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27 import javax.swing.event.ChangeEvent JavaDoc;
28 import javax.swing.event.ChangeListener JavaDoc;
29 import javax.swing.event.DocumentListener JavaDoc;
30 import org.openide.WizardDescriptor;
31 import org.openide.util.HelpCtx;
32 import org.netbeans.api.project.Project;
33 import org.netbeans.modules.web.api.webmodule.WebModule;
34 import org.netbeans.modules.web.struts.StrutsConfigUtilities;
35 import org.openide.util.NbBundle;
36
37 public class ActionPanelVisual extends javax.swing.JPanel JavaDoc implements HelpCtx.Provider, ActionListener JavaDoc, DocumentListener JavaDoc {
38     
39     static final String JavaDoc DEFAULT_ACTION = "org.apache.struts.action.Action"; //NOI18N
40
static final String JavaDoc DISPATCH_ACTION = "org.apache.struts.actions.DispatchAction"; //NOI18N
41
static final String JavaDoc MAPPING_DISPATCH_ACTION = "org.apache.struts.actions.MappingDispatchAction"; //NOI18N
42
static final String JavaDoc LOOKUP_DISPATCH_ACTION = "org.apache.struts.actions.LookupDispatchAction"; //NOI18N
43

44     private static final String JavaDoc[] SUPERCLASS_LIST = {DEFAULT_ACTION, DISPATCH_ACTION, MAPPING_DISPATCH_ACTION, LOOKUP_DISPATCH_ACTION};
45     
46     private final List JavaDoc/*<ChangeListener>*/ listeners = new ArrayList JavaDoc();
47     
48     /** Creates new form ActionPanelVisual */
49     public ActionPanelVisual(ActionPanel panel) {
50         initComponents();
51         jComboBoxSuperclass.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(SUPERCLASS_LIST));
52         jComboBoxSuperclass.getEditor().addActionListener( this );
53         Project proj = panel.getProject();
54         WebModule wm = WebModule.getWebModule(proj.getProjectDirectory());
55         if (wm != null){
56             String JavaDoc[] configFiles = StrutsConfigUtilities.getConfigFiles(wm.getDeploymentDescriptor());
57             jComboBoxConfigFile.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(configFiles));
58         }
59         jComboBoxConfigFile.getEditor().addActionListener( this );
60         jTextFieldPath.getDocument().addDocumentListener( this );
61         
62         Component JavaDoc superclassEditor = jComboBoxSuperclass.getEditor().getEditorComponent();
63         if ( superclassEditor instanceof javax.swing.JTextField JavaDoc ) {
64             ((javax.swing.JTextField JavaDoc)superclassEditor).getDocument().addDocumentListener( this );
65         }
66     }
67     
68     /** This method is called from within the constructor to
69      * initialize the form.
70      * WARNING: Do NOT modify this code. The content of this method is
71      * always regenerated by the Form Editor.
72      */

73     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
74
private void initComponents() {
75         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
76
77         jLabelSuperclass = new javax.swing.JLabel JavaDoc();
78         jComboBoxSuperclass = new javax.swing.JComboBox JavaDoc();
79         jLabelConfigFile = new javax.swing.JLabel JavaDoc();
80         jComboBoxConfigFile = new javax.swing.JComboBox JavaDoc();
81         jLabelPath = new javax.swing.JLabel JavaDoc();
82         jTextFieldPath = new javax.swing.JTextField JavaDoc();
83
84         setLayout(new java.awt.GridBagLayout JavaDoc());
85
86         jLabelSuperclass.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ActionPanelVisual.class, "LBL_Superlass_mnem").charAt(0));
87         jLabelSuperclass.setText(org.openide.util.NbBundle.getMessage(ActionPanelVisual.class, "LBL_Superclass"));
88         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
89         gridBagConstraints.gridx = 0;
90         gridBagConstraints.gridy = 0;
91         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
92         add(jLabelSuperclass, gridBagConstraints);
93
94         jComboBoxSuperclass.setEditable(true);
95         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
96         gridBagConstraints.gridx = 1;
97         gridBagConstraints.gridy = 0;
98         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
99         gridBagConstraints.weightx = 1.0;
100         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
101         add(jComboBoxSuperclass, gridBagConstraints);
102         jComboBoxSuperclass.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/wizards/Bundle").getString("ACSD_jComboBoxSuperclass"));
103
104         jLabelConfigFile.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ActionPanelVisual.class, "LBL_ConfigFile_mnem").charAt(0));
105         jLabelConfigFile.setLabelFor(jComboBoxConfigFile);
106         jLabelConfigFile.setText(org.openide.util.NbBundle.getMessage(ActionPanelVisual.class, "LBL_ConfigFile"));
107         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
108         gridBagConstraints.gridx = 0;
109         gridBagConstraints.gridy = 1;
110         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
111         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
112         add(jLabelConfigFile, gridBagConstraints);
113
114         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
115         gridBagConstraints.gridx = 1;
116         gridBagConstraints.gridy = 1;
117         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
118         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
119         add(jComboBoxConfigFile, gridBagConstraints);
120         jComboBoxConfigFile.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/wizards/Bundle").getString("ACSD_jComboBoxConfigFile"));
121
122         jLabelPath.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(ActionPanelVisual.class, "LBL_ActionPath_mnem").charAt(0));
123         jLabelPath.setLabelFor(jTextFieldPath);
124         jLabelPath.setText(org.openide.util.NbBundle.getMessage(ActionPanelVisual.class, "LBL_ActionPath"));
125         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints.gridx = 0;
127         gridBagConstraints.gridy = 2;
128         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
129         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 0, 0, 0);
130         add(jLabelPath, gridBagConstraints);
131
132         jTextFieldPath.setText("/");
133         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
134         gridBagConstraints.gridx = 1;
135         gridBagConstraints.gridy = 2;
136         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
138         gridBagConstraints.weighty = 1.0;
139         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 0);
140         add(jTextFieldPath, gridBagConstraints);
141         jTextFieldPath.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/web/struts/wizards/Bundle").getString("ACSD_jTextFieldPath"));
142
143     }// </editor-fold>//GEN-END:initComponents
144

145     
146     // Variables declaration - do not modify//GEN-BEGIN:variables
147
private javax.swing.JComboBox JavaDoc jComboBoxConfigFile;
148     private javax.swing.JComboBox JavaDoc jComboBoxSuperclass;
149     private javax.swing.JLabel JavaDoc jLabelConfigFile;
150     private javax.swing.JLabel JavaDoc jLabelPath;
151     private javax.swing.JLabel JavaDoc jLabelSuperclass;
152     private javax.swing.JTextField JavaDoc jTextFieldPath;
153     // End of variables declaration//GEN-END:variables
154

155     boolean valid(WizardDescriptor wizardDescriptor) {
156         // check super class
157
String JavaDoc superclass = (String JavaDoc) jComboBoxSuperclass.getEditor().getItem();
158         if (superclass == null || superclass.trim().equals("")){
159             wizardDescriptor.putProperty("WizardPanel_errorMessage", //NOI18N
160
NbBundle.getMessage(ActionPanelVisual.class, "MSG_NoSuperClassSelected")); //NOI18N
161
return false;
162         }
163         
164         // check configuration file
165
String JavaDoc configFile = (String JavaDoc) jComboBoxConfigFile.getSelectedItem();
166         if (configFile == null || configFile.trim().equals("")){
167             // Should dislpay only warning. We should allow to create action outside module. #68034
168
wizardDescriptor.putProperty("WizardPanel_errorMessage", //NOI18N
169
NbBundle.getMessage(ActionPanelVisual.class, "MSG_NoConfFileSelectedForAction"));//NOI18N
170
// don't check the action path, when the configuration file is not needed.
171
return true;
172         }
173         // check Action path
174
String JavaDoc actionPath = jTextFieldPath.getText();
175         if (actionPath == null || actionPath.trim().equals("") || actionPath.trim().equals("/")){//NOI18N
176
wizardDescriptor.putProperty("WizardPanel_errorMessage", //NOI18N
177
NbBundle.getMessage(ActionPanelVisual.class, "MSG_WrongActionPath")); //NOI18N
178
return false;
179         }
180         return true;
181     }
182     
183     void read (WizardDescriptor settings) {
184     }
185
186     void store(WizardDescriptor settings) {
187         settings.putProperty(WizardProperties.ACTION_PATH, jTextFieldPath.getText()); //NOI18N
188
settings.putProperty(WizardProperties.ACTION_SUPERCLASS, (String JavaDoc)jComboBoxSuperclass.getSelectedItem()); //NOI18N
189
settings.putProperty(WizardProperties.ACTION_CONFIG_FILE, (String JavaDoc)jComboBoxConfigFile.getSelectedItem()); //NOI18N
190
}
191
192     public HelpCtx getHelpCtx() {
193         return new HelpCtx(ActionPanelVisual.class);
194     }
195     
196     public void actionPerformed(java.awt.event.ActionEvent JavaDoc e) {
197          fireChange();
198     }
199     
200     public void addChangeListener(ChangeListener JavaDoc l) {
201         listeners.add(l);
202     }
203     
204     public void removeChangeListener(ChangeListener JavaDoc l) {
205         listeners.remove(l);
206     }
207     
208     private void fireChange() {
209         ChangeEvent JavaDoc e = new ChangeEvent JavaDoc(this);
210         Iterator JavaDoc it = listeners.iterator();
211         while (it.hasNext()) {
212             ((ChangeListener JavaDoc)it.next()).stateChanged(e);
213         }
214     }
215     
216     // DocumentListener implementation -----------------------------------------
217

218     public void changedUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
219         fireChange();
220     }
221     
222     public void insertUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
223         changedUpdate( e );
224     }
225     
226     public void removeUpdate(javax.swing.event.DocumentEvent JavaDoc e) {
227         changedUpdate( e );
228     }
229 }
230
Popular Tags