KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.JComponent JavaDoc;
25 import org.netbeans.api.project.Project;
26 import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
27 import org.netbeans.modules.ant.freeform.spi.support.Util;
28 import org.netbeans.modules.java.freeform.LookupProviderImpl;
29 import org.netbeans.spi.project.AuxiliaryConfiguration;
30 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
31 import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
32 import org.openide.filesystems.FileUtil;
33 import org.openide.util.Lookup;
34 import org.openide.util.NbBundle;
35 import org.openide.util.lookup.InstanceContent;
36
37 /**
38  *
39  * @author mkleint
40  */

41 public class SourceFoldersCategoryProvider implements ProjectCustomizer.CompositeCategoryProvider {
42     
43     /** Creates a new instance of SouceFoldersCustomizerProvider */
44     public SourceFoldersCategoryProvider() {
45     }
46     
47     public Category createCategory(Lookup context) {
48         AuxiliaryConfiguration aux = context.lookup(AuxiliaryConfiguration.class);
49         final ProjectAccessor acc = context.lookup(ProjectAccessor.class);
50         Project project = context.lookup(Project.class);
51         assert aux != null;
52         assert acc != null;
53         assert project != null;
54         if (LookupProviderImpl.isMyProject(aux)) {
55             Category cat = ProjectCustomizer.Category.create("SourceFolders", //NOI18N
56
NbBundle.getMessage(ClasspathPanel.class, "LBL_ProjectCustomizer_Category_Sources"), null, null);
57             final ProjectModel pm = ProjectModel.createModel(Util.getProjectLocation(acc.getHelper(), acc.getEvaluator()),
58                     FileUtil.toFile(project.getProjectDirectory()), acc.getEvaluator(), acc.getHelper());
59             InstanceContent ic = context.lookup(InstanceContent.class);
60             assert ic != null;
61             ic.add(pm);
62             cat.setOkButtonListener(new ActionListener JavaDoc() {
63                 public void actionPerformed(ActionEvent JavaDoc arg0) {
64                    // store changes always because model could be modified in ClasspathPanel or OutputPanel
65
ProjectModel.saveProject(acc.getHelper(), pm);
66                 }
67             });
68             return cat;
69         }
70         return null;
71     }
72
73     public JComponent JavaDoc createComponent(Category category, Lookup context) {
74         ProjectModel pm = context.lookup(ProjectModel.class);
75         ProjectAccessor acc = context.lookup(ProjectAccessor.class);
76         assert pm != null;
77         SourceFoldersPanel panel = new SourceFoldersPanel(false);
78         panel.setModel(pm, acc.getHelper());
79         return panel;
80         
81     }
82
83 }
84
Popular Tags