Search in sources :

Example 16 with ToolbarDecorator

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

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

the class AppSettingsTableUtils method createAppSettingPanel.

public static JPanel createAppSettingPanel(AppSettingsTable appSettingsTable) {
    final JPanel result = new JPanel();
    // create the parent panel which contains app settings table and prompt panel
    result.setLayout(new GridLayoutManager(2, 1));
    final JTextPane promptPanel = new JTextPane();
    final GridConstraints paneConstraint = new GridConstraints(1, 0, 1, 1, 0, GridConstraints.FILL_BOTH, 7, 7, null, null, null);
    promptPanel.setFocusable(false);
    result.add(promptPanel, paneConstraint);
    final AnActionButton btnAdd = new AnActionButton(message("common.add"), AllIcons.General.Add) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            final String key = DefaultLoader.getUIHelper().showInputDialog(appSettingsTable, message("function.appSettings.add.key.message"), message("function.appSettings.add.key.title"), null);
            if (StringUtils.isEmpty(key)) {
                return;
            }
            final String value = DefaultLoader.getUIHelper().showInputDialog(appSettingsTable, message("function.appSettings.add.value.message"), message("function.appSettings.add.value.title"), null);
            appSettingsTable.addAppSettings(key, value);
            appSettingsTable.repaint();
        }
    };
    final AnActionButton btnRemove = new AnActionButton(message("common.remove"), AllIcons.General.Remove) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            try {
                appSettingsTable.removeAppSettings(appSettingsTable.getSelectedRow());
                appSettingsTable.repaint();
            } catch (IllegalArgumentException iae) {
                PluginUtil.displayErrorDialog(message("function.appSettings.remove.error.title"), iae.getMessage());
            }
        }
    };
    final AnActionButton importButton = new AnActionButton(message("common.import"), AllIcons.ToolbarDecorator.Import) {

        @Override
        @AzureOperation(name = "function.import_app_settings", type = AzureOperation.Type.TASK)
        public void actionPerformed(AnActionEvent anActionEvent) {
            final ImportAppSettingsDialog importAppSettingsDialog = new ImportAppSettingsDialog(appSettingsTable.getLocalSettingsPath());
            importAppSettingsDialog.addWindowListener(new WindowAdapter() {

                @Override
                public void windowClosed(WindowEvent windowEvent) {
                    super.windowClosed(windowEvent);
                    final Map<String, String> appSettings = importAppSettingsDialog.getAppSettings();
                    if (importAppSettingsDialog.shouldErase()) {
                        appSettingsTable.clear();
                    }
                    if (appSettings != null) {
                        appSettingsTable.addAppSettings(appSettings);
                    }
                }
            });
            importAppSettingsDialog.setLocationRelativeTo(appSettingsTable);
            importAppSettingsDialog.pack();
            importAppSettingsDialog.setVisible(true);
        }
    };
    final AnActionButton exportButton = new AnActionButton(message("function.appSettings.export.title"), AllIcons.ToolbarDecorator.Export) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            try {
                final File file = DefaultLoader.getUIHelper().showFileSaver(message("function.appSettings.export.description"), LOCAL_SETTINGS_JSON);
                if (file != null) {
                    AppSettingsTableUtils.exportLocalSettingsJsonFile(file, appSettingsTable.getAppSettings());
                    PluginUtil.displayInfoDialog(message("function.appSettings.export.succeed.title"), message("function.appSettings.export.succeed.message"));
                }
            } catch (IOException e) {
                final String title = message("function.appSettings.export.error.title");
                final String message = message("function.appSettings.export.error.failedToSave", e.getMessage());
                PluginUtil.displayErrorDialog(title, message);
            }
        }
    };
    appSettingsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            final String prompt = AzureFunctionsConstants.getAppSettingHint(appSettingsTable.getSelectedKey());
            promptPanel.setText(prompt);
        }
    });
    appSettingsTable.addFocusListener(new FocusListener() {

        @Override
        public void focusGained(FocusEvent focusEvent) {
            final String prompt = AzureFunctionsConstants.getAppSettingHint(appSettingsTable.getSelectedKey());
            promptPanel.setText(prompt);
        }

        @Override
        public void focusLost(FocusEvent focusEvent) {
            promptPanel.setText("");
        }
    });
    final ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(appSettingsTable).addExtraActions(btnAdd, btnRemove, importButton, exportButton).setToolbarPosition(ActionToolbarPosition.RIGHT);
    final JPanel tablePanel = tableToolbarDecorator.createPanel();
    final GridConstraints tableConstraint = new GridConstraints(0, 0, 1, 1, 0, GridConstraints.FILL_BOTH, 7, 7, null, null, null);
    result.add(tablePanel, tableConstraint);
    result.setMinimumSize(new Dimension(-1, 100));
    return result;
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) WindowAdapter(java.awt.event.WindowAdapter) IOException(java.io.IOException) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnActionButton(com.intellij.ui.AnActionButton) FocusEvent(java.awt.event.FocusEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) WindowEvent(java.awt.event.WindowEvent) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) FocusListener(java.awt.event.FocusListener)

