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