Java Code Examples for org.eclipse.core.resources.IContainer#findMember()
The following examples show how to use
org.eclipse.core.resources.IContainer#findMember() .
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: RenameFolderDialog.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private void validateNewFolderName() { String newFolderName = fNewFolderNameText.getText(); IWorkspace workspace = fFolder.getResource().getWorkspace(); IStatus nameStatus = workspace.validateName(newFolderName, IResource.FOLDER); if ("".equals(newFolderName)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IContainer parentFolder = fFolder.getResource().getParent(); if (parentFolder.findMember(newFolderName) != null) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 2
Source File: PythonModuleWizard.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override protected AbstractPythonWizardPage createPathPage() { return new AbstractPythonWizardPage(this.description, selection) { @Override protected boolean shouldCreatePackageSelect() { return true; } @Override protected String checkNameText(String text) { String result = super.checkNameText(text); if (result != null) { return result; } IContainer p = getValidatedPackage(); if (p != null && p.findMember(text.concat(".py")) != null) { return "The module " + text + " already exists in " + p.getName() + "."; } return null; } }; }
Example 3
Source File: OverwriteHelper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean willOverwrite(IResource resource) { if (resource == null) return false; IResource destinationResource= ResourceUtil.getResource(fDestination); if (destinationResource.equals(resource.getParent())) return false; if (destinationResource instanceof IContainer) { IContainer container= (IContainer)destinationResource; IResource member= container.findMember(resource.getName()); if (member == null || !member.exists()) return false; return true; } return false; }
Example 4
Source File: ImportConflictHandler.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private static String rename(IPath tracePath) { IResource existingResource = getExistingResource(tracePath); if (existingResource == null) { return tracePath.lastSegment(); } // Not using IFolder on purpose to leave the door open to import // directly into an IProject IContainer folder = existingResource.getParent(); int i = 2; while (true) { String name = existingResource.getName() + '(' + Integer.toString(i++) + ')'; IResource resource = folder.findMember(name); if (resource == null) { return name; } } }
Example 5
Source File: DropAdapterAssistant.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Prompts the user to rename a trace * * @param element the conflicting element * @return the new name to use or null if rename is canceled */ private static String promptRename(ITmfProjectModelElement element) { MessageBox mb = new MessageBox(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.ICON_QUESTION | SWT.CANCEL | SWT.OK); mb.setText(Messages.DropAdapterAssistant_RenameTraceTitle); mb.setMessage(NLS.bind(Messages.DropAdapterAssistant_RenameTraceMessage, element.getName())); if (mb.open() != SWT.OK) { return null; } IContainer folder = element.getResource().getParent(); int i = 2; while (true) { String name = element.getName() + '(' + Integer.toString(i++) + ')'; IResource resource = folder.findMember(name); if (resource == null) { return name; } } }
Example 6
Source File: RenameTraceDialog.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
private void validateNewTraceName() { String newTraceName = fNewTraceNameText.getText(); IWorkspace workspace = fTrace.getResource().getWorkspace(); IStatus nameStatus = workspace.validateName(newTraceName, IResource.FOLDER); if ("".equals(newTraceName)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IContainer parentFolder = fTrace.getResource().getParent(); if (parentFolder.findMember(newTraceName) != null) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 7
Source File: OverwriteHelper.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private boolean willOverwrite(IResource resource) { if (resource == null) { return false; } IResource destinationResource= ResourceUtil.getResource(fDestination); if (destinationResource.equals(resource.getParent())) { return false; } if (destinationResource instanceof IContainer) { IContainer container= (IContainer)destinationResource; IResource member= container.findMember(resource.getName()); if (member == null || !member.exists()) { return false; } return true; } return false; }
Example 8
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public static IResource getFileOrFolder(String uriString) { IFile file = findFile(uriString); // This may return IFile even when uriString really describes a IContainer IContainer parent = file == null ? null : file.getParent(); if (parent == null) { return file; } try { parent.refreshLocal(DEPTH_ONE, null); } catch (CoreException e) { // Ignore } if (parent.findMember(file.getName()) instanceof IFolder) { return findFolder(uriString); } return file; }
Example 9
Source File: ViewerManager.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Determines the Resource which should be shown. Respects partial builds. * @return * @throws CoreException */ public static IResource getOuputResource(IProject project) throws CoreException { String outFileName = TexlipseProperties.getOutputFileName(project); if (outFileName == null || outFileName.length() == 0) { throw new CoreException(TexlipsePlugin.stat("Empty output file name.")); } // find out the directory where the file should be IContainer outputDir = null; // String fmtProp = TexlipseProperties.getProjectProperty(project, // TexlipseProperties.OUTPUT_FORMAT); // if (registry.getFormat().equals(fmtProp)) { outputDir = TexlipseProperties.getProjectOutputDir(project); /* } else { String base = outFileName.substring(0, outFileName.lastIndexOf('.') + 1); outFileName = base + registry.getFormat(); outputDir = TexlipseProperties.getProjectTempDir(project); }*/ if (outputDir == null) { outputDir = project; } IResource resource = outputDir.findMember(outFileName); return resource != null ? resource : project.getFile(outFileName); }
Example 10
Source File: TexBuilder.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Find a handle to the index file of this project. * @param project the current project * @param source buildable resource inside project * @return handle to index file or null if not found. * Returns null also if the index file is older than the current output file */ private IResource findNomencl(IProject project, IResource source) { IContainer srcDir = TexlipseProperties.getProjectSourceDir(project); if (srcDir == null) { srcDir = project; } String name = source.getName(); String nomenclName = name.substring(0, name.length() - source.getFileExtension().length()) + TexlipseProperties.INPUT_FORMAT_NOMENCL; IResource idxFile = srcDir.findMember(nomenclName); if (idxFile == null) { return null; } IResource outFile = TexlipseProperties.getProjectOutputFile(project); if (outFile.getLocalTimeStamp() > idxFile.getLocalTimeStamp()) { return null; } return idxFile; }
Example 11
Source File: TexBuilder.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Find a handle to the index file of this project. * @param project the current project * @param source buildable resource inside project * @return handle to index file or null if not found. * Returns null also if the index file is older than the current output file */ private IResource findIndex(IProject project, IResource source) { IContainer srcDir = TexlipseProperties.getProjectSourceDir(project); if (srcDir == null) { srcDir = project; } String name = source.getName(); String idxName = name.substring(0, name.length() - source.getFileExtension().length()) + TexlipseProperties.INPUT_FORMAT_IDX; IResource idxFile = srcDir.findMember(idxName); if (idxFile == null) { return null; } IResource outFile = TexlipseProperties.getProjectOutputFile(project); if (outFile.getLocalTimeStamp() > idxFile.getLocalTimeStamp()) { return null; } return idxFile; }
Example 12
Source File: BibtexRunner.java From texlipse with Eclipse Public License 1.0 | 6 votes |
/** * Parse a Bibtex error message from the given line. * Create also an error marker to the right place. * * @param sourceDir directory containing project's source files * @param line the error message line */ private void parseErrorLine(IContainer sourceDir, String line) { int index = line.indexOf("---line "); int index2 = line.indexOf(" of file ", index); String lineNumberString = line.substring(index+8, index2); Integer lineNumber = null; try { int num = Integer.parseInt(lineNumberString); lineNumber = new Integer(num); } catch (NumberFormatException e) { } String fileName = line.substring(index2+9); IResource resource = sourceDir.findMember(fileName); String error = line.substring(0, index); createMarker(resource, lineNumber, error); }
Example 13
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public static boolean isFolder(String uriString) { IFile fakeFile = findFile(uriString); // This may return IFile even when uriString really describes a IContainer IContainer parent = fakeFile == null ? null : fakeFile.getParent(); if (parent == null) { return false; } if (!parent.isSynchronized(DEPTH_ONE)) { try { parent.refreshLocal(DEPTH_ONE, null); } catch (CoreException e) { // Ignore } } return (parent.findMember(fakeFile.getName()) instanceof IFolder); }
Example 14
Source File: TrimTraceDialog.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private void validateNewTraceName() { String newTraceName = fNewElementName.getText(); TmfCommonProjectElement element = fElement; IWorkspace workspace = element.getResource().getWorkspace(); IStatus nameStatus = workspace.validateName(newTraceName, IResource.FOLDER); if ("".equals(newTraceName)) { //$NON-NLS-1$ updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_EmptyNameError, null)); return; } if (!nameStatus.isOK()) { updateStatus(nameStatus); return; } IContainer parentFolder = element.getResource().getParent(); if (parentFolder.findMember(newTraceName) != null) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } TmfTraceFolder tracesFolderElement = element.getProject().getTracesFolder(); if (tracesFolderElement != null) { IFolder tracesFolder = tracesFolderElement.getResource(); IPath traceDestinationPath = new Path(newTraceName); if (tracesFolder.getFolder(traceDestinationPath).exists()) { updateStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, Messages.Dialog_ExistingNameError, null)); return; } } updateStatus(new Status(IStatus.OK, Activator.PLUGIN_ID, "")); //$NON-NLS-1$ }
Example 15
Source File: WorkspaceFile.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
private IResource ensureResource(Class<? extends IResource> resourceClass) throws CoreException { if (resource != null && (!resource.isSynchronized(IResource.DEPTH_ZERO) || !resource.exists())) { resource = null; localFileStore = null; } if (resource == null) { IContainer container = workspaceRoot; if (path.segmentCount() > 2) { container = workspaceRoot.getFolder(path.removeLastSegments(1)); } else if (path.segmentCount() == 2) { container = workspaceRoot.getProject(path.segment(0)); } if (path.isRoot()) { resource = workspaceRoot; } else { resource = container.findMember(path.lastSegment()); } if (resource == null) { if (IFile.class.equals(resourceClass)) { resource = workspaceRoot.getFile(path); } else if (IFolder.class.equals(resourceClass)) { resource = workspaceRoot.getFolder(path); } } if (resourceClass != null && !resourceClass.isInstance(resource)) { resource = null; Policy.error(EFS.ERROR_WRONG_TYPE, NLS.bind(Messages.failedCreateWrongType, path)); } } return resource; }
Example 16
Source File: ReorgPolicyFactory.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
private static boolean isNewNameOk(IContainer container, String newName) { return container.findMember(newName) == null; }
Example 17
Source File: LatexRunner.java From texlipse with Eclipse Public License 1.0 | 4 votes |
/** * Adds a problem marker * * @param error The error or warning string * @param causingSourceFile name of the sourcefile * @param linenr where the error occurs * @param severity * @param resource * @param layout true, if this is a layout warning */ private void addProblemMarker(String error, String causingSourceFile, int linenr, int severity, IResource resource, boolean layout) { IProject project = resource.getProject(); IContainer sourceDir = TexlipseProperties.getProjectSourceDir(project); IResource extResource = null; if (causingSourceFile != null) { IPath p = new Path(causingSourceFile); if (p.isAbsolute()) { //Make absolute path relative to source directory //or to the directory of the resource if (sourceDir.getLocation().isPrefixOf(p)) { p = p.makeRelativeTo(sourceDir.getLocation()); } else if (resource.getParent().getLocation().isPrefixOf(p)) { p = p.makeRelativeTo(resource.getParent().getLocation()); } } extResource = sourceDir.findMember(p); if (extResource == null) { extResource = resource.getParent().findMember(p); } } if (extResource == null) createMarker(resource, null, error + (causingSourceFile != null ? " (Occurance: " + causingSourceFile + ")" : ""), severity); else { if (linenr >= 0) { if (layout) createLayoutMarker(extResource, new Integer(linenr), error); else createMarker(extResource, new Integer(linenr), error, severity); } else createMarker(extResource, null, error, severity); } }
Example 18
Source File: ReorgPolicyFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static boolean isNewNameOk(IContainer container, String newName) { return container.findMember(newName) == null; }
Example 19
Source File: H5ResourcePage.java From dawnsci with Eclipse Public License 1.0 | 4 votes |
/** * Ensures that both text fields are set. */ private void dialogChanged() { final IContainer container = getProjectContainer(); if (container==null) { updateStatus("Please select a valid parent project."); return; } if (choice == RESOURCE_CHOICE.PROJECT_AND_EXTERNAL_FOLDER) { final File dir = getExternalFolder(); if (dir==null) { updateStatus("Please select a valid import folder."); return; } if (!dir.exists()) { updateStatus("Please select an existing folder."); return; } if (!dir.isDirectory()) { updateStatus("Please select directory not a file."); return; } if (container.getFolder(new Path(container.getFullPath().toPortableString()+"/"+dir.getName())).exists()) { updateStatus("Please select a folder not existing or delete the existing folder with the name '"+dir.getName()+"'"); return; } } if (choice == RESOURCE_CHOICE.PROJECT_AND_NAME) { final String seqName = getSequenceName(); if (seqName==null) { updateStatus("Please set a name for the resource to create."); return; } if (!seqName.endsWith(getFileExtension(defaultName))) { updateStatus("The sequence name must end with '"+getFileExtension(defaultName)+"'"); return; } if (container.findMember(seqName)!=null) { updateStatus("The file '"+seqName+"' already exists."); return; } } updateStatus(null); }