List of usage examples for com.intellij.openapi.ui TextFieldWithBrowseButton getTextField
@NotNull
public JTextField getTextField()
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();// www . j a va 2s .c om 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.ide.ui.customization.CustomizableActionsPanel.java
License:Apache License
private static TextFieldWithBrowseButton createBrowseField() { TextFieldWithBrowseButton textField = new TextFieldWithBrowseButton(); textField.setPreferredSize(new Dimension(200, textField.getPreferredSize().height)); textField.setMinimumSize(new Dimension(200, textField.getPreferredSize().height)); final FileChooserDescriptor fileChooserDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {//w w w .j a va2 s .c o m public boolean isFileSelectable(VirtualFile file) { //noinspection HardCodedStringLiteral return file.getName().endsWith(".png"); } }; textField.addBrowseFolderListener(IdeBundle.message("title.browse.icon"), IdeBundle.message("prompt.browse.icon.for.selected.action"), null, fileChooserDescriptor); InsertPathAction.addTo(textField.getTextField(), fileChooserDescriptor); return textField; }
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 ww w . java2 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()); }//from w w w. ja va 2s .co 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: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);/*w w w. ja v a 2s .c om*/ 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:org.codehaus.cargo.intellijidea.CargoConfigurationEditor.java
License:Apache License
/** * Init the chooser.// w w w. j a va2 s .c o m * * @param field textField * @param title title * @param description description */ private void initChooser(TextFieldWithBrowseButton field, String title, String description) { field.getTextField().setEditable(true); field.addBrowseFolderListener(title, description, null, new FileChooserDescriptor(false, true, false, false, false, false)); }
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 a 2 s.com*/ 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.tfsIntegration.ui.FieldWithButtonCellEditor.java
License:Apache License
public FieldWithButtonCellEditor(boolean pathCompletion, final Helper<T> helper) { super(new JTextField()); setClickCountToStart(1);/*from w w w .j a va 2 s . c o m*/ final TextFieldWithBrowseButton field = pathCompletion ? new TextFieldWithBrowseButton() : new TextFieldWithBrowseButton.NoPathCompletion(); field.setOpaque(false); field.getTextField().setBorder(BorderFactory.createEmptyBorder()); field.getButton().addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { String result = helper.processButtonClick(field.getText()); if (result != null) { field.setText(result); } } }); delegate = new EditorDelegate() { public void setValue(Object value) { //noinspection unchecked field.setText(helper.toStringRepresentation((T) value)); } @Nullable public Object getCellEditorValue() { return helper.fromStringRepresentation(field.getText()); } public boolean shouldSelectCell(EventObject anEvent) { if (anEvent instanceof MouseEvent) { MouseEvent e = (MouseEvent) anEvent; return e.getID() != MouseEvent.MOUSE_DRAGGED; } return true; } }; editorComponent = field; }