com.intellij.ide.util.treeView.NodeDescriptor Java Examples

The following examples show how to use com.intellij.ide.util.treeView.NodeDescriptor. 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: ProjectViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private Object getSelectedNodeElement() {
  final AbstractProjectViewPane currentProjectViewPane = getCurrentProjectViewPane();
  if (currentProjectViewPane == null) { // can happen if not initialized yet
    return null;
  }
  DefaultMutableTreeNode node = currentProjectViewPane.getSelectedNode();
  if (node == null) {
    return null;
  }
  Object userObject = node.getUserObject();
  if (userObject instanceof AbstractTreeNode) {
    return ((AbstractTreeNode)userObject).getValue();
  }
  if (!(userObject instanceof NodeDescriptor)) {
    return null;
  }
  return ((NodeDescriptor)userObject).getElement();
}
 
Example #2
Source File: SlingServerTreeStructure.java    From aem-ide-tooling-4-intellij with Apache License 2.0 6 votes vote down vote up
@Override
@NotNull
public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
    if(element == myRoot) {
        return new RootNodeDescriptorSling(myProject, parentDescriptor);
    }

    if(element instanceof String) {
        return new TextInfoNodeDescriptorSling(myProject, parentDescriptor, (String) element);
    }

    if(element instanceof ServerConfiguration) {
        return new SlingServerNodeDescriptor(myProject, parentDescriptor, (ServerConfiguration) element);
    }

    if(element instanceof ServerConfiguration.Module) {
        return new SlingServerModuleNodeDescriptor(myProject, parentDescriptor, (ServerConfiguration.Module) element);
    }

    LOG.error("Unknown element for this tree structure " + element);
    return null;
}
 
Example #3
Source File: ContentEntryTreeCellRenderer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);

  final ContentEntryEditor editor = myTreeEditor.getContentEntryEditor();
  if (editor != null) {
    final Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
    if (userObject instanceof NodeDescriptor) {
      final Object element = ((NodeDescriptor)userObject).getElement();
      if (element instanceof FileElement) {
        final VirtualFile file = ((FileElement)element).getFile();
        if (file != null && file.isDirectory()) {
          final ContentEntry contentEntry = editor.getContentEntry();
          if (contentEntry != null) {
            setIcon(updateIcon(contentEntry, file, TargetAWT.from(getIcon())));
          }
        }
      }
    }
  }
}
 
Example #4
Source File: CertificateTreeBuilder.java    From consulo with Apache License 2.0 6 votes vote down vote up
public CertificateTreeBuilder(@Nonnull Tree tree) {
  init(tree, new DefaultTreeModel(new DefaultMutableTreeNode()), new MyTreeStructure(), new Comparator<NodeDescriptor>() {
    @Override
    public int compare(NodeDescriptor o1, NodeDescriptor o2) {
      if (o1 instanceof OrganizationDescriptor && o2 instanceof OrganizationDescriptor) {
        return ((String)o1.getElement()).compareTo((String)o2.getElement());
      }
      else if (o1 instanceof CertificateDescriptor && o2 instanceof CertificateDescriptor) {
        String cn1 = ((CertificateDescriptor)o1).getElement().getSubjectField(COMMON_NAME);
        String cn2 = ((CertificateDescriptor)o2).getElement().getSubjectField(COMMON_NAME);
        return cn1.compareTo(cn2);
      }
      return 0;
    }
  }, true);
  initRootNode();
}
 
Example #5
Source File: TfsTreeBuilder.java    From azure-devops-intellij with MIT License 6 votes vote down vote up
public int compare(NodeDescriptor o1, NodeDescriptor o2) {
    if (o1 instanceof TfsErrorTreeNode) {
        return o2 instanceof TfsErrorTreeNode ? ((TfsErrorTreeNode) o1).getMessage().compareTo(((TfsErrorTreeNode) o2).getMessage()) : -1;
    } else if (o2 instanceof TfsErrorTreeNode) {
        return 1;
    }

    final TfsTreeNode n1 = (TfsTreeNode) o1;
    final TfsTreeNode n2 = (TfsTreeNode) o2;
    if (n1.isDirectory() && !n2.isDirectory()) {
        return -1;
    } else if (!n1.isDirectory() && n2.isDirectory()) {
        return 1;
    }

    return n1.getFileName().compareToIgnoreCase(n2.getFileName());
}
 
