Search in sources :

Example 6 with AnActionButtonRunnable

use of com.intellij.ui.AnActionButtonRunnable in project intellij-community by JetBrains.

the class CertificateConfigurable method initializeUI.

private void initializeUI() {
    myTree = new Tree();
    myTreeBuilder = new CertificateTreeBuilder(myTree);
    myTrustManager = CertificateManager.getInstance().getCustomTrustManager();
    // show newly added certificates
    myTrustManager.addListener(this);
    myTree.getEmptyText().setText("No certificates");
    myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    myTree.setRootVisible(false);
    //myTree.setShowsRootHandles(false);
    ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions();
    decorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            // show choose file dialog, add certificate
            FileChooser.chooseFile(CERTIFICATE_DESCRIPTOR, null, null, file -> {
                String path = file.getPath();
                X509Certificate certificate = CertificateUtil.loadX509Certificate(path);
                if (certificate == null) {
                    Messages.showErrorDialog(myRootPanel, "Malformed X509 server certificate", "Not Imported");
                } else if (myCertificates.contains(certificate)) {
                    Messages.showWarningDialog(myRootPanel, "Certificate already exists", "Not Imported");
                } else {
                    myCertificates.add(certificate);
                    myTreeBuilder.addCertificate(certificate);
                    addCertificatePanel(certificate);
                    myTreeBuilder.selectCertificate(certificate);
                }
            });
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            // allow to delete several certificates at once
            for (X509Certificate certificate : myTreeBuilder.getSelectedCertificates(true)) {
                myCertificates.remove(certificate);
                myTreeBuilder.removeCertificate(certificate);
            }
            if (myCertificates.isEmpty()) {
                showCard(EMPTY_PANEL);
            } else {
                myTreeBuilder.selectFirstCertificate();
            }
        }
    });
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            X509Certificate certificate = myTreeBuilder.getFirstSelectedCertificate(true);
            if (certificate != null) {
                showCard(getCardName(certificate));
            }
        }
    });
    myCertificatesListPanel.add(decorator.createPanel(), BorderLayout.CENTER);
}
Also used : AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) Tree(com.intellij.ui.treeStructure.Tree) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) AnActionButton(com.intellij.ui.AnActionButton) X509Certificate(java.security.cert.X509Certificate)

Example 7 with AnActionButtonRunnable

use of com.intellij.ui.AnActionButtonRunnable in project intellij-community by JetBrains.

the class LibraryRootsComponent method init.

