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

The following examples show how to use org.eclipse.core.resources.IResource#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: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) throws JavaModelException {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	if (!resource.isAccessible())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);

	if (resource.getType() == IResource.ROOT)
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (isChildOfOrEqualToAnyFolder(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);

	return new RefactoringStatus();
}
 
Example 2
Source File: TestsRunner.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isInteresting(final IProject p) throws CoreException {
	if (p == null || !p.exists() || !p.isAccessible())
		return false;
	// If it is contained in one of the built-in tests projects, return true
	if (p.getDescription().hasNature(WorkbenchHelper.TEST_NATURE))
		return true;
	if (GamaPreferences.Runtime.USER_TESTS.getValue()) {
		// If it is not in user defined projects, return false
		if (p.getDescription().hasNature(WorkbenchHelper.BUILTIN_NATURE))
			return false;
		// We try to find in the project a folder called 'tests'
		final IResource r = p.findMember("tests");
		if (r != null && r.exists() && r.isAccessible() && r.getType() == IResource.FOLDER)
			return true;
	}
	return false;
}
 
Example 3
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	if (!resource.isAccessible())
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);

	if (!(resource instanceof IContainer))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (resource.getType() == IResource.ROOT)
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (isChildOfOrEqualToAnyFolder(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource))
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);

	return new RefactoringStatus();
}
 
Example 4
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) throws JavaModelException {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	}
	if (!resource.isAccessible()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);
	}

	if (resource.getType() == IResource.ROOT) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (isChildOfOrEqualToAnyFolder(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);
	}

	return new RefactoringStatus();
}
 
Example 5
Source File: PySearchIndexPage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void checkSelectedResource(Collection<String> projectNames, Collection<String> moduleNames,
        IResource resource) {
    if (resource != null && resource.isAccessible()) {
        IProject project = resource.getProject();
        projectNames.add(project.getName());
        PythonNature nature = PythonNature.getPythonNature(project);
        if (nature == null) {
            return;
        }
        String moduleName;
        try {
            moduleName = nature.resolveModule(resource);
        } catch (MisconfigurationException e) {
            Log.log(e);
            return;
        }
        if (moduleName != null) {
            for (String s : moduleNames) {
                if (s.endsWith(".*")) {
                    if (moduleName.startsWith(s.substring(0, s.length() - 1))) {
                        //There's already another one which includes what we're about to add.
                        return;
                    }
                }
            }
            if (resource instanceof IContainer) {
                moduleNames.add(moduleName + ".*");
            } else {
                moduleNames.add(moduleName);
            }
        }
    }
}
 
Example 6
Source File: DerivedResourceMarkers.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
@Override
public IMarker[] findDerivedResourceMarkers(IResource file) throws CoreException {
	if (!file.isAccessible())
		return new IMarker[0];
	return file.findMarkers(MARKER_ID, true, IResource.DEPTH_INFINITE);
}
 
Example 7
Source File: NewEntryPointWizardPage.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void initEntryPointPage(IResource resource) {
  if (resource.getType() == IResource.ROOT || !resource.isAccessible()) {
    return;
  }

  if (moduleField.init(resource)) {
    // Initialize the package based on the module's client source path
    if (moduleStatus.isOK()) {
      initPackageFromModule();
    } else {
      // If initializing the module caused an error, reset it
      moduleField.setText("");
    }
  }
}
 
Example 8
Source File: WorkspaceAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The <code>WorkspaceAction</code> implementation of this
 * <code>SelectionListenerAction</code> method ensures that this action is
 * disabled if any of the selected resources are inaccessible. Subclasses may
 * extend to react to selection changes; however, if the super method returns
 * <code>false</code>, the overriding method should also return <code>false</code>.
 */
@Override
protected boolean updateSelection(IStructuredSelection selection) {
    if (!super.updateSelection(selection) || selection.isEmpty()) {
        return false;
    }
    for (Iterator<? extends IResource> i = getSelectedResources().iterator(); i.hasNext();) {
        IResource r = i.next();
        if (!r.isAccessible()) {
            return false;
        }
    }
    return true;
}
 
