Search in sources :

Example 11 with AnActionButton

use of com.intellij.ui.AnActionButton 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 12 with AnActionButton

use of com.intellij.ui.AnActionButton in project android by JetBrains.

the class CreateXmlResourceSubdirPanel method setupDirectoriesPanel.

protected void setupDirectoriesPanel() {
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myDirectoriesList);
    decorator.setEditAction(null);
    decorator.disableUpDownActions();
    decorator.setAddAction(button -> doAddNewDirectory());
    decorator.setRemoveAction(button -> doDeleteDirectory());
    final AnActionButton selectAll = new AnActionButton("Select All", null, PlatformIcons.SELECT_ALL_ICON) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            doSelectAllDirs();
        }
    };
    decorator.addExtraAction(selectAll);
    final AnActionButton unselectAll = new AnActionButton("Unselect All", null, PlatformIcons.UNSELECT_ALL_ICON) {

        @Override
        public void actionPerformed(AnActionEvent e) {
            doUnselectAllDirs();
        }
    };
    decorator.addExtraAction(unselectAll);
    myDirectoriesPanel.add(decorator.createPanel());
    updateDirectories(true, myParent.getResourceDirectory());
}
Also used : ToolbarDecorator(com.intellij.ui.ToolbarDecorator) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnActionButton(com.intellij.ui.AnActionButton)

Example 13 with AnActionButton

use of com.intellij.ui.AnActionButton in project intellij-plugins by JetBrains.

the class FilesToPackageForm method initTableButtons.

private void initTableButtons() {
    ToolbarDecorator d = ToolbarDecorator.createDecorator(myFilesToPackageTable);
    d.setAddAction(new AnActionButtonRunnable() {

        public void run(AnActionButton button) {
            final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, true, false, true);
            final VirtualFile[] files = FileChooser.chooseFiles(descriptor, myProject, null);
            final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
            for (final VirtualFile file : files) {
                final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(file);
                String relativePath = sourceRoot == null ? null : sourceRoot.equals(file) ? "." : VfsUtilCore.getRelativePath(file, sourceRoot, '/');
                myFilesToPackage.add(new FilePathAndPathInPackage(file.getPath(), StringUtil.notNullize(relativePath, file.getName())));
            }
            if (files.length > 0) {
                fireDataChanged();
                IdeFocusManager.getInstance(myProject).requestFocus(myFilesToPackageTable, true);
                final int rowCount = myFilesToPackageTable.getRowCount();
                myFilesToPackageTable.setRowSelectionInterval(rowCount - files.length, rowCount - 1);
            }
        }
    });
    d.setRemoveAction(new AnActionButtonRunnable() {

        public void run(AnActionButton anActionButton) {
            TableUtil.stopEditing(myFilesToPackageTable);
            final int[] selectedRows = myFilesToPackageTable.getSelectedRows();
            Arrays.sort(selectedRows);
            for (int i = selectedRows.length - 1; i >= 0; i--) {
                myFilesToPackage.remove(selectedRows[i]);
            }
            fireDataChanged();
        }
    });
    myMainPanel.add(d.createPanel(), BorderLayout.CENTER);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FilePathAndPathInPackage(com.intellij.lang.javascript.flex.projectStructure.model.AirPackagingOptions.FilePathAndPathInPackage) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) AnActionButton(com.intellij.ui.AnActionButton)

Aggregations

AnActionButton (com.intellij.ui.AnActionButton)13 AnActionButtonRunnable (com.intellij.ui.AnActionButtonRunnable)9 ToolbarDecorator (com.intellij.ui.ToolbarDecorator)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)7 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 JBTable (com.intellij.ui.table.JBTable)2 Tree (com.intellij.ui.treeStructure.Tree)2 List (java.util.List)2 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 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 FileChooserDescriptorFactory (com.intellij.openapi.fileChooser.FileChooserDescriptorFactory)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1