Example usage for com.intellij.openapi.actionSystem CommonShortcuts INSERT

List of usage examples for com.intellij.openapi.actionSystem CommonShortcuts INSERT

Introduction

In this page you can find the example usage for com.intellij.openapi.actionSystem CommonShortcuts INSERT.

Prototype

ShortcutSet INSERT

To view the source code for com.intellij.openapi.actionSystem CommonShortcuts INSERT.

Click Source Link

Usage

From source file:com.intellij.codeInspection.ui.InspectionResultsView.java

License:Apache License

@SuppressWarnings({ "NonStaticInitializer" })
private JComponent createRightActionsToolbar() {
    myIncludeAction = new AnAction(InspectionsBundle.message("inspections.result.view.include.action.text")) {
        {//  ww w  .  ja  v a 2s.c  om
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        @Override
        public void actionPerformed(AnActionEvent e) {
            ((InspectionTreeNode) myTree.getSelectionPath().getLastPathComponent()).amnesty();
            updateView(false);
        }

        @Override
        public void update(final AnActionEvent e) {
            final TreePath path = myTree.getSelectionPath();
            e.getPresentation().setEnabled(
                    path != null && !myGlobalInspectionContext.getUIOptions().FILTER_RESOLVED_ITEMS);
        }
    };

    myExcludeAction = new AnAction(InspectionsBundle.message("inspections.result.view.exclude.action.text")) {
        {
            registerCustomShortcutSet(CommonShortcuts.DELETE, myTree);
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            ((InspectionTreeNode) myTree.getSelectionPath().getLastPathComponent()).ignoreElement();
            updateView(false);
        }

        @Override
        public void update(final AnActionEvent e) {
            final TreePath path = myTree.getSelectionPath();
            e.getPresentation().setEnabled(path != null);
        }
    };

    DefaultActionGroup specialGroup = new DefaultActionGroup();
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createGroupBySeverityAction(this));
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createGroupByDirectoryAction(this));
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createFilterResolvedItemsAction(this));
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createShowOutdatedProblemsAction(this));
    specialGroup.add(myGlobalInspectionContext.getUIOptions().createShowDiffOnlyAction(this));
    specialGroup.add(new EditSettingsAction());
    specialGroup.add(new InvokeQuickFixAction(this));
    specialGroup.add(new InspectionsOptionsToolbarAction(this));
    return createToolbar(specialGroup);
}

From source file:com.intellij.debugger.ui.impl.MainWatchPanel.java

License:Apache License

public MainWatchPanel(Project project, DebuggerStateManager stateManager) {
    super(project, stateManager);
    final WatchDebuggerTree watchTree = getWatchTree();

    final AnAction removeWatchesAction = ActionManager.getInstance().getAction(DebuggerActions.REMOVE_WATCH);
    removeWatchesAction.registerCustomShortcutSet(CommonShortcuts.DELETE, watchTree);

    final AnAction newWatchAction = ActionManager.getInstance().getAction(DebuggerActions.NEW_WATCH);
    newWatchAction.registerCustomShortcutSet(CommonShortcuts.INSERT, watchTree);

    final ClickListener mouseListener = new DoubleClickListener() {
        @Override/* www. j ava 2 s  .  c o  m*/
        protected boolean onDoubleClick(MouseEvent e) {
            AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH);
            Presentation presentation = editWatchAction.getTemplatePresentation().clone();
            DataContext context = DataManager.getInstance().getDataContext(watchTree);

            AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation,
                    ActionManager.getInstance(), 0);
            editWatchAction.actionPerformed(actionEvent);
            return true;
        }
    };
    ListenerUtil.addClickListener(watchTree, mouseListener);

    final AnAction editWatchAction = ActionManager.getInstance().getAction(DebuggerActions.EDIT_WATCH);
    editWatchAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)),
            watchTree);
    registerDisposable(new Disposable() {
        public void dispose() {
            ListenerUtil.removeClickListener(watchTree, mouseListener);
            removeWatchesAction.unregisterCustomShortcutSet(watchTree);
            newWatchAction.unregisterCustomShortcutSet(watchTree);
            editWatchAction.unregisterCustomShortcutSet(watchTree);
        }
    });

    DnDManager.getInstance().registerTarget(new DnDNativeTarget() {
        public boolean update(final DnDEvent aEvent) {
            Object object = aEvent.getAttachedObject();
            if (object == null)
                return true;

            String add = DebuggerBundle.message("watchs.add.text");

            if (object.getClass().isArray()) {
                Class<?> type = object.getClass().getComponentType();
                if (DebuggerTreeNodeImpl.class.isAssignableFrom(type)) {
                    aEvent.setHighlighting(myTree, DnDEvent.DropTargetHighlightingType.RECTANGLE
                            | DnDEvent.DropTargetHighlightingType.TEXT);
                    aEvent.setDropPossible(add, new DropActionHandler() {
                        public void performDrop(final DnDEvent aEvent) {
                            addWatchesFrom((DebuggerTreeNodeImpl[]) aEvent.getAttachedObject());
                        }
                    });
                }
            } else if (object instanceof EventInfo) {
                EventInfo info = (EventInfo) object;
                final String text = info.getTextForFlavor(DataFlavor.stringFlavor);
                if (text != null) {
                    aEvent.setHighlighting(myTree, DnDEvent.DropTargetHighlightingType.RECTANGLE
                            | DnDEvent.DropTargetHighlightingType.TEXT);
                    aEvent.setDropPossible(add, new DropActionHandler() {
                        public void performDrop(final DnDEvent aEvent) {
                            addWatchesFrom(text);
                        }
                    });
                }
            }

            return true;
        }

        public void drop(final DnDEvent aEvent) {
        }

        public void cleanUpOnLeave() {
        }

        public void updateDraggedImage(final Image image, final Point dropPoint, final Point imageOffset) {
        }
    }, myTree);
}

