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