Example 9
Source File: ProblemHover.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ICompilationUnit getCompilationUnit(IMarker marker) {
	IResource res= marker.getResource();
	if (res instanceof IFile && res.isAccessible()) {
		IJavaElement element= JavaCore.create((IFile) res);
		if (element instanceof ICompilationUnit)
			return (ICompilationUnit) element;
	}
	return null;
}
 
Example 10
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	}
	if (!resource.isAccessible()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);
	}

	if (!(resource instanceof IContainer)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (resource.getType() == IResource.ROOT) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (isChildOfOrEqualToAnyFolder(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);
	}

	return new RefactoringStatus();
}
 
Example 11
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected RefactoringStatus verifyDestination(IResource resource) {
	Assert.isNotNull(resource);
	if (!resource.exists() || resource.isPhantom()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_phantom);
	}
	if (!resource.isAccessible()) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_inaccessible);
	}

	if (!(resource instanceof IContainer)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (resource.getType() == IResource.ROOT) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (isChildOfOrEqualToAnyFolder(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_not_this_resource);
	}

	if (containsLinkedResources() && !ReorgUtils.canBeDestinationForLinkedResources(resource)) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_linked);
	}

	return new RefactoringStatus();
}
 
Example 12
Source File: ProblemsLabelDecorator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private int getErrorTicksFromMarkers(IResource res, int depth, ISourceReference sourceElement) throws CoreException {
	if (res == null || !res.isAccessible()) {
		return 0;
	}
	int severity= 0;
	if (sourceElement == null) {
		if (res instanceof IProject) {
			severity= res.findMaxProblemSeverity(IJavaModelMarker.BUILDPATH_PROBLEM_MARKER, true, IResource.DEPTH_ZERO);
			if (severity == IMarker.SEVERITY_ERROR) {
				return ERRORTICK_BUILDPATH_ERROR;
			}
			severity= res.findMaxProblemSeverity(JavaRuntime.JRE_CONTAINER_MARKER, true, IResource.DEPTH_ZERO);
			if (severity == IMarker.SEVERITY_ERROR) {
				return ERRORTICK_BUILDPATH_ERROR;
			}
		}
		severity= res.findMaxProblemSeverity(IMarker.PROBLEM, true, depth);
	} else {
		IMarker[] markers= res.findMarkers(IMarker.PROBLEM, true, depth);
		if (markers != null && markers.length > 0) {
			for (int i= 0; i < markers.length && (severity != IMarker.SEVERITY_ERROR); i++) {
				IMarker curr= markers[i];
				if (isMarkerInRange(curr, sourceElement)) {
					int val= curr.getAttribute(IMarker.SEVERITY, -1);
					if (val == IMarker.SEVERITY_WARNING || val == IMarker.SEVERITY_ERROR) {
						severity= val;
					}
				}
			}
		}
	}
	if (severity == IMarker.SEVERITY_ERROR) {
		return ERRORTICK_ERROR;
	} else if (severity == IMarker.SEVERITY_WARNING) {
		return ERRORTICK_WARNING;
	}
	return 0;
}
 
Example 13
Source File: PyRenameResourceAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean isEnabled() {
    selected = new ArrayList<IResource>();

    ISelection selection = provider.getSelection();
    if (!selection.isEmpty()) {
        IStructuredSelection sSelection = (IStructuredSelection) selection;
        if (sSelection.size() >= 1) {
            Iterator iterator = sSelection.iterator();
            while (iterator.hasNext()) {
                Object element = iterator.next();
                if (element instanceof IAdaptable) {
                    IAdaptable adaptable = (IAdaptable) element;
                    IResource resource = adaptable.getAdapter(IResource.class);
                    if (resource != null && resource.isAccessible()) {
                        selected.add(resource);
                        continue;
                    }
                }
                // one of the elements did not satisfy the condition
                selected = null;
                return false;
            }
        }
    }
    return true;
}
 
Example 14
Source File: ProblemsLabelDecorator.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private int getErrorTicksFromMarkers(IResource res, int depth) throws CoreException
{
	if (res == null || !res.isAccessible())
	{
		return -1;
	}
	int info = -1;

	IMarker[] markers = res.findMarkers(IMarker.PROBLEM, true, depth);
	if (markers != null)
	{
		for (int i = 0; i < markers.length && info != ERROR; i++)
		{
			IMarker curr = markers[i];
			int severity = curr.getAttribute(IMarker.SEVERITY, -1);
			if (severity == IMarker.SEVERITY_WARNING)
			{
				info = WARNING;
			}
			else if (severity == IMarker.SEVERITY_ERROR)
			{
				info = ERROR;
			}
		}
	}
	return info;
}
 
