Search in sources :

Example 6 with ComboboxWithBrowseButton

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

the class EmulatorTargetConfigurable method createUIComponents.

private void createUIComponents() {
    myAvdCombo = new AvdComboBox(myProject, true, false) {

        @Override
        public Module getModule() {
            return myContext.getModule();
        }
    };
    myAvdCombo.startUpdatingAvds(ModalityState.current());
    JComboBox avdComboBox = myAvdCombo.getComboBox();
    avdComboBox.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof IdDisplay) {
                setText(((IdDisplay) value).getDisplay());
            } else {
                setText(String.format("<html><font color='red'>Unknown AVD %1$s</font></html>", value == null ? "" : value.toString()));
            }
        }
    });
    avdComboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            resetAvdCompatibilityWarningLabel();
        }
    });
    myAvdComboWithButton = new ComboboxWithBrowseButton(avdComboBox);
    Disposer.register(myParentDisposable, myAvdCombo);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) AvdComboBox(com.android.tools.idea.run.AvdComboBox) IdDisplay(com.android.sdklib.repository.IdDisplay) ActionListener(java.awt.event.ActionListener) ComboboxWithBrowseButton(com.intellij.ui.ComboboxWithBrowseButton) Module(com.intellij.openapi.module.Module)

Example 7 with ComboboxWithBrowseButton

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

the class ExternalToolsCheckinHandlerFactory method createHandler.

@NotNull
@Override
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
    final ToolsProjectConfig config = ToolsProjectConfig.getInstance(panel.getProject());
    return new CheckinHandler() {

        @Override
        public RefreshableOnComponent getAfterCheckinConfigurationPanel(Disposable parentDisposable) {
            final JLabel label = new JLabel(ToolsBundle.message("tools.after.commit.description"));
            ComboboxWithBrowseButton listComponent = new ComboboxWithBrowseButton();
            final JComboBox comboBox = listComponent.getComboBox();
            comboBox.setModel(new CollectionComboBoxModel(getComboBoxElements(), null));
            comboBox.setRenderer(new ListCellRendererWrapper<Object>() {

                @Override
                public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
                    if (value instanceof ToolsGroup) {
                        setText(StringUtil.notNullize(((ToolsGroup) value).getName(), ToolsBundle.message("tools.unnamed.group")));
                    } else if (value instanceof Tool) {
                        setText("  " + StringUtil.notNullize(((Tool) value).getName()));
                    } else {
                        setText(ToolsBundle.message("tools.list.item.none"));
                    }
                }
            });
            listComponent.getButton().addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    final Object item = comboBox.getSelectedItem();
                    String id = null;
                    if (item instanceof Tool) {
                        id = ((Tool) item).getActionId();
                    }
                    final ToolSelectDialog dialog = new ToolSelectDialog(panel.getProject(), id, new ToolsPanel());
                    if (!dialog.showAndGet()) {
                        return;
                    }
                    comboBox.setModel(new CollectionComboBoxModel(getComboBoxElements(), dialog.getSelectedTool()));
                }
            });
            BorderLayout layout = new BorderLayout();
            layout.setVgap(3);
            final JPanel panel = new JPanel(layout);
            panel.add(label, BorderLayout.NORTH);
            panel.add(listComponent, BorderLayout.CENTER);
            listComponent.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 0));
            if (comboBox.getItemCount() == 0 || (comboBox.getItemCount() == 1 && comboBox.getItemAt(0) == NONE_TOOL)) {
                return null;
            }
            return new RefreshableOnComponent() {

                @Override
                public JComponent getComponent() {
                    return panel;
                }

                @Override
                public void refresh() {
                    String id = config.getAfterCommitToolsId();
                    if (id == null) {
                        comboBox.setSelectedIndex(-1);
                    } else {
                        for (int i = 0; i < comboBox.getItemCount(); i++) {
                            final Object itemAt = comboBox.getItemAt(i);
                            if (itemAt instanceof Tool && id.equals(((Tool) itemAt).getActionId())) {
                                comboBox.setSelectedIndex(i);
                                return;
                            }
                        }
                    }
                }

                @Override
                public void saveState() {
                    Object item = comboBox.getSelectedItem();
                    config.setAfterCommitToolId(item instanceof Tool ? ((Tool) item).getActionId() : null);
                }

                @Override
                public void restoreState() {
                    refresh();
                }
            };
        }

        @Override
        public void checkinSuccessful() {
            final String id = config.getAfterCommitToolsId();
            if (id == null) {
                return;
            }
            DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {

                @Override
                public void consume(final DataContext context) {
                    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

                        @Override
                        public void run() {
                            ToolAction.runTool(id, context);
                        }
                    });
                }
            });
        }
    };
}
Also used : ActionEvent(java.awt.event.ActionEvent) DataContext(com.intellij.openapi.actionSystem.DataContext) CollectionComboBoxModel(com.intellij.ui.CollectionComboBoxModel) Disposable(com.intellij.openapi.Disposable) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) ActionListener(java.awt.event.ActionListener) ComboboxWithBrowseButton(com.intellij.ui.ComboboxWithBrowseButton) RefreshableOnComponent(com.intellij.openapi.vcs.ui.RefreshableOnComponent) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ComboboxWithBrowseButton