private void init(AbstractTreeStructure treeStructure) {
    myTree = new Tree(new DefaultTreeModel(new DefaultMutableTreeNode()));
    myTree.setRootVisible(false);
    myTree.setShowsRootHandles(true);
    new LibraryRootsTreeSpeedSearch(myTree);
    myTree.setCellRenderer(new LibraryTreeRenderer());
    myTreeBuilder = new LibraryTableTreeBuilder(myTree, (DefaultTreeModel) myTree.getModel(), treeStructure);
    myTreePanel.setLayout(new BorderLayout());
    ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(myTree).disableUpDownActions().setRemoveActionName(ProjectBundle.message("library.remove.action")).disableRemoveAction();
    toolbarDecorator.setPanelBorder(new CustomLineBorder(1, 0, 0, 0));
    final List<AttachRootButtonDescriptor> popupItems = new ArrayList<>();
    for (AttachRootButtonDescriptor descriptor : myDescriptor.createAttachButtons()) {
        Icon icon = descriptor.getToolbarIcon();
        if (icon != null) {
            AttachItemAction action = new AttachItemAction(descriptor, descriptor.getButtonText(), icon);
            toolbarDecorator.addExtraAction(AnActionButton.fromAction(action));
        } else {
            popupItems.add(descriptor);
        }
    }
    myAddExcludedRootActionButton = new AddExcludedRootActionButton();
    toolbarDecorator.addExtraAction(myAddExcludedRootActionButton);
    toolbarDecorator.addExtraAction(new AnActionButton("Remove", IconUtil.getRemoveIcon()) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            final Object[] selectedElements = getSelectedElements();
            if (selectedElements.length == 0) {
                return;
            }
            ApplicationManager.getApplication().runWriteAction(() -> {
                for (Object selectedElement : selectedElements) {
                    if (selectedElement instanceof ItemElement) {
                        final ItemElement itemElement = (ItemElement) selectedElement;
                        getLibraryEditor().removeRoot(itemElement.getUrl(), itemElement.getRootType());
                    } else if (selectedElement instanceof OrderRootTypeElement) {
                        final OrderRootType rootType = ((OrderRootTypeElement) selectedElement).getOrderRootType();
                        final String[] urls = getLibraryEditor().getUrls(rootType);
                        for (String url : urls) {
                            getLibraryEditor().removeRoot(url, rootType);
                        }
                    } else if (selectedElement instanceof ExcludedRootElement) {
                        getLibraryEditor().removeExcludedRoot(((ExcludedRootElement) selectedElement).getUrl());
                    }
                }
            });
            libraryChanged(true);
        }

        @Override
        public void updateButton(AnActionEvent e) {
            super.updateButton(e);
            Object[] elements = getSelectedElements();
            Presentation presentation = e.getPresentation();
            if (ContainerUtil.and(elements, new FilteringIterator.InstanceOf<>(ExcludedRootElement.class))) {
                presentation.setText("Cancel Exclusion");
            } else {
                presentation.setText(getTemplatePresentation().getText());
            }
        }

        @Override
        public ShortcutSet getShortcut() {
            return CommonShortcuts.getDelete();
        }
    });
    toolbarDecorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            if (popupItems.isEmpty()) {
                new AttachFilesAction(myDescriptor.getAttachFilesActionName()).actionPerformed(null);
                return;
            }
            List<AnAction> actions = new ArrayList<>();
            actions.add(new AttachFilesAction(myDescriptor.getAttachFilesActionName()));
            for (AttachRootButtonDescriptor descriptor : popupItems) {
                actions.add(new AttachItemAction(descriptor, descriptor.getButtonText(), null));
            }
            final DefaultActionGroup group = new DefaultActionGroup(actions);
            JBPopupFactory.getInstance().createActionGroupPopup(null, group, DataManager.getInstance().getDataContext(button.getContextComponent()), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true).show(button.getPreferredPopupPoint());
        }
    });
    myTreePanel.add(toolbarDecorator.createPanel(), BorderLayout.CENTER);
    Disposer.register(this, myTreeBuilder);
}
Also used : AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Tree(com.intellij.ui.treeStructure.Tree) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) List(java.util.List) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) AnActionButton(com.intellij.ui.AnActionButton) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) PersistentOrderRootType(com.intellij.openapi.roots.PersistentOrderRootType) OrderRootType(com.intellij.openapi.roots.OrderRootType)

Example 8 with AnActionButtonRunnable

use of com.intellij.ui.AnActionButtonRunnable in project intellij-community by JetBrains.

the class JsonSchemaMappingsView method createUI.

