KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > earproject > ui > EarCustomizerProvider


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.earproject.ui;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.event.ActionEvent JavaDoc;
24 import java.awt.event.ActionListener JavaDoc;
25 import javax.swing.JButton JavaDoc;
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 /**
41  * Customization of Enterprise Application project.
42  *
43  * @author Petr Hrebejk
44  */

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     // Option indexes
53
private static final int OPTION_OK = 0;
54     private static final int OPTION_CANCEL = OPTION_OK + 1;
55     
56     // Option command names
57
private static final String JavaDoc COMMAND_OK = "OK"; // NOI18N
58
private static final String JavaDoc COMMAND_CANCEL = "CANCEL"; // NOI18N
59

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 JavaDoc createDialog() {
72         // Create options
73
JButton JavaDoc options[] = new JButton JavaDoc[] {
74             new JButton JavaDoc( NbBundle.getMessage( EarCustomizerProvider.class, "LBL_Customizer_Ok_Option") ), // NOI18N
75
new JButton JavaDoc( NbBundle.getMessage( EarCustomizerProvider.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
EarProjectProperties earProperties = new EarProjectProperties( (EarProject)project, refHelper, abpt );
84         ActionListener JavaDoc 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); // , preselectedNodeName);
91
DialogDescriptor dialogDescriptor = new DialogDescriptor(
92                 innerPane, // new EarCustomizer(earProperties, pwm), // innerPane
93
NbBundle.getMessage( EarCustomizerProvider.class, "LBL_Customizer_Title" , // displayName
94
ProjectUtils.getInformation(project).getDisplayName() ),
95                 false, // modal
96
options, // options
97
options[OPTION_OK], // initial value
98
DialogDescriptor.BOTTOM_ALIGN, // options align
99
null, // helpCtx
100
null ); // listener
101

102         innerPane.setDialogDescriptor(dialogDescriptor);
103         dialogDescriptor.setClosingOptions( new Object JavaDoc[] { options[ OPTION_OK ], options[ OPTION_CANCEL ] } );
104         
105         return DialogDisplayer.getDefault().createDialog(dialogDescriptor);
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 EarProjectProperties earProperties;
113         
114         OptionListener( Project project, EarProjectProperties earProperties ) {
115             this.project = project;
116             this.earProperties = earProperties;
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
earProperties.store();
125             }
126             
127         }
128         
129     }
130                             
131 }
132
Popular Tags