Search in sources :

Example 21 with ComboBox

use of com.intellij.openapi.ui.ComboBox in project android by JetBrains.

the class AndroidLogcatView method createSearchComponent.

@NotNull
public final JPanel createSearchComponent() {
    final JPanel panel = new JPanel();
    final ComboBox editFiltersCombo = new ComboBox();
    myFilterComboBoxModel = new DefaultComboBoxModel();
    myFilterComboBoxModel.addElement(myNoFilter);
    myFilterComboBoxModel.addElement(EDIT_FILTER_CONFIGURATION);
    updateDefaultFilters(null);
    updateUserFilters();
    String selectName = AndroidLogcatPreferences.getInstance(myProject).TOOL_WINDOW_CONFIGURED_FILTER;
    if (StringUtil.isEmpty(selectName)) {
        selectName = myDeviceContext != null ? SELECTED_APP_FILTER : NO_FILTERS;
    }
    selectFilterByName(selectName);
    editFiltersCombo.setModel(myFilterComboBoxModel);
    applySelectedFilter();
    // note: the listener is added after the initial call to populate the combo
    // boxes in the above call to updateConfiguredFilters
    editFiltersCombo.addItemListener(new ItemListener() {

        @Nullable
        private AndroidLogcatFilter myLastSelected;

        @Override
        public void itemStateChanged(ItemEvent e) {
            Object item = e.getItem();
            if (e.getStateChange() == ItemEvent.DESELECTED) {
                if (item instanceof AndroidLogcatFilter) {
                    myLastSelected = (AndroidLogcatFilter) item;
                }
            } else if (e.getStateChange() == ItemEvent.SELECTED) {
                if (item instanceof AndroidLogcatFilter) {
                    applySelectedFilter();
                } else {
                    assert EDIT_FILTER_CONFIGURATION.equals(item);
                    final EditLogFilterDialog dialog = new EditLogFilterDialog(AndroidLogcatView.this, myLastSelected == null ? null : myLastSelected.getName());
                    dialog.setTitle(AndroidBundle.message("android.logcat.new.filter.dialog.title"));
                    if (dialog.showAndGet()) {
                        final PersistentAndroidLogFilters.FilterData filterData = dialog.getActiveFilter();
                        updateUserFilters();
                        if (filterData != null) {
                            selectFilterByName(filterData.getName());
                        }
                    } else {
                        editFiltersCombo.setSelectedItem(myLastSelected);
                    }
                }
            }
        }
    });
    editFiltersCombo.setRenderer(new ColoredListCellRenderer<Object>() {

        @Override
        protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof AndroidLogcatFilter) {
                setBorder(null);
                append(((AndroidLogcatFilter) value).getName());
            } else {
                setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
                append(value.toString());
            }
        }
    });
    panel.add(editFiltersCombo);
    final JPanel searchComponent = new JPanel();
    searchComponent.setLayout(new BoxLayout(searchComponent, X_AXIS));
    searchComponent.add(myLogConsole.getSearchComponent());
    searchComponent.add(panel);
    return searchComponent;
}
Also used : ItemEvent(java.awt.event.ItemEvent) ComboBox(com.intellij.openapi.ui.ComboBox) ItemListener(java.awt.event.ItemListener) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with ComboBox

use of com.intellij.openapi.ui.ComboBox in project android by JetBrains.

the class KeyValuePane method createComboBox.

private ComboBox createComboBox(boolean editable) {
    ComboBox comboBox = new ComboBox();
    comboBox.addItemListener(this);
    comboBox.setEditor(new FixedComboBoxEditor());
    comboBox.setEditable(true);
    // Default is only 20 chars
    comboBox.setMinLength(60);
    JBTextField editorComponent = (JBTextField) comboBox.getEditor().getEditorComponent();
    editorComponent.setEditable(editable);
    editorComponent.getDocument().addDocumentListener(this);
    return comboBox;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) JBTextField(com.intellij.ui.components.JBTextField) FixedComboBoxEditor(com.intellij.openapi.ui.FixedComboBoxEditor)

Example 23 with ComboBox

use of com.intellij.openapi.ui.ComboBox in project android by JetBrains.

the class KeyValuePane method updateCurrentObjectFromUi.

/**
   * Reads the state of the UI form objects and writes them into the currently selected object in the list, setting the dirty bit as
   * appropriate.
   */
