1 19 package org.netbeans.modules.j2ee.weblogic9.ui.nodes; 20 21 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.awt.Insets ; 25 import java.io.File ; 26 import java.util.ArrayList ; 27 import java.net.URL ; 28 import java.net.URI ; 29 import java.util.List ; 30 import javax.swing.*; 31 import javax.swing.event.ChangeEvent ; 32 import javax.swing.event.ChangeListener ; 33 import org.openide.filesystems.FileUtil; 34 import org.openide.util.NbBundle; 35 import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider; 36 import org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformImpl; 37 import org.netbeans.spi.project.libraries.LibraryImplementation; 38 39 40 45 public class Customizer extends JTabbedPane { 46 47 private static final String CLASSPATH = J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH; 48 private static final String SOURCES = J2eeLibraryTypeProvider.VOLUME_TYPE_SRC; 49 private static final String JAVADOC = J2eeLibraryTypeProvider.VOLUME_TYPE_JAVADOC; 50 51 private J2eePlatformImpl platform; 52 53 public Customizer(J2eePlatformImpl platform) { 54 this.platform = platform; 55 initComponents (); 56 } 57 58 private void initComponents() { 59 getAccessibleContext().setAccessibleName (NbBundle.getMessage(Customizer.class,"ACS_Customizer")); getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(Customizer.class,"ACS_Customizer")); addChangeListener(new ChangeListener () { 63 public void stateChanged(ChangeEvent e) { 64 String helpID = null; 65 switch (getSelectedIndex()) { 66 case 0 : helpID = "weblogic_customizer_classes"; break; 68 case 1 : helpID = "weblogic_customizer_sources"; break; 70 case 2 : helpID = "weblogic_customizer_javadoc"; break; 72 } 73 putClientProperty("HelpID", helpID); } 75 }); 76 addTab(NbBundle.getMessage(Customizer.class,"TXT_Classes"), createPathTab(CLASSPATH)); addTab(NbBundle.getMessage(Customizer.class,"TXT_Sources"), createPathTab(SOURCES)); addTab(NbBundle.getMessage(Customizer.class,"TXT_Javadoc"), createPathTab(JAVADOC)); } 80 81 82 private JComponent createPathTab(String type) { 83 return new PathView(platform, type); 84 } 85 86 87 private static class PathView extends JPanel { 88 89 private JList resources; 90 private JButton addButton; 91 private String type; 92 private J2eePlatformImpl platform; 93 94 public PathView (J2eePlatformImpl aPlatform, String aType) { 95 type = aType; 96 platform = aPlatform; 97 initComponents(); 98 } 99 100 private void initComponents() { 101 setLayout(new GridBagLayout ()); 102 JLabel label = new JLabel (); 103 String key = null; 104 String mneKey = null; 105 String ad = null; 106 if (type.equals(CLASSPATH)) { 107 key = "TXT_Classes"; mneKey = "MNE_Classes"; ad = "AD_Classes"; } else if (type.equals(SOURCES)) { 111 key = "TXT_Sources"; mneKey = "MNE_Sources"; ad = "AD_Sources"; } else if (type.equals(JAVADOC)) { 115 key = "TXT_Javadoc"; mneKey = "MNE_Javadoc"; ad = "AD_Javadoc"; } else { 119 assert false : "Illegal type of panel"; return; 121 } 122 label.setText(NbBundle.getMessage(Customizer.class,key)); 123 label.setDisplayedMnemonic(NbBundle.getMessage(Customizer.class,mneKey).charAt(0)); 124 GridBagConstraints c = new GridBagConstraints (); 125 c.gridx = GridBagConstraints.RELATIVE; 126 c.gridy = GridBagConstraints.RELATIVE; 127 c.gridwidth = GridBagConstraints.REMAINDER; 128 c.insets = new Insets (6,12,2,0); 129 c.fill = GridBagConstraints.HORIZONTAL; 130 c.weightx = 1.0; 131 ((GridBagLayout )getLayout()).setConstraints(label,c); 132 add(label); 133 resources = new JList(new PathModel(platform, type)); 134 label.setLabelFor(resources); 135 resources.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(Customizer.class,ad)); 136 JScrollPane spane = new JScrollPane (this.resources); 137 spane.setPreferredSize(new java.awt.Dimension (200, 100)); 140 c = new GridBagConstraints (); 141 c.gridx = GridBagConstraints.RELATIVE; 142 c.gridy = GridBagConstraints.RELATIVE; 143 c.gridwidth = 1; 144 c.gridheight = 5; 145 c.insets = new Insets (0,12,12,6); 146 c.fill = GridBagConstraints.BOTH; 147 c.weightx = 1.0; 148 c.weighty = 1.0; 149 ((GridBagLayout )this.getLayout()).setConstraints(spane,c); 150 add(spane); 151 } 152 } 153 154 155 private static class PathModel extends AbstractListModel { 156 157 private J2eePlatformImpl platform; 158 private String type; 159 private java.util.List data; 160 161 public PathModel (J2eePlatformImpl aPlatform, String aType) { 162 platform = aPlatform; 163 type = aType; 164 } 165 166 public int getSize() { 167 return this.getData().size(); 168 } 169 170 public Object getElementAt(int index) { 171 java.util.List list = this.getData(); 172 URL url = (URL )list.get(index); 173 if ("jar".equals(url.getProtocol())) { URL fileURL = FileUtil.getArchiveFile (url); 175 if (FileUtil.getArchiveRoot(fileURL).equals(url)) { 176 url = fileURL; 178 } else { 179 return url.toExternalForm(); 181 } 182 } 183 if ("file".equals(url.getProtocol())) { File f = new File (URI.create(url.toExternalForm())); 185 return f.getAbsolutePath(); 186 } 187 else { 188 return url.toExternalForm(); 189 } 190 } 191 192 private synchronized List getData() { 193 if (data == null) { 194 data = new ArrayList (); 195 LibraryImplementation[] libImpl = platform.getLibraries(); 196 for (int i = 0; i < libImpl.length; i++) { 197 data.addAll(libImpl[i].getContent(type)); 198 } 199 } 200 return data; 201 } 202 } 203 } 204 | Popular Tags |