1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.util.Arrays ; 23 import javax.swing.event.ListSelectionListener ; 24 import org.netbeans.api.project.Project; 25 import org.netbeans.modules.apisupport.project.NbModuleProject; 26 import org.netbeans.modules.apisupport.project.ui.UIUtil; 27 import org.openide.util.NbBundle; 28 29 34 final class SuiteCustomizerSources extends NbPropertyPanel.Suite { 35 36 39 SuiteCustomizerSources(final SuiteProperties suiteProps) { 40 super(suiteProps, SuiteCustomizerSources.class); 41 initComponents(); 42 initAccesibility(); 43 prjFolderValue.setText(suiteProps.getProjectDirectory()); 44 refresh(); 45 moduleList.setCellRenderer(CustomizerComponentFactory.getModuleCellRenderer()); 46 moduleList.addListSelectionListener(new ListSelectionListener () { 47 public void valueChanged(javax.swing.event.ListSelectionEvent e) { 48 if (!e.getValueIsAdjusting()) { 49 updateEnabled(); 50 } 51 } 52 }); 53 } 54 55 void refresh() { 56 moduleList.setModel(getProperties().getModulesListModel()); 57 } 58 59 private void updateEnabled() { 60 boolean enabled = moduleList.getSelectedIndex() != -1; 61 removeModuleButton.setEnabled(enabled); 62 } 63 64 private CustomizerComponentFactory.SuiteSubModulesListModel getModuleListModel() { 65 return (CustomizerComponentFactory.SuiteSubModulesListModel) moduleList.getModel(); 66 } 67 68 73 private void initComponents() { 75 java.awt.GridBagConstraints gridBagConstraints; 76 77 prjFolderPanel = new javax.swing.JPanel (); 78 prjFolder = new javax.swing.JLabel (); 79 prjFolderValue = new javax.swing.JTextField (); 80 moduleLabel = new javax.swing.JLabel (); 81 modulesSP = new javax.swing.JScrollPane (); 82 moduleList = new javax.swing.JList (); 83 buttonPanel = new javax.swing.JPanel (); 84 addModuleButton = new javax.swing.JButton (); 85 removeModuleButton = new javax.swing.JButton (); 86 87 setLayout(new java.awt.GridBagLayout ()); 88 89 prjFolderPanel.setLayout(new java.awt.GridBagLayout ()); 90 91 prjFolder.setLabelFor(prjFolderValue); 92 org.openide.awt.Mnemonics.setLocalizedText(prjFolder, org.openide.util.NbBundle.getMessage(SuiteCustomizerSources.class, "LBL_ProjectFolder")); 93 gridBagConstraints = new java.awt.GridBagConstraints (); 94 gridBagConstraints.gridx = 0; 95 gridBagConstraints.gridy = 0; 96 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 97 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 98 prjFolderPanel.add(prjFolder, gridBagConstraints); 99 100 prjFolderValue.setEditable(false); 101 gridBagConstraints = new java.awt.GridBagConstraints (); 102 gridBagConstraints.gridx = 1; 103 gridBagConstraints.gridy = 0; 104 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 105 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 106 gridBagConstraints.weightx = 1.0; 107 prjFolderPanel.add(prjFolderValue, gridBagConstraints); 108 109 gridBagConstraints = new java.awt.GridBagConstraints (); 110 gridBagConstraints.gridx = 0; 111 gridBagConstraints.gridy = 0; 112 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 113 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 114 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 115 add(prjFolderPanel, gridBagConstraints); 116 117 moduleLabel.setLabelFor(moduleList); 118 org.openide.awt.Mnemonics.setLocalizedText(moduleLabel, org.openide.util.NbBundle.getMessage(SuiteCustomizerSources.class, "LBL_SuiteModules")); 119 gridBagConstraints = new java.awt.GridBagConstraints (); 120 gridBagConstraints.gridx = 0; 121 gridBagConstraints.gridy = 1; 122 gridBagConstraints.gridwidth = 2; 123 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 124 gridBagConstraints.insets = new java.awt.Insets (18, 0, 2, 0); 125 add(moduleLabel, gridBagConstraints); 126 127 modulesSP.setViewportView(moduleList); 128 129 gridBagConstraints = new java.awt.GridBagConstraints (); 130 gridBagConstraints.gridx = 0; 131 gridBagConstraints.gridy = 2; 132 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 133 gridBagConstraints.weightx = 1.0; 134 gridBagConstraints.weighty = 1.0; 135 add(modulesSP, gridBagConstraints); 136 137 buttonPanel.setLayout(new java.awt.GridLayout (2, 1, 0, 6)); 138 139 org.openide.awt.Mnemonics.setLocalizedText(addModuleButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerSources.class, "CTL_AddButton")); 140 addModuleButton.addActionListener(new java.awt.event.ActionListener () { 141 public void actionPerformed(java.awt.event.ActionEvent evt) { 142 addModule(evt); 143 } 144 }); 145 146 buttonPanel.add(addModuleButton); 147 148 org.openide.awt.Mnemonics.setLocalizedText(removeModuleButton, org.openide.util.NbBundle.getMessage(SuiteCustomizerSources.class, "CTL_RemoveButton")); 149 removeModuleButton.setEnabled(false); 150 removeModuleButton.addActionListener(new java.awt.event.ActionListener () { 151 public void actionPerformed(java.awt.event.ActionEvent evt) { 152 removeModule(evt); 153 } 154 }); 155 156 buttonPanel.add(removeModuleButton); 157 158 gridBagConstraints = new java.awt.GridBagConstraints (); 159 gridBagConstraints.gridx = 1; 160 gridBagConstraints.gridy = 2; 161 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 162 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 163 add(buttonPanel, gridBagConstraints); 164 165 } 166 168 private void removeModule(java.awt.event.ActionEvent evt) { getModuleListModel().removeModules(Arrays.asList(moduleList.getSelectedValues())); 170 if (moduleList.getModel().getSize() > 0) { 171 moduleList.setSelectedIndex(0); 172 } 173 moduleList.requestFocus(); 174 } 176 private void addModule(java.awt.event.ActionEvent evt) { NbModuleProject project = UIUtil.chooseSuiteComponent(this, getProperties().getProject()); 178 if (project != null) { 179 if (getModuleListModel().contains(project)) { 180 moduleList.setSelectedValue(project, true); 181 } else { 182 getModuleListModel().addModule(project); 183 } 184 } 185 } 187 private javax.swing.JButton addModuleButton; 189 private javax.swing.JPanel buttonPanel; 190 private javax.swing.JLabel moduleLabel; 191 private javax.swing.JList moduleList; 192 private javax.swing.JScrollPane modulesSP; 193 private javax.swing.JLabel prjFolder; 194 private javax.swing.JPanel prjFolderPanel; 195 private javax.swing.JTextField prjFolderValue; 196 private javax.swing.JButton removeModuleButton; 197 199 private static String getMessage(String key) { 200 return NbBundle.getMessage(CustomizerDisplay.class, key); 201 } 202 203 private void initAccesibility() { 204 addModuleButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_AddModuleButton")); 205 moduleList.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ModuleList")); 206 prjFolderValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_PrjFolderValue")); 207 removeModuleButton.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_RemoveModuleButton")); 208 } 209 210 } 211 | Popular Tags |