KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > weblogic9 > ui > nodes > 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.weblogic9.ui.nodes;
20
21
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.awt.GridBagLayout JavaDoc;
24 import java.awt.Insets JavaDoc;
25 import java.io.File JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.net.URI JavaDoc;
29 import java.util.List JavaDoc;
30 import javax.swing.*;
31 import javax.swing.event.ChangeEvent JavaDoc;
32 import javax.swing.event.ChangeListener JavaDoc;
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 /**
41  * WebLogic instance customizer which is accessible from server manager.
42  *
43  *
44  */

45 public class Customizer extends JTabbedPane {
46
47     private static final String JavaDoc CLASSPATH = J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH;
48     private static final String JavaDoc SOURCES = J2eeLibraryTypeProvider.VOLUME_TYPE_SRC;
49     private static final String JavaDoc 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")); // NOI18N
60
getAccessibleContext().setAccessibleDescription (NbBundle.getMessage(Customizer.class,"ACS_Customizer")); // NOI18N
61
// set help ID according to selected tab
62
addChangeListener(new ChangeListener JavaDoc() {
63             public void stateChanged(ChangeEvent JavaDoc e) {
64                 String JavaDoc helpID = null;
65                 switch (getSelectedIndex()) {
66                     case 0 : helpID = "weblogic_customizer_classes"; // NOI18N
67
break;
68                     case 1 : helpID = "weblogic_customizer_sources"; // NOI18N
69
break;
70                     case 2 : helpID = "weblogic_customizer_javadoc"; // NOI18N
71
break;
72                 }
73                 putClientProperty("HelpID", helpID); // NOI18N
74
}
75         });
76         addTab(NbBundle.getMessage(Customizer.class,"TXT_Classes"), createPathTab(CLASSPATH)); // NOI18N
77
addTab(NbBundle.getMessage(Customizer.class,"TXT_Sources"), createPathTab(SOURCES)); // NOI18N
78
addTab(NbBundle.getMessage(Customizer.class,"TXT_Javadoc"), createPathTab(JAVADOC)); // NOI18N
79
}
80
81
82     private JComponent createPathTab(String JavaDoc 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 JavaDoc type;
92         private J2eePlatformImpl platform;
93
94         public PathView (J2eePlatformImpl aPlatform, String JavaDoc aType) {
95             type = aType;
96             platform = aPlatform;
97             initComponents();
98         }
99
100         private void initComponents() {
101             setLayout(new GridBagLayout JavaDoc());
102             JLabel label = new JLabel ();
103             String JavaDoc key = null;
104             String JavaDoc mneKey = null;
105             String JavaDoc ad = null;
106             if (type.equals(CLASSPATH)) {
107                 key = "TXT_Classes"; // NOI18N
108
mneKey = "MNE_Classes"; // NOI18N
109
ad = "AD_Classes"; // NOI18N
110
} else if (type.equals(SOURCES)) {
111                 key = "TXT_Sources"; // NOI18N
112
mneKey = "MNE_Sources"; // NOI18N
113
ad = "AD_Sources"; // NOI18N
114
} else if (type.equals(JAVADOC)) {
115                 key = "TXT_Javadoc"; // NOI18N
116
mneKey = "MNE_Javadoc"; // NOI18N
117
ad = "AD_Javadoc"; // NOI18N
118
} else {
119                 assert false : "Illegal type of panel"; //NOI18N
120
return;
121             }
122             label.setText(NbBundle.getMessage(Customizer.class,key));
123             label.setDisplayedMnemonic(NbBundle.getMessage(Customizer.class,mneKey).charAt(0));
124             GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
125             c.gridx = GridBagConstraints.RELATIVE;
126             c.gridy = GridBagConstraints.RELATIVE;
127             c.gridwidth = GridBagConstraints.REMAINDER;
128             c.insets = new Insets JavaDoc (6,12,2,0);
129             c.fill = GridBagConstraints.HORIZONTAL;
130             c.weightx = 1.0;
131             ((GridBagLayout JavaDoc)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             // set the preferred size so that the size won't be set according to
138
// the longest row in the list by default
139
spane.setPreferredSize(new java.awt.Dimension JavaDoc(200, 100));
140             c = new GridBagConstraints JavaDoc();
141             c.gridx = GridBagConstraints.RELATIVE;
142             c.gridy = GridBagConstraints.RELATIVE;
143             c.gridwidth = 1;
144             c.gridheight = 5;
145             c.insets = new Insets JavaDoc (0,12,12,6);
146             c.fill = GridBagConstraints.BOTH;
147             c.weightx = 1.0;
148             c.weighty = 1.0;
149             ((GridBagLayout JavaDoc)this.getLayout()).setConstraints(spane,c);
150             add(spane);
151         }
152     }
153
154
155     private static class PathModel extends AbstractListModel/*<String>*/ {
156
157         private J2eePlatformImpl platform;
158         private String JavaDoc type;
159         private java.util.List JavaDoc data;
160
161         public PathModel (J2eePlatformImpl aPlatform, String JavaDoc aType) {
162             platform = aPlatform;
163             type = aType;
164         }
165
166         public int getSize() {
167             return this.getData().size();
168         }
169
170         public Object JavaDoc getElementAt(int index) {
171             java.util.List JavaDoc list = this.getData();
172             URL JavaDoc url = (URL JavaDoc)list.get(index);
173             if ("jar".equals(url.getProtocol())) { //NOI18N
174
URL JavaDoc fileURL = FileUtil.getArchiveFile (url);
175                 if (FileUtil.getArchiveRoot(fileURL).equals(url)) {
176                     // really the root
177
url = fileURL;
178                 } else {
179                     // some subdir, just show it as is
180
return url.toExternalForm();
181                 }
182             }
183             if ("file".equals(url.getProtocol())) { // NOI18N
184
File JavaDoc f = new File JavaDoc (URI.create(url.toExternalForm()));
185                 return f.getAbsolutePath();
186             }
187             else {
188                 return url.toExternalForm();
189             }
190         }
191
192         private synchronized List JavaDoc getData() {
193             if (data == null) {
194                 data = new ArrayList JavaDoc();
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