1 19 20 package org.netbeans.modules.web.struts.wizards; 21 22 import java.awt.Component ; 23 import java.awt.event.ActionListener ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import javax.swing.event.ChangeEvent ; 28 import javax.swing.event.ChangeListener ; 29 import javax.swing.event.DocumentListener ; 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 implements HelpCtx.Provider, ActionListener , DocumentListener { 38 39 static final String DEFAULT_ACTION = "org.apache.struts.action.Action"; static final String DISPATCH_ACTION = "org.apache.struts.actions.DispatchAction"; static final String MAPPING_DISPATCH_ACTION = "org.apache.struts.actions.MappingDispatchAction"; static final String LOOKUP_DISPATCH_ACTION = "org.apache.struts.actions.LookupDispatchAction"; 44 private static final String [] SUPERCLASS_LIST = {DEFAULT_ACTION, DISPATCH_ACTION, MAPPING_DISPATCH_ACTION, LOOKUP_DISPATCH_ACTION}; 45 46 private final List listeners = new ArrayList (); 47 48 49 public ActionPanelVisual(ActionPanel panel) { 50 initComponents(); 51 jComboBoxSuperclass.setModel(new javax.swing.DefaultComboBoxModel (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 [] configFiles = StrutsConfigUtilities.getConfigFiles(wm.getDeploymentDescriptor()); 57 jComboBoxConfigFile.setModel(new javax.swing.DefaultComboBoxModel (configFiles)); 58 } 59 jComboBoxConfigFile.getEditor().addActionListener( this ); 60 jTextFieldPath.getDocument().addDocumentListener( this ); 61 62 Component superclassEditor = jComboBoxSuperclass.getEditor().getEditorComponent(); 63 if ( superclassEditor instanceof javax.swing.JTextField ) { 64 ((javax.swing.JTextField )superclassEditor).getDocument().addDocumentListener( this ); 65 } 66 } 67 68 73 private void initComponents() { 75 java.awt.GridBagConstraints gridBagConstraints; 76 77 jLabelSuperclass = new javax.swing.JLabel (); 78 jComboBoxSuperclass = new javax.swing.JComboBox (); 79 jLabelConfigFile = new javax.swing.JLabel (); 80 jComboBoxConfigFile = new javax.swing.JComboBox (); 81 jLabelPath = new javax.swing.JLabel (); 82 jTextFieldPath = new javax.swing.JTextField (); 83 84 setLayout(new java.awt.GridBagLayout ()); 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 (); 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 (); 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 (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 (); 108 gridBagConstraints.gridx = 0; 109 gridBagConstraints.gridy = 1; 110 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 111 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 112 add(jLabelConfigFile, gridBagConstraints); 113 114 gridBagConstraints = new java.awt.GridBagConstraints (); 115 gridBagConstraints.gridx = 1; 116 gridBagConstraints.gridy = 1; 117 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 118 gridBagConstraints.insets = new java.awt.Insets (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 (); 126 gridBagConstraints.gridx = 0; 127 gridBagConstraints.gridy = 2; 128 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 129 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 130 add(jLabelPath, gridBagConstraints); 131 132 jTextFieldPath.setText("/"); 133 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 } 145 146 private javax.swing.JComboBox jComboBoxConfigFile; 148 private javax.swing.JComboBox jComboBoxSuperclass; 149 private javax.swing.JLabel jLabelConfigFile; 150 private javax.swing.JLabel jLabelPath; 151 private javax.swing.JLabel jLabelSuperclass; 152 private javax.swing.JTextField jTextFieldPath; 153 155 boolean valid(WizardDescriptor wizardDescriptor) { 156 String superclass = (String ) jComboBoxSuperclass.getEditor().getItem(); 158 if (superclass == null || superclass.trim().equals("")){ 159 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ActionPanelVisual.class, "MSG_NoSuperClassSelected")); return false; 162 } 163 164 String configFile = (String ) jComboBoxConfigFile.getSelectedItem(); 166 if (configFile == null || configFile.trim().equals("")){ 167 wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ActionPanelVisual.class, "MSG_NoConfFileSelectedForAction")); return true; 172 } 173 String actionPath = jTextFieldPath.getText(); 175 if (actionPath == null || actionPath.trim().equals("") || actionPath.trim().equals("/")){ wizardDescriptor.putProperty("WizardPanel_errorMessage", NbBundle.getMessage(ActionPanelVisual.class, "MSG_WrongActionPath")); 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()); settings.putProperty(WizardProperties.ACTION_SUPERCLASS, (String )jComboBoxSuperclass.getSelectedItem()); settings.putProperty(WizardProperties.ACTION_CONFIG_FILE, (String )jComboBoxConfigFile.getSelectedItem()); } 191 192 public HelpCtx getHelpCtx() { 193 return new HelpCtx(ActionPanelVisual.class); 194 } 195 196 public void actionPerformed(java.awt.event.ActionEvent e) { 197 fireChange(); 198 } 199 200 public void addChangeListener(ChangeListener l) { 201 listeners.add(l); 202 } 203 204 public void removeChangeListener(ChangeListener l) { 205 listeners.remove(l); 206 } 207 208 private void fireChange() { 209 ChangeEvent e = new ChangeEvent (this); 210 Iterator it = listeners.iterator(); 211 while (it.hasNext()) { 212 ((ChangeListener )it.next()).stateChanged(e); 213 } 214 } 215 216 218 public void changedUpdate(javax.swing.event.DocumentEvent e) { 219 fireChange(); 220 } 221 222 public void insertUpdate(javax.swing.event.DocumentEvent e) { 223 changedUpdate( e ); 224 } 225 226 public void removeUpdate(javax.swing.event.DocumentEvent e) { 227 changedUpdate( e ); 228 } 229 } 230 | Popular Tags |