Java Code Examples for javax.swing.event.TreeExpansionEvent

The following examples show how to use javax.swing.event.TreeExpansionEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: consulo   Source File: FileChooserDialogImpl.java    License: Apache License 2.0 6 votes vote down vote up
public void treeExpanded(TreeExpansionEvent event) {
  final Object[] path = event.getPath().getPath();
  if (path.length == 2 && path[1] instanceof DefaultMutableTreeNode) {
    // top node has been expanded => watch disk recursively
    final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path[1];
    Object userObject = node.getUserObject();
    if (userObject instanceof FileNodeDescriptor) {
      final VirtualFile file = ((FileNodeDescriptor)userObject).getElement().getFile();
      if (file != null && file.isDirectory()) {
        final String rootPath = file.getPath();
        if (myRequests.get(rootPath) == null) {
          final LocalFileSystem.WatchRequest watchRequest = LocalFileSystem.getInstance().addRootToWatch(rootPath, true);
          myRequests.put(rootPath, watchRequest);
        }
      }
    }
  }
}
 
Example 2
Source Project: netbeans   Source File: EventBroadcaster.java    License: Apache License 2.0 6 votes vote down vote up
/** Messaged if the tree expansion event (for which we will have already
 * constructed a TableModelEvent) was vetoed;  disposes of the constructed
 * TableModelEvent in that circumstance. */
@Override
public void treeExpansionVetoed(TreeExpansionEvent event, ExpandVetoException exception) {
    assert SwingUtilities.isEventDispatchThread();
    
    log ("treeExpansionVetoed", exception);
    
    //Make sure the event that was vetoed is the one we're interested in
    if (event == inProgressEvent) {
        //If so, delete the expansion event we thought we were going
        //to use in treeExpanded/treeCollapsed, so that it doesn't
        //stick around forever holding references to objects from the
        //model
        pendingExpansionEvent = null;
        inProgressEvent = null;
    }
}
 
Example 3
Source Project: netbeans   Source File: TreeModelRoot.java    License: Apache License 2.0 6 votes vote down vote up
private Object initExpandCollapseNotify(TreeExpansionEvent event) {
    Node node = Visualizer.findNode(event.getPath ().getLastPathComponent());
    Object obj = node.getLookup().lookup(Object.class);
    Object actOn;
    node = node.getParentNode();
    if (node == null) {
        actOn = new Integer(0);
    } else {
        Children ch = node.getChildren();
        if (ch instanceof TreeModelNode.TreeModelChildren) {
            actOn = ((TreeModelNode.TreeModelChildren) ch).getTreeDepth();
        } else {
            actOn = ch;
        }
    }
    Models.CompoundModel model = getModel();
    if (model != null) {
        DefaultTreeExpansionManager.get(model).setChildrenToActOn(actOn);
    }
    return obj;
}
 
Example 4
Source Project: netbeans   Source File: DirectoryChooserUI.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void treeExpanded(TreeExpansionEvent evt) {
    TreePath path = evt.getPath();
    DirectoryNode node = (DirectoryNode) path
            .getLastPathComponent();
    if(!node.isLoaded()) {
        expandNode(fileChooser, path);
    } else {
        // fixed #96954, to be able to add a new directory
        // when the node has been already loaded
        if(addNewDirectory) {
            addNewDirectory(path);
            addNewDirectory = false;
        }
        // Fix for IZ#123815 : Cannot refresh the tree content
        refreshNode( path , node );
    }
}
 
Example 5
Source Project: Luyten   Source File: Model.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void treeExpanded(final TreeExpansionEvent event) {
	final TreePath treePath = event.getPath();

	final Object expandedTreePathObject = treePath.getLastPathComponent();
	if (!(expandedTreePathObject instanceof TreeNode)) {
		return;
	}

	final TreeNode expandedTreeNode = (TreeNode) expandedTreePathObject;
	if (expandedTreeNode.getChildCount() == 1) {
		final TreeNode descendantTreeNode = expandedTreeNode.getChildAt(0);

		if (descendantTreeNode.isLeaf()) {
			return;
		}

		final TreePath nextTreePath = treePath.pathByAddingChild(descendantTreeNode);
		tree.expandPath(nextTreePath);
	}
}
 
