Search in sources :

Example 16 with TextFieldWithBrowseButton

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

the class TemplateWizardStep method refreshUiFromParameters.

public void refreshUiFromParameters() {
    if (myTemplateState.myTemplate == null) {
        return;
    }
    for (Parameter param : myTemplateState.myTemplate.getMetadata().getParameters()) {
        if (param.initial != null && !myTemplateState.myModified.contains(param.id)) {
            myTemplateState.myParameters.remove(param.id);
        }
    }
    myTemplateState.setParameterDefaults();
    Template.convertApisToInt(myTemplateState.getParameters());
    boolean oldIgnoreUpdates = myIgnoreUpdates;
    try {
        myIgnoreUpdates = true;
        for (String paramName : myParamFields.keySet()) {
            if (myTemplateState.myHidden.contains(paramName)) {
                continue;
            }
            JComponent component = myParamFields.get(paramName);
            Object value = myTemplateState.get(paramName);
            if (value == null) {
                continue;
            }
            if (component instanceof JCheckBox) {
                ((JCheckBox) component).setSelected(Boolean.parseBoolean(value.toString()));
            } else if (component instanceof JComboBox) {
                for (int i = 0; i < ((JComboBox) component).getItemCount(); i++) {
                    if (((ApiComboBoxItem) ((JComboBox) component).getItemAt(i)).getData().equals(value)) {
                        ((JComboBox) component).setSelectedIndex(i);
                        break;
                    }
                }
            } else if (component instanceof JTextField) {
                ((JTextField) component).setText(value.toString());
            } else if (component instanceof TextFieldWithBrowseButton) {
                ((TextFieldWithBrowseButton) component).setText(value.toString());
            } else if (component instanceof JSlider) {
                ((JSlider) component).setValue(Integer.parseInt(value.toString()));
            } else if (component instanceof JSpinner) {
                ((JSpinner) component).setValue(Integer.parseInt(value.toString()));
            } else if (component instanceof ColorPanel) {
                ((ColorPanel) component).setSelectedColor((Color) value);
            }
        }
    } finally {
        myIgnoreUpdates = oldIgnoreUpdates;
    }
}
Also used : ApiComboBoxItem(com.android.tools.idea.ui.ApiComboBoxItem) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) ColorPanel(com.intellij.ui.ColorPanel) Parameter(com.android.tools.idea.templates.Parameter)

Example 17 with TextFieldWithBrowseButton

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

the class IdeSdksConfigurable method createJdkLocationTextField.