From source file:com.intellij.ide.fileTemplates.impl.AllFileTemplatesConfigurable.java

License:Apache License

@Override
public JComponent createComponent() {
    myUIDisposable = Disposer.newDisposable();
    myTemplatesList = new FileTemplateTabAsList(TEMPLATES_TITLE) {
        @Override// w w w .  j  a  v  a2 s .  c o m
        public void onTemplateSelected() {
            onListSelectionChanged();
        }
    };
    myIncludesList = new FileTemplateTabAsList(INCLUDES_TITLE) {
        @Override
        public void onTemplateSelected() {
            onListSelectionChanged();
        }
    };
    myCurrentTab = myTemplatesList;

    final List<FileTemplateTab> allTabs = new ArrayList<FileTemplateTab>(
            Arrays.asList(myTemplatesList, myIncludesList));
    if (FileTemplateManager.getInstance().getAllCodeTemplates().length > 0) {
        myCodeTemplatesList = new FileTemplateTabAsList(CODE_TITLE) {
            @Override
            public void onTemplateSelected() {
                onListSelectionChanged();
            }
        };
        allTabs.add(myCodeTemplatesList);
    }

    final Set<FileTemplateGroupDescriptorFactory> factories = new THashSet<FileTemplateGroupDescriptorFactory>();
    ContainerUtil.addAll(factories,
            ApplicationManager.getApplication().getComponents(FileTemplateGroupDescriptorFactory.class));
    ContainerUtil.addAll(factories,
            Extensions.getExtensions(FileTemplateGroupDescriptorFactory.EXTENSION_POINT_NAME));

    if (!factories.isEmpty()) {
        myJ2eeTemplatesList = new FileTemplateTabAsTree(J2EE_TITLE) {
            @Override
            public void onTemplateSelected() {
                onListSelectionChanged();
            }

            @Override
            protected FileTemplateNode initModel() {
                SortedSet<FileTemplateGroupDescriptor> categories = new TreeSet<FileTemplateGroupDescriptor>(
                        new Comparator<FileTemplateGroupDescriptor>() {
                            @Override
                            public int compare(FileTemplateGroupDescriptor o1, FileTemplateGroupDescriptor o2) {
                                return o1.getTitle().compareTo(o2.getTitle());
                            }
                        });

                for (FileTemplateGroupDescriptorFactory templateGroupFactory : factories) {
                    ContainerUtil.addIfNotNull(templateGroupFactory.getFileTemplatesDescriptor(), categories);
                }

                //noinspection HardCodedStringLiteral
                return new FileTemplateNode("ROOT", null, ContainerUtil.map2List(categories,
                        new Function<FileTemplateGroupDescriptor, FileTemplateNode>() {
                            @Override
                            public FileTemplateNode fun(FileTemplateGroupDescriptor s) {
                                return new FileTemplateNode(s);
                            }
                        }));
            }
        };
        allTabs.add(myJ2eeTemplatesList);
    }
    myTabs = allTabs.toArray(new FileTemplateTab[allTabs.size()]);
    myTabbedPane = new TabbedPaneWrapper(myUIDisposable);
    myTabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    for (FileTemplateTab tab : myTabs) {
        myTabbedPane.addTab(tab.getTitle(), ScrollPaneFactory.createScrollPane(tab.getComponent()));
    }

    myTabbedPane.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            onTabChanged();
        }
    });

    DefaultActionGroup group = new DefaultActionGroup();
    AnAction removeAction = new AnAction(IdeBundle.message("action.remove.template"), null,
            AllIcons.General.Remove) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            onRemove();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            FileTemplate selectedItem = myCurrentTab.getSelectedTemplate();
            e.getPresentation().setEnabled(selectedItem != null
                    && !isInternalTemplate(selectedItem.getName(), myCurrentTab.getTitle()));
        }
    };
    AnAction addAction = new AnAction(IdeBundle.message("action.create.template"), null, AllIcons.General.Add) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            onAdd();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            e.getPresentation()
                    .setEnabled(!(myCurrentTab == myCodeTemplatesList || myCurrentTab == myJ2eeTemplatesList));
        }
    };
    AnAction cloneAction = new AnAction(IdeBundle.message("action.copy.template"), null,
            AllIcons.Actions.Copy) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            onClone();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            e.getPresentation().setEnabled(myCurrentTab != myCodeTemplatesList
                    && myCurrentTab != myJ2eeTemplatesList && myCurrentTab.getSelectedTemplate() != null);
        }
    };
    AnAction resetAction = new AnAction(IdeBundle.message("action.reset.to.default"), null,
            AllIcons.Actions.Reset) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            onReset();
        }

        @Override
        public void update(AnActionEvent e) {
            super.update(e);
            final FileTemplate selectedItem = myCurrentTab.getSelectedTemplate();
            e.getPresentation()
                    .setEnabled(selectedItem instanceof BundledFileTemplate && !selectedItem.isDefault());
        }
    };
    group.add(addAction);
    group.add(removeAction);
    group.add(cloneAction);
    group.add(resetAction);
    addAction.registerCustomShortcutSet(CommonShortcuts.INSERT, myCurrentTab.getComponent());
    removeAction.registerCustomShortcutSet(CommonShortcuts.DELETE, myCurrentTab.getComponent());

    myToolBar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true)
            .getComponent();

    myEditor = new FileTemplateConfigurable();

    myEditor.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            onEditorChanged();
        }
    });

    myMainPanel = new JPanel(new BorderLayout());
    Splitter splitter = new OnePixelSplitter();
    JPanel leftPanel = new JPanel(new BorderLayout());
    leftPanel.add(myToolBar, BorderLayout.NORTH);
    leftPanel.add(myTabbedPane.getComponent(), BorderLayout.CENTER);
    splitter.setFirstComponent(leftPanel);
    myEditorComponent = myEditor.createComponent();
    splitter.setSecondComponent(myEditorComponent);
    myMainPanel.add(splitter, BorderLayout.CENTER);
    return myMainPanel;
}