Example #6
Source File: TodoFileDirAndModuleComparator.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public int compare(NodeDescriptor obj1, NodeDescriptor obj2){
  final int weight1 = obj1.getWeight();
  final int weight2 = obj2.getWeight();
  if (weight1 != weight2) return weight1 - weight2;
  if (obj1 instanceof ProjectViewNode && obj2 instanceof ProjectViewNode) {
    return ((ProjectViewNode)obj1).getTitle().compareToIgnoreCase(((ProjectViewNode)obj2).getTitle());
  }
  if (obj1 instanceof ModuleToDoNode && obj2 instanceof ModuleToDoNode){
    return ((ModuleToDoNode)obj1).getValue().getName().compareToIgnoreCase(((ModuleToDoNode)obj2).getValue().getName());
  } else if(obj1 instanceof ModuleToDoNode) {
    return -1;
  } else if(obj2 instanceof ModuleToDoNode) {
    return 1;
  } else{
    throw new IllegalArgumentException(obj1.getClass().getName()+","+obj2.getClass().getName());
  }
}
 
Example #7
Source File: LibraryTreeStructure.java    From consulo with Apache License 2.0 6 votes vote down vote up
public LibraryTreeStructure(LibraryRootsComponent parentElement, LibraryRootsComponentDescriptor componentDescriptor) {
  myParentEditor = parentElement;
  myComponentDescriptor = componentDescriptor;
  myRootElementDescriptor = new NodeDescriptor(null, null) {
    @RequiredUIAccess
    @Override
    public boolean update() {
      myName = ProjectBundle.message("library.root.node");
      return false;
    }
    @Override
    public Object getElement() {
      return this;
    }
  };
}
 
Example #8
Source File: TreeStructureWrappenModel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void fetchChildren(@Nonnull Function<T, TreeNode<T>> nodeFactory, @Nullable T parentValue) {
  ThrowableComputable<Object[],RuntimeException> action = () -> myStructure.getChildElements(parentValue);
  for (Object o : AccessRule.read(action)) {
    T element = (T)o;
    TreeNode<T> apply = nodeFactory.apply(element);

    apply.setLeaf(o instanceof AbstractTreeNode && !((AbstractTreeNode)o).isAlwaysShowPlus());


    apply.setRender((fileElement, itemPresentation) -> {
      NodeDescriptor descriptor = myStructure.createDescriptor(element, null);

      descriptor.update();

      itemPresentation.append(descriptor.toString());
      try {
        AccessRule.read(() -> itemPresentation.setIcon(descriptor.getIcon()));
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    });
  }
}
 
Example #9
Source File: ViewerTreeStructure.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
  if (element == myRootElement) {
    return new NodeDescriptor(myProject, null) {
      @RequiredUIAccess
      @Override
      public boolean update() {
        return false;
      }
      @Override
      public Object getElement() {
        return myRootElement;
      }
    };
  }
  return new ViewerNodeDescriptor(myProject, element, parentDescriptor);
}
 
Example #10
Source File: WebProjectViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
private Object getSelectedNodeElement() {
  final AbstractProjectViewPane currentProjectViewPane = getCurrentProjectViewPane();
  if (currentProjectViewPane == null) { // can happen if not initialized yet
    return null;
  }
  DefaultMutableTreeNode node = currentProjectViewPane.getSelectedNode();
  if (node == null) {
    return null;
  }
  Object userObject = node.getUserObject();
  if (userObject instanceof AbstractTreeNode) {
    return ((AbstractTreeNode)userObject).getValue();
  }
  if (!(userObject instanceof NodeDescriptor)) {
    return null;
  }
  return ((NodeDescriptor)userObject).getElement();
}
 
Example #11
Source File: TodoPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean hasNextOccurence() {
  TreePath path = myTree.getSelectionPath();
  if (path == null) {
    return false;
  }
  DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
  Object userObject = node.getUserObject();
  if (userObject == null) {
    return false;
  }
  if (userObject instanceof NodeDescriptor && ((NodeDescriptor)userObject).getElement() instanceof TodoItemNode) {
    return myTree.getRowCount() != myTree.getRowForPath(path) + 1;
  }
  else {
    return node.getChildCount() > 0;
  }
}
 
