Search in sources :

Example 11 with ToolbarDecorator

use of com.intellij.ui.ToolbarDecorator 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 ToolbarDecorator

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

the class EditVariableDialog method createVariablesTable.

private JComponent createVariablesTable() {
    final String[] names = { CodeInsightBundle.message("templates.dialog.edit.variables.table.column.name"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.expression"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.default.value"), CodeInsightBundle.message("templates.dialog.edit.variables.table.column.skip.if.defined") };
    // Create a model of the data.
    TableModel dataModel = new VariablesModel(names);
    // Create the table
    myTable = new JBTable(dataModel);
    myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myTable.setPreferredScrollableViewportSize(new Dimension(500, myTable.getRowHeight() * 8));
    myTable.getColumn(names[0]).setPreferredWidth(120);
    myTable.getColumn(names[1]).setPreferredWidth(200);
    myTable.getColumn(names[2]).setPreferredWidth(200);
    myTable.getColumn(names[3]).setPreferredWidth(100);
    if (myVariables.size() > 0) {
        myTable.getSelectionModel().setSelectionInterval(0, 0);
    }
    Predicate<Macro> isAcceptableInContext = macro -> myContextTypes.stream().anyMatch(macro::isAcceptableInContext);
    Stream<String> availableMacroNames = Arrays.stream(MacroFactory.getMacros()).filter(isAcceptableInContext).map(Macro::getPresentableName).sorted();
    Set<String> uniqueNames = availableMacroNames.collect(Collectors.toCollection(LinkedHashSet::new));
    ComboBox comboField = new ComboBox();
    uniqueNames.forEach(comboField::addItem);
    comboField.setEditable(true);
    DefaultCellEditor cellEditor = new DefaultCellEditor(comboField);
    cellEditor.setClickCountToStart(1);
    myTable.getColumn(names[1]).setCellEditor(cellEditor);
    myTable.setRowHeight(comboField.getPreferredSize().height);
    JTextField textField = new JTextField();
    /*textField.addMouseListener(
      new PopupHandler(){
        public void invokePopup(Component comp,int x,int y){
          showCellPopup((JTextField)comp,x,y);
        }
      }
    );*/
    cellEditor = new DefaultCellEditor(textField);
    cellEditor.setClickCountToStart(1);
    myTable.setDefaultEditor(String.class, cellEditor);
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTable).disableAddAction().disableRemoveAction();
    return decorator.createPanel();
}
Also used : java.util(java.util) Document(com.intellij.openapi.editor.Document) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) CodeInsightBundle(com.intellij.codeInsight.CodeInsightBundle) TableCellEditor(javax.swing.table.TableCellEditor) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) CommonBundle(com.intellij.CommonBundle) AbstractTableModel(javax.swing.table.AbstractTableModel) TemplateContextType(com.intellij.codeInsight.template.TemplateContextType) TableModel(javax.swing.table.TableModel) ComboBox(com.intellij.openapi.ui.ComboBox) Predicate(java.util.function.Predicate) Editor(com.intellij.openapi.editor.Editor) Collectors(java.util.stream.Collectors) MacroFactory(com.intellij.codeInsight.template.macro.MacroFactory) java.awt(java.awt) CommandProcessor(com.intellij.openapi.command.CommandProcessor) HelpManager(com.intellij.openapi.help.HelpManager) JBTable(com.intellij.ui.table.JBTable) List(java.util.List) Stream(java.util.stream.Stream) Macro(com.intellij.codeInsight.template.Macro) EditableModel(com.intellij.util.ui.EditableModel) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) Macro(com.intellij.codeInsight.template.Macro) ComboBox(com.intellij.openapi.ui.ComboBox) JBTable(com.intellij.ui.table.JBTable) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 13 with ToolbarDecorator

use of com.intellij.ui.ToolbarDecorator 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 14 with ToolbarDecorator

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

the class SubscriptionsDialog method createUIComponents.

private void createUIComponents() {
    DefaultTableModel model = new SubscriptionTableModel();
    model.addColumn("");
    model.addColumn("Subscription name");
    model.addColumn("Subscription ID");
    table = new JBTable();
    table.setModel(model);
    TableColumn column = table.getColumnModel().getColumn(0);
    column.setMinWidth(23);
    column.setMaxWidth(23);
    table.setRowSelectionAllowed(false);
    table.setCellSelectionEnabled(false);
    AnActionButton refreshAction = new AnActionButton("Refresh", AllIcons.Actions.Refresh) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            AppInsightsClient.createByType(AppInsightsClient.EventType.Subscription, "", "Refresh", null);
            refreshSubscriptions();
        }
    };
    ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(table).disableUpDownActions().addExtraActions(refreshAction);
    panelTable = tableToolbarDecorator.createPanel();
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) TableColumn(javax.swing.table.TableColumn) AnActionButton(com.intellij.ui.AnActionButton)

Example 15 with ToolbarDecorator

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

the class CloudDebugHistoricalSnapshots method configureToolbar.

/**
 * Sets up the the toolbar that appears in the cloud debugger snapshots panel.
 */
private void configureToolbar() {
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table).disableUpDownActions().disableAddAction().setToolbarPosition(ActionToolbarPosition.TOP);
    decorator.setRemoveAction(new RemoveSelectedBreakpointsAction());
    decorator.addExtraAction(new RemoveAllBreakpointsAction());
    decorator.addExtraAction(new ReactivateBreakpointAction());
    this.add(decorator.createPanel());
}
Also used : ToolbarDecorator(com.intellij.ui.ToolbarDecorator)

Aggregations

ToolbarDecorator (com.intellij.ui.ToolbarDecorator)20 AnActionButton (com.intellij.ui.AnActionButton)15 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)9 AnActionButtonRunnable (com.intellij.ui.AnActionButtonRunnable)9 JBTable (com.intellij.ui.table.JBTable)8 DefaultTableModel (javax.swing.table.DefaultTableModel)6 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)3 List (java.util.List)3 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 CustomLineBorder (com.intellij.ui.border.CustomLineBorder)2 Tree (com.intellij.ui.treeStructure.Tree)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 TableColumn (javax.swing.table.TableColumn)2 CloudLineBreakpointType (com.google.cloud.tools.intellij.debugger.CloudLineBreakpointType)1 CommonBundle (com.intellij.CommonBundle)1 CodeInsightBundle (com.intellij.codeInsight.CodeInsightBundle)1 HintManager (com.intellij.codeInsight.hint.HintManager)1