Example #1
0
  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) {
      DLTKUIPlugin.log(e);
    }
  }
Example #2
0
  /**
   * Makes the given resources committable. Committable means that all resources are writeable and
   * that the content of the resources hasn't changed by calling <code>validateEdit</code> for a
   * given file on <tt>IWorkspace</tt>.
   *
   * @param resources the resources to be checked
   * @param context the context passed to <code>validateEdit</code>
   * @return IStatus status describing the method's result. If <code>status.
   * isOK()</code> returns <code>true</code> then the add resources are committable
   * @see org.eclipse.core.resources.IWorkspace#validateEdit(org.eclipse.core.resources.IFile[],
   *     java.lang.Object)
   */
  public static IStatus makeCommittable(IResource[] resources, Object context) {
    List<IFile> readOnlyFiles = new ArrayList<>();
    for (IResource resource : resources) {
      if (resource.getType() == IResource.FILE && resource.getResourceAttributes().isReadOnly())
        readOnlyFiles.add((IFile) resource);
    }
    if (readOnlyFiles.size() == 0) return Status.OK_STATUS;

    Map<IFile, Long> oldTimeStamps = createModificationStampMap(readOnlyFiles);
    IStatus status =
        ResourcesPlugin.getWorkspace()
            .validateEdit(readOnlyFiles.toArray(new IFile[readOnlyFiles.size()]), context);
    if (!status.isOK()) return status;

    IStatus modified = null;
    Map<IFile, Long> newTimeStamps = createModificationStampMap(readOnlyFiles);
    for (IFile file : oldTimeStamps.keySet()) {
      if (!oldTimeStamps.get(file).equals(newTimeStamps.get(file)))
        modified = addModified(modified, file);
    }
    if (modified != null) return modified;
    return Status.OK_STATUS;
  }
Example #3
0
 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();
 }