KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * InstallBundleDialog.java
3  *
4  * Created on 10. květen 2004, 22:42
5  */

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

24 public class ShareBundleDialog extends javax.swing.JDialog JavaDoc
25 {
26   private RMIAdminInterface admin;
27   private NodeNameFilter nodeFilter;
28   private ShareGroups shareGroups;
29   private boolean isOK;
30   
31   public static boolean showDialog(Component JavaDoc frameComp, RMIAdminInterface admin, String JavaDoc defaultBundleName)
32   {
33     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
34     ShareBundleDialog dialog = new ShareBundleDialog(frame, true, admin, defaultBundleName);
35     dialog.setLocationRelativeTo(frameComp);
36     dialog.setVisible(true);
37     return dialog.isOK();
38   }
39   
40   /** Creates new form ShareBundleDialog */
41   public ShareBundleDialog(java.awt.Frame JavaDoc parent, boolean modal, RMIAdminInterface admin, String JavaDoc defaultBundleName)
42   {
43     super(parent, modal);
44     this.admin = admin;
45     isOK = false;
46     nodeFilter = new NodeNameFilter();
47     shareGroups = new ShareGroups();
48     initComponents();
49     
50     bundleNameTextField.setText(defaultBundleName);
51   }
52   
53   public boolean isOK()
54   {
55     return isOK;
56   }
57   
58   /** This method is called from within the constructor to
59    * initialize the form.
60    * WARNING: Do NOT modify this code. The content of this method is
61    * always regenerated by the Form Editor.
62    */

63   private void initComponents()//GEN-BEGIN:initComponents
64
{
65     jPanel4 = new javax.swing.JPanel JavaDoc();
66     jPanel1 = new javax.swing.JPanel JavaDoc();
67     jPanel5 = new javax.swing.JPanel JavaDoc();
68     bundleNameLabel = new javax.swing.JLabel JavaDoc();
69     bundleNameTextField = new javax.swing.JTextField JavaDoc();
70     numberOfLicencesLabel = new javax.swing.JLabel JavaDoc();
71     numberOfLicencesTextField = new javax.swing.JTextField JavaDoc();
72     jPanel6 = new javax.swing.JPanel JavaDoc();
73     nodeFilterCheckBox = new javax.swing.JCheckBox JavaDoc();
74     nodeFilterButton = new javax.swing.JButton JavaDoc();
75     jPanel7 = new javax.swing.JPanel JavaDoc();
76     shareGroupsCheckBox = new javax.swing.JCheckBox JavaDoc();
77     shareGroupsButton = new javax.swing.JButton JavaDoc();
78     equalityCheckBox = new javax.swing.JCheckBox JavaDoc();
79     reshareCheckBox = new javax.swing.JCheckBox JavaDoc();
80     jPanel2 = new javax.swing.JPanel JavaDoc();
81     chooseBinaryBundleButton = new javax.swing.JButton JavaDoc();
82     chooseInstalledBundleButton = new javax.swing.JButton JavaDoc();
83     showLicenceButton = new javax.swing.JButton JavaDoc();
84     jPanel3 = new javax.swing.JPanel JavaDoc();
85     shareButton = new javax.swing.JButton JavaDoc();
86     cancelButton = new javax.swing.JButton JavaDoc();
87
88     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
89     setTitle("Share Bundle");
90     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
91
92     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
93     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(600, 280));
94     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
95
96     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
97     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
98     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
99     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(8, 0));
100
101     bundleNameLabel.setText("Bundle Name:");
102     jPanel5.add(bundleNameLabel);
103
104     bundleNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
105     bundleNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
106     jPanel5.add(bundleNameTextField);
107
108     numberOfLicencesLabel.setText("Number of Licences (use '*' or 'all' or leave empty for ''all'/'no licences'):");
109     jPanel5.add(numberOfLicencesLabel);
110
111     numberOfLicencesTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
112     numberOfLicencesTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
113     jPanel5.add(numberOfLicencesTextField);
114
115     jPanel6.setLayout(new javax.swing.BoxLayout JavaDoc(jPanel6, javax.swing.BoxLayout.X_AXIS));
116
117     nodeFilterCheckBox.setText("Node Filter");
118     nodeFilterCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
119     {
120       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
121       {
122         nodeFilterCheckBoxActionPerformed(evt);
123       }
124     });
125
126     jPanel6.add(nodeFilterCheckBox);
127
128     nodeFilterButton.setText("Edit Node Filter");
129     nodeFilterButton.setEnabled(false);
130     nodeFilterButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
131     {
132       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
133       {
134         nodeFilterButtonActionPerformed(evt);
135       }
136     });
137
138     jPanel6.add(nodeFilterButton);
139
140     jPanel5.add(jPanel6);
141
142     jPanel7.setLayout(new javax.swing.BoxLayout JavaDoc(jPanel7, javax.swing.BoxLayout.X_AXIS));
143
144     shareGroupsCheckBox.setText("Share Groups");
145     shareGroupsCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
146     {
147       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
148       {
149         shareGroupsCheckBoxActionPerformed(evt);
150       }
151     });
152
153     jPanel7.add(shareGroupsCheckBox);
154
155     shareGroupsButton.setText("Edit Share Groups");
156     shareGroupsButton.setEnabled(false);
157     shareGroupsButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
158     {
159       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
160       {
161         shareGroupsButtonActionPerformed(evt);
162       }
163     });
164
165     jPanel7.add(shareGroupsButton);
166
167     jPanel5.add(jPanel7);
168
169     equalityCheckBox.setSelected(true);
170     equalityCheckBox.setText("Equality of Manager and Clients");
171     jPanel5.add(equalityCheckBox);
172
173     reshareCheckBox.setText("Reshare");
174     jPanel5.add(reshareCheckBox);
175
176     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
177
178     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
179
180     chooseBinaryBundleButton.setText("Choose Binary Bundle");
181     chooseBinaryBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
182     {
183       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
184       {
185         chooseBinaryBundleButtonActionPerformed(evt);
186       }
187     });
188
189     jPanel2.add(chooseBinaryBundleButton);
190
191     chooseInstalledBundleButton.setText("Choose Installed Bundle");
192     chooseInstalledBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
193     {
194       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
195       {
196         chooseInstalledBundleButtonActionPerformed(evt);
197       }
198     });
199
200     jPanel2.add(chooseInstalledBundleButton);
201
202     showLicenceButton.setText("Show Licence of Selected Bundle");
203     showLicenceButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
204     {
205       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
206       {
207         showLicenceButtonActionPerformed(evt);
208       }
209     });
210
211     jPanel2.add(showLicenceButton);
212
213     jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
214
215     shareButton.setText("Share Bundle");
216     shareButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
217     {
218       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
219       {
220         shareButtonActionPerformed(evt);
221       }
222     });
223
224     jPanel3.add(shareButton);
225
226     cancelButton.setText("Cancel");
227     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
228     {
229       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
230       {
231         cancelButtonActionPerformed(evt);
232       }
233     });
234
235     jPanel3.add(cancelButton);
236
237     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
238
239     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
240
241     pack();
242   }//GEN-END:initComponents
243

