KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > rubyproject > 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.ruby.rubyproject.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.List JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.util.ResourceBundle JavaDoc;
32 import javax.swing.JComponent JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34 import org.netbeans.api.project.Project;
35 import org.netbeans.api.project.ProjectUtils;
36 import org.netbeans.modules.ruby.rubyproject.RubyProject;
37 import org.netbeans.modules.ruby.rubyproject.UpdateHelper;
38 import org.netbeans.modules.ruby.spi.project.support.rake.GeneratedFilesHelper;
39 import org.netbeans.modules.ruby.spi.project.support.rake.PropertyEvaluator;
40 import org.netbeans.modules.ruby.spi.project.support.rake.ReferenceHelper;
41 import org.netbeans.spi.project.ui.CustomizerProvider;
42 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
43 import org.openide.util.HelpCtx;
44 import org.openide.util.Lookup;
45 import org.openide.util.NbBundle;
46 import org.openide.util.lookup.Lookups;
47
48
49 /** Customization of Ruby project
50  *
51  * @author Petr Hrebejk
52  */

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

72     public static final String JavaDoc CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-ruby-rubyproject/Customizer"; //NO18N
73

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

133         public void actionPerformed( ActionEvent JavaDoc e ) {
134             // Store the properties into project
135
uiProperties.save();
136             
137             // Close & dispose the the dialog
138
Dialog JavaDoc dialog = (Dialog JavaDoc)project2Dialog.get( project );
139             if ( dialog != null ) {
140                 dialog.setVisible(false);
141                 dialog.dispose();
142             }
143         }
144         
145         // Listening to window events ------------------------------------------------------
146

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