1 19 20 package org.netbeans.modules.apisupport.project.ui.customizer; 21 22 import java.awt.Component ; 23 import java.awt.Dialog ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.awt.event.WindowAdapter ; 27 import java.awt.event.WindowEvent ; 28 import java.beans.PropertyChangeEvent ; 29 import java.beans.PropertyChangeListener ; 30 import java.io.IOException ; 31 import org.netbeans.api.project.Project; 32 import org.netbeans.api.project.ProjectManager; 33 import org.netbeans.api.project.ProjectUtils; 34 import org.netbeans.spi.project.ui.CustomizerProvider; 35 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 36 import org.openide.ErrorManager; 37 import org.openide.util.Lookup; 38 import org.openide.util.Mutex; 39 import org.openide.util.MutexException; 40 import org.openide.util.NbBundle; 41 import org.openide.util.lookup.Lookups; 42 import org.openide.util.lookup.ProxyLookup; 43 44 49 abstract class BasicCustomizer implements CustomizerProvider, PropertyChangeListener { 50 51 static final String LAST_SELECTED_PANEL = "lastSelectedPanel"; 53 54 private final Project project; 55 56 57 private Dialog dialog; 58 59 private Component lastSelectedPanel; 60 61 62 private String layerPath; 63 64 protected BasicCustomizer(final Project project, String path) { 65 this.project = project; 66 layerPath = path; 67 } 68 69 73 abstract void storeProperties() throws IOException ; 74 75 80 abstract void postSave() throws IOException ; 81 82 87 abstract Lookup prepareData(); 88 89 abstract void dialogCleanup(); 90 91 92 protected Project getProject() { 93 return project; 94 } 95 96 97 public void showCustomizer() { 98 showCustomizer(null); 99 } 100 101 102 public void showCustomizer(String preselectedCategory) { 103 showCustomizer(preselectedCategory, null); 104 } 105 106 public void showCustomizer(String preselectedCategory, String preselectedSubCategory) { 107 if (dialog != null) { 108 dialog.setVisible(true); 109 return; 110 } else { 111 Lookup context = prepareData(); 112 context = new ProxyLookup(context, Lookups.fixed(new SubCategoryProvider(preselectedCategory, preselectedSubCategory))); 116 OptionListener listener = new OptionListener(); 117 dialog = ProjectCustomizer.createCustomizerDialog(layerPath, context, 118 preselectedCategory, listener, 119 null); 120 dialog.addWindowListener(listener); 121 dialog.setTitle(NbBundle.getMessage(getClass(), "LBL_CustomizerTitle", 122 ProjectUtils.getInformation(getProject()).getDisplayName())); 123 dialog.setVisible(true); 124 } 125 } 132 133 134 141 142 public final void save() { 143 try { 144 ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction() { 145 public Object run() throws IOException { 146 storeProperties(); 147 ProjectManager.getDefault().saveProject(project); 148 return null; 149 } 150 }); 151 } catch (MutexException e) { 152 ErrorManager.getDefault().notify((IOException )e.getException()); 153 } 154 } 155 156 157 public void propertyChange(PropertyChangeEvent evt) { 158 String propertyName = evt.getPropertyName(); 159 if (propertyName == BasicCustomizer.LAST_SELECTED_PANEL) { 160 lastSelectedPanel = (Component ) evt.getSource(); 161 } 162 } 163 164 177 protected class OptionListener extends WindowAdapter implements ActionListener { 178 179 public void actionPerformed(ActionEvent e) { 181 save(); 182 } 183 184 public void windowClosed(WindowEvent e) { 186 doClose(); 187 } 188 189 public void windowClosing(WindowEvent e) { 190 doClose(); 193 } 194 195 public void doClose() { 196 if (dialog != null) { 197 dialog.removeWindowListener(this); 198 dialog.setVisible(false); 199 dialog.dispose(); 200 dialogCleanup(); 201 } 202 dialog = null; 203 } 204 205 } 206 207 208 209 static final class SubCategoryProvider { 210 211 private String subcategory; 212 213 private String category; 214 215 SubCategoryProvider(String category, String subcategory) { 216 this.category = category; 217 this.subcategory = subcategory; 218 } 219 public String getCategory() { 220 return category; 221 } 222 public String getSubcategory() { 223 return subcategory; 224 } 225 } 226 227 } 228 229 | Popular Tags |