org.eclipse.core.resources.ResourceAttributes Java Examples

The following examples show how to use org.eclipse.core.resources.ResourceAttributes. 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: RenameResourceAndCloseEditorAction.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check if the supplied resource is read only or null. If it is then ask
 * the user if they want to continue. Return true if the resource is not
 * read only or if the user has given permission.
 * 
 * @return boolean
 */
private boolean checkReadOnlyAndNull(IResource currentResource) {
	// Do a quick read only and null check
	if (currentResource == null) {
		return false;
	}

	// Do a quick read only check
	final ResourceAttributes attributes = currentResource
			.getResourceAttributes();
	if (attributes != null && attributes.isReadOnly()) {
		return MessageDialog.openQuestion(shellProvider.getShell(), CHECK_RENAME_TITLE,
				MessageFormat.format(CHECK_RENAME_MESSAGE,
						new Object[] { currentResource.getName() }));
	}

	return true;
}
 
Example #2
Source File: RenameResourceAndCloseEditorAction.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check if the supplied resource is read only or null. If it is then ask
 * the user if they want to continue. Return true if the resource is not
 * read only or if the user has given permission.
 * 
 * @return boolean
 */
private boolean checkReadOnlyAndNull(IResource currentResource) {
	// Do a quick read only and null check
	if (currentResource == null) {
		return false;
	}

	// Do a quick read only check
	final ResourceAttributes attributes = currentResource
			.getResourceAttributes();
	if (attributes != null && attributes.isReadOnly()) {
		return MessageDialog.openQuestion(shellProvider.getShell(), CHECK_RENAME_TITLE,
				MessageFormat.format(CHECK_RENAME_MESSAGE,
						new Object[] { currentResource.getName() }));
	}

	return true;
}
 
Example #3
Source File: IntegrationTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testBug342875() throws Exception {

		IJavaProject project = createJavaProject("foo");
		addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
		IFile file = createFile("foo/src/foo" + F_EXT, "objekt Foo ");
		ResourceAttributes resourceAttributes = file.getResourceAttributes();
		resourceAttributes.setReadOnly(true);
		file.setResourceAttributes(resourceAttributes);
		try {
			build();
			assertTrue(file.isReadOnly());
			assertEquals(1, countMarkers(file));
		} finally {
			resourceAttributes.setReadOnly(false);
			file.setResourceAttributes(resourceAttributes);
		}
	}
 
Example #4
Source File: ReorgPolicyFactory.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean canEnable() throws JavaModelException {
	if (!super.canEnable()) {
		return false;
	}
	IPackageFragmentRoot[] roots= getPackageFragmentRoots();
	for (int i= 0; i < roots.length; i++) {
		IPackageFragmentRoot root= roots[i];
		if (root.isReadOnly() && !root.isArchive() && !root.isExternal()) {
			final ResourceAttributes attributes= roots[i].getResource().getResourceAttributes();
			if (attributes == null || attributes.isReadOnly()) {
				return false;
			}
		}
	}
	return roots.length > 0;
}
 
Example #5
Source File: ProjectConfigurationWorkingCopy.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Store the audit configurations to the persistent state storage.
 */
private void storeToPersistence(ProjectConfigurationWorkingCopy config)
        throws CheckstylePluginException {

  try {

    Document docu = writeProjectConfig(config);
    byte[] data = XMLUtil.toByteArray(docu);
    InputStream pipeIn = new ByteArrayInputStream(data);

    // create or overwrite the .checkstyle file
    IProject project = config.getProject();
    IFile file = project.getFile(ProjectConfigurationFactory.PROJECT_CONFIGURATION_FILE);
    if (!file.exists()) {
      file.create(pipeIn, true, null);
      file.refreshLocal(IResource.DEPTH_INFINITE, null);
    } else {

      if (file.isReadOnly()) {
        ResourceAttributes attrs = ResourceAttributes.fromFile(file.getFullPath().toFile());
        attrs.setReadOnly(true);
        file.setResourceAttributes(attrs);
      }

      file.setContents(pipeIn, true, true, null);
    }

    config.getLocalCheckConfigWorkingSet().store();
  } catch (Exception e) {
    CheckstylePluginException.rethrow(e,
            NLS.bind(Messages.errorWritingCheckConfigurations, e.getLocalizedMessage()));
  }
}
 
Example #6
Source File: PyChange.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static boolean isReadOnly(IResource resource) {
    ResourceAttributes resourceAttributes = resource.getResourceAttributes();
    if (resourceAttributes == null) {
        return false;
    }
    return resourceAttributes.isReadOnly();
}
 
Example #7
Source File: DocumentAdapter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isReadOnly() {
	if (fTextFileBuffer != null)
		return !fTextFileBuffer.isCommitable();

	IResource resource= getUnderlyingResource();
	if (resource == null)
		return true;

	final ResourceAttributes attributes= resource.getResourceAttributes();
	return attributes == null ? false : attributes.isReadOnly();
}
 
