KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > ui > customizer > CustomizerProviderImpl


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.j2seproject.ui.customizer;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.awt.event.WindowAdapter JavaDoc;
26 import java.awt.event.WindowEvent JavaDoc;
27 import java.text.MessageFormat JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Map JavaDoc;
30 import org.netbeans.api.project.Project;
31 import org.netbeans.api.project.ProjectManager;
32 import org.netbeans.api.project.ProjectUtils;
33 import org.netbeans.modules.java.j2seproject.J2SEProject;
34 import org.netbeans.modules.java.j2seproject.UpdateHelper;
35 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper;
36 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
37 import org.netbeans.spi.project.support.ant.ReferenceHelper;
38 import org.netbeans.spi.project.ui.CustomizerProvider;
39 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
40 import org.openide.util.Lookup;
41 import org.openide.util.NbBundle;
42 import org.openide.util.lookup.Lookups;
43
44
45 /** Customization of J2SE project
46  *
47  * @author Petr Hrebejk
48  */

49 public class CustomizerProviderImpl implements CustomizerProvider {
50     
51     private final Project project;
52     private final UpdateHelper updateHelper;
53     private final PropertyEvaluator evaluator;
54     private final ReferenceHelper refHelper;
55     private final GeneratedFilesHelper genFileHelper;
56     
57     private ProjectCustomizer.Category categories[];
58     private ProjectCustomizer.CategoryComponentProvider panelProvider;
59     
60     // Option indexes
61
private static final int OPTION_OK = 0;
62     private static final int OPTION_CANCEL = OPTION_OK + 1;
63     
64     // Option command names
65
private static final String JavaDoc COMMAND_OK = "OK"; // NOI18N
66
private static final String JavaDoc COMMAND_CANCEL = "CANCEL"; // NOI18N
67

68     public static final String JavaDoc CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-java-j2seproject/Customizer"; //NO18N
69

70     private static Map JavaDoc /*<Project,Dialog>*/project2Dialog = new HashMap JavaDoc();
71     
72     public CustomizerProviderImpl(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper, GeneratedFilesHelper genFileHelper) {
73         this.project = project;
74         this.updateHelper = updateHelper;
75         this.evaluator = evaluator;
76         this.refHelper = refHelper;
77         this.genFileHelper = genFileHelper;
78     }
79             
80     public void showCustomizer() {
81         showCustomizer( null );
82     }
83     
84     
85     public void showCustomizer ( String JavaDoc preselectedCategory ) {
86         showCustomizer ( preselectedCategory, null );
87     }
88     
89     public void showCustomizer( String JavaDoc preselectedCategory, String JavaDoc preselectedSubCategory ) {
90         
91         Dialog JavaDoc dialog = (Dialog JavaDoc)project2Dialog.get (project);
92         if ( dialog != null ) {
93             dialog.setVisible(true);
94             return;
95         }
96         else {
97             J2SEProjectProperties uiProperties = new J2SEProjectProperties( (J2SEProject)project, updateHelper, evaluator, refHelper, genFileHelper );
98             Lookup context = Lookups.fixed(new Object JavaDoc[] {
99                 project,
100                 uiProperties,
101                 new SubCategoryProvider(preselectedCategory, preselectedSubCategory)
102             });
103
104             OptionListener listener = new OptionListener( project, uiProperties );
105             dialog = ProjectCustomizer.createCustomizerDialog( CUSTOMIZER_FOLDER_PATH, context, preselectedCategory, listener, null );
106             dialog.addWindowListener( listener );
107             dialog.setTitle( MessageFormat.format(
108                     NbBundle.getMessage( CustomizerProviderImpl.class, "LBL_Customizer_Title" ), // NOI18N
109
new Object JavaDoc[] { ProjectUtils.getInformation(project).getDisplayName() } ) );
110
111             project2Dialog.put(project, dialog);
112             dialog.setVisible(true);
113         }
114     }
115     
116     /** Listens to the actions on the Customizer's option buttons */
117     private class OptionListener extends WindowAdapter JavaDoc implements ActionListener JavaDoc {
118     
119         private Project project;
120         private J2SEProjectProperties uiProperties;
121         
122         OptionListener( Project project, J2SEProjectProperties uiProperties ) {
123             this.project = project;
124             this.uiProperties = uiProperties;
125         }
126         
127         // Listening to OK button ----------------------------------------------
128

129         public void actionPerformed( ActionEvent JavaDoc e ) {
130             // Store the properties into project
131

132 //#95952 some users experience this assertion on a fairly random set of changes in
133
// the customizer, that leads me to assume that a project can be already marked
134
// as modified before the project customizer is shown.
135
// assert !ProjectManager.getDefault().isModified(project) :
136
// "Some of the customizer panels has written the changed data before OK Button was pressed. Please file it as bug."; //NOI18N
137
uiProperties.save();
138             
139             // Close & dispose the the dialog
140
Dialog JavaDoc dialog = (Dialog JavaDoc)project2Dialog.get( project );
141             if ( dialog != null ) {
142                 dialog.setVisible(false);
143                 dialog.dispose();
144             }
145         }
146         
147         // Listening to window events ------------------------------------------
148

149         public void windowClosed( WindowEvent JavaDoc e) {
150             project2Dialog.remove( project );
151         }
152         
153         public void windowClosing (WindowEvent JavaDoc e) {
154             //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
155
//may not be called
156
Dialog JavaDoc dialog = (Dialog JavaDoc)project2Dialog.get( project );
157             if ( dialog != null ) {
158                 dialog.setVisible(false);
159                 dialog.dispose();
160             }
161         }
162     }
163     
164     static final class SubCategoryProvider {
165
166         private String JavaDoc subcategory;
167
168         private String JavaDoc category;
169
170         SubCategoryProvider(String JavaDoc category, String JavaDoc subcategory) {
171             this.category = category;
172             this.subcategory = subcategory;
173         }
174         public String JavaDoc getCategory() {
175             return category;
176         }
177         public String JavaDoc getSubcategory() {
178             return subcategory;
179         }
180     }
181    
182                             
183 }
184
Popular Tags