use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class TodoPanel method updatePreviewPanel.
private void updatePreviewPanel() {
if (myProject == null || myProject.isDisposed())
return;
List<UsageInfo> infos = new ArrayList<>();
final TreePath path = myTree.getSelectionPath();
if (path != null) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object userObject = node.getUserObject();
if (userObject instanceof NodeDescriptor) {
Object element = ((NodeDescriptor) userObject).getElement();
TodoItemNode pointer = myTodoTreeBuilder.getFirstPointerForElement(element);
if (pointer != null) {
final SmartTodoItemPointer value = pointer.getValue();
final Document document = value.getDocument();
final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
final RangeMarker rangeMarker = value.getRangeMarker();
if (psiFile != null) {
infos.add(new UsageInfo(psiFile, rangeMarker.getStartOffset(), rangeMarker.getEndOffset()));
}
}
}
}
myUsagePreviewPanel.updateLayout(infos.isEmpty() ? null : infos);
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class TodoPanel method getData.
@Override
public Object getData(String dataId) {
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
TreePath path = myTree.getSelectionPath();
if (path == null) {
return null;
}
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object userObject = node.getUserObject();
if (!(userObject instanceof NodeDescriptor)) {
return null;
}
Object element = ((NodeDescriptor) userObject).getElement();
if (!(element instanceof TodoFileNode || element instanceof TodoItemNode)) {
// allow user to use F4 only on files an TODOs
return null;
}
TodoItemNode pointer = myTodoTreeBuilder.getFirstPointerForElement(element);
if (pointer != null) {
return new OpenFileDescriptor(myProject, pointer.getValue().getTodoItem().getFile().getVirtualFile(), pointer.getValue().getRangeMarker().getStartOffset());
} else {
return null;
}
} else if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
final PsiFile file = getSelectedFile();
return file != null ? file.getVirtualFile() : null;
} else if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
return getSelectedElement();
} else if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
PsiFile file = getSelectedFile();
if (file != null) {
return new VirtualFile[] { file.getVirtualFile() };
} else {
return VirtualFile.EMPTY_ARRAY;
}
} else if (PlatformDataKeys.HELP_ID.is(dataId)) {
//noinspection HardCodedStringLiteral
return "find.todoList";
}
return super.getData(dataId);
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project intellij-community by JetBrains.
the class ComponentTree method getSelectedElements.
public <T> List<T> getSelectedElements(Class<? extends T> elementClass) {
final TreePath[] paths = getSelectionPaths();
if (paths == null) {
return Collections.emptyList();
}
final ArrayList<T> result = new ArrayList<>(paths.length);
for (TreePath path : paths) {
final DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
Object userObject = node.getUserObject();
if (userObject instanceof NodeDescriptor && elementClass.isInstance(((NodeDescriptor) userObject).getElement())) {
//noinspection unchecked
result.add((T) ((NodeDescriptor) node.getUserObject()).getElement());
}
}
return result;
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project android by JetBrains.
the class AndroidProjectViewPane method getData.
@Override
public Object getData(String dataId) {
if (CommonDataKeys.PROJECT.is(dataId)) {
return myProject;
}
if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(dataId)) {
Object o = getSelectedElement();
if (o instanceof PsiDirectory) {
VirtualFile directory = ((PsiDirectory) o).getVirtualFile();
// See https://code.google.com/p/android/issues/detail?id=212522
if (isTopModuleDirectoryOrParent(directory)) {
return new NoOpDeleteProvider();
}
}
}
if (LangDataKeys.MODULE.is(dataId)) {
Object o = getSelectedElement();
if (o instanceof PackageElement) {
PackageElement packageElement = (PackageElement) o;
return packageElement.getModule();
} else if (o instanceof AndroidFacet) {
return ((AndroidFacet) o).getModule();
}
}
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
Object o = getSelectedElement();
if (o instanceof PackageElement) {
PackageElement packageElement = (PackageElement) o;
Module m = packageElement.getModule();
if (m != null) {
PsiDirectory[] folders = packageElement.getPackage().getDirectories(GlobalSearchScope.moduleScope(m));
if (folders.length > 0) {
return folders[0].getVirtualFile();
} else {
return null;
}
}
}
}
if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId)) {
NodeDescriptor selectedDescriptor = getSelectedDescriptor();
if (selectedDescriptor instanceof FileGroupNode) {
PsiFile[] files = ((FileGroupNode) selectedDescriptor).getFiles();
if (files.length > 0) {
List<VirtualFile> virtualFiles = Lists.newArrayListWithExpectedSize(files.length);
for (PsiFile file : files) {
if (file.isValid()) {
virtualFiles.add(file.getVirtualFile());
}
}
return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
}
}
if (selectedDescriptor instanceof DirectoryGroupNode) {
PsiDirectory[] directories = ((DirectoryGroupNode) selectedDescriptor).getDirectories();
if (directories.length > 0) {
List<VirtualFile> virtualFiles = Lists.newArrayListWithExpectedSize(directories.length);
for (PsiDirectory directory : directories) {
if (directory.isValid()) {
virtualFiles.add(directory.getVirtualFile());
}
}
return virtualFiles.toArray(new VirtualFile[virtualFiles.size()]);
}
}
}
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
Object o = getSelectedElement();
if (o instanceof PsiElement) {
return o;
} else if (o instanceof List<?>) {
List<?> l = (List<?>) o;
if (!l.isEmpty() && l.get(0) instanceof PsiElement) {
return l.get(0);
}
}
NodeDescriptor selectedDescriptor = getSelectedDescriptor();
if (selectedDescriptor instanceof FileGroupNode) {
PsiFile[] files = ((FileGroupNode) selectedDescriptor).getFiles();
if (files.length > 0) {
return files[0];
}
}
if (selectedDescriptor instanceof DirectoryGroupNode) {
PsiDirectory[] directories = ((DirectoryGroupNode) selectedDescriptor).getDirectories();
if (directories.length > 0) {
return directories[0];
}
}
}
return super.getData(dataId);
}
use of com.intellij.ide.util.treeView.NodeDescriptor in project android by JetBrains.
the class AndroidResComparator method compare.
@Override
public int compare(Object o1, Object o2) {
if (!(o1 instanceof NodeDescriptor) || !(o2 instanceof NodeDescriptor)) {
return 0;
}
// we only support comparing res file nodes and res group nodes
if (!(o1 instanceof AndroidResFileNode) && !(o1 instanceof AndroidResGroupNode)) {
return 0;
}
if (!(o2 instanceof AndroidResFileNode) && !(o2 instanceof AndroidResGroupNode)) {
return 0;
}
// if one of them is a group node, then we just have to compare them alphabetically
if (o1 instanceof AndroidResGroupNode || o2 instanceof AndroidResGroupNode) {
String n1 = getName(o1);
String n2 = getName(o2);
return StringUtil.compare(n1, n2, false);
}
AndroidResFileNode r1 = (AndroidResFileNode) o1;
AndroidResFileNode r2 = (AndroidResFileNode) o2;
// first check file names
PsiFile file1 = r1.getValue();
PsiFile file2 = r2.getValue();
if (file1 != null && file2 != null) {
int c = StringUtil.compare(file1.getName(), file2.getName(), false);
if (c != 0) {
return c;
}
}
// check folder configurations
FolderConfiguration config1 = r1.getFolderConfiguration();
FolderConfiguration config2 = r2.getFolderConfiguration();
if (config1 != null && config2 != null) {
int c = config1.compareTo(config2);
if (c != 0) {
return c;
}
}
// then check qualifiers
return StringUtil.compare(r1.getQualifier(), r2.getQualifier(), false);
}
Aggregations