From source file:com.intellij.profile.codeInspection.ui.actions.AddScopeAction.java

License:Apache License

public AddScopeAction(Tree tree) {
    super("Add Scope", "Add Scope", IconUtil.getAddIcon());
    myTree = tree;/*from  ww  w  .  jav  a  2  s  . com*/
    registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
}

From source file:com.intellij.xdebugger.impl.frame.XWatchesViewImpl.java

License:Apache License

public XWatchesViewImpl(@NotNull XDebugSessionImpl session) {
    myTreePanel = new XDebuggerTreePanel(session.getProject(), session.getDebugProcess().getEditorsProvider(),
            this, null, XDebuggerActions.WATCHES_TREE_POPUP_GROUP, session.getValueMarkers());

    ActionManager actionManager = ActionManager.getInstance();

    XDebuggerTree tree = myTreePanel.getTree();
    actionManager.getAction(XDebuggerActions.XNEW_WATCH).registerCustomShortcutSet(CommonShortcuts.INSERT,
            tree);// w w w .j a  v  a2s.c o m
    actionManager.getAction(XDebuggerActions.XREMOVE_WATCH)
            .registerCustomShortcutSet(CommonShortcuts.getDelete(), tree);

    CustomShortcutSet f2Shortcut = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
    actionManager.getAction(XDebuggerActions.XEDIT_WATCH).registerCustomShortcutSet(f2Shortcut, tree);

    DnDManager.getInstance().registerTarget(this, tree);
    myRootNode = new WatchesRootNode(tree, this, session.getSessionData().getWatchExpressions());
    tree.setRoot(myRootNode, false);

    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTreePanel.getTree())
            .disableUpDownActions();
    decorator.setAddAction(new AnActionButtonRunnable() {
        @Override
        public void run(AnActionButton button) {
            executeAction(XDebuggerActions.XNEW_WATCH);
        }
    });
    decorator.setRemoveAction(new AnActionButtonRunnable() {
        @Override
        public void run(AnActionButton button) {
            executeAction(XDebuggerActions.XREMOVE_WATCH);
        }
    });
    CustomLineBorder border = new CustomLineBorder(CaptionPanel.CNT_ACTIVE_BORDER_COLOR,
            SystemInfo.isMac ? 1 : 0, 0, SystemInfo.isMac ? 0 : 1, 0);
    decorator.setToolbarBorder(border);
    myDecoratedPanel = new MyPanel(decorator.createPanel());
    myDecoratedPanel.setBorder(null);

    myTreePanel.getTree().getEmptyText().setText(XDebuggerBundle.message("debugger.no.watches"));

    installEditListeners();
}