244   private void shareGroupsButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_shareGroupsButtonActionPerformed
245
{//GEN-HEADEREND:event_shareGroupsButtonActionPerformed
246
StringListEditDialog.showDialog(this, shareGroups.getList(), "Share Group", "Share Groups Editor");
247   }//GEN-LAST:event_shareGroupsButtonActionPerformed
248

249   private void nodeFilterButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_nodeFilterButtonActionPerformed
250
{//GEN-HEADEREND:event_nodeFilterButtonActionPerformed
251
StringListEditDialog.showDialog(this, nodeFilter.getPatterns(), "Node Name Pattern", "Node Filter Editor");
252   }//GEN-LAST:event_nodeFilterButtonActionPerformed
253

254   private void shareGroupsCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_shareGroupsCheckBoxActionPerformed
255
{//GEN-HEADEREND:event_shareGroupsCheckBoxActionPerformed
256
shareGroupsButton.setEnabled(shareGroupsCheckBox.isSelected());
257   }//GEN-LAST:event_shareGroupsCheckBoxActionPerformed
258

259   private void nodeFilterCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_nodeFilterCheckBoxActionPerformed
260
{//GEN-HEADEREND:event_nodeFilterCheckBoxActionPerformed
261
nodeFilterButton.setEnabled(nodeFilterCheckBox.isSelected());
262   }//GEN-LAST:event_nodeFilterCheckBoxActionPerformed
263

