2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.j2ee.ejbcore.ejb.wizard.mdb;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
47
import org.netbeans.modules.j2ee.deployment.common.api.MessageDestination;
48
import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider;
51
* Panel for specifying message destination. Project or server message destination can be chosen.
54
public class MessageEJBWizardVisualPanel extends javax.swing.JPanel {
56
public static final String CHANGED = MessageEJBWizardVisualPanel.class.getName() + ".CHANGED";
58
private final J2eeModuleProvider provider;
59
private final Set<MessageDestination> moduleDestinations;
60
private final Set<MessageDestination> serverDestinations;
61
private final boolean isDestinationCreationSupportedByServerPlugin;
63
// private because correct initialization is needed
64
private MessageEJBWizardVisualPanel(J2eeModuleProvider provider, Set<MessageDestination> moduleDestinations, Set<MessageDestination> serverDestinations) {
67
this.provider = provider;
68
this.moduleDestinations = moduleDestinations;
69
this.serverDestinations = serverDestinations;
70
isDestinationCreationSupportedByServerPlugin = provider.getConfigSupport().supportsCreateMessageDestination();
74
* Factory method for creating new instance.
75
* @param provider Java EE module provider.
76
* @param moduleDestinations project message destinations.
77
* @param serverDestinations server message destinations.
78
* @return MessageEJBWizardVisualPanel instance.
80
public static MessageEJBWizardVisualPanel newInstance(final J2eeModuleProvider provider, final Set<MessageDestination> moduleDestinations,
81
final Set<MessageDestination> serverDestinations) {
82
MessageEJBWizardVisualPanel mdp = new MessageEJBWizardVisualPanel(provider, moduleDestinations, serverDestinations);
88
* Get the message destination.
89
* @return selected destination or <code>null</code> if no destination type is selected.
91
public MessageDestination getDestination() {
92
if (projectDestinationsRadio.isSelected()) {
93
return (MessageDestination) projectDestinationsCombo.getSelectedItem();
94
} else if (serverDestinationsRadio.isSelected()) {
95
return (MessageDestination) serverDestinationsCombo.getSelectedItem();
101
* Return <code>true</code> if current server supports message destination creation.
102
* @return <code>true</code> if current server supports message destination creation, <code>false</code> otherwise.
104
public boolean isDestinationCreationSupportedByServerPlugin() {
105
return isDestinationCreationSupportedByServerPlugin;
108
private void initialize() {
116
private void registerListeners() {
118
projectDestinationsRadio.addActionListener(new ActionListener() {
119
public void actionPerformed(ActionEvent actionEvent) {
124
serverDestinationsRadio.addActionListener(new ActionListener() {
125
public void actionPerformed(ActionEvent actionEvent) {
132
projectDestinationsCombo.addActionListener(new ActionListener() {
133
public void actionPerformed(ActionEvent actionEvent) {
137
serverDestinationsCombo.addActionListener(new ActionListener() {
138
public void actionPerformed(ActionEvent actionEvent) {
143
private void setupAddButton() {
144
if (!isDestinationCreationSupportedByServerPlugin) {
146
addButton.setEnabled(false);
150
private void handleComboBoxes() {
151
projectDestinationsCombo.setEnabled(projectDestinationsRadio.isSelected());
152
serverDestinationsCombo.setEnabled(serverDestinationsRadio.isSelected());
155
private void populate() {
156
MessageDestinationUiSupport.populateDestinations(moduleDestinations, projectDestinationsCombo, null);
157
MessageDestinationUiSupport.populateDestinations(serverDestinations, serverDestinationsCombo, null);
160
private void fire() {
161
firePropertyChange(CHANGED, null, null);
164
/** This method is called from within the constructor to
165
* initialize the form.
166
* WARNING: Do NOT modify this code. The content of this method is
167
* always regenerated by the Form Editor.
169
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
170
private void initComponents() {
172
destinationsGroup = new javax.swing.ButtonGroup();
173
projectDestinationsRadio = new javax.swing.JRadioButton();
174
serverDestinationsRadio = new javax.swing.JRadioButton();
175
projectDestinationsCombo = new javax.swing.JComboBox();
176
addButton = new javax.swing.JButton();
177
serverDestinationsCombo = new javax.swing.JComboBox();
179
destinationsGroup.add(projectDestinationsRadio);
180
projectDestinationsRadio.setSelected(true);
181
org.openide.awt.Mnemonics.setLocalizedText(projectDestinationsRadio, org.openide.util.NbBundle.getMessage(MessageEJBWizardVisualPanel.class, "LBL_ProjectDestinations")); // NOI18N
182
projectDestinationsRadio.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
183
projectDestinationsRadio.setMargin(new java.awt.Insets(0, 0, 0, 0));
185
destinationsGroup.add(serverDestinationsRadio);
186
org.openide.awt.Mnemonics.setLocalizedText(serverDestinationsRadio, org.openide.util.NbBundle.getMessage(MessageEJBWizardVisualPanel.class, "LBL_ServerDestinations")); // NOI18N
187
serverDestinationsRadio.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
188
serverDestinationsRadio.setMargin(new java.awt.Insets(0, 0, 0, 0));
190
org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(MessageEJBWizardVisualPanel.class, "LBL_Add")); // NOI18N
191
addButton.addActionListener(new java.awt.event.ActionListener() {
192
public void actionPerformed(java.awt.event.ActionEvent evt) {
193
addButtonActionPerformed(evt);
197
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
198
this.setLayout(layout);
199
layout.setHorizontalGroup(
200
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
201
.add(layout.createSequentialGroup()
203
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
204
.add(projectDestinationsRadio)
205
.add(serverDestinationsRadio))
206
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
207
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
208
.add(serverDestinationsCombo, 0, 261, Short.MAX_VALUE)
209
.add(projectDestinationsCombo, 0, 261, Short.MAX_VALUE))
210
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
214
layout.setVerticalGroup(
215
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
216
.add(layout.createSequentialGroup()
218
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
219
.add(projectDestinationsRadio)
221
.add(projectDestinationsCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
222
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
223
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
224
.add(serverDestinationsRadio)
225
.add(serverDestinationsCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
226
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
228
}// </editor-fold>//GEN-END:initComponents
230
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
231
MessageDestination destination =
232
MessageDestinationUiSupport.createMessageDestination(provider, moduleDestinations, serverDestinations);
233
if (destination != null) {
234
moduleDestinations.add(destination);
235
MessageDestinationUiSupport.populateDestinations(moduleDestinations, projectDestinationsCombo, destination);
237
}//GEN-LAST:event_addButtonActionPerformed
240
// Variables declaration - do not modify//GEN-BEGIN:variables
241
private javax.swing.JButton addButton;
242
private javax.swing.ButtonGroup destinationsGroup;
243
private javax.swing.JComboBox projectDestinationsCombo;
244
private javax.swing.JRadioButton projectDestinationsRadio;
245
private javax.swing.JComboBox serverDestinationsCombo;
246
private javax.swing.JRadioButton serverDestinationsRadio;
247
// End of variables declaration//GEN-END:variables