From source file:com.maddyhome.idea.copyright.ui.CopyrightProfilesPanel.java

License:Apache License

@Nullable
protected ArrayList<AnAction> createActions(boolean fromPopup) {
    ArrayList<AnAction> result = new ArrayList<AnAction>();
    result.add(new AnAction("Add", "Add", IconUtil.getAddIcon()) {
        {//from www .ja  va2s.c  om
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            final String name = askForProfileName("Create Copyright Profile", "");
            if (name == null)
                return;
            final CopyrightProfile copyrightProfile = new CopyrightProfile(name);
            addProfileNode(copyrightProfile);
        }
    });
    result.add(new MyDeleteAction(forAll(Conditions.alwaysTrue())));
    result.add(new AnAction("Copy", "Copy", AllIcons.Actions.Copy) {
        {
            registerCustomShortcutSet(
                    new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_MASK)), myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            final String profileName = askForProfileName("Copy Copyright Profile", "");
            if (profileName == null)
                return;
            final CopyrightProfile clone = new CopyrightProfile();
            clone.copyFrom((CopyrightProfile) getSelectedObject());
            clone.setName(profileName);
            addProfileNode(clone);
        }

        public void update(AnActionEvent event) {
            super.update(event);
            event.getPresentation().setEnabled(getSelectedObject() != null);
        }
    });
    result.add(new AnAction("Import", "Import", AllIcons.ToolbarDecorator.Import) {
        public void actionPerformed(AnActionEvent event) {
            final OpenProjectFileChooserDescriptor descriptor = new OpenProjectFileChooserDescriptor(true) {
                @Override
                public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
                    return super.isFileVisible(file, showHiddenFiles) || canContainCopyright(file);
                }

                @Override
                public boolean isFileSelectable(VirtualFile file) {
                    return super.isFileSelectable(file) || canContainCopyright(file);
                }

                private boolean canContainCopyright(VirtualFile file) {
                    return !file.isDirectory() && file.getFileType() == InternalStdFileTypes.XML;
                }
            };
            descriptor.setTitle("Choose file containing copyright notice");
            final VirtualFile file = FileChooser.chooseFile(descriptor, myProject, null);
            if (file == null)
                return;

            final List<CopyrightProfile> copyrightProfiles = ExternalOptionHelper
                    .loadOptions(VfsUtil.virtualToIoFile(file));
            if (copyrightProfiles == null)
                return;
            if (!copyrightProfiles.isEmpty()) {
                if (copyrightProfiles.size() == 1) {
                    importProfile(copyrightProfiles.get(0));
                } else {
                    JBPopupFactory.getInstance()
                            .createListPopup(new BaseListPopupStep<CopyrightProfile>("Choose profile to import",
                                    copyrightProfiles) {
                                @Override
                                public PopupStep onChosen(final CopyrightProfile selectedValue,
                                        boolean finalChoice) {
                                    return doFinalStep(new Runnable() {
                                        public void run() {
                                            importProfile(selectedValue);
                                        }
                                    });
                                }

                                @NotNull
                                @Override
                                public String getTextFor(CopyrightProfile value) {
                                    return value.getName();
                                }
                            }).showUnderneathOf(myNorthPanel);
                }
            } else {
                Messages.showWarningDialog(myProject,
                        "The selected file does not contain any copyright settings.", "Import Failure");
            }
        }

        private void importProfile(CopyrightProfile copyrightProfile) {
            final String profileName = askForProfileName("Import copyright profile",
                    copyrightProfile.getName());
            if (profileName == null)
                return;
            copyrightProfile.setName(profileName);
            addProfileNode(copyrightProfile);
            Messages.showInfoMessage(myProject, "The copyright settings have been successfully imported.",
                    "Import Complete");
        }
    });
    return result;
}

