Java Code Examples for org.eclipse.core.resources.IFile#isAccessible()

The following examples show how to use org.eclipse.core.resources.IFile#isAccessible() . 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: TestResultsView.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns true and shows an error message if the specified URI cannot be openend. Otherwise, false is returned.
 */
private boolean openErrorIfProblem(URI moduleLocationURI) {
	final IN4JSEclipseProject project = core.findProject(moduleLocationURI).orNull();
	if (project == null || !project.exists()) {
		openError(getShell(), "Cannot open editor", "The container project not found in the workspace.");
		return true;
	}
	final String[] projectRelativeSegments = moduleLocationURI.deresolve(project.getLocation().toURI())
			.segments();
	final String path = Joiner.on(SEPARATOR)
			.join(copyOfRange(projectRelativeSegments, 1, projectRelativeSegments.length));
	final IFile module = project.getProject().getFile(path);
	if (module == null || !module.isAccessible()) {
		openError(getShell(), "Cannot open editor", "Test class not found in selected project.");
		return true;
	}
	return false;
}
 
Example 2
Source File: AbstractRepositoryStore.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Override
public T getChild(final String fileName, boolean force) {
    Assert.isNotNull(fileName);
    final IFile file = getResource().getFile(fileName);
    if (force && !file.isSynchronized(IResource.DEPTH_ONE) && file.isAccessible()) {
        try {
            file.refreshLocal(IResource.DEPTH_ONE, Repository.NULL_PROGRESS_MONITOR);
        } catch (final CoreException e) {
            BonitaStudioLog.error(e);
        }
    }
    if (file.exists()) {
        return createRepositoryFileStore(fileName);
    }

    return null;
}
 
Example 3
Source File: EditorManager.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tries to add the given {@link IFile} to a set of locally opened files. The file gets connected
 * to its {@link IDocumentProvider} (e.g. CompilationUnitDocumentProvider for Java-Files) This
 * Method also converts the line delimiters of the document. Already connected files will not be
 * connected twice.
 */
void connect(final IFile file) {
  if (!file.isAccessible()) {
    log.error(".connect(): file " + file + " could not be accessed");
    return;
  }

  log.trace(".connect(" + file + ") invoked");

  if (isManaged(file)) {
    log.trace("file " + file + " is already connected");
    return;
  }

  if (EditorAPI.connect(new FileEditorInput(file)) != null) {
    connectedFiles.add(file);
  }
}
 
Example 4
Source File: PropertiesFileDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Checks whether the passed file editor input defines a Java properties file.
 * 
 * @param element the file editor input
 * @return <code>true</code> if element defines a Java properties file, <code>false</code>
 *         otherwise
 * @throws CoreException
 * 
 * @since 3.7
 */
public static boolean isJavaPropertiesFile(Object element) throws CoreException {
	if (JAVA_PROPERTIES_FILE_CONTENT_TYPE == null || !(element instanceof IFileEditorInput))
		return false;

	IFileEditorInput input= (IFileEditorInput)element;

	IFile file= input.getFile();
	if (file == null || !file.isAccessible())
		return false;

	IContentDescription description= file.getContentDescription();
	if (description == null || description.getContentType() == null || !description.getContentType().isKindOf(JAVA_PROPERTIES_FILE_CONTENT_TYPE))
		return false;

	return true;
}
 
Example 5
Source File: DeleteEditorFileHandler.java    From eclipse-extras with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute( ExecutionEvent event ) {
  IEditorInput editorInput = HandlerUtil.getActiveEditorInput( event );
  IFile resource = ResourceUtil.getFile( editorInput );
  if( resource != null ) {
    if( resource.isAccessible() ) {
      deleteResource( HandlerUtil.getActiveWorkbenchWindow( event ), resource );
    }
  } else {
    File file = getFile( editorInput );
    IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow( event );
    if( file != null && prompter.confirmDelete( workbenchWindow, file )) {
      deleteFile( workbenchWindow, file );
    }
  }
  return null;
}
 
Example 6
Source File: JsonRpcHelpers.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns an {@link IDocument} for the given {@link IFile}.
 *
 * @param file an {@link IFile}
 * @return a document with the contents of the file,
 * or <code>null</code> if the file can not be opened.
 */