private void createUI(final Project project) {
    myProject = project;
    myTableView = new TableView<>();
    myTableView.getTableHeader().setVisible(false);
    myDecorator = ToolbarDecorator.createDecorator(myTableView);
    myDecorator.setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final int[] rows = myTableView.getSelectedRows();
            if (rows != null && rows.length > 0) {
                int cnt = 0;
                for (int row : rows) {
                    myTableView.getListTableModel().removeRow(row - cnt);
                    ++cnt;
                }
                myTableView.getListTableModel().fireTableDataChanged();
                myTreeUpdater.run();
            }
        }
    }).setAddAction(new MyAddActionButtonRunnable(project)).disableUpDownActions();
    mySchemaField = new TextFieldWithBrowseButton();
    SwingHelper.installFileCompletionAndBrowseDialog(myProject, mySchemaField, JsonBundle.message("json.schema.add.schema.chooser.title"), FileChooserDescriptorFactory.createSingleFileDescriptor());
    attachNavigateToSchema();
    myError = SwingHelper.createHtmlLabel("Warning: conflicting mappings. <a href=\"#\">Show details</a>", null, s -> {
        final BalloonBuilder builder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(myErrorText, UIUtil.getBalloonWarningIcon(), MessageType.WARNING.getPopupBackground(), null);
        builder.setDisposable(this);
        builder.setHideOnClickOutside(true);
        builder.setCloseButtonEnabled(true);
        builder.createBalloon().showInCenterOf(myError);
    });
    final FormBuilder builder = FormBuilder.createFormBuilder();
    final JBLabel label = new JBLabel("JSON schema file:");
    builder.addLabeledComponent(label, mySchemaField);
    label.setBorder(JBUI.Borders.empty(0, 10, 0, 10));
    mySchemaField.setBorder(JBUI.Borders.empty(0, 0, 0, 10));
    final JPanel wrapper = new JPanel(new BorderLayout());
    wrapper.setBorder(JBUI.Borders.empty(0, 10, 0, 10));
    myErrorIcon = new JBLabel(UIUtil.getBalloonWarningIcon());
    wrapper.add(myErrorIcon, BorderLayout.WEST);
    wrapper.add(myError, BorderLayout.CENTER);
    builder.addComponent(wrapper);
    builder.addComponentFillVertically(myDecorator.createPanel(), 5);
    myComponent = builder.getPanel();
}
Also used : FileChooserDescriptorFactory(com.intellij.openapi.fileChooser.FileChooserDescriptorFactory) Getter(com.intellij.openapi.util.Getter) MessageType(com.intellij.openapi.ui.MessageType) ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBLabel(com.intellij.ui.components.JBLabel) ArrayList(java.util.ArrayList) Balloon(com.intellij.openapi.ui.popup.Balloon) JBTextField(com.intellij.ui.components.JBTextField) DialogBuilder(com.intellij.openapi.ui.DialogBuilder) Disposer(com.intellij.openapi.util.Disposer) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) AnActionButton(com.intellij.ui.AnActionButton) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JsonBundle(com.intellij.json.JsonBundle) StringUtil(com.intellij.openapi.util.text.StringUtil) TableView(com.intellij.ui.table.TableView) JBRadioButton(com.intellij.ui.components.JBRadioButton) ActionEvent(java.awt.event.ActionEvent) Disposable(com.intellij.openapi.Disposable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) File(java.io.File) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) Nullable(org.jetbrains.annotations.Nullable) CommonShortcuts(com.intellij.openapi.actionSystem.CommonShortcuts) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) com.intellij.util.ui(com.intellij.util.ui) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) JBPanel(com.intellij.ui.components.JBPanel) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) JBLabel(com.intellij.ui.components.JBLabel) AnActionButton(com.intellij.ui.AnActionButton) BalloonBuilder(com.intellij.openapi.ui.popup.BalloonBuilder)

Example 9 with AnActionButtonRunnable

use of com.intellij.ui.AnActionButtonRunnable in project google-cloud-intellij by GoogleCloudPlatform.

the class BreakpointConfigurationPanel method loadFrom.

