1 19 20 package org.netbeans.modules.j2ee.sun.ws7.ui; 21 22 23 import java.awt.GridBagConstraints ; 24 import java.awt.GridBagLayout ; 25 import java.awt.Insets ; 26 import java.io.File ; 27 import java.util.ArrayList ; 28 import java.net.URL ; 29 import java.net.URI ; 30 import java.util.List ; 31 import javax.swing.*; 32 import java.awt.event.*; 33 import javax.swing.event.ChangeEvent ; 34 import javax.swing.event.ChangeListener ; 35 import org.openide.filesystems.FileUtil; 36 import org.openide.util.NbBundle; 37 import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider; 38 import org.netbeans.modules.j2ee.deployment.plugins.api.J2eePlatformImpl; 39 import org.netbeans.spi.project.libraries.LibraryImplementation; 40 41 import org.netbeans.modules.j2ee.sun.ws7.dm.WS70SunDeploymentManager; 42 43 49 50 public class WS70Customizer extends JTabbedPane { 51 52 private static final String CLASSPATH = J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH; 53 private static final String SOURCES = J2eeLibraryTypeProvider.VOLUME_TYPE_SRC; 54 private static final String JAVADOC = J2eeLibraryTypeProvider.VOLUME_TYPE_JAVADOC; 55 56 private J2eePlatformImpl platform; 57 private WS70SunDeploymentManager dm; 58 59 60 public WS70Customizer(J2eePlatformImpl aPlatform, WS70SunDeploymentManager dm) { 61 platform = aPlatform; 62 this.dm = dm; 63 initComponents (); 64 } 65 66 private void initComponents() { 67 getAccessibleContext().setAccessibleName (NbBundle.getMessage(WS70Customizer.class,"ACS_Customizer")); getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(WS70Customizer.class,"ACS_Customizer")); addChangeListener(new ChangeListener () { 71 public void stateChanged(ChangeEvent e) { 72 String helpID = null; 73 switch (getSelectedIndex()) { 74 case 0 : helpID = "ws7_customizer_connection"; break; 76 case 1 : helpID = "ws7_customizer_classes"; break; 78 case 2 : helpID = "ws7_customizer_sources"; break; 80 case 3 : helpID = "ws7_customizer_javadoc"; break; 82 } 83 putClientProperty("HelpID", helpID); } 85 }); 86 addTab(NbBundle.getMessage(WS70Customizer.class,"TXT_Connection"), new WS70ConnectionTabVisualPanel(dm)); 87 addTab(NbBundle.getMessage(WS70Customizer.class,"TXT_Classes"), createPathTab(CLASSPATH)); addTab(NbBundle.getMessage(WS70Customizer.class,"TXT_Sources"), createPathTab(SOURCES)); addTab(NbBundle.getMessage(WS70Customizer.class,"TXT_Javadoc"), createPathTab(JAVADOC)); } 91 92 93 private JComponent createPathTab(String type) { 94 return new PathView(platform, type); 95 } 96 97 98 private static class PathView extends JPanel { 99 100 private JList resources; 101 private JButton addButton; 102 private String type; 103 private J2eePlatformImpl platform; 104 105 public PathView (J2eePlatformImpl aPlatform, String aType) { 106 type = aType; 107 platform = aPlatform; 108 initComponents(); 109 } 110 111 private void initComponents() { 112 setLayout(new GridBagLayout ()); 113 JLabel label = new JLabel (); 114 String key = null; 115 String mneKey = null; 116 String ad = null; 117 if (type.equals(CLASSPATH)) { 118 key = "TXT_Classes"; mneKey = "MNE_Classes"; ad = "AD_Classes"; } else if (type.equals(SOURCES)) { 122 key = "TXT_Sources"; mneKey = "MNE_Sources"; ad = "AD_Sources"; } else if (type.equals(JAVADOC)) { 126 key = "TXT_Javadoc"; mneKey = "MNE_Javadoc"; ad = "AD_Javadoc"; } else { 130 assert false : "Illegal type of panel"; return; 132 } 133 label.setText(NbBundle.getMessage(WS70Customizer.class,key)); 134 label.setDisplayedMnemonic(NbBundle.getMessage(WS70Customizer.class,mneKey).charAt(0)); 135 GridBagConstraints c = new GridBagConstraints (); 136 c.gridx = GridBagConstraints.RELATIVE; 137 c.gridy = GridBagConstraints.RELATIVE; 138 c.gridwidth = GridBagConstraints.REMAINDER; 139 c.insets = new Insets (6,12,2,0); 140 c.fill = GridBagConstraints.HORIZONTAL; 141 c.weightx = 1.0; 142 ((GridBagLayout )getLayout()).setConstraints(label,c); 143 add(label); 144 resources = new JList(new PathModel(platform, type)); 145 label.setLabelFor(resources); 146 resources.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WS70Customizer.class,ad)); 147 JScrollPane spane = new JScrollPane (this.resources); 148 151 c = new GridBagConstraints (); 154 c.gridx = GridBagConstraints.RELATIVE; 155 c.gridy = GridBagConstraints.RELATIVE; 156 c.gridwidth = 1; 157 c.gridheight = 5; 158 c.insets = new Insets (0,12,12,6); 159 c.fill = GridBagConstraints.BOTH; 160 c.weightx = 1.0; 161 c.weighty = 1.0; 162 ((GridBagLayout )this.getLayout()).setConstraints(spane,c); 163 add(spane); 164 } 165 } 166 167 168 private static class PathModel extends AbstractListModel { 169 170 private J2eePlatformImpl platform; 171 private String type; 172 private java.util.List data; 173 174 public PathModel (J2eePlatformImpl aPlatform, String aType) { 175 platform = aPlatform; 176 type = aType; 177 } 178 179 public int getSize() { 180 return this.getData().size(); 181 } 182 183 public Object getElementAt(int index) { 184 java.util.List list = this.getData(); 185 URL url = (URL )list.get(index); 186 if ("jar".equals(url.getProtocol())) { URL fileURL = FileUtil.getArchiveFile (url); 188 if (FileUtil.getArchiveRoot(fileURL).equals(url)) { 189 url = fileURL; 191 } else { 192 return url.toExternalForm(); 194 } 195 } 196 if ("file".equals(url.getProtocol())) { File f = new File (URI.create(url.toExternalForm())); 198 return f.getAbsolutePath(); 199 } 200 else { 201 return url.toExternalForm(); 202 } 203 } 204 205 private synchronized List getData() { 206 if (data == null) { 207 data = new ArrayList (); 208 LibraryImplementation[] libImpl = platform.getLibraries(); 209 for (int i = 0; i < libImpl.length; i++) { 210 data.addAll(libImpl[i].getContent(type)); 211 } 212 } 213 return data; 214 } 215 } 216 } 217 218 | Popular Tags |