diff options
author | Tobias Schwarz | 2013-09-25 06:44:51 +0000 |
---|---|---|
committer | Tobias Schwarz | 2013-09-25 06:45:47 +0000 |
commit | a6ec528c9de091f555ed1a96ac3cfd10e0009a8a (patch) | |
tree | 0817d49898c027ba2dbaefa1a612811abc6df197 /target_explorer/plugins | |
parent | 6946bedfe24ad0fbc8a67ec59c88861cce3b0913 (diff) | |
download | org.eclipse.tcf-a6ec528c9de091f555ed1a96ac3cfd10e0009a8a.tar.gz org.eclipse.tcf-a6ec528c9de091f555ed1a96ac3cfd10e0009a8a.tar.xz org.eclipse.tcf-a6ec528c9de091f555ed1a96ac3cfd10e0009a8a.zip |
Target Explorer: add check for relativ to workspace
Diffstat (limited to 'target_explorer/plugins')
3 files changed, 26 insertions, 3 deletions
diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java index 100ae4c27..f25b96817 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.java @@ -112,6 +112,7 @@ public class Messages extends NLS { public static String FileNameValidator_Error_IsRelativ; public static String FileNameValidator_Error_IsAbsolut; public static String FileNameValidator_Error_HasSpaces; + public static String FileNameValidator_Error_NotRelativToWorkspace; public static String DirectoryNameValidator_Information_MissingName; public static String DirectoryNameValidator_Error_IsFile; diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.properties b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.properties index 39a45983e..aa40a57f5 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.properties +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/nls/Messages.properties @@ -53,6 +53,7 @@ FileNameValidator_Error_NoAccess=The file you entered cannot be accessed. FileNameValidator_Error_IsRelativ=The file path you entered cannot be relative. FileNameValidator_Error_IsAbsolut=The file path you entered cannot be absolute. FileNameValidator_Error_HasSpaces=The file path you entered contains spaces. +FileNameValidator_Error_NotRelativToWorkspace=The file path you entered can only be relativ to the workspace. DirectoryNameValidator_Information_MissingName=Please enter a directory name. DirectoryNameValidator_Error_IsFile=The name you entered is an existing file. diff --git a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/FileNameValidator.java b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/FileNameValidator.java index 38508de9a..dfa1849a8 100644 --- a/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/FileNameValidator.java +++ b/target_explorer/plugins/org.eclipse.tcf.te.ui.controls/src/org/eclipse/tcf/te/ui/controls/validator/FileNameValidator.java @@ -14,6 +14,10 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; + /** * Input validator for files. @@ -31,6 +35,7 @@ public class FileNameValidator extends Validator { public static final String ERROR_NO_ACCESS = "FileNameValidator_Error_NoAccess"; //$NON-NLS-1$ public static final String ERROR_IS_RELATIV = "FileNameValidator_Error_IsRelativ"; //$NON-NLS-1$ public static final String ERROR_IS_ABSOLUT = "FileNameValidator_Error_IsAbsolut"; //$NON-NLS-1$ + public static final String ERROR_NOT_RELATIV_TO_WS = "FileNameValidator_Error_NotRelativToWorkspace"; //$NON-NLS-1$ public static final String ERROR_HAS_SPACES = "FileNameValidator_Error_HasSpaces"; //$NON-NLS-1$ // arguments @@ -43,7 +48,8 @@ public class FileNameValidator extends Validator { public static final int ATTR_ABSOLUT = 16; public static final int ATTR_RELATIV = 32; public static final int ATTR_NO_SPACES = 64; - // next attribute should start with 2^7 + public static final int ATTR_RELATIV_TO_WS = 128; + // next attribute should start with 2^8 // value attributes private boolean isFile; @@ -121,9 +127,19 @@ public class FileNameValidator extends Validator { newFile = newFile.trim(); File file = new File(newFile); + + absolute = file.isAbsolute(); + boolean relativToWs = false; + if (!absolute) { + IPath workSpacePath = ResourcesPlugin.getWorkspace().getRoot().getLocation(); + File absFile = workSpacePath.append(new Path(file.toString())).toFile(); + relativToWs = absFile.exists(); + if (relativToWs) { + file = absFile; + } + } exists = file.exists(); isFile = file.isFile() || !exists; - absolute = file.isAbsolute(); // To determine canRead and canWrite, we have to find the first existing parent directory File parentFile = file.getParentFile(); @@ -147,12 +163,17 @@ public class FileNameValidator extends Validator { setMessage(getMessageText(ERROR_HAS_SPACES), getMessageTextType(ERROR_HAS_SPACES, ERROR)); } // Third: all the rest - else if (isAttribute(ATTR_ABSOLUT) && !isAttribute(ATTR_RELATIV) && !absolute) { + + + else if (isAttribute(ATTR_ABSOLUT) && !isAttribute(ATTR_RELATIV) && !isAttribute(ATTR_RELATIV_TO_WS) && !absolute) { setMessage(getMessageText(ERROR_IS_RELATIV), getMessageTextType(ERROR_IS_RELATIV, ERROR)); } else if (isAttribute(ATTR_RELATIV) && !isAttribute(ATTR_ABSOLUT) && absolute) { setMessage(getMessageText(ERROR_IS_ABSOLUT), getMessageTextType(ERROR_IS_ABSOLUT, ERROR)); } + else if (isAttribute(ATTR_RELATIV_TO_WS) && !absolute && !relativToWs) { + setMessage(getMessageText(ERROR_NOT_RELATIV_TO_WS), getMessageTextType(ERROR_NOT_RELATIV_TO_WS, ERROR)); + } else if (exists && !isFile) { setMessage(getMessageText(ERROR_IS_DIRECTORY), getMessageTextType(ERROR_IS_DIRECTORY, ERROR)); } |