264   private void showLicenceButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_showLicenceButtonActionPerformed
265
{//GEN-HEADEREND:event_showLicenceButtonActionPerformed
266
String JavaDoc bundleName = bundleNameTextField.getText();
267     
268     BundleInfo bundleInfo = new BundleInfo();
269     try
270     {
271       bundleInfo.fromBundleName(bundleName);
272     }
273     catch (BundleInfo.InvalidBundleNameException e)
274     {
275       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
276       return;
277     }
278     
279     Licence licence = null;
280     try
281     {
282       licence = admin.getLicence(bundleName);
283     }
284     catch (RemoteException JavaDoc e)
285     {
286       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
287       return;
288     }
289
290     if (licence != null)
291     {
292       LicenceEditDialog.showDialog(this, licence, false, "Licence File of '" + bundleName + "'");
293     }
294     else
295     {
296       JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' is not limited by licence", "No Licence File Present", JOptionPane.INFORMATION_MESSAGE);
297     }
298   }//GEN-LAST:event_showLicenceButtonActionPerformed
299

300   private void chooseInstalledBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseInstalledBundleButtonActionPerformed
301
{//GEN-HEADEREND:event_chooseInstalledBundleButtonActionPerformed
302
LocalInfoDesc[] localInfoDescs = null;
303     try
304     {
305       localInfoDescs = admin.localInfoDescsList();
306     }
307     catch (RemoteException JavaDoc e)
308     {
309       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
310       return;
311     }
312
313     int size = 0;
314     int i;
315     for (i = 0; i < localInfoDescs.length; i++)
316     {
317       if (localInfoDescs[i].isInstalled()) size++;
318     }
319     
320     LocalInfoDesc[] installed = new LocalInfoDesc[size];
321     int j = 0;
322     for (i = 0; i < localInfoDescs.length; i++)
323     {
324       if (localInfoDescs[i].isInstalled())
325       {
326         installed[j++] = localInfoDescs[i];
327       }
328     }
329
330     Arrays.sort(installed);
331     
332     LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Installed Bundles:", "Choose Installed Bundle to Share", installed, null, null, false, true);
333     if (result != null) bundleNameTextField.setText(result.bundleName);
334   }//GEN-LAST:event_chooseInstalledBundleButtonActionPerformed
335

336   private void chooseBinaryBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseBinaryBundleButtonActionPerformed
337
{//GEN-HEADEREND:event_chooseBinaryBundleButtonActionPerformed
338
String JavaDoc[] bundles = null;
339     try
340     {
341       bundles = admin.binBundlesList();
342     }
343     catch (RemoteException JavaDoc e)
344     {
345       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
346       return;
347     }
348
349     Arrays.sort(bundles);
350     
351     String JavaDoc result = ListDialog.showDialog(this, this, "Binary Bundles:", "Choose Binary Bundle to Install", bundles, null, null, false, true);
352     if (result.length() != 0) bundleNameTextField.setText(result);
353     
354   }//GEN-LAST:event_chooseBinaryBundleButtonActionPerformed
355

