1 19 20 package org.netbeans.modules.ant.freeform.ui; 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.ant.freeform.FreeformProject; 34 import org.netbeans.modules.ant.freeform.spi.ProjectAccessor; 35 import org.netbeans.spi.project.AuxiliaryConfiguration; 36 import org.netbeans.spi.project.ui.CustomizerProvider; 37 import org.netbeans.spi.project.ui.support.ProjectCustomizer; 38 import org.openide.util.Lookup; 39 import org.openide.util.NbBundle; 40 import org.openide.util.lookup.AbstractLookup; 41 import org.openide.util.lookup.InstanceContent; 42 43 47 public class ProjectCustomizerProvider implements CustomizerProvider { 48 49 private final FreeformProject project; 50 51 public static final String CUSTOMIZER_FOLDER_PATH = "Projects/org-netbeans-modules-ant-freeform/Customizer"; 53 private static Map <Project,Dialog > project2Dialog = new HashMap <Project,Dialog >(); 54 55 public ProjectCustomizerProvider(FreeformProject project) { 56 this.project = project; 57 } 58 59 public void showCustomizer() { 60 Dialog dialog = project2Dialog.get (project); 61 if ( dialog != null ) { 62 dialog.setVisible(true); 63 return; 64 } 65 else { 66 InstanceContent ic = new InstanceContent(); 67 Lookup context = new AbstractLookup(ic); 68 ic.add(project); 69 ic.add(project.getLookup().lookup(ProjectAccessor.class)); 70 ic.add(project.getLookup().lookup(AuxiliaryConfiguration.class)); 71 ic.add(ic); 73 74 OptionListener listener = new OptionListener( project ); 75 dialog = ProjectCustomizer.createCustomizerDialog(CUSTOMIZER_FOLDER_PATH, context, null, listener, null ); 76 dialog.addWindowListener( listener ); 77 dialog.setTitle( MessageFormat.format( 78 NbBundle.getMessage( ProjectCustomizerProvider.class, "LBL_Customizer_Title" ), new Object [] { ProjectUtils.getInformation(project).getDisplayName() } ) ); 80 81 project2Dialog.put(project, dialog); 82 dialog.setVisible(true); 83 } 84 } 85 86 87 88 private class OptionListener extends WindowAdapter implements ActionListener { 89 90 private Project project; 91 92 OptionListener( Project project) { 93 this.project = project; 94 } 95 96 98 public void actionPerformed( ActionEvent e ) { 99 105 Dialog dialog = project2Dialog.get( project ); 107 if ( dialog != null ) { 108 dialog.setVisible(false); 109 dialog.dispose(); 110 } 111 } 112 113 115 public void windowClosed( WindowEvent e) { 116 project2Dialog.remove( project ); 117 } 118 119 public void windowClosing (WindowEvent e) { 120 Dialog dialog = project2Dialog.get( project ); 123 if ( dialog != null ) { 124 dialog.setVisible(false); 125 dialog.dispose(); 126 } 127 } 128 } 129 130 } 131 | Popular Tags |