Example 6
Source Project: consulo   Source File: InspectionTree.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
  final InspectionTreeNode node = (InspectionTreeNode)event.getPath().getLastPathComponent();
  final Object userObject = node.getUserObject();
  //TODO: never re-sort
  if (node.isValid() && !myExpandedUserObjects.contains(userObject)) {
    sortChildren(node);
    nodeStructureChanged(node);
  }
  myExpandedUserObjects.add(userObject);
  // Smart expand
  if (node.getChildCount() == 1) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        expandPath(new TreePath(node.getPath()));
      }
    });
  }
}
 
Example 7
public void treeExpanded(TreeExpansionEvent event) {
  // ensure children gets expanded later
  if (event.getPath() != null) {
    Object lastElement = event.getPath().getLastPathComponent();
    if (lastElement instanceof FileTreeNode && useNodeQueue) {
      if (((FileTreeNode)lastElement).isLoaded()) {
        for (Enumeration e = ((FileTreeNode)lastElement).children();
          e.hasMoreElements();
          ) {
          //Object node = enum.nextElement();
          addToQueue((FileTreeNode)e.nextElement(), tree);
        }
      }
    }
  }
}
 
Example 8
Source Project: consulo   Source File: ScopeTreeViewPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
  final TreePath path = event.getPath();
  if (path == null) return;
  final PackageDependenciesNode node = (PackageDependenciesNode)path.getLastPathComponent();
  node.sortChildren();
  ((DefaultTreeModel)myTree.getModel()).reload(node);
}
 
Example 9
private void setExpandedState(TreeExpansionEvent event, boolean shouldExpand) {
//AS TODO: Make sure this code is really not needed (3/1/2017)
//            final TreePath path = event.getPath();
//            final AbstractTreeUi ui = getUi();
//            final Object lastPathComponent = path.getLastPathComponent();
//            if(lastPathComponent != null) {
//                final Object element = ui.getElementFor(lastPathComponent);
//                if(element instanceof BaseNodeDescriptor) {
////          ((BaseNodeDescriptor)element).setShouldExpand(shouldExpand);
//                }
//            }
        }
 
Example 10
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {
  TreePath path = e.getPath();
  Object o = path.getLastPathComponent();
  if (o instanceof DefaultMutableTreeNode) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
    File file = (File) node.getUserObject();
    if (file.isFile()) {
      throw new ExpandVetoException(e, "Tree expansion cancelled");
    }
  }
}
 
Example 11
Source Project: stendhal   Source File: FileTree.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void treeExpanded(final TreeExpansionEvent evt) {
	// The expanded path
	final TreePath path = evt.getPath();
	// The tree
	final JTree tree = (JTree) evt.getSource();

	// Get the last component of the path and
	// arrange to have it fully populated.
	final FileTreeNode node = (FileTreeNode) path.getLastPathComponent();
	if (node.populateDirectories(true)) {
		((DefaultTreeModel) tree.getModel()).nodeStructureChanged(node);
	}
}
 
Example 12
Source Project: netbeans   Source File: ResultsOutlineSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void treeExpanded(TreeExpansionEvent event) {
    if (!expansionListenerEnabled) {
        return;
    }
    Object lpc = event.getPath().getLastPathComponent();
    Node node = Visualizer.findNode(lpc);
    if (node != null) {
        expandOnlyChilds(node);
    }
}
 
Example 13
Source Project: netbeans   Source File: EventBroadcaster.java    License: Apache License 2.0 5 votes vote down vote up
/** Receives a TreeWillCollapse event and constructs a TableModelEvent
 * based on the pending changes while the model still reflects the unchanged
 * state */
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
    assert SwingUtilities.isEventDispatchThread();
    
    log ("treeWillCollapse", event);
    
    //Construct the TableModelEvent here, before data structures have
    //changed.  We will fire it from TreeCollapsed if the change is 
    //not vetoed.
    pendingExpansionEvent = translateEvent (event, false);
    log ("treeWillCollapse generated ", pendingExpansionEvent);
    inProgressEvent = event;
}
 
Example 14
Source Project: megan-ce   Source File: InspectorWindow.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Invoked whenever a node in the tree is about to be collapsed.
 */
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
    if (inspectorWindow.isLocked()) {
        if (dir.getDocument().getProgressListener() != null)
            dir.getDocument().getProgressListener().setUserCancelled(true);
        throw new ExpandVetoException(event);
    }
}
 
