private String formatLogicalPackageMessage(LogicalPackage logicalPackage) { IScriptFolder[] fragments = logicalPackage.getScriptFolders(); StringBuffer buf = new StringBuffer(logicalPackage.getElementName()); buf.append(ScriptElementLabels.CONCAT_STRING); String message = ""; // $NON-NLS-1$ boolean firstTime = true; for (int i = 0; i < fragments.length; i++) { IScriptFolder fragment = fragments[i]; IModelElement element = fragment.getParent(); if (element instanceof IProjectFragment) { IProjectFragment root = (IProjectFragment) element; String label = ScriptElementLabels.getDefault() .getElementLabel( root, ScriptElementLabels.DEFAULT_QUALIFIED | ScriptElementLabels.ROOT_QUALIFIED); if (firstTime) { buf.append(label); firstTime = false; } else message = Messages.format( ScriptBrowsingMessages.StatusBar_concat, new String[] {message, label}); } } buf.append(message); return buf.toString(); }
public Object getHierarchicalPackageParent(final IScriptFolder child) { String name = child.getElementName(); IProjectFragment parent = (IProjectFragment) child.getParent(); int index = name.lastIndexOf(IScriptFolder.PACKAGE_DELIMITER); if (index != -1) { String realParentName = name.substring(0, index); IScriptFolder element = parent.getScriptFolder(realParentName); if (element != null && element.exists()) { try { if (fFoldPackages && ScriptExplorerContentProvider.isEmpty(element) && ScriptExplorerContentProvider.findSinglePackageChild(element, parent.getChildren()) != null) { return getHierarchicalPackageParent(element); } } catch (ModelException e) { // ignore } return element; } else if (element != null) { // bug 65240 IResource resource = element.getResource(); if (resource != null) { return resource; } } } if (parent.getResource() instanceof IProject) { return parent.getScriptProject(); } return parent; }
/* * (non-Javadoc) * * @see * org.eclipse.jdt.ui.StandardJavaElementContentProvider#getPackageContent * (org.eclipse.jdt.core.IPackageFragment) */ protected Object[] getScriptFolderContent(final IScriptFolder fragment) throws ModelException { if (fIsFlatLayout) { return super.getScriptFolderContent(fragment); } // hierarchical package mode ArrayList<Object> result = new ArrayList<Object>(); getHierarchicalPackageChildren((IProjectFragment) fragment.getParent(), fragment, result); Object[] nonPackages = super.getScriptFolderContent(fragment); if (result.isEmpty()) { return nonPackages; } for (int i = 0; i < nonPackages.length; i++) { result.add(nonPackages[i]); } return result.toArray(); }
/** Adds all of the openables defined within this package fragment to the list. */ private void injectAllOpenablesForPackageFragment(IScriptFolder packFrag, ArrayList openables) { try { IProjectFragment root = (IProjectFragment) packFrag.getParent(); int kind = root.getKind(); if (kind != 0) { boolean isSourcePackageFragment = (kind == IProjectFragment.K_SOURCE); if (isSourcePackageFragment) { ISourceModule[] cus = packFrag.getSourceModules(); for (int i = 0; i < cus.length; i++) { openables.add(cus[i]); } } } } catch (ModelException e) { // ignore } }
/** * Returns the hierarchical packages inside a given folder. * * @param folder The parent folder * @param result Collection where the resulting elements are added * @throws CoreException thrown when elements could not be accessed */ private void getHierarchicalPackagesInFolder( final IFolder folder, final Collection<Object> result) throws CoreException { IResource[] resources = folder.members(); for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; if (resource instanceof IFolder) { IFolder curr = (IFolder) resource; IModelElement element = DLTKCore.create(curr); if (element instanceof IScriptFolder) { if (fFoldPackages) { IScriptFolder fragment = (IScriptFolder) element; IProjectFragment root = (IProjectFragment) fragment.getParent(); element = ScriptExplorerContentProvider.getFolded(root.getChildren(), fragment); } result.add(element); } } } }