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:
042: package org.netbeans.modules.ant.freeform.ui;
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.ProjectManager;
054: import org.netbeans.api.project.ProjectUtils;
055: import org.netbeans.modules.ant.freeform.FreeformProject;
056: import org.netbeans.modules.ant.freeform.spi.ProjectAccessor;
057: import org.netbeans.spi.project.AuxiliaryConfiguration;
058: import org.netbeans.spi.project.ui.CustomizerProvider;
059: import org.netbeans.spi.project.ui.support.ProjectCustomizer;
060: import org.openide.util.Lookup;
061: import org.openide.util.NbBundle;
062: import org.openide.util.lookup.AbstractLookup;
063: import org.openide.util.lookup.InstanceContent;
064:
065: /**
066: *
067: * @author Petr Hrebejk, David Konecny
068: */
069: public class ProjectCustomizerProvider implements CustomizerProvider {
070:
071: private final FreeformProject project;
072:
073: public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-ant-freeform/Customizer"; //NO18N
074:
075: private static Map<Project, Dialog> project2Dialog = new HashMap<Project, Dialog>();
076:
077: public ProjectCustomizerProvider(FreeformProject project) {
078: this .project = project;
079: }
080:
081: public void showCustomizer() {
082: Dialog dialog = project2Dialog.get(project);
083: if (dialog != null) {
084: dialog.setVisible(true);
085: return;
086: } else {
087: InstanceContent ic = new InstanceContent();
088: Lookup context = new AbstractLookup(ic);
089: ic.add(project);
090: ic.add(project.getLookup().lookup(ProjectAccessor.class));
091: ic.add(project.getLookup().lookup(
092: AuxiliaryConfiguration.class));
093: //TODO replace with generic apis..
094: ic.add(ic);
095:
096: OptionListener listener = new OptionListener(project);
097: dialog = ProjectCustomizer.createCustomizerDialog(
098: CUSTOMIZER_FOLDER_PATH, context, null, listener,
099: null);
100: dialog.addWindowListener(listener);
101: dialog.setTitle(MessageFormat.format(NbBundle.getMessage(
102: ProjectCustomizerProvider.class,
103: "LBL_Customizer_Title"), // NOI18N
104: new Object[] { ProjectUtils.getInformation(project)
105: .getDisplayName() }));
106:
107: project2Dialog.put(project, dialog);
108: dialog.setVisible(true);
109: }
110: }
111:
112: /** Listens to the actions on the Customizer's option buttons */
113: private class OptionListener extends WindowAdapter implements
114: ActionListener {
115:
116: private Project project;
117:
118: OptionListener(Project project) {
119: this .project = project;
120: }
121:
122: // Listening to OK button ----------------------------------------------
123:
124: public void actionPerformed(ActionEvent e) {
125: //#95952 some users experience this assertion on a fairly random set of changes in
126: // the customizer, that leads me to assume that a project can be already marked
127: // as modified before the project customizer is shown.
128: // assert !ProjectManager.getDefault().isModified(project) :
129: // "Some of the customizer panels has written the changed data before OK Button was pressed. Please file it as bug."; //NOI18N
130:
131: // Close & dispose the the dialog
132: Dialog dialog = project2Dialog.get(project);
133: if (dialog != null) {
134: dialog.setVisible(false);
135: dialog.dispose();
136: }
137: }
138:
139: // Listening to window events ------------------------------------------
140:
141: public void windowClosed(WindowEvent e) {
142: project2Dialog.remove(project);
143: }
144:
145: public void windowClosing(WindowEvent e) {
146: //Dispose the dialog otherwsie the {@link WindowAdapter#windowClosed}
147: //may not be called
148: Dialog dialog = project2Dialog.get(project);
149: if (dialog != null) {
150: dialog.setVisible(false);
151: dialog.dispose();
152: }
153: }
154: }
155:
156: }
|