/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2001 Sun * Microsystems, Inc. All Rights Reserved. */ package net.hrebejk.modules.explorertest; import java.util.*; import javax.swing.*; import javax.swing.tree.*; import javax.swing.event.*; import java.beans.*; import java.beans.beancontext.*; import org.openide.nodes.*; import org.openide.explorer.*; import org.openide.explorer.view.*; import org.openide.util.NbBundle; import org.openide.util.Lookup; import org.openide.util.actions.*; import org.openide.util.HelpCtx; public class RefBrowser extends ExplorerPanel { public RefBrowser() { initGui(); } private void initGui() { //Node rootNode = createBeanNode(); Node rootNode = null; rootNode = new AbstractNode( new MyChildren() ); rootNode.setName( "ROOT" ); ExplorerPanel panel = new ExplorerPanel(); add( new MyBeanTreeView() ); getExplorerManager().setRootContext( rootNode ); } private static Node createBeanNode() { // Building a nested bean context BeanContext context = new BeanContextSupport(); context.add( new String() ); context.add( new JComboBox() ); BeanContextSupport context2 = new BeanContextSupport(); context2.add( new JLabel("label") ); context.add( context2 ); System.out.println("CTX " + context ); for( Iterator it = context.iterator(); it.hasNext(); ) { System.out.println( it.next() ); } System.out.println( "PEER " + context2.getBeanContextPeer() ); Node rootNode = null; // And viewing it in a tree view. try { rootNode = new BeanNode( context ); return rootNode; } catch(IntrospectionException ex) { return null; } } public static void main ( String[] args ) { RefBrowser rb = new RefBrowser(); rb.open(); } private class MyChildren extends Children.Keys { protected void addNotify() { System.out.println("ADD NOTIFY : " + Timer.TIMER ); RefBrowser.this.setCursor( org.openide.util.Utilities.createProgressCursor( RefBrowser.this ) ); ArrayList al = new ArrayList(); for ( int i = 0; i < 10000; i++ ) { al.add( new Integer( i ) ); //Thread.sleep( 200 ); } setKeys( al ); //RefBrowser.this.setCursor( null ); System.out.println("KEYS SET : " + Timer.TIMER ); //setKeys( Arrays.asList( new String[] { "A", "B", "C" } ) ); } protected Node[] createNodes(Object key) { AbstractNode an = new AbstractNode( new MyChildren() ); an.setName( key.toString() ); if ( key instanceof Integer && ((Integer)key).intValue() == 9999 ) { System.out.println("NODES CREATED " + Timer.TIMER ); RefBrowser.this.setCursor( null ); } return new Node[] { an }; } } private static class MyBeanTreeView extends BeanTreeView implements TreeWillExpandListener, TreeExpansionListener { MyBeanTreeView( ) { tree.addTreeWillExpandListener( this ); tree.addTreeExpansionListener( this ); } public JTree getJTree() { return tree; } /** Invoked whenever a node in the tree is about to be collapsed. * */ public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { } /** Invoked whenever a node in the tree is about to be expanded. * */ public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { System.out.println("WILL EXPAND :" + Timer.TIMER ); } /** Called whenever an item in the tree has been collapsed. * */ public void treeCollapsed(TreeExpansionEvent event) { } /** Called whenever an item in the tree has been expanded. * */ public void treeExpanded(TreeExpansionEvent event) { System.out.println("EXPANDED :" + Timer.TIMER ); } } private static class Timer { public static final Timer TIMER = new Timer(); long lastTime; Timer() { lastTime = System.currentTimeMillis(); } public String toString() { long currTime = System.currentTimeMillis(); String s = /*"CURR " + currTime + */ " DELTA : " + ( currTime - lastTime ); lastTime = currTime; return s; } } }