KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.*;
12 import java.rmi.RemoteException JavaDoc;
13 import java.util.*;
14 import java.awt.Component JavaDoc;
15 import java.awt.Frame JavaDoc;
16
17 /**
18  *
19  * @author Ladislav Sobr
20  */

21 public class InstallBundleDialog extends javax.swing.JDialog JavaDoc
22 {
23   private RMIAdminInterface admin;
24   private boolean isOK;
25   
26   public static boolean showDialog(Component JavaDoc frameComp, RMIAdminInterface admin, String JavaDoc defaultBundleName)
27   {
28     Frame JavaDoc frame = JOptionPane.getFrameForComponent(frameComp);
29     InstallBundleDialog dialog = new InstallBundleDialog(frame, true, admin, defaultBundleName);
30     dialog.setLocationRelativeTo(frameComp);
31     dialog.setVisible(true);
32     return dialog.isOK();
33   }
34   
35   /** Creates new form InstallBundleDialog */
36   public InstallBundleDialog(java.awt.Frame JavaDoc parent, boolean modal, RMIAdminInterface admin, String JavaDoc defaultBundleName)
37   {
38     super(parent, modal);
39     this.admin = admin;
40     isOK = false;
41     initComponents();
42     
43     bundleNameTextField.setText(defaultBundleName);
44   }
45   
46   public boolean isOK()
47   {
48     return isOK;
49   }
50   
51   /** This method is called from within the constructor to
52    * initialize the form.
53    * WARNING: Do NOT modify this code. The content of this method is
54    * always regenerated by the Form Editor.
55    */

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

151   private void chooseShareClientButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseShareClientButtonActionPerformed
152
{//GEN-HEADEREND:event_chooseShareClientButtonActionPerformed
153
LocalInfoDesc[] localInfoDescs = null;
154     try
155     {
156       localInfoDescs = admin.localInfoDescsList();
157     }
158     catch (RemoteException JavaDoc e)
159     {
160       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
161       return;
162     }
163
164     int size = 0;
165     int i;
166     for (i = 0; i < localInfoDescs.length; i++)
167     {
168       if (localInfoDescs[i].isShareClient()) size++;
169     }
170     
171     LocalInfoDesc[] shareClients = new LocalInfoDesc[size];
172     int j = 0;
173     for (i = 0; i < localInfoDescs.length; i++)
174     {
175       if (localInfoDescs[i].isShareClient())
176       {
177         shareClients[j++] = localInfoDescs[i];
178       }
179     }
180
181     Arrays.sort(shareClients);
182     
183     LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Bundles in Share Client Mode:", "Choose Share Client to Install", shareClients, null, null, false, true);
184     if (result != null) bundleNameTextField.setText(result.bundleName);
185     
186   }//GEN-LAST:event_chooseShareClientButtonActionPerformed
187

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

208   private void installButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_installButtonActionPerformed
209
{//GEN-HEADEREND:event_installButtonActionPerformed
210
String JavaDoc bundleName = bundleNameTextField.getText();
211     boolean reinstall = reinstallCheckBox.isSelected();
212
213     BundleInfo bundleInfo = new BundleInfo();
214     try
215     {
216       bundleInfo.fromBundleName(bundleName);
217     }
218     catch (BundleInfo.InvalidBundleNameException e)
219     {
220       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
221       return;
222     }
223     
224     try
225     {
226       admin.installBundle(bundleName, reinstall);
227     }
228     catch (RemoteException JavaDoc e)
229     {
230       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
231       dispose();
232       return;
233     }
234     catch (RMIAdminException e)
235     {
236       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
237       dispose();
238       return;
239     }
240     
241     JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully installed");
242     
243     isOK = true;
244     dispose();
245   }//GEN-LAST:event_installButtonActionPerformed
246

247   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
248
{//GEN-HEADEREND:event_cancelButtonActionPerformed
249
dispose();
250   }//GEN-LAST:event_cancelButtonActionPerformed
251

252   
253   // Variables declaration - do not modify//GEN-BEGIN:variables
254
private javax.swing.JLabel JavaDoc bundleNameLabel;
255   private javax.swing.JTextField JavaDoc bundleNameTextField;
256   private javax.swing.JButton JavaDoc cancelButton;
257   private javax.swing.JButton JavaDoc chooseBinaryBundleButton;
258   private javax.swing.JButton JavaDoc chooseShareClientButton;
259   private javax.swing.JButton JavaDoc installButton;
260   private javax.swing.JPanel JavaDoc jPanel1;
261   private javax.swing.JPanel JavaDoc jPanel2;
262   private javax.swing.JPanel JavaDoc jPanel3;
263   private javax.swing.JPanel JavaDoc jPanel4;
264   private javax.swing.JPanel JavaDoc jPanel5;
265   private javax.swing.JCheckBox JavaDoc reinstallCheckBox;
266   // End of variables declaration//GEN-END:variables
267

268 }
269
Popular Tags