KickJava   Java API By Example, From Geeks To Geeks.

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


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 UninstallBundleDialog 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     UninstallBundleDialog dialog = new UninstallBundleDialog(frame, true, admin, defaultBundleName);
30     dialog.setLocationRelativeTo(frameComp);
31     dialog.setVisible(true);
32     return dialog.isOK();
33   }
34   
35   /** Creates new form UninstallBundleDialog */
36   public UninstallBundleDialog(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     deleteComponentsCheckBox = new javax.swing.JCheckBox JavaDoc();
64     includingInterfacesCheckBox = new javax.swing.JCheckBox JavaDoc();
65     forceCheckBox = new javax.swing.JCheckBox JavaDoc();
66     jPanel2 = new javax.swing.JPanel JavaDoc();
67     chooseInstalledBundleButton = new javax.swing.JButton JavaDoc();
68     jPanel3 = new javax.swing.JPanel JavaDoc();
69     uninstallButton = new javax.swing.JButton JavaDoc();
70     cancelButton = new javax.swing.JButton JavaDoc();
71
72     setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
73     setTitle("Uninstall Bundle");
74     jPanel4.setLayout(new java.awt.BorderLayout JavaDoc());
75
76     jPanel4.setMinimumSize(new java.awt.Dimension JavaDoc(400, 93));
77     jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(400, 190));
78     jPanel1.setLayout(new java.awt.BorderLayout JavaDoc());
79
80     jPanel1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(1, 10, 1, 10)));
81     jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(26, 23));
82     jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(26, 23));
83     jPanel5.setLayout(new java.awt.GridLayout JavaDoc(5, 0));
84
85     bundleNameLabel.setText("Bundle Name:");
86     jPanel5.add(bundleNameLabel);
87
88     bundleNameTextField.setMinimumSize(new java.awt.Dimension JavaDoc(200, 21));
89     bundleNameTextField.setPreferredSize(new java.awt.Dimension JavaDoc(200, 21));
90     jPanel5.add(bundleNameTextField);
91
92     deleteComponentsCheckBox.setSelected(true);
93     deleteComponentsCheckBox.setText("Delete Components from TR");
94     deleteComponentsCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc()
95     {
96       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
97       {
98         deleteComponentsCheckBoxActionPerformed(evt);
99       }
100     });
101
102     jPanel5.add(deleteComponentsCheckBox);
103
104     includingInterfacesCheckBox.setText("Including Interfaces");
105     jPanel5.add(includingInterfacesCheckBox);
106
107     forceCheckBox.setText("Force");
108     jPanel5.add(forceCheckBox);
109
110     jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH);
111
112     jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER);
113
114     chooseInstalledBundleButton.setText("Choose Installed Bundle");
115     chooseInstalledBundleButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
116     {
117       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
118       {
119         chooseInstalledBundleButtonActionPerformed(evt);
120       }
121     });
122
123     jPanel2.add(chooseInstalledBundleButton);
124
125     jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH);
126
127     uninstallButton.setText("Uninstall Bundle");
128     uninstallButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
129     {
130       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
131       {
132         uninstallButtonActionPerformed(evt);
133       }
134     });
135
136     jPanel3.add(uninstallButton);
137
138     cancelButton.setText("Cancel");
139     cancelButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
140     {
141       public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt)
142       {
143         cancelButtonActionPerformed(evt);
144       }
145     });
146
147     jPanel3.add(cancelButton);
148
149     jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH);
150
151     getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER);
152
153     pack();
154   }//GEN-END:initComponents
155

156   private void deleteComponentsCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_deleteComponentsCheckBoxActionPerformed
157
{//GEN-HEADEREND:event_deleteComponentsCheckBoxActionPerformed
158
includingInterfacesCheckBox.setEnabled(deleteComponentsCheckBox.isSelected());
159   }//GEN-LAST:event_deleteComponentsCheckBoxActionPerformed
160

161   private void chooseInstalledBundleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_chooseInstalledBundleButtonActionPerformed
162
{//GEN-HEADEREND:event_chooseInstalledBundleButtonActionPerformed
163
LocalInfoDesc[] localInfoDescs = null;
164     try
165     {
166       localInfoDescs = admin.localInfoDescsList();
167     }
168     catch (RemoteException JavaDoc e)
169     {
170       JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
171       return;
172     }
173
174     int size = 0;
175     int i;
176     for (i = 0; i < localInfoDescs.length; i++)
177     {
178       if (localInfoDescs[i].isInstalled()) size++;
179     }
180     
181     LocalInfoDesc[] shareClients = new LocalInfoDesc[size];
182     int j = 0;
183     for (i = 0; i < localInfoDescs.length; i++)
184     {
185       if (localInfoDescs[i].isInstalled())
186       {
187         shareClients[j++] = localInfoDescs[i];
188       }
189     }
190
191     Arrays.sort(shareClients);
192     
193     LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Installed Bundles:", "Choose Installed Bundle to Uninstall", shareClients, null, null, false, true);
194     if (result != null) bundleNameTextField.setText(result.bundleName);
195     
196   }//GEN-LAST:event_chooseInstalledBundleButtonActionPerformed
197

198   private void uninstallButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_uninstallButtonActionPerformed
199
{//GEN-HEADEREND:event_uninstallButtonActionPerformed
200
String JavaDoc bundleName = bundleNameTextField.getText();
201     boolean deleteComponents = deleteComponentsCheckBox.isSelected();
202     boolean includingInterfaces = includingInterfacesCheckBox.isSelected();
203     boolean force = forceCheckBox.isSelected();
204
205     BundleInfo bundleInfo = new BundleInfo();
206     try
207     {
208       bundleInfo.fromBundleName(bundleName);
209     }
210     catch (BundleInfo.InvalidBundleNameException e)
211     {
212       JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
213       return;
214     }
215     
216     try
217     {
218       admin.uninstallBundle(bundleName, deleteComponents, includingInterfaces, force);
219     }
220     catch (RemoteException JavaDoc e)
221     {
222       JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE);
223       dispose();
224       return;
225     }
226     catch (RMIAdminException e)
227     {
228       JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
229       dispose();
230       return;
231     }
232     
233     JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully uninstalled");
234     
235     isOK = true;
236     dispose();
237   }//GEN-LAST:event_uninstallButtonActionPerformed
238

239   private void cancelButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt)//GEN-FIRST:event_cancelButtonActionPerformed
240
{//GEN-HEADEREND:event_cancelButtonActionPerformed
241
dispose();
242   }//GEN-LAST:event_cancelButtonActionPerformed
243

244   
245   // Variables declaration - do not modify//GEN-BEGIN:variables
246
private javax.swing.JLabel JavaDoc bundleNameLabel;
247   private javax.swing.JTextField JavaDoc bundleNameTextField;
248   private javax.swing.JButton JavaDoc cancelButton;
249   private javax.swing.JButton JavaDoc chooseInstalledBundleButton;
250   private javax.swing.JCheckBox JavaDoc deleteComponentsCheckBox;
251   private javax.swing.JCheckBox JavaDoc forceCheckBox;
252   private javax.swing.JCheckBox JavaDoc includingInterfacesCheckBox;
253   private javax.swing.JPanel JavaDoc jPanel1;
254   private javax.swing.JPanel JavaDoc jPanel2;
255   private javax.swing.JPanel JavaDoc jPanel3;
256   private javax.swing.JPanel JavaDoc jPanel4;
257   private javax.swing.JPanel JavaDoc jPanel5;
258   private javax.swing.JButton JavaDoc uninstallButton;
259   // End of variables declaration//GEN-END:variables
260

261 }
262
Popular Tags