|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.web.project.ui; import java.awt.Dialog; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.text.MessageFormat; import java.util.Map; import java.util.WeakHashMap; import javax.swing.JButton; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.ErrorManager; import org.openide.util.NbBundle; import org.netbeans.api.project.Project; import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.ProjectUtils; import org.netbeans.spi.project.support.ant.AntProjectHelper; import org.netbeans.spi.project.support.ant.ReferenceHelper; import org.netbeans.spi.project.ui.CustomizerProvider; import org.netbeans.modules.web.project.ProjectWebModule; import org.netbeans.modules.web.project.ui.customizer.WebCustomizer; import org.netbeans.modules.web.project.ui.customizer.WebProjectProperties; /** Customization of web project * * @author Petr Hrebejk */ public class WebCustomizerProvider implements CustomizerProvider { private final Project project; private final AntProjectHelper antProjectHelper; private final ReferenceHelper refHelper; // Option indexes private static final int OPTION_OK = 0; private static final int OPTION_CANCEL = OPTION_OK + 1; // Option command names private static final String COMMAND_OK = "OK"; // NOI18N private static final String COMMAND_CANCEL = "CANCEL"; // NOI18N private DialogDescriptor dialogDescriptor; private Map customizerPerProject = new WeakHashMap (); // Is is weak needed here? public WebCustomizerProvider(Project project, AntProjectHelper antProjectHelper, ReferenceHelper refHelper) { this.project = project; this.antProjectHelper = antProjectHelper; this.refHelper = refHelper; } public void showCustomizer() { if (customizerPerProject.containsKey(project)) { Dialog dlg = (Dialog) customizerPerProject.get(project); // check if the project is being customized if (dlg.isShowing()) { // make it showed dlg.show(); return ; } } // Create options JButton options[] = new JButton[] { new JButton( NbBundle.getMessage( WebCustomizerProvider.class, "LBL_Customizer_Ok_Option") ), // NOI18N new JButton( NbBundle.getMessage( WebCustomizerProvider.class, "LBL_Customizer_Cancel_Option" ) ) , // NOI18N }; options[OPTION_OK].getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WebCustomizerProvider.class, "ACS_Customizer_Ok_Option_A11YDesc")); //NOI18N options[OPTION_OK].setMnemonic(NbBundle.getMessage(WebCustomizerProvider.class, "LBL_Customizer_Ok_Option_LabelMnemonic").charAt(0)); //NOI18N options[OPTION_CANCEL].getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(WebCustomizerProvider.class, "ACS_Customizer_Cancel_Option_A11YDesc")); //NOI18N options[OPTION_CANCEL].setMnemonic(NbBundle.getMessage(WebCustomizerProvider.class, "LBL_Customizer_Cancel_Option_LabelMnemonic").charAt(0)); //NOI18N // Set commands options[ OPTION_OK ].setActionCommand( COMMAND_OK ); options[ OPTION_CANCEL ].setActionCommand( COMMAND_CANCEL ); // RegisterListener WebProjectProperties webProperties = new WebProjectProperties( project, antProjectHelper, refHelper ); ActionListener optionsListener = new OptionListener( project, webProperties ); options[ OPTION_OK ].addActionListener( optionsListener ); options[ OPTION_CANCEL ].addActionListener( optionsListener ); ProjectWebModule pwm = (ProjectWebModule) project.getLookup ().lookup (ProjectWebModule.class); WebCustomizer innerPane = new WebCustomizer(webProperties, pwm); dialogDescriptor = new DialogDescriptor( innerPane, // innerPane MessageFormat.format( // displayName NbBundle.getMessage( WebCustomizerProvider.class, "LBL_Customizer_Title" ), // NOI18N new Object[] { ProjectUtils.getInformation(project).getDisplayName() } ), false, // modal options, // options options[OPTION_OK], // initial value DialogDescriptor.BOTTOM_ALIGN, // options align null, // helpCtx null ); // listener innerPane.setDialogDescriptor(dialogDescriptor); dialogDescriptor.setClosingOptions( new Object[] { options[ OPTION_OK ], options[ OPTION_CANCEL ] } ); Dialog dialog = DialogDisplayer.getDefault().createDialog( dialogDescriptor ); customizerPerProject.put(project, dialog); dialog.show(); } /** Listens to the actions on the Customizer's option buttons */ private static class OptionListener implements ActionListener { private Project project; private WebProjectProperties webProperties; OptionListener( Project project, WebProjectProperties webProperties ) { this.project = project; this.webProperties = webProperties; } public void actionPerformed( ActionEvent e ) { String command = e.getActionCommand(); if (COMMAND_OK.equals(command)) { // Store the properties webProperties.store(); // XXX Maybe move into WebProjectProperties // And save the project try { ProjectManager.getDefault().saveProject(project); } catch ( IOException ex ) { ErrorManager.getDefault().notify( ex ); } } } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.