1 6 7 package SOFA.SOFAnet.Browser; 8 9 import SOFA.SOFAnet.Admin.RMI.*; 10 import SOFA.SOFAnet.Repository.BundleInfo; 11 import SOFA.SOFAnet.Repository.Licence; 12 import SOFA.SOFAnet.Repository.NodeNameFilter; 13 import SOFA.SOFAnet.Repository.ShareGroups; 14 import javax.swing.*; 15 import java.rmi.RemoteException ; 16 import java.util.*; 17 import java.awt.Component ; 18 import java.awt.Frame ; 19 20 24 public class ShareBundleDialog extends javax.swing.JDialog 25 { 26 private RMIAdminInterface admin; 27 private NodeNameFilter nodeFilter; 28 private ShareGroups shareGroups; 29 private boolean isOK; 30 31 public static boolean showDialog(Component frameComp, RMIAdminInterface admin, String defaultBundleName) 32 { 33 Frame frame = JOptionPane.getFrameForComponent(frameComp); 34 ShareBundleDialog dialog = new ShareBundleDialog(frame, true, admin, defaultBundleName); 35 dialog.setLocationRelativeTo(frameComp); 36 dialog.setVisible(true); 37 return dialog.isOK(); 38 } 39 40 41 public ShareBundleDialog(java.awt.Frame parent, boolean modal, RMIAdminInterface admin, String defaultBundleName) 42 { 43 super(parent, modal); 44 this.admin = admin; 45 isOK = false; 46 nodeFilter = new NodeNameFilter(); 47 shareGroups = new ShareGroups(); 48 initComponents(); 49 50 bundleNameTextField.setText(defaultBundleName); 51 } 52 53 public boolean isOK() 54 { 55 return isOK; 56 } 57 58 63 private void initComponents() { 65 jPanel4 = new javax.swing.JPanel (); 66 jPanel1 = new javax.swing.JPanel (); 67 jPanel5 = new javax.swing.JPanel (); 68 bundleNameLabel = new javax.swing.JLabel (); 69 bundleNameTextField = new javax.swing.JTextField (); 70 numberOfLicencesLabel = new javax.swing.JLabel (); 71 numberOfLicencesTextField = new javax.swing.JTextField (); 72 jPanel6 = new javax.swing.JPanel (); 73 nodeFilterCheckBox = new javax.swing.JCheckBox (); 74 nodeFilterButton = new javax.swing.JButton (); 75 jPanel7 = new javax.swing.JPanel (); 76 shareGroupsCheckBox = new javax.swing.JCheckBox (); 77 shareGroupsButton = new javax.swing.JButton (); 78 equalityCheckBox = new javax.swing.JCheckBox (); 79 reshareCheckBox = new javax.swing.JCheckBox (); 80 jPanel2 = new javax.swing.JPanel (); 81 chooseBinaryBundleButton = new javax.swing.JButton (); 82 chooseInstalledBundleButton = new javax.swing.JButton (); 83 showLicenceButton = new javax.swing.JButton (); 84 jPanel3 = new javax.swing.JPanel (); 85 shareButton = new javax.swing.JButton (); 86 cancelButton = new javax.swing.JButton (); 87 88 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 89 setTitle("Share Bundle"); 90 jPanel4.setLayout(new java.awt.BorderLayout ()); 91 92 jPanel4.setMinimumSize(new java.awt.Dimension (400, 93)); 93 jPanel4.setPreferredSize(new java.awt.Dimension (600, 280)); 94 jPanel1.setLayout(new java.awt.BorderLayout ()); 95 96 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (1, 10, 1, 10))); 97 jPanel1.setMinimumSize(new java.awt.Dimension (26, 23)); 98 jPanel1.setPreferredSize(new java.awt.Dimension (26, 23)); 99 jPanel5.setLayout(new java.awt.GridLayout (8, 0)); 100 101 bundleNameLabel.setText("Bundle Name:"); 102 jPanel5.add(bundleNameLabel); 103 104 bundleNameTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 105 bundleNameTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 106 jPanel5.add(bundleNameTextField); 107 108 numberOfLicencesLabel.setText("Number of Licences (use '*' or 'all' or leave empty for ''all'/'no licences'):"); 109 jPanel5.add(numberOfLicencesLabel); 110 111 numberOfLicencesTextField.setMinimumSize(new java.awt.Dimension (200, 21)); 112 numberOfLicencesTextField.setPreferredSize(new java.awt.Dimension (200, 21)); 113 jPanel5.add(numberOfLicencesTextField); 114 115 jPanel6.setLayout(new javax.swing.BoxLayout (jPanel6, javax.swing.BoxLayout.X_AXIS)); 116 117 nodeFilterCheckBox.setText("Node Filter"); 118 nodeFilterCheckBox.addActionListener(new java.awt.event.ActionListener () 119 { 120 public void actionPerformed(java.awt.event.ActionEvent evt) 121 { 122 nodeFilterCheckBoxActionPerformed(evt); 123 } 124 }); 125 126 jPanel6.add(nodeFilterCheckBox); 127 128 nodeFilterButton.setText("Edit Node Filter"); 129 nodeFilterButton.setEnabled(false); 130 nodeFilterButton.addActionListener(new java.awt.event.ActionListener () 131 { 132 public void actionPerformed(java.awt.event.ActionEvent evt) 133 { 134 nodeFilterButtonActionPerformed(evt); 135 } 136 }); 137 138 jPanel6.add(nodeFilterButton); 139 140 jPanel5.add(jPanel6); 141 142 jPanel7.setLayout(new javax.swing.BoxLayout (jPanel7, javax.swing.BoxLayout.X_AXIS)); 143 144 shareGroupsCheckBox.setText("Share Groups"); 145 shareGroupsCheckBox.addActionListener(new java.awt.event.ActionListener () 146 { 147 public void actionPerformed(java.awt.event.ActionEvent evt) 148 { 149 shareGroupsCheckBoxActionPerformed(evt); 150 } 151 }); 152 153 jPanel7.add(shareGroupsCheckBox); 154 155 shareGroupsButton.setText("Edit Share Groups"); 156 shareGroupsButton.setEnabled(false); 157 shareGroupsButton.addActionListener(new java.awt.event.ActionListener () 158 { 159 public void actionPerformed(java.awt.event.ActionEvent evt) 160 { 161 shareGroupsButtonActionPerformed(evt); 162 } 163 }); 164 165 jPanel7.add(shareGroupsButton); 166 167 jPanel5.add(jPanel7); 168 169 equalityCheckBox.setSelected(true); 170 equalityCheckBox.setText("Equality of Manager and Clients"); 171 jPanel5.add(equalityCheckBox); 172 173 reshareCheckBox.setText("Reshare"); 174 jPanel5.add(reshareCheckBox); 175 176 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 177 178 jPanel4.add(jPanel1, java.awt.BorderLayout.CENTER); 179 180 chooseBinaryBundleButton.setText("Choose Binary Bundle"); 181 chooseBinaryBundleButton.addActionListener(new java.awt.event.ActionListener () 182 { 183 public void actionPerformed(java.awt.event.ActionEvent evt) 184 { 185 chooseBinaryBundleButtonActionPerformed(evt); 186 } 187 }); 188 189 jPanel2.add(chooseBinaryBundleButton); 190 191 chooseInstalledBundleButton.setText("Choose Installed Bundle"); 192 chooseInstalledBundleButton.addActionListener(new java.awt.event.ActionListener () 193 { 194 public void actionPerformed(java.awt.event.ActionEvent evt) 195 { 196 chooseInstalledBundleButtonActionPerformed(evt); 197 } 198 }); 199 200 jPanel2.add(chooseInstalledBundleButton); 201 202 showLicenceButton.setText("Show Licence of Selected Bundle"); 203 showLicenceButton.addActionListener(new java.awt.event.ActionListener () 204 { 205 public void actionPerformed(java.awt.event.ActionEvent evt) 206 { 207 showLicenceButtonActionPerformed(evt); 208 } 209 }); 210 211 jPanel2.add(showLicenceButton); 212 213 jPanel4.add(jPanel2, java.awt.BorderLayout.NORTH); 214 215 shareButton.setText("Share Bundle"); 216 shareButton.addActionListener(new java.awt.event.ActionListener () 217 { 218 public void actionPerformed(java.awt.event.ActionEvent evt) 219 { 220 shareButtonActionPerformed(evt); 221 } 222 }); 223 224 jPanel3.add(shareButton); 225 226 cancelButton.setText("Cancel"); 227 cancelButton.addActionListener(new java.awt.event.ActionListener () 228 { 229 public void actionPerformed(java.awt.event.ActionEvent evt) 230 { 231 cancelButtonActionPerformed(evt); 232 } 233 }); 234 235 jPanel3.add(cancelButton); 236 237 jPanel4.add(jPanel3, java.awt.BorderLayout.SOUTH); 238 239 getContentPane().add(jPanel4, java.awt.BorderLayout.CENTER); 240 241 pack(); 242 } 244 private void shareGroupsButtonActionPerformed(java.awt.event.ActionEvent evt) { StringListEditDialog.showDialog(this, shareGroups.getList(), "Share Group", "Share Groups Editor"); 247 } 249 private void nodeFilterButtonActionPerformed(java.awt.event.ActionEvent evt) { StringListEditDialog.showDialog(this, nodeFilter.getPatterns(), "Node Name Pattern", "Node Filter Editor"); 252 } 254 private void shareGroupsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { shareGroupsButton.setEnabled(shareGroupsCheckBox.isSelected()); 257 } 259 private void nodeFilterCheckBoxActionPerformed(java.awt.event.ActionEvent evt) { nodeFilterButton.setEnabled(nodeFilterCheckBox.isSelected()); 262 } 264 private void showLicenceButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 267 268 BundleInfo bundleInfo = new BundleInfo(); 269 try 270 { 271 bundleInfo.fromBundleName(bundleName); 272 } 273 catch (BundleInfo.InvalidBundleNameException e) 274 { 275 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 276 return; 277 } 278 279 Licence licence = null; 280 try 281 { 282 licence = admin.getLicence(bundleName); 283 } 284 catch (RemoteException e) 285 { 286 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 287 return; 288 } 289 290 if (licence != null) 291 { 292 LicenceEditDialog.showDialog(this, licence, false, "Licence File of '" + bundleName + "'"); 293 } 294 else 295 { 296 JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' is not limited by licence", "No Licence File Present", JOptionPane.INFORMATION_MESSAGE); 297 } 298 } 300 private void chooseInstalledBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { LocalInfoDesc[] localInfoDescs = null; 303 try 304 { 305 localInfoDescs = admin.localInfoDescsList(); 306 } 307 catch (RemoteException e) 308 { 309 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 310 return; 311 } 312 313 int size = 0; 314 int i; 315 for (i = 0; i < localInfoDescs.length; i++) 316 { 317 if (localInfoDescs[i].isInstalled()) size++; 318 } 319 320 LocalInfoDesc[] installed = new LocalInfoDesc[size]; 321 int j = 0; 322 for (i = 0; i < localInfoDescs.length; i++) 323 { 324 if (localInfoDescs[i].isInstalled()) 325 { 326 installed[j++] = localInfoDescs[i]; 327 } 328 } 329 330 Arrays.sort(installed); 331 332 LocalInfoDesc result = (LocalInfoDesc)ListDialog.showDialog(this, this, "Installed Bundles:", "Choose Installed Bundle to Share", installed, null, null, false, true); 333 if (result != null) bundleNameTextField.setText(result.bundleName); 334 } 336 private void chooseBinaryBundleButtonActionPerformed(java.awt.event.ActionEvent evt) { String [] bundles = null; 339 try 340 { 341 bundles = admin.binBundlesList(); 342 } 343 catch (RemoteException e) 344 { 345 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 346 return; 347 } 348 349 Arrays.sort(bundles); 350 351 String result = ListDialog.showDialog(this, this, "Binary Bundles:", "Choose Binary Bundle to Install", bundles, null, null, false, true); 352 if (result.length() != 0) bundleNameTextField.setText(result); 353 354 } 356 private void shareButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = bundleNameTextField.getText(); 359 String numberOfLicencesText = numberOfLicencesTextField.getText().trim().toLowerCase(); 360 boolean equality = equalityCheckBox.isSelected(); 361 boolean reshare = reshareCheckBox.isSelected(); 362 363 BundleInfo bundleInfo = new BundleInfo(); 364 try 365 { 366 bundleInfo.fromBundleName(bundleName); 367 } 368 catch (BundleInfo.InvalidBundleNameException e) 369 { 370 JOptionPane.showMessageDialog(this, "Invalid name of bundle:\n" + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 371 return; 372 } 373 374 int numberOfLicences = Licence.ALL_LICENCES; 375 if (numberOfLicencesText.length() != 0 && numberOfLicencesText.compareTo("*") != 0 && numberOfLicencesText.compareTo("all") != 0) 376 { 377 try 378 { 379 numberOfLicences = Integer.parseInt(numberOfLicencesText); 380 if (numberOfLicences < 0) throw new NumberFormatException ("Negative 'Number of Licences' is not allowed"); 381 } 382 catch (NumberFormatException e) 383 { 384 JOptionPane.showMessageDialog(this, "Error occured while parsing 'Number of Licences':\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 385 return; 386 } 387 } 388 389 if (!nodeFilterCheckBox.isSelected()) nodeFilter = null; 390 if (!shareGroupsCheckBox.isSelected()) shareGroups = null; 391 392 try 393 { 394 admin.shareBundle(bundleName, numberOfLicences, shareGroups, nodeFilter, equality, reshare); 395 } 396 catch (RemoteException e) 397 { 398 JOptionPane.showMessageDialog(this, e, "Error", JOptionPane.ERROR_MESSAGE); 399 dispose(); 400 return; 401 } 402 catch (RMIAdminException e) 403 { 404 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 405 dispose(); 406 return; 407 } 408 409 JOptionPane.showMessageDialog(this, "Bundle '" + bundleName + "' successfully shared"); 410 411 isOK = true; 412 dispose(); 413 } 415 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) { dispose(); 418 } 420 421 private javax.swing.JLabel bundleNameLabel; 423 private javax.swing.JTextField bundleNameTextField; 424 private javax.swing.JButton cancelButton; 425 private javax.swing.JButton chooseBinaryBundleButton; 426 private javax.swing.JButton chooseInstalledBundleButton; 427 private javax.swing.JCheckBox equalityCheckBox; 428 private javax.swing.JPanel jPanel1; 429 private javax.swing.JPanel jPanel2; 430 private javax.swing.JPanel jPanel3; 431 private javax.swing.JPanel jPanel4; 432 private javax.swing.JPanel jPanel5; 433 private javax.swing.JPanel jPanel6; 434 private javax.swing.JPanel jPanel7; 435 private javax.swing.JButton nodeFilterButton; 436 private javax.swing.JCheckBox nodeFilterCheckBox; 437 private javax.swing.JLabel numberOfLicencesLabel; 438 private javax.swing.JTextField numberOfLicencesTextField; 439 private javax.swing.JCheckBox reshareCheckBox; 440 private javax.swing.JButton shareButton; 441 private javax.swing.JButton shareGroupsButton; 442 private javax.swing.JCheckBox shareGroupsCheckBox; 443 private javax.swing.JButton showLicenceButton; 444 446 } 447 | Popular Tags |