KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestPushBundleDialog 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     TestPushBundleDialog dialog = new TestPushBundleDialog(frame, true, admin, defaultBundleName);
32     dialog.setLocationRelativeTo(frameComp);
33     dialog.setVisible(true);
34     return dialog.isOK();
35   }
36   
37   /** Creates new form TestPushBundleDialog */
38   public TestPushBundleDialog(java.awt.Frame JavaDoc parent, boolean modal, RMIAdminInterface admin, String JavaDoc defaultBundleName)
39   {
40     super(parent, modal);
41     this.admin = admin;
42     initComponents();
43     
44     bundleNameTextField.setText(defaultBundleName);
45   }
46   
47   public boolean isOK()
48   {
49     return isOK;
50   }
51   
52   /** This method is called from within the constructor to
53    * initialize the form.
54    * WARNING: Do NOT modify this code. The content of this method is
55    * always regenerated by the Form Editor.
56    */

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

157   private void showLicenceButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_showLicenceButtonActionPerformed
158
{//GEN-HEADEREND:event_showLicenceButtonActionPerformed
159
String JavaDoc bundleName = bundleNameTextField.getText();
160     
161     BundleInfo bundleInfo = new BundleInfo();
162     try
163     {
164       bundleInfo.fromBundleName(bundleName);
165     }
166     catch (BundleInfo.InvalidBundleNameException e)
167     {
168       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
169       return;
170     }
171     
172     Licence licence = null;
173     try
174     {
175       licence = admin.getLicence(bundleName);
176     }
177     catch (RemoteException JavaDoc e)
178     {
179       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
180       return;
181     }
182
183     if (licence != null)
184     {
185       LicenceEditDialog.showDialog(this, licence, false, "Licence File of '" + bundleName + "'");
186     }
187     else
188     {
189       JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' is not limited by licence", "No Licence File Present", JOptionPane.INFORMATION_MESSAGE);
190     }
191   }//GEN-LAST:event_showLicenceButtonActionPerformed
192

193   private void chooseBinaryBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseBinaryBundleButtonActionPerformed
194
{//GEN-HEADEREND:event_chooseBinaryBundleButtonActionPerformed
195
String JavaDoc[] bundles = null;
196     try
197     {
198       bundles = admin.binBundlesList();
199     }
200     catch (RemoteException JavaDoc e)
201     {
202       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
203       return;
204     }
205
206     Arrays.sort(bundles);
207     
208     String JavaDoc result = ListDialog.showDialog(this, this, "Binary Bundles:", "Choose Binary Bundle to Test Push", bundles, null, null, false, true);
209     if (result.length() != 0) bundleNameTextField.setText(result);
210     
211   }//GEN-LAST:event_chooseBinaryBundleButtonActionPerformed
212

213   private void testPushButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_testPushButtonActionPerformed
214
{//GEN-HEADEREND:event_testPushButtonActionPerformed
215
String JavaDoc bundleName = bundleNameTextField.getText();
216     String JavaDoc nodeName = nodeNameTextField.getText();
217
218     BundleInfo bundleInfo = new BundleInfo();
219     try
220     {
221       bundleInfo.fromBundleName(bundleName);
222     }
223     catch (BundleInfo.InvalidBundleNameException e)
224     {
225       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
226       return;
227     }
228     
229     NodeInfo nodeInfo = new NodeInfo();
230     try
231     {
232       nodeInfo.setNodeName(nodeName);
233     }
234     catch (NodeInfo.InvalidNodeNameException e)
235     {
236       JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
237       return;
238     }
239     
240     boolean result = false;
241     try
242     {
243       result = admin.testPush(bundleName, nodeName, false);
244     }
245     catch (RemoteException JavaDoc e)
246     {
247       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
248       dispose();
249       return;
250     }
251     catch (RMIAdminException e)
252     {
253       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
254       dispose();
255       return;
256     }
257     
258     if (result) JOptionPane.showMessageDialog(this, "Node '" + nodeName + "' accepts push of bundle '" + bundleName + "'");
259     else JOptionPane.showMessageDialog(this, "Node '" + nodeName + "' DOES NOT ACCEPT push of bundle '" + bundleName + "'!");
260     
261     isOK = true;
262     dispose();
263   }//GEN-LAST:event_testPushButtonActionPerformed
264

265   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
266
{//GEN-HEADEREND:event_cancelButtonActionPerformed
267
dispose();
268   }//GEN-LAST:event_cancelButtonActionPerformed
269

270   
271   // Variables declaration - do not modify//GEN-BEGIN:variables
272
private javax.swing.JLabel JavaDoc bundleNameLabel;
273   private javax.swing.JTextField JavaDoc bundleNameTextField;
274   private javax.swing.JButton JavaDoc cancelButton;
275   private javax.swing.JButton JavaDoc chooseBinaryBundleButton;
276   private javax.swing.JPanel JavaDoc jPanel1;
277   private javax.swing.JPanel JavaDoc jPanel2;
278   private javax.swing.JPanel JavaDoc jPanel3;
279   private javax.swing.JPanel JavaDoc jPanel4;
280   private javax.swing.JPanel JavaDoc jPanel5;
281   private javax.swing.JLabel JavaDoc nodeNameLabel;
282   private javax.swing.JTextField JavaDoc nodeNameTextField;
283   private javax.swing.JButton JavaDoc showLicenceButton;
284   private javax.swing.JButton JavaDoc testPushButton;
285   // End of variables declaration//GEN-END:variables
286

287 }
288
Popular Tags