public void init() { getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) getCellRenderer(); setCellRenderer(new BrowserTreeCellRenderer()); // // Keep up to date with whats clicked when.... getSelectionModel().addTreeSelectionListener(this); addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { maybeDoBrowse(e); } public void mousePressed(MouseEvent e) { maybeDoPopup(e); } public void mouseReleased(MouseEvent e) { maybeDoPopup(e); } }); DataTipManager.get().register(this); try { getDropTarget().addDropTargetListener(this); } catch (TooManyListenersException e1) { log.error(e1.getMessage(), e1); } popupMenu = PopupMenuFactory.createBrowserTreePopup(this); }
private void init() { JPanel quickSearchPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); final TreeModel treeModel = explorer.getTreeModel(); final QuickTreeFilterField field = new QuickTreeFilterField(treeModel) { protected FilterableTreeModel createDisplayTreeModel(TreeModel treeModel) { return new FilterableTreeModel(treeModel) { @Override protected void configureListModelWrapper(ListModelWrapper wrapper, Object node) { if (node instanceof DefaultMutableTreeNode) { // ImageFileExplorer.LazyNode inode = (ImageFileExplorer.LazyNode) node; DefaultMutableTreeNode inode = (DefaultMutableTreeNode) node; boolean expanded = explorer.getJTree().isExpanded(new TreePath(inode.getPath())); if (inode.isLeaf() || expanded) { super.configureListModelWrapper(wrapper, node); } } } }; } }; field.setSearchingDelay(200); quickSearchPanel.add(field); JPanel treePanel = new JPanel(new BorderLayout(2, 2)); field.setTree(explorer.getJTree()); SearchableUtils.installSearchable(field.getTree()); JTree tree = field.getTree(); tree.setModel(field.getDisplayTreeModel()); DataTipManager.get().register(tree); treePanel.add(explorer.getComponent()); mainPanel.add(treePanel); mainPanel.add(quickSearchPanel, BorderLayout.BEFORE_FIRST_LINE); EventBus.subscribeStrongly( DataSourceStatusEvent.class, new EventSubscriber<DataSourceStatusEvent>() { @Override public void onEvent(DataSourceStatusEvent event) { explorer.getJTree().repaint(); } }); mainPanel.putClientProperty(IActionProvider.KEY, this); }