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-2007 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.compapp.projects.jbi.ui;
043:
044: import org.netbeans.modules.compapp.projects.jbi.CasaHelper;
045: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.JbiJarCustomizer;
046: import org.netbeans.modules.compapp.projects.jbi.ui.customizer.JbiProjectProperties;
047:
048: import org.netbeans.api.project.Project;
049: import org.netbeans.api.project.ProjectManager;
050: import org.netbeans.api.project.ProjectUtils;
051:
052: import org.netbeans.spi.project.support.ant.AntProjectHelper;
053: import org.netbeans.spi.project.support.ant.ReferenceHelper;
054: import org.netbeans.spi.project.ui.CustomizerProvider;
055:
056: import org.openide.DialogDescriptor;
057: import org.openide.DialogDisplayer;
058: import org.openide.ErrorManager;
059:
060: import org.openide.util.NbBundle;
061:
062: import java.awt.Dialog;
063: import java.awt.event.ActionEvent;
064: import java.awt.event.ActionListener;
065:
066: import java.io.IOException;
067:
068: import java.text.MessageFormat;
069:
070: import javax.swing.JButton;
071: import org.netbeans.modules.compapp.projects.jbi.JbiProject;
072:
073: /**
074: * Customization of web project
075: *
076: * @author Petr Hrebejk
077: */
078: public class JbiCustomizerProvider implements CustomizerProvider {
079: // Option indexes
080: private static final int OPTION_OK = 0;
081: private static final int OPTION_CANCEL = OPTION_OK + 1;
082:
083: // Option command names
084: private static final String COMMAND_OK = "OK"; // NOI18N
085: private static final String COMMAND_CANCEL = "CANCEL"; // NOI18N
086: private final JbiProject project;
087: private final AntProjectHelper antProjectHelper;
088: private final ReferenceHelper refHelper;
089: private JbiProjectProperties webProperties;
090:
091: /**
092: * Creates a new JbiCustomizerProvider object.
093: *
094: * @param project DOCUMENT ME!
095: * @param antProjectHelper DOCUMENT ME!
096: * @param refHelper DOCUMENT ME!
097: */
098: public JbiCustomizerProvider(JbiProject project,
099: AntProjectHelper antProjectHelper, ReferenceHelper refHelper) {
100: this .project = project;
101: this .antProjectHelper = antProjectHelper;
102: this .refHelper = refHelper;
103: }
104:
105: /**
106: * DOCUMENT ME!
107: */
108: public void showCustomizer() {
109: // Create options
110: JButton[] options = new JButton[] {
111: new JButton(NbBundle.getMessage(
112: JbiCustomizerProvider.class,
113: "LBL_Customizer_Ok_Option") // NOI18N
114: ), // NOI18N
115: new JButton(NbBundle.getMessage(
116: JbiCustomizerProvider.class,
117: "LBL_Customizer_Cancel_Option" // NOI18N
118: )), // NOI18N
119: };
120:
121: // Set commands
122: options[OPTION_OK].setActionCommand(COMMAND_OK);
123: options[OPTION_CANCEL].setActionCommand(COMMAND_CANCEL);
124:
125: //A11Y
126: options[OPTION_OK].getAccessibleContext()
127: .setAccessibleDescription(
128: NbBundle.getMessage(
129: JbiCustomizerProvider.class,
130: "AD_Customizer_Ok_Option")); // NOI18N
131: options[OPTION_CANCEL].getAccessibleContext()
132: .setAccessibleDescription(
133: NbBundle.getMessage(
134: JbiCustomizerProvider.class,
135: "AD_Customizer_Cancel_Option")); // NOI18N
136:
137: // RegisterListener
138: webProperties = new JbiProjectProperties(project,
139: antProjectHelper, refHelper);
140:
141: ActionListener optionsListener = new OptionListener(project,
142: webProperties);
143: options[OPTION_OK].addActionListener(optionsListener);
144: options[OPTION_CANCEL].addActionListener(optionsListener);
145:
146: CasaHelper.saveCasa(project);
147:
148: JbiJarCustomizer innerPane = new JbiJarCustomizer(webProperties); // , preselectedNodeName);
149: DialogDescriptor dialogDescriptor = new DialogDescriptor(
150: innerPane,//new JbiJarCustomizer(webProperties), //pwm)
151: MessageFormat.format( // displayName
152: NbBundle.getMessage(
153: JbiCustomizerProvider.class,
154: "LBL_Customizer_Title"), // NOI18N
155: new Object[] { ProjectUtils.getInformation(
156: project).getDisplayName() }), false, // modal
157: options, // options
158: options[OPTION_OK], // initial value
159: DialogDescriptor.BOTTOM_ALIGN, // options align
160: null, // helpCtx
161: null); // listener
162:
163: innerPane.setDialogDescriptor(dialogDescriptor);
164: dialogDescriptor.setClosingOptions(new Object[] {
165: options[OPTION_OK], options[OPTION_CANCEL] });
166:
167: Dialog dialog = DialogDisplayer.getDefault().createDialog(
168: dialogDescriptor);
169: dialog.setVisible(true);
170: }
171:
172: /**
173: * Listens to the actions on the Customizer's option buttons
174: */
175: private static class OptionListener implements ActionListener {
176: private Project project;
177: private JbiProjectProperties webProperties;
178:
179: /**
180: * Creates a new OptionListener object.
181: *
182: * @param project DOCUMENT ME!
183: * @param webProperties DOCUMENT ME!
184: */
185: OptionListener(Project project,
186: JbiProjectProperties webProperties) {
187: this .project = project;
188: this .webProperties = webProperties;
189: }
190:
191: /**
192: * DOCUMENT ME!
193: *
194: * @param e DOCUMENT ME!
195: */
196: public void actionPerformed(ActionEvent e) {
197: String command = e.getActionCommand();
198:
199: if (COMMAND_OK.equals(command)) {
200: // Store the properties
201: webProperties.store();
202: // webProperties.saveAssemblyInfo();
203:
204: // XXX Maybe move into WebProjectProperties
205: // And save the project
206: try {
207: ProjectManager.getDefault().saveProject(project);
208: } catch (IOException ex) {
209: ErrorManager.getDefault().notify(ex);
210: }
211: }
212: }
213: }
214: }
|