KickJava   Java API By Example, From Geeks To Geeks.

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


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.NodeInfo;
12 import SOFA.SOFAnet.Repository.Licence;
13 import javax.swing.*;
14 import java.rmi.RemoteException JavaDoc;
15 import java.util.*;
16 import java.awt.Component JavaDoc;
17 import java.awt.Frame JavaDoc;
18
19 /**
20  *
21  * @author Ladislav Sobr
22  */

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

58   private void initComponents()//GEN-BEGIN:initComponents
59
{
60     jPanel4 = new javax.swing.JPanel JavaDoc();
61     jPanel1 = new javax.swing.JPanel JavaDoc();
62     jPanel5 = new javax.swing.JPanel JavaDoc();
63     bundleNameLabel = new javax.swing.JLabel JavaDoc();
64     bundleNameTextField = new javax.swing.JTextField JavaDoc();
65     nodeNameLabel = new javax.swing.JLabel JavaDoc();
66     nodeNameTextField = new javax.swing.JTextField JavaDoc();
67     numberOfLicencesLabel = new javax.swing.JLabel JavaDoc();
68     numberOfLicencesTextField = new javax.swing.JTextField JavaDoc();
69     warnLabel = new javax.swing.JLabel JavaDoc();
70     jPanel2 = new javax.swing.JPanel JavaDoc();
71     chooseBinaryBundleButton = new javax.swing.JButton JavaDoc();
72     showLicenceButton = new javax.swing.JButton JavaDoc();
73     jPanel3 = new javax.swing.JPanel JavaDoc();
74     pushButton = new javax.swing.JButton JavaDoc();
75     cancelButton = new javax.swing.JButton JavaDoc();
76
77     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
78     setTitle("Push Bundle");
79     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
80
81     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
82     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(400, 230));
83     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
84
85     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
86     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
87     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
88     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(7, 0));
89
90     bundleNameLabel.setText("Bundle Name:");
91     jPanel5.add(bundleNameLabel);
92
93     bundleNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
94     bundleNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
95     jPanel5.add(bundleNameTextField);
96
97     nodeNameLabel.setText("Node name:");
98     jPanel5.add(nodeNameLabel);
99
100     nodeNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
101     nodeNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
102     jPanel5.add(nodeNameTextField);
103
104     numberOfLicencesLabel.setText("Number of Licences (leave empty for 'all'/'no licences'):");
105     jPanel5.add(numberOfLicencesLabel);
106
107     numberOfLicencesTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
108     numberOfLicencesTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
109     jPanel5.add(numberOfLicencesTextField);
110
111     warnLabel.setText("'Number of Licences' has no effect if Contract is present.");
112     jPanel5.add(warnLabel);
113
114     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
115
116     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
117
118     chooseBinaryBundleButton.setText("Choose Binary Bundle");
119     chooseBinaryBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
120     {
121       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
122       {
123         chooseBinaryBundleButtonActionPerformed(evt);
124       }
125     });
126
127     jPanel2.add(chooseBinaryBundleButton);
128
129     showLicenceButton.setText("Show Licence of Selected Bundle");
130     showLicenceButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
131     {
132       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
133       {
134         showLicenceButtonActionPerformed(evt);
135       }
136     });
137
138     jPanel2.add(showLicenceButton);
139
140     jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
141
142     pushButton.setText("Push Bundle");
143     pushButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
144     {
145       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
146       {
147         pushButtonActionPerformed(evt);
148       }
149     });
150
151     jPanel3.add(pushButton);
152
153     cancelButton.setText("Cancel");
154     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
155     {
156       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
157       {
158         cancelButtonActionPerformed(evt);
159       }
160     });
161
162     jPanel3.add(cancelButton);
163
164     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
165
166     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
167
168     pack();
169   }//GEN-END:initComponents
170

171   private void showLicenceButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_showLicenceButtonActionPerformed
172
{//GEN-HEADEREND:event_showLicenceButtonActionPerformed
173
String JavaDoc bundleName = bundleNameTextField.getText();
174     
175     BundleInfo bundleInfo = new BundleInfo();
176     try
177     {
178       bundleInfo.fromBundleName(bundleName);
179     }
180     catch (BundleInfo.InvalidBundleNameException e)
181     {
182       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
183       return;
184     }
185     
186     Licence licence = null;
187     try
188     {
189       licence = admin.getLicence(bundleName);
190     }
191     catch (RemoteException JavaDoc e)
192     {
193       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
194       return;
195     }
196
197     if (licence != null)
198     {
199       LicenceEditDialog.showDialog(this, licence, false, "Licence File of '" + bundleName + "'");
200     }
201     else
202     {
203       JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' is not limited by licence", "No Licence File Present", JOptionPane.INFORMATION_MESSAGE);
204     }
205   }//GEN-LAST:event_showLicenceButtonActionPerformed
206

