Java Code Examples for org.eclipse.core.resources.IContainer#getFullPath()

The following examples show how to use org.eclipse.core.resources.IContainer#getFullPath() . 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: PythonModelProvider.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This method checks if the given folder can be wrapped as a source-folder, and if that's possible, creates and returns
 * it
 * @return a created source folder or null if it couldn't be created.
 */
private PythonSourceFolder tryWrapSourceFolder(Object parent, IContainer container, Set<String> sourcePathSet) {
    IPath fullPath = container.getFullPath();
    if (sourcePathSet.contains(fullPath.toString())) {
        PythonSourceFolder sourceFolder;
        if (container instanceof IFolder) {
            sourceFolder = new PythonSourceFolder(parent, (IFolder) container);
        } else if (container instanceof IProject) {
            sourceFolder = new PythonProjectSourceFolder(parent, (IProject) container);
        } else {
            return null; //some other container we don't know how to treat!
        }
        //System.out.println("Created source folder: "+ret[i]+" - "+folder.getProject()+" - "+folder.getProjectRelativePath());
        Set<PythonSourceFolder> sourceFolders = getProjectSourceFolders(container.getProject());
        sourceFolders.add(sourceFolder);
        return sourceFolder;
    }
    return null;
}
 
Example 2
Source File: MultiModuleMoveRefactoringRequest.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public MultiModuleMoveRefactoringRequest(List<ModuleRenameRefactoringRequest> requests, IContainer target)
        throws MisconfigurationException, TargetNotInPythonpathException {
    super(requests.toArray(new RefactoringRequest[requests.size()]));
    PythonNature nature = PythonNature.getPythonNature(target);
    File file = target.getLocation().toFile();
    this.target = target;
    this.initialName = nature.resolveModule(file);
    IPath fullPath = target.getFullPath();
    if (this.initialName == null) {
        //Check if it's a source folder...
        try {
            Set<String> projectSourcePathSet = nature.getPythonPathNature().getProjectSourcePathSet(true);
            for (String string : projectSourcePathSet) {
                if (new Path(string).equals(fullPath)) {
                    this.initialName = "";
                    break;
                }
            }
        } catch (CoreException e) {
            Log.log(e);
        }
    }
    if (this.initialName == null) {
        throw new TargetNotInPythonpathException("Unable to resolve file as a python module: " + fullPath);
    }
}
 
Example 3
Source File: N4JSEclipseModel.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private boolean pathStartsWithFolder(IPath fullPath, IContainer container) {
	IPath containerPath = container.getFullPath();
	int maxSegments = containerPath.segmentCount();
	if (fullPath.segmentCount() >= maxSegments) {
		for (int j = 0; j < maxSegments; j++) {
			if (!fullPath.segment(j).equals(containerPath.segment(j))) {
				return false;
			}
		}
		return true;
	}
	return false;
}
 
Example 4
Source File: NewLibraryWizard.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected IPath getDefaultContainerPath( )
{
	IWorkbenchWindow benchWindow = PlatformUI.getWorkbench( )
			.getActiveWorkbenchWindow( );
	IWorkbenchPart part = benchWindow.getPartService( ).getActivePart( );

	Object selection = null;
	if ( part instanceof IEditorPart )
	{
		selection = ( (IEditorPart) part ).getEditorInput( );
	}
	else
	{
		ISelection sel = benchWindow.getSelectionService( ).getSelection( );
		if ( ( sel != null ) && ( sel instanceof IStructuredSelection ) )
		{
			selection = ( (IStructuredSelection) sel ).getFirstElement( );
		}
	}

	IContainer ct = getDefaultContainer( selection );

	if ( ct == null )
	{
		IEditorPart editor = UIUtil.getActiveEditor( true );

		if ( editor != null )
		{
			ct = getDefaultContainer( editor.getEditorInput( ) );
		}
	}

	if ( ct != null )
	{
		return ct.getFullPath( );
	}

	return Platform.getLocation( );
}
 
Example 5
Source File: NewReportWizard.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the path of default container
 * 
 */
IPath getDefaultContainerPath( )
{
	IWorkbenchWindow benchWindow = PlatformUI.getWorkbench( )
			.getActiveWorkbenchWindow( );
	IWorkbenchPart part = benchWindow.getPartService( ).getActivePart( );

	Object selection = null;
	if ( part instanceof IEditorPart )
	{
		selection = ( (IEditorPart) part ).getEditorInput( );
	}
	else
	{
		ISelection sel = benchWindow.getSelectionService( ).getSelection( );
		if ( ( sel != null ) && ( sel instanceof IStructuredSelection ) )
		{
			selection = ( (IStructuredSelection) sel ).getFirstElement( );
		}
	}

	IContainer ct = getDefaultContainer( selection );

	if ( ct == null )
	{
		IEditorPart editor = UIUtil.getActiveEditor( true );

		if ( editor != null )
		{
			ct = getDefaultContainer( editor.getEditorInput( ) );
		}
	}

	if ( ct != null )
	{
		return ct.getFullPath( );
	}

	return null;
}
 
