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