本文整理匯總了Java中org.eclipse.core.runtime.Path.fromOSString方法的典型用法代碼示例。如果您正苦於以下問題:Java Path.fromOSString方法的具體用法?Java Path.fromOSString怎麽用?Java Path.fromOSString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.core.runtime.Path
的用法示例。
在下文中一共展示了Path.fromOSString方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: editFile
import org.eclipse.core.runtime.Path; //導入方法依賴的package包/類
public static IEditorPart editFile(File file, boolean preferIdeEditor) throws IOException, PartInitException {
if (file == null || !file.exists() || !file.isFile() || !file.canRead()) {
throw new IOException("Invalid file: '" + file + "'");
}
IWorkbench workBench = PlatformUI.getWorkbench();
IWorkbenchPage page = workBench.getActiveWorkbenchWindow().getActivePage();
IPath location = Path.fromOSString(file.getAbsolutePath());
IFileStore fileStore = EFS.getLocalFileSystem().getStore(location);
FileStoreEditorInput fileStoreEditorInput = new FileStoreEditorInput(fileStore);
String editorId = IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID;
if (preferIdeEditor) {
IEditorDescriptor editorDescriptor = workBench.getEditorRegistry().getDefaultEditor(file.getName());
if (editorDescriptor != null) {
editorId = editorDescriptor.getId();
}
}
return page.openEditor(fileStoreEditorInput, editorId);
}
示例2: openEditor
import org.eclipse.core.runtime.Path; //導入方法依賴的package包/類
protected final IEditorPart openEditor(String filePath) throws PartInitException {
IPath location = Path.fromOSString(filePath);
IFileStore fileStore = EFS.getLocalFileSystem().getStore(location);
FileStoreEditorInput fileStoreEditorInput = new FileStoreEditorInput(fileStore);
String editorId = IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID;
IEditorDescriptor editorDescriptor = getWorkbench().getEditorRegistry().getDefaultEditor(filePath);
if (editorDescriptor != null) {
editorId = editorDescriptor.getId();
}
return openEditor(fileStoreEditorInput, editorId);
}
示例3: toIFile
import org.eclipse.core.runtime.Path; //導入方法依賴的package包/類
/**
* Return the passed parameters (a file) as an IFile
*
* @param file
* @return
*/
public static IFile toIFile(File file) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath location = Path.fromOSString(file.getAbsolutePath());
IFile ifile = workspace.getRoot().getFileForLocation(location);
return ifile;
}
示例4: toIFolder
import org.eclipse.core.runtime.Path; //導入方法依賴的package包/類
/**
* Return the passed parameters (a file) as an IFolder
*
* @param file
* @return
*/
public static IFolder toIFolder(File file) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPath location = Path.fromOSString(file.getAbsolutePath());
IFile ifile = workspace.getRoot().getFileForLocation(location);
return workspace.getRoot().getFolder(ifile.getFullPath());
}
示例5: getIResourceFromURL
import org.eclipse.core.runtime.Path; //導入方法依賴的package包/類
static public IResource getIResourceFromURL(URL url){
IWorkspace workspace= ResourcesPlugin.getWorkspace();
IResource ifile = (IResource) workspace.getRoot().findMember(FileHelpers.URLToStringWithoutFile(url));
if(ifile == null && url.getProtocol().equals("file")){
// try another method
try {
File file = new File(url.toURI());
IPath location= Path.fromOSString(file.getAbsolutePath());
ifile = workspace.getRoot().getFileForLocation(location);
} catch (URISyntaxException e) {
}
}
return ifile;
}
示例6: queryOverwrite
import org.eclipse.core.runtime.Path; //導入方法依賴的package包/類
/**
* The default implementation of this <code>IOverwriteQuery</code> method asks the user whether the existing
* resource at the given path should be overwritten.
*
* @param pathString
* the path of the archive
* @return the user's reply: one of <code>"YES"</code>, <code>"NO"</code>, <code>"ALL"</code>, or
* <code>"CANCEL"</code>
*/
@Override
public String queryOverwrite(String pathString) {
IPath path = Path.fromOSString(pathString);
String messageString;
// Break the message up if there is a file name and a directory
// and there are at least 2 segments.
if (path.getFileExtension() == null || path.segmentCount() < 2) {
messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_existsQuestion, pathString);
} else {
messageString = NLS.bind(IDEWorkbenchMessages.WizardDataTransfer_overwriteNameAndPathQuestion,
path.lastSegment(),
path.removeLastSegments(1).toOSString());
}
final MessageDialog dialog = new MessageDialog(getContainer()
.getShell(), IDEWorkbenchMessages.Question,
null, messageString, MessageDialog.QUESTION, new String[] {
IDialogConstants.YES_LABEL,
IDialogConstants.YES_TO_ALL_LABEL,
IDialogConstants.NO_LABEL,
IDialogConstants.NO_TO_ALL_LABEL,
IDialogConstants.CANCEL_LABEL }, 0) {
@Override
protected int getShellStyle() {
return super.getShellStyle() | SWT.SHEET;
}
};
String[] response = new String[] { YES, ALL, NO, NO_ALL, CANCEL };
// run in syncExec because callback is from an operation,
// which is probably not running in the UI thread.
getControl().getDisplay().syncExec(new Runnable() {
@Override
public void run() {
dialog.open();
}
});
return dialog.getReturnCode() < 0 ? CANCEL : response[dialog.getReturnCode()];
}
示例7: validate
import org.eclipse.core.runtime.Path; //導入方法依賴的package包/類
private void validate() {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
// check whether the project name is empty
String projectName = projectData.projectName;
if (projectName == null || projectName.trim().isEmpty()) {
setErrorMessage("Project name must not be empty");
setPageComplete(false);
return;
}
// check whether the project name is valid
final IStatus projectNameStatus = workspace.validateName(projectName, IResource.PROJECT);
if (!projectNameStatus.isOK()) {
setErrorMessage(projectNameStatus.getMessage());
setPageComplete(false);
return;
}
// check whether the project with the name already exists
IProject handle = workspace.getRoot().getProject(projectData.projectName);
if (handle.exists()) {
setErrorMessage("A project with name '" + projectData.projectName + "' already exists in the workspace");
setPageComplete(false);
return;
}
// check whether the location is empty
String location = projectData.projectLocation;
if (location == null || location.isEmpty()) {
setErrorMessage("Enter a location for the project.");
setPageComplete(false);
return;
}
// check whether the location is a syntactically correct path
if (!Path.EMPTY.isValidPath(location)) {
setErrorMessage("Invalid project contents directory");
setPageComplete(false);
return;
}
IPath projectPath = null;
if (!useDefaultsButton.getSelection()) {
projectPath = Path.fromOSString(location);
if (!projectPath.toFile().exists()) {
if (!canCreate(projectPath.toFile())) {
setErrorMessage("Cannot create project content at the given external location.");
setPageComplete(false);
return;
}
}
}
// check whether the location is valid
final IStatus locationStatus = workspace.validateProjectLocation(handle, projectPath);
if (!locationStatus.isOK()) {
setErrorMessage(locationStatus.getMessage());
setPageComplete(false);
return;
}
setErrorMessage(null);
setPageComplete(true);
}
示例8: toIResource
import org.eclipse.core.runtime.Path; //導入方法依賴的package包/類
/**
* Returns the equivalent {@linkplain org.eclipse.core.resources.IResource
* Eclipse IResource} for an {@linkplain org.eclipse.emf.common.util.URI Ecore
* URI}, if available.
*
* <p>
* {@code uri} can be represented as IResource if {@code uri} is an
* {@linkplain URI#isPlatformResource() platform resource} (i.e. {@code uri}
* starts with {@code platform:/resource/}). Otherwise, this method returns
* {@code null}.
* </p>
*
* <p>
* This method ignores any {@linkplain URI#fragment() fragment} or
* {@linkplain URI#query() query} of {@code uri}.
* </p>
*
* <p>
* If the resulting IResource exists, this method returns the existing kind of
* IResource ({@linkplain org.eclipse.core.resources.IWorkspaceRoot
* IWorkspaceRoot}, {@linkplain org.eclipse.core.resources.IProject IProject},
* {@linkplain org.eclipse.core.resources.IFolder IFolder}, or
* {@linkplain org.eclipse.core.resources.IFile IFile}).
* </p>
*
* <p>
* If the resulting IResource does not exist, this method returns an IFile
* pointing to the place equivalent to {@code uri}.
* </p>
*
* <p>
* This method handles excess slashes (behind the platform resource identifiers)
* gracefully (i.e. ignores the slashes).<br/>
* Example: An URI of
* {@code platform:/resource/////MyProject///folder///deep/myFile.ext//} leads
* to an IFile for path {@code /MyProject/folder/deep/myFile.ext}.
* </p>
*
* <p>
* <b>Note:</b> This method treats {@code uri} as case-sensitive (on <i>all</i>
* platforms, including Windows). Therefore, if the workspace contained a file
* at {@code /MyProject/myFolder/myFile.ext} and we passed the URI
* {@code platform:/resource/MyProject/myFolder/mYfILE.ext} to this method, the
* result is an IFile for path {@code /MyProject/myFolder/mYfILE.ext}.
* {@link IResource#exists() result.exists()} will return {@code false}.
* </p>
*
* @param uri
* The Ecore URI to return as Eclipse IResource.
* @return {@code uri} as Eclipse IResource, if available; {@code null}
* otherwise.
*
* @throws IllegalArgumentException
* If {@code uri} is seriously ill-formatted.
*
* @since 0.1
*/
public static @Nullable IResource toIResource(final @NonNull URI uri) {
if (uri.isPlatformResource()) {
String platformString = uri.toPlatformString(true);
IPath path = Path.fromOSString(platformString);
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
if (workspaceRoot.exists(path)) {
return workspaceRoot.findMember(path);
} else {
return workspaceRoot.getFile(path);
}
}
return null;
}