Search in sources :

Example 1 with AbstractProjectTreeStructure

use of com.intellij.ide.projectView.impl.AbstractProjectTreeStructure in project intellij-community by JetBrains.

the class AbstractTreeClassChooserDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final DefaultTreeModel model = new DefaultTreeModel(new DefaultMutableTreeNode());
    myTree = new Tree(model);
    ProjectAbstractTreeStructureBase treeStructure = new AbstractProjectTreeStructure(myProject) {

        @Override
        public boolean isFlattenPackages() {
            return false;
        }

        @Override
        public boolean isShowMembers() {
            return myIsShowMembers;
        }

        @Override
        public boolean isHideEmptyMiddlePackages() {
            return true;
        }

        @Override
        public boolean isAbbreviatePackageNames() {
            return false;
        }

        @Override
        public boolean isShowLibraryContents() {
            return myIsShowLibraryContents;
        }

        @Override
        public boolean isShowModules() {
            return false;
        }
    };
    myBuilder = new ProjectTreeBuilder(myProject, myTree, model, AlphaComparator.INSTANCE, treeStructure);
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    myTree.expandRow(0);
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    myTree.setCellRenderer(new NodeRenderer());
    UIUtil.setLineStyleAngled(myTree);
    JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
    scrollPane.setPreferredSize(JBUI.size(500, 300));
    myTree.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyCode()) {
                doOKAction();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            TreePath path = myTree.getPathForLocation(event.getX(), event.getY());
            if (path != null && myTree.isPathSelected(path)) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            handleSelectionChanged();
        }
    });
    new TreeSpeedSearch(myTree);
    myTabbedPane = new TabbedPaneWrapper(getDisposable());
    final JPanel dummyPanel = new JPanel(new BorderLayout());
    String name = null;
    /*
    if (myInitialClass != null) {
      name = myInitialClass.getName();
    }
*/
    myGotoByNamePanel = new ChooseByNamePanel(myProject, createChooseByNameModel(), name, myScope.isSearchInLibraries(), getContext()) {

        @Override
        protected void showTextFieldPanel() {
        }

        @Override
        protected void close(boolean isOk) {
            super.close(isOk);
            if (isOk) {
                doOKAction();
            } else {
                doCancelAction();
            }
        }

        @NotNull
        @Override
        protected Set<Object> filter(@NotNull Set<Object> elements) {
            return doFilter(elements);
        }

        @Override
        protected void initUI(ChooseByNamePopupComponent.Callback callback, ModalityState modalityState, boolean allowMultipleSelection) {
            super.initUI(callback, modalityState, allowMultipleSelection);
            dummyPanel.add(myGotoByNamePanel.getPanel(), BorderLayout.CENTER);
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(IdeFocusTraversalPolicy.getPreferredFocusedComponent(myGotoByNamePanel.getPanel()), true);
            });
        }

        @Override
        protected void showList() {
            super.showList();
            if (myInitialClass != null && myList.getModel().getSize() > 0) {
                myList.setSelectedValue(myInitialClass, true);
                myInitialClass = null;
            }
        }

        @Override
        protected void chosenElementMightChange() {
            handleSelectionChanged();
        }
    };
    Disposer.register(myDisposable, myGotoByNamePanel);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.search.by.name"), dummyPanel);
    myTabbedPane.addTab(IdeBundle.message("tab.chooser.project"), scrollPane);
    myGotoByNamePanel.invoke(new MyCallback(), getModalityState(), false);
    myTabbedPane.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            handleSelectionChanged();
        }
    });
    return myTabbedPane.getComponent();
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DoubleClickListener(com.intellij.ui.DoubleClickListener) KeyAdapter(java.awt.event.KeyAdapter) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) NotNull(org.jetbrains.annotations.NotNull) AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) KeyEvent(java.awt.event.KeyEvent) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) Tree(com.intellij.ui.treeStructure.Tree) ChangeListener(javax.swing.event.ChangeListener) MouseEvent(java.awt.event.MouseEvent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder) ProjectTreeBuilder(com.intellij.ide.projectView.impl.ProjectTreeBuilder) ModalityState(com.intellij.openapi.application.ModalityState) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 2 with AbstractProjectTreeStructure

use of com.intellij.ide.projectView.impl.AbstractProjectTreeStructure in project intellij-community by JetBrains.

the class PackagesTreeStructureTest method doTest.