From source file:net.andydvorak.intellij.lessc.ui.configurable.LessProfilesPanel.java

License:Apache License

@Nullable
protected ArrayList<AnAction> createActions(boolean fromPopup) {
    final ArrayList<AnAction> result = new ArrayList<AnAction>();

    final String addText = UIBundle.message("action.add.less.profile.text");
    final String addDescription = UIBundle.message("action.add.less.profile.description");
    final String addPromptTitle = UIBundle.message("action.add.less.profile.prompt.title");

    result.add(new AnAction(addText, addDescription, PlatformIcons.ADD_ICON) {
        {//from ww w.j  a  v  a 2s  .c  om
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            final String name = askForProfileName(addPromptTitle, "");
            if (name == null)
                return;
            final LessProfile lessProfile = new LessProfile(name);
            addProfileNode(lessProfile);
        }
    });

    result.add(new MyDeleteAction(forAll(Conditions.alwaysTrue())));

    final String copyText = UIBundle.message("action.copy.less.profile.text");
    final String copyDescription = UIBundle.message("action.copy.less.profile.description");
    final String copyPromptTitle = UIBundle.message("action.copy.less.profile.description");

    result.add(new AnAction(copyText, copyDescription, PlatformIcons.COPY_ICON) {
        {
            registerCustomShortcutSet(
                    new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_MASK)), myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            final String profileName = askForProfileName(copyPromptTitle, "");
            if (profileName == null)
                return;
            final LessProfile clone = new LessProfile((LessProfile) getSelectedObject());
            clone.setName(profileName);
            addProfileNode(clone);
        }

        public void update(AnActionEvent event) {
            super.update(event);
            event.getPresentation().setEnabled(getSelectedObject() != null);
        }
    });

    return result;
}

From source file:org.intellij.plugins.intelliLang.InjectionsSettingsUI.java

License:Apache License

