com.intellij.ui.treeStructure.SimpleTree Java Examples

The following examples show how to use com.intellij.ui.treeStructure.SimpleTree. 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: RestfulWindowToolWindowFactory.java    From NutzCodeInsight with Apache License 2.0 6 votes vote down vote up
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
    final SimpleTree apiTree = new SimpleTree();
    apiTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.toolWindowEx = (ToolWindowEx) toolWindow;
    RefreshAction refreshAction = new RefreshAction("刷新", "重新加载URL", AllIcons.Actions.Refresh, toolWindowEx, apiTree);
    toolWindowEx.setTitleActions(refreshAction, actionManager.getAction("GoToRequestMapping"));
    apiTree.addMouseListener(new ApiTreeMouseAdapter(apiTree));
    ContentManager contentManager = toolWindow.getContentManager();
    Content content = contentManager.getFactory().createContent(new RestServicesNavigatorPanel(apiTree), null, false);
    contentManager.addContent(content);
    contentManager.setSelectedContent(content);
    if (project.isInitialized()) {
        refreshAction.loadTree(project);
    }
}
 
Example #2
Source File: RestServicesNavigatorPanel.java    From NutzCodeInsight with Apache License 2.0 5 votes vote down vote up
public RestServicesNavigatorPanel(SimpleTree tree) {
    super(true, true);
    this.apiTree = tree;
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(this.apiTree);
    scrollPane.setBorder(BorderFactory.createLineBorder(Color.RED));
    servicesContentPaneSplitter = new Splitter(true, .5f);
    servicesContentPaneSplitter.setShowDividerControls(true);
    servicesContentPaneSplitter.setDividerWidth(10);
    servicesContentPaneSplitter.setBorder(BorderFactory.createLineBorder(Color.RED));
    servicesContentPaneSplitter.setFirstComponent(scrollPane);
    setContent(servicesContentPaneSplitter);
}
 
Example #3
Source File: GraphQLSchemaErrorNode.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void handleDoubleClickOrEnter(SimpleTree tree, InputEvent inputEvent) {
    final SourceLocation location = getLocation();
    if (location != null && location.getSourceName() != null) {
        GraphQLTreeNodeNavigationUtil.openSourceLocation(myProject, location, false);
    } else if (error instanceof GraphQLInternalSchemaError) {
        String stackTrace = ExceptionUtil.getThrowableText(((GraphQLInternalSchemaError) error).getException());
        PsiFile file = PsiFileFactory.getInstance(myProject).createFileFromText("graphql-error.txt", PlainTextLanguage.INSTANCE, stackTrace);
        new OpenFileDescriptor(myProject, file.getVirtualFile()).navigate(true);
    }
}
 
Example #4
Source File: GraphQLSchemaEndpointsListNode.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void handleDoubleClickOrEnter(SimpleTree tree, InputEvent inputEvent) {

    final String introspect = "Get GraphQL Schema from Endpoint (introspection)";
    final String createScratch = "New GraphQL Scratch File (for query, mutation testing)";
    ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>("Choose Endpoint Action", introspect, createScratch) {

        @Override
        public PopupStep onChosen(String selectedValue, boolean finalChoice) {
            return doFinalStep(() -> {
                if (introspect.equals(selectedValue)) {
                    GraphQLIntrospectionHelper.getService(myProject).performIntrospectionQueryAndUpdateSchemaPathFile(myProject, endpoint);
                } else if (createScratch.equals(selectedValue)) {
                    final String configBaseDir = endpoint.configPackageSet.getConfigBaseDir().getPresentableUrl();
                    final String text = "# " + GRAPHQLCONFIG_COMMENT + configBaseDir + "!" + Optional.ofNullable(projectKey).orElse("") + "\n\nquery ScratchQuery {\n\n}";
                    final VirtualFile scratchFile = ScratchRootType.getInstance().createScratchFile(myProject, "scratch.graphql", GraphQLLanguage.INSTANCE, text);
                    if (scratchFile != null) {
                        FileEditor[] fileEditors = FileEditorManager.getInstance(myProject).openFile(scratchFile, true);
                        for (FileEditor editor : fileEditors) {
                            if (editor instanceof TextEditor) {
                                final JSGraphQLEndpointsModel endpointsModel = ((TextEditor) editor).getEditor().getUserData(JS_GRAPH_QL_ENDPOINTS_MODEL);
                                if (endpointsModel != null) {
                                    endpointsModel.setSelectedItem(endpoint);
                                }
                            }
                        }
                    }
                }
            });
        }
    });
    if (inputEvent instanceof KeyEvent) {
        listPopup.showInFocusCenter();
    } else if (inputEvent instanceof MouseEvent) {
        listPopup.show(new RelativePoint((MouseEvent) inputEvent));
    }
}
 
