KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * InputTriggerShareActionPropertiesEditDialog.java
3  *
4  * Created on 17. květen 2004, 23:32
5  */

6
7 package SOFA.SOFAnet.Browser;
8
9 import SOFA.SOFAnet.Repository.InputTrigger;
10 import SOFA.SOFAnet.Repository.Licence;
11 import SOFA.SOFAnet.Repository.NodeNameFilter;
12 import SOFA.SOFAnet.Repository.ShareGroups;
13 import javax.swing.*;
14 import java.util.*;
15 import java.awt.Component JavaDoc;
16 import java.awt.Frame JavaDoc;
17
18 /**
19  *
20  * @author Ladislav Sobr
21  */

22 public class InputTriggerShareActionPropertiesEditDialog extends javax.swing.JDialog JavaDoc
23 {
24   private ActionShareParameters asParameters;
25   private NodeNameFilter asNodeFilter;
26   private ShareGroups asShareGroups;
27   private boolean isOK;
28   
29   public static class ActionShareParameters
30   {
31     private int asNoLicences;
32     private ShareGroups asShareGroups;
33     private NodeNameFilter asNodeFilter;
34     private boolean asEquality;
35     
36     public ActionShareParameters(InputTrigger inputTrigger)
37     {
38       asNoLicences = inputTrigger.getAsNoLicences();
39       asShareGroups = inputTrigger.getAsShareGroups();
40       asNodeFilter = inputTrigger.getAsNodeFilter();
41       asEquality = inputTrigger.getAsEquality();
42     }
43     
44     public void save(InputTrigger inputTrigger)
45     {
46       inputTrigger.setAsNoLicences(asNoLicences);
47       inputTrigger.setAsShareGroups(asShareGroups);
48       inputTrigger.setAsNodeFilter(asNodeFilter);
49       inputTrigger.setAsEquality(asEquality);
50     }
51     
52     public int getAsNoLicences()
53     {
54       return asNoLicences;
55     }
56
57     public ShareGroups getAsShareGroups()
58     {
59       return asShareGroups;
60     }
61
62     public NodeNameFilter getAsNodeFilter()
63     {
64       return asNodeFilter;
65     }
66
67     public boolean getAsEquality()
68     {
69       return asEquality;
70     }
71     
72     public void setAsNoLicences(int asNoLicences)
73     {
74       if (asNoLicences <= 0 && asNoLicences != Licence.ALL_LICENCES) asNoLicences = Licence.ONE_IMPLICIT_LICENCE;
75       this.asNoLicences = asNoLicences;
76     }
77
78     public void setAsShareGroups(ShareGroups asShareGroups)
79     {
80       this.asShareGroups = asShareGroups;
81     }
82
83     public void setAsNodeFilter(NodeNameFilter asNodeFilter)
84     {
85       this.asNodeFilter = asNodeFilter;
86     }
87
88     public void setAsEquality(boolean asEquality)
89     {
90       this.asEquality = asEquality;
91     }
92     
93   }
94   
95   public static boolean showDialog(Component JavaDoc frameComp, ActionShareParameters asParameters)
96   {
97     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
98     InputTriggerShareActionPropertiesEditDialog dialog = new InputTriggerShareActionPropertiesEditDialog(frame, true, asParameters);
99     dialog.setLocationRelativeTo(frameComp);
100     dialog.setVisible(true);
101     return dialog.isOK();
102   }
103   
104   /** Creates new form InputTriggerShareActionPropertiesEditDialog */
105   public InputTriggerShareActionPropertiesEditDialog(java.awt.Frame JavaDoc parent, boolean modal, ActionShareParameters asParameters)
106   {
107     super(parent, modal);
108     this.asParameters = asParameters;
109     asNodeFilter = asParameters.getAsNodeFilter();
110     asShareGroups = asParameters.getAsShareGroups();
111     isOK = false;
112     
113     initComponents();
114     
115     int numLic = asParameters.getAsNoLicences();
116     if (numLic == Licence.ONE_IMPLICIT_LICENCE)
117     {
118       asNumberOfLicencesCheckBox.setSelected(false);
119       asNumberOfLicencesTextField.setText("");
120       asNumberOfLicencesTextField.setEnabled(false);
121       asNumberOfLicencesLabel.setEnabled(false);
122     }
123     else
124     if (numLic == Licence.ALL_LICENCES)
125     {
126       asNumberOfLicencesCheckBox.setSelected(true);
127       asNumberOfLicencesTextField.setText("*");
128       asNumberOfLicencesTextField.setEnabled(true);
129       asNumberOfLicencesLabel.setEnabled(true);
130     }
131     else
132     {
133       asNumberOfLicencesCheckBox.setSelected(true);
134       asNumberOfLicencesTextField.setText(Integer.toString(numLic));
135       asNumberOfLicencesTextField.setEnabled(true);
136       asNumberOfLicencesLabel.setEnabled(true);
137     }
138     
139     if (asNodeFilter != null)
140     {
141       asNodeFilterCheckBox.setSelected(true);
142       asNodeFilterButton.setEnabled(true);
143     }
144     else
145     {
146       asNodeFilterCheckBox.setSelected(false);
147       asNodeFilterButton.setEnabled(false);
148     }
149     
150     if (asShareGroups != null)
151     {
152       asShareGroupsCheckBox.setSelected(true);
153       asShareGroupsButton.setEnabled(true);
154     }
155     else
156     {
157       asShareGroupsCheckBox.setSelected(false);
158       asShareGroupsButton.setEnabled(false);
159     }
160     
161     asEqualityCheckBox.setSelected(asParameters.getAsEquality());
162
163     if (asNodeFilter != null) asNodeFilter = (NodeNameFilter)asNodeFilter.clone();
164     else asNodeFilter = new NodeNameFilter();
165     if (asShareGroups != null) asShareGroups = (ShareGroups)asShareGroups.clone();
166     else asShareGroups = new ShareGroups();
167   }
168
169   public boolean isOK()
170   {
171     return isOK;
172   }
173   
174   /** This method is called from within the constructor to
175    * initialize the form.
176    * WARNING: Do NOT modify this code. The content of this method is
177    * always regenerated by the Form Editor.
178    */

179   private void initComponents()//GEN-BEGIN:initComponents
180
{
181     jPanel1 = new javax.swing.JPanel JavaDoc();
182     asNumberOfLicencesPanel = new javax.swing.JPanel JavaDoc();
183     asNumberOfLicencesCheckBox = new javax.swing.JCheckBox JavaDoc();
184     asNumberOfLicencesTextField = new javax.swing.JTextField JavaDoc();
185     asNumberOfLicencesLabel = new javax.swing.JLabel JavaDoc();
186     asShareGroupsPanel = new javax.swing.JPanel JavaDoc();
187     asShareGroupsCheckBox = new javax.swing.JCheckBox JavaDoc();
188     asShareGroupsButton = new javax.swing.JButton JavaDoc();
189     asNodeFilterPanel = new javax.swing.JPanel JavaDoc();
190     asNodeFilterCheckBox = new javax.swing.JCheckBox JavaDoc();
191     asNodeFilterButton = new javax.swing.JButton JavaDoc();
192     asEqualityCheckBox = new javax.swing.JCheckBox JavaDoc();
193     jPanel2 = new javax.swing.JPanel JavaDoc();
194     OKButton = new javax.swing.JButton JavaDoc();
195     cancelButton = new javax.swing.JButton JavaDoc();
196
197     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
198     setTitle("Share Action Properties");
199     jPanel1.setLayout(new java.awt.GridLayout JavaDoc(4, 0));
200
201     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(5, 5, 5, 5)));
202     asNumberOfLicencesPanel.setLayout(new javax.swing.BoxLayout JavaDoc(asNumberOfLicencesPanel, javax.swing.BoxLayout.X_AXIS));
203
204     asNumberOfLicencesCheckBox.setText("Number of Licences");
205     asNumberOfLicencesCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
206     {
207       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
208       {
209         asNumberOfLicencesCheckBoxActionPerformed(evt);
210       }
211     });
212
213     asNumberOfLicencesPanel.add(asNumberOfLicencesCheckBox);
214
215     asNumberOfLicencesPanel.add(asNumberOfLicencesTextField);
216
217     asNumberOfLicencesLabel.setText("(use '*' or 'all' for all licences)");
218     asNumberOfLicencesPanel.add(asNumberOfLicencesLabel);
219
220     jPanel1.add(asNumberOfLicencesPanel);
221
222     asShareGroupsPanel.setLayout(new javax.swing.BoxLayout JavaDoc(asShareGroupsPanel, javax.swing.BoxLayout.X_AXIS));
223
224     asShareGroupsCheckBox.setText("Share Groups");
225     asShareGroupsCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
226     {
227       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
228       {
229         asShareGroupsCheckBoxActionPerformed(evt);
230       }
231     });
232
233     asShareGroupsPanel.add(asShareGroupsCheckBox);
234
235     asShareGroupsButton.setText("Edit Share Groups");
236     asShareGroupsButton.setEnabled(false);
237     asShareGroupsButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
238     {
239       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
240       {
241         asShareGroupsButtonActionPerformed(evt);
242       }
243     });
244
245     asShareGroupsPanel.add(asShareGroupsButton);
246
247     jPanel1.add(asShareGroupsPanel);
248
249     asNodeFilterPanel.setLayout(new javax.swing.BoxLayout JavaDoc(asNodeFilterPanel, javax.swing.BoxLayout.X_AXIS));
250
251     asNodeFilterCheckBox.setText("Node Filter");
252     asNodeFilterCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
253     {
254       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
255       {
256         asNodeFilterCheckBoxActionPerformed(evt);
257       }
258     });
259
260     asNodeFilterPanel.add(asNodeFilterCheckBox);
261
262     asNodeFilterButton.setText("Edit Node Filter");
263     asNodeFilterButton.setEnabled(false);
264     asNodeFilterButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
265     {
266       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
267       {
268         asNodeFilterButtonActionPerformed(evt);
269       }
270     });
271
272     asNodeFilterPanel.add(asNodeFilterButton);
273
274     jPanel1.add(asNodeFilterPanel);
275
276     asEqualityCheckBox.setSelected(true);
277     asEqualityCheckBox.setText("Equality of Manager and Clients");
278     jPanel1.add(asEqualityCheckBox);
279
280     getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
281
282     jPanel2.setMinimumSize(new java.awt.Dimension JavaDoc(200, 35));
283     jPanel2.setPreferredSize(new java.awt.Dimension JavaDoc(400, 35));
284     OKButton.setText("OK");
285     OKButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
286     {
287       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
288       {
289         OKButtonActionPerformed(evt);
290       }
291     });
292
293     jPanel2.add(OKButton);
294
295     cancelButton.setText("Cancel");
296     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
297     {
298       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
299       {
300         cancelButtonActionPerformed(evt);
301       }
302     });
303
304     jPanel2.add(cancelButton);
305
306     getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
307
308     pack();
309   }//GEN-END:initComponents
310