207   private void chooseBinaryBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseBinaryBundleButtonActionPerformed
208
{//GEN-HEADEREND:event_chooseBinaryBundleButtonActionPerformed
209
String JavaDoc[] bundles = null;
210     try
211     {
212       bundles = admin.binBundlesList();
213     }
214     catch (RemoteException JavaDoc e)
215     {
216       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
217       return;
218     }
219
220     Arrays.sort(bundles);
221     
222     String JavaDoc result = ListDialog.showDialog(this, this, "Binary Bundles:", "Choose Binary Bundle to Push", bundles, null, null, false, true);
223     if (result.length() != 0) bundleNameTextField.setText(result);
224     
225   }//GEN-LAST:event_chooseBinaryBundleButtonActionPerformed
226

227   private void pushButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_pushButtonActionPerformed
228
{//GEN-HEADEREND:event_pushButtonActionPerformed
229
String JavaDoc bundleName = bundleNameTextField.getText();
230     String JavaDoc nodeName = nodeNameTextField.getText();
231     String JavaDoc numberOfLicencesText = numberOfLicencesTextField.getText().trim();
232     
233     BundleInfo bundleInfo = new BundleInfo();
234     try
235     {
236       bundleInfo.fromBundleName(bundleName);
237     }
238     catch (BundleInfo.InvalidBundleNameException e)
239     {
240       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
241       return;
242     }
243     
244     NodeInfo nodeInfo = new NodeInfo();
245     try
246     {
247       nodeInfo.setNodeName(nodeName);
248     }
249     catch (NodeInfo.InvalidNodeNameException e)
250     {
251       JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
252       return;
253     }
254     
255     int numberOfLicences = Licence.ALL_LICENCES;
256     if (numberOfLicencesText.length() != 0)
257     {
258       try
259       {
260         numberOfLicences = Integer.parseInt(numberOfLicencesText);
261         if (numberOfLicences < 0) throw new NumberFormatException JavaDoc("Negative 'Number of Licences' is not allowed");
262       }
263       catch (NumberFormatException JavaDoc e)
264       {
265         JOptionPane.showMessageDialog(this, "Error occured while parsing 'Number of Copies':\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
266         return;
267       }
268     }
269     
270     try
271     {
272       admin.pushBundle(bundleName, nodeName, numberOfLicences);
273     }
274     catch (RemoteException JavaDoc e)
275     {
276       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
277       dispose();
278       return;
279     }
280     catch (RMIAdminException e)
281     {
282       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
283       dispose();
284       return;
285     }
286     
287     JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' has been scheduled to push to node '" + nodeName + "'");
288     
289     isOK = true;
290     dispose();
291   }//GEN-LAST:event_pushButtonActionPerformed
292

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

298   
299   // Variables declaration - do not modify//GEN-BEGIN:variables
300
private javax.swing.JLabel JavaDoc bundleNameLabel;
301   private javax.swing.JTextField JavaDoc bundleNameTextField;
302   private javax.swing.JButton JavaDoc cancelButton;
303   private javax.swing.JButton JavaDoc chooseBinaryBundleButton;
304   private javax.swing.JPanel JavaDoc jPanel1;
305   private javax.swing.JPanel JavaDoc jPanel2;
306   private javax.swing.JPanel JavaDoc jPanel3;
307   private javax.swing.JPanel JavaDoc jPanel4;
308   private javax.swing.JPanel JavaDoc jPanel5;
309   private javax.swing.JLabel JavaDoc nodeNameLabel;
310   private javax.swing.JTextField JavaDoc nodeNameTextField;
311   private javax.swing.JLabel JavaDoc numberOfLicencesLabel;
312   private javax.swing.JTextField JavaDoc numberOfLicencesTextField;
313   private javax.swing.JButton JavaDoc pushButton;
314   private javax.swing.JButton JavaDoc showLicenceButton;
315   private javax.swing.JLabel JavaDoc warnLabel;
316   // End of variables declaration//GEN-END:variables
317

318 }
319
Popular Tags