Example 15
Source Project: netbeans   Source File: EventBroadcaster.java    License: Apache License 2.0 5 votes vote down vote up
/** Updates the layout to mark the descendants of the events path as also
 * expanded if they were the last it was expanded, then fires a table change. */
@Override
public void treeExpanded(TreeExpansionEvent event) {
    assert SwingUtilities.isEventDispatchThread();
    
    log ("treeExpanded", event);
    
    //Mysterious how the event could be null, but JTree tests it
    //so we will too.
    if(event != null) {
        updateExpandedDescendants(event.getPath());
    }

    log ("about to fire", pendingExpansionEvent);
    
    //Now fire a change on the owning row so its display is updated (it
    //may have just become an expandable node)
    int row;
    if (event != null) {
        TreePath path = event.getPath();
        row = getLayout().getRowForPath(path);
    } else {
        row = -1;
    }
    TableModelEvent evt;
    if (row == -1) {
        evt = new TableModelEvent(getModel());
    } else {
        evt = new TableModelEvent(getModel(), row, row, 0, TableModelEvent.UPDATE);
    }
    fireTableChange(new TableModelEvent[] {evt, pendingExpansionEvent});
    
    pendingExpansionEvent = null;
    inProgressEvent = null;
}
 
Example 16
Source Project: netbeans   Source File: TreePathSupport.java    License: Apache License 2.0 5 votes vote down vote up
private void fireTreeWillExpand (TreeExpansionEvent e, boolean expanded) throws ExpandVetoException {
    int size = weListeners.size();
    
    TreeWillExpandListener[] listeners = new TreeWillExpandListener[size];
    synchronized (this) {
        listeners = weListeners.toArray(listeners);
    }
    for (int i=0; i < listeners.length; i++) {
        if (expanded) {
            listeners[i].treeWillExpand(e);
        } else {
            listeners[i].treeWillCollapse(e);
        }
    }
}
 
Example 17
Source Project: IrScrutinizer   Source File: TreeImporter.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void treeExpanded(TreeExpansionEvent event) {
    DefaultMutableTreeNode remote = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    if (!Remote.class.isInstance(remote.getUserObject())) // Just to be on the safe side...
        return;

    for (Enumeration e = remote.children(); e.hasMoreElements();) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        Command command = (Command) node.getUserObject();
    }
}
 
Example 18
Source Project: megan-ce   Source File: InspectorWindow.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Invoked whenever a node in the tree is about to be expanded.
 */
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
    if (inspectorWindow.isLocked()) {
        if (dir.getDocument().getProgressListener() != null)
            dir.getDocument().getProgressListener().setUserCancelled(true);
        throw new ExpandVetoException(event);
    }

    final TreePath path = event.getPath();
    final NodeBase node = (NodeBase) path.getLastPathComponent();
    if (node.getChildCount() > 0) { // has already been expanded
        if (node.isCompleted())
            return;
        else {
            int result = JOptionPane.showConfirmDialog(inspectorWindow.getFrame(), "List of children incomplete, re-fetch?", "Re-fetch", JOptionPane.YES_NO_CANCEL_OPTION);
            if (result == JOptionPane.NO_OPTION)
                return;
            else if (result == JOptionPane.CANCEL_OPTION)
                throw new ExpandVetoException(event);
            else // remove all children to trigger re-download
                node.removeAllChildren();
        }
    }

    if (node instanceof TopLevelNode) {
        inspectorWindow.addChildren((TopLevelNode) node);
    } else if (node instanceof ReadHeadLineNode) {
        inspectorWindow.addChildren((ReadHeadLineNode) node, path.getPathComponent(1).toString());
    }
    if (node instanceof ReadDataHeadLineNode) {
        inspectorWindow.addChildren((ReadDataHeadLineNode) node);
    } else if (node instanceof MatchHeadLineNode) {
        inspectorWindow.addChildren((MatchHeadLineNode) node);
    }
}
 
Example 19
Source Project: netbeans   Source File: Browser.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void treeExpanded(TreeExpansionEvent event) {
    Object obj = event.getPath().getLastPathComponent();
    if(obj == null) return;
    Node n = Visualizer.findNode(obj);
    if(n instanceof RepositoryPathNode) {
        RepositoryPathNode node = (RepositoryPathNode) n;
        node.expand();
    }
}
 
