public void elementEncode(XMLWriter writer, IPath projectPath, boolean newLine) { // Keeping this as a HashMap (not a Map) for the XMLWriter HashMap parameters = new HashMap(); parameters.put(TAG_ENTRY_KIND, IncludePathEntry.entryKindToString(this.entryKind)); parameters.put(TAG_CONTENT_KIND, IncludePathEntry.contentKindToString(this.contentKind)); parameters.put( TAG_CREATEDREFERENCE, createdReference ? "true" : "false"); // $NON-NLS-1$ //$NON-NLS-2$ IPath xmlPath = this.path; if (this.entryKind != IIncludePathEntry.IPE_VARIABLE && this.entryKind != IIncludePathEntry.IPE_CONTAINER) { // translate to project relative from absolute (unless a device path) if (projectPath != null && projectPath.isPrefixOf(xmlPath)) { if (xmlPath.segment(0).equals(projectPath.segment(0))) { xmlPath = xmlPath.removeFirstSegments(1); xmlPath = xmlPath.makeRelative(); } else { xmlPath = xmlPath.makeAbsolute(); } } } parameters.put(TAG_PATH, String.valueOf(xmlPath)); if (resource != null) { parameters.put(TAG_RESOURCE, resource.getName()); } if (this.isExported) { parameters.put(TAG_EXPORTED, "true"); // $NON-NLS-1$ } writer.printTag(TAG_INCLUDEPATHENTRY, parameters); writer.endTag(TAG_INCLUDEPATHENTRY); }
/** * Returns the tool tip text for the given element. * * @param element the element * @return the tooltip for the element */ String getToolTipText(Object element) { String result; if (!(element instanceof IResource)) { result = ScriptElementLabels.getDefault() .getTextLabel(element, AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS); } else { IPath path = ((IResource) element).getFullPath(); if (path.isRoot()) { result = getConfigurationElement().getAttribute("name"); // $NON-NLS-1$ } else { result = path.makeRelative().toString(); } } if (fWorkingSetFilterActionGroup == null || fWorkingSetFilterActionGroup.getWorkingSet() == null) return result; IWorkingSet ws = fWorkingSetFilterActionGroup.getWorkingSet(); String wsstr = Messages.format( ScriptBrowsingMessages.JavaBrowsingPart_toolTip, new String[] {ws.getLabel()}); if (result.length() == 0) return wsstr; return Messages.format( ScriptBrowsingMessages.JavaBrowsingPart_toolTip2, new String[] {result, ws.getLabel()}); }
public String getText(Object element) { if (!(element instanceof IResource)) return null; IResource resource = (IResource) element; String text = null; if (!resource.exists()) text = SearchMessages.FileLabelProvider_removed_resource_label; else { IPath path = resource.getFullPath().removeLastSegments(1); if (path.getDevice() == null) path = path.makeRelative(); if (fOrder == SHOW_LABEL || fOrder == SHOW_LABEL_PATH) { text = fLabelProvider.getText(resource); if (path != null && fOrder == SHOW_LABEL_PATH) { fArgs[0] = text; fArgs[1] = path.toString(); text = MessageFormat.format(fgSeparatorFormat, fArgs); } } else { if (path != null) text = path.toString(); else text = ""; // $NON-NLS-1$ if (fOrder == SHOW_PATH_LABEL) { fArgs[0] = text; fArgs[1] = fLabelProvider.getText(resource); text = MessageFormat.format(fgSeparatorFormat, fArgs); } } } int matchCount = 0; AbstractTextSearchResult result = fPage.getInput(); if (result != null) matchCount = result.getMatchCount(element); if (matchCount <= 1) return text; String format = SearchMessages.FileLabelProvider_count_format; return MessageFormat.format(format, new Object[] {text, new Integer(matchCount)}); }
public void performFinish(IProgressMonitor monitor) throws CoreException { IVirtualComponent rootComponent = (IVirtualComponent) getTaskModel().getObject(IReferenceWizardConstants.ROOT_COMPONENT); String runtimeLoc = (String) getTaskModel().getObject(IReferenceWizardConstants.DEFAULT_LIBRARY_LOCATION); if (archives != null && archives.size() > 0) { ArrayList<IVirtualReference> refList = new ArrayList<IVirtualReference>(); Iterator iterator = archives.values().iterator(); while (iterator.hasNext()) { IPath path = (Path) iterator.next(); // IPath fullPath = project.getFile(selected[i]).getFullPath(); String type = VirtualArchiveComponent.LIBARCHIVETYPE + IPath.SEPARATOR; IVirtualComponent archive = ComponentCore.createArchiveComponent( rootComponent.getProject(), type + path.makeRelative().toString()); VirtualReference ref = new VirtualReference(rootComponent, archive); ref.setArchiveName(path.lastSegment()); if (runtimeLoc != null) { ref.setRuntimePath(new Path(runtimeLoc).makeAbsolute()); } refList.add(ref); } IVirtualReference[] finalRefs = refList.toArray(new IVirtualReference[refList.size()]); getTaskModel().putObject(IReferenceWizardConstants.FINAL_REFERENCE, finalRefs); } }
/* * Appends a path to a URI and returns the new combined URI in an array of 2 elements, * where the first element is in decoded form and the second element is in encoded form. */ private String[] appendPathToURI(URI uriObj, IPath path) { String schemeSpecificPart = uriObj.getSchemeSpecificPart(); if (schemeSpecificPart.endsWith("/")) path = path.makeRelative(); else path = path.makeAbsolute(); return new String[] { uriObj.getScheme() + ':' + schemeSpecificPart + path, uriObj.getScheme() + ':' + uriObj.getRawSchemeSpecificPart() + path }; }
void launch(IPath targetPath, String mode) { targetPath = targetPath.makeRelative(); try { ILaunchConfiguration config = findLaunchConfig(targetPath); if (config == null) { ILaunchConfigurationWorkingCopy wc = createConfiguration(targetPath); config = wc.doSave(); } DebugUITools.launch(config, mode); } catch (Exception e) { e.printStackTrace(); } }
private String getPathString(IPath path, boolean isExternal) { // if (ArchiveFileFilter.isArchivePath(path)) { // IPath appendedPath = path.removeLastSegments(1); // String appended = isExternal ? appendedPath.toPortableString() : // appendedPath.makeRelative().toString(); // return // CPathEntryMessages.getFormattedString("CPListLabelProvider.twopart", // //$NON-NLS-1$ // new String[] { path.lastSegment(), appended}); // } else { return isExternal ? path.toPortableString() : path.makeRelative().toString(); // } }
public ModelWorkspaceItem getWorkspaceItem(final IPath path, int resourceType) { CoreArgCheck.isNotNull(path); try { // first get all the projects ModelProject[] projects = getModelProjects(); for (int i = 0; i < projects.length; i++) { ModelProject project = projects[i]; if (resourceType == IResource.PROJECT) { if (project.getPath().equals(path)) { return project; } } else { if (!project.isOpen()) { continue; } // If the path only contains the project then we cannot match it // to a non-project type so return null if (path.segmentCount() < 2) { return null; } // If the first segment is not this project's name then skip it if (!path.segment(0).equals(project.getProject().getName())) { continue; } // Iterate over all the path segments navigating to the child by name ModelWorkspaceItem item = project; final String[] segments = path.segments(); for (int j = 1; j < segments.length; j++) { final String segment = segments[j]; if (!item.exists()) { // Must be in the process of closing (see defect 10957) ... return null; } item = item.getChild(segment); if (item == null) { break; } else if (item.getPath().makeRelative().equals(path.makeRelative())) { return item; } } // ModelWorkspaceItem[] children = project.getChildren(); // return recursiveLookUp(children, path); } } } catch (ModelWorkspaceException e) { // do nothing } return null; }
public static IIncludePathEntry newContainerEntry( IPath containerPath, IResource containerResource, boolean isExported) { if (containerPath == null) { throw new IllegalArgumentException("Container path cannot be null"); // $NON-NLS-1$ } if (containerPath.segmentCount() < 1) { throw new IllegalArgumentException( "Illegal include path container path: \'" + containerPath.makeRelative().toString() + "\', must have at least one segment (containerID+hints)"); //$NON-NLS-1$//$NON-NLS-2$ } return new IncludePathEntry( K_SOURCE, IIncludePathEntry.IPE_CONTAINER, containerPath, containerResource, isExported); }
public static IIncludePathEntry newVariableEntry( IPath variablePath, IResource variableResource, boolean isExported) { if (variablePath == null) { throw new IllegalArgumentException("Variable path cannot be null"); // $NON-NLS-1$ } if (variablePath.segmentCount() < 1) { throw new IllegalArgumentException( "Illegal classpath variable path: \'" + variablePath.makeRelative().toString() + "\', must have at least one segment"); //$NON-NLS-1$//$NON-NLS-2$ } return new IncludePathEntry( K_SOURCE, IIncludePathEntry.IPE_VARIABLE, variablePath, variableResource, isExported); }
/** Show a dialog that lets the user select a working directory from the workspace */ private void handleWorkspaceDirBrowseButtonSelected() { IContainer currentContainer = getContainer(); if (currentContainer == null) { currentContainer = ResourcesPlugin.getWorkspace().getRoot(); } ContainerSelectionDialog dialog = new ContainerSelectionDialog( getShell(), currentContainer, false, "Select a workspace relative working directory"); dialog.showClosedProjects(false); dialog.open(); Object[] results = dialog.getResult(); if ((results != null) && (results.length > 0) && (results[0] instanceof IPath)) { IPath path = (IPath) results[0]; String containerName = path.makeRelative().toString(); setOtherWorkingDirectoryText( "${workspace_loc:" + containerName + "}"); // $NON-NLS-1$ //$NON-NLS-2$ } }
private void addBaseString(IPath endPath, CPElement cpentry, StringBuffer str) { IPath baseRef = (IPath) cpentry.getAttribute(CPElement.BASE_REF); if (!baseRef.isEmpty()) { if (baseRef.isAbsolute()) { // str.append("From project "); IPath path = baseRef; if (endPath != null) { path = path.append(endPath); } str.append(path.makeRelative().toPortableString()); } else { // str.append("From contribution "); IPathEntryContainer container; if (endPath != null) { str.append(endPath.toPortableString()); } str.append(" - ("); // $NON-NLS-1$ try { container = CoreModel.getPathEntryContainer(baseRef, cpentry.getCProject()); if (container != null) { str.append(container.getDescription()); } } catch (CModelException e1) { } str.append(')'); } } else { IPath path = (IPath) cpentry.getAttribute(CPElement.BASE); if (!path.isEmpty()) { if (endPath != null) { path = path.append(endPath); } str.insert(0, path.toPortableString()); } else if (endPath != null) { str.insert(0, endPath.toPortableString()); } } }
public String getCPElementText(CPElement cpentry) { IPath path = cpentry.getPath(); switch (cpentry.getEntryKind()) { case IPathEntry.CDT_LIBRARY: { IPath libPath = (IPath) cpentry.getAttribute(CPElement.LIBRARY); StringBuffer str = new StringBuffer(); addBaseString(libPath, cpentry, str); addExport(cpentry, str); addParentInfo(cpentry, str); return str.toString(); } case IPathEntry.CDT_PROJECT: return path.lastSegment(); case IPathEntry.CDT_INCLUDE: { IPath incPath = ((IPath) cpentry.getAttribute(CPElement.INCLUDE)); StringBuffer str = new StringBuffer(); addBaseString(incPath, cpentry, str); addExport(cpentry, str); addParentInfo(cpentry, str); return str.toString(); } case IPathEntry.CDT_INCLUDE_FILE: { IPath incFilePath = ((IPath) cpentry.getAttribute(CPElement.INCLUDE_FILE)); StringBuffer str = new StringBuffer(); addBaseString(incFilePath, cpentry, str); addExport(cpentry, str); addParentInfo(cpentry, str); return str.toString(); } case IPathEntry.CDT_MACRO: { StringBuffer str = new StringBuffer( (String) cpentry.getAttribute(CPElement.MACRO_NAME) + "=" //$NON-NLS-1$ + (String) cpentry.getAttribute(CPElement.MACRO_VALUE)); addBaseString(null, cpentry, str); addExport(cpentry, str); addParentInfo(cpentry, str); return str.toString(); } case IPathEntry.CDT_MACRO_FILE: { IPath macroFilePath = ((IPath) cpentry.getAttribute(CPElement.MACROS_FILE)); StringBuffer str = new StringBuffer(); addBaseString(macroFilePath, cpentry, str); addExport(cpentry, str); addParentInfo(cpentry, str); return str.toString(); } case IPathEntry.CDT_CONTAINER: { StringBuffer str = new StringBuffer(path.toString()); try { IPathEntryContainer container = CoreModel.getPathEntryContainer(cpentry.getPath(), cpentry.getCProject()); if (container != null) { str.setLength(0); str.append(container.getDescription()); } } catch (CModelException e) { } addExport(cpentry, str); return str.toString(); } case IPathEntry.CDT_SOURCE: case IPathEntry.CDT_OUTPUT: { StringBuffer buf = new StringBuffer(path.makeRelative().toString()); IResource resource = cpentry.getResource(); if (resource != null && !resource.exists()) { buf.append(' '); if (cpentry.getStatus().getSeverity() != IStatus.OK) { // only valid error for src/output would missing path... buf.append(fCreateLabel); } else { buf.append(fNewLabel); } } return buf.toString(); } default: // pass } return CPathEntryMessages.CPElementLabelProvider_unknown_element_label; }