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.intellij.platform.LocationNameFieldsBinding.java

License:Apache License

public LocationNameFieldsBinding(@Nullable Project project, final TextFieldWithBrowseButton locationTextField,
        final JTextField nameTextField, String baseDir, final String browseFolderTitle) {

    myBaseDir = baseDir;/*from  w w w.j  a  va2 s  . co  m*/
    File suggestedProjectDirectory = FileUtil.findSequentNonexistentFile(new File(baseDir), "untitled", "");
    locationTextField.setText(suggestedProjectDirectory.toString());
    nameTextField.setDocument(new NameFieldDocument(nameTextField, locationTextField));
    mySuggestedProjectName = suggestedProjectDirectory.getName();
    nameTextField.setText(mySuggestedProjectName);
    nameTextField.selectAll();

    FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
    ComponentWithBrowseButton.BrowseFolderActionListener<JTextField> listener = new ComponentWithBrowseButton.BrowseFolderActionListener<JTextField>(
            browseFolderTitle, "", locationTextField, project, descriptor,
            TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT) {
        protected void onFileChoosen(VirtualFile chosenFile) {
            myBaseDir = chosenFile.getPath();
            if (isProjectNameChanged(nameTextField.getText())
                    && !nameTextField.getText().equals(chosenFile.getName())) {
                myExternalModify = true;
                locationTextField.setText(new File(chosenFile.getPath(), nameTextField.getText()).toString());
                myExternalModify = false;
            } else {
                myExternalModify = true;
                locationTextField.setText(chosenFile.getPath());
                nameTextField.setText(chosenFile.getName());
                myExternalModify = false;
            }
        }
    };
    locationTextField.addActionListener(listener);
    locationTextField.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            if (myExternalModify) {
                return;
            }
            myModifyingLocation = true;
            String path = locationTextField.getText().trim();
            if (path.endsWith(File.separator)) {
                path = path.substring(0, path.length() - File.separator.length());
            }
            int ind = path.lastIndexOf(File.separator);
            if (ind != -1) {
                String projectName = path.substring(ind + 1, path.length());
                if (!nameTextField.getText().trim().isEmpty()) {
                    myBaseDir = path.substring(0, ind);
                }
                if (!projectName.equals(nameTextField.getText())) {
                    if (!myModifyingProjectName) {
                        nameTextField.setText(projectName);
                    }
                }
            }
            myModifyingLocation = false;
        }
    });
}

From source file:com.intellij.xml.actions.xmlbeans.UIUtils.java

License:Apache License

public static void configureBrowseButton(final Project myProject, final TextFieldWithBrowseButton wsdlUrl,
        final String[] _extensions, final String selectFileDialogTitle, final boolean multipleFileSelection) {
    wsdlUrl.getButton().setToolTipText(XmlBundle.message("browse.button.tooltip"));
    wsdlUrl.getButton().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false,
                    false, false, multipleFileSelection) {
                private final List<String> extensions = Arrays.asList(_extensions);

                public boolean isFileSelectable(VirtualFile virtualFile) {
                    return extensions.contains(virtualFile.getExtension());
                }/*w  w w.  j av  a2s  .  c o  m*/

                @Override
                public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
                    return super.isFileVisible(file, showHiddenFiles)
                            && (file.isDirectory() || isFileSelectable(file));
                }
            };

            fileChooserDescriptor.setTitle(selectFileDialogTitle);

            VirtualFile initialFile = myProject.getBaseDir();
            String selectedItem = wsdlUrl.getTextField().getText();
            if (selectedItem != null && selectedItem.startsWith(LocalFileSystem.PROTOCOL_PREFIX)) {
                VirtualFile fileByPath = VfsUtil.findRelativeFile(ExternalResourceManager.getInstance()
                        .getResourceLocation(VfsUtil.fixURLforIDEA(selectedItem)), null);
                if (fileByPath != null)
                    initialFile = fileByPath;
            }

            final VirtualFile[] virtualFiles = FileChooser.chooseFiles(fileChooserDescriptor, myProject,
                    initialFile);
            if (virtualFiles.length == 1) {
                String url = fixIDEAUrl(virtualFiles[0].getUrl());
                wsdlUrl.setText(url);
            }
        }
    });
}

From source file:com.microsoft.intellij.ui.NewCertificateDialog.java