private void doTest(final boolean showModules, final boolean showLibraryContents, boolean flattenPackages, boolean abbreviatePackageNames, @NonNls final String expected, final int levels) throws InterruptedException {
    final ProjectViewImpl projectView = (ProjectViewImpl) ProjectView.getInstance(myProject);
    projectView.setShowModules(showModules, PackageViewPane.ID);
    projectView.setShowLibraryContents(showLibraryContents, PackageViewPane.ID);
    projectView.setFlattenPackages(flattenPackages, PackageViewPane.ID);
    projectView.setAbbreviatePackageNames(abbreviatePackageNames, PackageViewPane.ID);
    projectView.setHideEmptyPackages(true, PackageViewPane.ID);
    PackageViewPane packageViewPane = new PackageViewPane(myProject);
    packageViewPane.createComponent();
    ((AbstractProjectTreeStructure) packageViewPane.getTreeStructure()).setProviders(new ResourceBundleGrouper(myProject));
    packageViewPane.updateFromRoot(true);
    JTree tree = packageViewPane.getTree();
    TreeUtil.expand(tree, levels);
    PlatformTestUtil.assertTreeEqual(tree, expected);
    BaseProjectViewTestCase.checkContainsMethod(packageViewPane.getTreeStructure().getRootElement(), packageViewPane.getTreeStructure());
    Disposer.dispose(packageViewPane);
}
Also used : AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) ResourceBundleGrouper(com.intellij.lang.properties.projectView.ResourceBundleGrouper) PackageViewPane(com.intellij.ide.projectView.impl.PackageViewPane) ProjectViewImpl(com.intellij.ide.projectView.impl.ProjectViewImpl)

Example 3 with AbstractProjectTreeStructure

use of com.intellij.ide.projectView.impl.AbstractProjectTreeStructure 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();
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DoubleClickListener(com.intellij.ui.DoubleClickListener) KeyAdapter(java.awt.event.KeyAdapter) TreeSpeedSearch(com.intellij.ui.TreeSpeedSearch) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeStructureProvider(com.intellij.ide.projectView.TreeStructureProvider) AbstractProjectTreeStructure(com.intellij.ide.projectView.impl.AbstractProjectTreeStructure) NodeRenderer(com.intellij.ide.util.treeView.NodeRenderer) KeyEvent(java.awt.event.KeyEvent) ProjectAbstractTreeStructureBase(com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase) Tree(com.intellij.ui.treeStructure.Tree) ChangeListener(javax.swing.event.ChangeListener) PsiElement(com.intellij.psi.PsiElement) MouseEvent(java.awt.event.MouseEvent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ChooseByNamePanel(com.intellij.ide.util.gotoByName.ChooseByNamePanel) TreePath(javax.swing.tree.TreePath) ChangeEvent(javax.swing.event.ChangeEvent) BaseProjectTreeBuilder(com.intellij.ide.projectView.BaseProjectTreeBuilder) ProjectTreeBuilder(com.intellij.ide.projectView.impl.ProjectTreeBuilder) ModalityState(com.intellij.openapi.application.ModalityState) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) ChooseByNamePopupComponent(com.intellij.ide.util.gotoByName.ChooseByNamePopupComponent)

Aggregations

AbstractProjectTreeStructure (com.intellij.ide.projectView.impl.AbstractProjectTreeStructure)3 BaseProjectTreeBuilder (com.intellij.ide.projectView.BaseProjectTreeBuilder)2 ProjectAbstractTreeStructureBase (com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase)2 ProjectTreeBuilder (com.intellij.ide.projectView.impl.ProjectTreeBuilder)2 NodeRenderer (com.intellij.ide.util.treeView.NodeRenderer)2 ModalityState (com.intellij.openapi.application.ModalityState)2 DoubleClickListener (com.intellij.ui.DoubleClickListener)2 TabbedPaneWrapper (com.intellij.ui.TabbedPaneWrapper)2 TreeSpeedSearch (com.intellij.ui.TreeSpeedSearch)2 Tree (com.intellij.ui.treeStructure.Tree)2 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 MouseEvent (java.awt.event.MouseEvent)2 ChangeEvent (javax.swing.event.ChangeEvent)2 ChangeListener (javax.swing.event.ChangeListener)2 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)2 TreeSelectionListener (javax.swing.event.TreeSelectionListener)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 TreePath (javax.swing.tree.TreePath)2