KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ejbjarproject > 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.ejbjarproject.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.ejbjarproject.EjbJarProject;
34 import org.netbeans.modules.j2ee.ejbjarproject.UpdateHelper;
35 import org.netbeans.spi.project.support.ant.PropertyEvaluator;
36 import org.netbeans.spi.project.support.ant.ReferenceHelper;
37 import org.netbeans.spi.project.ui.CustomizerProvider;
38 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
39 import org.openide.util.Lookup;
40 import org.openide.util.NbBundle;
41 import org.openide.util.lookup.Lookups;
42
43 /** Customization of EJB project
44  *
45  * @author Petr Hrebejk
46  */

47 public class CustomizerProviderImpl implements CustomizerProvider {
48     
49     private final Project project;
50     private final UpdateHelper updateHelper;
51     private final PropertyEvaluator evaluator;
52     private final ReferenceHelper refHelper;
53     
54     private ProjectCustomizer.Category categories[];
55     
56     public static final String JavaDoc CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-j2ee-ejbjarproject/Customizer"; //NO18N
57

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

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

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