private void updateCurrentObjectFromUi() {
    if (myIsUpdating || myCurrentBuildFileObject == null) {
        return;
    }
    for (Map.Entry<BuildFileKey, JComponent> entry : myProperties.entrySet()) {
        BuildFileKey key = entry.getKey();
        JComponent component = entry.getValue();
        Object currentValue = myCurrentBuildFileObject.get(key);
        Object newValue;
        BuildFileKeyType type = key.getType();
        switch(type) {
            case BOOLEAN:
                {
                    ComboBox comboBox = (ComboBox) component;
                    JBTextField editorComponent = (JBTextField) comboBox.getEditor().getEditorComponent();
                    int index = comboBox.getSelectedIndex();
                    if (index == 2) {
                        newValue = Boolean.FALSE;
                        editorComponent.setForeground(JBColor.BLACK);
                    } else if (index == 1) {
                        newValue = Boolean.TRUE;
                        editorComponent.setForeground(JBColor.BLACK);
                    } else {
                        newValue = null;
                        editorComponent.setForeground(JBColor.GRAY);
                    }
                    break;
                }
            case FILE:
            case FILE_AS_STRING:
                {
                    newValue = ((TextFieldWithBrowseButton) component).getText();
                    if ("".equals(newValue)) {
                        newValue = null;
                    }
                    if (newValue != null) {
                        newValue = new File(newValue.toString());
                    }
                    break;
                }
            case INTEGER:
                {
                    try {
                        if (hasKnownValues(key)) {
                            String newStringValue = ((ComboBox) component).getEditor().getItem().toString();
                            newStringValue = getMappedValue(myKeysWithKnownValues.get(key).inverse(), newStringValue);
                            newValue = Integer.valueOf(newStringValue);
                        } else {
                            newValue = Integer.valueOf(((JBTextField) component).getText());
                        }
                    } catch (Exception e) {
                        newValue = null;
                    }
                    break;
                }
            case REFERENCE:
                {
                    newValue = ((ComboBox) component).getEditor().getItem();
                    String newStringValue = (String) newValue;
                    if (hasKnownValues(key)) {
                        newStringValue = getMappedValue(myKeysWithKnownValues.get(key).inverse(), newStringValue);
                    }
                    if (newStringValue != null && newStringValue.isEmpty()) {
                        newStringValue = null;
                    }
                    String prefix = getReferencePrefix(key);
                    if (newStringValue != null && !newStringValue.startsWith(prefix)) {
                        newStringValue = prefix + newStringValue;
                    }
                    newValue = newStringValue;
                    break;
                }
            case CLOSURE:
            case STRING:
            default:
                {
                    if (hasKnownValues(key)) {
                        String newStringValue = ((ComboBox) component).getEditor().getItem().toString();
                        newStringValue = getMappedValue(myKeysWithKnownValues.get(key).inverse(), newStringValue);
                        if (newStringValue.isEmpty()) {
                            newStringValue = null;
                        }
                        newValue = newStringValue;
                    } else {
                        newValue = ((JBTextField) component).getText();
                        if ("".equals(newValue)) {
                            newValue = null;
                        }
                    }
                    if (type == BuildFileKeyType.CLOSURE && newValue != null) {
                        List newListValue = new ArrayList();
                        for (String s : Splitter.on(',').omitEmptyStrings().trimResults().split((String) newValue)) {
                            newListValue.add(key.getValueFactory().parse(s, myProject));
                        }
                        newValue = newListValue;
                    }
                    break;
                }
        }
        if (!Objects.equal(currentValue, newValue)) {
            if (newValue == null) {
                myCurrentBuildFileObject.remove(key);
            } else {
                myCurrentBuildFileObject.put(key, newValue);
            }
            if (GradleBuildFile.shouldWriteValue(currentValue, newValue)) {
                myListener.modified(key);
            }
        }
    }
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) JBTextField(com.intellij.ui.components.JBTextField) AndroidTargetHash.getAddonHashString(com.android.sdklib.AndroidTargetHash.getAddonHashString) BuildFileKeyType(com.android.tools.idea.gradle.parser.BuildFileKeyType) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) BuildFileKey(com.android.tools.idea.gradle.parser.BuildFileKey) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) File(java.io.File)

Example 24 with ComboBox

use of com.intellij.openapi.ui.ComboBox in project intellij-plugins by JetBrains.

the class DartConfigurable method createUIComponents.

