use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class StructureNodeRenderer method getNodeDescriptor.
private static NodeDescriptor getNodeDescriptor(Object value) {
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
if (userObject instanceof NodeDescriptor) {
return (NodeDescriptor) userObject;
}
}
return null;
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class CallerMethodsTreeStructure method buildChildren.
@NotNull
@Override
protected final Object[] buildChildren(@NotNull final HierarchyNodeDescriptor descriptor) {
PsiMember enclosingElement = ((CallHierarchyNodeDescriptor) descriptor).getEnclosingElement();
HierarchyNodeDescriptor nodeDescriptor = getBaseDescriptor();
if (enclosingElement instanceof PsiMethod) {
PsiClass clazz = enclosingElement.getContainingClass();
if (isLocalOrAnonymousClass(clazz)) {
PsiElement parent = clazz.getParent();
PsiElement grandParent = parent instanceof PsiNewExpression ? parent.getParent() : null;
if (grandParent instanceof PsiExpressionList) {
// for created anonymous class that immediately passed as argument use instantiation point as next call point (IDEA-73312)
enclosingElement = CallHierarchyNodeDescriptor.getEnclosingElement(grandParent);
}
}
}
if (!(enclosingElement instanceof PsiMethod) || nodeDescriptor == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final PsiMethod baseMethod = (PsiMethod) ((CallHierarchyNodeDescriptor) nodeDescriptor).getTargetElement();
if (baseMethod == null) {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
final SearchScope searchScope = getSearchScope(myScopeType, baseMethod.getContainingClass());
final PsiMethod method = (PsiMethod) enclosingElement;
final PsiClass originalClass = method.getContainingClass();
assert originalClass != null;
final PsiClassType originalType = JavaPsiFacade.getElementFactory(myProject).createType(originalClass);
final Set<PsiMethod> methodsToFind = new HashSet<>();
methodsToFind.add(method);
ContainerUtil.addAll(methodsToFind, method.findDeepestSuperMethods());
final Map<PsiMember, NodeDescriptor> methodToDescriptorMap = new HashMap<>();
for (final PsiMethod methodToFind : methodsToFind) {
final JavaCallHierarchyData data = new JavaCallHierarchyData(originalClass, methodToFind, originalType, method, methodsToFind, descriptor, methodToDescriptorMap, myProject);
MethodReferencesSearch.search(methodToFind, searchScope, true).forEach(reference -> {
for (CallReferenceProcessor processor : CallReferenceProcessor.EP_NAME.getExtensions()) {
if (!processor.process(reference, data))
break;
}
return true;
});
}
return methodToDescriptorMap.values().toArray(new Object[methodToDescriptorMap.size()]);
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class StructureTreeBuilder method isAutoExpandNode.
@Override
protected final boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
StructureViewModel model = myStructureModel;
if (model instanceof TreeModelWrapper) {
model = ((TreeModelWrapper) model).getModel();
}
if (model instanceof StructureViewModel.ExpandInfoProvider) {
StructureViewModel.ExpandInfoProvider provider = (StructureViewModel.ExpandInfoProvider) model;
Object element = nodeDescriptor.getElement();
if (element instanceof StructureViewComponent.StructureViewTreeElementWrapper) {
StructureViewComponent.StructureViewTreeElementWrapper wrapper = (StructureViewComponent.StructureViewTreeElementWrapper) element;
if (wrapper.getValue() instanceof StructureViewTreeElement) {
final StructureViewTreeElement value = (StructureViewTreeElement) wrapper.getValue();
if (value != null) {
return provider.isAutoExpand(value);
}
}
} else if (element instanceof GroupWrapper) {
final Group group = ((GroupWrapper) element).getValue();
for (TreeElement treeElement : group.getChildren()) {
if (treeElement instanceof StructureViewTreeElement && !provider.isAutoExpand((StructureViewTreeElement) treeElement)) {
return false;
}
}
}
}
// expand root node & its immediate children
final NodeDescriptor parent = nodeDescriptor.getParentDescriptor();
return super.isAutoExpandNode(parent == null ? nodeDescriptor : parent);
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class ServersToolWindowContent method setupBuilder.
private void setupBuilder(@NotNull final Project project) {
ServersTreeStructure structure = myContribution.createTreeStructure(project, this);
myBuilder = new TreeBuilderBase(myTree, structure, myTreeModel) {
@Override
protected boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
return (nodeDescriptor instanceof ServersTreeStructure.RemoteServerNode || nodeDescriptor instanceof ServersTreeStructure.DeploymentNodeImpl) && (!myCollapsedTreeNodeValues.contains(((AbstractTreeNode) nodeDescriptor).getValue()));
}
};
Disposer.register(this, myBuilder);
project.getMessageBus().connect().subscribe(ServerConnectionListener.TOPIC, new ServerConnectionListener() {
@Override
public void onConnectionCreated(@NotNull ServerConnection<?> connection) {
getBuilder().queueUpdate();
}
@Override
public void onConnectionStatusChanged(@NotNull ServerConnection<?> connection) {
getBuilder().queueUpdate();
updateSelectedServerDetails();
if (connection.getStatus() == ConnectionStatus.CONNECTED) {
pollDeployments(connection);
}
}
@Override
public void onDeploymentsChanged(@NotNull ServerConnection<?> connection) {
getBuilder().queueUpdate();
updateSelectedServerDetails();
}
});
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class TodoPanel method initUI.
private void initUI() {
UIUtil.setLineStyleAngled(myTree);
myTree.setShowsRootHandles(true);
myTree.setRootVisible(false);
myTree.setCellRenderer(new TodoCompositeRenderer());
EditSourceOnDoubleClickHandler.install(myTree);
new TreeSpeedSearch(myTree);
DefaultActionGroup group = new DefaultActionGroup();
group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
group.addSeparator();
group.add(ActionManager.getInstance().getAction(IdeActions.GROUP_VERSION_CONTROLS));
PopupHandler.installPopupHandler(myTree, group, ActionPlaces.TODO_VIEW_POPUP, ActionManager.getInstance());
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (!e.isConsumed() && KeyEvent.VK_ENTER == e.getKeyCode()) {
TreePath path = myTree.getSelectionPath();
if (path == null) {
return;
}
final Object userObject = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
if (!((userObject instanceof NodeDescriptor ? (NodeDescriptor) userObject : null) instanceof TodoItemNode)) {
return;
}
OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(TodoPanel.this), false);
}
}
});
myUsagePreviewPanel = new UsagePreviewPanel(myProject, FindInProjectUtil.setupViewPresentation(false, new FindModel()));
Disposer.register(this, myUsagePreviewPanel);
myUsagePreviewPanel.setVisible(mySettings.showPreview);
setContent(createCenterComponent());
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent e) {
ApplicationManager.getApplication().invokeLater(() -> {
if (myUsagePreviewPanel.isVisible()) {
updatePreviewPanel();
}
}, ModalityState.NON_MODAL, myProject.getDisposed());
}
});
// Create tool bars and register custom shortcuts
JPanel toolBarPanel = new JPanel(new GridLayout());
DefaultActionGroup leftGroup = new DefaultActionGroup();
leftGroup.add(new PreviousOccurenceToolbarAction(myOccurenceNavigator));
leftGroup.add(new NextOccurenceToolbarAction(myOccurenceNavigator));
leftGroup.add(new ContextHelpAction("find.todoList"));
toolBarPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.TODO_VIEW_TOOLBAR, leftGroup, false).getComponent());
DefaultActionGroup rightGroup = new DefaultActionGroup();
AnAction expandAllAction = CommonActionsManager.getInstance().createExpandAllAction(myTreeExpander, this);
rightGroup.add(expandAllAction);
AnAction collapseAllAction = CommonActionsManager.getInstance().createCollapseAllAction(myTreeExpander, this);
rightGroup.add(collapseAllAction);
if (!myCurrentFileMode) {
MyShowModulesAction showModulesAction = new MyShowModulesAction();
showModulesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_M, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
rightGroup.add(showModulesAction);
MyShowPackagesAction showPackagesAction = new MyShowPackagesAction();
showPackagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_P, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
rightGroup.add(showPackagesAction);
MyFlattenPackagesAction flattenPackagesAction = new MyFlattenPackagesAction();
flattenPackagesAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F, SystemInfo.isMac ? InputEvent.META_MASK : InputEvent.CTRL_MASK)), myTree);
rightGroup.add(flattenPackagesAction);
}
MyAutoScrollToSourceHandler autoScrollToSourceHandler = new MyAutoScrollToSourceHandler();
autoScrollToSourceHandler.install(myTree);
rightGroup.add(autoScrollToSourceHandler.createToggleAction());
SetTodoFilterAction setTodoFilterAction = new SetTodoFilterAction(myProject, mySettings, todoFilter -> setTodoFilter(todoFilter));
rightGroup.add(setTodoFilterAction);
rightGroup.add(new MyPreviewAction());
toolBarPanel.add(ActionManager.getInstance().createActionToolbar(ActionPlaces.TODO_VIEW_TOOLBAR, rightGroup, false).getComponent());
setToolbar(toolBarPanel);
}
Aggregations