1 19 20 21 package org.netbeans.modules.autoupdate; 22 23 import java.awt.Font ; 24 import java.awt.event.FocusEvent ; 25 import java.awt.event.FocusListener ; 26 import java.beans.PropertyChangeListener ; 27 import java.beans.PropertyChangeEvent ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.ArrayList ; 32 33 import java.util.Date ; 34 import java.util.HashSet ; 35 import javax.swing.DefaultListModel ; 36 import javax.swing.JComponent ; 37 import javax.swing.SwingUtilities ; 38 import javax.swing.UIManager ; 39 import javax.swing.event.ListSelectionListener ; 40 import javax.swing.text.html.HTMLEditorKit ; 41 import javax.swing.text.html.StyleSheet ; 42 import org.openide.DialogDisplayer; 43 44 import org.openide.NotifyDescriptor; 45 import org.openide.awt.HtmlBrowser; 46 import org.openide.nodes.Children; 47 import org.openide.nodes.Node; 48 import org.openide.explorer.ExplorerManager; 49 import org.openide.explorer.view.BeanTreeView; 50 import org.openide.modules.SpecificationVersion; 51 import org.openide.util.NbBundle; 52 import org.openide.util.RequestProcessor; 53 54 55 class UpdatePanel extends javax.swing.JPanel { 56 57 private static final String EMPTY_STRING = ""; 59 private static final java.awt.Dimension PREFERRED_SIZE = new java.awt.Dimension ( 600, 500 ); 60 61 private static final String SPACE = " "; 63 transient private static final HashSet acceptedLicencies = new HashSet (10); 64 65 66 private ExplorerView explorerView; 67 68 private DefaultListModel selectedListModel; 69 70 private long totalSize; 71 72 private Wizard.Validator validator; 73 74 private UpdateNode.AllServers allNodes; 75 76 private int duplicateStatus = 0; 77 78 private PropertyChangeListener nodeListener; 79 80 static final long serialVersionUID =897622109141801200L; 81 82 static final String LINE_SEPARATOR = "<br>"; 84 88 public UpdatePanel( Wizard.Validator validator ) { 89 putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); putClientProperty("WizardPanel_contentSelectedIndex", new Integer (1)); putClientProperty("WizardPanel_contentData", new String [] { getBundle("WIZ_First"), 95 getBundle("WIZ_Select"), 96 getBundle("WIZ_Download"), 97 getBundle("WIZ_View") 98 }); 99 initComponents(); 100 101 HTMLEditorKit htmlkit = new HTMLEditorKit (); 102 105 110 StyleSheet css = htmlkit.getStyleSheet (); 111 112 if (css.getStyleSheets() == null) { 113 StyleSheet css2 = new StyleSheet (); 114 Font f = jList1.getFont (); 115 int size = jList1.getFont ().getSize (); 116 css2.addRule(new StringBuffer ("body { font-size: ").append(size) .append("; font-family: ").append(f.getName()).append("; }").toString()); css2.addStyleSheet(css); 119 htmlkit.setStyleSheet(css2); 120 } 121 122 this.description.setEditorKit (htmlkit); 123 124 setName(getBundle("LAB_Select2")); 125 126 this.validator = validator; 127 128 explorerView = new ExplorerView(); 130 explorerView.getExplorerManager().addPropertyChangeListener( 131 new PropertyChangeListener () { 132 public void propertyChange( PropertyChangeEvent evt ) { 133 if ( evt.getPropertyName() == ExplorerManager.PROP_SELECTED_NODES ) { 134 selectionChange( true ); 135 } 136 } 137 } ); 138 139 jList1.addFocusListener( 140 new FocusListener () { 141 public void focusGained( FocusEvent evt ) { 142 unselectLeft(); 143 if ( jList1.getSelectedIndex() == -1 && selectedListModel.getSize() > 0 ) 144 jList1.setSelectedIndex( 0 ); 145 } 146 147 public void focusLost( FocusEvent evt ) { 148 } 149 } ); 150 151 java.awt.GridBagConstraints gridBagConstraints1 = new java.awt.GridBagConstraints (); 152 gridBagConstraints1.gridwidth = 0; 153 gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; 154 gridBagConstraints1.weightx = 1.0; 155 gridBagConstraints1.weighty = 1.0; 156 gridBagConstraints1.insets = new java.awt.Insets (0, 3, 0, 3); 157 jPanel1.add (explorerView, gridBagConstraints1); 158 159 161 jList1.setCellRenderer( new SelectedListCellRenderer() ); 162 selectedListModel = new DefaultListModel (); 163 jList1.setModel( selectedListModel ); 164 jList1.getSelectionModel().setSelectionMode( javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); 165 jList1.getSelectionModel().addListSelectionListener( 166 new ListSelectionListener () { 167 public void valueChanged( javax.swing.event.ListSelectionEvent evt ) { 168 selectionChange( false ); 169 } 170 } 171 ); 172 173 panel1Label.setLabelFor(explorerView); 174 175 getAccessibleContext().setAccessibleName(getBundle("ACS_UpdatePanel")); 176 getAccessibleContext().setAccessibleDescription(getBundle("ACSD_UpdatePanel") + getBundle("LAB_227")); 177 moreButton.getAccessibleContext().setAccessibleDescription(getBundle("ACS_More")); 178 jList1.getAccessibleContext().setAccessibleDescription(getBundle("ACS_InstallList")); 179 explorerView.setName (getBundle ("ACSN_ExplorerView")); 180 } 181 182 183 public java.awt.Dimension getPreferredSize() { 184 return PREFERRED_SIZE; 185 } 186 187 192 private void initComponents() { 194 java.awt.GridBagConstraints gridBagConstraints; 195 196 panel1Label = new javax.swing.JLabel (); 197 jPanel1 = new javax.swing.JPanel (); 198 addButton = new javax.swing.JButton (); 199 removeButton = new javax.swing.JButton (); 200 addallButton = new javax.swing.JButton (); 201 removeallButton = new javax.swing.JButton (); 202 scrollpaneLabel = new javax.swing.JLabel (); 203 jScrollPane1 = new javax.swing.JScrollPane (); 204 jList1 = new javax.swing.JList (); 205 jPanel3 = new javax.swing.JPanel (); 206 totalsizeLabel = new javax.swing.JLabel (); 207 totalsizeTextField = new javax.swing.JTextField (); 208 jPanel2 = new javax.swing.JPanel (); 209 avLabel = new javax.swing.JLabel (); 210 avTextField = new javax.swing.JTextField (); 211 ivLabel = new javax.swing.JLabel (); 212 ivTextField = new javax.swing.JTextField (); 213 jScrollPane2 = new javax.swing.JScrollPane (); 214 description = new javax.swing.JEditorPane (); 215 moreButton = new javax.swing.JButton (); 216 217 setLayout(new java.awt.GridBagLayout ()); 218 219 org.openide.awt.Mnemonics.setLocalizedText(panel1Label, getBundle("LAB_221")); gridBagConstraints = new java.awt.GridBagConstraints (); 221 gridBagConstraints.gridx = 0; 222 gridBagConstraints.gridy = 0; 223 gridBagConstraints.gridwidth = 2; 224 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 225 add(panel1Label, gridBagConstraints); 226 227 jPanel1.setLayout(new java.awt.GridBagLayout ()); 228 229 gridBagConstraints = new java.awt.GridBagConstraints (); 230 gridBagConstraints.gridx = 0; 231 gridBagConstraints.gridy = 1; 232 gridBagConstraints.gridwidth = 2; 233 gridBagConstraints.gridheight = 5; 234 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 235 gridBagConstraints.weightx = 1.0; 236 gridBagConstraints.weighty = 1.0; 237 gridBagConstraints.insets = new java.awt.Insets (2, 0, 0, 0); 238 add(jPanel1, gridBagConstraints); 239 240 org.openide.awt.Mnemonics.setLocalizedText(addButton, getBundle("BTN_Add_2")); addButton.addActionListener(new java.awt.event.ActionListener () { 242 public void actionPerformed(java.awt.event.ActionEvent evt) { 243 addButtonActionPerformed(evt); 244 } 245 }); 246 247 gridBagConstraints = new java.awt.GridBagConstraints (); 248 gridBagConstraints.gridx = 2; 249 gridBagConstraints.gridy = 1; 250 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 251 gridBagConstraints.insets = new java.awt.Insets (2, 12, 0, 12); 252 add(addButton, gridBagConstraints); 253 254 org.openide.awt.Mnemonics.setLocalizedText(removeButton, getBundle("BTN_Remove_2")); removeButton.addActionListener(new java.awt.event.ActionListener () { 256 public void actionPerformed(java.awt.event.ActionEvent evt) { 257 removeButtonActionPerformed(evt); 258 } 259 }); 260 261 gridBagConstraints = new java.awt.GridBagConstraints (); 262 gridBagConstraints.gridx = 2; 263 gridBagConstraints.gridy = 2; 264 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 265 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 12); 266 add(removeButton, gridBagConstraints); 267 268 org.openide.awt.Mnemonics.setLocalizedText(addallButton, getBundle("BTN_AddAll_2")); addallButton.addActionListener(new java.awt.event.ActionListener () { 270 public void actionPerformed(java.awt.event.ActionEvent evt) { 271 addallButtonActionPerformed(evt); 272 } 273 }); 274 275 gridBagConstraints = new java.awt.GridBagConstraints (); 276 gridBagConstraints.gridx = 2; 277 gridBagConstraints.gridy = 3; 278 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 279 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 12); 280 add(addallButton, gridBagConstraints); 281 282 org.openide.awt.Mnemonics.setLocalizedText(removeallButton, getBundle("BTN_RemoveAll_2")); removeallButton.addActionListener(new java.awt.event.ActionListener () { 284 public void actionPerformed(java.awt.event.ActionEvent evt) { 285 removeallButtonActionPerformed(evt); 286 } 287 }); 288 289 gridBagConstraints = new java.awt.GridBagConstraints (); 290 gridBagConstraints.gridx = 2; 291 gridBagConstraints.gridy = 4; 292 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 293 gridBagConstraints.insets = new java.awt.Insets (6, 12, 0, 12); 294 add(removeallButton, gridBagConstraints); 295 296 scrollpaneLabel.setLabelFor(jList1); 297 org.openide.awt.Mnemonics.setLocalizedText(scrollpaneLabel, getBundle("LAB_222")); gridBagConstraints = new java.awt.GridBagConstraints (); 299 gridBagConstraints.gridx = 3; 300 gridBagConstraints.gridy = 0; 301 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 302 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 303 add(scrollpaneLabel, gridBagConstraints); 304 305 jList1.addMouseListener(new java.awt.event.MouseAdapter () { 306 public void mouseClicked(java.awt.event.MouseEvent evt) { 307 jList1MouseClicked(evt); 308 } 309 }); 310 311 jScrollPane1.setViewportView(jList1); 312 313 gridBagConstraints = new java.awt.GridBagConstraints (); 314 gridBagConstraints.gridx = 3; 315 gridBagConstraints.gridy = 1; 316 gridBagConstraints.gridwidth = 3; 317 gridBagConstraints.gridheight = 5; 318 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 319 gridBagConstraints.weightx = 1.0; 320 gridBagConstraints.weighty = 1.0; 321 gridBagConstraints.insets = new java.awt.Insets (2, 0, 0, 0); 322 add(jScrollPane1, gridBagConstraints); 323 324 jPanel3.setLayout(new java.awt.GridLayout (1, 2, 6, 0)); 325 326 totalsizeLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 327 totalsizeLabel.setLabelFor(totalsizeTextField); 328 org.openide.awt.Mnemonics.setLocalizedText(totalsizeLabel, getBundle("LAB_223")); jPanel3.add(totalsizeLabel); 330 331 totalsizeTextField.setEditable(false); 332 totalsizeTextField.setDisabledTextColor(java.awt.Color.black); 333 totalsizeTextField.setMinimumSize(new java.awt.Dimension (6, 20)); 334 jPanel3.add(totalsizeTextField); 335 336 gridBagConstraints = new java.awt.GridBagConstraints (); 337 gridBagConstraints.gridx = 3; 338 gridBagConstraints.gridy = 6; 339 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 340 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 341 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 342 gridBagConstraints.weightx = 1.0; 343 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 344 add(jPanel3, gridBagConstraints); 345 346 jPanel2.setLayout(new java.awt.GridBagLayout ()); 347 348 jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 349 avLabel.setLabelFor(avTextField); 350 org.openide.awt.Mnemonics.setLocalizedText(avLabel, getBundle("LAB_224")); gridBagConstraints = new java.awt.GridBagConstraints (); 352 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 353 gridBagConstraints.insets = new java.awt.Insets (4, 10, 0, 0); 354 jPanel2.add(avLabel, gridBagConstraints); 355 356 avTextField.setEditable(false); 357 avTextField.setDisabledTextColor(java.awt.Color.black); 358 avTextField.setMinimumSize(new java.awt.Dimension (60, 21)); 359 avTextField.setPreferredSize(new java.awt.Dimension (60, 21)); 360 gridBagConstraints = new java.awt.GridBagConstraints (); 361 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 362 gridBagConstraints.ipadx = 60; 363 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 364 gridBagConstraints.weightx = 1.0; 365 gridBagConstraints.insets = new java.awt.Insets (4, 6, 0, 0); 366 jPanel2.add(avTextField, gridBagConstraints); 367 368 ivLabel.setLabelFor(ivTextField); 369 org.openide.awt.Mnemonics.setLocalizedText(ivLabel, getBundle("LAB_225")); gridBagConstraints = new java.awt.GridBagConstraints (); 371 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 372 gridBagConstraints.insets = new java.awt.Insets (4, 12, 0, 0); 373 jPanel2.add(ivLabel, gridBagConstraints); 374 375 ivTextField.setEditable(false); 376 ivTextField.setDisabledTextColor(java.awt.Color.black); 377 ivTextField.setMinimumSize(new java.awt.Dimension (60, 21)); 378 ivTextField.setPreferredSize(new java.awt.Dimension (63, 21)); 379 gridBagConstraints = new java.awt.GridBagConstraints (); 380 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 381 gridBagConstraints.ipadx = 60; 382 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 383 gridBagConstraints.weightx = 1.0; 384 gridBagConstraints.insets = new java.awt.Insets (4, 6, 0, 0); 385 jPanel2.add(ivTextField, gridBagConstraints); 386 387 jScrollPane2.setMinimumSize(new java.awt.Dimension (22, 52)); 388 description.setEditable(false); 389 jScrollPane2.setViewportView(description); 390 391 gridBagConstraints = new java.awt.GridBagConstraints (); 392 gridBagConstraints.gridx = 0; 393 gridBagConstraints.gridy = 1; 394 gridBagConstraints.gridwidth = 5; 395 gridBagConstraints.gridheight = 2; 396 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 397 gridBagConstraints.weightx = 1.0; 398 gridBagConstraints.weighty = 1.0; 399 gridBagConstraints.insets = new java.awt.Insets (6, 10, 4, 0); 400 jPanel2.add(jScrollPane2, gridBagConstraints); 401 402 org.openide.awt.Mnemonics.setLocalizedText(moreButton, getBundle("BTN_More")); moreButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); 404 moreButton.setIconTextGap(0); 405 moreButton.addActionListener(new java.awt.event.ActionListener () { 406 public void actionPerformed(java.awt.event.ActionEvent evt) { 407 moreButtonActionPerformed(evt); 408 } 409 }); 410 411 gridBagConstraints = new java.awt.GridBagConstraints (); 412 gridBagConstraints.gridx = 5; 413 gridBagConstraints.gridy = 2; 414 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; 415 gridBagConstraints.insets = new java.awt.Insets (6, 11, 4, 4); 416 jPanel2.add(moreButton, gridBagConstraints); 417 418 gridBagConstraints = new java.awt.GridBagConstraints (); 419 gridBagConstraints.gridx = 0; 420 gridBagConstraints.gridy = 7; 421 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 422 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 423 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 424 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; 425 gridBagConstraints.weighty = 1.0; 426 gridBagConstraints.insets = new java.awt.Insets (12, 0, 0, 0); 427 add(jPanel2, gridBagConstraints); 428 429 } 431 private void moreButtonActionPerformed(java.awt.event.ActionEvent evt) { ModuleUpdate mu = getSingleSelection(); 433 434 if (mu != null && mu.getHomePage() != null) { 435 HtmlBrowser.URLDisplayer.getDefault().showURL(mu.getHomePage()); 436 } 437 } 439 private void removeallButtonActionPerformed(java.awt.event.ActionEvent evt) { for( int i = 0; i < selectedListModel.size(); i++ ) { 441 ((ModuleUpdate)selectedListModel.get(i)).setSelected( false ); 442 ((ModuleUpdate)selectedListModel.get(i)).setDownloadOK( false ); 443 ((ModuleUpdate)selectedListModel.get(i)).setSecurity( SignVerifier.NOT_CHECKED ); 444 } 445 refreshNodes(); 446 447 selectedListModel.clear(); 448 Downloader.deleteDownload(); 449 showSize(); 450 validator.setValid( selectedListModel.size() > 0 ); 451 452 buttonsCheck(); 453 } 455 private void addallButtonActionPerformed(java.awt.event.ActionEvent evt) { Collection modules = Wizard.getAllModules(); 457 458 Iterator it = modules.iterator(); 459 460 while ( it.hasNext() ) { 461 ModuleUpdate mu = (ModuleUpdate) it.next(); 462 if (mu.isSelected () || !DependencyChecker.checkPlatformDependency (mu.getRemoteModule ())) { 463 continue; 464 } 465 if ( !addModule (mu) ) { 466 removeallButtonActionPerformed(evt); 468 return; 469 } 470 } 471 buttonsCheck(); 472 473 } 475 private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) { int[] index = jList1.getSelectedIndices(); 477 478 if ( index.length == 0 ) 479 return; 480 481 java.util.List toremove = new ArrayList (); 482 for (int i = index.length -1; i >= 0 ; i-- ) 483 toremove.add( selectedListModel.get( index[i] )); 484 485 Iterator it = toremove.iterator(); 486 while (it.hasNext()) 487 removeModule( (ModuleUpdate)it.next() ); 488 489 refreshNodes(); 490 491 showSize(); 492 validator.setValid( selectedListModel.size() > 0 ); 493 buttonsCheck(); 494 } 496 private void addButtonActionPerformed(java.awt.event.ActionEvent evt) { Node[] nodes = explorerView.getSelectedNodes(); 498 List modulesToAdd = new ArrayList (); 499 ModuleUpdate mu = null; 500 501 for ( int i = 0; i < nodes.length; i ++ ) { 502 mu = (ModuleUpdate)nodes[i].getCookie( ModuleUpdate.class ); 503 if ( mu != null ) { 504 modulesToAdd.add( mu ); 505 } 506 else { 507 modulesToAdd.addAll( getUnselectedChildren( nodes[i] ) ); 509 } 510 } 511 512 Iterator iter = modulesToAdd.iterator(); 513 while ( iter.hasNext() ) { 514 mu = (ModuleUpdate)iter.next(); 515 if ( !addModule( mu , modulesToAdd ) ) { 516 return; 517 } 518 } 519 520 buttonsCheck(); 521 } 523 private void jList1MouseClicked(java.awt.event.MouseEvent evt) { if ( evt.getClickCount() == 2 ) { 525 int index = jList1.locationToIndex( evt.getPoint() ); 526 527 if ( index >= 0 && index < selectedListModel.size() ) { 528 removeModule( (ModuleUpdate)selectedListModel.get( index ) ); 529 showSize(); 530 validator.setValid( selectedListModel.size() > 0 ); 531 refreshNodes(); 532 } 533 buttonsCheck(); 534 } 535 } 537 private javax.swing.JButton addButton; 539 private javax.swing.JButton addallButton; 540 private javax.swing.JLabel avLabel; 541 private javax.swing.JTextField avTextField; 542 private javax.swing.JEditorPane description; 543 private javax.swing.JLabel ivLabel; 544 private javax.swing.JTextField ivTextField; 545 private javax.swing.JList jList1; 546 private javax.swing.JPanel jPanel1; 547 private javax.swing.JPanel jPanel2; 548 private javax.swing.JPanel jPanel3; 549 private javax.swing.JScrollPane jScrollPane1; 550 private javax.swing.JScrollPane jScrollPane2; 551 private javax.swing.JButton moreButton; 552 private javax.swing.JLabel panel1Label; 553 private javax.swing.JButton removeButton; 554 private javax.swing.JButton removeallButton; 555 private javax.swing.JLabel scrollpaneLabel; 556 private javax.swing.JLabel totalsizeLabel; 557 private javax.swing.JTextField totalsizeTextField; 558 560 void setUpdates( int wizardType ) { 561 562 boolean firstTime = true; 563 564 allNodes = null; 565 selectedListModel.clear(); 566 totalSize = 0; 567 Iterator it = Wizard.getAllModules().iterator(); 568 569 while( it.hasNext() ) { 570 ModuleUpdate mu = (ModuleUpdate)it.next(); 571 572 if ( mu.isSelected() && ( !selectedListModel.contains( mu ) ) ) { 573 selectedListModel.addElement( mu ); 574 totalSize += mu.getDownloadSize(); 575 } 576 577 if ( firstTime ) { 578 if ( wizardType == 1 || mu.isPurchased() ) { 579 addModule( mu ); 580 } 581 } 582 } 583 validator.setValid( selectedListModel.size() > 0 ); 584 585 totalsizeTextField.setText( ( totalSize / 1024 ) + SPACE + getBundle("CTL_UpdatePanel_KB") ); 586 587 buttonsCheck(); 588 showSize(); 589 590 javax.swing.SwingUtilities.invokeLater(new Runnable () { 591 public void run() { 592 refreshNodes(); 593 } 594 }); 595 596 nodeListener = new PropertyChangeListener () { 597 public void propertyChange(PropertyChangeEvent evt) { 598 if ( Settings.NODE_DEFAULT_ACTION.equals( evt.getPropertyName() )) { 599 final Node[] selectedNodes = explorerView.getSelectedNodes(); 601 SwingUtilities.invokeLater (new Runnable () { 602 public void run () { 603 if ( selectedNodes.length == 1 ) { 604 ModuleUpdate mu = (ModuleUpdate)selectedNodes[0].getCookie( ModuleUpdate.class ); 605 if ( mu != null ) 606 if ( ! addModule( mu ) ) 607 buttonsCheck(); 608 } 609 } 610 }); 611 } 612 } 613 }; 614 Settings.getShared().addPropertyChangeListener( nodeListener ); 615 } 616 617 static class ExplorerView extends JComponent implements ExplorerManager.Provider { 619 620 private ExplorerManager em; 621 private BeanTreeView btv; 622 623 static final long serialVersionUID =-5811911993587966912L; 624 ExplorerView( ) { 625 Node waitNode = new UpdateNode.Wait(); 626 createContent( waitNode ); 627 } 628 629 private void createContent ( Node node ) { 630 631 btv = new BeanTreeView (); 632 btv.setPopupAllowed( false ); 633 btv.setDefaultActionAllowed( true ); 634 btv.setBorder (UIManager.getBorder ("ScrollPane.border")); 636 setLayout (new java.awt.BorderLayout ()); 638 add ( java.awt.BorderLayout.CENTER, btv ); 639 640 getExplorerManager ().setRootContext ( node ); 641 642 btv.setRootVisible( false ); 643 } 644 645 public java.awt.Dimension getPreferredSize () { 646 java.awt.Dimension sup = super.getPreferredSize (); 647 return new java.awt.Dimension ( Math.max (sup.width, 450), Math.max (sup.height, 300 )); 648 } 649 650 void expandAll() { 651 expandChildren(getExplorerManager().getRootContext()); 652 } 653 654 public void addNotify () { 655 super.addNotify (); 656 btv.requestFocus (); 657 } 658 659 private void expandChildren (Node n) { 660 Node[] kids = n.getChildren().getNodes(); 661 for (int i=0; i < kids.length; i++) { 662 if (!kids[i].getDisplayName().startsWith("L10N")) { btv.expandNode(kids[i]); 664 if (kids[i].getChildren() != Children.LEAF) { 665 expandChildren(kids[i]); 666 } 667 } 668 } 669 } 670 671 Node[] getSelectedNodes() { 672 return getExplorerManager ().getSelectedNodes(); 673 } 674 675 public ExplorerManager getExplorerManager () { 676 if (em == null) { 677 em = new ExplorerManager (); 678 679 } 680 return em; 681 } 682 683 } 684 685 private ModuleUpdate getSingleSelection() { 686 if ( jList1.getSelectedIndex() >= 0 ) 687 return ((ModuleUpdate)selectedListModel.get(jList1.getSelectedIndex())); 689 else { 690 Node[] selectedNodes = explorerView.getSelectedNodes(); 692 if ( selectedNodes.length != 1 ) { 693 return null; 694 } 695 else { 696 return (ModuleUpdate)selectedNodes[0].getCookie( ModuleUpdate.class ); 697 } 698 } 699 } 700 701 private void unselectLeft() { 702 try { 703 explorerView.getExplorerManager().setSelectedNodes( new Node[0]); 704 } catch (java.beans.PropertyVetoException e) { 705 } 706 } 707 708 private String formatDescription (ModuleUpdate mu) { 709 Date date = mu.getReleaseDate (); 710 String release = date != null ? ModuleUpdate.DATE_FORMAT.format (date) : ""; String author = mu.getModuleAuthor () == null ? "" : mu.getModuleAuthor (); 713 String desc = getBundle ("LAB_226") + SPACE + ( mu.getDownloadSize() / 1024 ) + SPACE + getBundle("CTL_UpdatePanel_KB") + LINE_SEPARATOR + ((author.length () == 0) ? "" : getBundle ("LAB_AuthorName") + SPACE + author + LINE_SEPARATOR) + ((release.length () == 0) ? "" : getBundle ("LAB_ReleaseDate") + SPACE + release + LINE_SEPARATOR) + mu.getDescription (); 722 return desc; 723 } 724 725 726 private void selectionChange( boolean onLeft ) { 727 ModuleUpdate mu; 728 729 if ( onLeft && explorerView.getSelectedNodes().length > 0) { 730 jList1.clearSelection(); 731 } 732 733 mu = getSingleSelection(); 734 735 if ( mu == null ) { 736 ivTextField.setText( EMPTY_STRING ); 737 avTextField.setText( EMPTY_STRING ); 738 description.setText( EMPTY_STRING ); 739 } 740 else { 741 ivTextField.setText( mu.getLocalModule() == null ? 742 getBundle( "CTL_UpdatePanel_ModuleNotInstalled" ) : 743 (mu.getLocalModule().getSpecificationVersion() == null ? 744 "" : 745 mu.getLocalModule().getSpecificationVersion().toString())); 746 SpecificationVersion sv = mu.getRemoteModule().getSpecificationVersion(); 747 avTextField.setText( sv == null ? "" : sv.toString() ); 748 description.setText( formatDescription ( mu ) ); 749 description.setCaretPosition (0); 750 } 751 752 buttonsCheck(); 753 } 754 755 private void buttonsCheck() { 756 if ( selectedListModel.getSize() > 0 ) { 757 removeallButton.setEnabled(true); 758 if ( jList1.getSelectedIndex() != -1 ) 759 removeButton.setEnabled(true); 760 else 761 removeButton.setEnabled(false); 762 } else { 763 removeButton.setEnabled(false); 764 removeallButton.setEnabled(false); 765 } 766 767 if ( existUnselectedModule() ) { 768 addallButton.setEnabled(true); 769 if ( isLeftSelection() ) 770 addButton.setEnabled(true); 771 else 772 addButton.setEnabled(false); 773 } else { 774 addButton.setEnabled(false); 775 addallButton.setEnabled(false); 776 } 777 778 ModuleUpdate mu = getSingleSelection(); 779 moreButton.setEnabled(mu != null && mu.getHomePage() != null); 780 } 781 782 private boolean isLeftSelection() { 783 Node[] selectedNodes = explorerView.getSelectedNodes(); 785 for (int i=0; i<selectedNodes.length; i++) 786 if (selectedNodes[i].getCookie( ModuleUpdate.class ) != null) 787 return true; 788 else { 789 List lst = getUnselectedChildren( selectedNodes[i] ); 791 if ( lst.size() > 0 ) 792 return true; 793 } 794 return false; 795 } 796 797 798 private List getUnselectedChildren(Node group) { 799 Node[] nodes = group.getChildren().getNodes(); 800 List modlist = new ArrayList (); 801 for (int i = 0; i < nodes.length; i++) { 802 if (nodes[i].getCookie( ModuleUpdate.class ) != null) { 803 ModuleUpdate mu = (ModuleUpdate)nodes[i].getCookie( ModuleUpdate.class ); 804 if ( !mu.isSelected() ) 805 modlist.add( mu ); 806 } 807 else { 808 List lst = getUnselectedChildren( nodes[i] ); 809 if ( lst.size() > 0 ) 810 modlist.addAll( lst ); 811 } 812 } 813 return modlist; 814 } 815 816 private boolean addModule( final ModuleUpdate mu ) { 817 return addModule( mu, null ); 818 } 819 820 private boolean addModule( final ModuleUpdate mu, final List group ) { 821 return addModule( mu, group, true ); 822 } 823 824 829 private boolean addModule( final ModuleUpdate mu, final List group, boolean askForDuplicates ) { 830 if ( selectedListModel.contains( mu ) ) 831 return true; 833 String prepSpecVersion = PreparedModules.getPrepared().getPreparedVersion( mu.getCodeNameBase() ); 834 if ( prepSpecVersion != null ) { 836 NotifyDescriptor.Confirmation nd = 837 new NotifyDescriptor.Confirmation( 838 NbBundle.getMessage( UpdatePanel.class, "MSG_Prepared_Module", 839 mu.getName(), prepSpecVersion ), 840 getBundle( "CTL_Prepared_Title" ), 841 NotifyDescriptor.YES_NO_OPTION ); 842 if ( DialogDisplayer.getDefault().notify( nd ).equals( NotifyDescriptor.YES_OPTION ) ) { 843 PreparedModules.getPrepared().removeModule( mu.getCodeNameBase() ); 844 } 845 else 846 return true; 847 } 848 849 boolean remove = false; 851 for( int j = 0; j < selectedListModel.size(); j++ ) { 852 ModuleUpdate mu2 = (ModuleUpdate)selectedListModel.get(j); 853 String loc = null; 855 if (mu instanceof L10NUpdate) { 856 loc = ((L10NUpdate) mu).getLangcode (); 857 } 858 loc = loc == null ? "" : loc; String loc2 = null; 860 if (mu2 instanceof L10NUpdate) { 861 loc2 = ((L10NUpdate) mu2).getLangcode (); 862 } 863 loc2 = loc2 == null ? "" : loc2; if ( mu2.getCodeNameBase().equals( mu.getCodeNameBase() ) 865 && loc2.equals( loc ) ) { if ( askForDuplicates ) { 867 if ( duplicateStatus == DuplicateWarningDialog.YES_ALL ) 868 remove = true; 869 else if ( duplicateStatus == DuplicateWarningDialog.NO_ALL ) 870 return true; 871 else { 872 final java.awt.Dialog warnDialog = DuplicateWarningDialog.getDialog(mu.getName()); 873 warnDialog.setVisible (true); 874 duplicateStatus = DuplicateWarningDialog.getResult(); 875 if ( duplicateStatus == DuplicateWarningDialog.YES || 876 duplicateStatus == DuplicateWarningDialog.YES_ALL ) 877 remove = true; 878 else 879 return true; 880 } 881 } 882 else 883 remove = true; 884 } 885 if ( remove ) { 886 removeModule( mu2, mu ); 887 break; 888 } 889 } 890 891 if ( mu.getNotification() != null && mu.getNotification().length() > 0 893 && !mu.getNotificationAccepted() ) { 894 if ( Notification.performModuleNotification( mu.getNotification() ) ) { 895 mu.setNotificationAccepted( true ); 896 } else { 897 return false; 898 } 899 } 900 901 List ext_list = mu.getExternals(); 902 if ( ext_list != null ) { 903 Iterator it = ext_list.iterator(); 904 while ( it.hasNext() ) 905 ExternalDialog.showExternal( mu.getName(), (ModuleUpdate.External)it.next() ); 906 } 907 908 910 DependencyChecker dc = new DependencyChecker(); 911 StringBuffer dontAddModuleName = new StringBuffer (); 912 Collection modulesToAdd = dc.modulesToAdd( mu, selectedListModel.elements(), group, dontAddModuleName ); 913 if ( dontAddModuleName.length() > 0 ) 914 return false; 915 916 selectedListModel.add( findPosition( mu ), mu ); 917 918 Iterator it = modulesToAdd.iterator(); 919 while( it.hasNext() ) { 920 ModuleUpdate addMu = (ModuleUpdate)it.next(); 921 if ( !addModule( addMu, null, false ) ) { 922 selectedListModel.removeElement( mu ); 923 totalSize += mu.getDownloadSize(); 924 return false; 925 } 926 } 927 928 showSize(); 929 validator.setValid( selectedListModel.size() > 0 ); 930 jList1.revalidate(); 931 932 mu.setSelected( true ); 933 refreshNodes(); 934 935 return true; 936 } 937 938 941 boolean checkLicencies() { 942 ModuleUpdate mu; 943 for( int i = 0; i < selectedListModel.size(); i++ ) { 944 mu = (ModuleUpdate)selectedListModel.get(i); 945 946 if ( mu.getLicenceText() != null && mu.getLicenceID() != null ) { 947 948 if (!acceptedLicencies.contains (mu.getLicenceID ())) { 950 if (LicenceDialog.acceptLicence (mu.getLicenceText ())) { 951 acceptedLicencies.add (mu.getLicenceID ()); 952 } else { 953 return false; 954 } 955 } 956 } 957 } 958 return true; 959 } 960 961 962 private int findPosition( ModuleUpdate mu ) { 963 int pos = 0; 964 965 Collection modules = Wizard.getAllModules(); 966 Iterator it = modules.iterator(); 967 while ( it.hasNext() ) { 968 969 ModuleUpdate imu = ((ModuleUpdate)it.next()); 970 971 if ( mu == imu ) { 972 return pos; 973 } 974 if ( selectedListModel.contains( imu ) ) { 975 pos++; 976 } 977 } 978 979 return pos; 980 } 981 982 private void removeModule( final ModuleUpdate mu ) { 983 removeModule( mu, null ); 984 } 985 986 990 private void removeModule( final ModuleUpdate mu, ModuleUpdate toReplace ) { 991 992 if ( !selectedListModel.contains( mu ) ) 993 return; 995 final int index = selectedListModel.indexOf ( mu ); 996 totalSize -= mu.getDownloadSize(); 997 998 selectedListModel.remove( index ); 999 if ( mu.isDownloadStarted() ) 1000 Downloader.deleteModuleNBM( mu ); 1001 1002 DependencyChecker dc = new DependencyChecker(); 1003 Collection modulesToRemove = dc.modulesToRemove( mu, toReplace ); 1004 Iterator it = modulesToRemove.iterator(); 1005 while( it.hasNext() ) { 1006 ModuleUpdate removeMu = (ModuleUpdate)it.next(); 1007 removeModule( removeMu ); 1008 } 1009 1010 mu.setSelected( false ); 1011 mu.setDownloadOK( false ); 1012 mu.setSecurity( SignVerifier.NOT_CHECKED ); 1013 } 1014 1015 void showSize() { 1016 totalSize = 0; 1017 1018 for( int i = 0; i < selectedListModel.size(); i++ ) { 1019 if ( !((ModuleUpdate)selectedListModel.get(i)).isDownloadOK() ) { 1020 totalSize += ((ModuleUpdate)selectedListModel.get(i)).getDownloadSize(); 1021 } 1022 } 1023 1024 totalsizeTextField.setText( ( totalSize / 1024 ) + SPACE + getBundle("CTL_UpdatePanel_KB") ); 1025 } 1026 1027 int modulesToDownload() { 1028 int result = 0; 1029 1030 for( int i = 0; i < selectedListModel.size(); i++ ) { 1031 if ( !((ModuleUpdate)selectedListModel.get(i)).isDownloadOK() 1032 ||((ModuleUpdate)selectedListModel.get(i)).isNotChecked()) { 1033 result++; 1034 } 1035 } 1036 1037 return result; 1038 } 1039 1040 private boolean existUnselectedModule() { 1041 Collection modules = Wizard.getAllModules(); 1042 Iterator it = modules.iterator(); 1043 while ( it.hasNext() ) 1044 if ( ! ((ModuleUpdate)it.next()).isSelected() ) 1045 return true; 1046 return false; 1047 } 1048 1049 void markSelectedModules() { 1050 1051 Collection modules = Wizard.getAllModules(); 1053 Iterator it = modules.iterator(); 1054 while ( it.hasNext() ) { 1055 ((ModuleUpdate)it.next()).setSelected( false ); 1056 } 1057 1058 1060 for( int i = 0; i < selectedListModel.size(); i++ ) { 1061 ((ModuleUpdate)selectedListModel.get(i)).setSelected( true ); 1062 } 1063 } 1064 1065 private void refreshNodes() { 1066 if ( allNodes == null ) { 1067 allNodes = UpdateNode.getAllServers(); 1068 explorerView.getExplorerManager ().setRootContext (allNodes); 1069 explorerView.expandAll(); 1070 Runnable makeVisible = new Runnable () { 1071 public void run () { 1072 if (! allNodes.isLeaf ()) { 1073 explorerView.getExplorerManager ().setExploredContext (allNodes.getChildren ().getNodes ()[0]); 1074 } 1075 } 1076 }; 1077 RequestProcessor.getDefault ().post (makeVisible, 300); 1078 } 1079 else 1080 allNodes.refreshContent( true ); 1081 } 1082 1083 void removeListeners() { 1084 if ( nodeListener != null ) 1085 Settings.getShared().removePropertyChangeListener( nodeListener ); 1086 } 1087 1088 private static String getBundle( String key ) { 1089 return NbBundle.getMessage( UpdatePanel.class, key ); 1090 } 1091} 1092 | Popular Tags |