001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.ruby.rubyproject.ui.customizer;
043:
044: import java.awt.Dialog;
045: import java.awt.event.ActionEvent;
046: import java.awt.event.ActionListener;
047: import java.awt.event.WindowAdapter;
048: import java.awt.event.WindowEvent;
049: import java.text.MessageFormat;
050: import java.util.HashMap;
051: import java.util.Map;
052: import org.netbeans.api.project.Project;
053: import org.netbeans.api.project.ProjectUtils;
054: import org.netbeans.modules.ruby.rubyproject.RubyProject;
055: import org.netbeans.modules.ruby.rubyproject.UpdateHelper;
056: import org.netbeans.modules.ruby.spi.project.support.rake.GeneratedFilesHelper;
057: import org.netbeans.modules.ruby.spi.project.support.rake.PropertyEvaluator;
058: import org.netbeans.modules.ruby.spi.project.support.rake.ReferenceHelper;
059: import org.netbeans.spi.project.ui.CustomizerProvider;
060: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
061: import org.openide.util.Lookup;
062: import org.openide.util.NbBundle;
063: import org.openide.util.lookup.Lookups;
064:
065: /**
066: * Customization of Ruby project.
067: *
068: * @author Petr Hrebejk
069: */
070: public class CustomizerProviderImpl implements CustomizerProvider {
071:
072: private final Project project;
073: private final UpdateHelper updateHelper;
074: private final PropertyEvaluator evaluator;
075: private final ReferenceHelper refHelper;
076: private final GeneratedFilesHelper genFileHelper;
077:
078: public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-ruby-rubyproject/Customizer"; //NOI18N
079:
080: private static Map<Project, Dialog> project2Dialog = new HashMap<Project, Dialog>();
081:
082: public CustomizerProviderImpl(Project project,
083: UpdateHelper updateHelper, PropertyEvaluator evaluator,
084: ReferenceHelper refHelper,
085: GeneratedFilesHelper genFileHelper) {
086: this .project = project;
087: this .updateHelper = updateHelper;
088: this .evaluator = evaluator;
089: this .refHelper = refHelper;
090: this .genFileHelper = genFileHelper;
091: }
092:
093: public void showCustomizer() {
094: showCustomizer(null);
095: }
096:
097: public void showCustomizer(String preselectedCategory) {
098: showCustomizer(preselectedCategory, null);
099: }
100:
101: public void showCustomizer(String preselectedCategory,
102: String preselectedSubCategory) {
103:
104: Dialog dialog = project2Dialog.get(project);
105: if (dialog != null) {
106: dialog.setVisible(true);
107: return;
108: } else {
109: RubyProjectProperties uiProperties = new RubyProjectProperties(
110: (RubyProject) project, updateHelper, evaluator,
111: refHelper, genFileHelper);
112: Lookup context = Lookups.fixed(new Object[] {
113: project,
114: uiProperties,
115: new SubCategoryProvider(preselectedCategory,
116: preselectedSubCategory) });
117:
118: OptionListener listener = new OptionListener(project,
119: uiProperties);
120: dialog = ProjectCustomizer.createCustomizerDialog(
121: CUSTOMIZER_FOLDER_PATH, context,
122: preselectedCategory, listener, null);
123: dialog.addWindowListener(listener);
124: dialog.setTitle(MessageFormat.format(NbBundle.getMessage(
125: CustomizerProviderImpl.class,
126: "LBL_Customizer_Title"), // NOI18N
127: new Object[] { ProjectUtils.getInformation(project)
128: .getDisplayName() }));
129:
130: project2Dialog.put(project, dialog);
131: dialog.setVisible(true);
132: }
133: }
134:
135: /** Listens to the actions on the Customizer's option buttons */
136: private class OptionListener extends WindowAdapter implements
137: ActionListener {
138:
139: private Project project;
140: private RubyProjectProperties uiProperties;
141:
142: OptionListener(Project project,
143: RubyProjectProperties uiProperties) {
144: this .project = project;
145: this .uiProperties = uiProperties;
146: }
147:
148: // Listening to OK button ----------------------------------------------------------
149:
150: public void actionPerformed(ActionEvent e) {
151: // Store the properties into project
152: uiProperties.save();
153:
154: // Close & dispose the the dialog
155: Dialog dialog = project2Dialog.get(project);
156: if (dialog != null) {
157: dialog.setVisible(false);
158: dialog.dispose();
159: }
160: }
161:
162: // Listening to window events ------------------------------------------------------
163:
164: public @Override
165: void windowClosed(WindowEvent e) {
166: project2Dialog.remove(project);
167: }
168:
169: public @Override
170: void windowClosing(WindowEvent e) {
171: //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
172: //may not be called
173: Dialog dialog = project2Dialog.get(project);
174: if (dialog != null) {
175: dialog.setVisible(false);
176: dialog.dispose();
177: }
178: }
179: }
180:
181: static final class SubCategoryProvider {
182:
183: private String subcategory;
184:
185: private String category;
186:
187: SubCategoryProvider(String category, String subcategory) {
188: this .category = category;
189: this .subcategory = subcategory;
190: }
191:
192: public String getCategory() {
193: return category;
194: }
195:
196: public String getSubcategory() {
197: return subcategory;
198: }
199: }
200:
201: }
|