Java Code Examples for com.intellij.util.ui.tree.TreeUtil#getUserObject()

The following examples show how to use com.intellij.util.ui.tree.TreeUtil#getUserObject() . 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 File: StructureViewComponent.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void treeNodesInserted(TreeModelEvent e) {
  TreePath parentPath = e.getTreePath();
  if (Boolean.TRUE.equals(UIUtil.getClientProperty(tree, STRUCTURE_VIEW_STATE_RESTORED_KEY))) return;
  if (parentPath == null || parentPath.getPathCount() > autoExpandDepth.asInteger() - 1) return;
  Object[] children = e.getChildren();
  if (smartExpand && children.length == 1) {
    expandLater(parentPath, children[0]);
  }
  else {
    for (Object o : children) {
      NodeDescriptor descriptor = TreeUtil.getUserObject(NodeDescriptor.class, o);
      if (descriptor != null && isAutoExpandNode(descriptor)) {
        expandLater(parentPath, o);
      }
    }
  }
}
 
Example 2
Source File: TodoPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void treeNodesInserted(TreeModelEvent e) {
  TreePath parentPath = e.getTreePath();
  if (parentPath == null || parentPath.getPathCount() > 2) return;
  Object[] children = e.getChildren();
  for (Object o : children) {
    NodeDescriptor descriptor = TreeUtil.getUserObject(NodeDescriptor.class, o);
    if (descriptor != null && myBuilder.isAutoExpandNode(descriptor)) {
      ApplicationManager.getApplication().invokeLater(() -> {
        if (myTree.isVisible(parentPath) && myTree.isExpanded(parentPath)) {
          myTree.expandPath(parentPath.pathByAddingChild(o));
        }
      }, myBuilder.myProject.getDisposed());
    }
  }
}
 
Example 3
Source File: AbstractProjectViewPane.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Object getData(@Nonnull Key<?> dataId) {
  Object data = myTreeStructure instanceof AbstractTreeStructureBase ? ((AbstractTreeStructureBase)myTreeStructure).getDataFromProviders(getSelectedNodes(AbstractTreeNode.class), dataId) : null;
  if (data != null) {
    return data;
  }
  if (CommonDataKeys.NAVIGATABLE_ARRAY == dataId) {
    TreePath[] paths = getSelectionPaths();
    if (paths == null) return null;
    final ArrayList<Navigatable> navigatables = new ArrayList<>();
    for (TreePath path : paths) {
      Object node = path.getLastPathComponent();
      Object userObject = TreeUtil.getUserObject(node);
      if (userObject instanceof Navigatable) {
        navigatables.add((Navigatable)userObject);
      }
      else if (node instanceof Navigatable) {
        navigatables.add((Navigatable)node);
      }
    }
    return navigatables.isEmpty() ? null : navigatables.toArray(new Navigatable[0]);
  }
  return null;
}
 
Example 4
Source File: TreeState.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static List<PathElement> createPath(@Nonnull TreeModel model, @Nonnull TreePath treePath) {
  Object prev = null;
  int count = treePath.getPathCount();
  PathElement[] result = new PathElement[count];
  for (int i = 0; i < count; i++) {
    Object cur = treePath.getPathComponent(i);
    Object userObject = TreeUtil.getUserObject(cur);
    int childIndex = prev == null ? 0 : model.getIndexOfChild(prev, cur);
    result[i] = new PathElement(calcId(userObject), calcType(userObject), childIndex, userObject);
    prev = cur;
  }
  return Arrays.asList(result);
}
 
Example 5
Source File: ProjectViewTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
public ProjectViewTree(TreeModel model) {
  super(model);

  final NodeRenderer cellRenderer = new NodeRenderer() {
    @Override
    protected void doPaint(Graphics2D g) {
      super.doPaint(g);
      setOpaque(false);
    }

    @Override
    public void customizeCellRenderer(@Nonnull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
      super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
      Object object = TreeUtil.getUserObject(value);
      //if (object instanceof ProjectViewNode && UISettings.getInstance().getShowInplaceComments()) {
      //  VirtualFile file = ((ProjectViewNode)object).getVirtualFile();
      //  File ioFile = file == null || file.isDirectory() || !file.isInLocalFileSystem() ? null : VfsUtilCore.virtualToIoFile(file);
      //  BasicFileAttributes attr = null;
      //  try {
      //    attr = ioFile == null ? null : Files.readAttributes(Paths.get(ioFile.toURI()), BasicFileAttributes.class);
      //  }
      //  catch (Exception ignored) {
      //  }
      //  if (attr != null) {
      //    append("  ");
      //    SimpleTextAttributes attributes = SimpleTextAttributes.GRAYED_SMALL_ATTRIBUTES;
      //    append(DateFormatUtil.formatDateTime(attr.lastModifiedTime().toMillis()), attributes);
      //    append(", " + StringUtil.formatFileSize(attr.size()), attributes);
      //  }
      //}
    }
  };
  cellRenderer.setOpaque(false);
  cellRenderer.setIconOpaque(false);
  setCellRenderer(cellRenderer);
  cellRenderer.setTransparentIconBackground(true);

  HintUpdateSupply.installDataContextHintUpdateSupply(this);
}
 
Example 6
Source File: TreeState.java    From consulo with Apache License 2.0 4 votes vote down vote up
private Match getMatchTo(Object object) {
  Object userObject = TreeUtil.getUserObject(object);
  if (this.userObject != null && this.userObject.equals(userObject)) return Match.OBJECT;
  return Comparing.equal(id, calcId(userObject)) && Comparing.equal(type, calcType(userObject)) ? Match.ID_TYPE : null;
}
 
Example 7
Source File: StructureViewComponent.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public static Object unwrapNavigatable(Object o) {
  Object p = TreeUtil.getUserObject(o);
  return p instanceof FilteringTreeStructure.FilteringNode ? ((FilteringTreeStructure.FilteringNode)p).getDelegate() : p;
}