private DefaultActionGroup createActions() {
    final Consumer<BaseInjection> consumer = new Consumer<BaseInjection>() {
        @Override/*from  w w w .  j  a v a  2s  . c om*/
        public void consume(final BaseInjection injection) {
            addInjection(injection);
        }
    };
    final Factory<BaseInjection> producer = new NullableFactory<BaseInjection>() {
        @Override
        public BaseInjection create() {
            final InjInfo info = getSelectedInjection();
            return info == null ? null : info.injection;
        }
    };
    for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
        ContainerUtil.addAll(myAddActions, support.createAddActions(myProject, consumer));
        final AnAction action = support.createEditAction(myProject, producer);
        myEditActions.put(support.getId(),
                action == null ? AbstractLanguageInjectionSupport.createDefaultEditAction(myProject, producer)
                        : action);
        mySupports.put(support.getId(), support);
    }
    Collections.sort(myAddActions, new Comparator<AnAction>() {
        @Override
        public int compare(final AnAction o1, final AnAction o2) {
            return Comparing.compare(o1.getTemplatePresentation().getText(),
                    o2.getTemplatePresentation().getText());
        }
    });

    final DefaultActionGroup group = new DefaultActionGroup();
    final AnAction addAction = new AnAction("Add", "Add", IconUtil.getAddIcon()) {
        @Override
        public void update(final AnActionEvent e) {
            e.getPresentation().setEnabled(!myAddActions.isEmpty());
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            performAdd(e);
        }
    };
    final AnAction removeAction = new AnAction("Remove", "Remove", PlatformIcons.DELETE_ICON) {
        @Override
        public void update(final AnActionEvent e) {
            boolean enabled = false;
            for (InjInfo info : getSelectedInjections()) {
                if (!info.bundled) {
                    enabled = true;
                    break;
                }
            }
            e.getPresentation().setEnabled(enabled);
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            performRemove();
        }
    };

    final AnAction editAction = new AnAction("Edit", "Edit", PlatformIcons.PROPERTIES_ICON) {
        @Override
        public void update(final AnActionEvent e) {
            final AnAction action = getEditAction();
            e.getPresentation().setEnabled(action != null);
            if (action != null) {
                action.update(e);
            }
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            performEditAction(e);
        }
    };
    final AnAction copyAction = new AnAction("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
        @Override
        public void update(final AnActionEvent e) {
            final AnAction action = getEditAction();
            e.getPresentation().setEnabled(action != null);
            if (action != null) {
                action.update(e);
            }
        }

        @Override
        public void actionPerformed(final AnActionEvent e) {
            final InjInfo injection = getSelectedInjection();
            if (injection != null) {
                addInjection(injection.injection.copy());
                //performEditAction(e);
            }
        }
    };
    group.add(addAction);
    group.add(removeAction);
    group.add(copyAction);
    group.add(editAction);

    addAction.registerCustomShortcutSet(CommonShortcuts.INSERT, myInjectionsTable);
    removeAction.registerCustomShortcutSet(CommonShortcuts.DELETE, myInjectionsTable);
    editAction.registerCustomShortcutSet(CommonShortcuts.ENTER, myInjectionsTable);

    group.addSeparator();
    group.add(new AnAction("Enable Selected Injections", "Enable Selected Injections",
            PlatformIcons.SELECT_ALL_ICON) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            performSelectedInjectionsEnabled(true);
        }
    });
    group.add(new AnAction("Disable Selected Injections", "Disable Selected Injections",
            PlatformIcons.UNSELECT_ALL_ICON) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            performSelectedInjectionsEnabled(false);
        }
    });

    new AnAction("Toggle") {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            performToggleAction();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)),
            myInjectionsTable);

    if (myInfos.length > 1) {
        group.addSeparator();
        final AnAction shareAction = new AnAction("Make Global", null, PlatformIcons.IMPORT_ICON) {
            @Override
            public void actionPerformed(final AnActionEvent e) {
                final List<InjInfo> injections = getSelectedInjections();
                final CfgInfo cfg = getTargetCfgInfo(injections);
                if (cfg == null) {
                    return;
                }
                for (InjInfo info : injections) {
                    if (info.cfgInfo == cfg) {
                        continue;
                    }
                    if (info.bundled) {
                        continue;
                    }
                    info.cfgInfo.injectionInfos.remove(info);
                    cfg.addInjection(info.injection);
                }
                final int[] selectedRows = myInjectionsTable.getSelectedRows();
                myInjectionsTable.getListTableModel().setItems(getInjInfoList(myInfos));
                TableUtil.selectRows(myInjectionsTable, selectedRows);
            }

            @Override
            public void update(final AnActionEvent e) {
                final CfgInfo cfg = getTargetCfgInfo(getSelectedInjections());
                e.getPresentation().setEnabled(cfg != null);
                e.getPresentation().setText(cfg == getDefaultCfgInfo() ? "Make Global" : "Move to Project");
                super.update(e);
            }

            @Nullable
            private CfgInfo getTargetCfgInfo(final List<InjInfo> injections) {
                CfgInfo cfg = null;
                for (InjInfo info : injections) {
                    if (info.bundled) {
                        continue;
                    }
                    if (cfg == null) {
                        cfg = info.cfgInfo;
                    } else if (cfg != info.cfgInfo) {
                        return info.cfgInfo;
                    }
                }
                if (cfg == null) {
                    return cfg;
                }
                for (CfgInfo info : myInfos) {
                    if (info != cfg) {
                        return info;
                    }
                }
                throw new AssertionError();
            }
        };
        shareAction.registerCustomShortcutSet(
                new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, InputEvent.SHIFT_DOWN_MASK)),
                myInjectionsTable);
        group.add(shareAction);
    }
    group.addSeparator();
    group.add(new AnAction("Import", "Import", AllIcons.Actions.Install) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            doImportAction(e.getDataContext());
            updateCountLabel();
        }
    });
    group.add(new AnAction("Export", "Export", AllIcons.Actions.Export) {
        @Override
        public void actionPerformed(final AnActionEvent e) {
            final List<BaseInjection> injections = getInjectionList(getSelectedInjections());
            final VirtualFileWrapper wrapper = FileChooserFactory.getInstance()
                    .createSaveFileDialog(
                            new FileSaverDescriptor("Export Selected " + "Injections to File...", "", "xml"),
                            myProject)
                    .save(null, null);
            if (wrapper == null) {
                return;
            }
            final Configuration configuration = new Configuration();
            configuration.setInjections(injections);
            final Document document = new Document(configuration.getState());
            try {
                JDOMUtil.writeDocument(document, wrapper.getFile(), "\n");
            } catch (IOException ex) {
                final String msg = ex.getLocalizedMessage();
                Messages.showErrorDialog(myProject, msg != null && msg.length() > 0 ? msg : ex.toString(),
                        "Export Failed");
            }
        }

        @Override
        public void update(final AnActionEvent e) {
            e.getPresentation().setEnabled(!getSelectedInjections().isEmpty());
        }
    });

    return group;
}

