### Eclipse Workspace Patch 1.0 #P org.eclipse.team.examples.filesystem Index: src/org/eclipse/team/examples/pessimistic/PessimisticModificationValidator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/pessimistic/PessimisticModificationValidator.java,v retrieving revision 1.4 diff -u -r1.4 PessimisticModificationValidator.java --- src/org/eclipse/team/examples/pessimistic/PessimisticModificationValidator.java 22 Feb 2005 19:47:24 -0000 1.4 +++ src/org/eclipse/team/examples/pessimistic/PessimisticModificationValidator.java 28 Feb 2007 17:44:51 -0000 @@ -11,7 +11,10 @@ package org.eclipse.team.examples.pessimistic; import java.util.*; + import org.eclipse.core.resources.*; +import org.eclipse.core.resources.team.FileModificationValidationContext; +import org.eclipse.core.resources.team.FileModificationValidator; import org.eclipse.core.runtime.*; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ILabelProvider; @@ -31,7 +34,7 @@ * @see IFileModificationValidator */ public class PessimisticModificationValidator - implements IFileModificationValidator { + extends FileModificationValidator { /* * The provider for this validator */ @@ -44,7 +47,7 @@ /** * @see IFileModificationValidator#validateEdit(IFile[], Object) */ - public IStatus validateEdit(IFile[] files, Object context) { + public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { if (files.length == 0) { return new Status( IStatus.OK, getUid(), IStatus.OK, "OK", null); } @@ -79,7 +82,7 @@ return new Status( IStatus.ERROR, getUid(), IStatus.ERROR, "Fail Validate Edit Preference true", null); } if(statusCode == IStatus.CANCEL) { - return new Status( IStatus.CANCEL, getUid(), IStatus.ERROR, "Checkout cancelled by user", null); + return new Status( IStatus.CANCEL, getUid(), IStatus.ERROR, "Checkout canceled by user", null); } } else { if (isAutomaticCheckout()) { Index: src/org/eclipse/team/examples/filesystem/FileModificationValidator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.examples.filesystem/src/org/eclipse/team/examples/filesystem/FileModificationValidator.java,v retrieving revision 1.9 diff -u -r1.9 FileModificationValidator.java --- src/org/eclipse/team/examples/filesystem/FileModificationValidator.java 18 Mar 2005 20:25:42 -0000 1.9 +++ src/org/eclipse/team/examples/filesystem/FileModificationValidator.java 28 Feb 2007 17:44:51 -0000 @@ -14,8 +14,8 @@ import java.util.Collection; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFileModificationValidator; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.team.FileModificationValidationContext; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.team.core.RepositoryProvider; @@ -23,11 +23,11 @@ /** * This class models a sentry that verifies whether resources are available for editing or overwriting. - * This has been made a separate clas for illustration purposes. It may have been more apporpriate + * This has been made a separate class for illustration purposes. It may have been more appropriate * to have FileSystemProvider implement IFileModificationValidator itself since the interface * only has two methods and their implementation is straight forward. */ -public final class FileModificationValidator implements IFileModificationValidator { +public final class FileModificationValidator extends org.eclipse.core.resources.team.FileModificationValidator { private FileSystemOperations operations; @@ -39,7 +39,7 @@ } /** - * This method will convert any exceptions thrown by the SimpleAccessOperations.chechout() to a Status. + * This method will convert any exceptions thrown by the SimpleAccessOperations.checkout() to a Status. * @param resources the resources that are to be checked out * @return IStatus a status indicator that reports whether the operation went smoothly or not. */ @@ -57,7 +57,7 @@ * The idea is to prevent anyone from accidentally working on a file that they won't be able to check in changes to. * @see org.eclipse.core.resources.IFileModificationValidator#validateEdit(IFile[], Object) */ - public IStatus validateEdit(IFile[] files, Object context) { + public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { Collection toBeCheckedOut = new ArrayList(); //Make a list of all the files that need to be checked out: @@ -72,15 +72,14 @@ /** * This method will be called by the workbench before it tries to save a file. - * It should not attempt to save any files that don't recieve an OK status here. + * It should not attempt to save any files that don't receive an OK status here. * @see org.eclipse.core.resources.IFileModificationValidator#validateSave(IFile) */ public IStatus validateSave(IFile file) { if (file.isReadOnly()) { return checkout(new IResource[] { file }); - } else { - return Status.OK_STATUS; } + return Status.OK_STATUS; } } #P org.eclipse.team.ui Index: plugin.xml =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.ui/plugin.xml,v retrieving revision 1.184 diff -u -r1.184 plugin.xml --- plugin.xml 6 Feb 2007 13:46:55 -0000 1.184 +++ plugin.xml 28 Feb 2007 17:44:52 -0000 @@ -269,7 +269,7 @@ + id="org.eclipse.ui.navigator.ProjectExplorer"> Index: src/org/eclipse/team/internal/ui/DefaultUIFileModificationValidator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/DefaultUIFileModificationValidator.java,v retrieving revision 1.7 diff -u -r1.7 DefaultUIFileModificationValidator.java --- src/org/eclipse/team/internal/ui/DefaultUIFileModificationValidator.java 2 Oct 2006 20:19:01 -0000 1.7 +++ src/org/eclipse/team/internal/ui/DefaultUIFileModificationValidator.java 28 Feb 2007 17:44:52 -0000 @@ -15,6 +15,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourceAttributes; +import org.eclipse.core.resources.team.FileModificationValidationContext; import org.eclipse.core.runtime.*; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -118,12 +119,12 @@ } /* (non-Javadoc) - * @see org.eclipse.team.internal.core.DefaultFileModificationValidator#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object) + * @see org.eclipse.team.internal.core.DefaultFileModificationValidator#validateEdit(org.eclipse.core.resources.IFile[], org.eclipse.core.resources.team.FileModificationValidationContext) */ - public IStatus validateEdit(final IFile[] allFiles, Object context) { + public IStatus validateEdit(final IFile[] allFiles, FileModificationValidationContext context) { final IFile[] readOnlyFiles = getReadOnlyFiles(allFiles); - if (readOnlyFiles.length > 0 && context != null && context instanceof Shell) { - final Shell shell = (Shell)context; + if (readOnlyFiles.length > 0 && context != null) { + final Shell shell = getShell(context); final boolean[] ok = new boolean[] { false }; if (readOnlyFiles.length == 1) { shell.getDisplay().syncExec(new Runnable() { @@ -149,7 +150,13 @@ return getStatus(readOnlyFiles); } - public IStatus validateSave(IFile file) { + private Shell getShell(FileModificationValidationContext context) { + if (context.getShell() != null) + return (Shell)context.getShell(); + return Utils.getShell(null); + } + + public IStatus validateSave(IFile file) { if (file.isReadOnly() && isMakeWrittableWhenContextNotProvided()) { IFile[] readOnlyFiles = new IFile[] { file }; setWritable(readOnlyFiles); #P org.eclipse.team.core Index: schema/defaultFileModificationValidator.exsd =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.core/schema/defaultFileModificationValidator.exsd,v retrieving revision 1.4 diff -u -r1.4 defaultFileModificationValidator.exsd --- schema/defaultFileModificationValidator.exsd 13 Jun 2006 19:29:26 -0000 1.4 +++ schema/defaultFileModificationValidator.exsd 28 Feb 2007 17:44:54 -0000 @@ -40,7 +40,7 @@ - + @@ -88,7 +88,7 @@ - Copyright (c) 2004 IBM Corporation and others. + Copyright (c) 2004 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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> Index: src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.core/src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java,v retrieving revision 1.16 diff -u -r1.16 DefaultFileModificationValidator.java --- src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java 2 Oct 2006 20:19:14 -0000 1.16 +++ src/org/eclipse/team/internal/core/DefaultFileModificationValidator.java 28 Feb 2007 17:44:54 -0000 @@ -13,20 +13,22 @@ import java.util.ArrayList; import java.util.List; -import org.eclipse.core.resources.*; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.team.FileModificationValidationContext; +import org.eclipse.core.resources.team.FileModificationValidator; import org.eclipse.core.runtime.*; import org.eclipse.osgi.util.NLS; import org.eclipse.team.core.ITeamStatus; import org.eclipse.team.core.TeamStatus; -public class DefaultFileModificationValidator implements IFileModificationValidator { +public class DefaultFileModificationValidator extends FileModificationValidator { /* * A validator plugged in the the Team UI that will prompt * the user to make read-only files writable. In the absence of * this validator, edit/save fail on read-only files. */ - private IFileModificationValidator uiValidator; + private FileModificationValidator uiValidator; protected IStatus getDefaultStatus(IFile file) { return @@ -35,10 +37,7 @@ : Status.OK_STATUS; } - /** - * @see IFileModificationValidator#validateEdit(IFile[], Object) - */ - public IStatus validateEdit(IFile[] files, Object context) { + public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { IFile[] readOnlyFiles = getReadOnly(files); if (readOnlyFiles.length == 0) return Status.OK_STATUS; @@ -86,9 +85,6 @@ return (IFile[]) result.toArray(new IFile[result.size()]); } - /** - * @see IFileModificationValidator#validateSave(IFile) - */ public IStatus validateSave(IFile file) { if (!file.isReadOnly()) return Status.OK_STATUS; @@ -102,7 +98,7 @@ return getDefaultStatus(file); } - private IFileModificationValidator loadUIValidator() { + private FileModificationValidator loadUIValidator() { IExtensionPoint extension = Platform.getExtensionRegistry().getExtensionPoint(TeamPlugin.ID, TeamPlugin.DEFAULT_FILE_MODIFICATION_VALIDATOR_EXTENSION); if (extension != null) { IExtension[] extensions = extension.getExtensions(); @@ -111,8 +107,8 @@ if (configElements.length > 0) { try { Object o = configElements[0].createExecutableExtension("class"); //$NON-NLS-1$ - if (o instanceof IFileModificationValidator) { - return (IFileModificationValidator)o; + if (o instanceof FileModificationValidator) { + return (FileModificationValidator)o; } } catch (CoreException e) { TeamPlugin.log(e); Index: src/org/eclipse/team/internal/core/FileModificationValidatorManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.core/src/org/eclipse/team/internal/core/FileModificationValidatorManager.java,v retrieving revision 1.10 diff -u -r1.10 FileModificationValidatorManager.java --- src/org/eclipse/team/internal/core/FileModificationValidatorManager.java 10 May 2006 17:47:43 -0000 1.10 +++ src/org/eclipse/team/internal/core/FileModificationValidatorManager.java 28 Feb 2007 17:44:54 -0000 @@ -15,12 +15,14 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFileModificationValidator; +import org.eclipse.core.resources.team.FileModificationValidationContext; +import org.eclipse.core.resources.team.FileModificationValidator; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.MultiStatus; import org.eclipse.team.core.RepositoryProvider; -public class FileModificationValidatorManager implements IFileModificationValidator { - private IFileModificationValidator defaultValidator; +public class FileModificationValidatorManager extends FileModificationValidator { + private FileModificationValidator defaultValidator; /* * @see IFileModificationValidator#validateEdit(IFile[], Object) @@ -28,7 +30,7 @@ * Ask each provider once for its files. * Collect the resulting status' and return a MultiStatus. */ - public IStatus validateEdit(IFile[] files, Object context) { + public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { ArrayList returnStati = new ArrayList(); //map provider to the files under that provider's control @@ -63,7 +65,13 @@ if (v != null) validator = v; } - IStatus status = validator.validateEdit(filesArray, context); + IStatus status; + if (validator instanceof FileModificationValidator) { + FileModificationValidator fmv = (FileModificationValidator) validator; + status = fmv.validateEdit(filesArray, FileModificationValidationContext.createContextFor(context)); + } else { + status = validator.validateEdit(filesArray, context); + } if(!status.isOK()) allOK = false; @@ -99,7 +107,7 @@ return validator.validateSave(file); } - private synchronized IFileModificationValidator getDefaultValidator() { + private synchronized FileModificationValidator getDefaultValidator() { if (defaultValidator == null) { defaultValidator = new DefaultFileModificationValidator(); } #P org.eclipse.team.cvs.ui Index: src/org/eclipse/team/internal/ccvs/ui/FileModificationValidator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/FileModificationValidator.java,v retrieving revision 1.29 diff -u -r1.29 FileModificationValidator.java --- src/org/eclipse/team/internal/ccvs/ui/FileModificationValidator.java 10 May 2006 17:48:04 -0000 1.29 +++ src/org/eclipse/team/internal/ccvs/ui/FileModificationValidator.java 28 Feb 2007 17:44:55 -0000 @@ -17,6 +17,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; +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.Job; @@ -30,27 +31,30 @@ import org.eclipse.team.internal.ccvs.core.client.Command; import org.eclipse.team.internal.ccvs.ui.actions.EditorsAction; import org.eclipse.team.internal.ccvs.ui.operations.UpdateOperation; +import org.eclipse.team.internal.ui.Utils; import org.eclipse.ui.progress.IProgressConstants; /** - * IFileModificationValidator that is pluged into the CVS Repository Provider + * IFileModificationValidator that is plugged into the CVS Repository Provider */ public class FileModificationValidator extends CVSCoreFileModificationValidator { public FileModificationValidator() { } - /* (non-Javadoc) - * @see org.eclipse.team.internal.ccvs.core.CVSCoreFileModificationValidator#edit(org.eclipse.core.resources.IFile[], java.lang.Object) + /* (non-Javadoc) + * @see org.eclipse.team.internal.ccvs.core.CVSCoreFileModificationValidator#edit(org.eclipse.core.resources.IFile[], org.eclipse.core.resources.team.FileModificationValidationContext) */ - protected IStatus edit(IFile[] readOnlyFiles, Object context) { + protected IStatus edit(IFile[] readOnlyFiles, FileModificationValidationContext context) { return edit(readOnlyFiles, getShell(context)); } - private Shell getShell(Object context) { - if (context instanceof Shell) - return (Shell)context; - return null; + private Shell getShell(FileModificationValidationContext context) { + if (context == null) + return null; + if (context.getShell() != null) + return (Shell)context.getShell(); + return Utils.getShell(null); } private IStatus getStatus(InvocationTargetException e) { @@ -142,7 +146,7 @@ } private URL getOperationIcon() { - return Platform.find(CVSUIPlugin.getPlugin().getBundle(), new Path(ICVSUIConstants.ICON_PATH + ICVSUIConstants.IMG_CVS_PERSPECTIVE)); + return FileLocator.find(CVSUIPlugin.getPlugin().getBundle(), new Path(ICVSUIConstants.ICON_PATH + ICVSUIConstants.IMG_CVS_PERSPECTIVE), null); } private boolean isRunningInUIThread() { @@ -185,7 +189,7 @@ } private boolean promptEdit(Shell shell) { - // Open the dialog using a sync exec (there are no guarentees that we + // Open the dialog using a sync exec (there are no guarantees that we // were called from the UI thread final boolean[] result = new boolean[] { false }; int flags = isRunningInUIThread() ? 0 : CVSUIPlugin.PERFORM_SYNC_EXEC; @@ -198,7 +202,7 @@ } private boolean promptUpdate(Shell shell) { - // Open the dialog using a sync exec (there are no guarentees that we + // Open the dialog using a sync exec (there are no guarantees that we // were called from the UI thread final boolean[] result = new boolean[] { false }; int flags = isRunningInUIThread() ? 0 : CVSUIPlugin.PERFORM_SYNC_EXEC; #P org.eclipse.team.cvs.core Index: src/org/eclipse/team/internal/ccvs/core/CVSCoreFileModificationValidator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSCoreFileModificationValidator.java,v retrieving revision 1.10 diff -u -r1.10 CVSCoreFileModificationValidator.java --- src/org/eclipse/team/internal/ccvs/core/CVSCoreFileModificationValidator.java 10 May 2006 18:42:10 -0000 1.10 +++ src/org/eclipse/team/internal/ccvs/core/CVSCoreFileModificationValidator.java 28 Feb 2007 17:44:56 -0000 @@ -10,12 +10,11 @@ *******************************************************************************/ package org.eclipse.team.internal.ccvs.core; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import org.eclipse.core.resources.*; +import org.eclipse.core.resources.team.FileModificationValidationContext; +import org.eclipse.core.resources.team.FileModificationValidator; import org.eclipse.core.runtime.*; import org.eclipse.core.runtime.jobs.*; import org.eclipse.osgi.util.NLS; @@ -25,14 +24,14 @@ /** * Core validator that will load the UI validator only if a prompt is needed */ -public class CVSCoreFileModificationValidator implements ICVSFileModificationValidator { +public class CVSCoreFileModificationValidator extends FileModificationValidator implements ICVSFileModificationValidator { - IFileModificationValidator uiValidator; + FileModificationValidator uiValidator; /* (non-Javadoc) - * @see org.eclipse.core.resources.IFileModificationValidator#validateEdit(org.eclipse.core.resources.IFile[], java.lang.Object) + * @see org.eclipse.core.resources.team.FileModificationValidator#validateEdit(org.eclipse.core.resources.IFile[], org.eclipse.core.resources.team.FileModificationValidationContext) */ - public IStatus validateEdit(IFile[] files, Object context) { + public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { IFile[] unmanagedReadOnlyFiles = getUnmanagedReadOnlyFiles(files); if (unmanagedReadOnlyFiles.length > 0) { IStatus status = setWritable(unmanagedReadOnlyFiles); @@ -55,7 +54,7 @@ } return Status.OK_STATUS; } - return edit(new IFile[] {file}, (Object)null); + return edit(new IFile[] {file}, (FileModificationValidationContext)null); } /** @@ -67,8 +66,8 @@ * @param context * @return */ - protected IStatus edit(IFile[] readOnlyFiles, Object context) { - IFileModificationValidator override = getUIValidator(); + protected IStatus edit(IFile[] readOnlyFiles, FileModificationValidationContext context) { + FileModificationValidator override = getUIValidator(); if (override != null) { return override.validateEdit(readOnlyFiles, context); } else { @@ -77,7 +76,7 @@ } } - private IFileModificationValidator getUIValidator() { + private FileModificationValidator getUIValidator() { synchronized(this) { if (uiValidator == null) { uiValidator = getPluggedInValidator(); @@ -181,7 +180,7 @@ return (IFile[]) readOnlys.toArray(new IFile[readOnlys.size()]); } - private static IFileModificationValidator getPluggedInValidator() { + private static FileModificationValidator getPluggedInValidator() { IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(CVSProviderPlugin.ID, CVSProviderPlugin.PT_FILE_MODIFICATION_VALIDATOR).getExtensions(); if (extensions.length == 0) return null; @@ -193,7 +192,7 @@ } try { IConfigurationElement config = configs[0]; - return (IFileModificationValidator) config.createExecutableExtension("run");//$NON-NLS-1$ + return (FileModificationValidator) config.createExecutableExtension("run");//$NON-NLS-1$ } catch (CoreException ex) { CVSProviderPlugin.log(IStatus.ERROR, NLS.bind("The CVS file modification validator registered as ID {0} could not be instantiated", (new Object[] {extension.getUniqueIdentifier()})), ex);//$NON-NLS-1$ return null; @@ -201,7 +200,7 @@ } public ISchedulingRule validateEditRule(CVSResourceRuleFactory factory, IResource[] resources) { - IFileModificationValidator override = getUIValidator(); + FileModificationValidator override = getUIValidator(); if (override instanceof CVSCoreFileModificationValidator && override != this) { CVSCoreFileModificationValidator ui = (CVSCoreFileModificationValidator) override; return ui.validateEditRule(factory, resources); Index: src/org/eclipse/team/internal/ccvs/core/ICVSFileModificationValidator.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/ICVSFileModificationValidator.java,v retrieving revision 1.5 diff -u -r1.5 ICVSFileModificationValidator.java --- src/org/eclipse/team/internal/ccvs/core/ICVSFileModificationValidator.java 10 May 2006 18:42:10 -0000 1.5 +++ src/org/eclipse/team/internal/ccvs/core/ICVSFileModificationValidator.java 28 Feb 2007 17:44:56 -0000 @@ -11,7 +11,6 @@ package org.eclipse.team.internal.ccvs.core; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFileModificationValidator; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -23,7 +22,7 @@ * To enable and disable the creation of type comments go to * Window>Preferences>Java>Code Generation. */ -public interface ICVSFileModificationValidator extends IFileModificationValidator { +public interface ICVSFileModificationValidator { public IStatus validateMoveDelete(IFile[] files, IProgressMonitor monitor); #P org.eclipse.team.tests.core Index: src/org/eclipse/team/tests/core/RepositoryProviderTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/RepositoryProviderTests.java,v retrieving revision 1.17 diff -u -r1.17 RepositoryProviderTests.java --- src/org/eclipse/team/tests/core/RepositoryProviderTests.java 10 May 2006 17:49:31 -0000 1.17 +++ src/org/eclipse/team/tests/core/RepositoryProviderTests.java 28 Feb 2007 17:44:56 -0000 @@ -11,27 +11,15 @@ package org.eclipse.team.tests.core; import java.io.ByteArrayInputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import junit.extensions.TestSetup; import junit.framework.Test; import junit.framework.TestSuite; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFileModificationValidator; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.team.IMoveDeleteHook; -import org.eclipse.core.resources.team.IResourceTree; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.resources.*; +import org.eclipse.core.resources.team.*; +import org.eclipse.core.runtime.*; import org.eclipse.team.core.RepositoryProvider; import org.eclipse.team.core.TeamException; @@ -132,9 +120,9 @@ // test that validator gets called by team core dispatching final boolean[] called = new boolean[] {false}; - bicProvider.setModificationValidator(new IFileModificationValidator() { + bicProvider.setModificationValidator(new FileModificationValidator() { // can't test validate edit here because it is only called from editors - public IStatus validateEdit(IFile[] files, Object context) { + public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { return null; } public IStatus validateSave(IFile file) { @@ -149,9 +137,9 @@ // test that validator can veto a setContents called[0] = false; - bicProvider.setModificationValidator(new IFileModificationValidator() { + bicProvider.setModificationValidator(new FileModificationValidator() { // can't test validate edit here because it is only called from editors - public IStatus validateEdit(IFile[] files, Object context) { + public IStatus validateEdit(IFile[] files, FileModificationValidationContext context) { return null; } public IStatus validateSave(IFile file) { #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 17:44:58 -0000 @@ -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 17:44:58 -0000 @@ -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; @@ -1272,7 +1273,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 FileModificationValidationContext#PROMPT_IF_POSSIBLE} 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 prompter 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 +1284,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 +1294,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. *

