1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.librarydescriptor; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 import java.util.List ; 27 import org.netbeans.api.project.libraries.LibrariesCustomizer; 28 import org.netbeans.api.project.libraries.Library; 29 import org.netbeans.modules.apisupport.project.ui.platform.LibrariesModel; 30 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator; 31 import org.openide.WizardDescriptor; 32 import org.openide.util.HelpCtx; 33 import org.openide.util.NbBundle; 34 35 40 final class SelectLibraryPanel extends BasicWizardIterator.Panel { 41 42 private NewLibraryDescriptor.DataModel data; 43 44 47 public SelectLibraryPanel(WizardDescriptor setting, NewLibraryDescriptor.DataModel data) { 48 super(setting); 49 this.data = data; 50 initComponents(); 51 initAccessibility(); 52 putClientProperty("NewFileWizard_Title", getMessage("LBL_LibraryWizardTitle")); 53 54 } 55 56 private void initAccessibility() { 57 this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_SelectLibraryPanel")); 58 manageLibrariessButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_ManageLibraries")); 59 librariesValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_LBL_Library")); 60 } 61 62 private void checkValidity() { 63 markValid(); 65 } 66 67 Library getSelectedLibrary() { 68 return (librariesValue != null) ?(Library)librariesValue.getSelectedItem() : null; 69 } 70 71 protected void storeToDataModel() { 72 data.setLibrary(getSelectedLibrary()); 73 } 74 75 protected void readFromDataModel() { 76 checkValidity(); 77 } 78 79 protected String getPanelName() { 80 return getMessage("LBL_SelectLibraryPanel_Title"); 81 } 82 83 protected HelpCtx getHelp() { 84 return new HelpCtx(SelectLibraryPanel.class); 85 } 86 87 private static String getMessage(String key) { 88 return NbBundle.getMessage(SelectLibraryPanel.class, key); 89 } 90 91 96 private void initComponents() { 98 java.awt.GridBagConstraints gridBagConstraints; 99 100 platformPanel = new javax.swing.JPanel (); 101 library = new javax.swing.JLabel (); 102 librariesValue = LibrariesModel.getComboBox(); 103 manageLibrariessButton = new javax.swing.JButton (); 104 fillerPanel = new javax.swing.JPanel (); 105 fillerLabel = new javax.swing.JLabel (); 106 107 setLayout(new java.awt.GridBagLayout ()); 108 109 platformPanel.setLayout(new java.awt.GridBagLayout ()); 110 111 library.setLabelFor(librariesValue); 112 org.openide.awt.Mnemonics.setLocalizedText(library, org.openide.util.NbBundle.getMessage(SelectLibraryPanel.class, "LBL_Library")); 113 gridBagConstraints = new java.awt.GridBagConstraints (); 114 gridBagConstraints.gridx = 0; 115 gridBagConstraints.gridy = 0; 116 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 117 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 118 platformPanel.add(library, gridBagConstraints); 119 120 librariesValue.addItemListener(new java.awt.event.ItemListener () { 121 public void itemStateChanged(java.awt.event.ItemEvent evt) { 122 librariesValueItemStateChanged(evt); 123 } 124 }); 125 126 gridBagConstraints = new java.awt.GridBagConstraints (); 127 gridBagConstraints.gridx = 1; 128 gridBagConstraints.gridy = 0; 129 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 130 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 131 gridBagConstraints.weightx = 1.0; 132 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 133 platformPanel.add(librariesValue, gridBagConstraints); 134 135 org.openide.awt.Mnemonics.setLocalizedText(manageLibrariessButton, org.openide.util.NbBundle.getMessage(SelectLibraryPanel.class, "CTL_ManageLibraries")); 136 manageLibrariessButton.addActionListener(new java.awt.event.ActionListener () { 137 public void actionPerformed(java.awt.event.ActionEvent evt) { 138 manageLibraries(evt); 139 } 140 }); 141 142 gridBagConstraints = new java.awt.GridBagConstraints (); 143 gridBagConstraints.gridx = 2; 144 gridBagConstraints.gridy = 0; 145 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 146 platformPanel.add(manageLibrariessButton, gridBagConstraints); 147 148 gridBagConstraints = new java.awt.GridBagConstraints (); 149 gridBagConstraints.gridx = 0; 150 gridBagConstraints.gridy = 0; 151 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 152 add(platformPanel, gridBagConstraints); 153 154 fillerPanel.setLayout(new java.awt.GridBagLayout ()); 155 156 gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.gridx = 0; 158 gridBagConstraints.gridy = 2; 159 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 160 gridBagConstraints.weightx = 1.0; 161 gridBagConstraints.weighty = 1.0; 162 fillerPanel.add(fillerLabel, gridBagConstraints); 163 164 gridBagConstraints = new java.awt.GridBagConstraints (); 165 gridBagConstraints.gridx = 0; 166 gridBagConstraints.gridy = 2; 167 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 168 gridBagConstraints.weightx = 1.0; 169 gridBagConstraints.weighty = 1.0; 170 add(fillerPanel, gridBagConstraints); 171 172 } 173 175 private void librariesValueItemStateChanged(java.awt.event.ItemEvent evt) { checkValidity(); 177 } 179 private void manageLibraries(java.awt.event.ActionEvent evt) { LibrariesModel model = (LibrariesModel) librariesValue.getModel(); 181 Collection oldLibraries = Arrays.asList(model.getLibraries()); 182 LibrariesCustomizer.showCustomizer((Library)librariesValue.getSelectedItem()); 183 List currentLibraries = Arrays.asList(model.getLibraries()); 184 Collection newLibraries = new ArrayList (currentLibraries); 185 186 newLibraries.removeAll(oldLibraries); 187 int indexes[] = new int [newLibraries.size()]; 188 189 int i=0; 190 for (Iterator it = newLibraries.iterator(); it.hasNext();i++) { 191 Library lib = (Library) it.next(); 192 indexes[i] = currentLibraries.indexOf(lib); 193 } 194 if (indexes.length > 0 && i > 0) { 195 librariesValue.setSelectedIndex(indexes[i-1]); 196 } 197 } 199 private javax.swing.JLabel fillerLabel; 201 private javax.swing.JPanel fillerPanel; 202 private javax.swing.JComboBox librariesValue; 203 private javax.swing.JLabel library; 204 private javax.swing.JButton manageLibrariessButton; 205 private javax.swing.JPanel platformPanel; 206 208 } 209 | Popular Tags |