@NotNull public static TextFieldWithHistoryWithBrowseButton createTextFieldWithHistoryWithBrowseButton(@Nullable Project project, @NotNull String browseDialogTitle, @NotNull FileChooserDescriptor fileChooserDescriptor, @Nullable NotNullProducer<List<String>> historyProvider) { TextFieldWithHistoryWithBrowseButton textFieldWithHistoryWithBrowseButton = new TextFieldWithHistoryWithBrowseButton(); TextFieldWithHistory textFieldWithHistory = textFieldWithHistoryWithBrowseButton.getChildComponent(); textFieldWithHistory.setHistorySize(-1); textFieldWithHistory.setMinimumAndPreferredWidth(0); if (historyProvider != null) { addHistoryOnExpansion(textFieldWithHistory, historyProvider); } installFileCompletionAndBrowseDialog( project, textFieldWithHistoryWithBrowseButton, browseDialogTitle, fileChooserDescriptor ); return textFieldWithHistoryWithBrowseButton; }
public static void resizeDialogToFitTextFor(@NotNull final JComponent... components) { if (components.length == 0) return; doWithDialogWrapper(components[0], new Consumer<DialogWrapper>() { @Override public void consume(final DialogWrapper dialogWrapper) { if (dialogWrapper instanceof SettingsDialog || dialogWrapper instanceof SingleConfigurableEditor) { for (Component component : components) { if (component instanceof TextFieldWithHistoryWithBrowseButton) { setPreferredWidthToFitText((TextFieldWithHistoryWithBrowseButton)component); } else if (component instanceof TextFieldWithBrowseButton) { setPreferredWidthToFitText((TextFieldWithBrowseButton)component); } else if (component instanceof JTextField) { setPreferredWidthToFitText((JTextField)component); } } ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { adjustDialogSizeToFitPreferredSize(dialogWrapper); } }, ModalityState.any()); } } }); }
public static void installFileCompletionAndBrowseDialog(@Nullable Project project, @NotNull TextFieldWithHistoryWithBrowseButton textFieldWithHistoryWithBrowseButton, @NotNull @Nls(capitalization = Nls.Capitalization.Title) String browseDialogTitle, @NotNull FileChooserDescriptor fileChooserDescriptor) { doInstall(project, textFieldWithHistoryWithBrowseButton, textFieldWithHistoryWithBrowseButton.getChildComponent().getTextEditor(), browseDialogTitle, fileChooserDescriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); }
@Override protected JComponent createNorthPanel() { myNameLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true); myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton(); final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS); if (recentEntries != null) { myTargetDirectoryField.getChildComponent().setHistory(recentEntries); } final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.moved.to.this.directory"), myProject, descriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor(); FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable()); textField.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { validateOKButton(); } }); myTargetDirectoryField.setTextFieldPreferredWidth(CopyFilesOrDirectoriesDialog.MAX_PATH_LENGTH); Disposer.register(getDisposable(), myTargetDirectoryField); String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references")); myCbSearchForReferences.setSelected(RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE); return FormBuilder.createFormBuilder().addComponent(myNameLabel) .addLabeledComponent(RefactoringBundle.message("move.files.to.directory.label"), myTargetDirectoryField, UIUtil.LARGE_VGAP) .addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText)) .addComponentToRightColumn(myCbSearchForReferences, UIUtil.LARGE_VGAP).getPanel(); }
private void validateField(Validator validator, TextFieldWithHistoryWithBrowseButton field, boolean allowEmpty, String message) { if (!ValidationUtils.validatePath(project, field.getChildComponent().getText(), allowEmpty)) { validator.add(field.getChildComponent().getTextEditor(), message, FIX_IT); } }
private static TextFieldWithHistory configWithDefaults(TextFieldWithHistoryWithBrowseButton field) { TextFieldWithHistory textFieldWithHistory = field.getChildComponent(); textFieldWithHistory.setHistorySize(-1); textFieldWithHistory.setMinimumAndPreferredWidth(0); return textFieldWithHistory; }
private static boolean areEqual(TextFieldWithHistoryWithBrowseButton field, String value) { return field.getChildComponent().getText().equals(value); }
public static void setPreferredWidthToFitText(@NotNull TextFieldWithHistoryWithBrowseButton component) { int childWidth = calcWidthToFitText(component.getChildComponent().getTextEditor(), JBUI.scale(32)); setPreferredWidthForComponentWithBrowseButton(component, childWidth); }
@Override protected JComponent createNorthPanel() { myNameLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true); myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton(); final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS); if (recentEntries != null) { myTargetDirectoryField.getChildComponent().setHistory(recentEntries); } final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.moved.to.this.directory"), myProject, descriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor(); FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable()); textField.getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { validateOKButton(); } }); myTargetDirectoryField.setTextFieldPreferredWidth(CopyFilesOrDirectoriesDialog.MAX_PATH_LENGTH); Disposer.register(getDisposable(), myTargetDirectoryField); String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); myCbSearchForReferences = new NonFocusableCheckBox(RefactoringBundle.message("search.for.references")); myCbSearchForReferences.setSelected(RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE); myOpenInEditorCb = new NonFocusableCheckBox("Open moved files in editor"); myOpenInEditorCb.setSelected(isOpenInEditor()); return FormBuilder.createFormBuilder().addComponent(myNameLabel) .addLabeledComponent(RefactoringBundle.message("move.files.to.directory.label"), myTargetDirectoryField, UIUtil.LARGE_VGAP) .addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText)) .addComponentToRightColumn(myCbSearchForReferences, UIUtil.LARGE_VGAP) .addComponentToRightColumn(myOpenInEditorCb, UIUtil.LARGE_VGAP) .getPanel(); }
@Override protected JComponent createNorthPanel() { myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true); final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap( UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP); DocumentListener documentListener = new DocumentAdapter() { @Override public void textChanged(DocumentEvent event) { validateOKButton(); } }; if (myShowNewNameField) { myNewNameField = new JBTextField(); myNewNameField.getDocument().addDocumentListener(documentListener); formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField); } if (myShowDirectoryField) { myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton(); myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH); final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS); if (recentEntries != null) { myTargetDirectoryField.getChildComponent().setHistory(recentEntries); } final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.copied.to.this.directory"), myProject, descriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); myTargetDirectoryField.getChildComponent().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { validateOKButton(); } }); formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField); String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText)); } final JPanel wrapper = new JPanel(new BorderLayout()); wrapper.add(myOpenFilesInEditor, BorderLayout.EAST); formBuilder.addComponent(wrapper); return formBuilder.getPanel(); }
private void validateField(Validator validator, TextFieldWithHistoryWithBrowseButton field, boolean allowEmpty, String message) { if (!ValidationUtils.validatePath(project, field.getChildComponent().getText(), allowEmpty)) { ValidationInfo error = new ValidationInfo(field.getChildComponent().getTextEditor(), message, FIX_IT); validator.errors.add(error); } }
private void validateField(List<ValidationInfo> errors, TextFieldWithHistoryWithBrowseButton field, boolean allowEmpty, String message) { if (!ValidationUtils.validatePath(project, field.getChildComponent().getText(), allowEmpty)) { ValidationInfo error = new ValidationInfo(field.getChildComponent().getTextEditor(), message, FIX_IT); errors.add(error); } }
private void validateField(List<ValidationInfo> errors, TextFieldWithHistoryWithBrowseButton field, boolean allowEmpty, String message) { if (!validatePath(field.getChildComponent().getText(), allowEmpty)) { ValidationInfo error = new ValidationInfo(field.getChildComponent().getTextEditor(), message, FIX_IT); errors.add(error); } }
private void addDocumentListenerToComp(TextFieldWithHistoryWithBrowseButton field, DocumentAdapter docAdp) { field.getChildComponent().getTextEditor().getDocument().addDocumentListener(docAdp); }
private void validateField(Validator validator, TextFieldWithHistoryWithBrowseButton field, boolean allowEmpty, String message) { if (!validatePath(field.getChildComponent().getText(), allowEmpty)) { validator.add(field.getChildComponent().getTextEditor(), message, FIX_IT); // addError(validator, field.getChildComponent().getTextEditor(), message, FIX_IT); } }
public TextFieldWithHistoryWithBrowseButton getControllerNameBox() { return controllerNameBox; }
@Override protected JComponent createNorthPanel() { myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true); final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap( UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP); DocumentListener documentListener = new DocumentAdapter() { @Override public void textChanged(DocumentEvent event) { validateOKButton(); } }; if (myShowNewNameField) { myNewNameField = new JTextField(); myNewNameField.getDocument().addDocumentListener(documentListener); formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField); } if (myShowDirectoryField) { myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton(); myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH); final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS); if (recentEntries != null) { myTargetDirectoryField.getChildComponent().setHistory(recentEntries); } final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.copied.to.this.directory"), myProject, descriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT); myTargetDirectoryField.getChildComponent().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { validateOKButton(); } }); formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField); String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION)); formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText)); } final JPanel wrapper = new JPanel(new BorderLayout()); wrapper.add(myOpenFilesInEditor, BorderLayout.EAST); formBuilder.addComponent(wrapper); return formBuilder.getPanel(); }