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

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

Introduction

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

Prototype

public void addBrowseFolderListener(@NotNull TextBrowseFolderListener listener) 

Source Link

Usage

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 va2 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.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);// w w w  .j  ava 2s.  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);
        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 ww .  j av a 2s  .  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);
        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:org.eclipse.xtext.idea.util.IdeaWidgetFactory.java

License:Open Source License

public TextFieldWithBrowseButton browseField(final Project project) {
    final TextFieldWithBrowseButton field = new TextFieldWithBrowseButton();
    FileChooserDescriptor _createSingleFolderDescriptor = FileChooserDescriptorFactory
            .createSingleFolderDescriptor();
    final MacroAwareTextBrowseFolderListener listener = new MacroAwareTextBrowseFolderListener(
            _createSingleFolderDescriptor, project);
    field.addBrowseFolderListener(listener);
    return field;
}