Example #12
Source File: NewProjectTreeStructure.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public NodeDescriptor createDescriptor(@Nonnull Object element, @Nullable NodeDescriptor parentDescriptor) {
  return new PresentableNodeDescriptor(null, parentDescriptor) {

    @Override
    protected void update(PresentationData presentation) {
      if (element instanceof NewModuleContextNode) {
        boolean isGroup = element instanceof NewModuleContextGroup;
        presentation.addText(((NewModuleContextNode)element).getName().getValue(), isGroup ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES : SimpleTextAttributes.REGULAR_ATTRIBUTES);
        presentation.setIcon(((NewModuleContextNode)element).getImage());
      }
    }

    @Override
    public Object getElement() {
      return element;
    }
  };
}
 
Example #13
Source File: FilteringTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FilteringTreeBuilder(Tree tree, ElementFilter filter, AbstractTreeStructure structure, @Nullable Comparator<? super NodeDescriptor> comparator) {
  super(tree, (DefaultTreeModel)tree.getModel(), structure instanceof FilteringTreeStructure ? structure : new FilteringTreeStructure(filter, structure), comparator);

  myTree = tree;
  initRootNode();

  if (filter instanceof ElementFilter.Active) {
    ((ElementFilter.Active)filter).addListener(new ElementFilter.Listener() {
      @Nonnull
      @Override
      public Promise<?> update(final Object preferredSelection, final boolean adjustSelection, final boolean now) {
        return refilter(preferredSelection, adjustSelection, now);
      }
    }, this);
  }

  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      TreePath newPath = e.getNewLeadSelectionPath();
      if (newPath != null) {
        Object element = getElementFor(newPath.getLastPathComponent());
        if (element != null) {
          myLastSuccessfulSelect = element;
        }
      }
    }
  });
}
 
Example #14
Source File: FileTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean isAlwaysShowPlus(NodeDescriptor nodeDescriptor) {
  Object element = nodeDescriptor.getElement();
  if (element != null) {
    FileElement descriptor = (FileElement)element;
    VirtualFile file = descriptor.getFile();
    if (file != null) {
      if (myChooserDescriptor.isChooseJarContents() && FileElement.isArchive(file)) {
        return true;
      }
      return file.isDirectory();
    }
  }
  return true;
}
 
Example #15
Source File: StructureTreeModel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private Node(@Nonnull NodeDescriptor descriptor, @Nonnull LeafState leafState, int hashCode) {
  super(descriptor, leafState != LeafState.ALWAYS);
  this.leafState = leafState;
  this.hashCode = hashCode;
  if (leafState == LeafState.ALWAYS) children.set(null); // validate children for leaf node
  update(); // an exception may be thrown while updating
}
 
Example #16
Source File: SMTRunnerTreeStructure.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public SMTRunnerNodeDescriptor createDescriptor(final Object element,
                                                final NodeDescriptor parentDesc) {
  //noinspection unchecked
  return new SMTRunnerNodeDescriptor(myProject,
                                     (SMTestProxy)element,
                                     (NodeDescriptor<SMTestProxy>)parentDesc);
}
 
Example #17
Source File: HaxeCallReferenceProcessor.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public CallData(PsiClass originalClass,
                             PsiMethod methodToFind,
                             PsiClassType originalType,
                             PsiMethod method,
                             Set<PsiMethod> methodsToFind,
                             NodeDescriptor nodeDescriptor,
                             Map<PsiMember, NodeDescriptor> resultMap,
                             Project project,
                             HaxeHierarchyTimeoutHandler timeoutHandler) {
  super(originalClass, methodToFind, originalType, method, methodsToFind, nodeDescriptor, resultMap, project);
  myTimeoutHandler = timeoutHandler;
}
 
Example #18
Source File: ErrorViewTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected boolean isAlwaysShowPlus(NodeDescriptor nodeDescriptor) {
  final ErrorTreeElement element = (ErrorTreeElement)nodeDescriptor.getElement();
  if (element instanceof GroupingElement) {
    return ((ErrorViewStructure)getTreeStructure()).getChildCount((GroupingElement)element) > 0;
  }
  return false;
}
 
