@Override public void handle(@NotNull CommonActionsPanel.Buttons type, Project project, @NotNull Set<Object> selectedObjects, JComponent component) { Rectangle bounds = component.getBounds(); if (component instanceof JTree) { JTree tree = (JTree)component; bounds = tree.getRowBounds(tree.getLeadSelectionRow()); bounds.y += bounds.height/2; bounds = tree.getVisibleRect().intersection(bounds); } Point whereToShow = new Point((int)bounds.getCenterX(), (int)bounds.getCenterY()); BreakpointItem breakpointItem = (BreakpointItem)((AbstractTreeNode)selectedObjects.iterator().next()).getValue(); switch (type) { case EDIT: DebuggerSupport debuggerSupport = XBreakpointUtil.getDebuggerSupport(myProject, breakpointItem); if (debuggerSupport == null) return; debuggerSupport.getEditBreakpointAction().editBreakpoint(myProject, component, whereToShow, breakpointItem); break; case REMOVE: breakpointItem.removed(myProject); break; default: break; } }
@Override public boolean willHandle(@NotNull CommonActionsPanel.Buttons type, Project project, @NotNull Set<Object> selectedObjects) { switch (type) { case EDIT: if (selectedObjects.size() != 1) { return false; } Object toEdit = selectedObjects.iterator().next(); return toEdit instanceof AbstractTreeNode && ((AbstractTreeNode)toEdit).getValue() instanceof Bookmark; case REMOVE: for (Object toRemove : selectedObjects) { if (!(toRemove instanceof AbstractTreeNode && ((AbstractTreeNode)toRemove).getValue() instanceof Bookmark)) { return false; } } return true; default: return false; } }
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject(); FavoritesViewTreeBuilder treeBuilder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(e.getDataContext()); String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(e.getDataContext()); if (project == null || treeBuilder == null || listName == null) { return; } FavoritesManager favoritesManager = FavoritesManager.getInstance(project); FavoritesListProvider provider = favoritesManager.getListProvider(listName); Set<Object> selection = treeBuilder.getSelectedElements(); if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection)) { provider.handle(CommonActionsPanel.Buttons.EDIT, project, selection, treeBuilder.getTree()); return; } favoritesManager.renameList(project, listName); }
@Override public void update(AnActionEvent e) { e.getPresentation().setText(getTemplatePresentation().getText()); e.getPresentation().setIcon(CommonActionsPanel.Buttons.EDIT.getIcon()); e.getPresentation().setEnabled(true); Project project = e.getProject(); FavoritesViewTreeBuilder treeBuilder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(e.getDataContext()); String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(e.getDataContext()); if (project == null || treeBuilder == null || listName == null) { e.getPresentation().setEnabled(false); return; } FavoritesManager favoritesManager = FavoritesManager.getInstance(project); FavoritesListProvider provider = favoritesManager.getListProvider(listName); Set<Object> selection = treeBuilder.getSelectedElements(); if (provider != null) { e.getPresentation().setEnabled(provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection)); e.getPresentation().setText(provider.getCustomName(CommonActionsPanel.Buttons.EDIT)); } }
@Override public void update(AnActionEvent e) { e.getPresentation().setText(CommonActionsPanel.Buttons.EDIT.getText()); e.getPresentation().setIcon(CommonActionsPanel.Buttons.EDIT.getIcon()); e.getPresentation().setEnabled(true); Project project = e.getProject(); FavoritesViewTreeBuilder treeBuilder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(e.getDataContext()); String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(e.getDataContext()); if (project == null || treeBuilder == null || listName == null) { e.getPresentation().setEnabled(false); return; } FavoritesManager favoritesManager = FavoritesManager.getInstance(project); FavoritesListProvider provider = favoritesManager.getListProvider(listName); Set<Object> selection = treeBuilder.getSelectedElements(); if (provider != null) { e.getPresentation().setEnabled(provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection)); e.getPresentation().setText(provider.getCustomName(CommonActionsPanel.Buttons.EDIT)); } }
@Override public void handle(@Nonnull CommonActionsPanel.Buttons type, Project project, @Nonnull Set<Object> selectedObjects, JComponent component) { Rectangle bounds = component.getBounds(); if (component instanceof JTree) { JTree tree = (JTree)component; bounds = tree.getRowBounds(tree.getLeadSelectionRow()); bounds.y += bounds.height/2; bounds = tree.getVisibleRect().intersection(bounds); } Point whereToShow = new Point((int)bounds.getCenterX(), (int)bounds.getCenterY()); BreakpointItem breakpointItem = (BreakpointItem)((AbstractTreeNode)selectedObjects.iterator().next()).getValue(); switch (type) { case EDIT: DebuggerSupport debuggerSupport = XBreakpointUtil.getDebuggerSupport(myProject, breakpointItem); if (debuggerSupport == null) return; debuggerSupport.getEditBreakpointAction().editBreakpoint(myProject, component, whereToShow, breakpointItem); break; case REMOVE: breakpointItem.removed(myProject); break; default: break; } }
@Override public boolean willHandle(@Nonnull CommonActionsPanel.Buttons type, Project project, @Nonnull Set<Object> selectedObjects) { switch (type) { case EDIT: if (selectedObjects.size() != 1) { return false; } Object toEdit = selectedObjects.iterator().next(); return toEdit instanceof AbstractTreeNode && ((AbstractTreeNode)toEdit).getValue() instanceof Bookmark; case REMOVE: for (Object toRemove : selectedObjects) { if (!(toRemove instanceof AbstractTreeNode && ((AbstractTreeNode)toRemove).getValue() instanceof Bookmark)) { return false; } } return true; default: return false; } }
@Override public void actionPerformed(AnActionEvent e) { Project project = e.getProject(); FavoritesViewTreeBuilder treeBuilder = e.getDataContext().getData(FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY); String listName = e.getDataContext().getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY); if (project == null || treeBuilder == null || listName == null) { return; } FavoritesManager favoritesManager = FavoritesManager.getInstance(project); FavoritesListProvider provider = favoritesManager.getListProvider(listName); Set<Object> selection = treeBuilder.getSelectedElements(); if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection)) { provider.handle(CommonActionsPanel.Buttons.EDIT, project, selection, treeBuilder.getTree()); return; } favoritesManager.renameList(project, listName); }
@Override public void update(AnActionEvent e) { e.getPresentation().setText(CommonActionsPanel.Buttons.EDIT.getText()); e.getPresentation().setIcon(CommonActionsPanel.Buttons.EDIT.getIcon()); e.getPresentation().setEnabled(true); Project project = e.getProject(); FavoritesViewTreeBuilder treeBuilder = e.getDataContext().getData(FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY); String listName = e.getDataContext().getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY); if (project == null || treeBuilder == null || listName == null) { e.getPresentation().setEnabled(false); return; } FavoritesManager favoritesManager = FavoritesManager.getInstance(project); FavoritesListProvider provider = favoritesManager.getListProvider(listName); Set<Object> selection = treeBuilder.getSelectedElements(); if (provider != null) { e.getPresentation().setEnabled(provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection)); e.getPresentation().setText(provider.getCustomName(CommonActionsPanel.Buttons.EDIT)); } }
@Nullable @Override public String getCustomName(@NotNull CommonActionsPanel.Buttons type) { switch (type) { case EDIT: return "Edit breakpoint"; case REMOVE: return "Remove breakpoint"; default: return null; } }
@Nullable @Override public String getCustomName(@NotNull CommonActionsPanel.Buttons type) { switch (type) { case EDIT: return IdeBundle.message("action.bookmark.edit.description"); case REMOVE: return IdeBundle.message("action.bookmark.delete"); default: return null; } }
private void clickButton(CommonActionsPanel.Buttons button) { final AnActionButton action = getAnActionButton(button); final AnActionEvent event = new TestActionEvent(action); execute(new GuiTask() { @Override protected void executeInEDT() throws Throwable { action.actionPerformed(event); } }); }
@Nullable @Override public String getCustomName(@Nonnull CommonActionsPanel.Buttons type) { switch (type) { case EDIT: return "Edit breakpoint"; case REMOVE: return "Remove breakpoint"; default: return null; } }
@Nullable @Override public String getCustomName(@Nonnull CommonActionsPanel.Buttons type) { switch (type) { case EDIT: return IdeBundle.message("action.bookmark.edit.description"); case REMOVE: return IdeBundle.message("action.bookmark.delete"); default: return null; } }
@Override public boolean willHandle(@NotNull CommonActionsPanel.Buttons type, Project project, @NotNull Set<Object> selectedObjects) { return (selectedObjects.size() == 1 && (type == CommonActionsPanel.Buttons.EDIT || type == CommonActionsPanel.Buttons.REMOVE)) && ((AbstractTreeNode)selectedObjects.iterator().next()).getValue() instanceof BreakpointItem; }
@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; } } }
@Nullable String getCustomName(@NotNull CommonActionsPanel.Buttons type);
@Nullable @Override public String getCustomName(@NotNull CommonActionsPanel.Buttons type) { return null; }
@Override public boolean willHandle(@NotNull CommonActionsPanel.Buttons type, Project project, @NotNull Set<Object> selectedObjects) { return false; }
@Override public void handle(@NotNull CommonActionsPanel.Buttons type, Project project, @NotNull Set<Object> selectedObjects, JComponent component) { }
public AddAction() { setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD)); }
public EditAction() { super(ApplicationBundle.message("action.edit"), null, EDIT_ICON); setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.EDIT)); }
public RemoveAction() { super(ApplicationBundle.message("action.remove"), null, REMOVE_ICON); setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.REMOVE)); }
protected ShowPopupAction(ActionGroup group) { super(ApplicationBundle.message("action.add"), null, DomCollectionControl.ADD_ICON); myGroup = group; setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD)); }
@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); 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)); } 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; } } }
public EditAction() { super(ApplicationBundle.message("action.edit"), null, DomCollectionControl.EDIT_ICON); setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.EDIT)); }
public RemoveAction() { super(ApplicationBundle.message("action.remove"), null, DomCollectionControl.REMOVE_ICON); setShortcutSet(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.REMOVE)); }
private AnActionButton getAnActionButton(CommonActionsPanel.Buttons button) { return panel.getToolbarDecorator() .getActionsPanel() .getAnActionButton(button); }