use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.
the class DissociateResourceBundleAction method dissociate.
public static void dissociate(final Collection<ResourceBundle> resourceBundles, final Project project) {
final Set<PsiFileSystemItem> toUpdateInProjectView = new HashSet<>();
for (ResourceBundle resourceBundle : resourceBundles) {
for (final PropertiesFile propertiesFile : resourceBundle.getPropertiesFiles()) {
PsiDirectory containingDirectory = propertiesFile.getContainingFile().getContainingDirectory();
if (containingDirectory != null) {
toUpdateInProjectView.add(containingDirectory);
}
}
ResourceBundleManager.getInstance(project).dissociateResourceBundle(resourceBundle);
}
AbstractProjectViewPane currentProjectViewPane = ProjectView.getInstance(project).getCurrentProjectViewPane();
if (currentProjectViewPane == null) {
return;
}
AbstractTreeBuilder treeBuilder = currentProjectViewPane.getTreeBuilder();
if (treeBuilder != null) {
for (PsiFileSystemItem item : toUpdateInProjectView) {
treeBuilder.queueUpdateFrom(item, false);
}
}
}
use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.
the class ContentEntryTreeEditor method setContentEntryEditor.
/**
* @param contentEntryEditor : null means to clear the editor
*/
public void setContentEntryEditor(final ContentEntryEditor contentEntryEditor) {
if (myContentEntryEditor != null && myContentEntryEditor.equals(contentEntryEditor)) {
return;
}
if (myFileSystemTree != null) {
Disposer.dispose(myFileSystemTree);
myFileSystemTree = null;
}
if (myContentEntryEditor != null) {
myContentEntryEditor.removeContentEntryEditorListener(myContentEntryEditorListener);
myContentEntryEditor = null;
}
if (contentEntryEditor == null) {
((DefaultTreeModel) myTree.getModel()).setRoot(EMPTY_TREE_ROOT);
myTreePanel.setVisible(false);
if (myFileSystemTree != null) {
Disposer.dispose(myFileSystemTree);
}
return;
}
myTreePanel.setVisible(true);
myContentEntryEditor = contentEntryEditor;
myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener);
final ContentEntry entry = contentEntryEditor.getContentEntry();
assert entry != null : contentEntryEditor;
final VirtualFile file = entry.getFile();
if (file != null) {
myDescriptor.setRoots(file);
} else {
String path = VfsUtilCore.urlToPath(entry.getUrl());
myDescriptor.setTitle(FileUtil.toSystemDependentName(path));
}
final Runnable init = () -> {
//noinspection ConstantConditions
myFileSystemTree.updateTree();
myFileSystemTree.select(file, null);
};
myFileSystemTree = new FileSystemTreeImpl(myProject, myDescriptor, myTree, getContentEntryCellRenderer(), init, null) {
@Override
protected AbstractTreeBuilder createTreeBuilder(JTree tree, DefaultTreeModel treeModel, AbstractTreeStructure treeStructure, Comparator<NodeDescriptor> comparator, FileChooserDescriptor descriptor, final Runnable onInitialized) {
return new MyFileTreeBuilder(tree, treeModel, treeStructure, comparator, descriptor, onInitialized);
}
};
myFileSystemTree.showHiddens(true);
Disposer.register(myProject, myFileSystemTree);
final NewFolderAction newFolderAction = new MyNewFolderAction();
final DefaultActionGroup mousePopupGroup = new DefaultActionGroup();
mousePopupGroup.add(myEditingActionsGroup);
mousePopupGroup.addSeparator();
mousePopupGroup.add(newFolderAction);
myFileSystemTree.registerMouseListener(mousePopupGroup);
}
use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.
the class SelectSdkDialogFixture method selectPathToSdk.
public SelectSdkDialogFixture selectPathToSdk(@NotNull File pathToSdk) {
final JTextField textField = myRobot.finder().findByType(JTextField.class);
execute(new GuiTask() {
@Override
protected void executeInEDT() throws Throwable {
textField.setText(pathToSdk.getPath());
}
});
final Tree tree = myRobot.finder().findByType(myDialog, Tree.class);
final AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(tree);
pause(new Condition("Wait until path is updated") {
@Override
public boolean test() {
//noinspection ConstantConditions
return execute(new GuiQuery<Boolean>() {
@Override
protected Boolean executeInEDT() throws Throwable {
return (textField.getText().equals(pathToSdk.getPath()) && !builder.getUi().getUpdater().hasNodesToUpdate());
}
});
}
}, SHORT_TIMEOUT);
return this;
}
use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.
the class TreeUtil method showAndSelect.
@NotNull
public static ActionCallback showAndSelect(@NotNull final JTree tree, int top, int bottom, final int row, final int previous, final boolean addToSelection, final boolean scroll, final boolean resetSelection) {
final TreePath path = tree.getPathForRow(row);
if (path == null)
return ActionCallback.DONE;
final int size = tree.getRowCount();
if (size == 0) {
tree.clearSelection();
return ActionCallback.DONE;
}
if (top < 0) {
top = 0;
}
if (bottom >= size) {
bottom = size - 1;
}
if (row >= tree.getRowCount())
return ActionCallback.DONE;
boolean okToScroll = true;
if (tree.isShowing()) {
if (!tree.isValid()) {
tree.validate();
}
} else {
Application app = ApplicationManager.getApplication();
if (app != null && app.isUnitTestMode()) {
okToScroll = false;
}
}
Runnable selectRunnable = () -> {
if (!tree.isRowSelected(row)) {
if (addToSelection) {
tree.getSelectionModel().addSelectionPath(tree.getPathForRow(row));
} else {
tree.setSelectionRow(row);
}
} else if (resetSelection) {
if (!addToSelection) {
tree.setSelectionRow(row);
}
}
};
if (!okToScroll || !scroll) {
selectRunnable.run();
return ActionCallback.DONE;
}
final Rectangle rowBounds = tree.getRowBounds(row);
if (rowBounds == null)
return ActionCallback.DONE;
Rectangle topBounds = tree.getRowBounds(top);
if (topBounds == null) {
topBounds = rowBounds;
}
Rectangle bottomBounds = tree.getRowBounds(bottom);
if (bottomBounds == null) {
bottomBounds = rowBounds;
}
Rectangle bounds = topBounds.union(bottomBounds);
bounds.x = rowBounds.x;
bounds.width = rowBounds.width;
final Rectangle visible = tree.getVisibleRect();
if (visible.contains(bounds)) {
selectRunnable.run();
return ActionCallback.DONE;
} else {
final Component comp = tree.getCellRenderer().getTreeCellRendererComponent(tree, path.getLastPathComponent(), true, true, false, row, false);
if (comp instanceof SimpleColoredComponent) {
final SimpleColoredComponent renderer = (SimpleColoredComponent) comp;
final Dimension scrollableSize = renderer.computePreferredSize(true);
bounds.width = scrollableSize.width;
}
}
final ActionCallback callback = new ActionCallback();
selectRunnable.run();
final Range<Integer> range = getExpandControlRange(tree, path);
if (range != null) {
int delta = bounds.x - range.getFrom().intValue();
bounds.x -= delta;
bounds.width -= delta;
}
if (visible.width < bounds.width) {
bounds.width = visible.width;
}
if (tree instanceof Tree && !((Tree) tree).isHorizontalAutoScrollingEnabled()) {
bounds.x = 0;
}
LOG.debug("tree scroll: ", path);
tree.scrollRectToVisible(bounds);
// try to scroll later when the tree is ready
Object property = tree.getClientProperty(TREE_UTIL_SCROLL_TIME_STAMP);
long stamp = property instanceof Long ? (Long) property + 1L : Long.MIN_VALUE;
tree.putClientProperty(TREE_UTIL_SCROLL_TIME_STAMP, stamp);
// store relative offset because the row can be moved during the tree updating
int offset = rowBounds.y - bounds.y;
AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(tree);
scrollToVisible(tree, path, bounds, offset, stamp, callback::setDone, builder, 3);
return callback;
}
use of com.intellij.ide.util.treeView.AbstractTreeBuilder in project intellij-community by JetBrains.
the class ConfigureTasksActivationDialog method createTreeBuilder.
private static AbstractTreeBuilder createTreeBuilder(@NotNull Project project, @NotNull SimpleNode root, @NotNull Tree tree) {
final DefaultTreeModel treeModel = new DefaultTreeModel(new DefaultMutableTreeNode(root));
tree.setModel(treeModel);
tree.setRootVisible(false);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
final AbstractTreeBuilder treeBuilder = new AbstractTreeBuilder(tree, treeModel, new SimpleTreeStructure.Impl(root), null);
Disposer.register(project, treeBuilder);
return treeBuilder;
}
Aggregations