KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > resources > team > FileModificationValidator


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.resources.team;
12
13 import org.eclipse.core.resources.*;
14 import org.eclipse.core.runtime.IStatus;
15
16 /**
17  * The file modification validator is a Team-related hook for pre-checking operations
18  * that modify the contents of files.
19  * <p>
20  * This class is used only in conjunction with the
21  * "org.eclipse.core.resources.fileModificationValidator"
22  * extension point. It is intended to be implemented only
23  * by the Eclipse Platform Team plug-in or by repository providers
24  * whose validator get invoked by Team.
25  * </p>
26  * @since 3.3
27  */

28 public abstract class FileModificationValidator implements IFileModificationValidator {
29
30     /**
31      * Validates that the given files can be modified. The files must all exist
32      * in the workspace. The optional context object may be supplied if
33      * UI-based validation is required. If the context is <code>null</code>, the
34      * validator must attempt to perform the validation in a headless manner.
35      * The returned status is <code>IStatus.OK</code> if this validator
36      * believes the given file can be modified. Other return statuses indicate
37      * the reason why the individual files cannot be modified.
38      *
39      * @param files the files that are to be modified; these files must all exist in the workspace
40      * @param context the <code>org.eclipse.swt.widgets.Shell</code> that is to be used to
41      * parent any dialogs with the user, or <code>null</code> if there is no UI context (declared
42      * as an <code>Object</code> to avoid any direct references on the SWT component)
43      * @return a status object that is OK if things are fine, otherwise a status describing
44      * reasons why modifying the given files is not reasonable
45      * @see IWorkspace#validateEdit(IFile[], Object)
46      * @deprecated this method is part of the deprecated {@link IFileModificationValidator}
47      * interface. Clients should call {@link #validateEdit(IFile[], FileModificationValidationContext)}
48      * instead.
49      */

50     public final IStatus validateEdit(IFile[] files, Object JavaDoc context) {
51         FileModificationValidationContext validationContext;
52         if (context == null)
53             validationContext = null;
54         else if (context instanceof FileModificationValidationContext)
55             validationContext = (FileModificationValidationContext) context;
56         else
57             validationContext = new FileModificationValidationContext(context);
58         return validateEdit(files, validationContext);
59     }
60
61     /**
62      * Validates that the given file can be saved. This method is called from
63      * <code>IFile#setContents</code> and <code>IFile#appendContents</code>
64      * before any attempt to write data to disk. The returned status is
65      * <code>IStatus.OK</code> if this validator believes the given file can be
66      * successfully saved. In all other cases the return value is a non-OK status.
67      * Note that a return value of <code>IStatus.OK</code> does not guarantee
68      * that the save will succeed.
69      *
70      * @param file the file that is to be modified; this file must exist in the workspace
71      * @return a status indicating whether or not it is reasonable to try writing to the given file;
72      * <code>IStatus.OK</code> indicates a save should be attempted.
73      *
74      * @see IFile#setContents(java.io.InputStream, int, org.eclipse.core.runtime.IProgressMonitor)
75      * @see IFile#appendContents(java.io.InputStream, int, org.eclipse.core.runtime.IProgressMonitor)
76      */

77     public IStatus validateSave(IFile file) {
78         return validateEdit(new IFile[] {file}, (FileModificationValidationContext) null);
79     }
80
81     /**
82      * Validates that the given files can be modified. The files must all exist
83      * in the workspace. The optional context may be supplied if
84      * UI-based validation is required. If the context is <code>null</code>, the
85      * validator must attempt to perform the validation in a headless manner.
86      * The returned status is <code>IStatus.OK</code> if this validator
87      * believes the given file can be modified. Other return statuses indicate
88      * the reason why the individual files cannot be modified.
89      *
90      * @param files the files that are to be modified; these files must all exist in the workspace
91      * @param context the context to aid in UI-based validation or <code>null</code> if the validation
92      * must be headless
93      * @return a status object that is OK if things are fine, otherwise a status describing
94      * reasons why modifying the given files is not reasonable
95      * @see IWorkspace#validateEdit(IFile[], Object)
96      */

97     public abstract IStatus validateEdit(IFile[] files, FileModificationValidationContext context);
98
99 }
100
Popular Tags