KickJava   Java API By Example, From Geeks To Geeks.

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


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 PushBundleOfferDialog 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     PushBundleOfferDialog dialog = new PushBundleOfferDialog(frame, true, admin, defaultBundleName);
32     dialog.setLocationRelativeTo(frameComp);
33     dialog.setVisible(true);
34     return dialog.isOK();
35   }
36   
37   /** Creates new form PushBundleOfferDialog */
38   public PushBundleOfferDialog(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     pushBundleOfferButton = new javax.swing.JButton JavaDoc();
71     cancelButton = new javax.swing.JButton JavaDoc();
72
73     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
74     setTitle("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     pushBundleOfferButton.setText("Push Bundle Offer");
118     pushBundleOfferButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
119     {
120       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
121       {
122         pushBundleOfferButtonActionPerformed(evt);
123       }
124     });
125
126     jPanel3.add(pushBundleOfferButton);
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 pushBundleOfferButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_pushBundleOfferButtonActionPerformed
167
{//GEN-HEADEREND:event_pushBundleOfferButtonActionPerformed
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     try
194     {
195       admin.pushBundleOffer(bundleName, nodeName);
196     }
197     catch (RemoteException JavaDoc e)
198     {
199       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
200       dispose();
201       return;
202     }
203     catch (RMIAdminException e)
204     {
205       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
206       dispose();
207       return;
208     }
209     
210     JOptionPane.showMessageDialog(this, "Bundle offer '" + bundleName + "' has been scheduled to push to node '" + nodeName + "'");
211     
212     isOK = true;
213     dispose();
214   }//GEN-LAST:event_pushBundleOfferButtonActionPerformed
215

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

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

237 }
238
Popular Tags