1 19 20 package org.netbeans.modules.j2ee.clientproject.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.j2ee.clientproject.AppClientProject; 34 import org.netbeans.modules.j2ee.clientproject.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 48 public class CustomizerProviderImpl implements CustomizerProvider { 49 50 private final Project project; 51 private final UpdateHelper updateHelper; 52 private final PropertyEvaluator evaluator; 53 private final ReferenceHelper refHelper; 54 private final GeneratedFilesHelper genFileHelper; 55 56 public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-j2ee-clientproject/Customizer"; 58 private static Map <Project, Dialog > project2Dialog = new HashMap <Project, Dialog >(); 59 60 public CustomizerProviderImpl(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper, GeneratedFilesHelper genFileHelper) { 61 this.project = project; 62 this.updateHelper = updateHelper; 63 this.evaluator = evaluator; 64 this.refHelper = refHelper; 65 this.genFileHelper = genFileHelper; 66 } 67 68 public void showCustomizer() { 69 showCustomizer( null ); 70 } 71 72 73 public void showCustomizer ( String preselectedCategory ) { 74 showCustomizer ( preselectedCategory, null ); 75 } 76 77 public void showCustomizer( String preselectedCategory, String preselectedSubCategory ) { 78 79 Dialog dialog = (Dialog )project2Dialog.get (project); 80 if ( dialog != null ) { 81 dialog.setVisible(true); 82 return; 83 } 84 else { 85 AppClientProjectProperties uiProperties = new AppClientProjectProperties( (AppClientProject)project, updateHelper, evaluator, refHelper, genFileHelper ); 86 Lookup context = Lookups.fixed(new Object [] { 87 project, 88 uiProperties, 89 new SubCategoryProvider(preselectedCategory, preselectedSubCategory) 90 }); 91 92 OptionListener listener = new OptionListener( project, uiProperties ); 93 dialog = ProjectCustomizer.createCustomizerDialog( CUSTOMIZER_FOLDER_PATH, context, preselectedCategory, listener, null ); 94 dialog.addWindowListener( listener ); 95 dialog.setTitle( MessageFormat.format( 96 NbBundle.getMessage( CustomizerProviderImpl.class, "LBL_Customizer_Title" ), new Object [] { ProjectUtils.getInformation(project).getDisplayName() } ) ); 98 99 project2Dialog.put(project, dialog); 100 dialog.setVisible(true); 101 } 102 } 103 104 105 private class OptionListener extends WindowAdapter implements ActionListener { 106 107 private Project project; 108 private AppClientProjectProperties uiProperties; 109 110 OptionListener( Project project, AppClientProjectProperties uiProperties ) { 111 this.project = project; 112 this.uiProperties = uiProperties; 113 } 114 115 117 public void actionPerformed( ActionEvent e ) { 118 assert !ProjectManager.getDefault().isModified(project) : 120 "Some of the customizer panels has written the changed data before OK Button was pressed. Please file it as bug."; uiProperties.save(); 122 123 Dialog dialog = (Dialog )project2Dialog.get( project ); 125 if ( dialog != null ) { 126 dialog.setVisible(false); 127 dialog.dispose(); 128 } 129 } 130 131 133 public void windowClosed( WindowEvent e) { 134 project2Dialog.remove( project ); 135 } 136 137 public void windowClosing (WindowEvent e) { 138 Dialog dialog = (Dialog )project2Dialog.get( project ); 141 if ( dialog != null ) { 142 dialog.setVisible(false); 143 dialog.dispose(); 144 } 145 } 146 } 147 148 static final class SubCategoryProvider { 149 150 private String subcategory; 151 private String category; 152 153 SubCategoryProvider(String category, String subcategory) { 154 this.category = category; 155 this.subcategory = subcategory; 156 } 157 158 public String getCategory() { 159 return category; 160 } 161 162 public String getSubcategory() { 163 return subcategory; 164 } 165 } 166 167 } 168 | Popular Tags |