311   private void asNumberOfLicencesCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_asNumberOfLicencesCheckBoxActionPerformed
312
{//GEN-HEADEREND:event_asNumberOfLicencesCheckBoxActionPerformed
313
asNumberOfLicencesTextField.setEnabled(asNumberOfLicencesCheckBox.isSelected());
314     asNumberOfLicencesLabel.setEnabled(asNumberOfLicencesCheckBox.isSelected());
315   }//GEN-LAST:event_asNumberOfLicencesCheckBoxActionPerformed
316

317   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
318
{//GEN-HEADEREND:event_cancelButtonActionPerformed
319
dispose();
320   }//GEN-LAST:event_cancelButtonActionPerformed
321

322   private void OKButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_OKButtonActionPerformed
323
{//GEN-HEADEREND:event_OKButtonActionPerformed
324
boolean asNumberOfLicencesSelected = asNumberOfLicencesCheckBox.isSelected();
325     String JavaDoc asNumberOfLicencesText = asNumberOfLicencesTextField.getText().trim().toLowerCase();
326     boolean asEquality = asEqualityCheckBox.isSelected();
327     
328     int asNumberOfLicences = Licence.ONE_IMPLICIT_LICENCE;
329     if (asNumberOfLicencesSelected && asNumberOfLicencesText.length() != 0)
330     {
331       if (asNumberOfLicencesText.compareTo("*") == 0 || asNumberOfLicencesText.compareTo("all") == 0) asNumberOfLicences = Licence.ALL_LICENCES;
332       else
333       {
334         try
335         {
336           asNumberOfLicences = Integer.parseInt(asNumberOfLicencesText);
337           if (asNumberOfLicences < 0) throw new NumberFormatException JavaDoc("Negative 'Number of Licences' is not allowed");
338         }
339         catch (NumberFormatException JavaDoc e)
340         {
341           JOptionPane.showMessageDialog(this, "Error occured while parsing 'Number of Licences':\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
342           return;
343         }
344       }
345     }
346
347     if (!asNodeFilterCheckBox.isSelected()) asNodeFilter = null;
348     if (!asShareGroupsCheckBox.isSelected()) asShareGroups = null;
349     
350     asParameters.setAsNoLicences(asNumberOfLicences);
351     asParameters.setAsNodeFilter(asNodeFilter);
352     asParameters.setAsShareGroups(asShareGroups);
353     asParameters.setAsEquality(asEquality);
354     
355     isOK = true;
356     dispose();
357   }//GEN-LAST:event_OKButtonActionPerformed
358

359   private void asNodeFilterButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_asNodeFilterButtonActionPerformed
360
{//GEN-HEADEREND:event_asNodeFilterButtonActionPerformed
361
StringListEditDialog.showDialog(this, asNodeFilter.getPatterns(), "Node Name Pattern", "Node Filter Editor");
362   }//GEN-LAST:event_asNodeFilterButtonActionPerformed
363

364   private void asShareGroupsButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_asShareGroupsButtonActionPerformed
365
{//GEN-HEADEREND:event_asShareGroupsButtonActionPerformed
366
StringListEditDialog.showDialog(this, asShareGroups.getList(), "Share Group", "Share Groups Editor");
367   }//GEN-LAST:event_asShareGroupsButtonActionPerformed
368

369   private void asNodeFilterCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_asNodeFilterCheckBoxActionPerformed
370
{//GEN-HEADEREND:event_asNodeFilterCheckBoxActionPerformed
371
asNodeFilterButton.setEnabled(asNodeFilterCheckBox.isSelected());
372   }//GEN-LAST:event_asNodeFilterCheckBoxActionPerformed
373

374   private void asShareGroupsCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_asShareGroupsCheckBoxActionPerformed
375
{//GEN-HEADEREND:event_asShareGroupsCheckBoxActionPerformed
376
asShareGroupsButton.setEnabled(asShareGroupsCheckBox.isSelected());
377   }//GEN-LAST:event_asShareGroupsCheckBoxActionPerformed
378

379   // Variables declaration - do not modify//GEN-BEGIN:variables
380
private javax.swing.JButton JavaDoc OKButton;
381   private javax.swing.JCheckBox JavaDoc asEqualityCheckBox;
382   private javax.swing.JButton JavaDoc asNodeFilterButton;
383   private javax.swing.JCheckBox JavaDoc asNodeFilterCheckBox;
384   private javax.swing.JPanel JavaDoc asNodeFilterPanel;
385   private javax.swing.JCheckBox JavaDoc asNumberOfLicencesCheckBox;
386   private javax.swing.JLabel JavaDoc asNumberOfLicencesLabel;
387   private javax.swing.JPanel JavaDoc asNumberOfLicencesPanel;
388   private javax.swing.JTextField JavaDoc asNumberOfLicencesTextField;
389   private javax.swing.JButton JavaDoc asShareGroupsButton;
390   private javax.swing.JCheckBox JavaDoc asShareGroupsCheckBox;
391   private javax.swing.JPanel JavaDoc asShareGroupsPanel;
392   private javax.swing.JButton JavaDoc cancelButton;
393   private javax.swing.JPanel JavaDoc jPanel1;
394   private javax.swing.JPanel JavaDoc jPanel2;
395   // End of variables declaration//GEN-END:variables
396

397 }
398
Popular Tags