public static IDocument toDocument(IFile file) {
	if (file != null && file.isAccessible()) {
		IPath path = file.getFullPath();
		ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
		LocationKind kind = LocationKind.IFILE;
		try {
			fileBufferManager.connect(path, kind, new NullProgressMonitor());
			ITextFileBuffer fileBuffer = fileBufferManager.getTextFileBuffer(path, kind);
			if (fileBuffer != null) {
				return fileBuffer.getDocument();
			}
		} catch (CoreException e) {
			JavaLanguageServerPlugin.logException("Failed to convert "+ file +"  to an IDocument", e);
		} finally {
			try {
				fileBufferManager.disconnect(path, kind, new NullProgressMonitor());
			} catch (CoreException slurp) {
				//Don't care
			}
		}
	}
	return null;
}
 
Example 7
Source File: Storage2UriMapperImpl.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */ URI uri, IFile file) {
	if (file == null || !file.isAccessible()) {
		Iterable<Pair<IStorage, IProject>> result = contribution.getStorages(uri);
		if (result == null || !result.iterator().hasNext()) {
			 // Handle files external to the workspace. But check contribution first to be backwards compatible.
			if (uri.isFile()) {
				Path filePath = new Path(uri.toFileString());
				IFileStore fileStore = EFS.getLocalFileSystem().getStore(filePath);
				IFileInfo fileInfo = fileStore.fetchInfo();
				if (fileInfo.exists() && !fileInfo.isDirectory()) {
					return Collections.singletonList(
							Tuples.<IStorage, IProject> create(new FileStoreStorage(fileStore, fileInfo, filePath), (IProject) null));
				}
			}
		}
		return result;
	}
	return Collections.singleton(Tuples.<IStorage, IProject> create(file, file.getProject()));
}
 
Example 8
Source File: XpectCompareCommandHandler.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Display comparison view of test file with expected and actual xpect expectation
 */
private void displayComparisonView(ComparisonFailure cf, Description desc) {
	IXpectURIProvider uriProfider = XpectRunner.INSTANCE.getUriProvider();
	IFile fileTest = null;
	if (uriProfider instanceof N4IDEXpectTestURIProvider) {
		N4IDEXpectTestURIProvider fileCollector = (N4IDEXpectTestURIProvider) uriProfider;
		fileTest = ResourcesPlugin.getWorkspace().getRoot()
				.getFileForLocation(new Path(fileCollector.findRawLocation(desc)));
	}

	if (fileTest != null && fileTest.isAccessible()) {
		N4IDEXpectCompareEditorInput inp = new N4IDEXpectCompareEditorInput(fileTest, cf);
		CompareUI.openCompareEditor(inp);
	} else {
		throw new RuntimeException("paths in descriptions changed!");
	}
}
 
Example 9
Source File: FindbugsPlugin.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Get the FindBugs preferences file for a project (which may not exist yet)
 *
 * @param project
 *            the project
 * @return the IFile for the FindBugs preferences file, if any. Can be
 *         "empty" handle if the real file does not exist yet
 */
private static IFile getUserPreferencesFile(IProject project) {
    IFile defaultFile = project.getFile(DEFAULT_PREFS_PATH);
    IFile oldFile = project.getFile(DEPRECATED_PREFS_PATH);
    if (defaultFile.isAccessible() || !oldFile.isAccessible()) {
        return defaultFile;
    }
    return oldFile;
}
 
Example 10
Source File: FindbugsPlugin.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static boolean isProjectSettingsEnabled(IProject project) {
    // fast path: read from session, if available
    Boolean enabled;
    try {
        enabled = (Boolean) project.getSessionProperty(SESSION_PROPERTY_SETTINGS_ON);
    } catch (CoreException e) {
        enabled = null;
    }
    if (enabled != null) {
        return enabled.booleanValue();
    }

    // legacy support: before 1.3.8, there was ONLY project preferences in
    // .fbprefs
    // so check if the file is there...
    IFile file = getUserPreferencesFile(project);
    boolean projectPropsEnabled = file.isAccessible();
    if (projectPropsEnabled) {
        ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(project), PLUGIN_ID);
        // so if the file is there, we can check if after 1.3.8 the flag is
        // set
        // to use workspace properties instead
        projectPropsEnabled = !store.contains(FindBugsConstants.PROJECT_PROPS_DISABLED)
                || !store.getBoolean(FindBugsConstants.PROJECT_PROPS_DISABLED);
    }
    // remember in the session to speedup access, don't touch the store
    setProjectSettingsEnabled(project, null, projectPropsEnabled);
    return projectPropsEnabled;
}
 