License:Open Source License

private ActionListener getFileSaverListener(final TextFieldWithBrowseButton field,
        final TextFieldWithBrowseButton fieldToUpdate, final String suffixToReplace, final String suffix) {
    return new ActionListener() {
        @Override/*from w ww . j  av a 2 s. c o m*/
        public void actionPerformed(ActionEvent e) {
            final FileSaverDialog dialog = FileChooserFactory.getInstance().createSaveFileDialog(
                    new FileSaverDescriptor(message("newCertDlgBrwFldr"), "", suffixToReplace), field);
            final VirtualFile baseDir = myProject.getBaseDir();
            final VirtualFileWrapper save = dialog.save(baseDir, "");
            if (save != null) {
                field.setText(FileUtil.toSystemDependentName(save.getFile().getAbsolutePath()));
                if (fieldToUpdate.getText().isEmpty()) {
                    fieldToUpdate.setText(Utils.replaceLastSubString(field.getText(), suffixToReplace, suffix));
                }
            }
        }
    };
}

From source file:com.microsoft.intellij.ui.util.UIUtils.java

License:Open Source License

public static ActionListener createFileChooserListener(final TextFieldWithBrowseButton parent,
        final @Nullable Project project, final FileChooserDescriptor descriptor) {
    return new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            //                final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createAllButJarContentsDescriptor();
            //                DataContext dataContext = DataManager.getInstance().getDataContextFromFocus().getResult();
            final VirtualFile[] files = FileChooser.chooseFiles(descriptor, parent, project,
                    (project == null) && !parent.getText().isEmpty()
                            ? LocalFileSystem.getInstance().findFileByPath(parent.getText())
                            : null);/*from w  w  w . ja  va 2  s . co m*/
            if (files.length > 0) {
                final StringBuilder builder = new StringBuilder();
                for (VirtualFile file : files) {
                    if (builder.length() > 0) {
                        builder.append(File.pathSeparator);
                    }
                    builder.append(FileUtil.toSystemDependentName(file.getPath()));
                }
                parent.setText(builder.toString());
            }
        }
    };
}

From source file:de.mprengemann.intellij.plugin.androidicons.forms.AndroidMultiDrawableImporter.java

License:Apache License

private void initBrowser(Resolution resolution, final TextFieldWithBrowseButton browseButton) {
    final FileChooserDescriptor imageDescriptor = FileChooserDescriptorFactory
            .createSingleFileDescriptor(ImageFileTypeManager.getInstance().getImageFileType());
    String title1 = "Select your " + resolution.getName() + " asset";
    imageDescriptor.setTitle(title1);//from   w  w  w  .ja  v a  2s . co m
    ImageFileBrowserFolderActionListener actionListener = new ImageFileBrowserFolderActionListener(title1,
            project, browseButton, imageDescriptor) {
        @Override
        @SuppressWarnings("deprecation") // Otherwise not compatible to AndroidStudio
        protected void onFileChoosen(@NotNull VirtualFile chosenFile) {
            super.onFileChoosen(chosenFile);
            fillImageInformation(chosenFile);
        }
    };
    browseButton.addBrowseFolderListener(project, actionListener);
    browseButton.getTextField().addMouseListener(new SimpleMouseListener() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            updateImage(browseButton.getText());
        }
    });
    new FileDrop(browseButton.getTextField(), new FileDrop.Target() {
        @Override
        public FileChooserDescriptor getDescriptor() {
            return imageDescriptor;
        }

        @Override
        public boolean isHiddenShown() {
            return false;
        }

        @Override
        public void dropFiles(List<VirtualFile> virtualFiles) {
            if (virtualFiles != null) {
                if (virtualFiles.size() == 1) {
                    VirtualFile chosenFile = virtualFiles.get(0);
                    browseButton.setText(chosenFile.getCanonicalPath());
                    fillImageInformation(chosenFile);
                }
            }
        }
    });
}

From source file:de.mprengemann.intellij.plugin.androidicons.util.AndroidResourcesHelper.java

License:Apache License

