1 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 39 public class MessageDrivenOverviewPanel extends MessageDrivenOverviewForm { 40 41 private ActivationConfig config; 42 private static final String PROPERTY_MESSAGE_SELECTOR = "messageSelector"; private static final String PROPERTY_ACKNOWLEDGE_NAME = "acknowledgeMode"; private static final String PROPERTY_SUBSCRIPTION_DURABILITY = "subscriptionDurability"; private static final String DESTINATION_TYPE_TOPIC = MessageDrivenDestination.DESTINATION_TYPE_TOPIC; 46 private static final String DESTINATION_TYPE_QUEUE = MessageDrivenDestination.DESTINATION_TYPE_QUEUE; 47 private static final String SUBSCRIPTION_DURABILITY_NONDURABLE = MessageDrivenDestination.SUBSCRIPTION_DURABILITY_NONDURABLE; 48 private static final String SUBSCRIPTION_DURABILITY_DURABLE = MessageDrivenDestination.SUBSCRIPTION_DURABILITY_DURABLE; 49 private static final String DESTINATION_TYPE = MessageDrivenDestination.DESTINATION_TYPE; 50 51 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 getValue() { 64 return messageDriven.getEjbName(); 65 } 66 67 protected void setValue(String value) { 68 messageDriven.setEjbName(value); 69 } 70 })); 71 getNameTextField().setEditable(false); 72 73 addRefreshable(new ItemOptionHelper(synchronizer, getTransactionTypeButtonGroup()) { 74 public String getItemValue() { 75 return messageDriven.getTransactionType(); 76 } 77 78 public void setItemValue(String 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 getValue() { 102 return getConfigProperty(PROPERTY_MESSAGE_SELECTOR); 103 } 104 105 protected void setValue(String value) { 106 setConfigProperty(PROPERTY_MESSAGE_SELECTOR, value); 107 } 108 })); 109 110 addRefreshable(new ItemOptionHelper(synchronizer, getAcknowledgeModeButtonGroup()) { 111 public String getItemValue() { 112 return getConfigProperty(PROPERTY_ACKNOWLEDGE_NAME, "Auto-acknowledge"); } 114 115 public void setItemValue(String 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 getItemValue() { 128 return getConfigProperty(MessageDrivenDestination.DESTINATION_TYPE); 129 } 130 131 public void setItemValue(String 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 new ItemComboBoxHelper(synchronizer, destinationTypeComboBox) { 145 146 public String getItemValue() { 147 try { 148 return messageDriven.getMessageDestinationType(); 149 } catch (VersionNotSupportedException e) { 150 return null; 151 } 152 } 153 154 public void setItemValue(String value) { 155 try { 156 messageDriven.setMessageDestinationType(value); 157 } catch (VersionNotSupportedException e) { 158 } 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 getConfigProperty(String propertyName) { 178 return getConfigProperty(propertyName, null); 179 } 180 181 private String getConfigProperty(String propertyName, String defaultValue) { 182 ActivationConfigProperty[] properties = config.getActivationConfigProperty(); 183 String 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 propertyName, String 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 source, String propertyName, Object oldValue, Object 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 getItemValue() { 227 return getConfigProperty(PROPERTY_SUBSCRIPTION_DURABILITY, "NonDurable"); } 229 230 public void setItemValue(String 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 |