use of com.intellij.ide.projectView.TreeStructureProvider in project intellij-community by JetBrains.
the class AbstractTreeStructureBase method getChildElements.
@Override
public Object[] getChildElements(Object element) {
LOG.assertTrue(element instanceof AbstractTreeNode, element != null ? element.getClass().getName() : null);
AbstractTreeNode<?> treeNode = (AbstractTreeNode) element;
Collection<? extends AbstractTreeNode> elements = treeNode.getChildren();
List<TreeStructureProvider> providers = getProvidersDumbAware();
if (!providers.isEmpty()) {
ViewSettings settings = treeNode instanceof SettingsProvider ? ((SettingsProvider) treeNode).getSettings() : ViewSettings.DEFAULT;
for (TreeStructureProvider provider : providers) {
try {
elements = provider.modify(treeNode, (Collection<AbstractTreeNode>) elements, settings);
} catch (ProcessCanceledException e) {
throw e;
} catch (Exception e) {
LOG.error(e);
}
}
}
for (AbstractTreeNode node : elements) {
node.setParent(treeNode);
}
return ArrayUtil.toObjectArray(elements);
}
use of com.intellij.ide.projectView.TreeStructureProvider in project android by JetBrains.
the class GradleSyncTest method jdkNodeModificationInProjectView.
@Test
public void jdkNodeModificationInProjectView() throws IOException {
guiTest.importSimpleApplication();
Project project = guiTest.ideFrame().getProject();
AndroidTreeStructureProvider treeStructureProvider = null;
TreeStructureProvider[] treeStructureProviders = Extensions.getExtensions(TreeStructureProvider.EP_NAME, project);
for (TreeStructureProvider current : treeStructureProviders) {
if (current instanceof AndroidTreeStructureProvider) {
treeStructureProvider = (AndroidTreeStructureProvider) current;
}
}
List<AbstractTreeNode> changedNodes = Lists.newArrayList();
treeStructureProvider.addChangeListener((parent, newChildren) -> changedNodes.add(parent));
ProjectViewFixture projectView = guiTest.ideFrame().getProjectView();
ProjectViewFixture.PaneFixture projectPane = projectView.selectProjectPane();
ProjectViewFixture.NodeFixture externalLibrariesNode = projectPane.findExternalLibrariesNode();
projectPane.expand();
// 2 nodes should be changed: JDK (remove all children except rt.jar) and rt.jar (remove all children except packages 'java' and
// 'javax'.
Wait.seconds(1).expecting("'Project View' to be customized").until(() -> changedNodes.size() == 2);
List<ProjectViewFixture.NodeFixture> libraryNodes = externalLibrariesNode.getChildren();
ProjectViewFixture.NodeFixture jdkNode = null;
// Find JDK node.
for (ProjectViewFixture.NodeFixture node : libraryNodes) {
if (node.isJdk()) {
jdkNode = node;
break;
}
}
ProjectViewFixture.NodeFixture finalJdkNode = jdkNode;
Wait.seconds(1).expecting("JDK node to be customized").until(() -> finalJdkNode.getChildren().size() == 1);
// Now we verify that the JDK node has only these children:
// - jdk
// - rt.jar
// - java
// - javax
List<ProjectViewFixture.NodeFixture> jdkChildren = jdkNode.getChildren();
assertThat(jdkChildren).hasSize(1);
ProjectViewFixture.NodeFixture rtJarNode = jdkChildren.get(0);
rtJarNode.requireDirectory("rt.jar");
List<ProjectViewFixture.NodeFixture> rtJarChildren = rtJarNode.getChildren();
assertThat(rtJarChildren).hasSize(2);
rtJarChildren.get(0).requireDirectory("java");
rtJarChildren.get(1).requireDirectory("javax");
}
use of com.intellij.ide.projectView.TreeStructureProvider in project intellij-community by JetBrains.
the class ProjectViewSelectInTarget method select.
@Override
public void select(PsiElement element, final boolean requestFocus) {
PsiElement toSelect = null;
for (TreeStructureProvider provider : getProvidersDumbAware()) {
if (provider instanceof SelectableTreeStructureProvider) {
toSelect = ((SelectableTreeStructureProvider) provider).getTopLevelElement(element);
}
if (toSelect != null)
break;
}
toSelect = findElementToSelect(element, toSelect);
if (toSelect != null) {
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(toSelect);
select(toSelect, virtualFile, requestFocus);
}
}
use of com.intellij.ide.projectView.TreeStructureProvider 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();
}
Aggregations