@Override
public void loadFrom(@NotNull XLineBreakpoint<CloudLineBreakpointProperties> breakpoint) {
    XBreakpointBase lineBreakpointImpl = breakpoint instanceof XBreakpointBase ? (XBreakpointBase) breakpoint : null;
    Breakpoint javaBreakpoint = BreakpointManager.getJavaBreakpoint(breakpoint);
    CloudLineBreakpointType.CloudLineBreakpoint cloudBreakpoint = null;
    if (javaBreakpoint instanceof CloudLineBreakpointType.CloudLineBreakpoint) {
        cloudBreakpoint = (CloudLineBreakpointType.CloudLineBreakpoint) javaBreakpoint;
    }
    if (cloudBreakpoint == null || lineBreakpointImpl == null) {
        return;
    }
    XDebuggerEditorsProvider debuggerEditorsProvider = cloudLineBreakpointType.getEditorsProvider(breakpoint, cloudBreakpoint.getProject());
    if (debuggerEditorsProvider != null) {
        treePanel = new XDebuggerTreePanel(cloudBreakpoint.getProject(), debuggerEditorsProvider, this, breakpoint.getSourcePosition(), "GoogleCloudTools.BreakpointWatchContextMenu", null);
        List<XExpression> watches = new ArrayList<XExpression>();
        for (String watchExpression : breakpoint.getProperties().getWatchExpressions()) {
            watches.add(debuggerEditorsProvider.createExpression(((XBreakpointBase) breakpoint).getProject(), new DocumentImpl(watchExpression), getFileTypeLanguage(breakpoint), EvaluationMode.EXPRESSION));
        }
        rootNode = new WatchesRootNode(treePanel.getTree(), this, watches.toArray(new XExpression[watches.size()]));
        treePanel.getTree().setRoot(rootNode, false);
        watchPanel.removeAll();
        watchPanel.add(watchLabel, BorderLayout.NORTH);
        treePanel.getTree().getEmptyText().setText("There are no custom watches for this snapshot location.");
        final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(treePanel.getTree()).disableUpDownActions();
        decorator.setToolbarPosition(ActionToolbarPosition.RIGHT);
        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);
        watchPanel.add(decorator.createPanel(), BorderLayout.CENTER);
    }
}
Also used : XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) XBreakpointBase(com.intellij.xdebugger.impl.breakpoints.XBreakpointBase) XDebuggerTreePanel(com.intellij.xdebugger.impl.ui.tree.XDebuggerTreePanel) ArrayList(java.util.ArrayList) XDebuggerEditorsProvider(com.intellij.xdebugger.evaluation.XDebuggerEditorsProvider) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) AnActionButton(com.intellij.ui.AnActionButton) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) WatchesRootNode(com.intellij.xdebugger.impl.ui.tree.nodes.WatchesRootNode) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) XExpression(com.intellij.xdebugger.XExpression) CloudLineBreakpointType(com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType)

Example 10 with AnActionButtonRunnable

use of com.intellij.ui.AnActionButtonRunnable in project azure-tools-for-java by Microsoft.

the class LibrariesConfigurationDialog method createUIComponents.

private void createUIComponents() {
    librariesList = new JBList(currentLibs);
    tempList = new ArrayList(currentLibs);
    librariesPanel = ToolbarDecorator.createDecorator(librariesList).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            addLibrary();
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            removeLibrary();
        }
    }).setEditAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            editLibrary();
        }
    }).disableUpDownActions().createPanel();
}
Also used : AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) AnActionButton(com.intellij.ui.AnActionButton)

Aggregations

AnActionButton (com.intellij.ui.AnActionButton)10 AnActionButtonRunnable (com.intellij.ui.AnActionButtonRunnable)10 ToolbarDecorator (com.intellij.ui.ToolbarDecorator)8 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)3 ArrayList (java.util.ArrayList)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 CustomLineBorder (com.intellij.ui.border.CustomLineBorder)2 Tree (com.intellij.ui.treeStructure.Tree)2 List (java.util.List)2 CloudLineBreakpointType (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType)1 Breakpoint (com.intellij.debugger.ui.breakpoints.Breakpoint)1 JsonBundle (com.intellij.json.JsonBundle)1 FilePathAndPathInPackage (com.intellij.lang.javascript.flex.projectStructure.model.AirPackagingOptions.FilePathAndPathInPackage)1 Disposable (com.intellij.openapi.Disposable)1 CommonShortcuts (com.intellij.openapi.actionSystem.CommonShortcuts)1 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)1 ModalityState (com.intellij.openapi.application.ModalityState)1 DocumentImpl (com.intellij.openapi.editor.impl.DocumentImpl)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 FileChooserDescriptorFactory (com.intellij.openapi.fileChooser.FileChooserDescriptorFactory)1