private void createJdkLocationTextField() {
    JTextField textField = new JTextField(10);
    myJdkLocationTextField = new TextFieldWithBrowseButton(textField, e -> chooseJdkLocation());
}
Also used : FocusListener(java.awt.event.FocusListener) HyperlinkEvent(javax.swing.event.HyperlinkEvent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DetailsComponent(com.intellij.openapi.ui.DetailsComponent) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) WizardUtils.validateLocation(com.android.tools.idea.npw.WizardUtils.validateLocation) JBUI(com.intellij.util.ui.JBUI) AsyncProcessIcon(com.intellij.util.ui.AsyncProcessIcon) StudioProgressRunner(com.android.tools.idea.sdk.progress.StudioProgressRunner) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) Messages(com.intellij.openapi.ui.Messages) AndroidSdkData(org.jetbrains.android.sdk.AndroidSdkData) EmbeddedDistributionPaths(com.android.tools.idea.gradle.util.EmbeddedDistributionPaths) Logger(com.intellij.openapi.diagnostic.Logger) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) BiMap(com.google.common.collect.BiMap) ActionCallback(com.intellij.openapi.util.ActionCallback) NDK_DIR_PROPERTY(com.android.SdkConstants.NDK_DIR_PROPERTY) FileChooser.chooseFile(com.intellij.openapi.fileChooser.FileChooser.chooseFile) LocalProperties(com.android.tools.idea.gradle.util.LocalProperties) ProgressIndicator(com.android.repository.api.ProgressIndicator) JdkUtil.checkForJdk(com.intellij.openapi.projectRoots.JdkUtil.checkForJdk) WritableCheckMode(com.android.tools.idea.npw.WizardUtils.WritableCheckMode) ModelWizardDialog(com.android.tools.idea.wizard.model.ModelWizardDialog) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) BaseConfigurable(com.intellij.openapi.options.BaseConfigurable) SdkPaths.validateAndroidNdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidNdk) Function(com.intellij.util.Function) ApplicationManager(com.intellij.openapi.application.ApplicationManager) JDK_1_8(com.intellij.openapi.projectRoots.JavaSdkVersion.JDK_1_8) ConfigurationException(com.intellij.openapi.options.ConfigurationException) NotNull(org.jetbrains.annotations.NotNull) FD_NDK(com.android.SdkConstants.FD_NDK) DocumentAdapter(com.intellij.ui.DocumentAdapter) SdkQuickfixUtils.createDialogForPaths(com.android.tools.idea.sdk.wizard.SdkQuickfixUtils.createDialogForPaths) Strings.nullToEmpty(com.google.common.base.Strings.nullToEmpty) NonNls(org.jetbrains.annotations.NonNls) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) ActionManager(com.intellij.openapi.actionSystem.ActionManager) History(com.intellij.ui.navigation.History) FocusAdapter(java.awt.event.FocusAdapter) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) StudioLoggerProgressIndicator(com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator) Project(com.intellij.openapi.project.Project) DocumentEvent(javax.swing.event.DocumentEvent) WizardUtils(com.android.tools.idea.npw.WizardUtils) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) UIUtil.getLabelBackground(com.intellij.util.ui.UIUtil.getLabelBackground) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter) FileUtilRt.toSystemDependentName(com.intellij.openapi.util.io.FileUtilRt.toSystemDependentName) MAC_JDK_CONTENT_PATH(com.android.tools.idea.sdk.IdeSdks.MAC_JDK_CONTENT_PATH) IOException(java.io.IOException) StringUtil.isEmpty(com.intellij.openapi.util.text.StringUtil.isEmpty) Sdk(com.intellij.openapi.projectRoots.Sdk) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) com.android.tools.idea.sdk(com.android.tools.idea.sdk) ValidationResult(com.android.tools.idea.sdk.SdkPaths.ValidationResult) java.awt(java.awt) SdkPaths.validateAndroidSdk(com.android.tools.idea.sdk.SdkPaths.validateAndroidSdk) HashBiMap(com.google.common.collect.HashBiMap) Place(com.intellij.ui.navigation.Place) FocusEvent(java.awt.event.FocusEvent) RepoManager(com.android.repository.api.RepoManager) UIUtil.getTextFieldBackground(com.intellij.util.ui.UIUtil.getTextFieldBackground) javax.swing(javax.swing) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton)

Example 18 with TextFieldWithBrowseButton

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

the class IdeSdksConfigurable method createTextFieldWithBrowseButton.

