KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > freeform > ui > ClasspathCategoryProvider


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.java.freeform.ui;
21
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.io.IOException JavaDoc;
25 import javax.swing.JComponent JavaDoc;
26 import javax.swing.event.ChangeEvent JavaDoc;
27 import javax.swing.event.ChangeListener JavaDoc;
28 import org.netbeans.api.java.platform.JavaPlatform;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
31 import org.netbeans.modules.java.freeform.LookupProviderImpl;
32 import org.netbeans.modules.java.freeform.jdkselection.JdkConfiguration;
33 import org.netbeans.spi.project.AuxiliaryConfiguration;
34 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
35 import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
36 import org.openide.ErrorManager;
37 import org.openide.util.Lookup;
38 import org.openide.util.NbBundle;
39
40 /**
41  *
42  * @author mkleint
43  */

44 public class ClasspathCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider {
45     
46     /** Creates a new instance of ClasspathCategoryProvider */
47     public ClasspathCategoryProvider() {
48     }
49     
50     public Category createCategory(Lookup context) {
51         AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
52         assert aux != null;
53         if (LookupProviderImpl.isMyProject(aux)) {
54             Category cat = ProjectCustomizer.Category.create("classpath", //NOI18N
55
NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath"), null, null);
56             return cat;
57         }
58         return null;
59     }
60
61     public JComponent JavaDoc createComponent(Category category, Lookup context) {
62         Project project = (Project)context.lookup(Project.class);
63         ProjectAccessor acc = (ProjectAccessor)context.lookup(ProjectAccessor.class);
64         AuxiliaryConfiguration aux = (AuxiliaryConfiguration)context.lookup(AuxiliaryConfiguration.class);
65         assert aux != null;
66         assert acc != null;
67         assert project != null;
68         
69         final JdkConfiguration jdkConf = new JdkConfiguration(project, acc.getHelper(), acc.getEvaluator());
70         
71         final ClasspathPanel panel = new ClasspathPanel(jdkConf);
72         final JavaPlatform initialPlatform = (JavaPlatform) panel.javaPlatform.getSelectedItem();
73         ProjectModel pm = context.lookup(ProjectModel.class);
74         assert pm != null;
75         panel.setModel(pm);
76         pm.addChangeListener(new ChangeListener JavaDoc() {
77             public void stateChanged(ChangeEvent JavaDoc arg0) {
78                 panel.updateControls();
79             }
80         });
81         category.setOkButtonListener(new ActionListener JavaDoc() {
82             public void actionPerformed(ActionEvent JavaDoc arg0) {
83                 JavaPlatform p = (JavaPlatform) panel.javaPlatform.getSelectedItem();
84                 if (p != initialPlatform) {
85                     try {
86                         jdkConf.setSelectedPlatform(p);
87                     } catch (IOException JavaDoc x) {
88                         ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, x);
89                     }
90                 }
91             }
92         });
93         return panel;
94         
95     }
96
97 }
98
Popular Tags