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;
}
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;
}
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);
}
}
}
}
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);
}
});
}
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<>());
}
Aggregations