KickJava   Java API By Example, From Geeks To Geeks.

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


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 TestPullBundleDialog 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     TestPullBundleDialog dialog = new TestPullBundleDialog(frame, true, admin, defaultBundleName);
32     dialog.setLocationRelativeTo(frameComp);
33     dialog.setVisible(true);
34     return dialog.isOK();
35   }
36   
37   /** Creates new form TestPullBundleDialog */
38   public TestPullBundleDialog(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     contractIDLabel = new javax.swing.JLabel JavaDoc();
68     contractIDTextField = new javax.swing.JTextField JavaDoc();
69     jPanel3 = new javax.swing.JPanel JavaDoc();
70     testPullButton = new javax.swing.JButton JavaDoc();
71     cancelButton = new javax.swing.JButton JavaDoc();
72
73     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
74     setTitle("Test Pull 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, 180));
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(6, 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     contractIDLabel.setText("Contract ID (leave empty for no contract):");
101     jPanel5.add(contractIDLabel);
102
103     contractIDTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
104     contractIDTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
105     jPanel5.add(contractIDTextField);
106
107     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
108
109     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
110
111     testPullButton.setText("Test Pull Bundle");
112     testPullButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
113     {
114       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
115       {
116         testPullButtonActionPerformed(evt);
117       }
118     });
119
120     jPanel3.add(testPullButton);
121
122     cancelButton.setText("Cancel");
123     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
124     {
125       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
126       {
127         cancelButtonActionPerformed(evt);
128       }
129     });
130
131     jPanel3.add(cancelButton);
132
133     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
134
135     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
136
137     pack();
138   }//GEN-END:initComponents
139

140   private void testPullButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_testPullButtonActionPerformed
141
{//GEN-HEADEREND:event_testPullButtonActionPerformed
142
String JavaDoc bundleName = bundleNameTextField.getText();
143     String JavaDoc nodeName = nodeNameTextField.getText();
144     String JavaDoc contractID = contractIDTextField.getText();
145
146     BundleInfo bundleInfo = new BundleInfo();
147     try
148     {
149       bundleInfo.fromBundleName(bundleName);
150     }
151     catch (BundleInfo.InvalidBundleNameException e)
152     {
153       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
154       return;
155     }
156     
157     NodeInfo nodeInfo = new NodeInfo();
158     try
159     {
160       nodeInfo.setNodeName(nodeName);
161     }
162     catch (NodeInfo.InvalidNodeNameException e)
163     {
164       JOptionPane.showMessageDialog(this, "Invalid name of SOFA node:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
165       return;
166     }
167     
168     boolean result = false;
169     try
170     {
171       result = admin.testPull(bundleName, nodeName, contractID);
172     }
173     catch (RemoteException JavaDoc e)
174     {
175       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
176       dispose();
177       return;
178     }
179     catch (RMIAdminException e)
180     {
181       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
182       dispose();
183       return;
184     }
185     
186     if (result) JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' can be pulled from node '" + nodeName + "'");
187     else JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' CAN NOT be pulled from node '" + nodeName + "'!");
188     
189     isOK = true;
190     dispose();
191   }//GEN-LAST:event_testPullButtonActionPerformed
192

193   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
194
{//GEN-HEADEREND:event_cancelButtonActionPerformed
195
dispose();
196   }//GEN-LAST:event_cancelButtonActionPerformed
197

198   
199   // Variables declaration - do not modify//GEN-BEGIN:variables
200
private javax.swing.JLabel JavaDoc bundleNameLabel;
201   private javax.swing.JTextField JavaDoc bundleNameTextField;
202   private javax.swing.JButton JavaDoc cancelButton;
203   private javax.swing.JLabel JavaDoc contractIDLabel;
204   private javax.swing.JTextField JavaDoc contractIDTextField;
205   private javax.swing.JPanel JavaDoc jPanel1;
206   private javax.swing.JPanel JavaDoc jPanel3;
207   private javax.swing.JPanel JavaDoc jPanel4;
208   private javax.swing.JPanel JavaDoc jPanel5;
209   private javax.swing.JLabel JavaDoc nodeNameLabel;
210   private javax.swing.JTextField JavaDoc nodeNameTextField;
211   private javax.swing.JButton JavaDoc testPullButton;
212   // End of variables declaration//GEN-END:variables
213

214 }
215
Popular Tags