private IProject getProject() { IScriptProject scriptProject = getScriptProject(); if (scriptProject != null) { return scriptProject.getProject(); } return null; }
/* * (non-Javadoc) * * @see * org.eclipse.jdt.ui.StandardJavaElementContentProvider#getPackageFragmentRoots * (org.eclipse.jdt.core.IJavaProject) */ protected Object[] getProjectFragments(final IScriptProject project) throws ModelException { if (!project.getProject().isOpen()) { return StandardModelElementContentProvider.NO_CHILDREN; } List<Object> result = new ArrayList<Object>(); boolean addZIPContainer = false; IProjectFragment[] roots = project.getProjectFragments(); for (int i = 0; i < roots.length; i++) { IProjectFragment root = roots[i]; IBuildpathEntry classpathEntry = root.getRawBuildpathEntry(); if (classpathEntry == null) { continue; } int entryKind = classpathEntry.getEntryKind(); if (entryKind == IBuildpathEntry.BPE_CONTAINER) { // all ClassPathContainers are added later } else if (fShowLibrariesNode && (entryKind == IBuildpathEntry.BPE_LIBRARY /* * || entryKind * == * IBuildpathEntry * .BPE_VARIABLE */)) { addZIPContainer = true; } else { if (isProjectProjectFragment(root)) { // filter out package fragments that correspond to projects // and // replace them with the package fragments directly Object[] fragments = getProjectFragmentContent(root); for (int j = 0; j < fragments.length; j++) { result.add(fragments[j]); } } else { result.add(root); } } } if (addZIPContainer) { result.add(new LibraryContainer(project)); } // separate loop to make sure all containers are on the classpath IBuildpathEntry[] rawBuidspath = project.getRawBuildpath(); for (int i = 0; i < rawBuidspath.length; i++) { IBuildpathEntry classpathEntry = rawBuidspath[i]; if (classpathEntry.getEntryKind() == IBuildpathEntry.BPE_CONTAINER) { result.add(new BuildPathContainer(project, classpathEntry)); } } Object[] resources = project.getForeignResources(); for (int i = 0; i < resources.length; i++) { result.add(resources[i]); } return result.toArray(); }
/** * Answers if the given <code>element</code> is a valid input for this part. * * @param element the object to test * @return <true> if the given element is a valid input */ protected boolean isValidInput(Object element) { if (element instanceof IScriptProject || (element instanceof IProjectFragment && ((IModelElement) element).getElementName() != IProjectFragment.DEFAULT_PACKAGE_ROOT)) { IScriptProject jProject = ((IModelElement) element).getScriptProject(); if (jProject != null) return DLTKLanguageManager.hasScriptNature(jProject.getProject()); } return false; }
public void installSymfony(IProgressMonitor monitor) { if (monitor == null) monitor = new NullProgressMonitor(); SymfonyProjectWizardFirstPage firstPage = (SymfonyProjectWizardFirstPage) fFirstPage; monitor.beginTask("Installing symfony...", 100); monitor.worked(10); IProject projectHandle = fFirstPage.getProjectHandle(); final IScriptProject scriptProject = DLTKCore.create(projectHandle); File file = null; final List<IBuildpathEntry> entries = new ArrayList<IBuildpathEntry>(); level = 0; try { file = new File(firstPage.getLibraryPath()); symfonyPath = new Path(firstPage.getLibraryPath()).toString(); if (file.isDirectory()) { final File[] files = file.listFiles(); if (!scriptProject.isOpen()) { scriptProject.open(monitor); } if (files != null && scriptProject != null && scriptProject.isOpen()) { for (File f : files) { importFile(f, scriptProject.getProject(), entries); } BuildPathUtils.addEntriesToBuildPath(scriptProject, entries); monitor.worked(90); } } } catch (ModelException e) { e.printStackTrace(); Logger.logException(e); } catch (Exception e) { e.printStackTrace(); Logger.logException(e); } finally { monitor.worked(100); monitor.done(); } }
/** * Returns the transitive closure of buildpath entries for the given project entry. * * @param projectEntry project buildpath entry * @param expandedPath a list of entries already expanded, should be empty to begin, and contains * the result * @param expanding a list of projects that have been or are currently being expanded (to detect * cycles) * @exception CoreException if unable to expand the buildpath */ private void expandProject(IBuildpathEntry projectEntry, List expandedPath, List expanding) throws CoreException { expanding.add(projectEntry); // 1. Get the raw buildpath // 2. Replace source folder entries with a project entry IPath projectPath = projectEntry.getPath(); IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(projectPath.lastSegment()); if (res == null) { // add project entry and return expandedPath.add(projectEntry); return; } IScriptProject project = (IScriptProject) DLTKCore.create(res); if (project == null || !project.getProject().isOpen() || !project.exists()) { // add project entry and return expandedPath.add(projectEntry); return; } IBuildpathEntry[] buildPath = project.getRawBuildpath(); List unexpandedPath = new ArrayList(buildPath.length); // boolean projectAdded = false; for (int i = 0; i < buildPath.length; i++) { IBuildpathEntry buildpathEntry = buildPath[i]; if (buildpathEntry.getEntryKind() == IBuildpathEntry.BPE_SOURCE) { // sources // are // always // added unexpandedPath.add(buildpathEntry); } else { // add exported entires, as configured if (buildpathEntry.isExported()) { unexpandedPath.add(buildpathEntry); } else if (!isExportedEntriesOnly() || project.equals(getScriptProject())) { // add non exported entries from root project or if we are // including all entries unexpandedPath.add(buildpathEntry); } } } // 3. expand each project entry (except for the root project) // 4. replace each container entry with a runtime entry associated with // the project Iterator iter = unexpandedPath.iterator(); while (iter.hasNext()) { IBuildpathEntry entry = (IBuildpathEntry) iter.next(); if (entry == projectEntry) { expandedPath.add(entry); } else { switch (entry.getEntryKind()) { case IBuildpathEntry.BPE_PROJECT: if (!expanding.contains(entry)) { expandProject(entry, expandedPath, expanding); } break; case IBuildpathEntry.BPE_CONTAINER: IBuildpathContainer container = DLTKCore.getBuildpathContainer(entry.getPath(), project); int property = -1; if (container != null) { switch (container.getKind()) { case IBuildpathContainer.K_APPLICATION: property = IRuntimeBuildpathEntry.USER_ENTRY; break; case IBuildpathContainer.K_DEFAULT_SYSTEM: property = IRuntimeBuildpathEntry.STANDARD_ENTRY; break; case IBuildpathContainer.K_SYSTEM: property = IRuntimeBuildpathEntry.BOOTSTRAP_ENTRY; break; } IRuntimeBuildpathEntry r = ScriptRuntime.newRuntimeContainerBuildpathEntry( entry.getPath(), property, project); // check for duplicate/redundant entries boolean duplicate = false; BuildpathContainerInitializer initializer = DLTKCore.getBuildpathContainerInitializer(r.getPath().segment(0)); for (int i = 0; i < expandedPath.size(); i++) { Object o = expandedPath.get(i); if (o instanceof IRuntimeBuildpathEntry) { IRuntimeBuildpathEntry re = (IRuntimeBuildpathEntry) o; if (re.getType() == IRuntimeBuildpathEntry.CONTAINER) { BuildpathContainerInitializer initializer2 = DLTKCore.getBuildpathContainerInitializer(re.getPath().segment(0)); Object id1 = null; Object id2 = null; if (initializer == null) { id1 = r.getPath().segment(0); } else { id1 = initializer.getComparisonID(r.getPath(), project); } if (initializer2 == null) { id2 = re.getPath().segment(0); } else { IScriptProject context = re.getScriptProject(); if (context == null) { context = project; } id2 = initializer2.getComparisonID(re.getPath(), context); } if (id1 == null) { duplicate = id2 == null; } else { duplicate = id1.equals(id2); } if (duplicate) { break; } } } } if (!duplicate) { expandedPath.add(r); } } break; default: if (!expandedPath.contains(entry)) { expandedPath.add(entry); } break; } } } return; }
/** * Processes a delta recursively. When more than two children are affected the tree is fully * refreshed starting at this node. * * @param delta the delta to process * @param runnables the resulting view changes as runnables (type {@link Runnable} ) * @return true is returned if the conclusion is to refresh a parent of an element. In that case * no siblings need to be processed * @throws JavaModelException thrown when the access to an element failed */ private boolean processDelta(final IModelElementDelta delta, final Collection<Runnable> runnables) throws ModelException { int kind = delta.getKind(); int flags = delta.getFlags(); IModelElement element = delta.getElement(); int elementType = element.getElementType(); if (elementType != IModelElement.SCRIPT_MODEL && elementType != IModelElement.SCRIPT_PROJECT) { IScriptProject proj = element.getScriptProject(); if (proj == null || !proj.getProject().isOpen()) { // TODO: Not needed if parent already did the 'open' check! return false; } } if (elementType == IModelElement.SCRIPT_FOLDER) { if ((flags & (IModelElementDelta.F_CONTENT | IModelElementDelta.F_CHILDREN)) == IModelElementDelta.F_CONTENT) { if (!fIsFlatLayout) { Object parent = getHierarchicalPackageParent((IScriptFolder) element); if (!(parent instanceof IProjectFragment)) { postRefresh(internalGetParent(parent), GRANT_PARENT, element, runnables); return true; } } // content change, without children info (for example resource // added/removed to class folder package) postRefresh(internalGetParent(element), PARENT, element, runnables); return true; } if (!fIsFlatLayout) { if (kind == IModelElementDelta.REMOVED) { final Object parent = getHierarchicalPackageParent((IScriptFolder) element); if (parent instanceof IProjectFragment) { postRemove(element, runnables); return false; } else { postRefresh(internalGetParent(parent), GRANT_PARENT, element, runnables); return true; } } else if (kind == IModelElementDelta.ADDED) { final Object parent = getHierarchicalPackageParent((IScriptFolder) element); if (parent instanceof IProjectFragment) { if (fFoldPackages) { postRefresh(parent, PARENT, element, runnables); return true; } else { postAdd(parent, element, runnables); return false; } } else { postRefresh(internalGetParent(parent), GRANT_PARENT, element, runnables); return true; } } handleAffectedChildren(delta, element, runnables); return false; } } if (elementType == IModelElement.SOURCE_MODULE) { ISourceModule cu = (ISourceModule) element; if (!ScriptModelUtil.isPrimary(cu)) { return false; } if (!getProvideMembers() && cu.isWorkingCopy() && kind == IModelElementDelta.CHANGED) { return false; } if (kind == IModelElementDelta.CHANGED && !isStructuralCUChange(flags)) { return false; // test moved ahead } if (!isOnClassPath(cu)) { // TODO: isOnClassPath expensive! Should // be put after all cheap tests return false; } } if (elementType == IModelElement.SCRIPT_PROJECT) { // handle open and closing of a project if ((flags & (IModelElementDelta.F_CLOSED | IModelElementDelta.F_OPENED)) != 0) { postRefresh(element, ORIGINAL, element, runnables); return false; } // if the class path has changed we refresh the entire project if ((flags & IModelElementDelta.F_BUILDPATH_CHANGED) != 0) { postRefresh(element, ORIGINAL, element, runnables); return false; } // if added it could be that the corresponding IProject is already // shown. Remove it first. // bug 184296 if (kind == IModelElementDelta.ADDED) { postRemove(element.getResource(), runnables); postAdd(element.getParent(), element, runnables); return false; } } if (kind == IModelElementDelta.REMOVED) { Object parent = internalGetParent(element); if (element instanceof IScriptFolder) { // refresh package fragment root to allow filtering empty // (parent) packages: bug 72923 if (fViewer.testFindItem(parent) != null) { postRefresh(parent, PARENT, element, runnables); } return true; } else if (element instanceof IProjectFragment && ((IProjectFragment) element).getKind() != IProjectFragment.K_SOURCE) { // libs and class folders can show up twice (in library // container and as resource at original location) IResource resource = element.getResource(); if (resource != null) postRemove(resource, runnables); } postRemove(element, runnables); if (parent instanceof IScriptFolder) { postUpdateIcon((IScriptFolder) parent, runnables); } // we are filtering out empty subpackages, so we // a package becomes empty we remove it from the viewer. if (isScriptFolderEmpty(element.getParent())) { if (fViewer.testFindItem(parent) != null) { postRefresh(internalGetParent(parent), GRANT_PARENT, element, runnables); } return true; } return false; } if (kind == IModelElementDelta.ADDED) { Object parent = internalGetParent(element); // we are filtering out empty subpackages, so we // have to handle additions to them specially. if (parent instanceof IScriptFolder) { Object grandparent = internalGetParent(parent); // 1GE8SI6: ITPJUI:WIN98 - Rename is not shown in Packages View // avoid posting a refresh to an invisible parent if (parent.equals(fInput)) { postRefresh(parent, PARENT, element, runnables); } else { // refresh from grandparent if parent isn't visible yet if (fViewer.testFindItem(parent) == null) { postRefresh(grandparent, GRANT_PARENT, element, runnables); } else { postRefresh(parent, PARENT, element, runnables); } } return true; } else { postAdd(parent, element, runnables); } } if (elementType == IModelElement.SOURCE_MODULE || elementType == IModelElement.BINARY_MODULE) { if (kind == IModelElementDelta.CHANGED) { // isStructuralCUChange already performed above postRefresh(element, ORIGINAL, element, runnables); } return false; } if (elementType == IModelElement.PROJECT_FRAGMENT) { // the contents of an external JAR or class folder has changed if ((flags & IModelElementDelta.F_ARCHIVE_CONTENT_CHANGED) != 0) { postRefresh(element, ORIGINAL, element, runnables); return false; } if ((flags & (IModelElementDelta.F_CONTENT | IModelElementDelta.F_CHILDREN)) == IModelElementDelta.F_CONTENT) { // content change, without children info (for example resource // added/removed to class folder package) postRefresh(internalGetParent(element), PARENT, element, runnables); return true; } // the source attachment of a JAR has changed // if ((flags & ( | IModelElementDelta.F_SOURCEDETACHED)) != 0) { // postUpdateIcon(element, runnables); // } if (isBuildPathChange(delta)) { // throw the towel and do a full refresh of the affected java // project. postRefresh(element.getScriptProject(), PROJECT, element, runnables); return true; } } handleAffectedChildren(delta, element, runnables); return false; }