use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class UsageFavoriteNodeProvider method getFavoriteNodes.
@Override
public Collection<AbstractTreeNode> getFavoriteNodes(DataContext context, ViewSettings viewSettings) {
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
return null;
}
final Usage[] usages = UsageView.USAGES_KEY.getData(context);
if (usages != null) {
final List<AbstractTreeNode> result = new SmartList<>();
final MultiMap<VirtualFile, Usage> map = new MultiMap<>();
final List<Usage> nonMapped = new ArrayList<>();
for (Usage usage : usages) {
if (usage instanceof UsageInFile) {
map.putValue(((UsageInFile) usage).getFile(), usage);
} else if (usage instanceof UsageInFiles) {
final VirtualFile[] files = ((UsageInFiles) usage).getFiles();
for (VirtualFile file : files) {
map.putValue(file, usage);
}
} else {
nonMapped.add(usage);
}
}
final TreeSet<VirtualFile> keys = new TreeSet<>(VIRTUAL_FILE_COMPARATOR);
keys.addAll(map.keySet());
for (VirtualFile key : keys) {
final FileGroupingProjectNode grouping = new FileGroupingProjectNode(project, new File(key.getPath()), viewSettings);
result.add(grouping);
final Collection<Usage> subUsages = map.get(key);
for (Usage usage : subUsages) {
if (usage instanceof UsageInfo2UsageAdapter) {
final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
grouping.addChild(node);
} else if (NullUsage.INSTANCE.equals(usage)) {
continue;
} else {
grouping.addChild(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
}
}
}
for (Usage usage : nonMapped) {
if (usage instanceof UsageInfo2UsageAdapter) {
final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
result.add(node);
} else if (NullUsage.INSTANCE.equals(usage)) {
continue;
} else {
result.add(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
}
}
return result;
}
return null;
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class AddToFavoritesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
Collection<AbstractTreeNode> nodesToAdd = getNodesToAdd(dataContext, true);
if (!nodesToAdd.isEmpty()) {
Project project = e.getProject();
FavoritesManager.getInstance(project).addRoots(myFavoritesListName, nodesToAdd);
}
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class AddToNewFavoritesListAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
Project project = e.getProject();
Collection<AbstractTreeNode> nodesToAdd = AddToFavoritesAction.getNodesToAdd(e.getDataContext(), true);
if (!nodesToAdd.isEmpty()) {
final String newName = AddNewFavoritesListAction.doAddNewFavoritesList(project);
if (newName != null) {
FavoritesManager.getInstance(project).addRoots(newName, nodesToAdd);
}
}
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class DeleteFromFavoritesAction method updateButton.
@Override
public void updateButton(AnActionEvent e) {
e.getPresentation().setText(getTemplatePresentation().getText());
final DataContext dataContext = e.getDataContext();
Project project = e.getProject();
FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
if (project == null || builder == null) {
e.getPresentation().setEnabled(false);
return;
}
Set<Object> selection = builder.getSelectedElements();
String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
if (listName == null) {
//Selection is empty or contains several items under favorites/bookmarks/breakpoints at the same time
e.getPresentation().setText(CommonActionsPanel.Buttons.REMOVE.getText());
e.getPresentation().setEnabled(false);
return;
}
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
FavoritesListProvider provider = favoritesManager.getListProvider(listName);
if (provider != null) {
boolean willHandle = provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection);
e.getPresentation().setEnabled(willHandle);
if (willHandle) {
e.getPresentation().setText(provider.getCustomName(CommonActionsPanel.Buttons.REMOVE));
} else {
e.getPresentation().setText(CommonActionsPanel.Buttons.REMOVE.getText());
}
return;
}
FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
if (roots == null || roots.length == 0 || selection.isEmpty()) {
e.getPresentation().setEnabled(false);
return;
}
for (Object o : selection) {
if (o instanceof AbstractTreeNode) {
AbstractTreeNode node = (AbstractTreeNode) o;
int deep = getDeep(node);
if (deep != 2 && deep != 3) {
//favorite list or it's nested "root"
e.getPresentation().setEnabled(false);
return;
}
} else {
e.getPresentation().setEnabled(false);
return;
}
}
}
use of com.intellij.ide.util.treeView.AbstractTreeNode in project intellij-community by JetBrains.
the class SendToFavoritesAction method doSend.
public void doSend(final FavoritesManager favoritesManager, final FavoritesTreeNodeDescriptor[] roots, final String listName) {
for (FavoritesTreeNodeDescriptor root : roots) {
final AbstractTreeNode rootElement = root.getElement();
String name = listName;
if (name == null) {
name = root.getFavoritesRoot().getName();
}
favoritesManager.removeRoot(name, Collections.singletonList(rootElement));
favoritesManager.addRoots(toName, Collections.singletonList(rootElement));
}
}
Aggregations