KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > 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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.project.ui.customizer;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.GridBagConstraints JavaDoc;
24 import java.awt.GridBagLayout JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.awt.event.WindowAdapter JavaDoc;
28 import java.awt.event.WindowEvent JavaDoc;
29 import java.text.MessageFormat JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.List JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.ResourceBundle JavaDoc;
34 import javax.swing.JComponent JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36 import javax.swing.JPanel JavaDoc;
37 import javax.swing.SwingConstants JavaDoc;
38 import org.netbeans.api.project.Project;
39 import org.netbeans.api.project.ProjectManager;
40 import org.netbeans.api.project.ProjectUtils;
41 import org.openide.filesystems.FileObject;
42 import org.netbeans.modules.web.project.ProjectWebModule;
43 import org.netbeans.modules.web.project.WebProject;
44 import org.netbeans.modules.web.project.UpdateHelper;
45 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport;
46 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport;
47 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
48 import org.netbeans.spi.project.support.ant.ReferenceHelper;
49 import org.netbeans.spi.project.ui.CustomizerProvider;
50 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
51 import org.openide.util.HelpCtx;
52 import org.openide.util.Lookup;
53 import org.openide.util.NbBundle;
54 import org.openide.util.lookup.Lookups;
55
56
57 /** Customization of Web project
58  *
59  * @author Petr Hrebejk, Radko Najman
60  */

61 public class CustomizerProviderImpl implements CustomizerProvider {
62     
63     private final Project project;
64     private final UpdateHelper updateHelper;
65     private final PropertyEvaluator evaluator;
66     private final ReferenceHelper refHelper;
67     
68     private ProjectCustomizer.Category categories[];
69     
70     // Option indexes
71
private static final int OPTION_OK = 0;
72     
73     public static final String JavaDoc CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-web-project/Customizer"; //NO18N
74

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

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

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