Example #5
Source File: FilteringTreeBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
private Object getSelected() {
  if (isSimpleTree()) {
    FilteringTreeStructure.FilteringNode selected = (FilteringTreeStructure.FilteringNode)((SimpleTree)myTree).getSelectedNode();
    return selected != null ? selected.getDelegate() : null;
  }
  else {
    final Object[] nodes = myTree.getSelectedNodes(Object.class, null);
    return nodes.length > 0 ? nodes[0] : null;
  }
}
 
Example #6
Source File: ComplexPackagingElementNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void handleDoubleClickOrEnter(SimpleTree tree, InputEvent inputEvent) {
  mySubstitutionParameters.setShowContent(this);
  final LayoutTree layoutTree = (LayoutTree)tree;
  final CompositePackagingElementNode parentNode = getParentNode();
  if (parentNode != null) {
    layoutTree.addSubtreeToUpdate(parentNode);
  }
}
 
Example #7
Source File: DependencyViewer.java    From gradle-view with Apache License 2.0 5 votes vote down vote up
public void updateView(GradleNode rootDependency, final GradleNode selectedDependency) {
    // TODO replace this hack with something that populates the GradleNode graph

    DefaultMutableTreeNode fullRoot = new DefaultMutableTreeNode(new GradleNode("Project Dependencies"));
    if(rootDependency == null) {
        DefaultMutableTreeNode loading = new DefaultMutableTreeNode(new GradleNode("Loading..."));
        fullRoot.add(loading);
    } else {
        DefaultMutableTreeNode flattenedRoot = convertToSortedTreeNode(rootDependency);
        DefaultMutableTreeNode hierarchyRoot = convertToHierarchyTreeNode(rootDependency);
        fullRoot.add(flattenedRoot);
        fullRoot.add(hierarchyRoot);
    }

    TreeModel treeModel = new DefaultTreeModel(fullRoot);
    final SimpleTree fullTree = new SimpleTree(treeModel);
    fullTree.setCellRenderer(dependencyCellRenderer);

    // expand path for first level from root
    //fullTree.expandPath(new TreePath(hierarchyRoot.getNextNode().getPath()));

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if(gradleBaseDir != null) {
                toolWindow.setTitle("- " + gradleBaseDir);
            }
            splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(fullTree));
            splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(information));
        }
    });
}
 
Example #8
Source File: TreeMouseListener.java    From leetcode-editor with Apache License 2.0 4 votes vote down vote up
public TreeMouseListener(SimpleTree tree, Project project) {
    this.tree = tree;
    this.project = project;
}
 
Example #9
Source File: CSharpAssemblyFileEditor.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public JComponent getComponent()
{
	DefaultMutableTreeNode root = new DefaultMutableTreeNode();

	for(CSharpAssemblyBlock block : myBlocks)
	{
		DefaultMutableTreeNode newChild = new DefaultMutableTreeNode(block);

		root.add(newChild);
	}

	final SimpleTree simpleTree = new SimpleTree(new DefaultTreeModel(root));
	simpleTree.setRootVisible(false);
	simpleTree.setCellRenderer(new ColoredTreeCellRenderer()
	{
		@RequiredUIAccess
		@Override
		public void customizeCellRenderer(JTree jTree, Object o, boolean b, boolean b2, boolean b3, int i, boolean b4)
		{
			Object object = ((DefaultMutableTreeNode) o).getUserObject();
			if(object instanceof CSharpAssemblyBlock)
			{
				append(((CSharpAssemblyBlock) object).getTitle());
			}
		}
	});

	final OnePixelSplitter splitter = new OnePixelSplitter();
	simpleTree.addTreeSelectionListener(new TreeSelectionListener()
	{
		@Override
		public void valueChanged(TreeSelectionEvent e)
		{
			List<CSharpAssemblyBlock> cSharpAssemblyBlocks = TreeUtil.collectSelectedObjectsOfType(simpleTree, CSharpAssemblyBlock.class);

			CSharpAssemblyBlock firstItem = ContainerUtil.getFirstItem(cSharpAssemblyBlocks);
			if(firstItem == null)
			{
				splitter.setSecondComponent(new JPanel());
			}
			else
			{

				splitter.setSecondComponent(firstItem.createAndLoadComponent(myPsiFile, !myIsReadonlyFile));
			}
		}
	});

	splitter.setAndLoadSplitterProportionKey("CSharpAssemblyFileEditor");

	splitter.setFirstComponent(simpleTree);
	splitter.setSecondComponent(new JPanel());

	return ScrollPaneFactory.createScrollPane(splitter);
}
 
Example #10
Source File: CrucibleFilterNode.java    From Crucible4IDEA with MIT License 4 votes vote down vote up
@Override
public void handleSelection(SimpleTree tree) {
  super.handleSelection(tree);
  myReviewModel.updateModel(myFilter);
}
 
