1 19 20 package org.apache.excalibur.instrument.client; 21 22 import java.util.ArrayList ; 23 import java.util.HashMap ; 24 25 import javax.swing.event.TreeModelEvent ; 26 import javax.swing.event.TreeModelListener ; 27 import javax.swing.tree.DefaultMutableTreeNode ; 28 import javax.swing.tree.TreeModel ; 29 import javax.swing.tree.TreePath ; 30 31 import org.apache.avalon.framework.logger.AbstractLogEnabled; 32 33 36 class InstrumentManagerTreeModel 37 extends AbstractLogEnabled 38 implements InstrumentManagerConnectionListener, TreeModel 39 { 40 private final InstrumentManagerConnection m_connection; 41 42 43 private int m_lastClientStateVersion; 44 45 private boolean m_lastConnected = false; 46 47 private DefaultMutableTreeNode m_root; 48 49 private ArrayList m_listeners = new ArrayList (); 50 private TreeModelListener [] m_listenerArray; 51 52 private HashMap m_elementMap = new HashMap (); 53 private HashMap m_leasedSampleMap = new HashMap (); 54 private DefaultMutableTreeNode [] m_leasedSampleArray; 55 56 59 InstrumentManagerTreeModel( InstrumentManagerConnection connection ) 60 { 61 m_connection = connection; 62 63 m_root = new DefaultMutableTreeNode ( "Root" ); 64 } 65 66 69 75 public void opened( InstrumentManagerConnection connection ) 76 { 77 getLogger().debug( "InstrumentManagerTreeModel.opened(" + connection + ")" ); 78 refreshModel(); 79 } 80 81 87 public void closed( InstrumentManagerConnection connection ) 88 { 89 getLogger().debug( "InstrumentManagerTreeModel.closed(" + connection + ")" ); 90 refreshModel(); 91 } 92 93 98 public void deleted( InstrumentManagerConnection connection ) 99 { 100 getLogger().debug( "InstrumentManagerTreeModel.deleted(" + connection + ")" ); 101 refreshModel(); 102 } 103 104 107 113 public Object getRoot() 114 { 115 return m_root; 116 } 117 118 128 public Object getChild( Object parent, int index ) 129 { 130 if ( parent instanceof DefaultMutableTreeNode ) 132 { 133 DefaultMutableTreeNode node = (DefaultMutableTreeNode )parent; 134 return node.getChildAt( index ); 135 } 136 else 137 { 138 return "---"; 139 } 140 } 141 142 143 151 public int getChildCount( Object parent ) 152 { 153 if ( parent instanceof DefaultMutableTreeNode ) 155 { 156 DefaultMutableTreeNode node = (DefaultMutableTreeNode )parent; 157 return node.getChildCount(); 158 } 159 else 160 { 161 return 0; 162 } 163 } 164 165 174 public boolean isLeaf( Object node ) 175 { 176 if ( node == m_root ) 178 { 179 return false; 182 } 183 else if ( node instanceof DefaultMutableTreeNode ) 184 { 185 DefaultMutableTreeNode inode = (DefaultMutableTreeNode )node; 186 return inode.isLeaf(); 187 } 188 else 189 { 190 return true; 191 } 192 } 193 194 203 public void valueForPathChanged( TreePath path, Object newValue ) 204 { 205 } 208 209 212 public int getIndexOfChild( Object parent, Object child ) 213 { 214 if ( parent instanceof DefaultMutableTreeNode ) 216 { 217 DefaultMutableTreeNode node = (DefaultMutableTreeNode )parent; 218 return node.getIndex( (DefaultMutableTreeNode )child ); 219 } 220 else 221 { 222 return 0; 223 } 224 } 225 226 231 public void addTreeModelListener( TreeModelListener listener ) 232 { 233 synchronized(this) 235 { 236 m_listeners.add( listener ); 237 m_listenerArray = null; 238 } 239 } 240 241 246 public void removeTreeModelListener( TreeModelListener listener ) 247 { 248 synchronized(this) 250 { 251 m_listeners.remove( listener ); 252 m_listenerArray = null; 253 } 254 } 255 256 257 260 265 private TreeModelListener [] getListeners() 266 { 267 TreeModelListener [] listeners = m_listenerArray; 268 if ( listeners == null ) 269 { 270 synchronized(this) 271 { 272 m_listenerArray = new TreeModelListener [ m_listeners.size() ]; 273 m_listeners.toArray( m_listenerArray ); 274 listeners = m_listenerArray; 275 } 276 } 277 return listeners; 278 } 279 280 private void fireTreeNodesChanged( TreeModelEvent event ) 281 { 282 TreeModelListener [] listeners = getListeners(); 283 for ( int i = 0; i < listeners.length; i++ ) 284 { 285 listeners[i].treeNodesChanged( event ); 286 } 287 } 288 289 private void fireTreeNodesInserted( TreeModelEvent event ) 290 { 291 TreeModelListener [] listeners = getListeners(); 292 for ( int i = 0; i < listeners.length; i++ ) 293 { 294 listeners[i].treeNodesInserted( event ); 295 } 296 } 297 298 private void fireTreeNodesRemoved( TreeModelEvent event ) 299 { 300 TreeModelListener [] listeners = getListeners(); 301 for ( int i = 0; i < listeners.length; i++ ) 302 { 303 listeners[i].treeNodesRemoved( event ); 304 } 305 } 306 307 private void fireTreeStructureChanged( TreeModelEvent event ) 308 { 309 TreeModelListener [] listeners = getListeners(); 310 for ( int i = 0; i < listeners.length; i++ ) 311 { 312 listeners[i].treeStructureChanged( event ); 313 } 314 } 315 316 323 public DefaultMutableTreeNode getInstrumentableTreeNode( String name ) 324 { 325 DefaultMutableTreeNode node = (DefaultMutableTreeNode )m_elementMap.get( name ); 326 if ( node != null ) 327 { 328 Object element = node.getUserObject(); 329 if ( element instanceof InstrumentableNodeData ) 330 { 331 return node; 332 } 333 } 334 return null; 335 } 336 337 344 public DefaultMutableTreeNode getInstrumentTreeNode( String name ) 345 { 346 DefaultMutableTreeNode node = (DefaultMutableTreeNode )m_elementMap.get( name ); 347 if ( node != null ) 348 { 349 Object element = node.getUserObject(); 350 if ( element instanceof InstrumentNodeData ) 351 { 352 return node; 353 } 354 } 355 return null; 356 } 357 358 365 public DefaultMutableTreeNode getInstrumentSampleTreeNode( String name ) 366 { 367 DefaultMutableTreeNode node = (DefaultMutableTreeNode )m_elementMap.get( name ); 368 if ( node != null ) 369 { 370 Object element = node.getUserObject(); 371 if ( element instanceof InstrumentSampleNodeData ) 372 { 373 return node; 374 } 375 } 376 return null; 377 } 378 379 386 private DefaultMutableTreeNode [] getLeasedSampleArray() 387 { 388 DefaultMutableTreeNode [] leasedSampleArray = m_leasedSampleArray; 389 if ( leasedSampleArray == null ) 390 { 391 synchronized(this) 392 { 393 m_leasedSampleArray = new DefaultMutableTreeNode [ m_leasedSampleMap.size() ]; 394 m_leasedSampleMap.values().toArray( m_leasedSampleArray ); 395 leasedSampleArray = m_leasedSampleArray; 396 } 397 } 398 return leasedSampleArray; 399 } 400 401 407 void renewAllSampleLeases() 408 { 409 DefaultMutableTreeNode [] leasedSampleArray = getLeasedSampleArray(); 410 411 for ( int i = 0; i < leasedSampleArray.length; i++ ) 412 { 413 InstrumentSampleNodeData sampleNodeData = 415 (InstrumentSampleNodeData)leasedSampleArray[i].getUserObject(); 416 InstrumentSampleData sample = sampleNodeData.getData(); 417 418 updateInstrumentSample( sample ); 419 } 420 } 421 422 425 void purgeExpiredSamples() 426 { 427 DefaultMutableTreeNode [] leasedSampleArray = getLeasedSampleArray(); 428 429 for ( int i = 0; i < leasedSampleArray.length; i++ ) 430 { 431 InstrumentSampleNodeData sampleNodeData = 433 (InstrumentSampleNodeData)leasedSampleArray[i].getUserObject(); 434 if ( sampleNodeData.getRemainingLeaseTime() < 0 ) 437 { 438 DefaultMutableTreeNode instrumentTreeNode = 440 (DefaultMutableTreeNode )leasedSampleArray[i].getParent(); 441 InstrumentData instrumentData = 442 ((InstrumentNodeData)instrumentTreeNode.getUserObject()).getData(); 443 updateInstrument( instrumentData, instrumentTreeNode, -1 ); 444 } 445 } 446 } 447 448 453 void refreshModel() 454 { 455 if ( m_connection.isConnected() != m_lastConnected ) 457 { 458 m_root.removeAllChildren(); 459 m_elementMap.clear(); 460 m_leasedSampleMap.clear(); 461 m_leasedSampleArray = null; 462 m_lastClientStateVersion = -1; 463 fireTreeStructureChanged( new TreeModelEvent ( this, m_root.getPath() ) ); 464 } 465 466 if ( m_connection.isConnected() ) 467 { 468 updateInstrumentManagerData( 470 m_connection.getInstrumentManager(), m_root, m_lastClientStateVersion ); 471 } 472 473 m_lastConnected = m_connection.isConnected(); 474 } 475 476 483 private void updateInstrumentManagerData( InstrumentManagerData manager, 484 DefaultMutableTreeNode rootTreeNode, 485 int oldStateVersion ) 486 { 487 int stateVersion = manager.getStateVersion(); 488 if ( stateVersion == oldStateVersion ) 489 { 490 return; 492 } 493 494 if ( getLogger().isDebugEnabled() ) 495 { 496 getLogger().debug( "update manager(" + manager.getName() + ") " 497 + "state new=" + stateVersion + ", old=" + oldStateVersion ); 498 } 499 500 InstrumentableData[] instrumentables = manager.getInstrumentables(); 502 int i; 503 for ( i = 0; i < instrumentables.length; i++ ) 504 { 505 InstrumentableData instrumentable = instrumentables[i]; 506 int oldInstrumentableStateVersion = -1; 507 DefaultMutableTreeNode newChild = null; 508 int childCount = rootTreeNode.getChildCount(); 509 if ( i < childCount ) 510 { 511 int cmp; 512 do { 513 DefaultMutableTreeNode oldChild = 514 (DefaultMutableTreeNode )rootTreeNode.getChildAt( i ); 515 cmp = ((InstrumentableNodeData)oldChild.getUserObject()).getDescription(). 516 compareTo( instrumentable.getDescription() ); 517 if ( cmp == 0 ) 518 { 519 InstrumentableNodeData nodeData = 521 (InstrumentableNodeData)oldChild.getUserObject(); 522 oldInstrumentableStateVersion = nodeData.getStateVersion(); 523 if ( nodeData.update() ) 524 { 525 fireTreeNodesChanged( new TreeModelEvent ( this, 527 rootTreeNode.getPath(), new int[] { i }, new Object [] { oldChild } ) ); 528 } 529 newChild = oldChild; 530 531 } 533 else if ( cmp > 0 ) 534 { 535 newChild = new DefaultMutableTreeNode ( 537 new InstrumentableNodeData( instrumentable ), true ); 538 rootTreeNode.insert( newChild, i ); 539 fireTreeNodesInserted( new TreeModelEvent ( this, 540 rootTreeNode.getPath(),new int[] { i }, new Object [] { newChild } ) ); 541 542 m_elementMap.put( ((InstrumentableNodeData)newChild.getUserObject()). 544 getName(), newChild ); 545 } 546 else if ( cmp < 0 ) 547 { 548 rootTreeNode.remove( i ); 550 fireTreeNodesRemoved( new TreeModelEvent ( this, 551 rootTreeNode.getPath(), new int[] { i }, new Object [] { oldChild } ) ); 552 553 m_elementMap.remove( ((InstrumentableNodeData)oldChild.getUserObject()). 555 getName() ); 556 } 557 } while ( cmp < 0 ); 558 } 559 else 560 { 561 newChild = new DefaultMutableTreeNode ( 563 new InstrumentableNodeData( instrumentable ), true ); 564 rootTreeNode.insert( newChild, i ); 565 fireTreeNodesInserted( new TreeModelEvent ( this, rootTreeNode.getPath(), 566 new int[] { i }, new Object [] { newChild } ) ); 567 568 m_elementMap.put( ((InstrumentableNodeData)newChild.getUserObject()). 570 getName(), newChild ); 571 } 572 573 updateInstrumentable( instrumentable, newChild, oldInstrumentableStateVersion ); 574 } 575 while ( i < rootTreeNode.getChildCount() ) 577 { 578 DefaultMutableTreeNode oldChild = (DefaultMutableTreeNode )rootTreeNode.getChildAt( i ); 580 rootTreeNode.remove( i ); 581 fireTreeNodesRemoved( new TreeModelEvent ( 582 this, rootTreeNode.getPath(), new int[] { i }, new Object [] { oldChild } ) ); 583 584 m_elementMap.remove( ((InstrumentableNodeData)oldChild.getUserObject()). 586 getName() ); 587 } 588 589 m_lastClientStateVersion = stateVersion; 590 } 591 592 598 private void updateInstrumentable( InstrumentableData instrumentableData, 599 DefaultMutableTreeNode instrumentableTreeNode, 600 int oldStateVersion ) 601 { 602 int stateVersion = instrumentableData.getStateVersion(); 603 if ( stateVersion == oldStateVersion ) 604 { 605 return; 607 } 608 609 if ( getLogger().isDebugEnabled() ) 610 { 611 getLogger().debug( "update instrumentable(" + instrumentableData.getName() + ") " 612 + "state new=" + stateVersion + ", old=" + oldStateVersion ); 613 } 614 615 InstrumentableData[] childInstrumentables = instrumentableData.getInstrumentables(); 617 int i; 619 for ( i = 0; i < childInstrumentables.length; i++ ) 620 { 621 InstrumentableData childInstrumentable = childInstrumentables[i]; 622 int oldInstrumentableStateVersion = -1; 623 DefaultMutableTreeNode newChild = null; 625 int childCount = instrumentableTreeNode.getChildCount(); 626 if ( i < childCount ) 627 { 628 int cmp; 629 do { 630 DefaultMutableTreeNode oldChild = 631 (DefaultMutableTreeNode )instrumentableTreeNode.getChildAt( i ); 632 if ( oldChild.getUserObject() instanceof InstrumentableNodeData ) 633 { 634 cmp = ((InstrumentableNodeData)oldChild.getUserObject()).getDescription(). 635 compareTo( childInstrumentable.getDescription() ); 636 } 637 else 638 { 639 cmp = 1; 641 } 642 643 if ( cmp == 0 ) 644 { 645 InstrumentableNodeData nodeData = 647 (InstrumentableNodeData)oldChild.getUserObject(); 648 oldInstrumentableStateVersion = nodeData.getStateVersion(); 649 if ( nodeData.update() ) 650 { 651 fireTreeNodesChanged( new TreeModelEvent ( this, 653 instrumentableTreeNode.getPath(), new int[] { i }, 654 new Object [] { oldChild } ) ); 655 } 656 newChild = oldChild; 657 658 } 660 else if ( cmp > 0 ) 661 { 662 newChild = new DefaultMutableTreeNode ( 664 new InstrumentableNodeData( childInstrumentable ), true ); 665 instrumentableTreeNode.insert( newChild, i ); 666 fireTreeNodesInserted( new TreeModelEvent ( this, 667 instrumentableTreeNode.getPath(),new int[] { i }, 668 new Object [] { newChild } ) ); 669 670 m_elementMap.put( ((InstrumentableNodeData)newChild.getUserObject()). 672 getName(), newChild ); 673 } 674 else if ( cmp < 0 ) 675 { 676 instrumentableTreeNode.remove( i ); 678 fireTreeNodesRemoved( new TreeModelEvent ( this, 679 instrumentableTreeNode.getPath(), new int[] { i }, 680 new Object [] { oldChild } ) ); 681 682 m_elementMap.remove( ((InstrumentableNodeData)oldChild.getUserObject()). 684 getName() ); 685 } 686 } while ( cmp < 0 ); 687 } 688 else 689 { 690 newChild = new DefaultMutableTreeNode ( 692 new InstrumentableNodeData( childInstrumentable ), true ); 693 instrumentableTreeNode.insert( newChild, i ); 694 fireTreeNodesInserted( new TreeModelEvent ( this, instrumentableTreeNode.getPath(), 695 new int[] { i }, new Object [] { newChild } ) ); 696 697 m_elementMap.put( ((InstrumentableNodeData)newChild.getUserObject()). 699 getName(), newChild ); 700 } 701 702 updateInstrumentable( childInstrumentable, newChild, oldInstrumentableStateVersion ); 703 } 704 while ( i < instrumentableTreeNode.getChildCount() ) 706 { 707 DefaultMutableTreeNode oldChild = 709 (DefaultMutableTreeNode )instrumentableTreeNode.getChildAt( i ); 710 if ( !( oldChild.getUserObject() instanceof InstrumentableNodeData ) ) 711 { 712 break; 713 } 714 715 instrumentableTreeNode.remove( i ); 716 fireTreeNodesRemoved( new TreeModelEvent ( 717 this, instrumentableTreeNode.getPath(), new int[] { i }, 718 new Object [] { oldChild } ) ); 719 720 m_elementMap.remove( ((InstrumentableNodeData)oldChild.getUserObject()). 722 getName() ); 723 } 724 725 726 InstrumentData[] instruments = 728 instrumentableData.getInstruments(); 729 for ( i = childInstrumentables.length; i < instruments.length + childInstrumentables.length; i++ ) 730 { 731 InstrumentData instrument = instruments[i - childInstrumentables.length]; 732 int oldInstrumentStateVersion = -1; 733 DefaultMutableTreeNode newChild = null; 735 int childCount = instrumentableTreeNode.getChildCount(); 736 if ( i < childCount ) 737 { 738 int cmp; 739 do { 740 DefaultMutableTreeNode oldChild = 741 (DefaultMutableTreeNode )instrumentableTreeNode.getChildAt( i ); 742 if ( oldChild.getUserObject() instanceof InstrumentNodeData ) 743 { 744 cmp = ((InstrumentNodeData)oldChild.getUserObject()).getDescription(). 745 compareTo( instrument.getDescription() ); 746 } 747 else 748 { 749 cmp = 1; 751 } 752 753 if ( cmp == 0 ) 754 { 755 InstrumentNodeData nodeData = (InstrumentNodeData)oldChild.getUserObject(); 757 oldInstrumentStateVersion = nodeData.getStateVersion(); 758 if ( nodeData.update() ) 759 { 760 fireTreeNodesChanged( new TreeModelEvent ( this, 762 instrumentableTreeNode.getPath(), new int[] { i }, 763 new Object [] { oldChild } ) ); 764 } 765 newChild = oldChild; 766 767 } 769 else if ( cmp > 0 ) 770 { 771 newChild = new DefaultMutableTreeNode ( 773 new InstrumentNodeData( instrument, m_connection ), true ); 774 instrumentableTreeNode.insert( newChild, i ); 775 fireTreeNodesInserted( new TreeModelEvent ( this, 776 instrumentableTreeNode.getPath(),new int[] { i }, 777 new Object [] { newChild } ) ); 778 779 m_elementMap.put( ((InstrumentNodeData)newChild.getUserObject()). 781 getName(), newChild ); 782 } 783 else if ( cmp < 0 ) 784 { 785 instrumentableTreeNode.remove( i ); 787 fireTreeNodesRemoved( new TreeModelEvent ( this, 788 instrumentableTreeNode.getPath(), new int[] { i }, 789 new Object [] { oldChild } ) ); 790 791 m_elementMap.remove( ((InstrumentNodeData)oldChild.getUserObject()). 793 getName() ); 794 } 795 } while ( cmp < 0 ); 796 } 797 else 798 { 799 newChild = new DefaultMutableTreeNode ( 801 new InstrumentNodeData( instrument, m_connection ), true ); 802 instrumentableTreeNode.insert( newChild, i ); 803 fireTreeNodesInserted( new TreeModelEvent ( this, instrumentableTreeNode.getPath(), 804 new int[] { i }, new Object [] { newChild } ) ); 805 806 m_elementMap.put( ((InstrumentNodeData)newChild.getUserObject()). 808 getName(), newChild ); 809 } 810 811 updateInstrument( instrument, newChild, oldInstrumentStateVersion ); 812 } 813 while ( i < instrumentableTreeNode.getChildCount() ) 815 { 816 DefaultMutableTreeNode oldChild = 818 (DefaultMutableTreeNode )instrumentableTreeNode.getChildAt( i ); 819 instrumentableTreeNode.remove( i ); 820 fireTreeNodesRemoved( new TreeModelEvent ( 821 this, instrumentableTreeNode.getPath(), new int[] { i }, 822 new Object [] { oldChild } ) ); 823 824 m_elementMap.remove( ((InstrumentNodeData)oldChild.getUserObject()). 826 getName() ); 827 } 828 } 829 830 833 void updateInstrument( InstrumentData instrumentData ) 834 { 835 DefaultMutableTreeNode instrumentTreeNode = 837 getInstrumentTreeNode( instrumentData.getName() ); 838 if ( instrumentTreeNode != null ) 839 { 840 updateInstrument( instrumentData, instrumentTreeNode, -1 ); 841 } 842 } 843 844 848 void updateInstrument( InstrumentData instrumentData, 849 DefaultMutableTreeNode instrumentTreeNode, 850 int oldStateVersion ) 851 { 852 int stateVersion = instrumentData.getStateVersion(); 853 if ( stateVersion == oldStateVersion ) 854 { 855 return; 857 } 858 859 if ( getLogger().isDebugEnabled() ) 860 { 861 getLogger().debug( "update instrument(" + instrumentData.getName() + ") " 862 + "state new=" + stateVersion + ", old=" + oldStateVersion ); 863 } 864 865 InstrumentSampleData[] samples = 867 instrumentData.getInstrumentSamples(); 868 int i; 870 for ( i = 0; i < samples.length; i++ ) 871 { 872 InstrumentSampleData sample = samples[i]; 873 DefaultMutableTreeNode newChild = null; 875 int childCount = instrumentTreeNode.getChildCount(); 876 if ( i < childCount ) 877 { 878 int cmp; 879 do { 880 DefaultMutableTreeNode oldChild = 882 (DefaultMutableTreeNode )instrumentTreeNode.getChildAt( i ); 883 cmp = ((InstrumentSampleNodeData)oldChild.getUserObject()). 884 getDescription().compareTo( sample.getDescription() ); 885 886 if ( cmp == 0 ) 887 { 888 if ( ((InstrumentSampleNodeData)oldChild.getUserObject()).update() ) 890 { 891 fireTreeNodesChanged( new TreeModelEvent ( this, 893 instrumentTreeNode.getPath(), new int[] { i }, 894 new Object [] { oldChild } ) ); 895 } 896 newChild = oldChild; 897 898 } 900 else if ( cmp > 0 ) 901 { 902 newChild = new DefaultMutableTreeNode ( 904 new InstrumentSampleNodeData( instrumentData.getName(), 905 sample, m_connection ), true ); 906 instrumentTreeNode.insert( newChild, i ); 907 fireTreeNodesInserted( new TreeModelEvent ( this, 908 instrumentTreeNode.getPath(),new int[] { i }, 909 new Object [] { newChild } ) ); 910 911 InstrumentSampleNodeData newNodeData = 913 (InstrumentSampleNodeData)newChild.getUserObject(); 914 String sampleName = newNodeData.getName(); 915 m_elementMap.put( sampleName, newChild ); 916 if ( newNodeData.isLeased() ) 917 { 918 m_leasedSampleMap.put( sampleName, newChild ); 919 m_leasedSampleArray = null; 920 } 921 922 MaintainedSampleLease lease = 924 m_connection.getMaintainedSampleLease( sampleName ); 925 if ( lease != null ) 926 { 927 newNodeData.setLeaseDuration( lease.getLeaseDuration() ); 928 } 929 } 930 else if ( cmp < 0 ) 931 { 932 instrumentTreeNode.remove( i ); 934 fireTreeNodesRemoved( new TreeModelEvent ( this, 935 instrumentTreeNode.getPath(), new int[] { i }, 936 new Object [] { oldChild } ) ); 937 938 InstrumentSampleNodeData oldNodeData = 940 (InstrumentSampleNodeData)oldChild.getUserObject(); 941 String sampleName = oldNodeData.getName(); 942 m_elementMap.remove( sampleName ); 943 if ( oldNodeData.isLeased() ) 944 { 945 m_leasedSampleMap.remove( sampleName ); 946 m_leasedSampleArray = null; 947 } 948 } 949 } while ( cmp < 0 ); 950 } 951 else 952 { 953 newChild = new DefaultMutableTreeNode ( 955 new InstrumentSampleNodeData( instrumentData.getName(), sample, m_connection ), 956 true ); 957 instrumentTreeNode.insert( newChild, i ); 958 fireTreeNodesInserted( new TreeModelEvent ( this, instrumentTreeNode.getPath(), 959 new int[] { i }, new Object [] { newChild } ) ); 960 961 InstrumentSampleNodeData newNodeData = 963 (InstrumentSampleNodeData)newChild.getUserObject(); 964 String sampleName = newNodeData.getName(); 965 m_elementMap.put( sampleName, newChild ); 966 if ( newNodeData.isLeased() ) 967 { 968 m_leasedSampleMap.put( sampleName, newChild ); 969 m_leasedSampleArray = null; 970 } 971 972 MaintainedSampleLease lease = 974 m_connection.getMaintainedSampleLease( sampleName ); 975 if ( lease != null ) 976 { 977 newNodeData.setLeaseDuration( lease.getLeaseDuration() ); 978 } 979 } 980 } 981 while ( i < instrumentTreeNode.getChildCount() ) 983 { 984 DefaultMutableTreeNode oldChild = 986 (DefaultMutableTreeNode )instrumentTreeNode.getChildAt( i ); 987 988 instrumentTreeNode.remove( i ); 989 fireTreeNodesRemoved( new TreeModelEvent ( 990 this, instrumentTreeNode.getPath(), new int[] { i }, 991 new Object [] { oldChild } ) ); 992 993 InstrumentSampleNodeData oldNodeData = 995 (InstrumentSampleNodeData)oldChild.getUserObject(); 996 String sampleName = oldNodeData.getName(); 997 m_elementMap.remove( sampleName ); 998 if ( oldNodeData.isLeased() ) 999 { 1000 m_leasedSampleMap.remove( sampleName ); 1001 m_leasedSampleArray = null; 1002 } 1003 } 1004 } 1005 1006 1009 void updateInstrumentSample( InstrumentSampleData sampleData ) 1010 { 1011 DefaultMutableTreeNode sampleTreeNode = 1013 getInstrumentSampleTreeNode( sampleData.getName() ); 1014 if ( sampleTreeNode != null ) 1015 { 1016 updateInstrumentSample( sampleData, sampleTreeNode ); 1017 } 1018 } 1019 1020 1024 void updateInstrumentSample( InstrumentSampleData sampleData, 1025 DefaultMutableTreeNode sampleTreeNode ) 1026 { 1027 ((InstrumentSampleNodeData)sampleTreeNode.getUserObject()).update(); 1029 1030 fireTreeNodesChanged( new TreeModelEvent ( this, 1032 sampleTreeNode.getPath(), new int[ 0 ], new Object [ 0 ] ) ); 1033 } 1034} 1035 | Popular Tags |