Example 18 with ToolbarDecorator

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

the class SubscriptionsDialog method createUIComponents.

private void createUIComponents() {
    contentPane = new JPanel();
    contentPane.setPreferredSize(new Dimension(350, 200));
    DefaultTableModel model = new SubscriptionTableModel();
    // Set the text read by JAWS
    model.addColumn("Selected");
    model.addColumn("Subscription name");
    model.addColumn("Subscription ID");
    table = new JBTable();
    table.setModel(model);
    TableColumn column = table.getColumnModel().getColumn(CHECKBOX_COLUMN);
    // Don't show title text
    column.setHeaderValue("");
    column.setMinWidth(23);
    column.setMaxWidth(23);
    JTableUtils.enableBatchSelection(table, CHECKBOX_COLUMN);
    table.getTableHeader().setReorderingAllowed(false);
    new TableSpeedSearch(table);
    AnActionButton refreshAction = new AnActionButton("Refresh", AllIcons.Actions.Refresh) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            this.setEnabled(false);
            model.setRowCount(0);
            model.fireTableDataChanged();
            table.getEmptyText().setText("Refreshing");
            AppInsightsClient.createByType(AppInsightsClient.EventType.Subscription, "", "Refresh", null);
            final AzureString title = AzureOperationBundle.title("account|subscription.refresh");
            final AzureTask task = new AzureTask(project, title, true, () -> {
                try {
                    SubscriptionsDialog.this.refreshSubscriptions();
                } finally {
                    this.setEnabled(true);
                }
            }, AzureTask.Modality.ANY);
            AzureTaskManager.getInstance().runInBackground(task);
        }
    };
    refreshAction.registerCustomShortcutSet(KeyEvent.VK_R, InputEvent.ALT_DOWN_MASK, contentPane);
    ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(table).disableUpDownActions().addExtraActions(refreshAction);
    panelTable = tableToolbarDecorator.createPanel();
}
Also used : TableSpeedSearch(com.intellij.ui.TableSpeedSearch) DefaultTableModel(javax.swing.table.DefaultTableModel) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AzureTask(com.microsoft.azure.toolkit.lib.common.task.AzureTask) TableColumn(javax.swing.table.TableColumn) AnActionButton(com.intellij.ui.AnActionButton) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString)

Example 19 with ToolbarDecorator

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

the class WebAppBasePropertyView method createUIComponents.

