1 19 20 package org.netbeans.modules.web.project.ui.customizer; 21 import java.text.MessageFormat ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 import javax.swing.DefaultListModel ; 26 import javax.swing.ListSelectionModel ; 27 import javax.swing.event.ListSelectionListener ; 28 29 import org.openide.DialogDescriptor; 30 import org.openide.DialogDisplayer; 31 import org.openide.NotifyDescriptor; 32 import org.openide.util.HelpCtx; 33 import org.openide.util.NbBundle; 34 35 import org.netbeans.modules.web.api.webmodule.WebModule; 36 import org.netbeans.modules.web.api.webmodule.WebFrameworkSupport; 37 import org.netbeans.modules.web.project.WebProject; 38 import org.netbeans.modules.web.spi.webmodule.WebFrameworkProvider; 39 40 public class CustomizerFrameworks extends javax.swing.JPanel implements HelpCtx.Provider, ListSelectionListener { 41 42 private WebProject project; 43 private WebProjectProperties uiProperties; 44 private List usedFrameworks = new LinkedList (); 45 private List newFrameworks = new LinkedList (); 46 47 48 public CustomizerFrameworks(WebProjectProperties uiProperties) { 49 this.uiProperties = uiProperties; 50 initComponents(); 51 52 project = uiProperties.getProject(); 53 initFrameworksList(project.getAPIWebModule()); 54 } 55 56 private void initFrameworksList(WebModule webModule) { 57 jListFrameworks.setModel(new DefaultListModel ()); 58 List frameworks = WebFrameworkSupport.getFrameworkProviders(); 59 for (int i = 0; i < frameworks.size(); i++) { 60 WebFrameworkProvider framework = (WebFrameworkProvider) frameworks.get(i); 61 if (framework.isInWebModule(webModule)) { 62 usedFrameworks.add(framework); 63 ((DefaultListModel ) jListFrameworks.getModel()).addElement(framework.getName()); 64 } 65 } 66 jListFrameworks.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 67 jListFrameworks.addListSelectionListener(this); 68 if (usedFrameworks.size() > 0) 69 jListFrameworks.setSelectedIndex(0); 70 71 if (frameworks.size() == jListFrameworks.getModel().getSize()) 72 jButtonAdd.setEnabled(false); 73 } 74 75 80 private void initComponents() { 82 java.awt.GridBagConstraints gridBagConstraints; 83 84 jLabelFrameworks = new javax.swing.JLabel (); 85 jScrollPane1 = new javax.swing.JScrollPane (); 86 jListFrameworks = new javax.swing.JList (); 87 jButtonAdd = new javax.swing.JButton (); 88 jSeparator1 = new javax.swing.JSeparator (); 89 jLabelConfig = new javax.swing.JLabel (); 90 jPanelConfig = new javax.swing.JPanel (); 91 92 setLayout(new java.awt.GridBagLayout ()); 93 94 jLabelFrameworks.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "LBL_CustomizerFrameworks_ListMnemonic").charAt(0)); 95 jLabelFrameworks.setLabelFor(jListFrameworks); 96 jLabelFrameworks.setText(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "LBL_UsedFrameworks")); 97 gridBagConstraints = new java.awt.GridBagConstraints (); 98 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 99 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 100 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 101 add(jLabelFrameworks, gridBagConstraints); 102 103 jScrollPane1.setViewportView(jListFrameworks); 104 jListFrameworks.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "ACS_Frameworks_FrameworksList_A11YDesc")); 105 106 gridBagConstraints = new java.awt.GridBagConstraints (); 107 gridBagConstraints.gridx = 0; 108 gridBagConstraints.gridy = 1; 109 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 110 gridBagConstraints.weightx = 1.0; 111 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 12); 112 add(jScrollPane1, gridBagConstraints); 113 114 jButtonAdd.setMnemonic(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "LBL_CustomizerFrameworks_AddButton_LabelMnemonic").charAt(0)); 115 jButtonAdd.setText(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "LBL_AddFramework")); 116 jButtonAdd.setActionCommand("Add..."); 117 jButtonAdd.addActionListener(new java.awt.event.ActionListener () { 118 public void actionPerformed(java.awt.event.ActionEvent evt) { 119 jButtonAddActionPerformed(evt); 120 } 121 }); 122 123 gridBagConstraints = new java.awt.GridBagConstraints (); 124 gridBagConstraints.gridx = 1; 125 gridBagConstraints.gridy = 1; 126 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 127 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 128 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 129 add(jButtonAdd, gridBagConstraints); 130 jButtonAdd.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerFrameworks.class, "ACS_Frameworks_AddButton_A11YDesc")); 131 132 gridBagConstraints = new java.awt.GridBagConstraints (); 133 gridBagConstraints.gridx = 0; 134 gridBagConstraints.gridy = 2; 135 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 136 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 137 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 138 add(jSeparator1, gridBagConstraints); 139 140 jLabelConfig.setLabelFor(jPanelConfig); 141 gridBagConstraints = new java.awt.GridBagConstraints (); 142 gridBagConstraints.gridx = 0; 143 gridBagConstraints.gridy = 3; 144 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 145 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 146 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 147 add(jLabelConfig, gridBagConstraints); 148 149 jPanelConfig.setLayout(new java.awt.GridBagLayout ()); 150 151 gridBagConstraints = new java.awt.GridBagConstraints (); 152 gridBagConstraints.gridx = 0; 153 gridBagConstraints.gridy = 4; 154 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 155 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 156 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 157 gridBagConstraints.weighty = 1.0; 158 add(jPanelConfig, gridBagConstraints); 159 160 } 162 private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) { AddFrameworkPanel panel = new AddFrameworkPanel(usedFrameworks); 164 javax.swing.JPanel inner = new javax.swing.JPanel (); 165 inner.setLayout(new java.awt.GridBagLayout ()); 166 inner.getAccessibleContext().setAccessibleDescription(panel.getAccessibleContext().getAccessibleDescription()); 167 inner.getAccessibleContext().setAccessibleName(panel.getAccessibleContext().getAccessibleName()); 168 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 169 gridBagConstraints.gridx = 0; 170 gridBagConstraints.gridy = 0; 171 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 172 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 173 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 174 gridBagConstraints.weightx = 1.0; 175 gridBagConstraints.weighty = 1.0; 176 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 12); 177 inner.add(panel, gridBagConstraints); 178 179 DialogDescriptor desc = new DialogDescriptor(inner, NbBundle.getMessage(CustomizerFrameworks.class, "LBL_SelectWebExtension_DialogTitle")); Object res = DialogDisplayer.getDefault().notify(desc); 181 if (res.equals(NotifyDescriptor.YES_OPTION)) { 182 newFrameworks.addAll(panel.getSelectedFrameworks()); 183 if (newFrameworks != null) { 184 uiProperties.setNewFrameworks(newFrameworks); 185 for(int i = 0; i < newFrameworks.size(); i++) { 186 WebFrameworkProvider framework = (WebFrameworkProvider) newFrameworks.get(i); 187 if (!((DefaultListModel ) jListFrameworks.getModel()).contains(framework.getName())) 188 ((DefaultListModel ) jListFrameworks.getModel()).addElement(framework.getName()); 189 190 if (usedFrameworks.size() == 0) 191 usedFrameworks.add(framework); 192 else 193 for (int j = 0; j < usedFrameworks.size(); j++) 194 if (!((WebFrameworkProvider) usedFrameworks.get(j)).getName().equals(framework.getName())) { 195 usedFrameworks.add(framework); 196 break; 197 } 198 199 jListFrameworks.setSelectedValue(framework.getName(), true); 200 } 201 } 202 } 203 204 if (WebFrameworkSupport.getFrameworkProviders().size() == jListFrameworks.getModel().getSize()) 205 jButtonAdd.setEnabled(false); 206 } 208 209 private javax.swing.JButton jButtonAdd; 211 private javax.swing.JLabel jLabelConfig; 212 private javax.swing.JLabel jLabelFrameworks; 213 private javax.swing.JList jListFrameworks; 214 private javax.swing.JPanel jPanelConfig; 215 private javax.swing.JScrollPane jScrollPane1; 216 private javax.swing.JSeparator jSeparator1; 217 219 222 public HelpCtx getHelpCtx() { 223 return new HelpCtx(CustomizerFrameworks.class); 224 } 225 226 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 227 String frameworkName = (String ) jListFrameworks.getSelectedValue(); 228 int selectedIndex = jListFrameworks.getSelectedIndex(); 229 if (selectedIndex != -1) { 230 WebFrameworkProvider framework = (WebFrameworkProvider) usedFrameworks.get(selectedIndex); 231 WebModule wm = WebModule.getWebModule(project.getProjectDirectory()); 232 if (framework.getName().equals(frameworkName)) 233 if (framework.getConfigurationPanel(wm) != null) { 234 String message = MessageFormat.format(NbBundle.getMessage(CustomizerFrameworks.class, "LBL_FrameworkConfiguration"), new Object [] {frameworkName}); jLabelConfig.setText(message); 236 jPanelConfig.removeAll(); 237 238 java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints (); 239 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 240 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 241 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 242 gridBagConstraints.weightx = 1.0; 243 gridBagConstraints.weighty = 1.0; 244 245 jPanelConfig.add(framework.getConfigurationPanel(wm).getComponent(), gridBagConstraints); 246 jPanelConfig.revalidate(); 247 } else { 248 hideConfigPanel(); 249 } 250 } else 251 hideConfigPanel(); 252 } 253 254 private void hideConfigPanel() { 255 jLabelConfig.setText(""); jPanelConfig.removeAll(); 257 jPanelConfig.repaint(); 258 jPanelConfig.revalidate(); 259 } 260 } 261 | Popular Tags |