Java Code Examples for org.eclipse.core.resources.IFolder#getParent()

The following examples show how to use org.eclipse.core.resources.IFolder#getParent() . 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: BuildscriptGenerator.java    From cmake4eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Recursively creates the folder hierarchy needed for the build output, if
 * necessary. If the folder is created, its derived bit is set to true so the
 * CM system ignores the contents. If the resource exists, respect the
 * existing derived setting.
 *
 * @param folder
 *        a folder, somewhere below the project root
 */
private void createFolder(IFolder folder) throws CoreException {
  if (!folder.exists()) {
    // Make sure that parent folders exist
    IContainer parent = folder.getParent();
    if (parent instanceof IFolder && !parent.exists()) {
      createFolder((IFolder) parent);
    }

    // Now make the requested folder
    try {
      folder.create(IResource.DERIVED, true, monitor);
    } catch (CoreException e) {
      if (e.getStatus().getCode() == IResourceStatus.PATH_OCCUPIED)
        folder.refreshLocal(IResource.DEPTH_ZERO, monitor);
      else
        throw e;
    }
  }
}
 
Example 2
Source File: NavigatorPackageViewerFilter.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	try {
		if (element instanceof IFolder) {
			IFolder folder = (IFolder) element;
			IProject project = folder.getProject();
			
			if (folder.getParent() instanceof IProject && project.hasNature(GoNature.NATURE_ID)) {
				return !(folder.getName().equals("bin") || folder.getName().equals("pkg"));
			}
		}
	} catch (CoreException e) {
		
	}
	
	return true;
}
 
Example 3
Source File: PackagesViewHierarchicalContentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Object getHierarchicalParent(IPackageFragment fragment) {
	IJavaElement parent= fragment.getParent();

	if ((parent instanceof IPackageFragmentRoot) && parent.exists()) {
		IPackageFragmentRoot root= (IPackageFragmentRoot) parent;
		if (root.isArchive() || root.isExternal() || !fragment.exists()) {
			return findNextLevelParentByElementName(fragment);
		} else {
			IResource resource= fragment.getResource();
			if ((resource != null) && (resource instanceof IFolder)) {
				IFolder folder= (IFolder) resource;
				IResource res= folder.getParent();

				IJavaElement el= JavaCore.create(res);
				if (el != null) {
					return el;
				} else {
					return res;
				}
			}
		}
	}
	return parent;
}
 
Example 4
Source File: CoreUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static void createDerivedFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
	if (!folder.exists()) {
		IContainer parent= folder.getParent();
		if (parent instanceof IFolder) {
			createDerivedFolder((IFolder)parent, force, local, null);
		}
		folder.create(force ? (IResource.FORCE | IResource.DERIVED) : IResource.DERIVED, local, monitor);
	}
}
 
Example 5
Source File: ResourceUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) 
		throws CoreException {
	if (folder.exists()) {
		return;
	}
	
	IContainer parent = folder.getParent();
	if (parent instanceof IFolder) {
		createFolder((IFolder) parent, force, local, monitor);
	}
	folder.create(force, local, monitor);
}
 
Example 6
Source File: PluginsFolderContentFilter.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if(!(element instanceof IFolder) )
		return true;
	IFolder folder = (IFolder) element;
	IContainer parent = folder.getParent();
	if(parent.getName().equals(PlatformConstants.DIR_PLUGINS) && parent.getProjectRelativePath().segmentCount() == 1){
		return false;
	}
	return true;
}
 
Example 7
Source File: HybridProjectCreator.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
private void createFolder(IFolder folder, IProgressMonitor monitor) throws CoreException {
    IContainer parent = folder.getParent();
    IFolder parentFolder = (IFolder)parent.getAdapter(IFolder.class);
    if ( parentFolder != null ) {
        createFolder(parentFolder, monitor);
    }
    if ( !folder.exists() ) {
        folder.create(false, true, monitor);
    }
}
 
Example 8
Source File: PlatformsFolderContentFilter.java    From thym with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
	if(!(element instanceof IFolder) )
		return true;
	IFolder folder = (IFolder) element;
	IContainer parent = folder.getParent();
	if(parent.getName().equals(PlatformConstants.DIR_PLATFORMS) && parent.getProjectRelativePath().segmentCount() == 1){
		return false;
	}
	return true;
}
 
Example 9
Source File: ProjectUtils.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
public static boolean createFolder(IFolder folder) throws CoreException{
	if (folder.exists()){
		return true;
	}else{
		if (folder.getParent()!=null && folder.getParent().exists()){
			folder.create(true, true, null);
			return true;
		}else if (folder.getParent() instanceof IFolder && createFolder((IFolder)folder.getParent())){
			folder.create(true, true, null);
			return true;
		}
	}
	return false;
}
 
Example 10
Source File: RouteResourceUtil.java    From tesb-studio-se with Apache License 2.0 5 votes vote down vote up
public static void prepareFolder(IFolder folder) throws CoreException {
    IContainer parent = folder.getParent();
    if (IResource.FOLDER == parent.getType()) {
        prepareFolder((IFolder) parent);
    }
    if (!folder.exists()) {
        folder.create(true, true, null);
    }
}
 