use of com.intellij.ui.ComboboxWithBrowseButton in project intellij by bazelbuild.

the class BlazeCreateResourceFileDialog method setupUi.

/**
 * Initially generated by IntelliJ from a .form file.
 */
private void setupUi() {
    myPanel = new JPanel();
    myPanel.setLayout(new GridLayoutManager(7, 3, new Insets(0, 0, 0, 0), -1, -1));
    myPanel.setPreferredSize(new Dimension(800, 400));
    myFileNameLabel = new JLabel();
    myFileNameLabel.setText("File name:");
    myFileNameLabel.setDisplayedMnemonic('F');
    myFileNameLabel.setDisplayedMnemonicIndex(0);
    myPanel.add(myFileNameLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myFileNameField = new JTextField();
    myPanel.add(myFileNameField, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
    myResTypeLabel = new JLabel();
    myResTypeLabel.setText("Resource type:");
    myResTypeLabel.setDisplayedMnemonic('R');
    myResTypeLabel.setDisplayedMnemonicIndex(0);
    myPanel.add(myResTypeLabel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myUpDownHint = new JLabel();
    myUpDownHint.setToolTipText("Pressing Up or Down arrows while in editor changes the kind");
    myPanel.add(myUpDownHint, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myResourceTypeCombo = new TemplateKindCombo();
    myPanel.add(myResourceTypeCombo, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myDeviceConfiguratorWrapper = new JPanel();
    myDeviceConfiguratorWrapper.setLayout(new BorderLayout(0, 0));
    myPanel.add(myDeviceConfiguratorWrapper, new GridConstraints(5, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
    myErrorLabel = new JBLabel();
    myPanel.add(myErrorLabel, new GridConstraints(6, 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    final JBLabel jBLabel1 = new JBLabel();
    jBLabel1.setText("Sub-directory:");
    jBLabel1.setDisplayedMnemonic('Y');
    jBLabel1.setDisplayedMnemonicIndex(12);
    myPanel.add(jBLabel1, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myDirectoryNameTextField = new JTextField();
    myDirectoryNameTextField.setEditable(true);
    myDirectoryNameTextField.setEnabled(true);
    myPanel.add(myDirectoryNameTextField, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
    myRootElementLabel = new JBLabel();
    myRootElementLabel.setText("Root element:");
    myRootElementLabel.setDisplayedMnemonic('E');
    myRootElementLabel.setDisplayedMnemonicIndex(5);
    myPanel.add(myRootElementLabel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myRootElementFieldWrapper = new JPanel();
    myRootElementFieldWrapper.setLayout(new BorderLayout(0, 0));
    myPanel.add(myRootElementFieldWrapper, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myResDirLabel = new JBLabel();
    myResDirLabel.setText("Base directory:");
    myResDirLabel.setDisplayedMnemonic('B');
    myResDirLabel.setDisplayedMnemonicIndex(0);
    myPanel.add(myResDirLabel, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myResDirCombo = new ComboboxWithBrowseButton();
    myPanel.add(myResDirCombo, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
    myFileNameLabel.setLabelFor(myFileNameField);
    jBLabel1.setLabelFor(myDirectoryNameTextField);
}
Also used : JPanel(javax.swing.JPanel) Insets(java.awt.Insets) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) BorderLayout(java.awt.BorderLayout) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) JBLabel(com.intellij.ui.components.JBLabel) ComboboxWithBrowseButton(com.intellij.ui.ComboboxWithBrowseButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) TemplateKindCombo(com.intellij.ide.actions.TemplateKindCombo)

Aggregations

ComboboxWithBrowseButton (com.intellij.ui.ComboboxWithBrowseButton)8 JBLabel (com.intellij.ui.components.JBLabel)3 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)3 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)3 BorderLayout (java.awt.BorderLayout)3 Dimension (java.awt.Dimension)3 Insets (java.awt.Insets)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JPanel (javax.swing.JPanel)3 JTextField (javax.swing.JTextField)3 ComboBox (com.intellij.openapi.ui.ComboBox)2 JComboBox (javax.swing.JComboBox)2 JLabel (javax.swing.JLabel)2 IdDisplay (com.android.sdklib.repository.IdDisplay)1 AvdComboBox (com.android.tools.idea.run.AvdComboBox)1 TemplateKindCombo (com.intellij.ide.actions.TemplateKindCombo)1 Disposable (com.intellij.openapi.Disposable)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Module (com.intellij.openapi.module.Module)1