Example usage for com.intellij.openapi.ui TextFieldWithBrowseButton setText

List of usage examples for com.intellij.openapi.ui TextFieldWithBrowseButton setText

Introduction

In this page you can find the example usage for com.intellij.openapi.ui TextFieldWithBrowseButton setText.

Prototype

@Override
    public void setText(@Nullable String text) 

Source Link

Usage

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. j ava  2  s .  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.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 ww  .ja  v  a 2  s  . c  o 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.dynamic.ScopedDataBinderTest.java

License:Apache License

public void testRegisterTextFieldWithBrowseButton() throws Exception {
    Key<String> textKey = myState.createKey("textField", String.class);
    Key<String> textKey2 = myState.createKey("boundSecond", String.class);
    final Key<String> triggerKey = myState.createKey("triggerKey", String.class);
    TextFieldWithBrowseButton textField = new TextFieldWithBrowseButton();

    myScopedDataBinder.register(textKey, textField);
    myScopedDataBinder.register(textKey2, textField);

    // Test binding UI -> Store
    textField.setText("Hello World!");
    assertEquals("Hello World!", myState.get(textKey));
    assertEquals("Hello World!", myState.get(textKey2));

    // Test binding Store -> UI
    myState.put(textKey, "Awesome");
    assertEquals("Awesome", textField.getText());
    assertEquals("Awesome", myState.get(textKey2));

    myState.put(textKey2, "Goodbye");
    assertEquals("Goodbye", textField.getText());
    assertEquals("Goodbye", myState.get(textKey));

    final AtomicBoolean respectsUserEdits = new AtomicBoolean(true);

    // Test value derivation
    myScopedDataBinder.registerValueDeriver(textKey, new ValueDeriver<String>() {
        @Nullable/* w  ww  .j a v a 2s.c om*/
        @Override
        public Set<Key<?>> getTriggerKeys() {
            return makeSetOf(triggerKey);
        }

        @Override
        public boolean respectUserEdits() {
            return respectsUserEdits.get();
        }

        @NotNull
        @Override
        public String deriveValue(ScopedStateStore state, Key changedKey, @Nullable String currentValue) {
            String trigger = state.get(triggerKey);
            if (trigger == null) {
                return "UNEXPECTED NULL!";
            } else {
                return trigger.toUpperCase();
            }
        }
    });

    myState.put(triggerKey, "Some value to trigger update");
    // The deriver does not fire because user edits are respected
    assertEquals("Goodbye", textField.getText());

    respectsUserEdits.set(false);
    myState.put(triggerKey, "the quick brown fox");
    // The deriver fires because user edits are not respected
    assertEquals("THE QUICK BROWN FOX", textField.getText());
}

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.
 *//*  w w w.  j a  v  a2s . c o 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);
    } else {//  w  ww  .  jav a 2 s  .  co  m
        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);
    } else {//  w  ww  .  j ava 2 s .c o m
        myTemplateState.put(paramName, field.getText());
    }
    myParamFields.put(paramName, (JComponent) field);
    field.addFocusListener(this);
    field.getTextField().getDocument().addDocumentListener(this);
}

From source file:com.google.cloud.tools.intellij.appengine.server.integration.AppEngineServerEditorTest.java

License:Open Source License

@Test
public void testInvalidPathChange() {
    AppEngineServerEditor editor = new AppEngineServerEditor();
    TextFieldWithBrowseButton sdkHomeField = editor.getSdkHomeField();
    JLabel warningMessage = editor.getWarningMessage();

    sdkHomeField.setText("/some/invalid/location");
    Assert.assertEquals(NO_DEVAPPSERVER_IN_GCLOUD, warningMessage.getText());
}

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

From source file:com.intellij.application.options.CodeStyleHtmlPanel.java

License:Apache License

private static void customizeField(final String title, final TextFieldWithBrowseButton uiField) {
    uiField.getTextField().setEditable(false);
    uiField.setButtonIcon(PlatformIcons.OPEN_EDIT_DIALOG_ICON);
    uiField.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            final TagListDialog tagListDialog = new TagListDialog(title);
            tagListDialog.setData(createCollectionOn(uiField.getText()));
            tagListDialog.show();//from   w ww  . j  a v  a2s. co m
            if (tagListDialog.isOK()) {
                uiField.setText(createStringOn(tagListDialog.getData()));
            }
        }

        private String createStringOn(final ArrayList<String> data) {
            return StringUtil.join(ArrayUtil.toStringArray(data), ",");
        }

        private ArrayList<String> createCollectionOn(final String data) {
            if (data == null) {
                return new ArrayList<String>();
            }
            return new ArrayList<String>(Arrays.asList(data.split(",")));
        }

    });
}

From source file:com.intellij.packaging.impl.ManifestFileUtil.java

License:Apache License

public static void setupMainClassField(final Project project, final TextFieldWithBrowseButton field) {
    field.addActionListener(new ActionListener() {
        @Override//  w ww .j a v a2  s  . co  m
        public void actionPerformed(ActionEvent e) {
            final PsiClass selected = selectMainClass(project, field.getText());
            if (selected != null) {
                field.setText(selected.getQualifiedName());
            }
        }
    });
}