1 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 ; 13 import java.util.*; 14 import java.awt.Component ; 15 import java.awt.Frame ; 16 17 21 public class UninstallBundleDialog extends javax.swing.JDialog 22 { 23 private RMIAdminInterface admin; 24 private boolean isOK; 25 26 public static boolean showDialog(Component frameComp, RMIAdminInterface admin, String defaultBundleName) 27 { 28 Frame 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 36 public UninstallBundleDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String 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 56 private void initComponents() { 58 jPanel4 = new javax.swing.JPanel (); 59 jPanel1 = new javax.swing.JPanel (); 60 jPanel5 = new javax.swing.JPanel (); 61 bundleNameLabel = new javax.swing.JLabel (); 62 bundleNameTextField = new javax.swing.JTextField (); 63 deleteComponentsCheckBox = new javax.swing.JCheckBox (); 64 includingInterfacesCheckBox = new javax.swing.JCheckBox (); 65 forceCheckBox = new javax.swing.JCheckBox (); 66 jPanel2 = new javax.swing.JPanel (); 67 chooseInstalledBundleButton = new javax.swing.JButton (); 68 jPanel3 = new javax.swing.JPanel (); 69 uninstallButton = new javax.swing.JButton (); 70 cancelButton = new javax.swing.JButton (); 71 72 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 73 setTitle("Uninstall Bundle"); 74 jPanel4.setLayout(new java.awt.BorderLayout ()); 75 76 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 77 jPanel4.setPreferredSize(new java.awt.Dimension (400, 190)); 78 jPanel1.setLayout(new java.awt.BorderLayout ()); 79 80 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 81 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 82 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 83 jPanel5.setLayout(new java.awt.GridLayout (5, 0)); 84 85 bundleNameLabel.setText("Bundle Name:"); 86 jPanel5.add(bundleNameLabel); 87 88 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 89 bundleNameTextField.setPreferredSize(new java.awt.Dimension (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 () 95 { 96 public void actionPerformed(java.awt.event.ActionEvent 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 () 116 { 117 public void actionPerformed(java.awt.event.ActionEvent 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 () 129 { 130 public void actionPerformed(java.awt.event.ActionEvent 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 () 140 { 141 public void actionPerformed(java.awt.event.ActionEvent 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 } 156 private void deleteComponentsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { includingInterfacesCheckBox.setEnabled(deleteComponentsCheckBox.isSelected()); 159 } 161 private void chooseInstalledBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { LocalInfoDesc[] localInfoDescs = null; 164 try 165 { 166 localInfoDescs = admin.localInfoDescsList(); 167 } 168 catch (RemoteException 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 } 198 private void uninstallButtonActionPerformed(java.awt.event.ActionEvent evt) { String 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 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 } 239 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 242 } 244 245 private javax.swing.JLabel bundleNameLabel; 247 private javax.swing.JTextField bundleNameTextField; 248 private javax.swing.JButton cancelButton; 249 private javax.swing.JButton chooseInstalledBundleButton; 250 private javax.swing.JCheckBox deleteComponentsCheckBox; 251 private javax.swing.JCheckBox forceCheckBox; 252 private javax.swing.JCheckBox includingInterfacesCheckBox; 253 private javax.swing.JPanel jPanel1; 254 private javax.swing.JPanel jPanel2; 255 private javax.swing.JPanel jPanel3; 256 private javax.swing.JPanel jPanel4; 257 private javax.swing.JPanel jPanel5; 258 private javax.swing.JButton uninstallButton; 259 261 } 262 | Popular Tags |