From source file:org.jetbrains.idea.svn.config.SvnConfigureProxiesComponent.java

License:Apache License

protected ArrayList<AnAction> createActions(final boolean fromPopup) {
    ArrayList<AnAction> result = new ArrayList<AnAction>();
    result.add(new AnAction("Add", "Add", IconUtil.getAddIcon()) {
        {//  ww w . j  av  a2 s  . c o  m
            registerCustomShortcutSet(CommonShortcuts.INSERT, myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            addGroup(null);
        }

    });
    result.add(new MyDeleteAction(forAll(new Condition<Object>() {
        public boolean value(final Object o) {
            if (o instanceof MyNode) {
                final MyNode node = (MyNode) o;
                if (node.getConfigurable() instanceof GroupConfigurable) {
                    final ProxyGroup group = ((GroupConfigurable) node.getConfigurable()).getEditableObject();
                    return !group.isDefault();
                }
            }
            return false;
        }
    })) {
        public void actionPerformed(final AnActionEvent e) {
            final TreePath path = myTree.getSelectionPath();
            final MyNode node = (MyNode) path.getLastPathComponent();
            final MyNode parentNode = (MyNode) node.getParent();
            int idx = parentNode.getIndex(node);

            super.actionPerformed(e);

            idx = (idx == parentNode.getChildCount()) ? idx - 1 : idx;
            if (parentNode.getChildCount() > 0) {
                final TreePath newSelectedPath = new TreePath(parentNode.getPath())
                        .pathByAddingChild(parentNode.getChildAt(idx));
                myTree.setSelectionPath(newSelectedPath);
            }
        }
    });

    result.add(new AnAction("Copy", "Copy", PlatformIcons.COPY_ICON) {
        {
            registerCustomShortcutSet(
                    new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_D, KeyEvent.CTRL_MASK)), myTree);
        }

        public void actionPerformed(AnActionEvent event) {
            // apply - for update of editable object
            try {
                getSelectedConfigurable().apply();
            } catch (ConfigurationException e) {
                // suppress & wait for OK
            }
            final ProxyGroup selectedGroup = (ProxyGroup) getSelectedObject();
            if (selectedGroup != null) {
                addGroup(selectedGroup);
            }
        }

        public void update(AnActionEvent event) {
            super.update(event);
            event.getPresentation().setEnabled(getSelectedObject() != null);
        }
    });
    return result;
}

From source file:org.jetbrains.idea.svn.integrate.IntegratedSelectedOptionsDialog.java

License:Apache License