@NotNull
private TextFieldWithBrowseButton createTextFieldWithBrowseButton(@NotNull String title, @NotNull String errorMessage, @NotNull Function<File, ValidationResult> validation) {
    FileChooserDescriptor descriptor = createSingleFolderDescriptor(title, file -> {
        ValidationResult validationResult = validation.fun(file);
        if (!validationResult.success) {
            String msg = validationResult.message;
            if (isEmpty(msg)) {
                msg = errorMessage;
            }
            throw new IllegalArgumentException(msg);
        }
        return null;
    });
    JTextField textField = new JTextField(10);
    return new TextFieldWithBrowseButton(textField, e -> {
        VirtualFile suggestedDir = null;
        File ndkLocation = getNdkLocation();
        if (ndkLocation.isDirectory()) {
            suggestedDir = findFileByIoFile(ndkLocation, false);
        }
        VirtualFile chosen = chooseFile(descriptor, null, suggestedDir);
        if (chosen != null) {
            File f = virtualToIoFile(chosen);
            textField.setText(f.getPath());
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ValidationResult(com.android.tools.idea.sdk.SdkPaths.ValidationResult) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) FileChooser.chooseFile(com.intellij.openapi.fileChooser.FileChooser.chooseFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with TextFieldWithBrowseButton

use of com.intellij.openapi.ui.TextFieldWithBrowseButton in project intellij-community by JetBrains.

the class IdeaGradleProjectSettingsControlBuilder method addGradleHomeComponents.

@Override
public IdeaGradleProjectSettingsControlBuilder addGradleHomeComponents(PaintAwarePanel content, int indentLevel) {
    if (dropGradleHomePathComponents)
        return this;
    myGradleHomeLabel = new JBLabel(GradleBundle.message("gradle.settings.text.home.path"));
    myGradleHomePathField = new TextFieldWithBrowseButton();
    myGradleHomePathField.addBrowseFolderListener("", GradleBundle.message("gradle.settings.text.home.path"), null, GradleUtil.getGradleHomeFileChooserDescriptor(), TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
    myGradleHomePathField.getTextField().getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            myGradleHomePathField.getTextField().setForeground(LocationSettingType.EXPLICIT_CORRECT.getColor());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            myGradleHomePathField.getTextField().setForeground(LocationSettingType.EXPLICIT_CORRECT.getColor());
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
        }
    });
    content.add(myGradleHomeLabel, ExternalSystemUiUtil.getLabelConstraints(indentLevel));
    content.add(myGradleHomePathField, ExternalSystemUiUtil.getFillLineConstraints(0));
    return this;
}
Also used : DocumentListener(javax.swing.event.DocumentListener) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) JBLabel(com.intellij.ui.components.JBLabel) DocumentEvent(javax.swing.event.DocumentEvent)

Example 20 with TextFieldWithBrowseButton

use of com.intellij.openapi.ui.TextFieldWithBrowseButton in project intellij-community by JetBrains.

the class DirDiffPanel method createUIComponents.

private void createUIComponents() {
    mySourceDirField = new TextFieldWithBrowseButton(null, this);
    myTargetDirField = new TextFieldWithBrowseButton(null, this);
    final AtomicBoolean callUpdate = new AtomicBoolean(true);
    myRootPanel = new JPanel(new BorderLayout()) {

        @Override
        protected void paintChildren(Graphics g) {
            super.paintChildren(g);
            if (callUpdate.get()) {
                callUpdate.set(false);
                myModel.reloadModel(false);
            }
        }
    };
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton)

Aggregations

TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)59 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)22 NotNull (org.jetbrains.annotations.NotNull)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 ActionEvent (java.awt.event.ActionEvent)9 ActionListener (java.awt.event.ActionListener)8 JBLabel (com.intellij.ui.components.JBLabel)6 JBTextField (com.intellij.ui.components.JBTextField)6 DocumentEvent (javax.swing.event.DocumentEvent)6 File (java.io.File)5 Nullable (org.jetbrains.annotations.Nullable)5 FileTextField (com.intellij.openapi.fileChooser.FileTextField)4 ComboBox (com.intellij.openapi.ui.ComboBox)4 TextBrowseFolderListener (com.intellij.openapi.ui.TextBrowseFolderListener)4 DocumentListener (javax.swing.event.DocumentListener)4 AndroidTargetHash.getAddonHashString (com.android.sdklib.AndroidTargetHash.getAddonHashString)3 BuildFileKey (com.android.tools.idea.gradle.parser.BuildFileKey)3 ComponentWithBrowseButton (com.intellij.openapi.ui.ComponentWithBrowseButton)3 RawCommandLineEditor (com.intellij.ui.RawCommandLineEditor)3 JBCheckBox (com.intellij.ui.components.JBCheckBox)3