platform35/org.eclipse.core.resources/src/org/eclipse/core/resources/team/FileModificationValidator.java
author timkelly
Thu, 30 Jul 2009 11:56:23 -0500
changeset 40 eb3c938c7fef
permissions -rw-r--r--
set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     1
/*******************************************************************************
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     2
 * Copyright (c) 2007 IBM Corporation and others.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     3
 * All rights reserved. This program and the accompanying materials
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     4
 * are made available under the terms of the Eclipse Public License v1.0
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     5
 * which accompanies this distribution, and is available at
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     6
 * http://www.eclipse.org/legal/epl-v10.html
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     7
 * 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     8
 * Contributors:
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
     9
 *     IBM Corporation - initial API and implementation
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    10
 *******************************************************************************/
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    11
package org.eclipse.core.resources.team;
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    12
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    13
import org.eclipse.core.resources.*;
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    14
import org.eclipse.core.runtime.IStatus;
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    15
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    16
/**
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    17
 * The file modification validator is a Team-related hook for pre-checking operations 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    18
 * that modify the contents of files.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    19
 * <p>
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    20
 * This class is used only in conjunction with the
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    21
 * "org.eclipse.core.resources.fileModificationValidator"
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    22
 * extension point. It is intended to be implemented only 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    23
 * by the Eclipse Platform Team plug-in or by repository providers
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    24
 * whose validator get invoked by Team.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    25
 * </p>
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    26
 * @since 3.3
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    27
 */
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    28
public abstract class FileModificationValidator implements IFileModificationValidator {
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    29
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    30
	/**
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    31
	 * Validates that the given files can be modified.  The files must all exist
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    32
	 * in the workspace.  The optional context object may be supplied if
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    33
	 * UI-based validation is required.  If the context is <code>null</code>, the 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    34
	 * validator must attempt to perform the validation in a headless manner.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    35
	 * The returned status is <code>IStatus.OK</code> if this validator 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    36
	 * believes the given file can be modified.  Other return statuses indicate
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    37
	 * the reason why the individual files cannot be modified.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    38
	 * 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    39
	 * @param files the files that are to be modified; these files must all exist in the workspace
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    40
	 * @param context the <code>org.eclipse.swt.widgets.Shell</code> that is to be used to
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    41
	 *    parent any dialogs with the user, or <code>null</code> if there is no UI context (declared
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    42
	 *   as an <code>Object</code> to avoid any direct references on the SWT component)
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    43
	 * @return a status object that is OK if things are fine, otherwise a status describing
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    44
	 *    reasons why modifying the given files is not reasonable
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    45
	 * @see IWorkspace#validateEdit(IFile[], Object)
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    46
	 * @deprecated this method is part of the deprecated {@link IFileModificationValidator}
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    47
	 * interface. Clients should call {@link #validateEdit(IFile[], FileModificationValidationContext)}
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    48
	 * instead.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    49
	 */
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    50
	public final IStatus validateEdit(IFile[] files, Object context) {
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    51
		FileModificationValidationContext validationContext;
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    52
		if (context == null)
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    53
			validationContext = null;
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    54
		else if (context instanceof FileModificationValidationContext)
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    55
			validationContext = (FileModificationValidationContext) context;
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    56
		else
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    57
			validationContext = new FileModificationValidationContext(context);
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    58
		return validateEdit(files, validationContext);
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    59
	}
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    60
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    61
	/**
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    62
	 * Validates that the given file can be saved.  This method is called from 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    63
	 * <code>IFile#setContents</code> and <code>IFile#appendContents</code> 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    64
	 * before any attempt to write data to disk.  The returned status is 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    65
	 * <code>IStatus.OK</code> if this validator believes the given file can be 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    66
	 * successfully saved.  In all other cases the return value is a non-OK status.  
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    67
	 * Note that a return value of <code>IStatus.OK</code> does not guarantee 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    68
	 * that the save will succeed.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    69
	 * 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    70
	 * @param file the file that is to be modified; this file must exist in the workspace
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    71
	 * @return a status indicating whether or not it is reasonable to try writing to the given file; 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    72
	 * <code>IStatus.OK</code> indicates a save should be attempted.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    73
	 * 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    74
	 * @see IFile#setContents(java.io.InputStream, int, org.eclipse.core.runtime.IProgressMonitor)
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    75
	 * @see IFile#appendContents(java.io.InputStream, int, org.eclipse.core.runtime.IProgressMonitor)
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    76
	 */
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    77
	public IStatus validateSave(IFile file) {
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    78
		return validateEdit(new IFile[] {file}, (FileModificationValidationContext) null);
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    79
	}
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    80
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    81
	/**
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    82
	 * Validates that the given files can be modified.  The files must all exist
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    83
	 * in the workspace.  The optional context may be supplied if
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    84
	 * UI-based validation is required.  If the context is <code>null</code>, the 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    85
	 * validator must attempt to perform the validation in a headless manner.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    86
	 * The returned status is <code>IStatus.OK</code> if this validator 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    87
	 * believes the given file can be modified.  Other return statuses indicate
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    88
	 * the reason why the individual files cannot be modified.
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    89
	 * 
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    90
	 * @param files the files that are to be modified; these files must all exist in the workspace
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    91
	 * @param context the context to aid in UI-based validation or <code>null</code> if the validation
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    92
	 *    must be headless
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    93
	 * @return a status object that is OK if things are fine, otherwise a status describing
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    94
	 *    reasons why modifying the given files is not reasonable
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    95
	 * @see IWorkspace#validateEdit(IFile[], Object)
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    96
	 */
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    97
	public abstract IStatus validateEdit(IFile[] files, FileModificationValidationContext context);
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    98
eb3c938c7fef set up for custom build for logging. merged from carbide 2.1.x builds. this state is as it comes from platform. Next changelog will add the updates.
timkelly
parents:
diff changeset
    99
}