KickJava   Java API By Example, From Geeks To Geeks.

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


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 PullBundleDialog 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     PullBundleDialog dialog = new PullBundleDialog(frame, true, admin, defaultBundleName);
32     dialog.setLocationRelativeTo(frameComp);
33     dialog.setVisible(true);
34     return dialog.isOK();
35   }
36   
37   /** Creates new form PullBundleDialog */
38   public PullBundleDialog(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     synchroCheckBox = new javax.swing.JCheckBox JavaDoc();
70     jPanel3 = new javax.swing.JPanel JavaDoc();
71     pullButton = new javax.swing.JButton JavaDoc();
72     cancelButton = new javax.swing.JButton JavaDoc();
73
74     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
75     setTitle("Pull Bundle");
76     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
77
78     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
79     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(400, 210));
80     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
81
82     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
83     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
84     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
85     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(7, 0));
86
87     bundleNameLabel.setText("Bundle Name:");
88     jPanel5.add(bundleNameLabel);
89
90     bundleNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
91     bundleNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
92     jPanel5.add(bundleNameTextField);
93
94     nodeNameLabel.setText("Node name:");
95     jPanel5.add(nodeNameLabel);
96
97     nodeNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
98     nodeNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
99     jPanel5.add(nodeNameTextField);
100
101     contractIDLabel.setText("Contract ID (leave empty for no contract):");
102     jPanel5.add(contractIDLabel);
103
104     contractIDTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
105     contractIDTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
106     jPanel5.add(contractIDTextField);
107
108     synchroCheckBox.setSelected(true);
109     synchroCheckBox.setText("Synchronous");
110     jPanel5.add(synchroCheckBox);
111
112     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
113
114     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
115
116     pullButton.setText("Pull Bundle");
117     pullButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
118     {
119       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
120       {
121         pullButtonActionPerformed(evt);
122       }
123     });
124
125     jPanel3.add(pullButton);
126
127     cancelButton.setText("Cancel");
128     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
129     {
130       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
131       {
132         cancelButtonActionPerformed(evt);
133       }
134     });
135
136     jPanel3.add(cancelButton);
137
138     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
139
140     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
141
142     pack();
143   }//GEN-END:initComponents
144

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

198   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
199
{//GEN-HEADEREND:event_cancelButtonActionPerformed
200
dispose();
201   }//GEN-LAST:event_cancelButtonActionPerformed
202

203   
204   // Variables declaration - do not modify//GEN-BEGIN:variables
205
private javax.swing.JLabel JavaDoc bundleNameLabel;
206   private javax.swing.JTextField JavaDoc bundleNameTextField;
207   private javax.swing.JButton JavaDoc cancelButton;
208   private javax.swing.JLabel JavaDoc contractIDLabel;
209   private javax.swing.JTextField JavaDoc contractIDTextField;
210   private javax.swing.JPanel JavaDoc jPanel1;
211   private javax.swing.JPanel JavaDoc jPanel3;
212   private javax.swing.JPanel JavaDoc jPanel4;
213   private javax.swing.JPanel JavaDoc jPanel5;
214   private javax.swing.JLabel JavaDoc nodeNameLabel;
215   private javax.swing.JTextField JavaDoc nodeNameTextField;
216   private javax.swing.JButton JavaDoc pullButton;
217   private javax.swing.JCheckBox JavaDoc synchroCheckBox;
218   // End of variables declaration//GEN-END:variables
219

220 }
221
Popular Tags