Java Code Examples for org.eclipse.core.resources.IWorkspaceRoot#getContainerForLocation()

The following examples show how to use org.eclipse.core.resources.IWorkspaceRoot#getContainerForLocation() . 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: WorkbenchResourceUtil.java    From typescript.java with MIT License 6 votes vote down vote up
public static IContainer findContainerFromWorkspace(IPath containerPath) {
	if (containerPath == null) {
		return null;
	}
	IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
	IContainer container = root.getContainerForLocation(containerPath);
	if (container != null && container.exists()) {
		return container;
	}
	IContainer[] containers = ResourcesPlugin.getWorkspace().getRoot().findContainersForLocation(containerPath);
	if (containers.length > 0) {
		container = containers[0];
		if (container.exists()) {
			return container;
		}
	}
	return null;
}
 
Example 2
Source File: EIPModelTreeContentProvider.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/** */
private static void findEIPModels(List<IResource> models, IPath path, IWorkspaceRoot workspaceRoot){
   IContainer container =  workspaceRoot.getContainerForLocation(path);

   try {
      IResource[] iResources = container.members();
      for (IResource iResource : iResources) {
         if ("eip".equalsIgnoreCase(iResource.getFileExtension())) {
            models.add(iResource);
         }
         if (iResource.getType() == IResource.FOLDER) {
            IPath tempPath = iResource.getLocation();
            findEIPModels(models, tempPath, workspaceRoot);
         }
      }
   } catch (CoreException e) {
      System.err.println("CoreException while browsing " + path);
   }
}
 
Example 3
Source File: RouteTreeContentProvider.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/** */
private static void findEIPModels(List<IResource> models, IPath path, IWorkspaceRoot workspaceRoot){
   IContainer container =  workspaceRoot.getContainerForLocation(path);

   try {
      IResource[] iResources = container.members();
      for (IResource iResource : iResources) {
         if ("eip".equalsIgnoreCase(iResource.getFileExtension())) {
            models.add(iResource);
         }
         if (iResource.getType() == IResource.FOLDER) {
            IPath tempPath = iResource.getLocation();
            findEIPModels(models, tempPath, workspaceRoot);
         }
      }
   } catch (CoreException e) {
      e.printStackTrace();
   }
}
 
Example 4
Source File: EIPModelTreeContentProvider.java    From eip-designer with Apache License 2.0 6 votes vote down vote up
/** */
private static void findEIPModels(List<IResource> models, IPath path, IWorkspaceRoot workspaceRoot){
   IContainer container =  workspaceRoot.getContainerForLocation(path);

   try {
      IResource[] iResources = container.members();
      for (IResource iResource : iResources) {
         if ("eip".equalsIgnoreCase(iResource.getFileExtension())) {
            models.add(iResource);
         }
         if (iResource.getType() == IResource.FOLDER) {
            IPath tempPath = iResource.getLocation();
            findEIPModels(models, tempPath, workspaceRoot);
         }
      }
   } catch (CoreException e) {
      e.printStackTrace();
   }
}
 
Example 5
Source File: File2Resource.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * get the IResource corresponding to the given file. Given file does not
 * need to exist.
 * 
 * @param file
 * @param isDirectory
 *            if true, an IContainer will be returned, otherwise an IFile
 *            will be returned
 * @return
 */
public static IResource getResource(File file, boolean isDirectory) {
	if (file == null) return null;
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot workspaceRoot = workspace.getRoot();

    IPath pathEclipse = new Path(file.getAbsolutePath());

    IResource resource = null;

    if (isDirectory) {
        resource = workspaceRoot.getContainerForLocation(pathEclipse);
    } else {
        resource = workspaceRoot.getFileForLocation(pathEclipse);
    }
    return resource;
}
 
Example 6
Source File: URIUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/** @return a {@link IContainer} for the given absolute file {@link URI} */
static public IContainer convertFileUriToPlatformContainer(org.eclipse.emf.common.util.URI fileUri) {
	if (fileUri.isFile()) {
		String fileString = fileUri.toFileString();
		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
		IPath iPath = org.eclipse.core.runtime.Path.fromOSString(fileString);
		if (iPath != null) {
			IContainer iContainer = root.getContainerForLocation(iPath);
			return iContainer;
		}
	}
	return null;
}
 
Example 7
Source File: OrganizeImportsCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public Object organizeImports(List<Object> arguments) throws CoreException {
	WorkspaceEdit edit = new WorkspaceEdit();
	if (arguments != null && !arguments.isEmpty() && arguments.get(0) instanceof String) {
		final String fileUri = (String) arguments.get(0);
		final IPath rootPath = ResourceUtils.filePathFromURI(fileUri);
		if (rootPath == null) {
			throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "URI is not found"));
		}
		final IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
		IResource resource = wsroot.getFileForLocation(rootPath);
		if (resource == null) {
			resource = wsroot.getContainerForLocation(rootPath);
		}
		if (resource != null) {
			final OrganizeImportsCommand command = new OrganizeImportsCommand();
			int type = resource.getType();
			switch (type) {
				case IResource.PROJECT:
					edit = command.organizeImportsInProject(resource.getAdapter(IProject.class));
					break;
				case IResource.FOLDER:
					edit = command.organizeImportsInDirectory(fileUri, resource.getProject());
					break;
				case IResource.FILE:
					edit = command.organizeImportsInFile(fileUri);
					break;
				default://This can only be IResource.ROOT. Which is not relevant to jdt.ls
					// do nothing allow to return the empty WorkspaceEdit.
					break;
			}
		}
	}
	return edit;
}