public static void initResourceBrowser(final Project project, Module module, final String title,
        @Nullable final TextFieldWithBrowseButton browser) {
    final VirtualFile resRoot = SettingsHelper.getResRootForProject(project);

    if (resRoot == null) {
        getResRootFile(project, module, new ResourcesDialog.ResourceSelectionListener() {
            @Override//from  w  w w .j  a va 2  s  .  c  om
            public void onResourceSelected(VirtualFile resDir) {
                if (browser != null) {
                    browser.setText(resDir.getCanonicalPath());
                }
                SettingsHelper.saveResRootForProject(project, resDir.getUrl());
            }
        });
    } else {
        if (browser != null) {
            browser.setText(resRoot.getCanonicalPath());
        }
    }

    if (browser != null) {
        FileChooserDescriptor workingDirectoryChooserDescriptor = FileChooserDescriptorFactory
                .createSingleFolderDescriptor();
        workingDirectoryChooserDescriptor.setTitle(title);
        browser.addBrowseFolderListener(title, null, project, workingDirectoryChooserDescriptor);
        browser.addBrowseFolderListener(new TextBrowseFolderListener(workingDirectoryChooserDescriptor) {
            @Override
            @SuppressWarnings("deprecation") // Otherwise not compatible to AndroidStudio
            protected void onFileChoosen(@NotNull VirtualFile chosenFile) {
                super.onFileChoosen(chosenFile);
                SettingsHelper.saveResRootForProject(project, chosenFile.getUrl());
            }
        });
    }
}

From source file:org.argus.cit.intellij.android.newProject.ConfigureArgusProjectStep.java

License:Open Source License

private void browseForFile(TextFieldWithBrowseButton button, FileSaverDescriptor saver) {
    File currentPath = new File(button.getText());
    File parentPath = currentPath.getParentFile();
    if (parentPath == null) {
        String homePath = System.getProperty("user.home");
        parentPath = homePath == null ? new File("/") : new File(homePath);
    }/*  ww w. java2  s  .  c  o  m*/
    VirtualFile parent = LocalFileSystem.getInstance().findFileByIoFile(parentPath);
    String filename = currentPath.getName();
    VirtualFileWrapper fileWrapper = FileChooserFactory.getInstance()
            .createSaveFileDialog(saver, (Project) null).save(parent, filename);
    if (fileWrapper != null) {
        button.setText(fileWrapper.getFile().getAbsolutePath());
    }
}

From source file:org.jboss.forge.plugin.idea.components.FileChooserComponentBuilder.java

License:Open Source License

@Override
public JComponent build(final InputComponent<?, Object> input, Container container) {
    // Added Label
    container.add(new JLabel(input.getLabel() == null ? input.getName() : input.getLabel()));

    final TextFieldWithBrowseButton fileField = new TextFieldWithBrowseButton(new ActionListener() {

        @Override/* w  w w.  ja v a2  s. co  m*/
        public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub

        }
    });
    // Set Default Value
    final ConverterFactory converterFactory = ForgeService.INSTANCE.getConverterFactory();
    Converter<Object, String> converter = converterFactory.getConverter(input.getValueType(), String.class);
    String value = converter.convert(InputComponents.getValueFor(input));
    fileField.setText(value == null ? "" : value);

    final JTextField textField = fileField.getTextField();
    textField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            InputComponents.setValueFor(converterFactory, input, textField.getText());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            InputComponents.setValueFor(converterFactory, input, textField.getText());
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            InputComponents.setValueFor(converterFactory, input, textField.getText());
        }
    });

    fileField.addBrowseFolderListener("Select a directory", null, null,
            FileChooserDescriptorFactory.createSingleFolderDescriptor());
    container.add(fileField);
    return null;
}

From source file:org.jetbrains.idea.svn.update.SvnIntegrateRootOptionsPanel.java

License:Apache License

private boolean chooseUrl(final TextFieldWithBrowseButton textField, final SvnVcs vcs) {
    String url = textField.getText();
    final String selectedUrl = SelectLocationDialog.selectLocation(vcs.getProject(), url);
    if (selectedUrl != null) {
        textField.setText(selectedUrl);
        return true;
    } else {/*from  w w  w  .  j a v a  2  s  . c  om*/
        return false;
    }
}

From source file:org.jetbrains.plugins.javaFX.packaging.JavaFxArtifactPropertiesEditor.java

License:Apache License

private static void setText(TextFieldWithBrowseButton tf, final String title) {
    if (title != null) {
        tf.setText(title.trim());
    }/*w w w .  j a va2s  .c  o  m*/
}