private void createUIComponents() {
    tableModel = new DefaultTableModel();
    tableModel.addColumn(TABLE_HEADER_KEY);
    tableModel.addColumn(TABLE_HEADER_VALUE);
    tblAppSetting = new JBTable(tableModel);
    tblAppSetting.setRowSelectionAllowed(true);
    tblAppSetting.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tblAppSetting.getEmptyText().setText(TABLE_LOADING_MESSAGE);
    tblAppSetting.addPropertyChangeListener(evt -> {
        if ("tableCellEditor".equals(evt.getPropertyName())) {
            if (!tblAppSetting.isEditing()) {
                editedAppSettings.clear();
                int row = 0;
                while (row < tableModel.getRowCount()) {
                    Object keyObj = tableModel.getValueAt(row, 0);
                    String key = "";
                    String value = "";
                    if (keyObj != null) {
                        key = (String) keyObj;
                    }
                    if (key.isEmpty() || editedAppSettings.containsKey(key)) {
                        tableModel.removeRow(row);
                        continue;
                    }
                    Object valueObj = tableModel.getValueAt(row, 1);
                    if (valueObj != null) {
                        value = (String) valueObj;
                    }
                    editedAppSettings.put(key, value);
                    ++row;
                }
                updateSaveAndDiscardBtnStatus();
                updateTableActionBtnStatus(false);
            } else {
                updateTableActionBtnStatus(true);
            }
        }
    });
    btnAdd = new AnActionButton(BUTTON_ADD, AllIcons.General.Add) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            if (tblAppSetting.isEditing()) {
                tblAppSetting.getCellEditor().stopCellEditing();
            }
            tableModel.addRow(new String[] { "", "" });
            tblAppSetting.editCellAt(tblAppSetting.getRowCount() - 1, 0);
        }
    };
    btnRemove = new AnActionButton(BUTTON_REMOVE, AllIcons.General.Remove) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            int selectedRow = tblAppSetting.getSelectedRow();
            if (selectedRow == -1) {
                return;
            }
            editedAppSettings.remove(tableModel.getValueAt(selectedRow, 0));
            tableModel.removeRow(selectedRow);
            updateSaveAndDiscardBtnStatus();
        }
    };
    btnEdit = new AnActionButton(BUTTON_EDIT, AllIcons.Actions.Edit) {

        @Override
        public void actionPerformed(AnActionEvent anActionEvent) {
            int selectedRow = tblAppSetting.getSelectedRow();
            int selectedCol = tblAppSetting.getSelectedColumn();
            if (selectedRow == -1 || selectedCol == -1) {
                return;
            }
            tblAppSetting.editCellAt(selectedRow, selectedCol);
        }
    };
    ToolbarDecorator tableToolbarDecorator = ToolbarDecorator.createDecorator(tblAppSetting).addExtraActions(btnAdd, btnRemove, btnEdit).setToolbarPosition(ActionToolbarPosition.RIGHT);
    pnlAppSettings = tableToolbarDecorator.createPanel();
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) AzureString(com.microsoft.azure.toolkit.lib.common.bundle.AzureString) JBTable(com.intellij.ui.table.JBTable) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnActionButton(com.intellij.ui.AnActionButton)

Example 20 with ToolbarDecorator

use of com.intellij.ui.ToolbarDecorator in project sonarlint-intellij by SonarSource.

the class SonarQubeServerMgmtPanel method create.