Example #11
Source File: CruciblePanel.java    From Crucible4IDEA with MIT License 4 votes vote down vote up
public CruciblePanel(@NotNull final Project project) {
  super(false);
  myProject = project;

  final JBSplitter splitter = new JBSplitter(false, 0.2f);

  myReviewModel = new CrucibleReviewModel(project);
  myReviewTable = new JBTable(myReviewModel);
  myReviewTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  myReviewTable.setStriped(true);
  myReviewTable.setExpandableItemsEnabled(false);

  final TableColumnModel columnModel = myReviewTable.getColumnModel();
  columnModel.getColumn(1).setCellRenderer(new DescriptionCellRenderer());

  setUpColumnWidths(myReviewTable);
  myReviewTable.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
      if (e.getClickCount() == 2) {
        final int viewRow = myReviewTable.getSelectedRow();
        if (viewRow >= 0 &&  viewRow < myReviewTable.getRowCount()) {
          ApplicationManager.getApplication().invokeLater(new Runnable() {
            @Override
            public void run() {
              final Review review =
                CrucibleManager.getInstance(myProject).getDetailsForReview((String)myReviewTable.
                  getValueAt(viewRow, myReviewTable.getColumnModel().getColumnIndex(CrucibleBundle.message("crucible.id"))));
              if (review != null) {
                openDetailsToolWindow(review);
                myReviewTable.clearSelection();
              }
            }
          }, ModalityState.stateForComponent(myReviewTable));

        }
      }
  }});

  final TableRowSorter<TableModel> rowSorter = new TableRowSorter<TableModel>(myReviewModel);
  rowSorter.setSortKeys(Collections.singletonList(new RowSorter.SortKey(4, SortOrder.ASCENDING)));
  rowSorter.sort();
  myReviewTable.setRowSorter(rowSorter);

  final JScrollPane detailsScrollPane = ScrollPaneFactory.createScrollPane(myReviewTable);

  final SimpleTreeStructure reviewTreeStructure = createTreeStructure();
  final DefaultTreeModel model = new CrucibleTreeModel();
  final SimpleTree reviewTree = new SimpleTree(model);

  new AbstractTreeBuilder(reviewTree, model, reviewTreeStructure, null);
  reviewTree.invalidate();

  final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(reviewTree);
  splitter.setFirstComponent(scrollPane);
  splitter.setSecondComponent(detailsScrollPane);
  setContent(splitter);
}
 
Example #12
Source File: FilteringTreeBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean isSimpleTree() {
  return myTree instanceof SimpleTree;
}
 
Example #13
Source File: GenerateByPatternDialog.java    From consulo with Apache License 2.0 4 votes vote down vote up
public GenerateByPatternDialog(Project project, PatternDescriptor[] descriptors, DataContext context) {
  super(project);
  setTitle("Generate by Pattern");
  setOKButtonText("Generate");

  myMap = new MultiMap<String, PatternDescriptor>();
  for (PatternDescriptor descriptor : descriptors) {
    myMap.putValue(descriptor.getParentId(), descriptor);
  }
  DefaultMutableTreeNode root = createNode(null);

  myTree = new SimpleTree() {

  };
  myTree.setRootVisible(false);
  myTree.setCellRenderer(new DefaultTreeCellRenderer() {
    @Override
    public Component getTreeCellRendererComponent(JTree tree,
                                                  Object value,
                                                  boolean sel,
                                                  boolean expanded,
                                                  boolean leaf,
                                                  int row,
                                                  boolean hasFocus) {
      Component component = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,

                                                                         hasFocus);
      Object object = ((DefaultMutableTreeNode)value).getUserObject();
      if (object instanceof PatternDescriptor) {
        setText(((PatternDescriptor)object).getName());
        setIcon(((PatternDescriptor)object).getIcon());
      }
      return component;
    }
  });

  myTree.setModel(new DefaultTreeModel(root));
  myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    public void valueChanged(TreeSelectionEvent e) {
      update();
    }
  });
  myEditor = TemplateEditorUtil.createEditor(true, "");

  mySplitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myTree));
  JPanel details = new JPanel(new BorderLayout());
  details.add(myEditor.getComponent(), BorderLayout.CENTER);
  mySplitter.setSecondComponent(details);
  mySplitter.setHonorComponentsMinimumSize(true);
  mySplitter.setShowDividerControls(true);

  myTree.setSelectionRow(0);

  init();
}
 
Example #14
Source File: SourceItemNode.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void handleDoubleClickOrEnter(SimpleTree tree, InputEvent inputEvent) {
  if (mySourceItem.isProvideElements() && getChildren().length == 0) {
    getArtifactEditor().getLayoutTreeComponent().putIntoDefaultLocations(Collections.singletonList(mySourceItem));
  }
}