1 6 7 package SOFA.SOFAnet.Browser; 8 9 import javax.swing.*; 10 import SOFA.SOFAnet.Admin.RMI.*; 11 import SOFA.SOFAnet.Repository.Licence; 12 import java.rmi.RemoteException ; 13 import java.util.SortedSet ; 14 import java.util.TreeSet ; 15 import java.util.Iterator ; 16 17 21 public class BinBundlesAndLicencesPanel extends javax.swing.JPanel 22 { 23 private RMIAdminInterface admin; 24 private DefaultListModel content; 25 26 private class BundleLic implements Comparable 27 { 28 public String bundleName; 29 public boolean isBinBundle; 30 public boolean isLicence; 31 32 BundleLic(String bundleName, boolean isBinBundle, boolean isLicence) 33 { 34 this.bundleName = bundleName; 35 this.isBinBundle = isBinBundle; 36 this.isLicence = isLicence; 37 } 38 39 public boolean equals(Object o) 40 { 41 if (this == o) return true; 42 if (o instanceof BundleLic) 43 { 44 BundleLic bundleLic = (BundleLic)o; 45 return bundleName.compareTo(bundleLic.bundleName) == 0; 46 } 47 else return false; 48 } 49 50 public int compareTo(Object o) 51 { 52 BundleLic bundleLic = (BundleLic)o; 53 return bundleName.compareTo(bundleLic.bundleName); 54 } 55 56 public String toString() 57 { 58 if (isBinBundle) 59 { 60 if (isLicence) return bundleName + " (with licence)"; 61 else return bundleName; 62 } 63 else 64 { 65 if (isLicence) return bundleName + " (LICENCE ONLY!)"; 66 else return "error"; 67 } 68 } 69 } 70 71 public BinBundlesAndLicencesPanel(RMIAdminInterface admin) 72 { 73 this.admin = admin; 74 content = new DefaultListModel(); 75 initComponents(); 77 } 78 79 private void reload() 80 { 81 content.clear(); 82 83 String [] bundles = null; 84 String [] licences = null; 85 try 86 { 87 bundles = admin.binBundlesList(); 88 licences = admin.licencesList(); 89 } 90 97 catch (RemoteException e) 98 { 99 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 100 return; 101 } 102 103 SortedSet ss = new TreeSet (); 104 int i; 105 BundleLic tmpBundleLic = new BundleLic("", false, false); 106 for (i = 0; i < bundles.length; i++) ss.add(new BundleLic(bundles[i], true, false)); 107 for (i = 0; i < licences.length; i++) 108 { 109 tmpBundleLic.bundleName = licences[i]; 110 if (ss.contains(tmpBundleLic)) 111 { 112 Iterator it = ss.iterator(); 113 while (it.hasNext()) 114 { 115 BundleLic bundleLic = (BundleLic)it.next(); 116 if (bundleLic.equals(tmpBundleLic)) 117 { 118 bundleLic.isLicence = true; 119 break; 120 } 121 } 122 } 123 else ss.add(new BundleLic(tmpBundleLic.bundleName, false, true)); 124 } 125 126 content.ensureCapacity(ss.size()); 127 128 Iterator it = ss.iterator(); 129 while (it.hasNext()) content.addElement(it.next()); 130 } 131 132 private String getSelectedBundleName() 133 { 134 String bundleName = ""; 135 136 int index = contentList.getSelectedIndex(); 137 if (index != -1) bundleName = ((BundleLic)content.getElementAt(index)).bundleName; 138 return bundleName; 139 } 140 141 146 private void initComponents() { 148 jPanel3 = new javax.swing.JPanel (); 149 binBundleCheckBox = new javax.swing.JCheckBox (); 150 licenceCheckBox = new javax.swing.JCheckBox (); 151 jPanel2 = new javax.swing.JPanel (); 152 jPanel4 = new javax.swing.JPanel (); 153 installButton = new javax.swing.JButton (); 154 shareButton = new javax.swing.JButton (); 155 deleteButton = new javax.swing.JButton (); 156 deleteBinaryButton = new javax.swing.JButton (); 157 createOfferButton = new javax.swing.JButton (); 158 testPushButton = new javax.swing.JButton (); 159 pushButton = new javax.swing.JButton (); 160 showLicenceButton = new javax.swing.JButton (); 161 editLicenceButton = new javax.swing.JButton (); 162 deleteLicenceButton = new javax.swing.JButton (); 163 jPanel1 = new javax.swing.JPanel (); 164 jPanel5 = new javax.swing.JPanel (); 165 refreshButton = new javax.swing.JButton (); 166 testPullButton = new javax.swing.JButton (); 167 pullButton = new javax.swing.JButton (); 168 jScrollPane1 = new javax.swing.JScrollPane (); 169 contentList = new javax.swing.JList (); 170 171 setLayout(new java.awt.BorderLayout ()); 172 173 addComponentListener(new java.awt.event.ComponentAdapter () 174 { 175 public void componentShown(java.awt.event.ComponentEvent evt) 176 { 177 formComponentShown(evt); 178 } 179 }); 180 181 jPanel3.setLayout(new java.awt.GridLayout (1, 0)); 182 183 jPanel3.setBorder(new javax.swing.border.TitledBorder ("Bundle & Licence Info")); 184 binBundleCheckBox.setText("Binary Bundle"); 185 binBundleCheckBox.setBorderPaintedFlat(true); 186 binBundleCheckBox.addActionListener(new java.awt.event.ActionListener () 187 { 188 public void actionPerformed(java.awt.event.ActionEvent evt) 189 { 190 CheckBoxNoChangeAction(evt); 191 } 192 }); 193 194 jPanel3.add(binBundleCheckBox); 195 196 licenceCheckBox.setText("Licence"); 197 licenceCheckBox.setBorderPaintedFlat(true); 198 licenceCheckBox.addActionListener(new java.awt.event.ActionListener () 199 { 200 public void actionPerformed(java.awt.event.ActionEvent evt) 201 { 202 CheckBoxNoChangeAction(evt); 203 } 204 }); 205 206 jPanel3.add(licenceCheckBox); 207 208 add(jPanel3, java.awt.BorderLayout.SOUTH); 209 210 jPanel2.setLayout(new java.awt.BorderLayout ()); 211 212 jPanel2.setPreferredSize(new java.awt.Dimension (200, 379)); 213 jPanel4.setLayout(new java.awt.GridLayout (10, 0)); 214 215 jPanel4.setBorder(new javax.swing.border.TitledBorder ("Bundle Specific")); 216 installButton.setText("Install Bundle"); 217 installButton.addActionListener(new java.awt.event.ActionListener () 218 { 219 public void actionPerformed(java.awt.event.ActionEvent evt) 220 { 221 installButtonActionPerformed(evt); 222 } 223 }); 224 225 jPanel4.add(installButton); 226 227 shareButton.setText("Share Bundle"); 228 shareButton.addActionListener(new java.awt.event.ActionListener () 229 { 230 public void actionPerformed(java.awt.event.ActionEvent evt) 231 { 232 shareButtonActionPerformed(evt); 233 } 234 }); 235 236 jPanel4.add(shareButton); 237 238 deleteButton.setText("Delete Bundle"); 239 deleteButton.addActionListener(new java.awt.event.ActionListener () 240 { 241 public void actionPerformed(java.awt.event.ActionEvent evt) 242 { 243 deleteButtonActionPerformed(evt); 244 } 245 }); 246 247 jPanel4.add(deleteButton); 248 249 deleteBinaryButton.setText("Delete Binary Bundle"); 250 deleteBinaryButton.addActionListener(new java.awt.event.ActionListener () 251 { 252 public void actionPerformed(java.awt.event.ActionEvent evt) 253 { 254 deleteBinaryButtonActionPerformed(evt); 255 } 256 }); 257 258 jPanel4.add(deleteBinaryButton); 259 260 createOfferButton.setText("Create Bundle Offer"); 261 createOfferButton.addActionListener(new java.awt.event.ActionListener () 262 { 263 public void actionPerformed(java.awt.event.ActionEvent evt) 264 { 265 createOfferButtonActionPerformed(evt); 266 } 267 }); 268 269 jPanel4.add(createOfferButton); 270 271 testPushButton.setText("Test Push Bundle"); 272 testPushButton.addActionListener(new java.awt.event.ActionListener () 273 { 274 public void actionPerformed(java.awt.event.ActionEvent evt) 275 { 276 testPushButtonActionPerformed(evt); 277 } 278 }); 279 280 jPanel4.add(testPushButton); 281 282 pushButton.setText("Push Bundle"); 283 pushButton.addActionListener(new java.awt.event.ActionListener () 284 { 285 public void actionPerformed(java.awt.event.ActionEvent evt) 286 { 287 pushButtonActionPerformed(evt); 288 } 289 }); 290 291 jPanel4.add(pushButton); 292 293 showLicenceButton.setText("Show Licence"); 294 showLicenceButton.addActionListener(new java.awt.event.ActionListener () 295 { 296 public void actionPerformed(java.awt.event.ActionEvent evt) 297 { 298 showLicenceButtonActionPerformed(evt); 299 } 300 }); 301 302 jPanel4.add(showLicenceButton); 303 304 editLicenceButton.setText("Edit Licence (HACK!)"); 305 editLicenceButton.addActionListener(new java.awt.event.ActionListener () 306 { 307 public void actionPerformed(java.awt.event.ActionEvent evt) 308 { 309 editLicenceButtonActionPerformed(evt); 310 } 311 }); 312 313 jPanel4.add(editLicenceButton); 314 315 deleteLicenceButton.setText("Delete Licence (HACK!)"); 316 deleteLicenceButton.addActionListener(new java.awt.event.ActionListener () 317 { 318 public void actionPerformed(java.awt.event.ActionEvent evt) 319 { 320 deleteLicenceButtonActionPerformed(evt); 321 } 322 }); 323 324 jPanel4.add(deleteLicenceButton); 325 326 jPanel2.add(jPanel4, java.awt.BorderLayout.NORTH); 327 328 jPanel1.setLayout(new java.awt.BorderLayout ()); 329 330 jPanel1.setBorder(new javax.swing.border.TitledBorder ("General")); 331 jPanel5.setLayout(new java.awt.GridLayout (3, 0)); 332 333 refreshButton.setText("Refresh"); 334 refreshButton.addActionListener(new java.awt.event.ActionListener () 335 { 336 public void actionPerformed(java.awt.event.ActionEvent evt) 337 { 338 refreshButtonActionPerformed(evt); 339 } 340 }); 341 342 jPanel5.add(refreshButton); 343 344 testPullButton.setText("Test Pull Bundle"); 345 testPullButton.addActionListener(new java.awt.event.ActionListener () 346 { 347 public void actionPerformed(java.awt.event.ActionEvent evt) 348 { 349 testPullButtonActionPerformed(evt); 350 } 351 }); 352 353 jPanel5.add(testPullButton); 354 355 pullButton.setText("Pull Bundle"); 356 pullButton.addActionListener(new java.awt.event.ActionListener () 357 { 358 public void actionPerformed(java.awt.event.ActionEvent evt) 359 { 360 pullButtonActionPerformed(evt); 361 } 362 }); 363 364 jPanel5.add(pullButton); 365 366 jPanel1.add(jPanel5, java.awt.BorderLayout.NORTH); 367 368 jPanel2.add(jPanel1, java.awt.BorderLayout.CENTER); 369 370 add(jPanel2, java.awt.BorderLayout.EAST); 371 372 contentList.setModel(content); 373 contentList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 374 contentList.setVisibleRowCount(-1); 375 contentList.addListSelectionListener(new javax.swing.event.ListSelectionListener () 376 { 377 public void valueChanged(javax.swing.event.ListSelectionEvent evt) 378 { 379 contentListValueChanged(evt); 380 } 381 }); 382 contentList.addMouseListener(new java.awt.event.MouseAdapter () 383 { 384 public void mouseClicked(java.awt.event.MouseEvent evt) 385 { 386 contentListMouseClicked(evt); 387 } 388 }); 389 390 jScrollPane1.setViewportView(contentList); 391 392 add(jScrollPane1, java.awt.BorderLayout.CENTER); 393 394 } 396 private void contentListMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2) 399 { 400 showLicenceButton.doClick(); } 402 } 404 private void testPullButtonActionPerformed(java.awt.event.ActionEvent evt) { TestPullBundleDialog.showDialog(this, admin, ""); 407 } 409 private void pullButtonActionPerformed(java.awt.event.ActionEvent evt) { if (PullBundleDialog.showDialog(this, admin, "")) reload(); 412 } 414 private void deleteLicenceButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = getSelectedBundleName(); 417 418 if (bundleName.length() == 0) 419 { 420 JOptionPane.showMessageDialog(this, "No bundle selected", "Warning", JOptionPane.WARNING_MESSAGE); 421 return; 422 } 423 else 424 { 425 if (JOptionPane.showConfirmDialog(this, "Do you really want to delete Licence File for bundle '" + bundleName + "'?") != JOptionPane.YES_OPTION) return; 426 } 427 428 Licence licence = null; 429 try 430 { 431 licence = admin.getLicence(bundleName); 432 } 433 catch (RemoteException e) 434 { 435 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 436 return; 437 } 438 439 if (licence == null) 440 { 441 JOptionPane.showMessageDialog(this, "No Licence File present for bundle '" + bundleName + "'"); 442 return; 443 } 444 445 try 446 { 447 admin.updateLicence(bundleName, null); 448 } 449 catch (RemoteException e) 450 { 451 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 452 return; 453 } 454 catch (RMIAdminException e) 455 { 456 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 457 return; 458 } 459 460 reload(); 461 } 463 private void editLicenceButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = getSelectedBundleName(); 466 467 if (bundleName.length() == 0) 468 { 469 JOptionPane.showMessageDialog(this, "No bundle selected", "Warning", JOptionPane.WARNING_MESSAGE); 470 return; 471 } 472 473 Licence licence = null; 474 try 475 { 476 licence = admin.getLicence(bundleName); 477 } 478 catch (RemoteException e) 479 { 480 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 481 return; 482 } 483 484 if (licence == null) 485 { 486 if (JOptionPane.showConfirmDialog(this, "No Licence File present for bundle '" + bundleName + "'\nDo you want to create licence file?") != JOptionPane.YES_OPTION) return; 487 licence = new Licence(); 488 } 489 else 490 { 491 if (JOptionPane.showConfirmDialog(this, "Do you really want to edit Licence File for bundle '" + bundleName + "'?") != JOptionPane.YES_OPTION) return; 492 } 493 494 if (LicenceEditDialog.showDialog(this, licence, true, "Licence File of '" + bundleName + "'")) 495 { 496 try 497 { 498 admin.updateLicence(bundleName, licence); 499 } 500 catch (RemoteException e) 501 { 502 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 503 return; 504 } 505 catch (RMIAdminException e) 506 { 507 JOptionPane.showMessageDialog(this, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); 508 return; 509 } 510 511 reload(); 512 } 513 514 } 516 private void showLicenceButtonActionPerformed(java.awt.event.ActionEvent evt) { String bundleName = getSelectedBundleName(); 519 520 if (bundleName.length() == 0) 521 { 522 JOptionPane.showMessageDialog(this, "No bundle selected", "Warning", JOptionPane.WARNING_MESSAGE); 523 return; 524 } 525 526 Licence licence = null; 527 try 528 { 529 licence = admin.getLicence(bundleName); 530 } 531 catch (RemoteException e) 532 { 533 JOptionPane.showMessageDialog(this, "RMI Error occured while accessing SOFA net node:\n" + e, "Error", JOptionPane.ERROR_MESSAGE); 534 return; 535 } 536 537 if (licence != null) 538 { 539 LicenceEditDialog.showDialog(this, licence, false, "Licence File of '" + bundleName + "'"); 540 } 541 else 542 { 543 JOptionPane.showMessageDialog(this, "No Licence File present for bundle '" + bundleName + "'", "No Licence File Present", JOptionPane.INFORMATION_MESSAGE); 544 } 545 } 547 private void pushButtonActionPerformed(java.awt.event.ActionEvent evt) { PushBundleDialog.showDialog(this, admin, getSelectedBundleName()); 550 } 552 private void testPushButtonActionPerformed(java.awt.event.ActionEvent evt) { TestPushBundleDialog.showDialog(this, admin, getSelectedBundleName()); 555 } 557 private void createOfferButtonActionPerformed(java.awt.event.ActionEvent evt) { CreateBundleOfferDialog.showDialog(this, admin, getSelectedBundleName()); 560 } 562 private void deleteBinaryButtonActionPerformed(java.awt.event.ActionEvent evt) { if (DeleteBinaryBundleDialog.showDialog(this, admin, getSelectedBundleName())) reload(); 565 } 567 private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) { if (DeleteBundleDialog.showDialog(this, admin, getSelectedBundleName())) reload(); 570 } 572 private void shareButtonActionPerformed(java.awt.event.ActionEvent evt) { ShareBundleDialog.showDialog(this, admin, getSelectedBundleName()); 575 } 577 private void formComponentShown(java.awt.event.ComponentEvent evt) { reload(); 580 } 582 private void installButtonActionPerformed(java.awt.event.ActionEvent evt) { InstallBundleDialog.showDialog(this, admin, getSelectedBundleName()); 585 } 587 private void contentListValueChanged(javax.swing.event.ListSelectionEvent evt) { int index = contentList.getSelectedIndex(); 590 BundleLic bundleLic = null; 591 if (index != -1) bundleLic = (BundleLic)content.getElementAt(index); 592 593 if (bundleLic != null) 594 { 595 binBundleCheckBox.setSelected(bundleLic.isBinBundle); 596 licenceCheckBox.setSelected(bundleLic.isLicence); 597 } 598 else 599 { 600 binBundleCheckBox.setSelected(false); 601 licenceCheckBox.setSelected(false); 602 } 603 } 605 private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) { reload(); 608 } 610 private void CheckBoxNoChangeAction(java.awt.event.ActionEvent evt) { JCheckBox checkBox = (JCheckBox)evt.getSource(); 613 checkBox.setSelected(!checkBox.isSelected()); 614 } 616 617 private javax.swing.JCheckBox binBundleCheckBox; 619 private javax.swing.JList contentList; 620 private javax.swing.JButton createOfferButton; 621 private javax.swing.JButton deleteBinaryButton; 622 private javax.swing.JButton deleteButton; 623 private javax.swing.JButton deleteLicenceButton; 624 private javax.swing.JButton editLicenceButton; 625 private javax.swing.JButton installButton; 626 private javax.swing.JPanel jPanel1; 627 private javax.swing.JPanel jPanel2; 628 private javax.swing.JPanel jPanel3; 629 private javax.swing.JPanel jPanel4; 630 private javax.swing.JPanel jPanel5; 631 private javax.swing.JScrollPane jScrollPane1; 632 private javax.swing.JCheckBox licenceCheckBox; 633 private javax.swing.JButton pullButton; 634 private javax.swing.JButton pushButton; 635 private javax.swing.JButton refreshButton; 636 private javax.swing.JButton shareButton; 637 private javax.swing.JButton showLicenceButton; 638 private javax.swing.JButton testPullButton; 639 private javax.swing.JButton testPushButton; 640 642 } 643 | Popular Tags |