use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class ContentEntryTreeCellRenderer method customizeCellRenderer.
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
final ContentEntryEditor editor = myTreeEditor.getContentEntryEditor();
if (editor != null) {
final Object userObject = ((DefaultMutableTreeNode) value).getUserObject();
if (userObject instanceof NodeDescriptor) {
final Object element = ((NodeDescriptor) userObject).getElement();
if (element instanceof FileElement) {
final VirtualFile file = ((FileElement) element).getFile();
if (file != null && file.isDirectory()) {
final ContentEntry contentEntry = editor.getContentEntry();
if (contentEntry != null) {
final String prefix = getPresentablePrefix(contentEntry, file);
if (!prefix.isEmpty()) {
append(" (" + prefix + ")", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, JBColor.GRAY));
}
setIcon(updateIcon(contentEntry, file, getIcon()));
}
}
}
}
}
}
use of com.intellij.ide.util.treeView.NodeDescriptor 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.NodeDescriptor in project intellij-community by JetBrains.
the class LibraryTreeRenderer method customizeCellRenderer.
@Override
public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
Object userObject = node.getUserObject();
if (userObject instanceof NodeDescriptor) {
final NodeDescriptor descriptor = (NodeDescriptor) userObject;
setIcon(descriptor.getIcon());
append(descriptor.toString(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, descriptor.getColor()));
}
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class AbstractListBuilder method updateList.
protected final void updateList() {
if (myIsDisposed || myCurrentParent == null) {
return;
}
if (myTreeStructure.hasSomethingToCommit()) {
myTreeStructure.commit();
}
AbstractTreeNode parentDescriptor = myCurrentParent;
while (true) {
parentDescriptor.update();
if (parentDescriptor.getValue() != null)
break;
parentDescriptor = parentDescriptor.getParent();
}
final Object[] children = getChildren(parentDescriptor);
final HashMap<Object, Integer> elementToIndexMap = new HashMap<>();
for (int i = 0; i < children.length; i++) {
elementToIndexMap.put(children[i], Integer.valueOf(i));
}
final List<NodeDescriptor> resultDescriptors = new ArrayList<>();
final Object[] listChildren = myModel.toArray();
for (final Object child : listChildren) {
if (!(child instanceof NodeDescriptor)) {
continue;
}
final NodeDescriptor descriptor = (NodeDescriptor) child;
descriptor.update();
final Object newElement = descriptor.getElement();
final Integer index = newElement != null ? elementToIndexMap.get(newElement) : null;
if (index != null) {
resultDescriptors.add(descriptor);
descriptor.setIndex(index.intValue());
elementToIndexMap.remove(newElement);
}
}
for (final Object child : elementToIndexMap.keySet()) {
final Integer index = elementToIndexMap.get(child);
if (index != null) {
final NodeDescriptor childDescr = myTreeStructure.createDescriptor(child, parentDescriptor);
childDescr.setIndex(index.intValue());
childDescr.update();
resultDescriptors.add(childDescr);
}
}
final SelectionInfo selection = storeSelection();
if (myComparator != null) {
Collections.sort(resultDescriptors, myComparator);
} else {
Collections.sort(resultDescriptors, IndexComparator.INSTANCE);
}
if (shouldAddTopElement()) {
final List elems = new ArrayList();
elems.add(new TopLevelNode(myProject, parentDescriptor.getValue()));
elems.addAll(resultDescriptors);
myModel.replaceElements(elems);
} else {
myModel.replaceElements(resultDescriptors);
}
restoreSelection(selection);
updateParentTitle();
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class BaseProjectTreeBuilder method expandNodeChildren.
@Override
protected final void expandNodeChildren(@NotNull final DefaultMutableTreeNode node) {
final NodeDescriptor userObject = (NodeDescriptor) node.getUserObject();
if (userObject == null)
return;
Object element = userObject.getElement();
VirtualFile virtualFile = getFileToRefresh(element);
super.expandNodeChildren(node);
if (virtualFile != null) {
virtualFile.refresh(true, false);
}
}
Aggregations