1 19 20 package org.netbeans.modules.j2ee.earproject.ui; 21 22 import java.awt.Dialog ; 23 import java.awt.event.ActionEvent ; 24 import java.awt.event.ActionListener ; 25 import javax.swing.JButton ; 26 import org.netbeans.api.project.Project; 27 import org.netbeans.api.project.ProjectUtils; 28 import org.netbeans.modules.j2ee.earproject.EarProject; 29 import org.netbeans.modules.j2ee.earproject.ProjectEar; 30 import org.netbeans.modules.j2ee.earproject.ui.customizer.EarCustomizer; 31 import org.netbeans.modules.j2ee.earproject.ui.customizer.EarProjectProperties; 32 import org.netbeans.spi.project.support.ant.AntBasedProjectType; 33 import org.netbeans.spi.project.support.ant.AntProjectHelper; 34 import org.netbeans.spi.project.support.ant.ReferenceHelper; 35 import org.netbeans.spi.project.ui.CustomizerProvider; 36 import org.openide.DialogDescriptor; 37 import org.openide.DialogDisplayer; 38 import org.openide.util.NbBundle; 39 40 45 public class EarCustomizerProvider implements CustomizerProvider { 46 47 private final Project project; 48 private final AntProjectHelper antProjectHelper; 49 private final ReferenceHelper refHelper; 50 private final AntBasedProjectType abpt; 51 52 private static final int OPTION_OK = 0; 54 private static final int OPTION_CANCEL = OPTION_OK + 1; 55 56 private static final String COMMAND_OK = "OK"; private static final String COMMAND_CANCEL = "CANCEL"; 60 public EarCustomizerProvider(Project project, AntProjectHelper antProjectHelper, ReferenceHelper refHelper, AntBasedProjectType abpt) { 61 this.project = project; 62 this.antProjectHelper = antProjectHelper; 63 this.refHelper = refHelper; 64 this.abpt = abpt; 65 } 66 67 public void showCustomizer() { 68 createDialog().setVisible(true); 69 } 70 71 Dialog createDialog() { 72 JButton options[] = new JButton [] { 74 new JButton ( NbBundle.getMessage( EarCustomizerProvider.class, "LBL_Customizer_Ok_Option") ), new JButton ( NbBundle.getMessage( EarCustomizerProvider.class, "LBL_Customizer_Cancel_Option" ) ) , }; 77 78 options[ OPTION_OK ].setActionCommand( COMMAND_OK ); 80 options[ OPTION_CANCEL ].setActionCommand( COMMAND_CANCEL ); 81 82 EarProjectProperties earProperties = new EarProjectProperties( (EarProject)project, refHelper, abpt ); 84 ActionListener optionsListener = new OptionListener( project, earProperties ); 85 options[ OPTION_OK ].addActionListener( optionsListener ); 86 options[ OPTION_CANCEL ].addActionListener( optionsListener ); 87 88 ProjectEar pwm = (ProjectEar) project.getLookup().lookup(ProjectEar.class); 89 90 EarCustomizer innerPane = new EarCustomizer(earProperties, pwm); DialogDescriptor dialogDescriptor = new DialogDescriptor( 92 innerPane, NbBundle.getMessage( EarCustomizerProvider.class, "LBL_Customizer_Title" , ProjectUtils.getInformation(project).getDisplayName() ), 95 false, options, options[OPTION_OK], DialogDescriptor.BOTTOM_ALIGN, null, null ); 102 innerPane.setDialogDescriptor(dialogDescriptor); 103 dialogDescriptor.setClosingOptions( new Object [] { options[ OPTION_OK ], options[ OPTION_CANCEL ] } ); 104 105 return DialogDisplayer.getDefault().createDialog(dialogDescriptor); 106 } 107 108 109 private static class OptionListener implements ActionListener { 110 111 private Project project; 112 private EarProjectProperties earProperties; 113 114 OptionListener( Project project, EarProjectProperties earProperties ) { 115 this.project = project; 116 this.earProperties = earProperties; 117 } 118 119 public void actionPerformed( ActionEvent e ) { 120 String command = e.getActionCommand(); 121 122 if (COMMAND_OK.equals(command)) { 123 earProperties.store(); 125 } 126 127 } 128 129 } 130 131 } 132 | Popular Tags |