### Eclipse Workspace Patch 1.0 #P org.eclipse.core.resources Index: src/org/eclipse/core/resources/team/ResourceRuleFactory.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/resources/team/ResourceRuleFactory.java,v retrieving revision 1.10 diff -u -r1.10 ResourceRuleFactory.java --- src/org/eclipse/core/resources/team/ResourceRuleFactory.java 13 Feb 2006 22:42:41 -0000 1.10 +++ src/org/eclipse/core/resources/team/ResourceRuleFactory.java 28 Feb 2007 22:07:32 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -141,7 +141,7 @@ * * @see org.eclipse.core.runtime.jobs.ISchedulingRule#contains(org.eclipse.core.runtime.jobs.ISchedulingRule) * @see org.eclipse.core.resources.IResourceRuleFactory#modifyRule(IResource) - * @see IFileModificationValidator#validateSave(IFile) + * @see FileModificationValidator#validateSave(IFile) * @see IProjectDescription#DESCRIPTION_FILE_NAME */ public ISchedulingRule modifyRule(IResource resource) { Index: src/org/eclipse/core/resources/IWorkspace.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/resources/IWorkspace.java,v retrieving revision 1.77 diff -u -r1.77 IWorkspace.java --- src/org/eclipse/core/resources/IWorkspace.java 13 Jul 2006 17:42:24 -0000 1.77 +++ src/org/eclipse/core/resources/IWorkspace.java 28 Feb 2007 22:07:32 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -14,6 +14,7 @@ import java.io.InputStream; import java.net.URI; import java.util.Map; +import org.eclipse.core.resources.team.FileModificationValidationContext; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.ISchedulingRule; import org.eclipse.core.runtime.jobs.LockListener; @@ -80,6 +81,15 @@ public static final int AVOID_UPDATE = 1; /** + * Constant that can be passed to {@link #validateEdit(org.eclipse.core.resources.IFile[], Object)} + * to indicate that the caller does not have access to a UI context but would still + * like to have UI-based validation if possible. + * @since 3.3 + * @see #validateEdit(IFile[], Object) + */ + public static final Object VALIDATE_PROMPT = FileModificationValidationContext.VALIDATE_PROMPT; + + /** * Adds the given listener for resource change events to this workspace. Has * no effect if an identical listener is already registered. *
@@ -1272,7 +1282,10 @@
* dialogs to query the user or report difficulties; the shell should be
* used to parent any such dialogs; the caller may safely assume that the
* reasons for failure will have been made clear to the user. If
- * null
is passed, the user should not be contacted; any
+ * {@link IWorkspace#VALIDATE_PROMPT} is passed
+ * as the context, this indicates that the caller does not have access to
+ * a UI context but would still like the user to be prompted if required.
+ * If null
is passed, the user should not be contacted; any
* failures should be reported via the result; the caller may chose to
* present these to the user however they see fit. The ideal implementation
* of this method is transactional; no files would be affected unless the
@@ -1280,7 +1293,7 @@
* ensure such changes get done atomically.)
*
- * The method calls IFileModificationValidator.validateEdit
+ * The method calls FileModificationValidator.validateEdit
* for the file modification validator (if provided by the VCM plug-in).
* When there is no file modification validator, this method returns a
* status with an IResourceStatus.READ_ONLY_LOCAL
code if one
@@ -1290,13 +1303,14 @@
*
* This method may be called from any thread. If the UI context is used, it
* is the responsibility of the implementor of
- * IFileModificationValidator.validateEdit
to interact with
+ * FileModificationValidator.validateEdit
to interact with
* the UI context in an appropriate thread.
*
org.eclipse.swt.widgets.Shell
that is
+ * @param context either {@link IWorkspace#VALIDATE_PROMPT},
+ * or the org.eclipse.swt.widgets.Shell
that is
* to be used to parent any dialogs with the user, or null
if
* there is no UI context (declared as an Object
to avoid any
* direct references on the SWT component)
Index: src/org/eclipse/core/resources/IFileModificationValidator.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/resources/IFileModificationValidator.java,v
retrieving revision 1.14
diff -u -r1.14 IFileModificationValidator.java
--- src/org/eclipse/core/resources/IFileModificationValidator.java 4 Apr 2006 20:53:47 -0000 1.14
+++ src/org/eclipse/core/resources/IFileModificationValidator.java 28 Feb 2007 22:07:32 -0000
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.core.resources;
+import org.eclipse.core.resources.team.FileModificationValidator;
import org.eclipse.core.runtime.IStatus;
/**
@@ -21,8 +22,9 @@
* extension point. It is intended to be implemented only
* by the Eclipse Platform Team plug-in.
*
- *
+ *
* @since 2.0
+ * @deprecated clients should subclass {@link FileModificationValidator}
*/
public interface IFileModificationValidator {
/**
Index: src/org/eclipse/core/internal/resources/Workspace.java
===================================================================
RCS file: /cvsroot/eclipse/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/Workspace.java,v
retrieving revision 1.211
diff -u -r1.211 Workspace.java
--- src/org/eclipse/core/internal/resources/Workspace.java 23 Jan 2007 22:45:37 -0000 1.211
+++ src/org/eclipse/core/internal/resources/Workspace.java 28 Feb 2007 22:07:32 -0000
@@ -22,8 +22,7 @@
import org.eclipse.core.internal.utils.*;
import org.eclipse.core.internal.watson.*;
import org.eclipse.core.resources.*;
-import org.eclipse.core.resources.team.IMoveDeleteHook;
-import org.eclipse.core.resources.team.TeamHook;
+import org.eclipse.core.resources.team.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
@@ -2017,7 +2016,12 @@
}
public void run() throws Exception {
- status[0] = validator.validateEdit(files, context);
+ Object c = context;
+ //must null any reference to FileModificationValidationContext for backwards compatibility
+ if (!(validator instanceof FileModificationValidator))
+ if (c instanceof FileModificationValidationContext)
+ c = null;
+ status[0] = validator.validateEdit(files, c);
}
};
SafeRunner.run(body);
Index: src/org/eclipse/core/resources/team/FileModificationValidator.java
===================================================================
RCS file: src/org/eclipse/core/resources/team/FileModificationValidator.java
diff -N src/org/eclipse/core/resources/team/FileModificationValidator.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/core/resources/team/FileModificationValidator.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.resources.team;
+
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.IStatus;
+
+/**
+ * The file modification validator is a Team-related hook for pre-checking operations
+ * that modify the contents of files.
+ * + * This class is used only in conjunction with the + * "org.eclipse.core.resources.fileModificationValidator" + * extension point. It is intended to be implemented only + * by the Eclipse Platform Team plug-in or by repository providers + * whose validator get invoked by Team. + *
+ * @since 3.3 + */ +public abstract class FileModificationValidator implements IFileModificationValidator { + + /** + * Validates that the given files can be modified. The files must all exist + * in the workspace. The optional context object may be supplied if + * UI-based validation is required. If the context isnull
, the
+ * validator must attempt to perform the validation in a headless manner.
+ * The returned status is IStatus.OK
if this validator
+ * believes the given file can be modified. Other return statuses indicate
+ * the reason why the individual files cannot be modified.
+ *
+ * @param files the files that are to be modified; these files must all exist in the workspace
+ * @param context the org.eclipse.swt.widgets.Shell
that is to be used to
+ * parent any dialogs with the user, or null
if there is no UI context (declared
+ * as an Object
to avoid any direct references on the SWT component)
+ * @return a status object that is OK if things are fine, otherwise a status describing
+ * reasons why modifying the given files is not reasonable
+ * @see IWorkspace#validateEdit(IFile[], Object)
+ * @deprecated this method is part of the deprecated {@link IFileModificationValidator}
+ * interface. Clients should call {@link #validateEdit(IFile[], FileModificationValidationContext)}
+ * instead.
+ */
+ public final IStatus validateEdit(IFile[] files, Object context) {
+ FileModificationValidationContext validationContext;
+ if (context == null)
+ validationContext = null;
+ else if (context instanceof FileModificationValidationContext)
+ validationContext = (FileModificationValidationContext) context;
+ else
+ validationContext = new FileModificationValidationContext(context);
+ return validateEdit(files, validationContext);
+ }
+
+ /**
+ * Validates that the given file can be saved. This method is called from
+ * IFile#setContents
and IFile#appendContents
+ * before any attempt to write data to disk. The returned status is
+ * IStatus.OK
if this validator believes the given file can be
+ * successfully saved. In all other cases the return value is a non-OK status.
+ * Note that a return value of IStatus.OK
does not guarantee
+ * that the save will succeed.
+ *
+ * @param file the file that is to be modified; this file must exist in the workspace
+ * @return a status indicating whether or not it is reasonable to try writing to the given file;
+ * IStatus.OK
indicates a save should be attempted.
+ *
+ * @see IFile#setContents(java.io.InputStream, int, org.eclipse.core.runtime.IProgressMonitor)
+ * @see IFile#appendContents(java.io.InputStream, int, org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public IStatus validateSave(IFile file) {
+ return validateEdit(new IFile[] {file}, (FileModificationValidationContext) null);
+ }
+
+ /**
+ * Validates that the given files can be modified. The files must all exist
+ * in the workspace. The optional context may be supplied if
+ * UI-based validation is required. If the context is null
, the
+ * validator must attempt to perform the validation in a headless manner.
+ * The returned status is IStatus.OK
if this validator
+ * believes the given file can be modified. Other return statuses indicate
+ * the reason why the individual files cannot be modified.
+ *
+ * @param files the files that are to be modified; these files must all exist in the workspace
+ * @param context the context to aid in UI-based validation or null
if the validation
+ * must be headless
+ * @return a status object that is OK if things are fine, otherwise a status describing
+ * reasons why modifying the given files is not reasonable
+ * @see IWorkspace#validateEdit(IFile[], Object)
+ *
+ */
+ public abstract IStatus validateEdit(IFile[] files, FileModificationValidationContext context);
+
+}
Index: src/org/eclipse/core/resources/team/FileModificationValidationContext.java
===================================================================
RCS file: src/org/eclipse/core/resources/team/FileModificationValidationContext.java
diff -N src/org/eclipse/core/resources/team/FileModificationValidationContext.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/core/resources/team/FileModificationValidationContext.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.core.resources.team;
+
+import org.eclipse.core.resources.IWorkspace;
+
+/**
+ * A context that is used in conjunction with the {@link FileModificationValidator}
+ * to indicate that UI-based validation is desired.
+ *
+ * This class is not intended to be instantiated or subclassed by clients.
+ *
+ * @see FileModificationValidator
+ * @since 3.3
+ */
+public class FileModificationValidationContext {
+
+ /**
+ * Constant that can be passed to {@link IWorkspace#validateEdit(org.eclipse.core.resources.IFile[], Object)}
+ * to indicate that the caller does not have access to a UI context but would still
+ * like to have UI-based validation if possible.
+ */
+ public static final FileModificationValidationContext VALIDATE_PROMPT = new FileModificationValidationContext(null);
+
+ private final Object shell;
+
+ /**
+ * Create a context with the given shell.
+ *
+ * @param shell the shell
+ */
+ FileModificationValidationContext(Object shell) {
+ this.shell = shell;
+ }
+
+ /**
+ * Return the org.eclipse.swt.widgets.Shell
that is to be used to
+ * parent any dialogs with the user, or null
if there is no UI context
+ * available (declared as an Object
to avoid any direct references on the SWT component).
+ * If there is no shell, the {@link FileModificationValidator} may still perform
+ * UI-based validation if they can obtain a Shell from another source.
+ * @return the org.eclipse.swt.widgets.Shell
that is to be used to
+ * parent any dialogs with the user, or null
+ */
+ public Object getShell() {
+ return shell;
+ }
+}