Java Code Examples for org.eclipse.core.resources.IWorkspace#validateName()
The following examples show how to use
org.eclipse.core.resources.IWorkspace#validateName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExportToTranslationDictionaryDialog.java From ermasterr with Apache License 2.0 | 6 votes |
@Override protected String getErrorMessage() { if (isBlank(dictionaryNameText)) { return "error.translation.dictionary.name.empty"; } final String fileName = dictionaryNameText.getText().trim(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IStatus result = workspace.validateName(fileName, IResource.FILE); if (!result.isOK()) { return result.getMessage(); } final File file = new File(PreferenceInitializer.getTranslationPath(fileName)); if (file.exists()) { return "error.translation.dictionary.name.duplicated"; } return null; }
Example 2
Source File: NewFolderDialog.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private void validateNewFolderName() { String name = fFolderName.getText(); IWorkspace workspace = fParentFolder.getWorkspace(); IStatus nameStatus = workspace.validateName(name, IResource.FOLDER); if ("".equals(name)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } if (fParentFolder.findMember(name) != null) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 3
Source File: NewExperimentDialog.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private void validateNewExperimentName() { String name = fExperimentName.getText(); IWorkspace workspace = fExperimentFolder.getWorkspace(); IStatus nameStatus = workspace.validateName(name, IResource.FOLDER); if ("".equals(name)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IPath path = new Path(name); if (fExperimentFolder.getFolder(path).exists() || fExperimentFolder.getFile(path).exists()) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 4
Source File: RenameExperimentDialog.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private void validateNewExperimentName() { String name = fNewExperimentName.getText(); IWorkspace workspace = fExperimentFolder.getWorkspace(); IStatus nameStatus = workspace.validateName(name, IResource.FOLDER); if ("".equals(name)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IPath path = new Path(name); if (fExperimentFolder.getFolder(path).exists() || fExperimentFolder.getFile(path).exists()) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 5
Source File: CopyTraceDialog.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private void validateNewTraceName() { String name = fNewTraceName.getText(); IWorkspace workspace = fTraceFolder.getWorkspace(); IStatus nameStatus = workspace.validateName(name, IResource.FOLDER); if ("".equals(name)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IPath path = new Path(name); if (fTraceFolder.getFolder(path).exists() || fTraceFolder.getFile(path).exists()) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 6
Source File: RenameFolderDialog.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private void validateNewFolderName() { String newFolderName = fNewFolderNameText.getText(); IWorkspace workspace = fFolder.getResource().getWorkspace(); IStatus nameStatus = workspace.validateName(newFolderName, IResource.FOLDER); if ("".equals(newFolderName)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IContainer parentFolder = fFolder.getResource().getParent(); if (parentFolder.findMember(newFolderName) != null) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 7
Source File: RenameTraceDialog.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private void validateNewTraceName() { String newTraceName = fNewTraceNameText.getText(); IWorkspace workspace = fTrace.getResource().getWorkspace(); IStatus nameStatus = workspace.validateName(newTraceName, IResource.FOLDER); if ("".equals(newTraceName)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IContainer parentFolder = fTrace.getResource().getParent(); if (parentFolder.findMember(newTraceName) != null) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 8
Source File: MainProjectWizardPage.java From sarl with Apache License 2.0 | 6 votes |
/** Check the project name. * * @param workspace the workspace. * @param name name of the project. * @throws ValidationException if the name is invalid. */ private void checkProjectName(IWorkspace workspace, String name) throws ValidationException { // check whether the project name field is empty if (name.length() == 0) { throw new ValidationException( NewWizardMessages.NewJavaProjectWizardPageOne_Message_enterProjectName, null); } // check whether the project name is valid final IStatus nameStatus = workspace.validateName(name, IResource.PROJECT); if (!nameStatus.isOK()) { throw new ValidationException( null, nameStatus.getMessage()); } }
Example 9
Source File: RenameResourceAction.java From gama with GNU General Public License v3.0 | 6 votes |
/** * Return the new name to be given to the target resource. * * @return java.lang.String * @param resource * the resource to query status on */ protected String queryNewResourceName(final IResource resource) { final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace(); final IPath prefix = resource.getFullPath().removeLastSegments(1); final IInputValidator validator = string -> { if (resource.getName().equals(string)) { return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent; } final IStatus status = workspace.validateName(string, resource.getType()); if (!status.isOK()) { return status.getMessage(); } if (workspace.getRoot().exists(prefix.append(string))) { return IDEWorkbenchMessages.RenameResourceAction_nameExists; } return null; }; final InputDialog dialog = new InputDialog(WorkbenchHelper.getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle, IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator); dialog.setBlockOnOpen(true); final int result = dialog.open(); if (result == Window.OK) { return dialog.getValue(); } return null; }
Example 10
Source File: ExportToTranslationDictionaryDialog.java From ermaster-b with Apache License 2.0 | 6 votes |
@Override protected String getErrorMessage() { if (isBlank(this.dictionaryNameText)) { return "error.translation.dictionary.name.empty"; } String fileName = this.dictionaryNameText.getText().trim(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IStatus result = workspace.validateName(fileName, IResource.FILE); if (!result.isOK()) { return result.getMessage(); } File file = new File(PreferenceInitializer.getTranslationPath(fileName)); if (file.exists()) { return "error.translation.dictionary.name.duplicated"; } return null; }
Example 11
Source File: JavaBuildConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IStatus validateResourceFilters() { String text= getValue(PREF_RESOURCE_FILTER); IWorkspace workspace= ResourcesPlugin.getWorkspace(); String[] filters= getTokens(text, ","); //$NON-NLS-1$ for (int i= 0; i < filters.length; i++) { String fileName= filters[i].replace('*', 'x'); int resourceType= IResource.FILE; int lastCharacter= fileName.length() - 1; if (lastCharacter >= 0 && fileName.charAt(lastCharacter) == '/') { fileName= fileName.substring(0, lastCharacter); resourceType= IResource.FOLDER; } IStatus status= workspace.validateName(fileName, resourceType); if (status.matches(IStatus.ERROR)) { String message= Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_filter_invalidsegment_error, status.getMessage()); return new StatusInfo(IStatus.ERROR, message); } } return new StatusInfo(); }
Example 12
Source File: RenameResourceAndCloseEditorAction.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * Return the new name to be given to the target resource. * * @return java.lang.String * @param resource * the resource to query status on */ protected String queryNewResourceName(final IResource resource) { final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace(); final IPath prefix = resource.getFullPath().removeLastSegments(1); IInputValidator validator = new IInputValidator() { public String isValid(String string) { if (resource.getName().equals(string)) { return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent; } IStatus status = workspace.validateName(string, resource .getType()); if (!status.isOK()) { return status.getMessage(); } if (workspace.getRoot().exists(prefix.append(string))) { return IDEWorkbenchMessages.RenameResourceAction_nameExists; } return null; } }; InputDialog dialog = new InputDialog(shellProvider.getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle, IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator); dialog.setBlockOnOpen(true); int result = dialog.open(); if (result == Window.OK) return dialog.getValue(); return null; }
Example 13
Source File: CopyExperimentDialog.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private void validateNewExperimentName() { String name = fNewExperimentName.getText(); IWorkspace workspace = fExperimentFolder.getWorkspace(); IStatus nameStatus = workspace.validateName(name, IResource.FOLDER); if ("".equals(name)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IPath path = new Path(name); if (fExperimentFolder.getFolder(path).exists() || fExperimentFolder.getFile(path).exists()) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } Status deepCopyStatus = validateDeepCopyDestination(); if (deepCopyStatus.getSeverity() != IStatus.OK) { updateStatus(deepCopyStatus); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 14
Source File: PyRenameResourceAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Return the new name to be given to the target resource. * * @return java.lang.String * @param resource the resource to query status on * * Fix from platform: was not checking return from dialog.open */ @Override protected String queryNewResourceName(final IResource resource) { final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace(); final IPath prefix = resource.getFullPath().removeLastSegments(1); IInputValidator validator = new IInputValidator() { @Override public String isValid(String string) { if (resource.getName().equals(string)) { return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent; } IStatus status = workspace.validateName(string, resource.getType()); if (!status.isOK()) { return status.getMessage(); } if (workspace.getRoot().exists(prefix.append(string))) { return IDEWorkbenchMessages.RenameResourceAction_nameExists; } return null; } }; InputDialog dialog = new InputDialog(shell, IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle, IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator); dialog.setBlockOnOpen(true); if (dialog.open() == Window.OK) { return dialog.getValue(); } else { return null; } }
Example 15
Source File: SARLAgentMainLaunchConfigurationTab.java From sarl with Apache License 2.0 | 5 votes |
/** Replies if the project name is valid. * * <p>Copied from JDT. * * @return the validity state. */ protected boolean isValidProjectName() { final String name = this.fProjText.getText(); if (Strings.isNullOrEmpty(name)) { setErrorMessage(Messages.MainLaunchConfigurationTab_3); return false; } final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IStatus status = workspace.validateName(name, IResource.PROJECT); if (status.isOK()) { final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (!project.exists()) { setErrorMessage(MessageFormat.format( Messages.MainLaunchConfigurationTab_4, name)); return false; } if (!project.isOpen()) { setErrorMessage(MessageFormat.format( Messages.MainLaunchConfigurationTab_5, name)); return false; } } else { setErrorMessage(MessageFormat.format( Messages.MainLaunchConfigurationTab_6, status.getMessage())); return false; } return true; }
Example 16
Source File: NewProjectWizardProjInfoPage.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
public void update() { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); String projectName = getProjectName(); String result = ValidationUtils.validateProjectName(projectName); if (result != null) { setErrorMessage(result); setPageComplete(false); return; } // check whether the project name is valid final IStatus nameStatus = workspace.validateName(projectName, IResource.PROJECT); if (!nameStatus.isOK()) { setErrorMessage(nameStatus.getMessage()); setPageComplete(false); return; } // 修改,上一步验证是验证在当前操作系统下的字符,但打包出来的项目名有可能在其他操作系统不支持。故再验证一次 robert 2013-04-25 char[] errorChars = new char[]{'/', '\\', ':', '?', '"', '<', '>', '|'}; if (Platform.getOS().indexOf("win") == -1) { for (int i = 0; i < errorChars.length; i++){ if (projectName.indexOf(errorChars[i]) != -1) { setErrorMessage(MessageFormat.format(Messages.getString("NewProjectWizardProjInfoPage.valid.waring"), new Object[]{errorChars[i], projectName})); setPageComplete(false); return; } } } final IProject project = getProject(); if (project.exists()) { setErrorMessage(Messages.getString("wizard.NewProjectWizardProjInfoPage.msg1")); setPageComplete(false); return; } final IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(projectName); if (projectLocation.toFile().exists()) { setErrorMessage(Messages.getString("wizard.NewProjectWizardProjInfoPage.msg2")); setPageComplete(false); return; } if (lstText != null && lstText.size() > 0) { for (Text txt : lstText) { String value = txt.getText(); if (value != null && !value.equals("")) { if (value.trim().equals("")) { setErrorMessage(Messages.getString("wizard.NewProjectWizardProjInfoPage.msg3")); setPageComplete(false); return; } else if (value.trim().length() > 50) { setErrorMessage(Messages.getString("wizard.NewProjectWizardProjInfoPage.msg4")); setPageComplete(false); return; } } } } setPageComplete(true); setErrorMessage(null); setMessage(null); }
Example 17
Source File: NewProjectWizardProjInfoPage.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
public void update() { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); String projectName = getProjectName(); String result = ValidationUtils.validateProjectName(projectName); if (result != null) { setErrorMessage(result); setPageComplete(false); return; } // check whether the project name is valid final IStatus nameStatus = workspace.validateName(projectName, IResource.PROJECT); if (!nameStatus.isOK()) { setErrorMessage(nameStatus.getMessage()); setPageComplete(false); return; } // 修改,上一步验证是验证在当前操作系统下的字符,但打包出来的项目名有可能在其他操作系统不支持。故再验证一次 robert 2013-04-25 String validResult = CommonFunction.validResourceName(projectName); if (validResult != null) { setErrorMessage(validResult); setPageComplete(false); return; } final IProject project = getProject(); if (project.exists()) { setErrorMessage(Messages.getString("wizard.NewProjectWizardProjInfoPage.msg1")); setPageComplete(false); return; } final IPath projectLocation = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(projectName); if (projectLocation.toFile().exists()) { setErrorMessage(Messages.getString("wizard.NewProjectWizardProjInfoPage.msg2")); setPageComplete(false); return; } if (lstText != null && lstText.size() > 0) { for (Text txt : lstText) { String value = txt.getText(); if (value != null && !value.equals("")) { if (value.trim().equals("")) { setErrorMessage(Messages.getString("wizard.NewProjectWizardProjInfoPage.msg3")); setPageComplete(false); return; } else if (value.trim().length() > 50) { setErrorMessage(Messages.getString("wizard.NewProjectWizardProjInfoPage.msg4")); setPageComplete(false); return; } } } } setPageComplete(true); setErrorMessage(null); setMessage(null); }
Example 18
Source File: RenameResourceAndCloseEditorAction.java From tmxeditor8 with GNU General Public License v2.0 | 4 votes |
/** * Save the changes and dispose of the text widget. * * @param resource - * the resource to move. */ private void saveChangesAndDispose(IResource resource) { if (saving == true) { return; } saving = true; // Cache the resource to avoid selection loss since a selection of // another item can trigger this method inlinedResource = resource; final String newName = textEditor.getText(); // Run this in an async to make sure that the operation that triggered // this action is completed. Otherwise this leads to problems when the // icon of the item being renamed is clicked (i.e., which causes the // rename // text widget to lose focus and trigger this method). Runnable query = new Runnable() { public void run() { try { if (!newName.equals(inlinedResource.getName())) { IWorkspace workspace = IDEWorkbenchPlugin .getPluginWorkspace(); IStatus status = workspace.validateName(newName, inlinedResource.getType()); if (!status.isOK()) { displayError(status.getMessage()); } else { IPath newPath = inlinedResource.getFullPath() .removeLastSegments(1).append(newName); runWithNewPath(newPath, inlinedResource); } } inlinedResource = null; // Dispose the text widget regardless disposeTextWidget(); // Ensure the Navigator tree has focus, which it may not if // the // text widget previously had focus. if (navigatorTree != null && !navigatorTree.isDisposed()) { navigatorTree.setFocus(); } } finally { saving = false; } } }; getTree().getShell().getDisplay().asyncExec(query); }
Example 19
Source File: RenameResourceAndCloseEditorAction.java From translationstudio8 with GNU General Public License v2.0 | 4 votes |
/** * Save the changes and dispose of the text widget. * * @param resource - * the resource to move. */ private void saveChangesAndDispose(IResource resource) { if (saving == true) { return; } saving = true; // Cache the resource to avoid selection loss since a selection of // another item can trigger this method inlinedResource = resource; final String newName = textEditor.getText(); // Run this in an async to make sure that the operation that triggered // this action is completed. Otherwise this leads to problems when the // icon of the item being renamed is clicked (i.e., which causes the // rename // text widget to lose focus and trigger this method). Runnable query = new Runnable() { public void run() { try { if (!newName.equals(inlinedResource.getName())) { IWorkspace workspace = IDEWorkbenchPlugin .getPluginWorkspace(); IStatus status = workspace.validateName(newName, inlinedResource.getType()); if (!status.isOK()) { displayError(status.getMessage()); } else { // 验证资源名称是否合法 robert 2013-07-01 String validResult = CommonFunction.validResourceName(newName); if (validResult != null) { displayError(validResult); }else { IPath newPath = inlinedResource.getFullPath() .removeLastSegments(1).append(newName); runWithNewPath(newPath, inlinedResource); } } } inlinedResource = null; // Dispose the text widget regardless disposeTextWidget(); // Ensure the Navigator tree has focus, which it may not if // the // text widget previously had focus. if (navigatorTree != null && !navigatorTree.isDisposed()) { navigatorTree.setFocus(); } } finally { saving = false; } } }; getTree().getShell().getDisplay().asyncExec(query); }
Example 20
Source File: NewFolderDialogOfHs.java From translationstudio8 with GNU General Public License v2.0 | votes |
/** * Checks if the folder name is valid. * * @return null if the new folder name is valid. * a message that indicates the problem otherwise. */ @SuppressWarnings("restriction") private boolean validateFolderName() { String name = folderNameField.getText(); IWorkspace workspace = container.getWorkspace(); IStatus nameStatus = workspace.validateName(name, IResource.FOLDER); if ("".equals(name)) { //$NON-NLS-1$ updateStatus(IStatus.ERROR, IDEWorkbenchMessages.NewFolderDialog_folderNameEmpty); return false; } if (nameStatus.isOK() == false) { updateStatus(nameStatus); return false; } // 修改创建文件夹时,所进行的文件名特殊字符验证 --robert 2013-07-01 String result = null; if ((result = CommonFunction.validResourceName(name)) != null) { updateStatus(new ResourceStatus(IResourceStatus.INVALID_VALUE, null, result)); return false; } IPath path = new Path(name); if (container.getFolder(path).exists() || container.getFile(path).exists()) { updateStatus(IStatus.ERROR, NLS.bind( IDEWorkbenchMessages.NewFolderDialog_alreadyExists, name)); return false; } updateStatus(IStatus.OK, ""); //$NON-NLS-1$ return true; }