Example 20
Source Project: consulo   Source File: FileSystemTreeImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void treeExpanded(final TreeExpansionEvent event) {
  if (myTreeBuilder == null || !myTreeBuilder.isNodeBeingBuilt(event.getPath())) return;

  TreePath path = event.getPath();
  DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
  if (node.getUserObject() instanceof FileNodeDescriptor) {
    FileNodeDescriptor nodeDescriptor = (FileNodeDescriptor)node.getUserObject();
    final FileElement fileDescriptor = nodeDescriptor.getElement();
    final VirtualFile virtualFile = fileDescriptor.getFile();
    if (virtualFile != null) {
      if (!myEverExpanded.contains(virtualFile)) {
        if (virtualFile instanceof NewVirtualFile) {
          ((NewVirtualFile)virtualFile).markDirty();
        }
        myEverExpanded.add(virtualFile);
      }


      final boolean async = myTreeBuilder.isToBuildChildrenInBackground(virtualFile);
      if (virtualFile instanceof NewVirtualFile) {
        RefreshQueue.getInstance().refresh(async, false, null, ModalityState.stateForComponent(myTree), virtualFile);
      }
      else {
        virtualFile.refresh(async, false);
      }
    }
  }
}
 
Example 21
Source Project: pdfxtk   Source File: Preferences.java    License: Apache License 2.0 5 votes vote down vote up
public void treeExpanded(TreeExpansionEvent event) {
     tree = (JTree)event.getSource();
     
     if(tree.getParent().getParent() instanceof JScrollPane)
SwingUtilities.invokeLater(this);
     
     state.add(event.getPath(), tree);
   }
 
Example 22
Source Project: netbeans   Source File: TreeModelRoot.java    License: Apache License 2.0 5 votes vote down vote up
/**
  * Called whenever an item in the tree has been expanded.
  */
public void treeExpanded (TreeExpansionEvent event) {
    Models.CompoundModel model = getModel();
    if (model != null) {
        model.nodeExpanded (initExpandCollapseNotify(event));
    }
}
 
Example 23
Source Project: netbeans   Source File: TreeModelRoot.java    License: Apache License 2.0 5 votes vote down vote up
/**
  * Called whenever an item in the tree has been collapsed.
  */
public void treeCollapsed (TreeExpansionEvent event) {
    Models.CompoundModel model = getModel();
    if (model != null) {
        model.nodeCollapsed (initExpandCollapseNotify(event));
    }
}
 
Example 24
Source Project: megan-ce   Source File: InspectorWindow.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called whenever an item in the tree has been collapsed.
 */
public void treeCollapsed(TreeExpansionEvent event) {
    final TreePath path = event.getPath();
    final NodeBase node = (NodeBase) path.getLastPathComponent();
    if (!inspectorWindow.getClassification2RootNode().containsValue(node)) {
        //node.removeAllChildren();
        DefaultTreeModel model = (DefaultTreeModel) inspectorWindow.dataTree.getModel();
        model.nodeStructureChanged(node);
    }
    inspectorWindow.updateView(Director.ALL);
}
 
Example 25
Source Project: nextreports-designer   Source File: DBBrowserTree.java    License: Apache License 2.0 5 votes vote down vote up
public void treeExpanded(TreeExpansionEvent ev) {
	final TreePath path = ev.getPath();
	final Object parentObj = path.getLastPathComponent();
	if (parentObj instanceof DBBrowserNode) {
		startExpandingTree((DBBrowserNode) parentObj, false, null);
		// expandedPathNames.put(path.toString(), null);
	}
}
 
Example 26
@Override
public void treeExpanded(TreeExpansionEvent event) {
  final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)event.getPath().getLastPathComponent();
  maybeLoadChildren(treeNode);

  if (!programaticExpansionInProgress) {
    lastExpanded = treeNode;
    animateTo(treeNode);
  }
}
 
Example 27
Source Project: consulo   Source File: FileChooserDialogImpl.java    License: Apache License 2.0 4 votes vote down vote up
public void treeCollapsed(TreeExpansionEvent event) {
}
 
Example 28
@Override
public void treeCollapsed(TreeExpansionEvent event)
{
	saveExpansionState();
}
 
Example 29
@Override
public void treeExpanded(TreeExpansionEvent aEvent) {
	DefaultMutableTreeNode theNode = (DefaultMutableTreeNode) aEvent
			.getPath().getLastPathComponent();
	expandedUserObjects.add(theNode.getUserObject());
}
 
Example 30
Source Project: IrScrutinizer   Source File: TreeImporter.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}