Example 6
Source File: BuildPathCommand.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
public static Result removeFromSourcePath(String sourceFolderUri) {
	IPath sourceFolderPath = ResourceUtils.filePathFromURI(sourceFolderUri);
	IProject targetProject = findBelongedProject(sourceFolderPath);
	if (targetProject != null && !ProjectUtils.isGeneralJavaProject(targetProject)) {
		String message = ProjectUtils.isGradleProject(targetProject) ? UNSUPPORTED_ON_GRADLE : UNSUPPORTED_ON_MAVEN;
		return new Result(false, message);
	}

	IPath projectLocation = null;
	IContainer projectRootResource = null;
	if (targetProject == null) {
		IPath workspaceRoot = ProjectUtils.findBelongedWorkspaceRoot(sourceFolderPath);
		if (workspaceRoot == null) {
			return new Result(false, Messages.format("The folder ''{0}'' doesn''t belong to any workspace.", getWorkspacePath(sourceFolderPath).toOSString()));
		}

		String invisibleProjectName = ProjectUtils.getWorkspaceInvisibleProjectName(workspaceRoot);
		targetProject = ResourcesPlugin.getWorkspace().getRoot().getProject(invisibleProjectName);
		if (!targetProject.exists()) {
			return new Result(true, Messages.format("No need to remove it from source path, because the folder ''{0}'' isn''t on any project''s source path.", getWorkspacePath(sourceFolderPath).toOSString()));
		}

		projectLocation = workspaceRoot;
		projectRootResource = targetProject.getFolder(ProjectUtils.WORKSPACE_LINK);
	} else {
		projectLocation = targetProject.getLocation();
		projectRootResource = targetProject;
	}

	IPath relativeSourcePath = sourceFolderPath.makeRelativeTo(projectLocation);
	IPath sourcePath = relativeSourcePath.isEmpty() ? projectRootResource.getFullPath() : projectRootResource.getFolder(relativeSourcePath).getFullPath();
	IJavaProject javaProject = JavaCore.create(targetProject);
	try {
		if (ProjectUtils.removeSourcePath(sourcePath, javaProject)) {
			return new Result(true, Messages.format("Successfully removed ''{0}'' from the project {1}''s source path.", new String[] { getWorkspacePath(sourceFolderPath).toOSString(), targetProject.getName() }));
		} else {
			return new Result(true, Messages.format("No need to remove it from source path, because the folder ''{0}'' isn''t on any project''s source path.", getWorkspacePath(sourceFolderPath).toOSString()));
		}
	} catch (CoreException e) {
		return new Result(false, e.getMessage());
	}
}
 
Example 7
Source File: WorkspaceConnectionPoint.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 
 */
/* package */WorkspaceConnectionPoint(IContainer resource)
{
	super(TYPE);
	this.path = resource.getFullPath();
}
 
Example 8
Source File: WorkspaceConnectionPoint.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param resource
 *            the resource to set
 */
public void setResource(IContainer resource)
{
	this.path = resource.getFullPath();
}
 
Example 9
Source File: AddSourceFolderWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private static StatusInfo validatePathName(String str, IContainer parent) {
	StatusInfo result= new StatusInfo();
	result.setOK();

	IPath parentPath= parent.getFullPath();

	if (str.length() == 0) {
		result.setError(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_error_EnterRootName, BasicElementLabels.getPathLabel(parentPath, false)));
		return result;
	}

	IPath path= parentPath.append(str);

	IWorkspaceRoot workspaceRoot= ResourcesPlugin.getWorkspace().getRoot();
	IStatus validate= workspaceRoot.getWorkspace().validatePath(path.toString(), IResource.FOLDER);
	if (validate.matches(IStatus.ERROR)) {
		result.setError(Messages.format(NewWizardMessages.NewSourceFolderWizardPage_error_InvalidRootName, validate.getMessage()));
		return result;
	}

	IResource res= workspaceRoot.findMember(path);
	if (res != null) {
		if (res.getType() != IResource.FOLDER) {
			result.setError(NewWizardMessages.NewSourceFolderWizardPage_error_NotAFolder);
			return result;
		}
	} else {

		URI parentLocation= parent.getLocationURI();
		if (parentLocation != null) {
			try {
				IFileStore store= EFS.getStore(parentLocation).getChild(str);
				if (store.fetchInfo().exists()) {
					result.setError(NewWizardMessages.NewSourceFolderWizardPage_error_AlreadyExistingDifferentCase);
					return result;
				}
			} catch (CoreException e) {
				// we couldn't create the file store. Ignore the exception
				// since we can't check if the file exist. Pretend that it
				// doesn't.
			}
		}
	}

	return result;
}
 
Example 10
Source File: IndexBinaryFolder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public IndexBinaryFolder(IContainer folder, IndexManager manager) {
	super(folder.getFullPath(), manager);
	this.folder = folder;
}