1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.awt.EventQueue ; 23 import java.beans.PropertyChangeEvent ; 24 import java.util.Iterator ; 25 import java.util.SortedSet ; 26 import javax.swing.DefaultComboBoxModel ; 27 import org.netbeans.modules.apisupport.project.ui.UIUtil; 28 import org.netbeans.modules.apisupport.project.universe.LocalizedBundleInfo; 29 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 30 import org.openide.util.NbBundle; 31 32 37 final class CustomizerDisplay extends NbPropertyPanel.Single { 38 39 private boolean noBundle; 40 private ProjectCustomizer.Category cat; 41 42 43 CustomizerDisplay(final SingleModuleProperties props, ProjectCustomizer.Category cat) { 44 super(props, CustomizerDisplay.class); 45 initComponents(); 46 initAccesibility(); 47 refresh(); 48 this.cat = cat; 49 checkValidity(); 50 } 51 52 void refresh() { 53 this.noBundle = getBundle() == null; 54 if (noBundle) { 55 nameValue.setEnabled(false); 56 categoryValue.setEnabled(false); 57 shortDescValue.setEnabled(false); 58 longDescValue.setEnabled(false); 59 } else { 60 readFromProperties(); 61 } 62 } 63 64 private void checkValidity() { 65 if (this.noBundle) { 66 cat.setErrorMessage(getMessage("MSG_NoBundleForModule")); 67 } else { 68 cat.setErrorMessage(null); 69 } 70 } 71 72 public void store() { 73 if (!noBundle) { 74 getBundle().setDisplayName(nameValue.getText()); 75 getBundle().setCategory(getSelectedCategory()); 76 getBundle().setShortDescription(shortDescValue.getText()); 77 getBundle().setLongDescription(longDescValue.getText()); 78 } 79 } 80 81 private LocalizedBundleInfo getBundle() { 82 return getProperties().getBundleInfo(); 83 } 84 85 private void readFromProperties() { 86 UIUtil.setText(nameValue, getBundle().getDisplayName()); 87 UIUtil.setText(shortDescValue, getBundle().getShortDescription()); 88 longDescValue.setText(getBundle().getLongDescription()); 89 fillUpCategoryValue(); 90 } 91 92 private void fillUpCategoryValue() { 93 categoryValue.setEnabled(false); 94 categoryValue.setModel(CustomizerComponentFactory.createComboWaitModel()); 95 categoryValue.setSelectedItem(CustomizerComponentFactory.WAIT_VALUE); 96 ModuleProperties.RP.post(new Runnable () { 97 public void run() { 98 final SortedSet moduleCategories = getProperties().getModuleCategories(); 99 EventQueue.invokeLater(new Runnable () { 100 public void run() { 101 DefaultComboBoxModel model = new DefaultComboBoxModel (); 102 categoryValue.removeAllItems(); 103 for (Iterator it = moduleCategories.iterator(); it.hasNext(); ) { 104 model.addElement(it.next()); 105 } 106 if (!moduleCategories.contains(getCategory())) { 107 model.insertElementAt(getCategory(), 0); 109 } 110 categoryValue.setModel(model); 111 categoryValue.setSelectedItem(getCategory()); 112 categoryValue.setEnabled(true); 113 } 114 }); 115 } 116 }); 117 } 118 119 private String getCategory() { 120 LocalizedBundleInfo bundle = getBundle(); 121 String category = bundle != null ? bundle.getCategory() : null; 122 return category != null ? category : ""; } 124 125 public void propertyChange(PropertyChangeEvent evt) { 126 super.propertyChange(evt); 127 if (SingleModuleProperties.NB_PLATFORM_PROPERTY == evt.getPropertyName()) { 128 fillUpCategoryValue(); 129 } 130 } 131 132 private String getSelectedCategory() { 133 String cat = (String ) categoryValue.getSelectedItem(); 134 return CustomizerComponentFactory.WAIT_VALUE == cat ? getCategory() : cat; 135 } 136 137 142 private void initComponents() { 144 java.awt.GridBagConstraints gridBagConstraints; 145 146 name = new javax.swing.JLabel (); 147 nameValue = new javax.swing.JTextField (); 148 category = new javax.swing.JLabel (); 149 categoryValue = new javax.swing.JComboBox (); 150 shortDesc = new javax.swing.JLabel (); 151 shortDescValue = new javax.swing.JTextField (); 152 longDesc = new javax.swing.JLabel (); 153 hackPanel = new javax.swing.JPanel (); 154 longDescValueSP = new javax.swing.JScrollPane (); 155 longDescValue = new javax.swing.JTextArea (); 156 157 setLayout(new java.awt.GridBagLayout ()); 158 159 name.setLabelFor(nameValue); 160 org.openide.awt.Mnemonics.setLocalizedText(name, org.openide.util.NbBundle.getMessage(CustomizerDisplay.class, "LBL_DisplayName")); 161 gridBagConstraints = new java.awt.GridBagConstraints (); 162 gridBagConstraints.gridx = 0; 163 gridBagConstraints.gridy = 0; 164 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 165 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 166 add(name, gridBagConstraints); 167 168 gridBagConstraints = new java.awt.GridBagConstraints (); 169 gridBagConstraints.gridx = 1; 170 gridBagConstraints.gridy = 0; 171 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 172 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 173 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 174 add(nameValue, gridBagConstraints); 175 176 category.setLabelFor(categoryValue); 177 org.openide.awt.Mnemonics.setLocalizedText(category, org.openide.util.NbBundle.getMessage(CustomizerDisplay.class, "LBL_DisplayCategory")); 178 gridBagConstraints = new java.awt.GridBagConstraints (); 179 gridBagConstraints.gridx = 0; 180 gridBagConstraints.gridy = 1; 181 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 182 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 183 add(category, gridBagConstraints); 184 185 categoryValue.setEditable(true); 186 gridBagConstraints = new java.awt.GridBagConstraints (); 187 gridBagConstraints.gridx = 1; 188 gridBagConstraints.gridy = 1; 189 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 190 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 191 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 192 add(categoryValue, gridBagConstraints); 193 194 shortDesc.setLabelFor(shortDescValue); 195 org.openide.awt.Mnemonics.setLocalizedText(shortDesc, org.openide.util.NbBundle.getMessage(CustomizerDisplay.class, "LBL_ShortDescription")); 196 gridBagConstraints = new java.awt.GridBagConstraints (); 197 gridBagConstraints.gridx = 0; 198 gridBagConstraints.gridy = 2; 199 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 200 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 201 add(shortDesc, gridBagConstraints); 202 203 gridBagConstraints = new java.awt.GridBagConstraints (); 204 gridBagConstraints.gridx = 1; 205 gridBagConstraints.gridy = 2; 206 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 207 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 208 gridBagConstraints.insets = new java.awt.Insets (0, 0, 6, 6); 209 add(shortDescValue, gridBagConstraints); 210 211 longDesc.setLabelFor(longDescValue); 212 org.openide.awt.Mnemonics.setLocalizedText(longDesc, org.openide.util.NbBundle.getMessage(CustomizerDisplay.class, "LBL_LongDescription")); 213 gridBagConstraints = new java.awt.GridBagConstraints (); 214 gridBagConstraints.gridx = 0; 215 gridBagConstraints.gridy = 3; 216 gridBagConstraints.gridwidth = 2; 217 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 218 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 6); 219 add(longDesc, gridBagConstraints); 220 221 hackPanel.setLayout(new java.awt.BorderLayout ()); 222 223 longDescValue.setLineWrap(true); 224 longDescValue.setRows(10); 225 longDescValue.setWrapStyleWord(true); 226 longDescValueSP.setViewportView(longDescValue); 227 228 hackPanel.add(longDescValueSP, java.awt.BorderLayout.NORTH); 229 230 gridBagConstraints = new java.awt.GridBagConstraints (); 231 gridBagConstraints.gridx = 0; 232 gridBagConstraints.gridy = 4; 233 gridBagConstraints.gridwidth = 2; 234 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 235 gridBagConstraints.weightx = 1.0; 236 gridBagConstraints.weighty = 1.0; 237 add(hackPanel, gridBagConstraints); 238 239 } 240 242 243 private javax.swing.JLabel category; 245 private javax.swing.JComboBox categoryValue; 246 private javax.swing.JPanel hackPanel; 247 private javax.swing.JLabel longDesc; 248 private javax.swing.JTextArea longDescValue; 249 private javax.swing.JScrollPane longDescValueSP; 250 private javax.swing.JLabel name; 251 private javax.swing.JTextField nameValue; 252 private javax.swing.JLabel shortDesc; 253 private javax.swing.JTextField shortDescValue; 254 256 private static String getMessage(String key) { 257 return NbBundle.getMessage(CustomizerDisplay.class, key); 258 } 259 260 private void initAccesibility() { 261 longDescValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_LongDescValue")); 262 nameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_NameValue")); 263 shortDescValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_ShortDescValue")); 264 } 265 266 } 267 | Popular Tags |