private void createUIComponents() {
    mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
    myDartiumPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
    final CheckboxTree.CheckboxTreeCellRenderer checkboxTreeCellRenderer = new CheckboxTree.CheckboxTreeCellRenderer() {

        @Override
        public void customizeRenderer(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            if (!(value instanceof CheckedTreeNode))
                return;
            final boolean dartSupportEnabled = myEnableDartSupportCheckBox.isSelected();
            final CheckedTreeNode node = (CheckedTreeNode) value;
            final Object userObject = node.getUserObject();
            if (userObject instanceof Project) {
                if (!dartSupportEnabled) {
                    //disabled state is also used as partially selected, that's why we do not change 'enabled' state if dartSupportEnabled
                    getCheckbox().setEnabled(false);
                }
                getTextRenderer().setEnabled(dartSupportEnabled);
                getTextRenderer().append(DartBundle.message("project.0", ((Project) userObject).getName()));
            } else if (userObject instanceof Module) {
                getCheckbox().setEnabled(dartSupportEnabled);
                getTextRenderer().setEnabled(dartSupportEnabled);
                final Icon moduleIcon = ModuleType.get((Module) userObject).getIcon();
                getTextRenderer().setIcon(dartSupportEnabled ? moduleIcon : IconLoader.getDisabledIcon(moduleIcon));
                getTextRenderer().append(((Module) userObject).getName());
            }
        }
    };
    myModulesCheckboxTreeTable = new CheckboxTreeTable(null, checkboxTreeCellRenderer, new ColumnInfo[] { new TreeColumnInfo("") });
    myModulesCheckboxTreeTable.addCheckboxTreeListener(new CheckboxTreeAdapter() {

        @Override
        public void nodeStateChanged(@NotNull CheckedTreeNode node) {
            updateErrorLabel();
        }
    });
    //myModulesCheckboxTreeTable.setRowHeight(myModulesCheckboxTreeTable.getRowHeight() + 2);
    myModulesCheckboxTreeTable.getTree().addTreeWillExpandListener(new TreeWillExpandListener() {

        public void treeWillExpand(final TreeExpansionEvent event) throws ExpandVetoException {
        }

        public void treeWillCollapse(final TreeExpansionEvent event) throws ExpandVetoException {
            throw new ExpandVetoException(event);
        }
    });
}
Also used : TreeWillExpandListener(javax.swing.event.TreeWillExpandListener) ComboBox(com.intellij.openapi.ui.ComboBox) ColumnInfo(com.intellij.util.ui.ColumnInfo) TreeColumnInfo(com.intellij.ui.treeStructure.treetable.TreeColumnInfo) ExpandVetoException(javax.swing.tree.ExpandVetoException) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent) TreeColumnInfo(com.intellij.ui.treeStructure.treetable.TreeColumnInfo)

Example 25 with ComboBox

use of com.intellij.openapi.ui.ComboBox in project intellij-plugins by JetBrains.

the class DartGeneratorPeer method createUIComponents.

private void createUIComponents() {
    mySdkPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
    myDartiumPathComboWithBrowse = new ComboboxWithBrowseButton(new ComboBox<>());
}
Also used : ComboboxWithBrowseButton(com.intellij.ui.ComboboxWithBrowseButton) ComboBox(com.intellij.openapi.ui.ComboBox)

Aggregations

ComboBox (com.intellij.openapi.ui.ComboBox)46 Nullable (org.jetbrains.annotations.Nullable)12 ActionListener (java.awt.event.ActionListener)11 ActionEvent (java.awt.event.ActionEvent)10 JBLabel (com.intellij.ui.components.JBLabel)7 NotNull (org.jetbrains.annotations.NotNull)7 JBTextField (com.intellij.ui.components.JBTextField)6 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)5 AndroidTargetHash.getAddonHashString (com.android.sdklib.AndroidTargetHash.getAddonHashString)4 BuildFileKey (com.android.tools.idea.gradle.parser.BuildFileKey)4 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)4 Project (com.intellij.openapi.project.Project)4 javax.swing (javax.swing)4 Module (com.intellij.openapi.module.Module)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 JBCheckBox (com.intellij.ui.components.JBCheckBox)3 java.awt (java.awt)3 ItemEvent (java.awt.event.ItemEvent)3 ItemListener (java.awt.event.ItemListener)3 CompletionResultSet (com.intellij.codeInsight.completion.CompletionResultSet)2