Example 11
Source File: AbstractBuilderParticipantTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/***/
protected void createParentFolder(IFolder folder) throws CoreException {
	IContainer parent = folder.getParent();
	if (parent instanceof IFolder) {
		IFolder parentFolder = (IFolder) parent;
		if (!parentFolder.exists()) {
			createParentFolder(parentFolder);
			parentFolder.create(true, true, null);
		}
	}
}
 
Example 12
Source File: YangProjectSupport.java    From yang-design-studio with Eclipse Public License 1.0 5 votes vote down vote up
private static void createFolder(IFolder folder)
  throws CoreException
{
  IContainer parent = folder.getParent();
  if ((parent instanceof IFolder)) {
    createFolder((IFolder)parent);
  }
  if (!folder.exists()) {
    folder.create(false, true, null);
  }
}
 
Example 13
Source File: TestFileCopier.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void ensureFolderExists(IFolder folder) {
	if (!folder.exists()) {
		if (!folder.getParent().exists() && folder.getParent() instanceof IFolder) {
			ensureFolderExists((IFolder) folder.getParent());
		}
		try {
			folder.create(true, true, new NullProgressMonitor());
		} catch (CoreException e) {
			throw new RuntimeException(e);
		}
	}
}
 
Example 14
Source File: BirtWizardUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Make Directory
 * 
 * @param folder
 * @throws CoreException
 */
public static void mkdirs( final IFolder folder ) throws CoreException
{
	if ( !folder.exists( ) )
	{
		if ( folder.getParent( ) instanceof IFolder )
		{
			mkdirs( (IFolder) folder.getParent( ) );
		}

		folder.create( true, true, null );
	}
}
 
Example 15
Source File: TmfCommonProjectElement.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static void deleteFolder(IFolder folder) throws CoreException {
    if (folder.exists()) {
        folder.delete(true, new NullProgressMonitor());
    }
    IContainer parent = folder.getParent();
    // delete empty folders up to the parent project
    if (parent instanceof IFolder && (!parent.exists() || parent.members().length == 0)) {
        deleteFolder((IFolder) parent);
    }
}
 
Example 16
Source File: BirtWizardUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Make Directory
 * 
 * @param folder
 * @throws CoreException
 */
public static void mkdirs( final IFolder folder ) throws CoreException
{
	if ( !folder.exists( ) )
	{
		if ( folder.getParent( ) instanceof IFolder )
		{
			mkdirs( (IFolder) folder.getParent( ) );
		}

		folder.create( true, true, null );
	}
}
 
Example 17
Source File: IDEOpenSampleReportAction.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void createFolder( IFolder folder ) throws CoreException
{
	if ( !folder.exists( ) )
	{
		IContainer parent = folder.getParent( );
		if ( parent instanceof IFolder )
		{
			createFolder( (IFolder) parent );
		}
		folder.create( true, true, null );
	}
}
 
Example 18
Source File: CoreUtility.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates a folder and all parent folders if not existing.
 * Project must exist.
 * <code> org.eclipse.ui.dialogs.ContainerGenerator</code> is too heavy
 * (creates a runnable)
 * @param folder the folder to create
 * @param force a flag controlling how to deal with resources that
 *    are not in sync with the local file system
 * @param local a flag controlling whether or not the folder will be local
 *    after the creation
 * @param monitor the progress monitor
 * @throws CoreException thrown if the creation failed
 */
public static void createFolder(IFolder folder, boolean force, boolean local, IProgressMonitor monitor) throws CoreException {
	if (!folder.exists()) {
		IContainer parent= folder.getParent();
		if (parent instanceof IFolder) {
			createFolder((IFolder)parent, force, local, null);
		}
		folder.create(force, local, monitor);
	}
}
 
Example 19
Source File: TraceUtils.java    From tracecompass with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Create a folder, ensuring all parent folders are also created.
 *
 * @param folder
 *            the folder to create
 * @param monitor
 *            the progress monitor
 * @throws CoreException
 *            if the folder cannot be created
 */
public static void createFolder(IFolder folder, IProgressMonitor monitor) throws CoreException {
    if (!folder.exists()) {
        if (folder.getParent() instanceof IFolder) {
            createFolder((IFolder) folder.getParent(), monitor);
        }
        folder.create(true, true, monitor);
    }
}
 
Example 20
Source File: N4JSProjectExplorerHelper.java    From n4js with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Returns with {@code true} if the folder argument represents a node_modules folder in its container project.
 * Otherwise returns with {@code false}.
 *
 * @param folder
 *            the folder to test whether it is an output folder or not.
 * @return {@code true} if the folder is detected as an node_modules folder in the project, otherwise returns with
 *         {@code false}.
 */
public boolean isNodeModulesNpmProject(IFolder folder) {
	IContainer parentContainer = folder.getParent();
	if (parentContainer instanceof IFolder) {
		return isNodeModulesFolder(parentContainer);
	}
	return false;
}