Example #8
Source File: Resources.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static void setReadOnly(IResource resource, boolean readOnly) {
	ResourceAttributes resourceAttributes = resource.getResourceAttributes();
	if (resourceAttributes == null) // not supported on this platform for this resource
		return;

	resourceAttributes.setReadOnly(readOnly);
	try {
		resource.setResourceAttributes(resourceAttributes);
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
}
 
Example #9
Source File: ReorgPolicyFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean canEnable() throws JavaModelException {
	if (!super.canEnable())
		return false;
	IPackageFragmentRoot[] roots= getPackageFragmentRoots();
	for (int i= 0; i < roots.length; i++) {
		IPackageFragmentRoot root= roots[i];
		if (root.isReadOnly() && !root.isArchive() && !root.isExternal()) {
			final ResourceAttributes attributes= roots[i].getResource().getResourceAttributes();
			if (attributes == null || attributes.isReadOnly())
				return false;
		}
	}
	return roots.length > 0;
}
 
Example #10
Source File: RenameResourceAction.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Check if the supplied resource is read only or null. If it is then ask the user if they want to continue. Return
 * true if the resource is not read only or if the user has given permission.
 *
 * @return boolean
 */
private boolean checkReadOnlyAndNull(final IResource currentResource) {
	// Do a quick read only and null check
	if (currentResource == null) { return false; }

	// Do a quick read only check
	final ResourceAttributes attributes = currentResource.getResourceAttributes();
	if (attributes != null && attributes.isReadOnly()) {
		return MessageDialog.openQuestion(WorkbenchHelper.getShell(), CHECK_RENAME_TITLE,
				MessageFormat.format(CHECK_RENAME_MESSAGE, new Object[] { currentResource.getName() }));
	}

	return true;
}
 
Example #11
Source File: TarLeveledStructureProvider.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the resource attributes for this file.
 *
 * @param element the element to get the attributes from
 * @return the attributes of the file
 */
public ResourceAttributes getResourceAttributes(Object element) {
    ResourceAttributes attributes = new ResourceAttributes();
    TarArchiveEntry entry = (TarArchiveEntry) element;
    attributes.setExecutable((entry.getMode() & 0100) != 0);
    attributes.setReadOnly((entry.getMode() & 0200) == 0);
    return attributes;
}
 
Example #12
Source File: DocumentAdapter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean isReadOnly() {
	if (fTextFileBuffer != null) {
		return fTextFileBuffer.isCommitable();
	}

	ResourceAttributes attributes = fFile.getResourceAttributes();
	return attributes != null ? attributes.isReadOnly() : false;
}
 
Example #13
Source File: SingleProjectTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testBug342875() throws Exception {
	IFile file = createFile("sample/first" + F_EXT, "Hello A");
	ResourceAttributes resourceAttributes = file.getResourceAttributes();
	resourceAttributes.setReadOnly(true);
	file.setResourceAttributes(resourceAttributes);
	try {
		build();
		assertTrue(file.isReadOnly());
		assertEquals(1, countMarkers(file));
	} finally {
		resourceAttributes.setReadOnly(false);
		file.setResourceAttributes(resourceAttributes);
	}
}
 
Example #14
Source File: XtextProjectCreator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private void addExecutableFlag(IFile file) {
	ResourceAttributes attributes = file.getResourceAttributes();
	if (attributes != null) {
		attributes.setExecutable(true);
		try {
			file.setResourceAttributes(attributes);
		} catch (CoreException e) {
			LOG.warn("Failed to set executable flag for " + file.getFullPath().toOSString(), e);
		}
	}
}
 
Example #15
Source File: WriteProtectedFilter.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean accept(Object element) {

  boolean goesThrough = true;

  if (element instanceof IResource) {

    ResourceAttributes attrs = ((IResource) element).getResourceAttributes();
    goesThrough = attrs != null && !attrs.isReadOnly();
  }
  return goesThrough;
}
 
Example #16
Source File: CheckstyleNature.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void ensureProjectFileWritable() throws CoreException {
  IFile projectFile = mProject.getFile(".project");
  if (projectFile.isReadOnly()) {
    ResourceAttributes attrs = ResourceAttributes.fromFile(projectFile.getFullPath().toFile());
    attrs.setReadOnly(true);
    projectFile.setResourceAttributes(attrs);
  }
}
 
Example #17
Source File: Resources.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isReadOnly(IResource resource) {
	ResourceAttributes resourceAttributes = resource.getResourceAttributes();
	if (resourceAttributes == null)  // not supported on this platform for this resource
		return false;
	return resourceAttributes.isReadOnly();
}
 
Example #18
Source File: TestFile.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
public ResourceAttributes getResourceAttributes() {
        throw new RuntimeException("not implemented"); //$NON-NLS-1$
//        return null;
    }
 
Example #19
Source File: TestFile.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
public void setResourceAttributes(ResourceAttributes arg0) throws CoreException {
    throw new RuntimeException("not implemented"); //$NON-NLS-1$
}
 
Example #20
Source File: ClientTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void setResourceAttributes(ResourceAttributes attributes)
		throws CoreException {
	// TODO Auto-generated method stub

}
 
Example #21
Source File: ClientTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ResourceAttributes getResourceAttributes() {
	// TODO Auto-generated method stub
	return null;
}
 
Example #22
Source File: FakeIFile.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ResourceAttributes getResourceAttributes() {
	// TODO Auto-generated method stub
	return null;
}
 
Example #23
Source File: FakeIFile.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void setResourceAttributes(ResourceAttributes attributes)
		throws CoreException {
	// TODO Auto-generated method stub

}
 
Example #24
Source File: AbstractIResourceStub.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ResourceAttributes getResourceAttributes() {
    throw new RuntimeException("Not implemented");
}
 
Example #25
Source File: AbstractIResourceStub.java    From Pydev with Eclipse Public License 1.0 2 votes vote down vote up
@Override
public void setResourceAttributes(ResourceAttributes attributes) throws CoreException {

}