Java Examples for com.intellij.ui.ComboboxWithBrowseButton

The following java examples will help you to understand the usage of com.intellij.ui.ComboboxWithBrowseButton. These source code samples are taken from different open source projects.

Example 1
Project: MetricsReloaded-master  File: ProfileSelectionPanel.java View source code
private static ComboboxWithBrowseButton buildComboBoxWithBrowseButton(final Project project, final MetricsProfileRepository repository) {
    final String[] profiles = repository.getProfileNames();
    final JComboBox comboBox = new JComboBox(new DefaultComboBoxModel(profiles));
    final ComboboxWithBrowseButton comboboxWithBrowseButton = new ComboboxWithBrowseButton(comboBox);
    final MetricsProfile currentProfile = repository.getCurrentProfile();
    final String currentProfileName = currentProfile.getName();
    comboBox.setSelectedItem(currentProfileName);
    comboBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.DESELECTED) {
                return;
            }
            final String selectedProfile = (String) comboBox.getSelectedItem();
            repository.setSelectedProfile(selectedProfile);
        }
    });
    comboboxWithBrowseButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final MetricsConfigurationDialog configurationDialog = new MetricsConfigurationDialog(project, repository);
            configurationDialog.show();
            final String[] profiles = repository.getProfileNames();
            comboBox.setModel(new DefaultComboBoxModel(profiles));
            final MetricsProfile currentProfile = repository.getCurrentProfile();
            final String currentProfileName = currentProfile.getName();
            comboBox.setSelectedItem(currentProfileName);
        }
    });
    return comboboxWithBrowseButton;
}
Example 2
Project: intellij-community-master  File: CodeInspectionAction.java View source code
private void createUIComponents() {
    myBrowseProfilesCombo = new ComboboxWithBrowseButton(new SchemesCombo<InspectionProfileImpl>() {

        @Override
        protected boolean supportsProjectSchemes() {
            return true;
        }

        @Override
        protected boolean isProjectScheme(@NotNull InspectionProfileImpl profile) {
            return profile.isProjectLevel();
        }

        @NotNull
        @Override
        protected SimpleTextAttributes getSchemeAttributes(InspectionProfileImpl profile) {
            return SimpleTextAttributes.REGULAR_ATTRIBUTES;
        }
    });
}
Example 3
Project: intellij-plugins-master  File: DartSdkUtil.java View source code
public static void initDartSdkAndDartiumControls(@Nullable final Project project, @NotNull final ComboboxWithBrowseButton dartSdkPathComponent, @NotNull final JBLabel versionLabel, @NotNull final ComboboxWithBrowseButton dartiumPathComponent, @NotNull final Computable<ChromeSettings> currentDartiumSettingsRetriever, @NotNull final JButton dartiumSettingsButton, @NotNull final Computable<Boolean> isResettingControlsComputable) {
    dartSdkPathComponent.getComboBox().setEditable(true);
    addKnownPathsToCombo(dartSdkPathComponent.getComboBox(), DART_SDK_KNOWN_PATHS, DartSdkUtil::isDartSdkHome);
    dartiumPathComponent.getComboBox().setEditable(true);
    addKnownPathsToCombo(dartiumPathComponent.getComboBox(), DARTIUM_KNOWN_PATHS,  path -> !path.isEmpty() && new File(path).exists());
    final String sdkHomePath = dartSdkPathComponent.getComboBox().getEditor().getItem().toString().trim();
    versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath));
    final TextComponentAccessor<JComboBox> textComponentAccessor = new TextComponentAccessor<JComboBox>() {

        @Override
        public String getText(final JComboBox component) {
            return component.getEditor().getItem().toString();
        }

        @Override
        public void setText(@NotNull final JComboBox component, @NotNull final String text) {
            if (!text.isEmpty() && !isDartSdkHome(text)) {
                final String probablySdkPath = text + "/dart-sdk";
                if (isDartSdkHome(probablySdkPath)) {
                    component.getEditor().setItem(FileUtilRt.toSystemDependentName(probablySdkPath));
                    return;
                }
            }
            component.getEditor().setItem(FileUtilRt.toSystemDependentName(text));
        }
    };
    final ComponentWithBrowseButton.BrowseFolderActionListener<JComboBox> browseFolderListener = new ComponentWithBrowseButton.BrowseFolderActionListener<>("Select Dart SDK path", null, dartSdkPathComponent, project, FileChooserDescriptorFactory.createSingleFolderDescriptor(), textComponentAccessor);
    dartSdkPathComponent.addActionListener(browseFolderListener);
    dartiumPathComponent.addBrowseFolderListener("Select Dartium browser path", null, project, FileChooserDescriptorFactory.createSingleFileOrExecutableAppDescriptor(), TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT);
    final JTextComponent editorComponent = (JTextComponent) dartSdkPathComponent.getComboBox().getEditor().getEditorComponent();
    editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(final DocumentEvent e) {
            final String sdkHomePath = dartSdkPathComponent.getComboBox().getEditor().getItem().toString().trim();
            versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath));
            if (!isResettingControlsComputable.compute() && isDartSdkHome(sdkHomePath)) {
                final String dartiumPath = DartiumUtil.getDartiumPathForSdk(sdkHomePath);
                if (dartiumPath != null) {
                    dartiumPathComponent.getComboBox().getEditor().setItem(FileUtilRt.toSystemDependentName(dartiumPath));
                }
            }
        }
    });
    dartiumSettingsButton.addActionListener( e -> ShowSettingsUtil.getInstance().editConfigurable(dartiumSettingsButton, currentDartiumSettingsRetriever.compute().createConfigurable()));
// we decided to save one line in settings and always use Dartium in checked mode
//checkedModeCheckBox.addActionListener(new ActionListener() {
//  public void actionPerformed(final ActionEvent e) {
//    DartiumUtil.setCheckedMode(currentDartiumSettingsRetriever.compute().getEnvironmentVariables(), checkedModeCheckBox.isSelected());
//  }
//});
}
Example 4
Project: consulo-master  File: ExternalToolsCheckinHandlerFactory.java View source code
@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());
            dialog.show();
            if (!dialog.isOK()) {
                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();
        }
    };
}