String path = getTextControl().getText(); if (path != null) { path = path.trim(); if (!isEmptyStringAllowed()) { msg = getErrorMessage(); msg = getErrorMessage(); showErrorMessage(msg); return false; if(doCheckState()) { // OK! clearErrorMessage(); return true; msg = getErrorMessage(); // subclass might have changed it in the #doCheckState() if (msg != null) { showErrorMessage(msg);
/** * Creates a file field editor. * * @param name the name of the preference this field editor works on * @param labelText the label text of the field editor * @param enforceAbsolute <code>true</code> if the file path * must be absolute, and <code>false</code> otherwise * @param validationStrategy either {@link StringButtonFieldEditor#VALIDATE_ON_KEY_STROKE} * to perform on the fly checking, or {@link StringButtonFieldEditor#VALIDATE_ON_FOCUS_LOST} * (the default) to perform validation only after the text has been typed in * @param parent the parent of the field editor's control. * @since 3.4 * @see StringButtonFieldEditor#VALIDATE_ON_KEY_STROKE * @see StringButtonFieldEditor#VALIDATE_ON_FOCUS_LOST */ public FileFieldEditor(String name, String labelText, boolean enforceAbsolute, int validationStrategy, Composite parent) { init(name, labelText); this.enforceAbsolute = enforceAbsolute; setErrorMessage(JFaceResources .getString("FileFieldEditor.errorMessage"));//$NON-NLS-1$ setChangeButtonText(JFaceResources.getString("openBrowse"));//$NON-NLS-1$ setValidateStrategy(validationStrategy); createControl(parent); }
@Override protected String changePressed() { File f = new File(getTextControl().getText()); if (!f.exists()) { f = null; } File d = getFile(f); if (d == null) { return null; } return d.getAbsolutePath(); }
protected void createFieldEditors() { addField(new IntegerFieldEditor("launchCount", "Number of times it has been launched", getFieldEditorParent())); IntegerFieldEditor offset = new IntegerFieldEditor("offset", "Current offset from GMT", getFieldEditorParent()); offset.setValidRange(-14, +12); addField(offset); String[][] data = ZoneId.getAvailableZoneIds()// .stream().sorted().map(s -> new String[] { s, s }) // .collect(Collectors.toList()).toArray(new String[][] {}); addField(new ComboFieldEditor("favorite", "Favorite time zone", data, getFieldEditorParent())); addField(new BooleanFieldEditor("tick", "Boolean value", getFieldEditorParent())); addField(new ColorFieldEditor("colour", "Favourite colour", getFieldEditorParent())); addField(new ScaleFieldEditor("scale", "Scale", getFieldEditorParent(), 0, 360, 10, 90)); addField(new FileFieldEditor("file", "Pick a file", getFieldEditorParent())); addField(new DirectoryFieldEditor("dir", "Pick a directory", getFieldEditorParent())); addField(new PathEditor("path", "Path", "Directory", getFieldEditorParent())); addField(new RadioGroupFieldEditor("group", "Radio choices", 3, data, getFieldEditorParent(), true)); }
/** * Helper to open the file chooser dialog. * @param startingDirectory the directory to open the dialog on. * @return File The File the user selected or <code>null</code> if they * do not. */ private File getFile(File startingDirectory) { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.SHEET); if (startingDirectory != null) { dialog.setFileName(startingDirectory.getPath()); } else if (filterPath != null) { dialog.setFilterPath(filterPath.getPath()); } if (extensions != null) { dialog.setFilterExtensions(extensions); } String file = dialog.open(); if (file != null) { file = file.trim(); if (file.length() > 0) { return new File(file); } } return null; }
/** * Creates the field editors. Field editors are abstractions of the common * GUI blocks needed to manipulate various types of preferences. Each field * editor knows how to save and restore itself. */ public void createFieldEditors() { clangFormatPath = new FileFieldEditor(CppStyleConstants.CLANG_FORMAT_PATH, "Clang-format path:", getFieldEditorParent()); addField(clangFormatPath); cpplintPath = new FileFieldEditor(CppStyleConstants.CPPLINT_PATH, "Cpplint path:", getFieldEditorParent()); addField(cpplintPath); enableCpplintOnSave = new BooleanFieldEditor(CppStyleConstants.ENABLE_CPPLINT_ON_SAVE, CppStyleConstants.ENABLE_CPPLINT_TEXT, getFieldEditorParent()); if (!checkPathExist(CppStyle.getCpplintPath())) { enableCpplintOnSave.setEnabled(false, getFieldEditorParent()); } addField(enableCpplintOnSave); enableClangFormatOnSave = new BooleanFieldEditor(CppStyleConstants.ENABLE_CLANGFORMAT_ON_SAVE, CppStyleConstants.ENABLE_CLANGFORMAT_TEXT, getFieldEditorParent()); if (!checkPathExist(ClangFormatFormatter.getClangFormatPath())) { enableClangFormatOnSave.setEnabled(false, getFieldEditorParent()); } addField(enableClangFormatOnSave); }
/** * Helper to open the file chooser dialog. * @param startingDirectory the directory to open the dialog on. * @return File The File the user selected or <code>null</code> if they * do not. */ private File getFile(File startingDirectory) { FileDialog dialog = new FileDialog(getShell(), SWT.OPEN | SWT.SHEET); if (startingDirectory != null) { dialog.setFileName(startingDirectory.getPath()); } else if (filterPath != null) { dialog.setFilterPath(filterPath.getPath()); } if (extensions != null) { dialog.setFilterExtensions(extensions); } String file = dialog.open(); if (file != null) { file = file.trim(); if (file.length() > 0) { return new File(file); } } return null; }
String path = getTextControl().getText(); if (path != null) { path = path.trim(); if (!isEmptyStringAllowed()) { msg = getErrorMessage(); msg = getErrorMessage(); showErrorMessage(msg); return false; if(doCheckState()) { // OK! clearErrorMessage(); return true; msg = getErrorMessage(); // subclass might have changed it in the #doCheckState() if (msg != null) { showErrorMessage(msg);
/** * Creates a file field editor. * * @param name the name of the preference this field editor works on * @param labelText the label text of the field editor * @param enforceAbsolute <code>true</code> if the file path * must be absolute, and <code>false</code> otherwise * @param validationStrategy either {@link StringButtonFieldEditor#VALIDATE_ON_KEY_STROKE} * to perform on the fly checking, or {@link StringButtonFieldEditor#VALIDATE_ON_FOCUS_LOST} * (the default) to perform validation only after the text has been typed in * @param parent the parent of the field editor's control. * @since 3.4 * @see StringButtonFieldEditor#VALIDATE_ON_KEY_STROKE * @see StringButtonFieldEditor#VALIDATE_ON_FOCUS_LOST */ public FileFieldEditor(String name, String labelText, boolean enforceAbsolute, int validationStrategy, Composite parent) { init(name, labelText); this.enforceAbsolute = enforceAbsolute; setErrorMessage(JFaceResources .getString("FileFieldEditor.errorMessage"));//$NON-NLS-1$ setChangeButtonText(JFaceResources.getString("openBrowse"));//$NON-NLS-1$ setValidateStrategy(validationStrategy); createControl(parent); }
@Override protected String changePressed() { File f = new File(getTextControl().getText()); if (!f.exists()) { f = null; } File d = getFile(f); if (d == null) { return null; } return d.getAbsolutePath(); }