Example #19
Source File: LibraryTreeRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
  Object userObject = node.getUserObject();
  if (userObject instanceof NodeDescriptor) {
    final NodeDescriptor descriptor = (NodeDescriptor)userObject;
    setIcon(descriptor.getIcon());
    append(descriptor.toString(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, descriptor.getColor()));
  }
}
 
Example #20
Source File: ProjectViewImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static SelectionInfo create(final AbstractProjectViewPane viewPane) {
  List<Object> selectedElements = Collections.emptyList();
  if (viewPane != null) {
    final TreePath[] selectionPaths = viewPane.getSelectionPaths();
    if (selectionPaths != null) {
      selectedElements = new ArrayList<>();
      for (TreePath path : selectionPaths) {
        NodeDescriptor descriptor = TreeUtil.getLastUserObject(NodeDescriptor.class, path);
        if (descriptor != null) selectedElements.add(descriptor.getElement());
      }
    }
  }
  return new SelectionInfo(selectedElements.toArray());
}
 
Example #21
Source File: FilteringTreeStructure.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
protected void doUpdate() {
  clearColoredText();
  if (myDelegate instanceof PresentableNodeDescriptor) {
    PresentableNodeDescriptor node = (PresentableNodeDescriptor)myDelegate;
    node.update();
    apply(node.getPresentation());
  }
  else if (myDelegate != null) {
    NodeDescriptor descriptor = myBaseStructure.createDescriptor(myDelegate, getParentDescriptor());
    descriptor.update();
    setIcon(descriptor.getIcon());
    setPlainText(myDelegate.toString());
  }
}
 
Example #22
Source File: AbstractListBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public final void goUp() {
  if (myCurrentParent == myShownRoot.getParent()) {
    return;
  }
  final AbstractTreeNode element = myCurrentParent.getParent();
  if (element == null) {
    return;
  }

  try {
    AbstractTreeNode oldParent = myCurrentParent;

    buildList(element);

    for (int i = 0; i < myModel.getSize(); i++) {
      if (myModel.getElementAt(i) instanceof NodeDescriptor) {
        final NodeDescriptor desc = (NodeDescriptor)myModel.getElementAt(i);
        final Object elem = desc.getElement();
        if (oldParent.equals(elem)) {
          selectItem(i);
          break;
        }
      }
    }
  }
  finally {
    updateParentTitle();
  }
}
 
Example #23
Source File: ProjectViewTree.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public final int getToggleClickCount() {
  int count = super.getToggleClickCount();
  TreePath path = getSelectionPath();
  if (path != null) {
    NodeDescriptor descriptor = TreeUtil.getLastUserObject(NodeDescriptor.class, path);
    if (descriptor != null && !descriptor.expandOnDoubleClick()) {
      LOG.debug("getToggleClickCount: -1 for ", descriptor.getClass().getName());
      return -1;
    }
  }
  return count;
}
 
Example #24
Source File: ExcludeFromCompileAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
private VirtualFile getSelectedFile() {
  final ErrorTreeNodeDescriptor descriptor = myErrorTreeView.getSelectedNodeDescriptor();
  ErrorTreeElement element = descriptor != null? descriptor.getElement() : null;
  if (element != null && !(element instanceof GroupingElement)) {
    NodeDescriptor parent = descriptor.getParentDescriptor();
    if (parent instanceof ErrorTreeNodeDescriptor) {
      element = ((ErrorTreeNodeDescriptor)parent).getElement();
    }
  }
  return element instanceof GroupingElement? ((GroupingElement)element).getFile() : null;
}
 
Example #25
Source File: TodoPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void updatePreviewPanel() {
  if (myProject == null || myProject.isDisposed()) return;
  List<UsageInfo> infos = new ArrayList<>();
  final TreePath path = myTree.getSelectionPath();
  if (path != null) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
    Object userObject = node.getUserObject();
    if (userObject instanceof NodeDescriptor) {
      Object element = ((NodeDescriptor)userObject).getElement();
      TodoItemNode pointer = myTodoTreeBuilder.getFirstPointerForElement(element);
      if (pointer != null) {
        final SmartTodoItemPointer value = pointer.getValue();
        final Document document = value.getDocument();
        final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
        final RangeMarker rangeMarker = value.getRangeMarker();
        if (psiFile != null) {
          infos.add(new UsageInfo(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset()));
          for (RangeMarker additionalMarker : value.getAdditionalRangeMarkers()) {
            if (additionalMarker.isValid()) {
              infos.add(new UsageInfo(psiFile, additionalMarker.getStartOffset(), additionalMarker.getEndOffset()));
            }
          }
        }
      }
    }
  }
  myUsagePreviewPanel.updateLayout(infos.isEmpty() ? null : infos);
}
 
