KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > ui > WS70Customizer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.ws7.ui;
21
22
23 import java.awt.GridBagConstraints JavaDoc;
24 import java.awt.GridBagLayout JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.io.File JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.net.URI JavaDoc;
30 import java.util.List JavaDoc;
31 import javax.swing.*;
32 import java.awt.event.*;
33 import javax.swing.event.ChangeEvent JavaDoc;
34 import javax.swing.event.ChangeListener JavaDoc;
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 /**
44  * WebServer70 instance customizer which is accessible from server manager.
45  *
46  * @author Stepan Herold
47  * Adapted by Mukesh Garg for Webserver70 customizer.
48  */

49
50 public class WS70Customizer extends JTabbedPane {
51
52     private static final String JavaDoc CLASSPATH = J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH;
53     private static final String JavaDoc SOURCES = J2eeLibraryTypeProvider.VOLUME_TYPE_SRC;
54     private static final String JavaDoc 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")); // NOI18N
68
getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(WS70Customizer.class,"ACS_Customizer")); // NOI18N
69
// set help ID according to selected tab
70
addChangeListener(new ChangeListener JavaDoc() {
71             public void stateChanged(ChangeEvent JavaDoc e) {
72                 String JavaDoc helpID = null;
73                 switch (getSelectedIndex()) {
74                     case 0 : helpID = "ws7_customizer_connection"; // NOI18N
75
break;
76                     case 1 : helpID = "ws7_customizer_classes"; // NOI18N
77
break;
78                     case 2 : helpID = "ws7_customizer_sources"; // NOI18N
79
break;
80                     case 3 : helpID = "ws7_customizer_javadoc"; // NOI18N
81
break;
82                 }
83                 putClientProperty("HelpID", helpID); // NOI18N
84
}
85         });
86         addTab(NbBundle.getMessage(WS70Customizer.class,"TXT_Connection"), new WS70ConnectionTabVisualPanel(dm));
87         addTab(NbBundle.getMessage(WS70Customizer.class,"TXT_Classes"), createPathTab(CLASSPATH)); // NOI18N
88
addTab(NbBundle.getMessage(WS70Customizer.class,"TXT_Sources"), createPathTab(SOURCES)); // NOI18N
89
addTab(NbBundle.getMessage(WS70Customizer.class,"TXT_Javadoc"), createPathTab(JAVADOC)); // NOI18N
90
}
91
92
93     private JComponent createPathTab(String JavaDoc 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 JavaDoc type;
103         private J2eePlatformImpl platform;
104
105         public PathView (J2eePlatformImpl aPlatform, String JavaDoc aType) {
106             type = aType;
107             platform = aPlatform;
108             initComponents();
109         }
110
111         private void initComponents() {
112             setLayout(new GridBagLayout JavaDoc());
113             JLabel label = new JLabel ();
114             String JavaDoc key = null;
115             String JavaDoc mneKey = null;
116             String JavaDoc ad = null;
117             if (type.equals(CLASSPATH)) {
118                 key = "TXT_Classes"; // NOI18N
119
mneKey = "MNE_Classes"; // NOI18N
120
ad = "AD_Classes"; // NOI18N
121
} else if (type.equals(SOURCES)) {
122                 key = "TXT_Sources"; // NOI18N
123
mneKey = "MNE_Sources"; // NOI18N
124
ad = "AD_Sources"; // NOI18N
125
} else if (type.equals(JAVADOC)) {
126                 key = "TXT_Javadoc"; // NOI18N
127
mneKey = "MNE_Javadoc"; // NOI18N
128
ad = "AD_Javadoc"; // NOI18N
129
} else {
130                 assert false : "Illegal type of panel"; //NOI18N
131
return;
132             }
133             label.setText(NbBundle.getMessage(WS70Customizer.class,key));
134             label.setDisplayedMnemonic(NbBundle.getMessage(WS70Customizer.class,mneKey).charAt(0));
135             GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
136             c.gridx = GridBagConstraints.RELATIVE;
137             c.gridy = GridBagConstraints.RELATIVE;
138             c.gridwidth = GridBagConstraints.REMAINDER;
139             c.insets = new Insets JavaDoc (6,12,2,0);
140             c.fill = GridBagConstraints.HORIZONTAL;
141             c.weightx = 1.0;
142             ((GridBagLayout JavaDoc)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             // set the preferred size so that the size won't be set according to
149
// the longest row in the list by default
150

151             //Fixing Issue# 80007
152
//spane.setPreferredSize(new java.awt.Dimension(200, 100));
153
c = new GridBagConstraints JavaDoc();
154             c.gridx = GridBagConstraints.RELATIVE;
155             c.gridy = GridBagConstraints.RELATIVE;
156             c.gridwidth = 1;
157             c.gridheight = 5;
158             c.insets = new Insets JavaDoc (0,12,12,6);
159             c.fill = GridBagConstraints.BOTH;
160             c.weightx = 1.0;
161             c.weighty = 1.0;
162             ((GridBagLayout JavaDoc)this.getLayout()).setConstraints(spane,c);
163             add(spane);
164         }
165     }
166
167
168     private static class PathModel extends AbstractListModel/*<String>*/ {
169
170         private J2eePlatformImpl platform;
171         private String JavaDoc type;
172         private java.util.List JavaDoc data;
173
174         public PathModel (J2eePlatformImpl aPlatform, String JavaDoc aType) {
175             platform = aPlatform;
176             type = aType;
177         }
178
179         public int getSize() {
180             return this.getData().size();
181         }
182
183         public Object JavaDoc getElementAt(int index) {
184             java.util.List JavaDoc list = this.getData();
185             URL JavaDoc url = (URL JavaDoc)list.get(index);
186             if ("jar".equals(url.getProtocol())) { // NOI18N
187
URL JavaDoc fileURL = FileUtil.getArchiveFile (url);
188                 if (FileUtil.getArchiveRoot(fileURL).equals(url)) {
189                     // really the root
190
url = fileURL;
191                 } else {
192                     // some subdir, just show it as is
193
return url.toExternalForm();
194                 }
195             }
196             if ("file".equals(url.getProtocol())) { // NOI18N
197
File JavaDoc f = new File JavaDoc (URI.create(url.toExternalForm()));
198                 return f.getAbsolutePath();
199             }
200             else {
201                 return url.toExternalForm();
202             }
203         }
204
205         private synchronized List JavaDoc getData() {
206             if (data == null) {
207                 data = new ArrayList JavaDoc();
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