* * @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 + * @param context either {@link FileModificationValidationContext#PROMPT_IF_POSSIBLE}, + * 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 17:44:58 -0000 @@ -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 17:44:58 -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,16 @@ } public void run() throws Exception { - status[0] = validator.validateEdit(files, context); + if (validator instanceof FileModificationValidator) { + FileModificationValidator fmv = (FileModificationValidator) validator; + status[0] = fmv.validateEdit(files, FileModificationValidationContext.createContextFor(context)); + } else { + Object c = context; + 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,102 @@ +/******************************************************************************* + * 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 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 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 IStatus validateEdit(IFile[] files, Object context) { + return validateEdit(files, asValidationContext(context)); + } + + private FileModificationValidationContext asValidationContext(Object context) { + if (context == null) + return null; + if (context instanceof FileModificationValidationContext) { + return (FileModificationValidationContext) context; + } + return new FileModificationValidationContext(context); + } + + /** + * 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,81 @@ +/******************************************************************************* + * 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; +import org.eclipse.core.runtime.Assert; + +/** + * A context that is used in conjunction with the {@link FileModificationValidator} + * to indicate that UI-based validation is desired. + * + * @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 PROMPT_IF_POSSIBLE = new FileModificationValidationContext(); + + private final Object shell; + + /** + * Create a context with the given context object. If the given object is null + * then null is returned. If the object is an org.eclipse.swt.widgets.Shell + * then a {@link FileModificationValidationContext} for the shell is returned. If the object + * is already a {@link FileModificationValidationContext}, then it is returned directly + * Clients that do not have access to a shell but still desire UI-based validation + * can pass {@link #PROMPT_IF_POSSIBLE} as the context. + * @param object the context object or null + */ + public static FileModificationValidationContext createContextFor(Object object) { + if (object == null) + return null; + if (object instanceof FileModificationValidationContext) { + return (FileModificationValidationContext) object; + } + return new FileModificationValidationContext(object); + } + + /** + * Create a context with the given shell + * @param shell the shell + */ + /* package */ FileModificationValidationContext(Object shell) { + Assert.isNotNull(shell); + this.shell = shell; + } + + /** + * Create a context with no shell + */ + private FileModificationValidationContext() { + this.shell = null; + } + + /** + * 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; + } + +}