Java Code Examples for javax.swing.tree.ExpandVetoException

The following examples show how to use javax.swing.tree.ExpandVetoException. 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: leetcode-editor   Source File: TreeWillListener.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {

    TreePath selPath = event.getPath();
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) selPath.getLastPathComponent();
    Question question = (Question) node.getUserObject();
    if (!isOneOpen(node)) {
        return;
    } else if ("lock".equals(question.getStatus())) {
        MessageUtils.showMsg(toolWindow.getContentManager().getComponent(), MessageType.INFO, "info", "no permissions");
        throw new ExpandVetoException(event);
    }
    ProgressManager.getInstance().run(new Task.Backgroundable(project,"leetcode.editor.tree",false) {
        @Override
        public void run(@NotNull ProgressIndicator progressIndicator) {
            loadData(question,node,selPath,tree,toolWindow);
        }
    });
    throw new ExpandVetoException(event);
}
 
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: 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 4
Source Project: netbeans   Source File: TreeView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void treeWillExpand(TreeExpansionEvent event)
throws ExpandVetoException {
    // prepare wait cursor and optionally show it
    TreePath path = event.getPath();
    prepareWaitCursor(DragDropUtilities.secureFindNode(path.getLastPathComponent()));
}
 
Example 5
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 6
Source Project: netbeans   Source File: EventBroadcaster.java    License: Apache License 2.0 5 votes vote down vote up
/** Receives a TreeWillExpand event and constructs a TableModelEvent
 * based on the pending changes while the model still reflects the unchanged
 * state */
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
    assert SwingUtilities.isEventDispatchThread();

    log ("treeWillExpand", event);
    
    //Construct the TableModelEvent here, before data structures have
    //changed.  We will fire it from TreeExpanded if the change is not
    //vetoed
    pendingExpansionEvent = translateEvent (event, true);
    
    log ("treeWillExpand generated", pendingExpansionEvent);
    inProgressEvent = event;
}
 
Example 7
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 8
Source Project: netbeans   Source File: TreePathSupport.java    License: Apache License 2.0 5 votes vote down vote up
private void fireTreeExpansionVetoed (TreeExpansionEvent e, ExpandVetoException ex) {
    int size = weListeners.size();
    
    TreeWillExpandListener[] listeners = new TreeWillExpandListener[size];
    synchronized (this) {
        listeners = weListeners.toArray(listeners);
    }
    for (int i=0; i < listeners.length; i++) {
        if (listeners[i] instanceof ExtTreeWillExpandListener) {
            ((ExtTreeWillExpandListener) listeners[i]).treeExpansionVetoed(e,
                ex);
        }
    }
}
 
Example 9
Source Project: openjdk-jdk9   Source File: JTreeOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTree.fireTreeWillCollapse(TreePath)} through queue
 */
public void fireTreeWillCollapse(final TreePath treePath) {
    runMapping(new MapVoidAction("fireTreeWillCollapse") {
        @Override
        public void map() throws ExpandVetoException {
            ((JTree) getSource()).fireTreeWillCollapse(treePath);
        }
    });
}
 
Example 10
Source Project: openjdk-jdk9   Source File: JTreeOperator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTree.fireTreeWillExpand(TreePath)} through queue
 */
public void fireTreeWillExpand(final TreePath treePath) {
    runMapping(new MapVoidAction("fireTreeWillExpand") {
        @Override
        public void map() throws ExpandVetoException {
            ((JTree) getSource()).fireTreeWillExpand(treePath);
        }
    });
}
 
Example 11
Source Project: megan-ce   Source File: ViewerJTree.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 (classificationViewer.isLocked()) {
        throw new ExpandVetoException(event);
    }
    jTree.addChildren((ViewerJTree.MyJTreeNode) event.getPath().getLastPathComponent());
}
 
Example 12
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 13
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 14
Source Project: i18n-editor   Source File: TranslationTree.java    License: MIT License 5 votes vote down vote up
@Override
 	public void treeWillCollapse(TreeExpansionEvent e) throws ExpandVetoException {
// Prevent root key from being collapsed
 		if (e.getPath().getPathCount() == 1) {
 			throw new ExpandVetoException(e);        			
 		}
 	}
 
Example 15
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 16
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();
    String name = file.getName();
    // System.out.println(name);
    if (!name.isEmpty() && name.codePointAt(0) == '.') {
      throw new ExpandVetoException(e, "Tree expansion cancelled");
    }
  }
}
 
Example 17
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 18
Source Project: netbeans   Source File: TreeView.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void treeWillCollapse(TreeExpansionEvent event)
throws ExpandVetoException {
}
 
Example 19
Source Project: netbeans   Source File: ProfilerTreeTable.java    License: Apache License 2.0 4 votes vote down vote up
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
    Object expanding = event.getPath().getLastPathComponent();
    if (expanding instanceof TreeNode) nodeExpanding((TreeNode)expanding);
}
 
Example 20
Source Project: netbeans   Source File: ProfilerTreeTable.java    License: Apache License 2.0 4 votes vote down vote up
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
    Object collapsing = event.getPath().getLastPathComponent();
    if (collapsing instanceof TreeNode) nodeCollapsing((TreeNode)collapsing);
}
 
Example 21
Source Project: visualvm   Source File: ProfilerTreeTable.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
    Object expanding = event.getPath().getLastPathComponent();
    if (expanding instanceof TreeNode) nodeExpanding((TreeNode)expanding);
}
 
Example 22
Source Project: visualvm   Source File: ProfilerTreeTable.java    License: GNU General Public License v2.0 4 votes vote down vote up
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
    Object collapsing = event.getPath().getLastPathComponent();
    if (collapsing instanceof TreeNode) nodeCollapsing((TreeNode)collapsing);
}
 
Example 23
Source Project: i18n-editor   Source File: TranslationTree.java    License: MIT License 4 votes vote down vote up
@Override
public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException {}
 
Example 24
Source Project: jsqsh   Source File: Tree.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void treeWillCollapse(final TreeExpansionEvent event)
        throws ExpandVetoException {

}
 
Example 25
public void treeWillExpand( final TreeExpansionEvent event ) throws ExpandVetoException {
  addExpandedNode( getRowForPath( event.getPath() ) );
}
 
Example 26
public void treeWillCollapse( final TreeExpansionEvent event ) throws ExpandVetoException {
  removeExpandedNode( getRowForPath( event.getPath() ) );
}
 
Example 27
Source Project: consulo   Source File: InspectionTree.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
  InspectionTreeNode node = (InspectionTreeNode)event.getPath().getLastPathComponent();
  myExpandedUserObjects.remove(node.getUserObject());
}
 
Example 28
Source Project: consulo   Source File: ScopeTreeViewPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
}
 
Example 29
/**
 * Invoked whenever a node in the tree is about to be expanded.
 */
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException;
 
Example 30
/**
 * Invoked whenever a node in the tree is about to be collapsed.
 */
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException;