KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Browser > OutputTriggerEditDialog


1 /*
2  * OutputTriggerEditDialog.java
3  *
4  * Created on 17. květen 2004, 22:47
5  */

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 JavaDoc;
13 import java.text.DateFormat JavaDoc;
14 import java.text.ParseException JavaDoc;
15 import javax.swing.*;
16 import java.awt.Component JavaDoc;
17 import java.awt.Frame JavaDoc;
18
19 /**
20  *
21  * @author Ladislav Sobr
22  */

23 public class OutputTriggerEditDialog extends javax.swing.JDialog JavaDoc
24 {
25   private OutputTrigger outputTrigger;
26   private BundleNameFilter bundleFilter;
27   private NodeNameFilter nodeFilter;
28   private boolean isOK;
29   
30   public static boolean showDialog(Component JavaDoc frameComp, OutputTrigger outputTrigger, String JavaDoc title)
31   {
32     Frame JavaDoc 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   /** Creates new form OutputTriggerEditDialog */
40   public OutputTriggerEditDialog(java.awt.Frame JavaDoc parent, boolean modal, OutputTrigger outputTrigger, String JavaDoc 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 JavaDoc validFrom = outputTrigger.getValidFrom();
82     Date JavaDoc validTo = outputTrigger.getValidTo();
83     DateFormat JavaDoc 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   /** This method is called from within the constructor to
106    * initialize the form.
107    * WARNING: Do NOT modify this code. The content of this method is
108    * always regenerated by the Form Editor.
109    */

110   private void initComponents()//GEN-BEGIN:initComponents
111
{
112     nameAndDescriptionPanel = new javax.swing.JPanel JavaDoc();
113     nameLabel = new javax.swing.JLabel JavaDoc();
114     nameTextField = new javax.swing.JTextField JavaDoc();
115     descriptionLabel = new javax.swing.JLabel JavaDoc();
116     descriptionTextField = new javax.swing.JTextField JavaDoc();
117     jPanel7 = new javax.swing.JPanel JavaDoc();
118     jPanel3 = new javax.swing.JPanel JavaDoc();
119     parametersPanel = new javax.swing.JPanel JavaDoc();
120     bundleFilterPanel = new javax.swing.JPanel JavaDoc();
121     bundleFilterCheckBox = new javax.swing.JCheckBox JavaDoc();
122     bundleFilterButton = new javax.swing.JButton JavaDoc();
123     nodeFilterPanel = new javax.swing.JPanel JavaDoc();
124     nodeFilterCheckBox = new javax.swing.JCheckBox JavaDoc();
125     nodeFilterButton = new javax.swing.JButton JavaDoc();
126     validFromPanel = new javax.swing.JPanel JavaDoc();
127     validFromLabel = new javax.swing.JLabel JavaDoc();
128     validFromTextField = new javax.swing.JTextField JavaDoc();
129     validToPanel = new javax.swing.JPanel JavaDoc();
130     validToLabel = new javax.swing.JLabel JavaDoc();
131     validToTextField = new javax.swing.JTextField JavaDoc();
132     autodeleteCheckBox = new javax.swing.JCheckBox JavaDoc();
133     contractPanel = new javax.swing.JPanel JavaDoc();
134     jPanel5 = new javax.swing.JPanel JavaDoc();
135     contractIDLabel = new javax.swing.JLabel JavaDoc();
136     contractIDTextField = new javax.swing.JTextField JavaDoc();
137     contractRuleLabel = new javax.swing.JLabel JavaDoc();
138     contractRuleTextField = new javax.swing.JTextField JavaDoc();
139     jPanel6 = new javax.swing.JPanel JavaDoc();
140     OKButton = new javax.swing.JButton JavaDoc();
141     cancelButton = new javax.swing.JButton JavaDoc();
142
143     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
144     nameAndDescriptionPanel.setLayout(new java.awt.GridLayout JavaDoc(4, 0));
145
146     nameAndDescriptionPanel.setBorder(new javax.swing.border.TitledBorder JavaDoc("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 JavaDoc());
161
162     jPanel3.setLayout(new java.awt.GridLayout JavaDoc(1, 0));
163
164     parametersPanel.setLayout(new java.awt.GridLayout JavaDoc(5, 0));
165
166     parametersPanel.setBorder(new javax.swing.border.TitledBorder JavaDoc("Parameters"));
167     bundleFilterPanel.setLayout(new javax.swing.BoxLayout JavaDoc(bundleFilterPanel, javax.swing.BoxLayout.X_AXIS));
168
169     bundleFilterCheckBox.setText("Bundle Filter");
170     bundleFilterCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
171     {
172       public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc()
182     {
183       public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc(nodeFilterPanel, javax.swing.BoxLayout.X_AXIS));
194
195     nodeFilterCheckBox.setText("Node Filter");
196     nodeFilterCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
197     {
198       public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc()
208     {
209       public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc(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 JavaDoc(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 JavaDoc());
243
244     contractPanel.setBorder(new javax.swing.border.TitledBorder JavaDoc("Contract Connection"));
245     contractPanel.setMinimumSize(new java.awt.Dimension JavaDoc(200, 111));
246     contractPanel.setPreferredSize(new java.awt.Dimension JavaDoc(200, 111));
247     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(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 JavaDoc()
269     {
270       public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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 JavaDoc()
280     {
281       public void actionPerformed(java.awt.event.ActionEvent JavaDoc 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   }//GEN-END:initComponents
293

294   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
295
{//GEN-HEADEREND:event_cancelButtonActionPerformed
296
dispose();
297   }//GEN-LAST:event_cancelButtonActionPerformed
298

299   private void OKButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_OKButtonActionPerformed
300
{//GEN-HEADEREND:event_OKButtonActionPerformed
301
Date JavaDoc validFrom = null;
302     Date JavaDoc validTo = null;
303     try
304     {
305       DateFormat JavaDoc dateFormat = DateFormat.getInstance();
306       String JavaDoc validFromText = validFromTextField.getText().trim().toLowerCase();
307       if (validFromText.length() != 0 && validFromText.compareTo("no limitation") != 0) validFrom = dateFormat.parse(validFromText);
308
309       String JavaDoc validToText = validToTextField.getText().trim().toLowerCase();
310       if (validToText.length() != 0 && validToText.compareTo("no limitation") != 0) validTo = dateFormat.parse(validToText);
311     }
312     catch (ParseException JavaDoc 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 JavaDoc contractID = contractIDTextField.getText().trim();
319     String JavaDoc 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   }//GEN-LAST:event_OKButtonActionPerformed
342

343   private void nodeFilterButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_nodeFilterButtonActionPerformed
344
{//GEN-HEADEREND:event_nodeFilterButtonActionPerformed
345
StringListEditDialog.showDialog(this, nodeFilter.getPatterns(), "Node Name Pattern", "Node Filter Editor");
346   }//GEN-LAST:event_nodeFilterButtonActionPerformed
347

348   private void nodeFilterCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_nodeFilterCheckBoxActionPerformed
349
{//GEN-HEADEREND:event_nodeFilterCheckBoxActionPerformed
350
nodeFilterButton.setEnabled(nodeFilterCheckBox.isSelected());
351   }//GEN-LAST:event_nodeFilterCheckBoxActionPerformed
352

353   private void bundleFilterButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_bundleFilterButtonActionPerformed
354
{//GEN-HEADEREND:event_bundleFilterButtonActionPerformed
355
StringListEditDialog.showDialog(this, bundleFilter.getPatterns(), "Bundle Name Pattern", "Bundle Filter Editor");
356   }//GEN-LAST:event_bundleFilterButtonActionPerformed
357

358   private void bundleFilterCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_bundleFilterCheckBoxActionPerformed
359
{//GEN-HEADEREND:event_bundleFilterCheckBoxActionPerformed
360
bundleFilterButton.setEnabled(bundleFilterCheckBox.isSelected());
361   }//GEN-LAST:event_bundleFilterCheckBoxActionPerformed
362

363   // Variables declaration - do not modify//GEN-BEGIN:variables
364
private javax.swing.JButton JavaDoc OKButton;
365   private javax.swing.JCheckBox JavaDoc autodeleteCheckBox;
366   private javax.swing.JButton JavaDoc bundleFilterButton;
367   private javax.swing.JCheckBox JavaDoc bundleFilterCheckBox;
368   private javax.swing.JPanel JavaDoc bundleFilterPanel;
369   private javax.swing.JButton JavaDoc cancelButton;
370   private javax.swing.JLabel JavaDoc contractIDLabel;
371   private javax.swing.JTextField JavaDoc contractIDTextField;
372   private javax.swing.JPanel JavaDoc contractPanel;
373   private javax.swing.JLabel JavaDoc contractRuleLabel;
374   private javax.swing.JTextField JavaDoc contractRuleTextField;
375   private javax.swing.JLabel JavaDoc descriptionLabel;
376   private javax.swing.JTextField JavaDoc descriptionTextField;
377   private javax.swing.JPanel JavaDoc jPanel3;
378   private javax.swing.JPanel JavaDoc jPanel5;
379   private javax.swing.JPanel JavaDoc jPanel6;
380   private javax.swing.JPanel JavaDoc jPanel7;
381   private javax.swing.JPanel JavaDoc nameAndDescriptionPanel;
382   private javax.swing.JLabel JavaDoc nameLabel;
383   private javax.swing.JTextField JavaDoc nameTextField;
384   private javax.swing.JButton JavaDoc nodeFilterButton;
385   private javax.swing.JCheckBox JavaDoc nodeFilterCheckBox;
386   private javax.swing.JPanel JavaDoc nodeFilterPanel;
387   private javax.swing.JPanel JavaDoc parametersPanel;
388   private javax.swing.JLabel JavaDoc validFromLabel;
389   private javax.swing.JPanel JavaDoc validFromPanel;
390   private javax.swing.JTextField JavaDoc validFromTextField;
391   private javax.swing.JLabel JavaDoc validToLabel;
392   private javax.swing.JPanel JavaDoc validToPanel;
393   private javax.swing.JTextField JavaDoc validToTextField;
394   // End of variables declaration//GEN-END:variables
395

396 }
397
Popular Tags