KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > ui > Customizer


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 package org.netbeans.modules.j2ee.websphere6.ui;
20
21 import java.awt.GridBagConstraints JavaDoc;
22 import java.awt.GridBagLayout JavaDoc;
23 import java.awt.Insets JavaDoc;
24 import java.io.File JavaDoc;
25 import java.util.ArrayList JavaDoc;
26 import java.net.URL JavaDoc;
27 import java.net.URI JavaDoc;
28 import java.util.List JavaDoc;
29 import javax.swing.*;
30 import javax.swing.event.ChangeEvent JavaDoc;
31 import javax.swing.event.ChangeListener JavaDoc;
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 /**
40  * WebSphere instance customizer which is accessible from server manager.
41  *
42  * @author Dmitry Lipin
43  */

44 public class Customizer extends JTabbedPane {
45
46     private static final String JavaDoc CLASSPATH = J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH;
47     private static final String JavaDoc SOURCES = J2eeLibraryTypeProvider.VOLUME_TYPE_SRC;
48     private static final String JavaDoc 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")); // NOI18N
64
getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(Customizer.class,"WS_Customizer")); // NOI18N
65
// set help ID according to selected tab
66
addChangeListener(new ChangeListener JavaDoc() {
67             public void stateChanged(ChangeEvent JavaDoc e) {
68                 String JavaDoc helpID = null;
69                 switch (getSelectedIndex()) {
70                     case 0 : helpID = "websphere6_customizer_connection"; // NOI18N
71
break;
72                     case 1 : helpID = "websphere6_customizer_classes"; // NOI18N
73
break;
74                     case 2 : helpID = "websphere6_customizer_sources"; // NOI18N
75
break;
76                     case 3 : helpID = "websphere6_customizer_javadoc"; // NOI18N
77
break;
78                 }
79                 putClientProperty("HelpID", helpID); // NOI18N
80
}
81         });
82         
83         addTab(NbBundle.getMessage(Customizer.class,"TXT_Connection"), new ConnectionTabVisualPanel(dmp));
84         addTab(NbBundle.getMessage(Customizer.class,"TXT_Classes"), createPathTab(CLASSPATH)); // NOI18N
85
addTab(NbBundle.getMessage(Customizer.class,"TXT_Sources"), createPathTab(SOURCES)); // NOI18N
86
addTab(NbBundle.getMessage(Customizer.class,"TXT_Javadoc"), createPathTab(JAVADOC)); // NOI18N
87

88     }
89
90
91     private JComponent createPathTab(String JavaDoc 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 JavaDoc type;
101         private J2eePlatformImpl platform;
102
103         public PathView (J2eePlatformImpl aPlatform, String JavaDoc aType) {
104             type = aType;
105             platform = aPlatform;
106             initComponents();
107         }
108
109         private void initComponents() {
110             setLayout(new GridBagLayout JavaDoc());
111             JLabel label = new JLabel ();
112             String JavaDoc key = null;
113             String JavaDoc mneKey = null;
114             String JavaDoc ad = null;
115             if (type.equals(CLASSPATH)) {
116                 key = "TXT_Classes"; // NOI18N
117
mneKey = "MNE_Classes"; // NOI18N
118
ad = "AD_Classes"; // NOI18N
119
} else if (type.equals(SOURCES)) {
120                 key = "TXT_Sources"; // NOI18N
121
mneKey = "MNE_Sources"; // NOI18N
122
ad = "AD_Sources"; // NOI18N
123
} else if (type.equals(JAVADOC)) {
124                 key = "TXT_Javadoc"; // NOI18N
125
mneKey = "MNE_Javadoc"; // NOI18N
126
ad = "AD_Javadoc"; // NOI18N
127
} else {
128                 assert false : "Illegal type of panel"; //NOI18N
129
return;
130             }
131             label.setText(NbBundle.getMessage(Customizer.class,key));
132             label.setDisplayedMnemonic(NbBundle.getMessage(Customizer.class,mneKey).charAt(0));
133             GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
134             c.gridx = GridBagConstraints.RELATIVE;
135             c.gridy = GridBagConstraints.RELATIVE;
136             c.gridwidth = GridBagConstraints.REMAINDER;
137             c.insets = new Insets JavaDoc (6,12,2,0);
138             c.fill = GridBagConstraints.HORIZONTAL;
139             c.weightx = 1.0;
140             ((GridBagLayout JavaDoc)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             // set the preferred size so that the size won't be set according to
147
// the longest row in the list by default
148
spane.setPreferredSize(new java.awt.Dimension JavaDoc(200, 100));
149             c = new GridBagConstraints JavaDoc();
150             c.gridx = GridBagConstraints.RELATIVE;
151             c.gridy = GridBagConstraints.RELATIVE;
152             c.gridwidth = 1;
153             c.gridheight = 5;
154             c.insets = new Insets JavaDoc (0,12,12,6);
155             c.fill = GridBagConstraints.BOTH;
156             c.weightx = 1.0;
157             c.weighty = 1.0;
158             ((GridBagLayout JavaDoc)this.getLayout()).setConstraints(spane,c);
159             add(spane);
160         }
161     }
162
163
164     private static class PathModel extends AbstractListModel/*<String>*/ {
165
166         private J2eePlatformImpl platform;
167         private String JavaDoc type;
168         private java.util.List JavaDoc data;
169
170         public PathModel (J2eePlatformImpl aPlatform, String JavaDoc aType) {
171             platform = aPlatform;
172             type = aType;
173         }
174
175         public int getSize() {
176             return this.getData().size();
177         }
178
179         public Object JavaDoc getElementAt(int index) {
180             java.util.List JavaDoc list = this.getData();
181             URL JavaDoc url = (URL JavaDoc)list.get(index);
182             if ("jar".equals(url.getProtocol())) { // NOI18N
183
URL JavaDoc fileURL = FileUtil.getArchiveFile (url);
184                 if (FileUtil.getArchiveRoot(fileURL).equals(url)) {
185                     // really the root
186
url = fileURL;
187                 } else {
188                     // some subdir, just show it as is
189
return url.toExternalForm();
190                 }
191             }
192             if ("file".equals(url.getProtocol())) { // NOI18N
193
File JavaDoc f = new File JavaDoc (URI.create(url.toExternalForm()));
194                 return f.getAbsolutePath();
195             }
196             else {
197                 return url.toExternalForm();
198             }
199         }
200
201         private synchronized List JavaDoc getData() {
202             if (data == null) {
203                 data = new ArrayList JavaDoc();
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