Example 15
Source File: PDEClassPathGenerator.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@CheckForNull
private static String resolveLibrary(IPath path) {
    if (path == null || path.segmentCount() != 1) {
        return null;
    }
    IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
    if (resource == null || !resource.isAccessible()) {
        return null;
    }
    IPath location = resource.getLocation();
    return location == null ? null : location.toOSString();
}
 
Example 16
Source File: JavaMarkerResolutionGenerator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private static ICompilationUnit getCompilationUnit(IMarker marker) {
  IResource res = marker.getResource();
  if (res instanceof IFile && res.isAccessible()) {
    IJavaElement element = JavaCore.create((IFile) res);
    if (element instanceof ICompilationUnit) {
      return (ICompilationUnit) element;
    }
  }
  return null;
}
 
Example 17
Source File: YangPageFile.java    From yang-design-studio with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Ensures that both text fields are set.
 */

private void dialogChanged() {
	IResource container = ResourcesPlugin.getWorkspace().getRoot()
			.findMember(new Path(getContainerName()));
	String fileName = getFileName();

	if (getContainerName().length() == 0) {
		updateStatus("File container must be specified");
		return;
	}
	if (container == null
			|| (container.getType() & (IResource.PROJECT | IResource.FOLDER)) == 0) {
		updateStatus("File container must exist");
		return;
	}
	if (!container.isAccessible()) {
		updateStatus("Project must be writable");
		return;
	}
	if (fileName.length() == 0) {
		updateStatus("File name must be specified");
		return;
	}
	if (fileName.replace('\\', '/').indexOf('/', 1) > 0) {
		updateStatus("File name must be valid");
		return;
	}
	int dotLoc = fileName.lastIndexOf('.');
	if (dotLoc != -1) {
		String ext = fileName.substring(dotLoc + 1);
		if (ext.equalsIgnoreCase("yang") == false) {
			updateStatus("File extension must be \"yang\"");
			return;
		}
	}
	updateStatus(null);
}
 
Example 18
Source File: NewReportWizard.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Judge whether the name new report has been used
 * 
 * @param prefix
 * @param ext
 * @param count
 * @param res
 * @return
 */
boolean validDuplicate( String prefix, String ext, int count, IResource res )
{
	if ( res != null && res.isAccessible( ) )
	{
		final String name;
		if ( count == 0 )
		{
			name = prefix + ext;
		}
		else
		{
			name = prefix + "_" + count + ext; //$NON-NLS-1$
		}

		try
		{
			tmpList.clear( );

			res.accept( new IResourceVisitor( ) {

				public boolean visit( IResource resource )
						throws CoreException
				{
					if ( resource.getType( ) == IResource.FILE )
					{
						if ( !Platform.getOS( ).equals( Platform.OS_WIN32 ) )
						{
							if ( name.equals( ( (IFile) resource ).getName( ) ) )
							{
								tmpList.add( Boolean.TRUE );
							}
						}
						else if ( name.equalsIgnoreCase( ( (IFile) resource ).getName( ) ) )
						{
							tmpList.add( Boolean.TRUE );
						}
					}

					return true;
				}
			},
					IResource.DEPTH_INFINITE,
					true );

			if ( tmpList.size( ) > 0 )
			{
				return false;
			}
		}
		catch ( CoreException e )
		{
			ExceptionUtil.handle( e );
		}
	}

	return true;
}
 
Example 19
Source File: ProblemsLabelDecorator.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private int getErrorTicksFromMarkers(IResource res, int depth) throws CoreException {
    if (!res.isAccessible()) {
        return 0;
    }
    return res.findMaxProblemSeverity(IMarker.PROBLEM, true, depth);
}
 
Example 20
Source File: ReorgUtils.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean canBeDestinationForLinkedResources(IResource resource) {
	return resource.isAccessible() && resource instanceof IProject;
}