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

The following examples show how to use org.eclipse.core.resources.IContainer#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: UIDArtifactFilters.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static ViewerFilter filterUIDArtifactChildren() {
    return new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            if (element instanceof IResource) {
                IContainer parent = ((IResource) element).getParent();
                if (parent != null) {
                    return parent.getParent() == null
                            || (parent.getParent() != null && (!isAUIDFolder(parent.getParent(), "web_page") &&
                                    !isAUIDFolder(parent.getParent(), "web_widgets") &&
                                    !isAUIDFolder(parent.getParent(), "web_fragments")));
                }
            }
            return true;
        }

    };
}
 
Example 2
Source File: ModuleFile.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns whether a folder is on the public path of this module. The public paths include the
 * paths explicitly declared with <code>&lt;public&gt;</code> tags and all of their descendant
 * sub-folders.
 *
 * @param folder the folder to check
 * @return <code>true</code> if this folder is on a public path, and <code>false</code> otherwise
 */
public boolean isPublicPath(IFolder folder) {
  IFolder[] publicFolders = getFolders(getPublicPaths());

  IContainer moduleContainer = getFile().getParent();
  IContainer container = folder;

  // Walk up the ancestor chain looking for a public path matching this folder
  while (container.getType() == IResource.FOLDER) {
    // If we reach the module's container, we're done searching
    if (container.equals(moduleContainer)) {
      return false;
    }

    for (IFolder publicFolder : publicFolders) {
      if (container.equals(publicFolder)) {
        return true;
      }
    }

    container = container.getParent();
  }

  return false;
}
 
Example 3
Source File: PyRenameResourceChange.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the destination folder and returns the created files.
 */
private IResource[] createDestination(IContainer destination) throws CoreException {
    ArrayList<IResource> lst = new ArrayList<IResource>();
    if (!destination.exists()) {
        //Create parent structure first
        IContainer parent = destination.getParent();
        lst.addAll(Arrays.asList(createDestination(parent)));

        IFolder folder = parent.getFolder(new Path(destination.getFullPath().lastSegment()));

        IFile file = destination.getFile(new Path("__init__.py"));

        folder.create(IResource.NONE, true, null);
        file.create(new ByteArrayInputStream(new byte[0]), IResource.NONE, null);

        //Add in the order to delete later (so, first file then folder).
        lst.add(file);
        lst.add(folder);
    }
    return lst.toArray(new IResource[lst.size()]);
}
 
Example 4
Source File: WizardSaveAsPage.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Sets the selected existing container.
 */
public void setSelectedContainer( IContainer container )
{
	selectedContainer = container;

	// expand to and select the specified container
	List itemsToExpand = new ArrayList( );
	IContainer parent = container.getParent( );
	while ( parent != null )
	{
		itemsToExpand.add( 0, parent );
		parent = parent.getParent( );
	}
	treeViewer.setExpandedElements( itemsToExpand.toArray( ) );
	treeViewer.setSelection( new StructuredSelection( container ), true );
}
 
Example 5
Source File: JDTUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public static void createFolders(IContainer folder, IProgressMonitor monitor) throws CoreException {
	if (!folder.exists() && folder instanceof IFolder) {
		IContainer parent = folder.getParent();
		createFolders(parent, monitor);
		folder.refreshLocal(IResource.DEPTH_ZERO, monitor);
		if (!folder.exists()) {
			((IFolder)folder).create(true, true, monitor);
		}
	}
}
 
Example 6
Source File: BonitaProjectPropertyTester.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean isContainedInBonitaStore(IResource resource) {
    IContainer parent = resource.getParent();
    while (parent != null && !isBonitaStoreContainer(parent)) {
        parent = parent.getParent();
    }
    return parent != null;
}
 
Example 7
Source File: Repository.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private boolean belongToRepositoryStore(final IRepositoryStore<?> store, final IFile file) {
    final IFolder parentFolder = store.getResource();
    if (parentFolder == null) {
        return false;
    }
    IContainer current = file.getParent();
    while (current != null && !parentFolder.equals(current)) {
        current = current.getParent();
    }
    return current != null && parentFolder.equals(current);
}
 
Example 8
Source File: ProjectFolderSelectionGroup.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the selected existing container.
 */
public void setSelectedContainer(IContainer container) {
    selectedContainer = container;

    //expand to and select the specified container
    List<IContainer> itemsToExpand = new ArrayList<IContainer>();
    IContainer parent = container.getParent();
    while (parent != null) {
        itemsToExpand.add(0, parent);
        parent = parent.getParent();
    }
    treeViewer.setExpandedElements(itemsToExpand.toArray());
    treeViewer.setSelection(new StructuredSelection(container), true);
}
 
Example 9
Source File: SyncFileChangeListener.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected IContainer handleChangedEntries(IResource resource, int kind) {		
	IContainer changedContainer = resource.getParent();
	IContainer parent           = changedContainer.getParent();
	if((parent != null) && parent.exists()) {
		return changedContainer;
	} else {
		return null;
	}
}
 
