KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > clientproject > 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.j2ee.clientproject.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.j2ee.clientproject.AppClientProject;
34 import org.netbeans.modules.j2ee.clientproject.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 /** Customization of J2SE project
45  *
46  * @author Petr Hrebejk
47  */

48 public class CustomizerProviderImpl implements CustomizerProvider {
49     
50     private final Project project;
51     private final UpdateHelper updateHelper;
52     private final PropertyEvaluator evaluator;
53     private final ReferenceHelper refHelper;
54     private final GeneratedFilesHelper genFileHelper;
55     
56     public static final String JavaDoc CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-j2ee-clientproject/Customizer"; //NO18N
57

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

117         public void actionPerformed( ActionEvent JavaDoc e ) {
118             // Store the properties into project
119
assert !ProjectManager.getDefault().isModified(project) :
120                 "Some of the customizer panels has written the changed data before OK Button was pressed. Please file it as bug."; //NOI18N
121
uiProperties.save();
122             
123             // Close & dispose the the dialog
124
Dialog JavaDoc dialog = (Dialog JavaDoc)project2Dialog.get( project );
125             if ( dialog != null ) {
126                 dialog.setVisible(false);
127                 dialog.dispose();
128             }
129         }
130         
131         // Listening to window events ------------------------------------------
132

133         public void windowClosed( WindowEvent JavaDoc e) {
134             project2Dialog.remove( project );
135         }
136         
137         public void windowClosing (WindowEvent JavaDoc e) {
138             //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
139
//may not be called
140
Dialog JavaDoc dialog = (Dialog JavaDoc)project2Dialog.get( project );
141             if ( dialog != null ) {
142                 dialog.setVisible(false);
143                 dialog.dispose();
144             }
145         }
146     }
147     
148     static final class SubCategoryProvider {
149
150         private String JavaDoc subcategory;
151         private String JavaDoc category;
152
153         SubCategoryProvider(String JavaDoc category, String JavaDoc subcategory) {
154             this.category = category;
155             this.subcategory = subcategory;
156         }
157         
158         public String JavaDoc getCategory() {
159             return category;
160         }
161         
162         public String JavaDoc getSubcategory() {
163             return subcategory;
164         }
165     }
166                             
167 }
168
Popular Tags