Search in sources :

Example 6 with AnActionButton

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

Example 7 with AnActionButton

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

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

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

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

the class EnvVariablesTable method createExtraActions.

@NotNull
@Override
protected AnActionButton[] createExtraActions() {
    AnActionButton copyButton = new AnActionButton(ActionsBundle.message("action.EditorCopy.text"), AllIcons.Actions.Copy) {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            stopEditing();
            StringBuilder sb = new StringBuilder();
            List<EnvironmentVariable> variables = getSelection();
            for (EnvironmentVariable environmentVariable : variables) {
                if (environmentVariable.getIsPredefined() || isEmpty(environmentVariable))
                    continue;
                if (sb.length() > 0)
                    sb.append('\n');
                sb.append(StringUtil.escapeChar(environmentVariable.getName(), '=')).append('=').append(StringUtil.escapeChar(environmentVariable.getValue(), '='));
            }
            CopyPasteManager.getInstance().setContents(new StringSelection(sb.toString()));
        }

        @Override
        public boolean isEnabled() {
            return super.isEnabled() && !getSelection().isEmpty();
        }
    };
    AnActionButton pasteButton = new AnActionButton(ActionsBundle.message("action.EditorPaste.text"), AllIcons.Actions.Menu_paste) {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            removeSelected();
            stopEditing();
            String content = CopyPasteManager.getInstance().getContents(DataFlavor.stringFlavor);
            if (content == null || !content.contains("="))
                return;
            List<EnvironmentVariable> parsed = new ArrayList<>();
            List<String> lines = StringUtil.split(content, "\n");
            for (String line : lines) {
                int pos = line.indexOf('=');
                if (pos == -1)
                    continue;
                while (pos > 0 && line.charAt(pos - 1) == '\\') {
                    pos = line.indexOf('=', pos + 1);
                }
                line = line.replaceAll("[\\\\]{1}", "\\\\\\\\");
                parsed.add(new EnvironmentVariable(StringUtil.unescapeStringCharacters(line.substring(0, pos)), StringUtil.unescapeStringCharacters(line.substring(pos + 1)), false));
            }
            List<EnvironmentVariable> variables = new ArrayList<>(getEnvironmentVariables());
            variables.addAll(parsed);
            setValues(variables);
        }
    };
    return new AnActionButton[] { copyButton, pasteButton };
}
Also used : ArrayList(java.util.ArrayList) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnActionButton(com.intellij.ui.AnActionButton) NotNull(org.jetbrains.annotations.NotNull) StringSelection(java.awt.datatransfer.StringSelection) NotNull(org.jetbrains.annotations.NotNull)

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