use of com.intellij.ui.TreeSpeedSearch in project intellij-community by JetBrains.
the class TreeFileChooserDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
myTree = new Tree(model);
final ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) {
@Override
public boolean isFlattenPackages() {
return false;
}
@Override
public boolean isShowMembers() {
return false;
}
@Override
public boolean isHideEmptyMiddlePackages() {
return true;
}
@Override
public Object[] getChildElements(final Object element) {
return filterFiles(super.getChildElements(element));
}
@Override
public boolean isAbbreviatePackageNames() {
return false;
}
@Override
public boolean isShowLibraryContents() {
return myShowLibraryContents;
}
@Override
public boolean isShowModules() {
return false;
}
@Override
public List<TreeStructureProvider> getProviders() {
return myDisableStructureProviders ? null : super.getProviders();
}
};
myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
myTree.setRootVisible(false);
myTree.expandRow(0);
myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
myTree.setCellRenderer(new NodeRenderer());
UIUtil.setLineStyleAngled(myTree);
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
scrollPane.setPreferredSize(JBUI.size(500, 300));
myTree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(final KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
doOKAction();
}
}
});
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
final TreePath path = myTree.getPathForLocation(e.getX(), e.getY());
if (path != null && myTree.isPathSelected(path)) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent e) {
handleSelectionChanged();
}
});
new TreeSpeedSearch(myTree);
myTabbedPane = new TabbedPaneWrapper(getDisposable());
final JPanel dummyPanel = new JPanel(new BorderLayout());
String name = null;
if (myInitialFile != null) {
name = myInitialFile.getName();
}
PsiElement context = myInitialFile == null ? null : myInitialFile;
myGotoByNamePanel = new ChooseByNamePanel(myProject, new MyGotoFileModel(), name, true, context) {
@Override
protected void close(final boolean isOk) {
super.close(isOk);
if (isOk) {
doOKAction();
} else {
doCancelAction();
}
}
@Override
protected void initUI(final ChooseByNamePopupComponent.Callback callback, final ModalityState modalityState, boolean allowMultipleSelection) {
super.initUI(callback, modalityState, allowMultipleSelection);
dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
//IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()).requestFocus();
if (mySelectSearchByNameTab) {
myTabbedPane.setSelectedIndex(1);
}
}
@Override
protected void showTextFieldPanel() {
}
@Override
protected void chosenElementMightChange() {
handleSelectionChanged();
}
};
myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
SwingUtilities.invokeLater(() -> myGotoByNamePanel.invoke(new MyCallback(), ModalityState.stateForComponent(getRootPane()), false));
myTabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(final ChangeEvent e) {
handleSelectionChanged();
}
});
return myTabbedPane.getComponent();
}
use of com.intellij.ui.TreeSpeedSearch in project intellij-community by JetBrains.
the class PackageChooserDialog method createCenterPanel.
protected JComponent createCenterPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
myModel = new DefaultTreeModel(new DefaultMutableTreeNode());
createTreeModel();
myTree = new Tree(myModel);
UIUtil.setLineStyleAngled(myTree);
myTree.setCellRenderer(new DefaultTreeCellRenderer() {
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
setIcon(PlatformIcons.PACKAGE_ICON);
if (value instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object object = node.getUserObject();
if (object instanceof PsiPackage) {
String name = ((PsiPackage) object).getName();
if (name != null && name.length() > 0) {
setText(name);
} else {
setText(IdeBundle.message("node.default"));
}
}
}
return this;
}
});
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
scrollPane.setPreferredSize(JBUI.size(500, 300));
new TreeSpeedSearch(myTree, new Convertor<TreePath, String>() {
public String convert(TreePath path) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object object = node.getUserObject();
if (object instanceof PsiPackage)
return ((PsiPackage) object).getName();
else
return "";
}
});
myTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
PsiPackage selection = getTreeSelection();
if (selection != null) {
String name = selection.getQualifiedName();
setTitle(myTitle + " - " + ("".equals(name) ? IdeBundle.message("node.default.package") : name));
} else {
setTitle(myTitle);
}
updatePathFromTree();
}
});
panel.add(scrollPane, BorderLayout.CENTER);
DefaultActionGroup group = createActionGroup(myTree);
final JPanel northPanel = new JPanel(new BorderLayout());
panel.add(northPanel, BorderLayout.NORTH);
ActionToolbar toolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
northPanel.add(toolBar.getComponent(), BorderLayout.WEST);
setupPathComponent(northPanel);
return panel;
}
Aggregations