Example 10
Source File: ResourceSelectionTree.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean isChild(IResource resource, IResource parent) {
   	IContainer container = resource.getParent();
   	while (container != null) {
   		if (container.getFullPath().toString().equals(parent.getFullPath().toString()))
   			return true;
   		container = container.getParent();
   	}		
	return false;
}
 
Example 11
Source File: SvnWizardCommitPage.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private boolean isChild(IResource resource, IContainer folder) {
	IContainer container = resource.getParent();
	while (container != null) {
		if (container.getFullPath().toString().equals(folder.getFullPath().toString()))
			return true;
		container = container.getParent();
	}
	return false;
}
 
Example 12
Source File: DerivedResourceCleanerJob.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void deleteEmptyParent(IProgressMonitor monitor, IContainer container) throws CoreException {
	final IContainer parent = container.getParent();
	if (container.members().length == 0) {
		container.delete(true, monitor);
		deleteEmptyParent(monitor, parent);
	}
}
 
Example 13
Source File: FileAnalysis.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 获取所有包括分析文件的文件夹(直接包括或间接包括都可)
 * @param rootFolder	起始文件夹
 * @param allFolderList	承装所有文件夹的集合
 */
public void getAllFolder(IContainer rootFolder, List<IContainer> allFolderList){
	
	if (allFolderList == null) {
		allFolderList = new LinkedList<IContainer>();
	}
	IResource[] members;
	try {
		members = rootFolder.members();
		for (IResource resource : members) {
			if (resource instanceof IContainer) {
				boolean faIFilesExsit = false;
				
				//循环判断所有的要分析的文件,检查当前容器下是否包括要分析的文件
				for (int fileIndex = 0; fileIndex < model.getAnalysisIFileList().size(); fileIndex++) {
					IFile ifile = model.getAnalysisIFileList().get(fileIndex);
					
					IContainer iFileParent = ifile.getParent();
					while (iFileParent != null ) {
						if (iFileParent.equals((IContainer)resource) ) {
							faIFilesExsit = true;
							break;
						}else {
							iFileParent = iFileParent.getParent();
						}
					}
					
					//如果当前容器下存在分析的文件,将该容器加载到缓存中,并停止循环其他分析的文件
					if (faIFilesExsit) {
						allFolderList.add((IContainer)resource);
						break;
					}
				}
				
				getAllFolder((IContainer)resource, allFolderList);
			}
		}
	} catch (CoreException e) {
		LOGGER.error("", e);
		e.printStackTrace();
	}
}
 
Example 14
Source File: FileAnalysis.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 获取所有包括分析文件的文件夹(直接包括或间接包括都可)
 * @param rootFolder	起始文件夹
 * @param allFolderList	承装所有文件夹的集合
 */
public void getAllFolder(IContainer rootFolder, List<IContainer> allFolderList){
	
	if (allFolderList == null) {
		allFolderList = new LinkedList<IContainer>();
	}
	IResource[] members;
	try {
		members = rootFolder.members();
		for (IResource resource : members) {
			if (resource instanceof IContainer) {
				boolean faIFilesExsit = false;
				
				//循环判断所有的要分析的文件,检查当前容器下是否包括要分析的文件
				for (int fileIndex = 0; fileIndex < model.getAnalysisIFileList().size(); fileIndex++) {
					IFile ifile = model.getAnalysisIFileList().get(fileIndex);
					
					IContainer iFileParent = ifile.getParent();
					while (iFileParent != null ) {
						if (iFileParent.equals((IContainer)resource) ) {
							faIFilesExsit = true;
							break;
						}else {
							iFileParent = iFileParent.getParent();
						}
					}
					
					//如果当前容器下存在分析的文件,将该容器加载到缓存中,并停止循环其他分析的文件
					if (faIFilesExsit) {
						allFolderList.add((IContainer)resource);
						break;
					}
				}
				
				getAllFolder((IContainer)resource, allFolderList);
			}
		}
	} catch (CoreException e) {
		LOGGER.error("", e);
		e.printStackTrace();
	}
}
 
Example 15
Source File: RefactoringModifications.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
protected void createIncludingParents(IContainer container) {
	while (container != null && !(container.exists() || getResourceModifications().willExist(container))) {
		getResourceModifications().addCreate(container);
		container= container.getParent();
	}
}
 
Example 16
Source File: PyRenameResourceChange.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the final folder for the created module and the resources created in the process. 
 * 
 * Receives the resource (i.e.: in filesystem), the resolved name (i.e.: my.mod1) and the final name (i.e.: bar.foo).
 */
