1 19 20 package org.netbeans.modules.java.freeform.ui; 21 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.io.IOException ; 25 import javax.swing.JComponent ; 26 import javax.swing.event.ChangeEvent ; 27 import javax.swing.event.ChangeListener ; 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 44 public class ClasspathCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider { 45 46 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", NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Classpath"), null, null); 56 return cat; 57 } 58 return null; 59 } 60 61 public JComponent 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 () { 77 public void stateChanged(ChangeEvent arg0) { 78 panel.updateControls(); 79 } 80 }); 81 category.setOkButtonListener(new ActionListener () { 82 public void actionPerformed(ActionEvent arg0) { 83 JavaPlatform p = (JavaPlatform) panel.javaPlatform.getSelectedItem(); 84 if (p != initialPlatform) { 85 try { 86 jdkConf.setSelectedPlatform(p); 87 } catch (IOException x) { 88 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, x); 89 } 90 } 91 } 92 }); 93 return panel; 94 95 } 96 97 } 98 | Popular Tags |