private void create() {
    Application app = ApplicationManager.getApplication();
    serverManager = app.getComponent(SonarLintEngineManager.class);
    serverChangeListener = app.getMessageBus().syncPublisher(GlobalConfigurationListener.TOPIC);
    serverList = new JBList();
    serverList.getEmptyText().setText(LABEL_NO_SERVERS);
    serverList.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                editServer();
            }
        }
    });
    serverList.addListSelectionListener(e -> {
        if (!e.getValueIsAdjusting()) {
            onServerSelect();
        }
    });
    serversPanel = new JPanel(new BorderLayout());
    ToolbarDecorator toolbarDecorator = ToolbarDecorator.createDecorator(serverList).setEditActionName("Edit").setEditAction(e -> editServer()).disableUpDownActions();
    toolbarDecorator.setAddAction(new AddServerAction());
    toolbarDecorator.setRemoveAction(new RemoveServerAction());
    serversPanel.add(toolbarDecorator.createPanel(), BorderLayout.CENTER);
    splitter = new Splitter(true);
    splitter.setFirstComponent(serversPanel);
    splitter.setSecondComponent(createServerStatus());
    JBLabel emptyLabel = new JBLabel("No server selected", SwingConstants.CENTER);
    emptyPanel = new JPanel(new BorderLayout());
    emptyPanel.add(emptyLabel, BorderLayout.CENTER);
    Border b = IdeBorderFactory.createTitledBorder("SonarQube servers");
    panel = new JPanel(new BorderLayout());
    panel.setBorder(b);
    panel.add(splitter);
    serverList.setCellRenderer(new ColoredListCellRenderer() {

        @Override
        protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            SonarQubeServer server = (SonarQubeServer) value;
            if (server.isSonarCloud()) {
                setIcon(SonarLintIcons.ICON_SONARCLOUD_16);
            } else {
                setIcon(SonarLintIcons.ICON_SONARQUBE_16);
            }
            append(server.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
            if (!server.isSonarCloud()) {
                append("    (" + server.getHostUrl() + ")", SimpleTextAttributes.GRAYED_ATTRIBUTES, false);
            }
        }
    });
}
Also used : AllIcons(com.intellij.icons.AllIcons) Application(com.intellij.openapi.application.Application) HyperlinkEvent(javax.swing.event.HyperlinkEvent) SonarLintEngineManager(org.sonarlint.intellij.core.SonarLintEngineManager) JBLabel(com.intellij.ui.components.JBLabel) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) GlobalConfigurationListener(org.sonarlint.intellij.messages.GlobalConfigurationListener) Border(javax.swing.border.Border) ProjectManager(com.intellij.openapi.project.ProjectManager) JBUI(com.intellij.util.ui.JBUI) Map(java.util.Map) AnActionButtonRunnable(com.intellij.ui.AnActionButtonRunnable) MouseAdapter(java.awt.event.MouseAdapter) Messages(com.intellij.openapi.ui.Messages) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) BorderLayout(java.awt.BorderLayout) AnActionButton(com.intellij.ui.AnActionButton) ConnectedSonarLintEngine(org.sonarsource.sonarlint.core.client.api.connected.ConnectedSonarLintEngine) ProgressManager(com.intellij.openapi.progress.ProgressManager) HintUtil(com.intellij.codeInsight.hint.HintUtil) Set(java.util.Set) SQServerWizard(org.sonarlint.intellij.config.global.wizard.SQServerWizard) GridBagConstraints(java.awt.GridBagConstraints) Collectors(java.util.stream.Collectors) List(java.util.List) ConfigurationPanel(org.sonarlint.intellij.config.ConfigurationPanel) AbstractAction(javax.swing.AbstractAction) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) ApplicationManager(com.intellij.openapi.application.ApplicationManager) GridBagLayout(java.awt.GridBagLayout) RelativePoint(com.intellij.ui.awt.RelativePoint) JPanel(javax.swing.JPanel) DateUtils(org.sonarsource.sonarlint.core.client.api.util.DateUtils) HashMap(java.util.HashMap) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SonarLintIcons(icons.SonarLintIcons) Project(com.intellij.openapi.project.Project) LinkedList(java.util.LinkedList) Nullable(javax.annotation.Nullable) Splitter(com.intellij.openapi.ui.Splitter) JComponent(javax.swing.JComponent) SonarLintUtils(org.sonarlint.intellij.util.SonarLintUtils) JBList(com.intellij.ui.components.JBList) FlowLayout(java.awt.FlowLayout) SonarLintProjectSettings(org.sonarlint.intellij.config.project.SonarLintProjectSettings) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter) JButton(javax.swing.JButton) JList(javax.swing.JList) CollectionListModel(com.intellij.ui.CollectionListModel) ActionEvent(java.awt.event.ActionEvent) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) StateListener(org.sonarsource.sonarlint.core.client.api.connected.StateListener) ServerUpdateTask(org.sonarlint.intellij.tasks.ServerUpdateTask) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) JLabel(javax.swing.JLabel) GlobalStorageStatus(org.sonarsource.sonarlint.core.client.api.connected.GlobalStorageStatus) HintManager(com.intellij.codeInsight.hint.HintManager) Collections(java.util.Collections) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) Splitter(com.intellij.openapi.ui.Splitter) MouseAdapter(java.awt.event.MouseAdapter) SonarLintEngineManager(org.sonarlint.intellij.core.SonarLintEngineManager) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) RelativePoint(com.intellij.ui.awt.RelativePoint) BorderLayout(java.awt.BorderLayout) JBLabel(com.intellij.ui.components.JBLabel) ToolbarDecorator(com.intellij.ui.ToolbarDecorator) JBList(com.intellij.ui.components.JBList) Application(com.intellij.openapi.application.Application) Border(javax.swing.border.Border) JList(javax.swing.JList)

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