public IntegratedSelectedOptionsDialog(final Project project, final SVNURL currentBranch,
        final String selectedBranchUrl) {
    super(project, true);
    myMustSelectBeforeOk = true;//from ww w.  j a  v  a 2 s  .  co  m
    myProject = project;
    mySelectedBranchUrl = selectedBranchUrl;
    myVcs = SvnVcs.getInstance(myProject);

    mySelectedRepositoryUUID = SvnUtil.getRepositoryUUID(myVcs, currentBranch);

    setTitle(SvnBundle.message("action.Subversion.integrate.changes.dialog.title"));
    init();

    myWorkingCopiesList.setModel(new DefaultListModel());
    myWorkingCopiesList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(final ListSelectionEvent e) {
            setOKActionEnabled((!myMustSelectBeforeOk) || (myWorkingCopiesList.getSelectedIndex() != -1));
        }
    });
    setOKActionEnabled((!myMustSelectBeforeOk) || (myWorkingCopiesList.getSelectedIndex() != -1));

    final List<WorkingCopyInfo> workingCopyInfoList = new ArrayList<WorkingCopyInfo>();
    final Set<String> workingCopies = SvnBranchMapperManager.getInstance().get(mySelectedBranchUrl);
    if (workingCopies != null) {
        for (String workingCopy : workingCopies) {
            workingCopyInfoList.add(new WorkingCopyInfo(workingCopy, underProject(new File(workingCopy))));
        }
    }
    Collections.sort(workingCopyInfoList, WorkingCopyInfoComparator.getInstance());

    for (WorkingCopyInfo info : workingCopyInfoList) {
        ((DefaultListModel) myWorkingCopiesList.getModel()).addElement(info);
    }
    if (!workingCopyInfoList.isEmpty()) {
        myWorkingCopiesList.setSelectedIndex(0);
    }

    SvnConfiguration svnConfig = SvnConfiguration.getInstance(myVcs.getProject());
    myDryRunCheckbox.setSelected(svnConfig.isMergeDryRun());
    myIgnoreWhitespacesCheckBox.setSelected(svnConfig.isIgnoreSpacesInMerge());

    mySourceInfoLabel.setText(SvnBundle
            .message("action.Subversion.integrate.changes.branch.info.source.label.text", currentBranch));
    myTargetInfoLabel.setText(SvnBundle
            .message("action.Subversion.integrate.changes.branch.info.target.label.text", selectedBranchUrl));

    final String addText = SvnBundle.message("action.Subversion.integrate.changes.dialog.add.wc.text");
    final AnAction addAction = new AnAction(addText, addText, IconUtil.getAddIcon()) {
        {
            registerCustomShortcutSet(CommonShortcuts.INSERT, myWorkingCopiesList);
        }

        public void actionPerformed(final AnActionEvent e) {
            final VirtualFile vFile = FileChooser
                    .chooseFile(FileChooserDescriptorFactory.createSingleFolderDescriptor(), myProject, null);
            if (vFile != null) {
                final File file = new File(vFile.getPath());
                if (hasDuplicate(file)) {
                    return; // silently do not add duplicate
                }

                final String repositoryUUID = SvnUtil.getRepositoryUUID(myVcs, file);

                // local not consistent copy can not prevent us from integration: only remote local copy is really involved
                if ((mySelectedRepositoryUUID != null) && (!mySelectedRepositoryUUID.equals(repositoryUUID))) {
                    if (Messages.OK == Messages.showOkCancelDialog((repositoryUUID == null)
                            ? SvnBundle.message(
                                    "action.Subversion.integrate.changes.message.not.under.control.text")
                            : SvnBundle.message("action.Subversion.integrate.changes.message.another.wc.text"),
                            getTitle(), UIUtil.getWarningIcon())) {
                        onOkToAdd(file);
                    }
                } else {
                    onOkToAdd(file);
                }
            }
        }
    };

    myGroup.add(addAction);

    final String removeText = SvnBundle.message("action.Subversion.integrate.changes.dialog.remove.wc.text");
    myGroup.add(new AnAction(removeText, removeText, PlatformIcons.DELETE_ICON) {
        {
            registerCustomShortcutSet(CommonShortcuts.getDelete(), myWorkingCopiesList);
        }

        public void update(final AnActionEvent e) {
            final Presentation presentation = e.getPresentation();
            final int idx = (myWorkingCopiesList == null) ? -1 : myWorkingCopiesList.getSelectedIndex();
            presentation.setEnabled(idx != -1);
        }

        public void actionPerformed(final AnActionEvent e) {
            final int idx = myWorkingCopiesList.getSelectedIndex();
            if (idx != -1) {
                final DefaultListModel model = (DefaultListModel) myWorkingCopiesList.getModel();
                final WorkingCopyInfo info = (WorkingCopyInfo) model.get(idx);
                model.removeElementAt(idx);
                SvnBranchMapperManager.getInstance().remove(mySelectedBranchUrl, new File(info.getLocalPath()));
            }
        }
    });
}