KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestPushBundleOfferDialog 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     TestPushBundleOfferDialog dialog = new TestPushBundleOfferDialog(frame, true, admin, defaultBundleName);
32     dialog.setLocationRelativeTo(frameComp);
33     dialog.setVisible(true);
34     return dialog.isOK();
35   }
36   
37   /** Creates new form TestPushBundleOfferDialog */
38   public TestPushBundleOfferDialog(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     jPanel2 = new javax.swing.JPanel JavaDoc();
68     chooseBundleOfferButton = new javax.swing.JButton JavaDoc();
69     jPanel3 = new javax.swing.JPanel JavaDoc();
70     testPushBundleOfferButton = 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 Offer");
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 Offer 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     chooseBundleOfferButton.setText("Choose Bundle Offer");
105     chooseBundleOfferButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
106     {
107       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
108       {
109         chooseBundleOfferButtonActionPerformed(evt);
110       }
111     });
112
113     jPanel2.add(chooseBundleOfferButton);
114
115     jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
116
117     testPushBundleOfferButton.setText("Test Push Bundle Offer");
118     testPushBundleOfferButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
119     {
120       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
121       {
122         testPushBundleOfferButtonActionPerformed(evt);
123       }
124     });
125
126     jPanel3.add(testPushBundleOfferButton);
127
128     cancelButton.setText("Cancel");
129     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
130     {
131       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
132       {
133         cancelButtonActionPerformed(evt);
134       }
135     });
136
137     jPanel3.add(cancelButton);
138
139     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
140
141     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
142
143     pack();
144   }//GEN-END:initComponents
145

146   private void chooseBundleOfferButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseBundleOfferButtonActionPerformed
147
{//GEN-HEADEREND:event_chooseBundleOfferButtonActionPerformed
148
String JavaDoc[] bundles = null;
149     try
150     {
151       bundles = admin.bundleOffersList();
152     }
153     catch (RemoteException JavaDoc e)
154     {
155       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
156       return;
157     }
158
159     Arrays.sort(bundles);
160     
161     String JavaDoc result = ListDialog.showDialog(this, this, "Bundle Offers:", "Choose Bundle Offer to Test Push", bundles, null, null, false, true);
162     if (result.length() != 0) bundleNameTextField.setText(result);
163     
164   }//GEN-LAST:event_chooseBundleOfferButtonActionPerformed
165

166   private void testPushBundleOfferButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_testPushBundleOfferButtonActionPerformed
167
{//GEN-HEADEREND:event_testPushBundleOfferButtonActionPerformed
168
String JavaDoc bundleName = bundleNameTextField.getText();
169     String JavaDoc nodeName = nodeNameTextField.getText();
170
171     BundleInfo bundleInfo = new BundleInfo();
172     try
173     {
174       bundleInfo.fromBundleName(bundleName);
175     }
176     catch (BundleInfo.InvalidBundleNameException e)
177     {
178       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
179       return;
180     }
181     
182     NodeInfo nodeInfo = new NodeInfo();
183     try
184     {
185       nodeInfo.setNodeName(nodeName);
186     }
187     catch (NodeInfo.InvalidNodeNameException e)
188     {
189       JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
190       return;
191     }
192     
193     boolean result = false;
194     try
195     {
196       result = admin.testPush(bundleName, nodeName, true);
197     }
198     catch (RemoteException JavaDoc e)
199     {
200       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
201       dispose();
202       return;
203     }
204     catch (RMIAdminException e)
205     {
206       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
207       dispose();
208       return;
209     }
210     
211     if (result) JOptionPane.showMessageDialog(this, "Node '" + nodeName + "' accepts push of bundle offer '" + bundleName + "'");
212     else JOptionPane.showMessageDialog(this, "Node '" + nodeName + "' DOES NOT ACCEPT push of bundle offer '" + bundleName + "'!");
213     
214     isOK = true;
215     dispose();
216   }//GEN-LAST:event_testPushBundleOfferButtonActionPerformed
217

218   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
219
{//GEN-HEADEREND:event_cancelButtonActionPerformed
220
dispose();
221   }//GEN-LAST:event_cancelButtonActionPerformed
222

223   
224   // Variables declaration - do not modify//GEN-BEGIN:variables
225
private javax.swing.JLabel JavaDoc bundleNameLabel;
226   private javax.swing.JTextField JavaDoc bundleNameTextField;
227   private javax.swing.JButton JavaDoc cancelButton;
228   private javax.swing.JButton JavaDoc chooseBundleOfferButton;
229   private javax.swing.JPanel JavaDoc jPanel1;
230   private javax.swing.JPanel JavaDoc jPanel2;
231   private javax.swing.JPanel JavaDoc jPanel3;
232   private javax.swing.JPanel JavaDoc jPanel4;
233   private javax.swing.JPanel JavaDoc jPanel5;
234   private javax.swing.JLabel JavaDoc nodeNameLabel;
235   private javax.swing.JTextField JavaDoc nodeNameTextField;
236   private javax.swing.JButton JavaDoc testPushBundleOfferButton;
237   // End of variables declaration//GEN-END:variables
238

239 }
240
Popular Tags