KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > archive > customizer > ProvidesCustomizer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.archive.customizer;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 import javax.swing.JButton JavaDoc;
28 import org.netbeans.modules.j2ee.archive.project.ArchiveProject;
29 import org.netbeans.modules.j2ee.archive.project.ArchiveProjectProperties;
30
31 import org.openide.DialogDescriptor;
32 import org.openide.DialogDisplayer;
33 import org.openide.ErrorManager;
34 import org.openide.util.NbBundle;
35
36 import org.netbeans.api.project.Project;
37 import org.netbeans.api.project.ProjectManager;
38 import org.netbeans.api.project.ProjectUtils;
39
40 import org.netbeans.spi.project.support.ant.AntProjectHelper;
41 import org.netbeans.spi.project.ui.CustomizerProvider;
42
43
44 /** Customization of J2EE/Java EE archive project
45  *
46  * @author vince kraemer
47  */

48 public class ProvidesCustomizer implements CustomizerProvider {
49     
50     private final Project project;
51     private final AntProjectHelper antProjectHelper;
52     
53     // Option indexes
54
private static final int OPTION_OK = 0;
55     private static final int OPTION_CANCEL = OPTION_OK + 1;
56     
57     // Option command names
58
private static final String JavaDoc COMMAND_OK = "OK"; // NOI18N
59
private static final String JavaDoc COMMAND_CANCEL = "CANCEL"; // NOI18N
60

61     public ProvidesCustomizer(Project project, AntProjectHelper antProjectHelper) {
62         this.project = project;
63         this.antProjectHelper = antProjectHelper;
64     }
65     
66     public void showCustomizer() {
67         Dialog JavaDoc dialog = createDialog();
68         dialog.setVisible(true);
69     }
70     
71     Dialog JavaDoc createDialog() {
72         // Create options
73
JButton JavaDoc options[] = new JButton JavaDoc[] {
74             new JButton JavaDoc( NbBundle.getMessage( ProvidesCustomizer.class, "LBL_Customizer_Ok_Option") ), // NOI18N
75
new JButton JavaDoc( NbBundle.getMessage( ProvidesCustomizer.class, "LBL_Customizer_Cancel_Option" ) ) , // NOI18N
76
};
77         
78         // Set commands
79
options[ OPTION_OK ].setActionCommand( COMMAND_OK );
80         options[ OPTION_CANCEL ].setActionCommand( COMMAND_CANCEL );
81         
82         // RegisterListener
83
ArchiveProjectProperties apProperties = new ArchiveProjectProperties( (ArchiveProject)project, antProjectHelper );
84         ActionListener JavaDoc optionsListener = new OptionListener( project, apProperties );
85         options[ OPTION_OK ].addActionListener( optionsListener );
86         options[ OPTION_CANCEL ].addActionListener( optionsListener );
87         
88         
89         ArchiveProjectCustomizer innerPane = new ArchiveProjectCustomizer(apProperties); // , pwm); // , preselectedNodeName);
90
DialogDescriptor dialogDescriptor = new DialogDescriptor(
91                 innerPane, // new EarCustomizer(apProperties, pwm), // innerPane
92
NbBundle.getMessage( ProvidesCustomizer.class, "LBL_Customizer_Title" , // displayName
93
ProjectUtils.getInformation(project).getDisplayName() ),
94                 false, // modal
95
options, // options
96
options[OPTION_OK], // initial value
97
DialogDescriptor.BOTTOM_ALIGN, // options align
98
null, // helpCtx
99
null ); // listener
100

101         innerPane.setDialogDescriptor(dialogDescriptor);
102         dialogDescriptor.setClosingOptions( new Object JavaDoc[] { options[ OPTION_OK ], options[ OPTION_CANCEL ] } );
103         
104         Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog( dialogDescriptor );
105         return dialog; // dialog.show();
106
}
107     
108     /** Listens to the actions on the Customizer's option buttons */
109     private static class OptionListener implements ActionListener JavaDoc {
110         
111         private Project project;
112         private ArchiveProjectProperties apProperties;
113         
114         OptionListener( Project project, ArchiveProjectProperties apProperties ) {
115             this.project = project;
116             this.apProperties = apProperties;
117         }
118         
119         public void actionPerformed( ActionEvent JavaDoc e ) {
120             String JavaDoc command = e.getActionCommand();
121             
122             if (COMMAND_OK.equals(command)) {
123                 // Store the properties
124
apProperties.save();
125                 
126                 // XXX Maybe move into WebProjectProperties
127
// And save the project
128
try {
129                     ProjectManager.getDefault().saveProject(project);
130                 } catch ( IOException JavaDoc ex ) {
131                     ErrorManager.getDefault().notify( ex );
132                 }
133             }
134             
135         }
136         
137     }
138     
139 }
140
Popular Tags