use of javax.swing.event.TreeSelectionEvent 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.TreeSelectionEvent 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.TreeSelectionEvent 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;
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class BreakpointItemsTreeController method setTreeView.
public void setTreeView(JTree treeView) {
myTreeView = treeView;
myTreeView.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent event) {
selectionChanged();
}
});
if (treeView instanceof BreakpointsCheckboxTree) {
((BreakpointsCheckboxTree) treeView).setDelegate(this);
}
myTreeView.setShowsRootHandles(!myGroupingRules.isEmpty());
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class FileStructurePopup method show.
public void show() {
//final long time = System.currentTimeMillis();
JComponent panel = createCenterPanel();
MnemonicHelper.init(panel);
myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null).setTitle(myTitle).setResizable(true).setModalContext(false).setFocusable(true).setRequestFocus(true).setMovable(true).setBelongsToGlobalPopupStack(true).setCancelKeyEnabled(false).setDimensionServiceKey(null, getDimensionServiceKey(), true).setCancelCallback(() -> myCanClose).createPopup();
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (myPopup.isVisible()) {
final PopupUpdateProcessor updateProcessor = myPopup.getUserData(PopupUpdateProcessor.class);
if (updateProcessor != null) {
final AbstractTreeNode node = getSelectedNode();
updateProcessor.updatePopup(node);
}
}
}
});
Disposer.register(myPopup, this);
Disposer.register(myPopup, new Disposable() {
@Override
public void dispose() {
if (!myTreeHasBuilt.isDone()) {
myTreeHasBuilt.setRejected();
}
}
});
myTree.getEmptyText().setText("Loading...");
myPopup.showCenteredInCurrentWindow(myProject);
((AbstractPopup) myPopup).setShowHints(true);
IdeFocusManager.getInstance(myProject).requestFocus(myTree, true);
Window window = SwingUtilities.windowForComponent(myPopup.getContent());
WindowFocusListener windowFocusListener = new WindowFocusListener() {
@Override
public void windowGainedFocus(WindowEvent e) {
}
@Override
public void windowLostFocus(WindowEvent e) {
myPopup.cancel();
}
};
window.addWindowFocusListener(windowFocusListener);
Disposer.register(myPopup, () -> window.removeWindowFocusListener(windowFocusListener));
ApplicationManager.getApplication().executeOnPooledThread(() -> {
ApplicationManager.getApplication().runReadAction(() -> myFilteringStructure.rebuild());
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
myAbstractTreeBuilder.queueUpdate().doWhenDone(() -> {
myTreeHasBuilt.setDone();
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> {
if (myAbstractTreeBuilder.isDisposed())
return;
if (selectPsiElement(myInitialPsiElement) == null) {
TreeUtil.ensureSelection(myAbstractTreeBuilder.getTree());
myAbstractTreeBuilder.revalidateTree();
}
});
});
installUpdater();
});
});
}
Aggregations