1 6 7 package SOFA.SOFAnet.Browser; 8 9 import SOFA.SOFAnet.Repository.OutputTrigger; 10 import SOFA.SOFAnet.Repository.NodeNameFilter; 11 import SOFA.SOFAnet.Repository.BundleNameFilter; 12 import java.util.Date ; 13 import java.text.DateFormat ; 14 import java.text.ParseException ; 15 import javax.swing.*; 16 import java.awt.Component ; 17 import java.awt.Frame ; 18 19 23 public class OutputTriggerEditDialog extends javax.swing.JDialog 24 { 25 private OutputTrigger outputTrigger; 26 private BundleNameFilter bundleFilter; 27 private NodeNameFilter nodeFilter; 28 private boolean isOK; 29 30 public static boolean showDialog(Component frameComp, OutputTrigger outputTrigger, String title) 31 { 32 Frame frame = JOptionPane.getFrameForComponent(frameComp); 33 OutputTriggerEditDialog dialog = new OutputTriggerEditDialog(frame, true, outputTrigger, title); 34 dialog.setLocationRelativeTo(frameComp); 35 dialog.setVisible(true); 36 return dialog.isOK(); 37 } 38 39 40 public OutputTriggerEditDialog(java.awt.Frame parent, boolean modal, OutputTrigger outputTrigger, String title) 41 { 42 super(parent, modal); 43 this.outputTrigger = outputTrigger; 44 bundleFilter = outputTrigger.getBundleFilter(); 45 nodeFilter = outputTrigger.getNodeFilter(); 46 isOK = false; 47 48 initComponents(); 49 setTitle(title); 50 51 nameTextField.setText(outputTrigger.getName()); 52 descriptionTextField.setText(outputTrigger.getDescription()); 53 54 if (bundleFilter != null) 55 { 56 bundleFilterCheckBox.setSelected(true); 57 bundleFilterButton.setEnabled(true); 58 } 59 else 60 { 61 bundleFilterCheckBox.setSelected(false); 62 bundleFilterButton.setEnabled(false); 63 } 64 65 if (nodeFilter != null) 66 { 67 nodeFilterCheckBox.setSelected(true); 68 nodeFilterButton.setEnabled(true); 69 } 70 else 71 { 72 nodeFilterCheckBox.setSelected(false); 73 nodeFilterButton.setEnabled(false); 74 } 75 76 if (bundleFilter != null) bundleFilter = (BundleNameFilter)bundleFilter.clone(); 77 else bundleFilter = new BundleNameFilter(); 78 if (nodeFilter != null) nodeFilter = (NodeNameFilter)nodeFilter.clone(); 79 else nodeFilter = new NodeNameFilter(); 80 81 Date validFrom = outputTrigger.getValidFrom(); 82 Date validTo = outputTrigger.getValidTo(); 83 DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); 84 85 if (validFrom != null) validFromTextField.setText(dateFormat.format(validFrom)); 86 else validFromTextField.setText(""); 87 88 if (validTo != null) validToTextField.setText(dateFormat.format(validTo)); 89 else validToTextField.setText(""); 90 91 autodeleteCheckBox.setSelected(outputTrigger.getAutoDelete()); 92 93 if (outputTrigger.isContract()) 94 { 95 contractIDTextField.setText(outputTrigger.getContractID()); 96 contractRuleTextField.setText(outputTrigger.getContractRule()); 97 } 98 } 99 100 public boolean isOK() 101 { 102 return isOK; 103 } 104 105 110 private void initComponents() { 112 nameAndDescriptionPanel = new javax.swing.JPanel (); 113 nameLabel = new javax.swing.JLabel (); 114 nameTextField = new javax.swing.JTextField (); 115 descriptionLabel = new javax.swing.JLabel (); 116 descriptionTextField = new javax.swing.JTextField (); 117 jPanel7 = new javax.swing.JPanel (); 118 jPanel3 = new javax.swing.JPanel (); 119 parametersPanel = new javax.swing.JPanel (); 120 bundleFilterPanel = new javax.swing.JPanel (); 121 bundleFilterCheckBox = new javax.swing.JCheckBox (); 122 bundleFilterButton = new javax.swing.JButton (); 123 nodeFilterPanel = new javax.swing.JPanel (); 124 nodeFilterCheckBox = new javax.swing.JCheckBox (); 125 nodeFilterButton = new javax.swing.JButton (); 126 validFromPanel = new javax.swing.JPanel (); 127 validFromLabel = new javax.swing.JLabel (); 128 validFromTextField = new javax.swing.JTextField (); 129 validToPanel = new javax.swing.JPanel (); 130 validToLabel = new javax.swing.JLabel (); 131 validToTextField = new javax.swing.JTextField (); 132 autodeleteCheckBox = new javax.swing.JCheckBox (); 133 contractPanel = new javax.swing.JPanel (); 134 jPanel5 = new javax.swing.JPanel (); 135 contractIDLabel = new javax.swing.JLabel (); 136 contractIDTextField = new javax.swing.JTextField (); 137 contractRuleLabel = new javax.swing.JLabel (); 138 contractRuleTextField = new javax.swing.JTextField (); 139 jPanel6 = new javax.swing.JPanel (); 140 OKButton = new javax.swing.JButton (); 141 cancelButton = new javax.swing.JButton (); 142 143 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 144 nameAndDescriptionPanel.setLayout(new java.awt.GridLayout (4, 0)); 145 146 nameAndDescriptionPanel.setBorder(new javax.swing.border.TitledBorder ("Name and Description of Output Trigger")); 147 nameLabel.setText("Name:"); 148 nameAndDescriptionPanel.add(nameLabel); 149 150 nameTextField.setEditable(false); 151 nameAndDescriptionPanel.add(nameTextField); 152 153 descriptionLabel.setText("Description:"); 154 nameAndDescriptionPanel.add(descriptionLabel); 155 156 nameAndDescriptionPanel.add(descriptionTextField); 157 158 getContentPane().add(nameAndDescriptionPanel, java.awt.BorderLayout.NORTH); 159 160 jPanel7.setLayout(new java.awt.BorderLayout ()); 161 162 jPanel3.setLayout(new java.awt.GridLayout (1, 0)); 163 164 parametersPanel.setLayout(new java.awt.GridLayout (5, 0)); 165 166 parametersPanel.setBorder(new javax.swing.border.TitledBorder ("Parameters")); 167 bundleFilterPanel.setLayout(new javax.swing.BoxLayout (bundleFilterPanel, javax.swing.BoxLayout.X_AXIS)); 168 169 bundleFilterCheckBox.setText("Bundle Filter"); 170 bundleFilterCheckBox.addActionListener(new java.awt.event.ActionListener () 171 { 172 public void actionPerformed(java.awt.event.ActionEvent evt) 173 { 174 bundleFilterCheckBoxActionPerformed(evt); 175 } 176 }); 177 178 bundleFilterPanel.add(bundleFilterCheckBox); 179 180 bundleFilterButton.setText("Edit Bundle Filter"); 181 bundleFilterButton.addActionListener(new java.awt.event.ActionListener () 182 { 183 public void actionPerformed(java.awt.event.ActionEvent evt) 184 { 185 bundleFilterButtonActionPerformed(evt); 186 } 187 }); 188 189 bundleFilterPanel.add(bundleFilterButton); 190 191 parametersPanel.add(bundleFilterPanel); 192 193 nodeFilterPanel.setLayout(new javax.swing.BoxLayout (nodeFilterPanel, javax.swing.BoxLayout.X_AXIS)); 194 195 nodeFilterCheckBox.setText("Node Filter"); 196 nodeFilterCheckBox.addActionListener(new java.awt.event.ActionListener () 197 { 198 public void actionPerformed(java.awt.event.ActionEvent evt) 199 { 200 nodeFilterCheckBoxActionPerformed(evt); 201 } 202 }); 203 204 nodeFilterPanel.add(nodeFilterCheckBox); 205 206 nodeFilterButton.setText("Edit Node Filter"); 207 nodeFilterButton.addActionListener(new java.awt.event.ActionListener () 208 { 209 public void actionPerformed(java.awt.event.ActionEvent evt) 210 { 211 nodeFilterButtonActionPerformed(evt); 212 } 213 }); 214 215 nodeFilterPanel.add(nodeFilterButton); 216 217 parametersPanel.add(nodeFilterPanel); 218 219 validFromPanel.setLayout(new javax.swing.BoxLayout (validFromPanel, javax.swing.BoxLayout.X_AXIS)); 220 221 validFromLabel.setText("Valid From:"); 222 validFromPanel.add(validFromLabel); 223 224 validFromPanel.add(validFromTextField); 225 226 parametersPanel.add(validFromPanel); 227 228 validToPanel.setLayout(new javax.swing.BoxLayout (validToPanel, javax.swing.BoxLayout.X_AXIS)); 229 230 validToLabel.setText("Valid To:"); 231 validToPanel.add(validToLabel); 232 233 validToPanel.add(validToTextField); 234 235 parametersPanel.add(validToPanel); 236 237 autodeleteCheckBox.setText("Automatically Delete When Expired"); 238 parametersPanel.add(autodeleteCheckBox); 239 240 jPanel3.add(parametersPanel); 241 242 contractPanel.setLayout(new java.awt.BorderLayout ()); 243 244 contractPanel.setBorder(new javax.swing.border.TitledBorder ("Contract Connection")); 245 contractPanel.setMinimumSize(new java.awt.Dimension (200, 111)); 246 contractPanel.setPreferredSize(new java.awt.Dimension (200, 111)); 247 jPanel5.setLayout(new java.awt.GridLayout (4, 0)); 248 249 contractIDLabel.setText("Contract ID:"); 250 jPanel5.add(contractIDLabel); 251 252 jPanel5.add(contractIDTextField); 253 254 contractRuleLabel.setText("Contract Rule:"); 255 jPanel5.add(contractRuleLabel); 256 257 jPanel5.add(contractRuleTextField); 258 259 contractPanel.add(jPanel5, java.awt.BorderLayout.NORTH); 260 261 jPanel3.add(contractPanel); 262 263 jPanel7.add(jPanel3, java.awt.BorderLayout.NORTH); 264 265 getContentPane().add(jPanel7, java.awt.BorderLayout.CENTER); 266 267 OKButton.setText("OK"); 268 OKButton.addActionListener(new java.awt.event.ActionListener () 269 { 270 public void actionPerformed(java.awt.event.ActionEvent evt) 271 { 272 OKButtonActionPerformed(evt); 273 } 274 }); 275 276 jPanel6.add(OKButton); 277 278 cancelButton.setText("Cancel"); 279 cancelButton.addActionListener(new java.awt.event.ActionListener () 280 { 281 public void actionPerformed(java.awt.event.ActionEvent evt) 282 { 283 cancelButtonActionPerformed(evt); 284 } 285 }); 286 287 jPanel6.add(cancelButton); 288 289 getContentPane().add(jPanel6, java.awt.BorderLayout.SOUTH); 290 291 pack(); 292 } 294 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 297 } 299 private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) { Date validFrom = null; 302 Date validTo = null; 303 try 304 { 305 DateFormat dateFormat = DateFormat.getInstance(); 306 String validFromText = validFromTextField.getText().trim().toLowerCase(); 307 if (validFromText.length() != 0 && validFromText.compareTo("no limitation") != 0) validFrom = dateFormat.parse(validFromText); 308 309 String validToText = validToTextField.getText().trim().toLowerCase(); 310 if (validToText.length() != 0 && validToText.compareTo("no limitation") != 0) validTo = dateFormat.parse(validToText); 311 } 312 catch (ParseException e) 313 { 314 JOptionPane.showMessageDialog(this, "Error occured while parsing 'Valid From' or 'Valid To':\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 315 return; 316 } 317 318 String contractID = contractIDTextField.getText().trim(); 319 String contractRule = contractRuleTextField.getText().trim(); 320 if (contractID.length() != 0 && contractRule.length() == 0) 321 { 322 JOptionPane.showMessageDialog(this, "Missing Contract Rule", "Error", JOptionPane.ERROR_MESSAGE); 323 return; 324 } 325 326 outputTrigger.setDescription(descriptionTextField.getText()); 327 328 329 if (!bundleFilterCheckBox.isSelected()) bundleFilter = null; 330 if (!nodeFilterCheckBox.isSelected()) nodeFilter = null; 331 outputTrigger.setBundleFilter(bundleFilter); 332 outputTrigger.setNodeFilter(nodeFilter); 333 outputTrigger.setValidFrom(validFrom); 334 outputTrigger.setValidTo(validTo); 335 outputTrigger.setAutoDelete(autodeleteCheckBox.isSelected()); 336 if (contractID.length() != 0) outputTrigger.setContract(contractID, contractRule); 337 else outputTrigger.setContract(null, null); 338 339 isOK = true; 340 dispose(); 341 } 343 private void nodeFilterButtonActionPerformed(java.awt.event.ActionEvent evt) { StringListEditDialog.showDialog(this, nodeFilter.getPatterns(), "Node Name Pattern", "Node Filter Editor"); 346 } 348 private void nodeFilterCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { nodeFilterButton.setEnabled(nodeFilterCheckBox.isSelected()); 351 } 353 private void bundleFilterButtonActionPerformed(java.awt.event.ActionEvent evt) { StringListEditDialog.showDialog(this, bundleFilter.getPatterns(), "Bundle Name Pattern", "Bundle Filter Editor"); 356 } 358 private void bundleFilterCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { bundleFilterButton.setEnabled(bundleFilterCheckBox.isSelected()); 361 } 363 private javax.swing.JButton OKButton; 365 private javax.swing.JCheckBox autodeleteCheckBox; 366 private javax.swing.JButton bundleFilterButton; 367 private javax.swing.JCheckBox bundleFilterCheckBox; 368 private javax.swing.JPanel bundleFilterPanel; 369 private javax.swing.JButton cancelButton; 370 private javax.swing.JLabel contractIDLabel; 371 private javax.swing.JTextField contractIDTextField; 372 private javax.swing.JPanel contractPanel; 373 private javax.swing.JLabel contractRuleLabel; 374 private javax.swing.JTextField contractRuleTextField; 375 private javax.swing.JLabel descriptionLabel; 376 private javax.swing.JTextField descriptionTextField; 377 private javax.swing.JPanel jPanel3; 378 private javax.swing.JPanel jPanel5; 379 private javax.swing.JPanel jPanel6; 380 private javax.swing.JPanel jPanel7; 381 private javax.swing.JPanel nameAndDescriptionPanel; 382 private javax.swing.JLabel nameLabel; 383 private javax.swing.JTextField nameTextField; 384 private javax.swing.JButton nodeFilterButton; 385 private javax.swing.JCheckBox nodeFilterCheckBox; 386 private javax.swing.JPanel nodeFilterPanel; 387 private javax.swing.JPanel parametersPanel; 388 private javax.swing.JLabel validFromLabel; 389 private javax.swing.JPanel validFromPanel; 390 private javax.swing.JTextField validFromTextField; 391 private javax.swing.JLabel validToLabel; 392 private javax.swing.JPanel validToPanel; 393 private javax.swing.JTextField validToTextField; 394 396 } 397 | Popular Tags |