List of usage examples for com.intellij.openapi.ui TextFieldWithBrowseButton getTextField
@NotNull
public JTextField getTextField()
From source file:com.android.tools.idea.gradle.structure.editors.KeyValuePane.java
License:Apache License
public void init(GradleBuildFile gradleBuildFile, Collection<BuildFileKey> properties) { GridLayoutManager layout = new GridLayoutManager(properties.size() + 1, 2); setLayout(layout);// ww w .j a va 2 s.c o m GridConstraints constraints = new GridConstraints(); constraints.setAnchor(GridConstraints.ANCHOR_WEST); constraints.setVSizePolicy(GridConstraints.SIZEPOLICY_FIXED); for (BuildFileKey property : properties) { constraints.setColumn(0); constraints.setFill(GridConstraints.FILL_NONE); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED); JBLabel label = new JBLabel(property.getDisplayName()); add(label, constraints); constraints.setColumn(1); constraints.setFill(GridConstraints.FILL_HORIZONTAL); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW); JComponent component; switch (property.getType()) { case BOOLEAN: { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = createComboBox(false); comboBox.addItem(""); comboBox.addItem("true"); comboBox.addItem("false"); comboBox.setPrototypeDisplayValue("(false) "); component = comboBox; break; } case FILE: case FILE_AS_STRING: { JBTextField textField = new JBTextField(); TextFieldWithBrowseButton fileField = new TextFieldWithBrowseButton(textField); FileChooserDescriptor d = new FileChooserDescriptor(true, false, false, true, false, false); d.setShowFileSystemRoots(true); fileField.addBrowseFolderListener(new TextBrowseFolderListener(d)); fileField.getTextField().getDocument().addDocumentListener(this); component = fileField; break; } case REFERENCE: { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = createComboBox(true); if (hasKnownValues(property)) { for (String s : myKeysWithKnownValues.get(property).values()) { comboBox.addItem(s); } } // If there are no hardcoded values, the combo box's values will get populated later when the panel for the container reference // type wakes up and notifies us of its current values. component = comboBox; break; } case CLOSURE: case STRING: case INTEGER: default: { if (hasKnownValues(property)) { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = createComboBox(true); for (String s : myKeysWithKnownValues.get(property).values()) { comboBox.addItem(s); } component = comboBox; } else { JBTextField textField = new JBTextField(); textField.getDocument().addDocumentListener(this); component = textField; } break; } } add(component, constraints); label.setLabelFor(component); myProperties.put(property, component); constraints.setRow(constraints.getRow() + 1); } constraints.setColumn(0); constraints.setVSizePolicy(GridConstraints.FILL_VERTICAL); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED); add(new JBLabel(""), constraints); updateUiFromCurrentObject(); }
From source file:com.android.tools.idea.gradle.structure.editors.KeyValuePane.java
License:Apache License
/** * Updates the form UI objects to reflect the currently selected object. Clears the objects and disables them if there is no selected * object./*from w w w .ja v a 2s . c o m*/ */ public void updateUiFromCurrentObject() { myIsUpdating = true; for (Map.Entry<BuildFileKey, JComponent> entry : myProperties.entrySet()) { BuildFileKey key = entry.getKey(); JComponent component = entry.getValue(); Object value = myCurrentBuildFileObject != null ? myCurrentBuildFileObject.get(key) : null; final Object modelValue = myCurrentModelObject != null ? myCurrentModelObject.get(key) : null; switch (key.getType()) { case BOOLEAN: { ComboBox comboBox = (ComboBox) component; String text = formatDefaultValue(modelValue); comboBox.removeItemAt(0); comboBox.insertItemAt(text, 0); JBTextField editorComponent = (JBTextField) comboBox.getEditor().getEditorComponent(); if (Boolean.FALSE.equals(value)) { comboBox.setSelectedIndex(2); editorComponent.setForeground(JBColor.BLACK); } else if (Boolean.TRUE.equals(value)) { comboBox.setSelectedIndex(1); editorComponent.setForeground(JBColor.BLACK); } else { comboBox.setSelectedIndex(0); editorComponent.setForeground(JBColor.GRAY); } break; } case FILE: case FILE_AS_STRING: { TextFieldWithBrowseButton fieldWithButton = (TextFieldWithBrowseButton) component; fieldWithButton.setText(value != null ? value.toString() : ""); JBTextField textField = (JBTextField) fieldWithButton.getTextField(); textField.getEmptyText().setText(formatDefaultValue(modelValue)); break; } case REFERENCE: { String stringValue = (String) value; if (hasKnownValues(key) && stringValue != null) { stringValue = getMappedValue(myKeysWithKnownValues.get(key), stringValue); } String prefix = getReferencePrefix(key); if (stringValue == null) { stringValue = ""; } else if (stringValue.startsWith(prefix)) { stringValue = stringValue.substring(prefix.length()); } ComboBox comboBox = (ComboBox) component; JBTextField textField = (JBTextField) comboBox.getEditor().getEditorComponent(); textField.getEmptyText().setText(formatDefaultValue(modelValue)); comboBox.setSelectedItem(stringValue); break; } case CLOSURE: if (value instanceof List) { value = Joiner.on(", ").join((List) value); } // Fall through to INTEGER/STRING/default case case INTEGER: case STRING: default: { if (hasKnownValues(key)) { if (value != null) { value = getMappedValue(myKeysWithKnownValues.get(key), value.toString()); } ComboBox comboBox = (ComboBox) component; comboBox.setSelectedItem(value != null ? value.toString() : ""); JBTextField textField = (JBTextField) comboBox.getEditor().getEditorComponent(); textField.getEmptyText().setText(formatDefaultValue(modelValue)); } else { JBTextField textField = (JBTextField) component; textField.setText(value != null ? value.toString() : ""); textField.getEmptyText().setText(formatDefaultValue(modelValue)); } break; } } component.setEnabled(myCurrentBuildFileObject != null); } myIsUpdating = false; }
From source file:com.android.tools.idea.structure.gradle.KeyValuePane.java
License:Apache License
public void init(GradleBuildFile gradleBuildFile, Collection<BuildFileKey> properties) { GridLayoutManager layout = new GridLayoutManager(properties.size() + 1, 2); setLayout(layout);//from www. j a v a2 s .c om GridConstraints constraints = new GridConstraints(); constraints.setAnchor(GridConstraints.ANCHOR_WEST); constraints.setVSizePolicy(GridConstraints.SIZEPOLICY_FIXED); for (BuildFileKey property : properties) { constraints.setColumn(0); constraints.setFill(GridConstraints.FILL_NONE); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED); JBLabel label = new JBLabel(property.getDisplayName()); add(label, constraints); constraints.setColumn(1); constraints.setFill(GridConstraints.FILL_HORIZONTAL); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW); JComponent component; switch (property.getType()) { case BOOLEAN: { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = getComboBox(false); comboBox.addItem(""); comboBox.addItem("true"); comboBox.addItem("false"); comboBox.setPrototypeDisplayValue("(false) "); component = comboBox; break; } case FILE: case FILE_AS_STRING: { JBTextField textField = new JBTextField(); TextFieldWithBrowseButton fileField = new TextFieldWithBrowseButton(textField); FileChooserDescriptor d = new FileChooserDescriptor(true, false, false, true, false, false); d.setShowFileSystemRoots(true); fileField.addBrowseFolderListener(new TextBrowseFolderListener(d)); fileField.getTextField().getDocument().addDocumentListener(this); component = fileField; break; } case REFERENCE: { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = getComboBox(true); if (hasKnownValues(property)) { for (String s : myKeysWithKnownValues.get(property).values()) { comboBox.addItem(s); } } // If there are no hardcoded values, the combo box's values will get populated later when the panel for the container reference // type wakes up and notifies us of its current values. component = comboBox; break; } case CLOSURE: case STRING: case INTEGER: default: { if (hasKnownValues(property)) { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = getComboBox(true); for (String s : myKeysWithKnownValues.get(property).values()) { comboBox.addItem(s); } component = comboBox; } else { JBTextField textField = new JBTextField(); textField.getDocument().addDocumentListener(this); component = textField; } break; } } add(component, constraints); label.setLabelFor(component); myProperties.put(property, component); constraints.setRow(constraints.getRow() + 1); } constraints.setColumn(0); constraints.setVSizePolicy(GridConstraints.FILL_VERTICAL); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED); add(new JBLabel(""), constraints); updateUiFromCurrentObject(); }
From source file:com.android.tools.idea.structure.KeyValuePane.java
License:Apache License
public void init(GradleBuildFile gradleBuildFile, Collection<BuildFileKey> properties) { GridLayoutManager layout = new GridLayoutManager(properties.size() + 1, 2); setLayout(layout);/*from w w w .j a v a 2 s. co m*/ GridConstraints constraints = new GridConstraints(); constraints.setAnchor(GridConstraints.ANCHOR_WEST); constraints.setVSizePolicy(GridConstraints.SIZEPOLICY_FIXED); for (BuildFileKey property : properties) { constraints.setColumn(0); constraints.setFill(GridConstraints.FILL_NONE); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED); add(new JBLabel(property.getDisplayName()), constraints); constraints.setColumn(1); constraints.setFill(GridConstraints.FILL_HORIZONTAL); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW); JComponent component; switch (property.getType()) { case BOOLEAN: { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = getComboBox(false); comboBox.addItem(""); comboBox.addItem("true"); comboBox.addItem("false"); comboBox.setPrototypeDisplayValue("(false) "); component = comboBox; break; } case FILE: case FILE_AS_STRING: { JBTextField textField = new JBTextField(); TextFieldWithBrowseButton fileField = new TextFieldWithBrowseButton(textField); FileChooserDescriptor d = new FileChooserDescriptor(true, false, false, true, false, false); d.setShowFileSystemRoots(true); fileField.addBrowseFolderListener(new TextBrowseFolderListener(d)); fileField.getTextField().getDocument().addDocumentListener(this); component = fileField; break; } case REFERENCE: { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = getComboBox(true); if (hasKnownValues(property)) { for (String s : myKeysWithKnownValues.get(property).values()) { comboBox.addItem(s); } } // If there are no hardcoded values, the combo box's values will get populated later when the panel for the container reference // type wakes up and notifies us of its current values. component = comboBox; break; } case CLOSURE: case STRING: case INTEGER: default: { if (hasKnownValues(property)) { constraints.setFill(GridConstraints.FILL_NONE); ComboBox comboBox = getComboBox(true); for (String s : myKeysWithKnownValues.get(property).values()) { comboBox.addItem(s); } component = comboBox; } else { JBTextField textField = new JBTextField(); textField.getDocument().addDocumentListener(this); component = textField; } break; } } add(component, constraints); myProperties.put(property, component); constraints.setRow(constraints.getRow() + 1); } constraints.setColumn(0); constraints.setVSizePolicy(GridConstraints.FILL_VERTICAL); constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED); add(new JBLabel(""), constraints); updateUiFromCurrentObject(); }
From source file:com.android.tools.idea.tests.gui.framework.fixture.newProjectWizard.FlutterProjectStepFixture.java
License:Open Source License
@NotNull public FlutterProjectStepFixture enterProjectLocation(@NotNull String text) { final TextFieldWithBrowseButton locationField = getLocationField(); replaceText(locationField.getTextField(), text); return this; }
From source file:com.android.tools.idea.wizard.dynamic.ScopedDataBinder.java
License:Apache License
/** * Connects the given {@link TextFieldWithBrowseButton} to the given key and sets a listener to pick up * changes that need to trigger validation and UI updates. *///from w w w. java 2 s. co m public void register(@NotNull Key<String> key, @NotNull final TextFieldWithBrowseButton field) { myDocumentsToComponent.put(field.getTextField().getDocument(), field); String value = bindAndGet(key, field, null); if (value != null) { field.setText(value); } else { myState.put(key, field.getText()); } field.addFocusListener(this); field.getTextField().getDocument().addDocumentListener(this); field.getTextField().addFocusListener(this); }
From source file:com.android.tools.idea.wizard.ScopedDataBinder.java
License:Apache License
/** * Connects the given {@link TextFieldWithBrowseButton} to the given key and sets a listener to pick up * changes that need to trigger validation and UI updates. *///from www . j av a 2 s .co m protected void register(@NotNull Key<String> key, @NotNull final TextFieldWithBrowseButton field) { myDocumentsToComponent.put(field.getTextField().getDocument(), field); String value = bindAndGet(key, field, null); if (value != null) { field.setText(value); } else { myState.put(key, field.getText()); } field.addFocusListener(this); field.getTextField().getDocument().addDocumentListener(this); field.getTextField().addFocusListener(this); }
From source file:com.android.tools.idea.wizard.template.TemplateWizardStep.java
License:Apache License
protected void register(@NotNull String paramName, @NotNull final TextFieldWithBrowseButton field) { String value = (String) myTemplateState.get(paramName); if (value != null) { field.setText(value);//from w w w . j a va 2s. c o m } else { myTemplateState.put(paramName, field.getText()); } myParamFields.put(paramName, (JComponent) field); field.addFocusListener(this); field.getTextField().getDocument().addDocumentListener(this); field.getTextField().addFocusListener(this); }
From source file:com.android.tools.idea.wizard.TemplateWizardStep.java
License:Apache License
protected void register(@NotNull String paramName, @NotNull final TextFieldWithBrowseButton field) { String value = (String) myTemplateState.get(paramName); if (value != null) { field.setText(value);/* w ww . j a v a 2s . c om*/ } else { myTemplateState.put(paramName, field.getText()); } myParamFields.put(paramName, (JComponent) field); field.addFocusListener(this); field.getTextField().getDocument().addDocumentListener(this); }
From source file:com.googlecode.idea.red5.SelectRed5LocationDialog.java
License:Open Source License
private static void initChooser(TextFieldWithBrowseButton field, String title, String description) { field.setText(getDefaultLocation()); field.getTextField().setEditable(true); field.addBrowseFolderListener(title, description, null, new FileChooserDescriptor(false, true, false, false, false, false)); }