public static IContainer getDestination(IResource initialResource, String initialName, String finalName,
        IProgressMonitor pm) {
    List<String> initialParts = StringUtils.split(initialName, ".");
    List<String> finalParts = StringUtils.split(finalName, ".");

    int startFrom = 0;
    int finalPartSize = finalParts.size();
    int initialPartSize = initialParts.size();

    initialPartSize--;
    String initialNamePart = initialParts.remove(initialPartSize); //remove the last, as that's the name

    finalPartSize--;
    String finalNamePart = finalParts.remove(finalPartSize); //remove the last, as that's the name

    //Get variable startFrom to the first place where the parts differ.
    for (; startFrom < finalPartSize; startFrom++) {
        String part = finalParts.get(startFrom);
        if (startFrom < initialPartSize) {
            String initial = initialParts.get(startFrom);
            if (!initial.equals(part)) {
                break;
            }
        } else {
            break;
        }
    }

    List<String> createParts = finalParts.subList(startFrom, finalPartSize); //the last path is the file, not the folder, so, skip it.
    List<String> backtrackParts = initialParts.subList(startFrom, initialPartSize);
    Collections.reverse(backtrackParts);
    IResource resource = initialResource;
    IContainer container = resource.getParent(); //always start from our container.
    for (String string : backtrackParts) {
        container = container.getParent();
    }

    if (createParts.size() > 0) {
        container = container.getFolder(new Path(StringUtils.join("/", createParts)));
    }

    return container;
}
 
Example 17
Source File: PythonModelProvider.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Converts the shape modification to use Python elements.
 * @param natureToSourcePathSet
 *
 * @param modification: the shape modification to convert
 * @param isAdd: boolean indicating whether this convertion is happening in an add operation
 */
@SuppressWarnings("unchecked")
private void convertToPythonElementsAddOrRemove(PipelinedShapeModification modification, boolean isAdd,
        Map<PythonNature, Set<String>> natureToSourcePathSet) {
    if (DEBUG) {
        debug("Before", modification);
    }
    Object parent = modification.getParent();
    if (parent instanceof IContainer) {
        IContainer parentContainer = (IContainer) parent;
        Object pythonParent = getResourceInPythonModel(parentContainer, true);

        if (pythonParent instanceof IWrappedResource) {
            IWrappedResource parentResource = (IWrappedResource) pythonParent;
            modification.setParent(parentResource);
            wrapChildren(parentResource, parentResource.getSourceFolder(), modification.getChildren(), isAdd,
                    natureToSourcePathSet);

        } else if (pythonParent == null) {

            Object parentInWrap = parentContainer;
            PythonSourceFolder sourceFolderInWrap = null;

            //this may happen when a source folder is added or some element that still doesn't have it's parent in the model...
            //so, we have to get the parent's parent until we actually 'know' that it is not in the model (or until we run
            //out of parents to try)
            //the case in which we reproduce this is Test 1 (described in the class)
            FastStack<Object> found = new FastStack<Object>(20);
            while (true) {

                //add the current to the found
                if (parentContainer == null) {
                    break;
                }

                found.push(parentContainer);
                if (parentContainer instanceof IProject) {
                    //we got to the project without finding any part of a python model already there, so, let's see
                    //if any of the parts was actually a source folder (that was still not added)
                    tryCreateModelFromProject((IProject) parentContainer, found, natureToSourcePathSet);
                    //and now, if it was created, try to convert it to the python model (without any further add)
                    convertToPythonElementsUpdateOrRefresh(modification.getChildren());
                    return;
                }

                Object p = getResourceInPythonModel(parentContainer, true);

                if (p instanceof IWrappedResource) {
                    IWrappedResource wrappedResource = (IWrappedResource) p;
                    sourceFolderInWrap = wrappedResource.getSourceFolder();

                    while (found.size() > 0) {
                        Object f = found.pop();
                        if (f instanceof IResource) {
                            //no need to create it if it's already in the model!
                            Object child = sourceFolderInWrap.getChild((IResource) f);
                            if (child != null && child instanceof IWrappedResource) {
                                wrappedResource = (IWrappedResource) child;
                                continue;
                            }
                        }
                        //creating is enough to add it to the model
                        if (f instanceof IFile) {
                            wrappedResource = new PythonFile(wrappedResource, (IFile) f, sourceFolderInWrap);
                        } else if (f instanceof IFolder) {
                            wrappedResource = new PythonFolder(wrappedResource, (IFolder) f, sourceFolderInWrap);
                        }
                    }
                    parentInWrap = wrappedResource;
                    break;
                }

                parentContainer = parentContainer.getParent();
            }

            wrapChildren(parentInWrap, sourceFolderInWrap, modification.getChildren(), isAdd,
                    natureToSourcePathSet);
        }

    } else if (parent == null) {
        wrapChildren(null, null, modification.getChildren(), isAdd, natureToSourcePathSet);
    }

    if (DEBUG) {
        debug("After", modification);
    }
}
 
Example 18
Source File: FileUtils.java    From saros with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Makes sure that the parent directories of the given {@linkplain IResource resource} exist.
 *
 * @throws CoreException
 */
public static void mkdirs(final IResource resource) throws CoreException {

  final List<IFolder> parents = new ArrayList<IFolder>();

  IContainer parent = resource.getParent();

  while (parent != null && parent.getType() == IResource.FOLDER) {
    if (parent.exists()) break;

    parents.add((IFolder) parent);
    parent = parent.getParent();
  }

  Collections.reverse(parents);

  for (final IFolder folder : parents) folder.create(false, true, null);
}
 
Example 19
Source File: RefactoringModifications.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
protected void createIncludingParents(IContainer container) {
	while (container != null && !(container.exists() || getResourceModifications().willExist(container))) {
		getResourceModifications().addCreate(container);
		container= container.getParent();
	}
}