Example #26
Source File: FileTreeStructure.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
  LOG.assertTrue(element instanceof FileElement, element.getClass().getName());
  VirtualFile file = ((FileElement)element).getFile();
  Image icon = file == null ? null : myChooserDescriptor.getIcon(file);
  String name = file == null ? null : myChooserDescriptor.getName(file);
  String comment = file == null ? null : myChooserDescriptor.getComment(file);

  return new FileNodeDescriptor(myProject, (FileElement)element, parentDescriptor, icon, name, comment);
}
 
Example #27
Source File: FileSystemTreeImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected AbstractTreeBuilder createTreeBuilder(final JTree tree,
                                                DefaultTreeModel treeModel,
                                                final AbstractTreeStructure treeStructure,
                                                final Comparator<NodeDescriptor> comparator,
                                                FileChooserDescriptor descriptor,
                                                @Nullable final Runnable onInitialized) {
  return new FileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
}
 
Example #28
Source File: TodoCompositeRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object obj, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  Component result;

  Object userObject = ((DefaultMutableTreeNode)obj).getUserObject();
  if (userObject instanceof SummaryNode) {
    myNodeRenderer.getTreeCellRendererComponent(tree, userObject.toString(), selected, expanded, leaf, row, hasFocus);
    myNodeRenderer.setFont(UIUtil.getTreeFont().deriveFont(Font.BOLD));
    myNodeRenderer.setIcon(null);
    result = myNodeRenderer;
  }
  else if (userObject instanceof TodoItemNode && !((TodoItemNode)userObject).getAdditionalLines().isEmpty()) {
    myMultiLineRenderer.getTreeCellRendererComponent(tree, obj, selected, expanded, leaf, row, hasFocus);
    result = myMultiLineRenderer;
  }
  else if (userObject instanceof NodeDescriptor && userObject instanceof HighlightedRegionProvider) {
    NodeDescriptor descriptor = (NodeDescriptor)userObject;
    HighlightedRegionProvider regionProvider = (HighlightedRegionProvider)userObject;
    myColorTreeCellRenderer.getTreeCellRendererComponent(tree, obj, selected, expanded, leaf, row, hasFocus);
    for (HighlightedRegion region : regionProvider.getHighlightedRegions()) {
      myColorTreeCellRenderer.addHighlighter(region.startOffset, region.endOffset, region.textAttributes);
    }
    myColorTreeCellRenderer.setIcon(TargetAWT.to(descriptor.getIcon()));
    result = myColorTreeCellRenderer;
  }
  else {
    result = myNodeRenderer.getTreeCellRendererComponent(tree, obj, selected, expanded, leaf, row, hasFocus);
  }

  if (result instanceof JComponent) {
    ((JComponent)result).setOpaque(!selected);
  }

  return result;
}
 
Example #29
Source File: CertificateTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public NodeDescriptor createDescriptor(Object element, NodeDescriptor parentDescriptor) {
  if (element == RootDescriptor.ROOT) {
    return ROOT_DESCRIPTOR;
  }
  else if (element instanceof String) {
    return new OrganizationDescriptor(parentDescriptor, (String)element);
  }
  return new CertificateDescriptor(parentDescriptor, (CertificateWrapper)element);
}
 
Example #30
Source File: ChooseLibrariesDialogBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected LibraryTableDescriptor(final Project project,
                                 final NodeDescriptor parentDescriptor,
                                 final LibraryTable table,
                                 final int weight,
                                 boolean autoExpand) {
  super(project, parentDescriptor, table);
  myWeight = weight;
  myAutoExpand = autoExpand;
  getTemplatePresentation().setIcon(AllIcons.Nodes.PpLib);
  final String nodeText = table.getPresentation().getDisplayName(true);
  getTemplatePresentation().addText(notEmpty(nodeText), SimpleTextAttributes.REGULAR_ATTRIBUTES);
}