KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > MessageDrivenOverviewPanel


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.ddloaders.multiview;
21
22 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
23 import org.netbeans.modules.j2ee.dd.api.ejb.ActivationConfig;
24 import org.netbeans.modules.j2ee.dd.api.ejb.ActivationConfigProperty;
25 import org.netbeans.modules.j2ee.dd.api.ejb.MessageDriven;
26 import org.netbeans.modules.j2ee.dd.api.ejb.MessageDrivenDestination;
27 import org.netbeans.modules.j2ee.ddloaders.multiview.ui.MessageDrivenOverviewForm;
28 import org.netbeans.modules.xml.multiview.ItemComboBoxHelper;
29 import org.netbeans.modules.xml.multiview.ItemEditorHelper;
30 import org.netbeans.modules.xml.multiview.ItemOptionHelper;
31 import org.netbeans.modules.xml.multiview.XmlMultiViewDataSynchronizer;
32 import org.netbeans.modules.xml.multiview.ui.SectionNodeView;
33
34 import javax.swing.*;
35
36 /**
37  * @author pfiala
38  */

39 public class MessageDrivenOverviewPanel extends MessageDrivenOverviewForm {
40
41     private ActivationConfig config;
42     private static final String JavaDoc PROPERTY_MESSAGE_SELECTOR = "messageSelector"; //NOI18N
43
private static final String JavaDoc PROPERTY_ACKNOWLEDGE_NAME = "acknowledgeMode"; //NOI18N
44
private static final String JavaDoc PROPERTY_SUBSCRIPTION_DURABILITY = "subscriptionDurability"; //NOI18N
45
private static final String JavaDoc DESTINATION_TYPE_TOPIC = MessageDrivenDestination.DESTINATION_TYPE_TOPIC;
46     private static final String JavaDoc DESTINATION_TYPE_QUEUE = MessageDrivenDestination.DESTINATION_TYPE_QUEUE;
47     private static final String JavaDoc SUBSCRIPTION_DURABILITY_NONDURABLE = MessageDrivenDestination.SUBSCRIPTION_DURABILITY_NONDURABLE;
48     private static final String JavaDoc SUBSCRIPTION_DURABILITY_DURABLE = MessageDrivenDestination.SUBSCRIPTION_DURABILITY_DURABLE;
49     private static final String JavaDoc DESTINATION_TYPE = MessageDrivenDestination.DESTINATION_TYPE;
50
51     /**
52      * @param sectionNodeView enclosing SectionNodeView object
53      */

54     public MessageDrivenOverviewPanel(SectionNodeView sectionNodeView, final MessageDriven messageDriven) {
55         super(sectionNodeView);
56
57         final EjbJarMultiViewDataObject dataObject = (EjbJarMultiViewDataObject) sectionNodeView.getDataObject();
58
59         XmlMultiViewDataSynchronizer synchronizer = dataObject.getModelSynchronizer();
60         addRefreshable(new ItemEditorHelper(getNameTextField(), new TextItemEditorModel(synchronizer,
61                 false) {
62
63             protected String JavaDoc getValue() {
64                 return messageDriven.getEjbName();
65             }
66
67             protected void setValue(String JavaDoc value) {
68                 messageDriven.setEjbName(value);
69             }
70         }));
71         getNameTextField().setEditable(false);
72
73         addRefreshable(new ItemOptionHelper(synchronizer, getTransactionTypeButtonGroup()) {
74             public String JavaDoc getItemValue() {
75                 return messageDriven.getTransactionType();
76             }
77
78             public void setItemValue(String JavaDoc value) {
79                 messageDriven.setTransactionType(value);
80             }
81         });
82
83         config = getActivationConfig(messageDriven);
84
85         final JTextField messageSelectorTextField = getMessageSelectorTextField();
86
87         final JComboBox destinationTypeComboBox = getDestinationTypeComboBox();
88         destinationTypeComboBox.addItem(DESTINATION_TYPE_TOPIC);
89         destinationTypeComboBox.addItem(DESTINATION_TYPE_QUEUE);
90
91         final JComboBox durabilityComboBox = getDurabilityComboBox();
92         durabilityComboBox.addItem(SUBSCRIPTION_DURABILITY_NONDURABLE);
93         durabilityComboBox.addItem(SUBSCRIPTION_DURABILITY_DURABLE);
94
95         if (config == null) {
96             durabilityComboBox.setEnabled(false);
97             messageSelectorTextField.setEnabled(false);
98         } else {
99             addRefreshable(new ItemEditorHelper(messageSelectorTextField,
100                             new TextItemEditorModel(synchronizer, true, true) {
101                 protected String JavaDoc getValue() {
102                     return getConfigProperty(PROPERTY_MESSAGE_SELECTOR);
103                 }
104
105                 protected void setValue(String JavaDoc value) {
106                     setConfigProperty(PROPERTY_MESSAGE_SELECTOR, value);
107                 }
108             }));
109
110             addRefreshable(new ItemOptionHelper(synchronizer, getAcknowledgeModeButtonGroup()) {
111                 public String JavaDoc getItemValue() {
112                     return getConfigProperty(PROPERTY_ACKNOWLEDGE_NAME, "Auto-acknowledge");//NOI18N
113
}
114
115                 public void setItemValue(String JavaDoc value) {
116                     setConfigProperty(PROPERTY_ACKNOWLEDGE_NAME, value);
117                 }
118             });
119
120             final DurabilityComboBoxHelper durabilityComboBoxHelper = new DurabilityComboBoxHelper(synchronizer, durabilityComboBox);
121
122             new ItemComboBoxHelper(synchronizer, destinationTypeComboBox) {
123                 {
124                     setDurabilityEnabled();
125                 }
126
127                 public String JavaDoc getItemValue() {
128                     return getConfigProperty(MessageDrivenDestination.DESTINATION_TYPE);
129                 }
130
131                 public void setItemValue(String JavaDoc value) {
132                     setConfigProperty(DESTINATION_TYPE, value);
133                     setDurabilityEnabled();
134                 }
135
136                 private void setDurabilityEnabled() {
137                     durabilityComboBoxHelper.setComboBoxEnabled(DESTINATION_TYPE_TOPIC.equals(getItemValue()));
138                 }
139             };
140
141         }
142
143         // the second ItemComboboxHelper for destinationTypeComboBox handles message-destination-type element
144
new ItemComboBoxHelper(synchronizer, destinationTypeComboBox) {
145
146             public String JavaDoc getItemValue() {
147                 try {
148                     return messageDriven.getMessageDestinationType();
149                 } catch (VersionNotSupportedException e) {
150                     return null;
151                 }
152             }
153
154             public void setItemValue(String JavaDoc value) {
155                 try {
156                     messageDriven.setMessageDestinationType(value);
157                 } catch (VersionNotSupportedException e) {
158                     // ignore
159
}
160             }
161
162         };
163
164     }
165
166     private ActivationConfig getActivationConfig(final MessageDriven messageDriven) {
167         ActivationConfig ac;
168
169         try {
170             ac = messageDriven.getActivationConfig();
171         } catch (VersionNotSupportedException e1) {
172             ac = null;
173         }
174         return ac;
175     }
176
177     private String JavaDoc getConfigProperty(String JavaDoc propertyName) {
178         return getConfigProperty(propertyName, null);
179     }
180
181     private String JavaDoc getConfigProperty(String JavaDoc propertyName, String JavaDoc defaultValue) {
182         ActivationConfigProperty[] properties = config.getActivationConfigProperty();
183         String JavaDoc value = null;
184         for (int i = 0; i < properties.length; i++) {
185             ActivationConfigProperty property = properties[i];
186             if (propertyName.equalsIgnoreCase(property.getActivationConfigPropertyName())) {
187                 value = property.getActivationConfigPropertyValue();
188                 break;
189             }
190         }
191         return value == null ? defaultValue : value;
192     }
193
194     private void setConfigProperty(String JavaDoc propertyName, String JavaDoc propertyValue) {
195         ActivationConfigProperty[] properties = config.getActivationConfigProperty();
196         for (int i = 0; i < properties.length; i++) {
197             ActivationConfigProperty property = properties[i];
198             if (propertyName.equalsIgnoreCase(property.getActivationConfigPropertyName())) {
199                 if (propertyValue != null) {
200                     property.setActivationConfigPropertyValue(propertyValue);
201                 } else {
202                     config.removeActivationConfigProperty(property);
203                 }
204                 signalUIChange();
205                 return;
206             }
207         }
208         if (propertyValue != null) {
209             ActivationConfigProperty property = config.newActivationConfigProperty();
210             property.setActivationConfigPropertyName(propertyName);
211             property.setActivationConfigPropertyValue(propertyValue);
212             config.addActivationConfigProperty(property);
213         }
214     }
215
216     public void dataModelPropertyChange(Object JavaDoc source, String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
217         scheduleRefreshView();
218     }
219
220     private class DurabilityComboBoxHelper extends ItemComboBoxHelper {
221
222         public DurabilityComboBoxHelper(XmlMultiViewDataSynchronizer synchronizer, JComboBox durabilityComboBox) {
223             super(synchronizer, durabilityComboBox);
224         }
225
226         public String JavaDoc getItemValue() {
227             return getConfigProperty(PROPERTY_SUBSCRIPTION_DURABILITY, "NonDurable");//NOI18N
228
}
229
230         public void setItemValue(String JavaDoc value) {
231             setConfigProperty(PROPERTY_SUBSCRIPTION_DURABILITY, value);
232         }
233
234         public void setComboBoxEnabled(boolean enabled) {
235             getComboBox().setEnabled(enabled);
236             setValue(enabled ? getItemValue() : null);
237         }
238     }
239 }
240
Popular Tags