1 19 20 package org.netbeans.modules.ruby.rubyproject.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.List ; 30 import java.util.Map ; 31 import java.util.ResourceBundle ; 32 import javax.swing.JComponent ; 33 import javax.swing.JPanel ; 34 import org.netbeans.api.project.Project; 35 import org.netbeans.api.project.ProjectUtils; 36 import org.netbeans.modules.ruby.rubyproject.RubyProject; 37 import org.netbeans.modules.ruby.rubyproject.UpdateHelper; 38 import org.netbeans.modules.ruby.spi.project.support.rake.GeneratedFilesHelper; 39 import org.netbeans.modules.ruby.spi.project.support.rake.PropertyEvaluator; 40 import org.netbeans.modules.ruby.spi.project.support.rake.ReferenceHelper; 41 import org.netbeans.spi.project.ui.CustomizerProvider; 42 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 43 import org.openide.util.HelpCtx; 44 import org.openide.util.Lookup; 45 import org.openide.util.NbBundle; 46 import org.openide.util.lookup.Lookups; 47 48 49 53 public class CustomizerProviderImpl implements CustomizerProvider { 54 55 private final Project project; 56 private final UpdateHelper updateHelper; 57 private final PropertyEvaluator evaluator; 58 private final ReferenceHelper refHelper; 59 private final GeneratedFilesHelper genFileHelper; 60 61 private ProjectCustomizer.Category categories[]; 62 private ProjectCustomizer.CategoryComponentProvider panelProvider; 63 64 private static final int OPTION_OK = 0; 66 private static final int OPTION_CANCEL = OPTION_OK + 1; 67 68 private static final String COMMAND_OK = "OK"; private static final String COMMAND_CANCEL = "CANCEL"; 72 public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-ruby-rubyproject/Customizer"; 74 private static Map project2Dialog = new HashMap (); 75 76 public CustomizerProviderImpl(Project project, UpdateHelper updateHelper, PropertyEvaluator evaluator, ReferenceHelper refHelper, GeneratedFilesHelper genFileHelper) { 77 this.project = project; 78 this.updateHelper = updateHelper; 79 this.evaluator = evaluator; 80 this.refHelper = refHelper; 81 this.genFileHelper = genFileHelper; 82 } 83 84 public void showCustomizer() { 85 showCustomizer( null ); 86 } 87 88 89 public void showCustomizer ( String preselectedCategory ) { 90 showCustomizer ( preselectedCategory, null ); 91 } 92 93 public void showCustomizer( String preselectedCategory, String preselectedSubCategory ) { 94 95 Dialog dialog = (Dialog )project2Dialog.get (project); 96 if ( dialog != null ) { 97 dialog.setVisible(true); 98 return; 99 } 100 else { 101 RubyProjectProperties uiProperties = new RubyProjectProperties( (RubyProject)project, updateHelper, evaluator, refHelper, genFileHelper ); 102 Lookup context = Lookups.fixed(new Object [] { 103 project, 104 uiProperties, 105 new SubCategoryProvider(preselectedCategory, preselectedSubCategory) 106 }); 107 108 OptionListener listener = new OptionListener( project, uiProperties ); 109 dialog = ProjectCustomizer.createCustomizerDialog( CUSTOMIZER_FOLDER_PATH, context, preselectedCategory, listener, null ); 110 dialog.addWindowListener( listener ); 111 dialog.setTitle( MessageFormat.format( 112 NbBundle.getMessage( CustomizerProviderImpl.class, "LBL_Customizer_Title" ), new Object [] { ProjectUtils.getInformation(project).getDisplayName() } ) ); 114 115 project2Dialog.put(project, dialog); 116 dialog.setVisible(true); 117 } 118 } 119 120 121 private class OptionListener extends WindowAdapter implements ActionListener { 122 123 private Project project; 124 private RubyProjectProperties uiProperties; 125 126 OptionListener( Project project, RubyProjectProperties uiProperties ) { 127 this.project = project; 128 this.uiProperties = uiProperties; 129 } 130 131 133 public void actionPerformed( ActionEvent e ) { 134 uiProperties.save(); 136 137 Dialog dialog = (Dialog )project2Dialog.get( project ); 139 if ( dialog != null ) { 140 dialog.setVisible(false); 141 dialog.dispose(); 142 } 143 } 144 145 147 public void windowClosed( WindowEvent e) { 148 project2Dialog.remove( project ); 149 } 150 151 public void windowClosing (WindowEvent e) { 152 Dialog dialog = (Dialog )project2Dialog.get( project ); 155 if ( dialog != null ) { 156 dialog.setVisible(false); 157 dialog.dispose(); 158 } 159 } 160 } 161 162 static final class SubCategoryProvider { 163 164 private String subcategory; 165 166 private String category; 167 168 SubCategoryProvider(String category, String subcategory) { 169 this.category = category; 170 this.subcategory = subcategory; 171 } 172 public String getCategory() { 173 return category; 174 } 175 public String getSubcategory() { 176 return subcategory; 177 } 178 } 179 180 181 } 182 | Popular Tags |