001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 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-2006 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: package org.netbeans.modules.php.project.customizer;
042:
043: import java.awt.Dialog;
044: import java.awt.event.ActionEvent;
045: import java.awt.event.ActionListener;
046: import java.awt.event.WindowAdapter;
047: import java.awt.event.WindowEvent;
048: import java.text.MessageFormat;
049: import java.util.HashMap;
050: import java.util.LinkedList;
051: import java.util.List;
052: import java.util.Map;
053: import java.util.ResourceBundle;
054:
055: import javax.swing.JComponent;
056: import javax.swing.JPanel;
057:
058: import org.netbeans.api.project.ProjectUtils;
059: import org.netbeans.modules.php.project.PhpProject;
060: import org.netbeans.modules.php.rt.utils.ProjectWithHostCustomizer;
061: import org.netbeans.spi.project.ui.CustomizerProvider;
062: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
063: import org.netbeans.spi.project.ui.support.ProjectCustomizer.Category;
064: import org.openide.util.NbBundle;
065:
066: /**
067: * @author ads
068: *
069: */
070: public class PhpCustomizerProvider implements CustomizerProvider,
071: ProjectWithHostCustomizer {
072:
073: public static final String SOURCES = "Sources"; // NOI18N
074: private static final String HOSTS = "Hosts"; // NOI18N
075: private static final String COMMAND_LINE = "CommandLine"; // NOI18N
076:
077: public PhpCustomizerProvider(PhpProject project) {
078: myProject = project;
079: }
080:
081: public void showCustomizerHostCategory() {
082: showCustomizer(HOSTS);
083: }
084:
085: public void showCustomizer(String category) {
086: mySelectedCategory = category;
087: showCustomizer();
088: mySelectedCategory = null;
089: }
090:
091: /* (non-Javadoc)
092: * @see org.netbeans.spi.project.ui.CustomizerProvider#showCustomizer()
093: */
094: public void showCustomizer() {
095: if (myDialog != null) {
096: // check if the project is being customized
097: if (myDialog.isShowing()) {
098: // make it showed
099: myDialog.setVisible(true);
100: return;
101: }
102: } else {
103: PhpProjectProperties uiProperties = new PhpProjectProperties(
104: getProject());
105: // load PhpProjectProperties here to do it once inside
106: // 'ProjectManager.mutex().readAccess'
107: uiProperties.load();
108: init(uiProperties);
109:
110: OptionListener listener = new OptionListener(uiProperties);
111:
112: myDialog = ProjectCustomizer.createCustomizerDialog(
113: myCategories, myPanelProvider, mySelectedCategory,
114: listener, null);
115: myDialog.addWindowListener(listener);
116: myDialog.setTitle(MessageFormat.format(NbBundle
117: .getMessage(PhpCustomizerProvider.class,
118: "LBL_Customizer_Title"), // NOI18N
119: new Object[] { ProjectUtils.getInformation(
120: getProject()).getDisplayName() }));
121: myDialog.setVisible(true);
122: }
123:
124: }
125:
126: private void init(PhpProjectProperties uiProperties) {
127: ResourceBundle bundle = NbBundle
128: .getBundle(PhpCustomizerProvider.class);
129:
130: ProjectCustomizer.Category sources = ProjectCustomizer.Category
131: .create(SOURCES,
132: bundle.getString("LBL_Config_Sources"), null,
133: null);
134:
135: List<ProjectCustomizer.Category> categories = new LinkedList<ProjectCustomizer.Category>();
136: categories.add(sources);
137:
138: Map<Category, JPanel> panels = new HashMap<Category, JPanel>();
139: panels.put(sources, new CustomizerSources(uiProperties));
140:
141: initWebProviderPanel(panels, categories, uiProperties);
142:
143: initCommandLinePanel(panels, categories, uiProperties);
144:
145: myCategories = (ProjectCustomizer.Category[]) categories
146: .toArray(new ProjectCustomizer.Category[categories
147: .size()]);
148:
149: myPanelProvider = new PanelProvider(panels);
150: }
151:
152: private void initWebProviderPanel(Map<Category, JPanel> panels,
153: List<ProjectCustomizer.Category> categories,
154: PhpProjectProperties properties) {
155: ResourceBundle bundle = NbBundle
156: .getBundle(PhpCustomizerProvider.class);
157:
158: ProjectCustomizer.Category hosts = ProjectCustomizer.Category
159: .create(HOSTS, bundle.getString("LBL_Config_Hosts"),
160: null, null);
161:
162: categories.add(hosts);
163:
164: panels.put(hosts, new CustomizerHost(properties));
165:
166: }
167:
168: private void initCommandLinePanel(Map<Category, JPanel> panels,
169: List<ProjectCustomizer.Category> categories,
170: PhpProjectProperties properties) {
171: ResourceBundle bundle = NbBundle
172: .getBundle(PhpCustomizerProvider.class);
173:
174: ProjectCustomizer.Category commandLine = ProjectCustomizer.Category
175: .create(COMMAND_LINE, bundle
176: .getString("LBL_Config_Command_Line"), null,
177: null);
178:
179: categories.add(commandLine);
180:
181: panels.put(commandLine, new CustomizerCommandLine(properties));
182:
183: }
184:
185: private PhpProject getProject() {
186: return myProject;
187: }
188:
189: /** Listens to the actions on the Customizer's option buttons */
190: private class OptionListener extends WindowAdapter implements
191: ActionListener {
192:
193: OptionListener(PhpProjectProperties uiProperties) {
194: myProperties = uiProperties;
195: }
196:
197: // Listening to OK button ----------------------------------------------
198:
199: public void actionPerformed(ActionEvent e) {
200: // Store the properties into project
201: myProperties.save();
202:
203: // Close & dispose the the dialog
204: if (myDialog != null) {
205: myDialog.setVisible(false);
206: myDialog.dispose();
207: }
208: }
209:
210: // Listening to window events ------------------------------------------
211:
212: public void windowClosed(WindowEvent e) {
213: myDialog = null;
214: }
215:
216: public void windowClosing(WindowEvent e) {
217: //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
218: //may not be called
219: if (myDialog != null) {
220: myDialog.setVisible(false);
221: myDialog.dispose();
222: }
223: }
224:
225: private PhpProjectProperties myProperties;
226: }
227:
228: private static class PanelProvider implements
229: ProjectCustomizer.CategoryComponentProvider {
230:
231: private JPanel EMPTY_PANEL = new JPanel();
232:
233: PanelProvider(Map<Category, JPanel> panels) {
234: myPanels = panels;
235: }
236:
237: public JComponent create(ProjectCustomizer.Category category) {
238: JComponent panel = myPanels.get(category);
239: return panel == null ? EMPTY_PANEL : panel;
240: }
241:
242: private Map<Category, JPanel> myPanels;
243: }
244:
245: private Dialog myDialog;
246:
247: private PhpProject myProject;
248:
249: private PanelProvider myPanelProvider;
250:
251: private ProjectCustomizer.Category[] myCategories;
252:
253: private String mySelectedCategory;
254: }
|