356   private void shareButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_shareButtonActionPerformed
357
{//GEN-HEADEREND:event_shareButtonActionPerformed
358
String JavaDoc bundleName = bundleNameTextField.getText();
359     String JavaDoc numberOfLicencesText = numberOfLicencesTextField.getText().trim().toLowerCase();
360     boolean equality = equalityCheckBox.isSelected();
361     boolean reshare = reshareCheckBox.isSelected();
362
363     BundleInfo bundleInfo = new BundleInfo();
364     try
365     {
366       bundleInfo.fromBundleName(bundleName);
367     }
368     catch (BundleInfo.InvalidBundleNameException e)
369     {
370       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
371       return;
372     }
373     
374     int numberOfLicences = Licence.ALL_LICENCES;
375     if (numberOfLicencesText.length() != 0 && numberOfLicencesText.compareTo("*") != 0 && numberOfLicencesText.compareTo("all") != 0)
376     {
377       try
378       {
379         numberOfLicences = Integer.parseInt(numberOfLicencesText);
380         if (numberOfLicences < 0) throw new NumberFormatException JavaDoc("Negative 'Number of Licences' is not allowed");
381       }
382       catch (NumberFormatException JavaDoc e)
383       {
384         JOptionPane.showMessageDialog(this, "Error occured while parsing 'Number of Licences':\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
385         return;
386       }
387     }
388
389     if (!nodeFilterCheckBox.isSelected()) nodeFilter = null;
390     if (!shareGroupsCheckBox.isSelected()) shareGroups = null;
391     
392     try
393     {
394       admin.shareBundle(bundleName, numberOfLicences, shareGroups, nodeFilter, equality, reshare);
395     }
396     catch (RemoteException JavaDoc e)
397     {
398       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
399       dispose();
400       return;
401     }
402     catch (RMIAdminException e)
403     {
404       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
405       dispose();
406       return;
407     }
408     
409     JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully shared");
410     
411     isOK = true;
412     dispose();
413   }//GEN-LAST:event_shareButtonActionPerformed
414

415   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
416
{//GEN-HEADEREND:event_cancelButtonActionPerformed
417
dispose();
418   }//GEN-LAST:event_cancelButtonActionPerformed
419

420   
421   // Variables declaration - do not modify//GEN-BEGIN:variables
422
private javax.swing.JLabel JavaDoc bundleNameLabel;
423   private javax.swing.JTextField JavaDoc bundleNameTextField;
424   private javax.swing.JButton JavaDoc cancelButton;
425   private javax.swing.JButton JavaDoc chooseBinaryBundleButton;
426   private javax.swing.JButton JavaDoc chooseInstalledBundleButton;
427   private javax.swing.JCheckBox JavaDoc equalityCheckBox;
428   private javax.swing.JPanel JavaDoc jPanel1;
429   private javax.swing.JPanel JavaDoc jPanel2;
430   private javax.swing.JPanel JavaDoc jPanel3;
431   private javax.swing.JPanel JavaDoc jPanel4;
432   private javax.swing.JPanel JavaDoc jPanel5;
433   private javax.swing.JPanel JavaDoc jPanel6;
434   private javax.swing.JPanel JavaDoc jPanel7;
435   private javax.swing.JButton JavaDoc nodeFilterButton;
436   private javax.swing.JCheckBox JavaDoc nodeFilterCheckBox;
437   private javax.swing.JLabel JavaDoc numberOfLicencesLabel;
438   private javax.swing.JTextField JavaDoc numberOfLicencesTextField;
439   private javax.swing.JCheckBox JavaDoc reshareCheckBox;
440   private javax.swing.JButton JavaDoc shareButton;
441   private javax.swing.JButton JavaDoc shareGroupsButton;
442   private javax.swing.JCheckBox JavaDoc shareGroupsCheckBox;
443   private javax.swing.JButton JavaDoc showLicenceButton;
444   // End of variables declaration//GEN-END:variables
445

446 }
447
Popular Tags