Example 11
Source File: ImportedResourceCache.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Refresh local file to avoid deadlock with scheduling rule XtextBuilder ->
 * Editing Domain runexclusive
 */
protected void refreshFile(final URI uri) {
	String platformString = uri.toPlatformString(true);
	if (platformString == null)
		return;
	IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(platformString));
	if (file.isAccessible() && !file.isSynchronized(IResource.DEPTH_INFINITE)) {
		try {
			file.refreshLocal(IResource.DEPTH_INFINITE, null);
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
}
 
Example 12
Source File: DefaultValidationIssueStore.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void connect(Resource resource) {
	if (connected) {
		throw new IllegalStateException("Issue store is already connected to a resource");
	}
	connectedResource = resource;
	IFile file = WorkspaceSynchronizer.getFile(resource);
	if ((file != null) && file.isAccessible()) {
		ResourcesPlugin.getWorkspace().addResourceChangeListener(this);
		connected = true;
	}
	initFromPersistentMarkers();
}
 
Example 13
Source File: DefaultValidationIssueStore.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected List<IMarker> getMarkersOfConnectedResource() {
	List<IMarker> markers = Lists.newArrayList();
	try {
		IFile file = WorkspaceSynchronizer.getFile(connectedResource);
		if ((file != null) && file.isAccessible()) {
			markers.addAll(
					Arrays.asList(file.findMarkers(SCTMarkerType.SUPERTYPE, true, IResource.DEPTH_INFINITE)));
			markers.addAll(
					Arrays.asList(file.findMarkers(SCTMarkerType.SCT_TASK_TYPE, true, IResource.DEPTH_INFINITE)));
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return markers;
}
 
Example 14
Source File: DefaultValidationIssueStore.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void disconnect(Resource resource) {
	IFile file = WorkspaceSynchronizer.getFile(resource);
	if ((file != null) && file.isAccessible()) {
		ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
		connected = false;
		connectedResource = null;
		synchronized (listener) {
			listener.clear();
		}
	}
}
 
Example 15
Source File: ValidatingEMFDatabindingContext.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected IStatus isWriteable() {
	IFile file = WorkspaceSynchronizer.getFile(context.eResource());
	if (file == null || !file.isAccessible())
		return new Status(IStatus.ERROR, DiagramActivator.PLUGIN_ID,
				"File does not exist " + context.eResource().getURI());
	return FileModificationValidator.getInstance().validateEdit(new IFile[] { file }, shell);

}
 
Example 16
Source File: JarPackageData.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Tells whether a manifest is available.
 *
 * @return <code>true</code> if the manifest is generated or the provided one is accessible
 */
public boolean isManifestAccessible() {
	if (isManifestGenerated())
		return true;
	IFile file= getManifestFile();
	return file != null && file.isAccessible();
}
 
Example 17
Source File: JarFileExportOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void saveManifest() throws CoreException, IOException {
	ByteArrayOutputStream manifestOutput= new ByteArrayOutputStream();
	Manifest manifest= fJarPackage.getManifestProvider().create(fJarPackage);
	manifest.write(manifestOutput);
	ByteArrayInputStream fileInput= new ByteArrayInputStream(manifestOutput.toByteArray());
	IFile manifestFile= fJarPackage.getManifestFile();
	if (manifestFile.isAccessible()) {
		if (fJarPackage.allowOverwrite() || JarPackagerUtil.askForOverwritePermission(fParentShell, manifestFile.getFullPath(), false))
			manifestFile.setContents(fileInput, true, true, null);
	} else
		manifestFile.create(fileInput, true, null);
}
 
Example 18
Source File: MarkerEraser.java    From xtext-eclipse with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Checks if a {@link IFile} should/can be processed
 * 
 * @return <code>true</code> if file is accessible and not hidden
 */
public final boolean shouldProcess(final IFile file) {
	return file.isAccessible() && file.getProject().isAccessible() && !file.getProject().isHidden();
}