1 19 20 package org.netbeans.modules.web.project.ui.customizer; 21 22 import java.awt.Dialog ; 23 import java.awt.GridBagConstraints ; 24 import java.awt.GridBagLayout ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 import java.awt.event.WindowAdapter ; 28 import java.awt.event.WindowEvent ; 29 import java.text.MessageFormat ; 30 import java.util.HashMap ; 31 import java.util.List ; 32 import java.util.Map ; 33 import java.util.ResourceBundle ; 34 import javax.swing.JComponent ; 35 import javax.swing.JLabel ; 36 import javax.swing.JPanel ; 37 import javax.swing.SwingConstants ; 38 import org.netbeans.api.project.Project; 39 import org.netbeans.api.project.ProjectManager; 40 import org.netbeans.api.project.ProjectUtils; 41 import org.openide.filesystems.FileObject; 42 import org.netbeans.modules.web.project.ProjectWebModule; 43 import org.netbeans.modules.web.project.WebProject; 44 import org.netbeans.modules.web.project.UpdateHelper; 45 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 46 import org.netbeans.modules.websvc.api.client.WebServicesClientSupport; 47 import org.netbeans.spi.project.support.ant.PropertyEvaluator; 48 import org.netbeans.spi.project.support.ant.ReferenceHelper; 49 import org.netbeans.spi.project.ui.CustomizerProvider; 50 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 51 import org.openide.util.HelpCtx; 52 import org.openide.util.Lookup; 53 import org.openide.util.NbBundle; 54 import org.openide.util.lookup.Lookups; 55 56 57 61 public class CustomizerProviderImpl implements CustomizerProvider { 62 63 private final Project project; 64 private final UpdateHelper updateHelper; 65 private final PropertyEvaluator evaluator; 66 private final ReferenceHelper refHelper; 67 68 private ProjectCustomizer.Category categories[]; 69 70 private static final int OPTION_OK = 0; 72 73 public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-web-project/Customizer"; 75 private static Map project2Dialog = new HashMap (); 76 77 public CustomizerProviderImpl(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper) { 78 this.project = project; 79 this.updateHelper = updateHelper; 80 this.evaluator = evaluator; 81 this.refHelper = refHelper; 82 } 83 84 public void showCustomizer() { 85 showCustomizer( null ); 86 } 87 88 public void showCustomizer( String preselectedCategory ) { 89 showCustomizer( preselectedCategory, null ); 90 } 91 92 public void showCustomizer( String preselectedCategory, String preselectedSubCategory ) { 93 94 Dialog dialog = (Dialog )project2Dialog.get (project); 95 if ( dialog != null ) { 96 dialog.setVisible(true); 97 return; 98 } 99 else { 100 WebProjectProperties uiProperties = new WebProjectProperties((WebProject) project, updateHelper, evaluator, refHelper); 101 Lookup context = Lookups.fixed(new Object [] { 102 project, 103 uiProperties, 104 new SubCategoryProvider(preselectedCategory, preselectedSubCategory) 105 }); 106 107 OptionListener listener = new OptionListener( project, uiProperties ); 108 dialog = ProjectCustomizer.createCustomizerDialog( CUSTOMIZER_FOLDER_PATH, context, preselectedCategory, listener, null ); 109 dialog.addWindowListener( listener ); 110 dialog.setTitle( MessageFormat.format( 111 NbBundle.getMessage( CustomizerProviderImpl.class, "LBL_Customizer_Title" ), new Object [] { ProjectUtils.getInformation(project).getDisplayName() } ) ); 113 114 project2Dialog.put(project, dialog); 115 dialog.setVisible(true); 116 } 117 } 118 119 120 private class OptionListener extends WindowAdapter implements ActionListener { 121 122 private Project project; 123 private WebProjectProperties uiProperties; 124 125 OptionListener( Project project, WebProjectProperties uiProperties ) { 126 this.project = project; 127 this.uiProperties = uiProperties; 128 } 129 130 132 public void actionPerformed( ActionEvent e ) { 133 uiProperties.save(); 139 140 Dialog dialog = (Dialog )project2Dialog.get( project ); 142 if ( dialog != null ) { 143 dialog.setVisible(false); 144 dialog.dispose(); 145 } 146 } 147 148 150 public void windowClosed( WindowEvent e) { 151 project2Dialog.remove( project ); 152 } 153 154 public void windowClosing( WindowEvent e ) { 155 Dialog dialog = (Dialog )project2Dialog.get( project ); 158 if ( dialog != null ) { 159 dialog.setVisible(false); 160 dialog.dispose(); 161 } 162 } 163 } 164 165 static final class SubCategoryProvider { 166 167 private String subcategory; 168 169 private String category; 170 171 SubCategoryProvider(String category, String subcategory) { 172 this.category = category; 173 this.subcategory = subcategory; 174 } 175 public String getCategory() { 176 return category; 177 } 178 public String getSubcategory() { 179 return subcategory; 180 } 181 } 182 } 183 | Popular Tags |