/** * Creates a directory field editor. * * @param name the name of the preference this field editor works on * @param labelText the label text of the field editor * @param parent the parent of the field editor's control */ public DirectoryFieldEditor(String name, String labelText, Composite parent) { init(name, labelText); setErrorMessage(JFaceResources .getString("DirectoryFieldEditor.errorMessage"));//$NON-NLS-1$ setChangeButtonText(JFaceResources.getString("openBrowse"));//$NON-NLS-1$ setValidateStrategy(VALIDATE_ON_FOCUS_LOST); createControl(parent); }
@Override protected boolean doCheckState() { String fileName = getTextControl().getText(); fileName = fileName.trim(); if (fileName.length() == 0 && isEmptyStringAllowed()) { return true; } File file = new File(fileName); return file.isDirectory(); }
@Override protected String changePressed() { File f = new File(getTextControl().getText()); if (!f.exists()) { f = null; } File d = getDirectory(f); if (d == null) { return null; } return d.getAbsolutePath(); }
@Override protected void createControl(Composite parent) { // setting validate strategy using the setter method is too late super.setValidateStrategy(StringFieldEditor.VALIDATE_ON_KEY_STROKE); super.createControl(parent); if (HAS_DEBUG_UI) addVariablesButton(parent); }
String errorMsg = super.getErrorMessage(); projectRoot.setPage(this); projectRoot.setFilterPath(new File(projectPath)); projectRoot.setPropertyChangeListener(this); projectRootText = projectRoot.getTextControl(composite); projectRootText.addModifyListener(this); projectRoot.setEnabled(true, composite); projectRoot.setStringValue(root);
/** * Helper that opens the directory chooser dialog. * @param startingDirectory The directory the dialog will open in. * @return File File or <code>null</code>. * */ private File getDirectory(File startingDirectory) { DirectoryDialog fileDialog = new DirectoryDialog(getShell(), SWT.OPEN | SWT.SHEET); if (startingDirectory != null) { fileDialog.setFilterPath(startingDirectory.getPath()); } else if (filterPath != null) { fileDialog.setFilterPath(filterPath.getPath()); } String dir = fileDialog.open(); if (dir != null) { dir = dir.trim(); if (dir.length() > 0) { return new File(dir); } } return null; }
/** * Helper that opens the directory chooser dialog. * @param startingDirectory The directory the dialog will open in. * @return File File or <code>null</code>. * */ private File getDirectory(File startingDirectory) { DirectoryDialog fileDialog = new DirectoryDialog(getShell(), SWT.OPEN | SWT.SHEET); if (startingDirectory != null) { fileDialog.setFilterPath(startingDirectory.getPath()); } else if (filterPath != null) { fileDialog.setFilterPath(filterPath.getPath()); } String dir = fileDialog.open(); if (dir != null) { dir = dir.trim(); if (dir.length() > 0) { return new File(dir); } } return null; }
/** * Creates a directory field editor. * * @param name the name of the preference this field editor works on * @param labelText the label text of the field editor * @param parent the parent of the field editor's control */ public DirectoryFieldEditor(String name, String labelText, Composite parent) { init(name, labelText); setErrorMessage(JFaceResources .getString("DirectoryFieldEditor.errorMessage"));//$NON-NLS-1$ setChangeButtonText(JFaceResources.getString("openBrowse"));//$NON-NLS-1$ setValidateStrategy(VALIDATE_ON_FOCUS_LOST); createControl(parent); }
@Override protected boolean doCheckState() { String fileName = getTextControl().getText(); fileName = fileName.trim(); if (fileName.length() == 0 && isEmptyStringAllowed()) { return true; } File file = new File(fileName); return file.isDirectory(); }
@Override protected String changePressed() { File f = new File(getTextControl().getText()); if (!f.exists()) { f = null; } File d = getDirectory(f); if (d == null) { return null; } return d.getAbsolutePath(); }