Java Code Examples for org.eclipse.core.resources.IResource#FILE
The following examples show how to use
org.eclipse.core.resources.IResource#FILE .
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: JavaBuildConfigurationBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private IStatus validateResourceFilters() { String text= getValue(PREF_RESOURCE_FILTER); IWorkspace workspace= ResourcesPlugin.getWorkspace(); String[] filters= getTokens(text, ","); //$NON-NLS-1$ for (int i= 0; i < filters.length; i++) { String fileName= filters[i].replace('*', 'x'); int resourceType= IResource.FILE; int lastCharacter= fileName.length() - 1; if (lastCharacter >= 0 && fileName.charAt(lastCharacter) == '/') { fileName= fileName.substring(0, lastCharacter); resourceType= IResource.FOLDER; } IStatus status= workspace.validateName(fileName, resourceType); if (status.matches(IStatus.ERROR)) { String message= Messages.format(PreferencesMessages.JavaBuildConfigurationBlock_filter_invalidsegment_error, status.getMessage()); return new StatusInfo(IStatus.ERROR, message); } } return new StatusInfo(); }
Example 2
Source File: MetainformationEditor.java From slr-toolkit with Eclipse Public License 1.0 | 6 votes |
/** * Sets bibtex documents and taxonomy input argument's resources as active * elements in ModelRegistry * * @param project * project whose workspace is searched for resources whose file * extensions are checked. Matching .taxonomy and .bib-files are * loaded in the ModelRegistry */ private void initializeWholeProject(IProject project) { initializeEditingDomain(); if (project.isOpen()) { IResource[] resources = null; try { resources = project.members(); } catch (CoreException e) { e.printStackTrace(); return; } for (IResource res : resources) { if (res.getType() == IResource.FILE && "bib".equals(res.getFileExtension())) { URI uri = URI.createURI(((IFile) res).getFullPath().toString()); editingDomain.getResourceSet().getResource(uri, true); } else if (res.getType() == IResource.FILE && "taxonomy".equals(res.getFileExtension())) { ModelRegistryPlugin.getModelRegistry().setTaxonomyFile((IFile) res); } } } }
Example 3
Source File: SarlClassPathDetector.java From sarl with Apache License 2.0 | 6 votes |
@Override public boolean visit(IResourceProxy proxy) { if (this.monitor.isCanceled()) { throw new OperationCanceledException(); } if (proxy.getType() == IResource.FILE) { final String name = proxy.getName(); if (isValidJavaCUName(name)) { visitJavaCompilationUnit((IFile) proxy.requestResource()); } else if (isValidSarlCUName(name)) { visitSarlCompilationUnit((IFile) proxy.requestResource()); } else if (FileSystem.hasExtension(name, ".class")) { //$NON-NLS-1$ this.classFiles.add(proxy.requestResource()); } else if (FileSystem.hasExtension(name, ".jar")) { //$NON-NLS-1$ this.jarFiles.add(proxy.requestFullPath()); } return false; } return true; }
Example 4
Source File: ResourceCloseManagement.java From birt with Eclipse Public License 1.0 | 6 votes |
private static String getResourceType( List<IResource> resources, List<IEditorPart> openedFiles ) { IResource currentResource = resources.get( 0 ); IEditorInput editorInput = openedFiles.get( 0 ).getEditorInput( ); if ( editorInput instanceof FileEditorInput ) { currentResource = ( (FileEditorInput) editorInput ).getFile( ); } switch ( currentResource.getType( ) ) { case IResource.FILE : return openedFiles.size( ) != 1 ? Messages.getString( "renameChecker.closeResourceMessage.forManyFile" ) //$NON-NLS-1$ : currentResource.getName( ) + " " //$NON-NLS-1$ + Messages.getString( "renameChecker.closeResourceMessage.forOneFile" ); //$NON-NLS-1$ case IResource.PROJECT : return Messages.getString( "renameChecker.closeResourceMessage.forProject" ); //$NON-NLS-1$ default : return Messages.getString( "renameChecker.closeResourceMessage.forFolder" ); //$NON-NLS-1$ } }
Example 5
Source File: EclipseBasedShouldGenerate.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override public boolean shouldGenerate(Resource resource, CancelIndicator cancelIndicator) { URI uri = resource.getURI(); if (uri == null || !uri.isPlatformResource()) { return false; } IResource member = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(uri.toPlatformString(true))); if (member != null && member.getType() == IResource.FILE) { ProjectConfigAdapter projectConfigAdapter = ProjectConfigAdapter.findInEmfObject(resource.getResourceSet()); if (projectConfigAdapter != null) { IProjectConfig projectConfig = projectConfigAdapter.getProjectConfig(); if (projectConfig != null && Objects.equals(member.getProject().getName(), projectConfig.getName())) { try { return member.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE) != IMarker.SEVERITY_ERROR; } catch (CoreException e) { LOG.error("The resource " + member.getName() + " does not exist", e); return false; } } } } return false; }
Example 6
Source File: JarFileExportOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Iterator<IResource> getClassesIn(IContainer classContainer) throws CoreException { IResource[] resources= classContainer.members(); List<IResource> files= new ArrayList<IResource>(resources.length); for (int i= 0; i < resources.length; i++) if (resources[i].getType() == IResource.FILE && isClassFile(resources[i])) files.add(resources[i]); return files.iterator(); }
Example 7
Source File: OrganizeImportsCommand.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
public Object organizeImports(List<Object> arguments) throws CoreException { WorkspaceEdit edit = new WorkspaceEdit(); if (arguments != null && !arguments.isEmpty() && arguments.get(0) instanceof String) { final String fileUri = (String) arguments.get(0); final IPath rootPath = ResourceUtils.filePathFromURI(fileUri); if (rootPath == null) { throw new CoreException(new Status(IStatus.ERROR, IConstants.PLUGIN_ID, "URI is not found")); } final IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = wsroot.getFileForLocation(rootPath); if (resource == null) { resource = wsroot.getContainerForLocation(rootPath); } if (resource != null) { final OrganizeImportsCommand command = new OrganizeImportsCommand(); int type = resource.getType(); switch (type) { case IResource.PROJECT: edit = command.organizeImportsInProject(resource.getAdapter(IProject.class)); break; case IResource.FOLDER: edit = command.organizeImportsInDirectory(fileUri, resource.getProject()); break; case IResource.FILE: edit = command.organizeImportsInFile(fileUri); break; default://This can only be IResource.ROOT. Which is not relevant to jdt.ls // do nothing allow to return the empty WorkspaceEdit. break; } } } return edit; }
Example 8
Source File: PackagesViewLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private String getHierarchicalText(IPackageFragment fragment) { if (fragment.isDefaultPackage()) { return super.getText(fragment); } IResource res= fragment.getResource(); if(res != null && !(res.getType() == IResource.FILE)) return decorateText(res.getName(), fragment); else return decorateText(calculateName(fragment), fragment); }
Example 9
Source File: StatusCacheManager.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Refresh the status of the given resource to the give depth. The depth can * be deeper in case of phantom resources. These have to be traversed to * infinite always ... * * @param resource * @param recursive * @return array of resources which were refreshed (including all phantoms * and their children) * @throws SVNException */ public IResource[] refreshStatus(final IResource resource, final boolean recursive) throws SVNException { if (SVNWorkspaceRoot.isLinkedResource(resource)) { return new IResource[0]; } final int depth = (recursive) ? IResource.DEPTH_INFINITE : IResource.DEPTH_ONE; final StatusUpdateStrategy strategy = (depth == IResource.DEPTH_INFINITE) ? (StatusUpdateStrategy) new RecursiveStatusUpdateStrategy(statusCache) : (StatusUpdateStrategy) new NonRecursiveStatusUpdateStrategy(statusCache); try { List<IResource> refreshedResources = updateCache(resource, strategy.statusesToUpdate(resource)); Set<IResource> resourcesToRefresh = resourcesToRefresh(resource, depth, IContainer.INCLUDE_PHANTOMS, refreshedResources.size()); for (Iterator<IResource> iter = refreshedResources.iterator(); iter.hasNext();) { resourcesToRefresh.remove(iter.next()); } //Resources which were not refreshed above (e.g. deleted resources) //We do it with depth = infinite, so the whole deleted trees are refreshed. for (IResource res : resourcesToRefresh) { if ((res.getType() != IResource.FILE) && res.isPhantom()) { Set<IResource> children = resourcesToRefresh(res, IResource.DEPTH_INFINITE, IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS, 0); for (IResource child : children) { statusCache.removeStatus(child); refreshedResources.add(child); } } statusCache.removeStatus(res); refreshedResources.add(res); } return (IResource[]) refreshedResources.toArray(new IResource[refreshedResources.size()]); } catch (CoreException e) { throw SVNException.wrapException(e); } }
Example 10
Source File: ProjectBasedModelManager.java From goclipse with Eclipse Public License 1.0 | 5 votes |
public boolean resourceIsManifest(IResource resource) { if(resource == null || resource.getType() != IResource.FILE) { return false; } try { Location projectLoc = ResourceUtils.getLocation(resource.getProject()); Location resourceLoc = ResourceUtils.getLocation(resource); return areEqual(new BundlePath(projectLoc).getManifestLocation(true), resourceLoc); } catch(CommonException e) { return false; } }
Example 11
Source File: SVNWorkspaceRoot.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * get the SVNLocalResource for the given resource */ public static ISVNLocalResource getSVNResourceFor(IResource resource) { if (resource.getType() == IResource.FILE) return getSVNFileFor((IFile) resource); else // container return getSVNFolderFor((IContainer) resource); }
Example 12
Source File: WizardExportResourcesPage2.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Set up the selection values for the resources and put them in the selectionMap. If a resource is a file see if it * matches one of the selected extensions. If not then check the children. */ private void setupSelectionsBasedOnSelectedTypes(Map selectionMap, IContainer parent) { List selections = new ArrayList(); IResource[] resources; boolean hasFiles = false; try { resources = parent.members(); } catch (CoreException exception) { // Just return if we can't get any info return; } for (int i = 0; i < resources.length; i++) { IResource resource = resources[i]; if (resource.getType() == IResource.FILE) { if (hasExportableExtension(resource.getName())) { hasFiles = true; selections.add(resource); } } else { setupSelectionsBasedOnSelectedTypes(selectionMap, (IContainer) resource); } } // Only add it to the list if there are files in this folder if (hasFiles) { selectionMap.put(parent, selections); } }
Example 13
Source File: ResourceDropAdapterAssistant.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Returns the actual target of the drop, given the resource under the * mouse. If the mouse target is a file, then the drop actually occurs in * its parent. If the drop location is before or after the mouse target and * feedback is enabled, the target is also the parent. */ private IContainer getActualTarget(IResource mouseTarget) { /* if cursor is on a file, return the parent */ if (mouseTarget.getType() == IResource.FILE) { return mouseTarget.getParent(); } /* otherwise the mouseTarget is the real target */ return (IContainer) mouseTarget; }
Example 14
Source File: MoveModifications.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public void buildValidateEdits(ValidateEditChecker checker) { for (Iterator<Object> iter= fMoves.iterator(); iter.hasNext();) { Object element= iter.next(); if (element instanceof ICompilationUnit) { ICompilationUnit unit= (ICompilationUnit)element; IResource resource= unit.getResource(); if (resource != null && resource.getType() == IResource.FILE) { checker.addFile((IFile)resource); } } } }
Example 15
Source File: PythonRunnerConfig.java From Pydev with Eclipse Public License 1.0 | 4 votes |
public boolean isFile() throws CoreException { int resourceType = configuration.getAttribute(Constants.ATTR_RESOURCE_TYPE, -1); return resourceType == IResource.FILE; }
Example 16
Source File: DetailViewModelWizard.java From neoscada with Eclipse Public License 1.0 | 4 votes |
/** * The framework calls this to create the contents of the wizard. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void addPages () { // Create a page, set the title, and the initial model file name. // newFileCreationPage = new DetailViewModelWizardNewFileCreationPage ( "Whatever", selection ); //$NON-NLS-1$ newFileCreationPage.setTitle ( DetailViewEditorPlugin.INSTANCE.getString ( "_UI_DetailViewModelWizard_label" ) ); //$NON-NLS-1$ newFileCreationPage.setDescription ( DetailViewEditorPlugin.INSTANCE.getString ( "_UI_DetailViewModelWizard_description" ) ); //$NON-NLS-1$ newFileCreationPage.setFileName ( DetailViewEditorPlugin.INSTANCE.getString ( "_UI_DetailViewEditorFilenameDefaultBase" ) + "." + FILE_EXTENSIONS.get ( 0 ) ); //$NON-NLS-1$ //$NON-NLS-2$ addPage ( newFileCreationPage ); // Try and get the resource selection to determine a current directory for the file dialog. // if ( selection != null && !selection.isEmpty () ) { // Get the resource... // Object selectedElement = selection.iterator ().next (); if ( selectedElement instanceof IResource ) { // Get the resource parent, if its a file. // IResource selectedResource = (IResource)selectedElement; if ( selectedResource.getType () == IResource.FILE ) { selectedResource = selectedResource.getParent (); } // This gives us a directory... // if ( selectedResource instanceof IFolder || selectedResource instanceof IProject ) { // Set this for the container. // newFileCreationPage.setContainerFullPath ( selectedResource.getFullPath () ); // Make up a unique new name here. // String defaultModelBaseFilename = DetailViewEditorPlugin.INSTANCE.getString ( "_UI_DetailViewEditorFilenameDefaultBase" ); //$NON-NLS-1$ String defaultModelFilenameExtension = FILE_EXTENSIONS.get ( 0 ); String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; //$NON-NLS-1$ for ( int i = 1; ( (IContainer)selectedResource ).findMember ( modelFilename ) != null; ++i ) { modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; //$NON-NLS-1$ } newFileCreationPage.setFileName ( modelFilename ); } } } initialObjectCreationPage = new DetailViewModelWizardInitialObjectCreationPage ( "Whatever2" ); //$NON-NLS-1$ initialObjectCreationPage.setTitle ( DetailViewEditorPlugin.INSTANCE.getString ( "_UI_DetailViewModelWizard_label" ) ); //$NON-NLS-1$ initialObjectCreationPage.setDescription ( DetailViewEditorPlugin.INSTANCE.getString ( "_UI_Wizard_initial_object_description" ) ); //$NON-NLS-1$ addPage ( initialObjectCreationPage ); }
Example 17
Source File: ProfileModelWizard.java From neoscada with Eclipse Public License 1.0 | 4 votes |
/** * The framework calls this to create the contents of the wizard. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void addPages () { // Create a page, set the title, and the initial model file name. // newFileCreationPage = new ProfileModelWizardNewFileCreationPage ( "Whatever", selection ); //$NON-NLS-1$ newFileCreationPage.setTitle ( WorldEditorPlugin.INSTANCE.getString ( "_UI_ProfileModelWizard_label" ) ); //$NON-NLS-1$ newFileCreationPage.setDescription ( WorldEditorPlugin.INSTANCE.getString ( "_UI_ProfileModelWizard_description" ) ); //$NON-NLS-1$ newFileCreationPage.setFileName ( WorldEditorPlugin.INSTANCE.getString ( "_UI_ProfileEditorFilenameDefaultBase" ) + "." + FILE_EXTENSIONS.get ( 0 ) ); //$NON-NLS-1$ //$NON-NLS-2$ addPage ( newFileCreationPage ); // Try and get the resource selection to determine a current directory for the file dialog. // if ( selection != null && !selection.isEmpty () ) { // Get the resource... // Object selectedElement = selection.iterator ().next (); if ( selectedElement instanceof IResource ) { // Get the resource parent, if its a file. // IResource selectedResource = (IResource)selectedElement; if ( selectedResource.getType () == IResource.FILE ) { selectedResource = selectedResource.getParent (); } // This gives us a directory... // if ( selectedResource instanceof IFolder || selectedResource instanceof IProject ) { // Set this for the container. // newFileCreationPage.setContainerFullPath ( selectedResource.getFullPath () ); // Make up a unique new name here. // String defaultModelBaseFilename = WorldEditorPlugin.INSTANCE.getString ( "_UI_ProfileEditorFilenameDefaultBase" ); //$NON-NLS-1$ String defaultModelFilenameExtension = FILE_EXTENSIONS.get ( 0 ); String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; //$NON-NLS-1$ for ( int i = 1; ( (IContainer)selectedResource ).findMember ( modelFilename ) != null; ++i ) { modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; //$NON-NLS-1$ } newFileCreationPage.setFileName ( modelFilename ); } } } initialObjectCreationPage = new ProfileModelWizardInitialObjectCreationPage ( "Whatever2" ); //$NON-NLS-1$ initialObjectCreationPage.setTitle ( WorldEditorPlugin.INSTANCE.getString ( "_UI_ProfileModelWizard_label" ) ); //$NON-NLS-1$ initialObjectCreationPage.setDescription ( WorldEditorPlugin.INSTANCE.getString ( "_UI_Wizard_initial_object_description" ) ); //$NON-NLS-1$ addPage ( initialObjectCreationPage ); }
Example 18
Source File: ComponentModelWizard.java From neoscada with Eclipse Public License 1.0 | 4 votes |
/** * The framework calls this to create the contents of the wizard. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ @Override public void addPages () { // Create a page, set the title, and the initial model file name. // newFileCreationPage = new ComponentModelWizardNewFileCreationPage ( "Whatever", selection ); //$NON-NLS-1$ newFileCreationPage.setTitle ( ComponentEditorPlugin.INSTANCE.getString ( "_UI_ComponentModelWizard_label" ) ); //$NON-NLS-1$ newFileCreationPage.setDescription ( ComponentEditorPlugin.INSTANCE.getString ( "_UI_ComponentModelWizard_description" ) ); //$NON-NLS-1$ newFileCreationPage.setFileName ( ComponentEditorPlugin.INSTANCE.getString ( "_UI_ComponentEditorFilenameDefaultBase" ) + "." + FILE_EXTENSIONS.get ( 0 ) ); //$NON-NLS-1$ //$NON-NLS-2$ addPage ( newFileCreationPage ); // Try and get the resource selection to determine a current directory for the file dialog. // if ( selection != null && !selection.isEmpty () ) { // Get the resource... // Object selectedElement = selection.iterator ().next (); if ( selectedElement instanceof IResource ) { // Get the resource parent, if its a file. // IResource selectedResource = (IResource)selectedElement; if ( selectedResource.getType () == IResource.FILE ) { selectedResource = selectedResource.getParent (); } // This gives us a directory... // if ( selectedResource instanceof IFolder || selectedResource instanceof IProject ) { // Set this for the container. // newFileCreationPage.setContainerFullPath ( selectedResource.getFullPath () ); // Make up a unique new name here. // String defaultModelBaseFilename = ComponentEditorPlugin.INSTANCE.getString ( "_UI_ComponentEditorFilenameDefaultBase" ); //$NON-NLS-1$ String defaultModelFilenameExtension = FILE_EXTENSIONS.get ( 0 ); String modelFilename = defaultModelBaseFilename + "." + defaultModelFilenameExtension; //$NON-NLS-1$ for ( int i = 1; ( (IContainer)selectedResource ).findMember ( modelFilename ) != null; ++i ) { modelFilename = defaultModelBaseFilename + i + "." + defaultModelFilenameExtension; //$NON-NLS-1$ } newFileCreationPage.setFileName ( modelFilename ); } } } initialObjectCreationPage = new ComponentModelWizardInitialObjectCreationPage ( "Whatever2" ); //$NON-NLS-1$ initialObjectCreationPage.setTitle ( ComponentEditorPlugin.INSTANCE.getString ( "_UI_ComponentModelWizard_label" ) ); //$NON-NLS-1$ initialObjectCreationPage.setDescription ( ComponentEditorPlugin.INSTANCE.getString ( "_UI_Wizard_initial_object_description" ) ); //$NON-NLS-1$ addPage ( initialObjectCreationPage ); }
Example 19
Source File: JarFileExportOperation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 3 votes |
/** * Answers whether the given resource is a class file. * The resource must be a file whose file name ends with ".class". * * @param file the file to test * @return a <code>true<code> if the given resource is a class file */ private boolean isClassFile(IResource file) { return file != null && file.getType() == IResource.FILE && file.getFileExtension() != null && file.getFileExtension().equalsIgnoreCase("class"); //$NON-NLS-1$ }
Example 20
Source File: Util.java From spotbugs with GNU Lesser General Public License v2.1 | 3 votes |
/** * Checks whether the given resource is a Java source file. * * @param resource * The resource to check. * @return <code>true</code> if the given resource is a Java source file, * <code>false</code> otherwise. */ public static boolean isJavaFile(IResource resource) { if (resource == null || (resource.getType() != IResource.FILE)) { return false; } String ex = resource.getFileExtension(); return "java".equalsIgnoreCase(ex); //$NON-NLS-1$ }