use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.
the class ModulesDependenciesPanel method installLeftTreeListeners.
private void installLeftTreeListeners() {
myLeftTree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
@Override
public void treeExpanded(TreeExpansionEvent event) {
DefaultMutableTreeNode expandedNode = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
for (int i = 0; i < expandedNode.getChildCount(); i++) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) expandedNode.getChildAt(i);
if (child.getChildCount() == 0 && !isLooped(event.getPath(), child)) {
Module module = ((MyUserObject) child.getUserObject()).myModule;
for (Module dependency : getModuleDependencies(module)) {
child.add(new DefaultMutableTreeNode(new MyUserObject(isInCycle(dependency), dependency)));
}
TreeUtil.sortRecursively(child, NODE_COMPARATOR);
}
}
}
private boolean isLooped(TreePath path, DefaultMutableTreeNode child) {
for (Object o : path.getPath()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
if (node != child && Comparing.equal(node.getUserObject(), child.getUserObject())) {
return true;
}
}
return false;
}
});
myLeftTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath selectionPath = myLeftTree.getSelectionPath();
if (selectionPath != null) {
myPathField.setText(StringUtil.join(selectionPath.getPath(), o -> {
Object userObject = ((DefaultMutableTreeNode) o).getUserObject();
return userObject instanceof MyUserObject ? ((MyUserObject) userObject).myModule.getName() : "";
}, " : "));
DefaultMutableTreeNode selection = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
if (selection != null) {
updateRightTree(((MyUserObject) selection.getUserObject()).myModule);
}
}
}
});
}
use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.
the class SMTestRunnerResultsForm method addEventsListener.
public void addEventsListener(final EventsListener listener) {
myEventListeners.add(listener);
addTestsTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(final TreeSelectionEvent e) {
//We should fire event only if it was generated by this component,
//e.g. it is focused. Otherwise it is side effect of selecting proxy in
//try by other component
//if (myTreeView.isFocusOwner()) {
@Nullable final SMTestProxy selectedProxy = (SMTestProxy) getTreeView().getSelectedTest();
listener.onSelected(selectedProxy, SMTestRunnerResultsForm.this, SMTestRunnerResultsForm.this);
//}
}
});
}
use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.
the class UpdateInfoTree method createTree.
private void createTree() {
SmartExpander.installOn(myTree);
SelectionSaver.installOn(myTree);
createTreeModel();
myTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
AbstractTreeNode treeNode = (AbstractTreeNode) e.getPath().getLastPathComponent();
VirtualFilePointer pointer = null;
if (treeNode instanceof FileTreeNode) {
pointer = ((FileTreeNode) treeNode).getFilePointer();
}
if (pointer != null) {
mySelectedUrl = pointer.getUrl();
mySelectedFile = pointer.getFile();
} else {
mySelectedUrl = null;
mySelectedFile = null;
}
}
});
myTree.setCellRenderer(new UpdateTreeCellRenderer());
TreeUtil.installActions(myTree);
new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
public String convert(TreePath path) {
Object last = path.getLastPathComponent();
if (last instanceof AbstractTreeNode) {
return ((AbstractTreeNode) last).getText();
}
return TreeSpeedSearch.NODE_DESCRIPTOR_TOSTRING.convert(path);
}
}, true);
myTree.addMouseListener(new PopupHandler() {
public void invokePopup(Component comp, int x, int y) {
final DefaultActionGroup group = (DefaultActionGroup) ActionManager.getInstance().getAction("UpdateActionGroup");
if (group != null) {
//if no UpdateActionGroup was configured
ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.UPDATE_POPUP, group);
popupMenu.getComponent().show(comp, x, y);
}
}
});
EditSourceOnDoubleClickHandler.install(myTree);
EditSourceOnEnterKeyHandler.install(myTree);
myTree.setSelectionRow(0);
}
use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.
the class TargetChooserDialog method initTree.
private Tree initTree() {
@NonNls final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
final Tree tree = new Tree(root);
tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
final TreePath selectionPath = tree.getSelectionPath();
if (selectionPath != null) {
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
final Object userObject = node.getUserObject();
if (userObject instanceof AntTargetNodeDescriptor) {
final AntTargetNodeDescriptor antBuildTarget = (AntTargetNodeDescriptor) userObject;
mySelectedTarget = antBuildTarget.getAntTarget();
} else {
mySelectedTarget = null;
}
}
}
});
tree.setCellRenderer(new MyTreeCellRenderer());
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.setLineStyleAngled();
TreeUtil.installActions(tree);
new TreeSpeedSearch(tree, new Convertor<TreePath, String>() {
public String convert(final TreePath path) {
final Object userObject = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject();
if (userObject instanceof AntTargetNodeDescriptor) {
final AntBuildTarget target = ((AntTargetNodeDescriptor) userObject).getAntTarget();
return target.getDisplayName();
}
return null;
}
});
DefaultMutableTreeNode selectedNode = null;
final AntConfiguration antConfiguration = AntConfigurationImpl.getInstance(myProject);
for (AntBuildFile buildFile : antConfiguration.getBuildFileList()) {
final DefaultMutableTreeNode buildFileNode = new DefaultMutableTreeNode(buildFile);
DefaultMutableTreeNode selection = processFileTargets(antConfiguration.getMetaTargets(buildFile), buildFile, buildFileNode);
if (selection != null) {
selectedNode = selection;
}
selection = processFileTargets(antConfiguration.getModel(buildFile).getTargets(), buildFile, buildFileNode);
if (selection != null) {
selectedNode = selection;
}
root.add(buildFileNode);
}
TreeUtil.expandAll(tree);
TreeUtil.selectInTree(selectedNode, true, tree);
return tree;
}
use of javax.swing.event.TreeSelectionListener in project intellij-community by JetBrains.
the class CallerChooserBase method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
Splitter splitter = new Splitter(false, (float) 0.6);
JPanel result = new JPanel(new BorderLayout());
if (myTree == null) {
myTree = createTree();
} else {
final CheckedTreeNode root = (CheckedTreeNode) myTree.getModel().getRoot();
myRoot = (MethodNodeBase) root.getFirstChild();
}
myTreeSelectionListener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
final TreePath path = e.getPath();
if (path != null) {
final MethodNodeBase<M> node = (MethodNodeBase) path.getLastPathComponent();
myAlarm.cancelAllRequests();
myAlarm.addRequest(() -> updateEditorTexts(node), 300);
}
}
};
myTree.getSelectionModel().addTreeSelectionListener(myTreeSelectionListener);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
splitter.setFirstComponent(scrollPane);
final JComponent callSitesViewer = createCallSitesViewer();
TreePath selectionPath = myTree.getSelectionPath();
if (selectionPath == null) {
selectionPath = new TreePath(myRoot.getPath());
myTree.getSelectionModel().addSelectionPath(selectionPath);
}
final MethodNodeBase<M> node = (MethodNodeBase) selectionPath.getLastPathComponent();
updateEditorTexts(node);
splitter.setSecondComponent(callSitesViewer);
result.add(splitter);
return result;
}
Aggregations