use of com.intellij.ide.dnd.aware.DnDAwareTree in project intellij-community by JetBrains.
the class HierarchyBrowserBaseEx method createTree.
protected final JTree createTree(boolean dndAware) {
final Tree tree;
final NullableFunction<Object, PsiElement> toPsiConverter = o -> {
if (o instanceof HierarchyNodeDescriptor) {
return ((HierarchyNodeDescriptor) o).getContainingFile();
}
return null;
};
if (dndAware) {
//noinspection Duplicates
tree = new DnDAwareTree(new DefaultTreeModel(new DefaultMutableTreeNode(""))) {
@Override
public void removeNotify() {
super.removeNotify();
if (ScreenUtil.isStandardAddRemoveNotify(this))
myRefreshAction.unregisterCustomShortcutSet(this);
}
@Override
public boolean isFileColorsEnabled() {
return ProjectViewTree.isFileColorsEnabledFor(this);
}
@Override
public Color getFileColorFor(Object object) {
return ProjectViewTree.getColorForObject(object, myProject, toPsiConverter);
}
};
if (!ApplicationManager.getApplication().isHeadlessEnvironment()) {
DnDManager.getInstance().registerSource(new DnDSource() {
@Override
public boolean canStartDragging(final DnDAction action, final Point dragOrigin) {
return getSelectedElements().length > 0;
}
@Override
public DnDDragStartBean startDragging(final DnDAction action, final Point dragOrigin) {
return new DnDDragStartBean(new TransferableWrapper() {
@Override
public TreeNode[] getTreeNodes() {
return tree.getSelectedNodes(TreeNode.class, null);
}
@Override
public PsiElement[] getPsiElements() {
return getSelectedElements();
}
@Override
public List<File> asFileList() {
return PsiCopyPasteManager.asFileList(getPsiElements());
}
});
}
@Override
public Pair<Image, Point> createDraggedImage(final DnDAction action, final Point dragOrigin) {
return null;
}
@Override
public void dragDropEnd() {
}
@Override
public void dropActionChanged(final int gestureModifiers) {
}
}, tree);
}
} else {
//noinspection Duplicates
tree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode(""))) {
@Override
public void removeNotify() {
super.removeNotify();
if (ScreenUtil.isStandardAddRemoveNotify(this))
myRefreshAction.unregisterCustomShortcutSet(this);
}
@Override
public boolean isFileColorsEnabled() {
return ProjectViewTree.isFileColorsEnabledFor(this);
}
@Override
public Color getFileColorFor(Object object) {
return ProjectViewTree.getColorForObject(object, myProject, toPsiConverter);
}
};
}
configureTree(tree);
EditSourceOnDoubleClickHandler.install(tree);
EditSourceOnEnterKeyHandler.install(tree);
myRefreshAction.registerShortcutOn(tree);
return tree;
}
use of com.intellij.ide.dnd.aware.DnDAwareTree in project intellij-community by JetBrains.
the class DeleteFromFavoritesAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
Project project = e.getProject();
FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
if (project == null || builder == null) {
return;
}
Set<Object> selection = builder.getSelectedElements();
if (selection.isEmpty()) {
return;
}
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
FavoritesListProvider provider = favoritesManager.getListProvider(listName);
if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection)) {
provider.handle(CommonActionsPanel.Buttons.REMOVE, project, selection, builder.getTree());
return;
}
FavoritesTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
final DnDAwareTree tree = FavoritesTreeViewPanel.FAVORITES_TREE_KEY.getData(dataContext);
assert roots != null && tree != null;
Map<String, List<AbstractTreeNode>> toRemove = new HashMap<>();
for (FavoritesTreeNodeDescriptor root : roots) {
final AbstractTreeNode node = root.getElement();
if (node instanceof FavoritesListNode) {
favoritesManager.removeFavoritesList((String) node.getValue());
} else {
final FavoritesListNode listNode = FavoritesTreeUtil.extractParentList(root);
LOG.assertTrue(listNode != null);
final String name = listNode.getName();
if (!toRemove.containsKey(name)) {
toRemove.put(name, new ArrayList<>());
}
toRemove.get(name).add(node);
}
}
for (String name : toRemove.keySet()) {
favoritesManager.removeRoot(name, toRemove.get(name));
}
}
Aggregations