KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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 java.net.URI JavaDoc;
14 import org.eclipse.core.filesystem.EFS;
15 import org.eclipse.core.filesystem.URIUtil;
16 import org.eclipse.core.internal.resources.InternalTeamHook;
17 import org.eclipse.core.resources.*;
18 import org.eclipse.core.runtime.*;
19
20 /**
21  * A general hook class for operations that team providers may be
22  * interested in participating in. Implementors of the hook should provide
23  * a concrete subclass, and override any methods they are interested in.
24  * <p>
25  * This class is intended to be subclassed by the team component in
26  * conjunction with the <code>org.eclipse.core.resources.teamHook</code>
27  * standard extension point. Individual team providers may also subclass this
28  * class. It is not intended to be subclassed by other clients. The methods
29  * defined on this class are called from within the implementations of
30  * workspace API methods and must not be invoked directly by clients.
31  * </p>
32  *
33  * @since 2.1
34  */

35 public abstract class TeamHook extends InternalTeamHook {
36     /**
37      * The default resource scheduling rule factory. This factory can be used for projects
38      * that the team hook methods do not participate in.
39      *
40      * @see #getRuleFactory(IProject)
41      * @see #setRuleFactory(IProject, IResourceRuleFactory)
42      * @since 3.0
43      */

44     protected final IResourceRuleFactory defaultFactory = new ResourceRuleFactory();
45
46     /**
47      * Creates a new team hook. Default constructor for use by subclasses and the
48      * resources plug-in only.
49      */

50     protected TeamHook() {
51         super();
52     }
53
54     /**
55      * Returns the resource scheduling rule factory that should be used when workspace
56      * operations are invoked on resources in that project. The workspace will ask the
57      * team hook this question only once per project, per session. The workspace will
58      * assume the returned result is valid for the rest of that session, unless the rule
59      * is changed by calling <code>setRuleFactory</code>.
60      * <p>
61      * This method must not return <code>null</code>. If no special rules are required
62      * by the team hook for the given project, the value of the <code>defaultFactory</code>
63      * field should be returned.
64      * <p>
65      * This default implementation always returns the value of the <code>defaultFactory</code>
66      * field. Subclasses may override and provide a subclass of <code>ResourceRuleFactory</code>.
67      *
68      * @param project the project to return scheduling rules for
69      * @return the resource scheduling rules for a project
70      * @see #setRuleFactory(IProject, IResourceRuleFactory)
71      * @see ResourceRuleFactory
72      * @since 3.0
73      */

74     public IResourceRuleFactory getRuleFactory(IProject project) {
75         return defaultFactory;
76     }
77
78     /**
79      * Sets the resource scheduling rule factory to use for resource modifications
80      * in the given project. This method only needs to be called if the factory has changed
81      * since the initial call to <code>getRuleFactory</code> for the given project
82      * <p>
83      * The supplied factory must not be <code>null</code>. If no special rules are required
84      * by the team hook for the given project, the value of the <code>defaultFactory</code>
85      * field should be used.
86      * <p>
87      * Note that the new rule factory will only take effect for resource changing
88      * operations that begin after this method completes. Care should be taken to
89      * avoid calling this method during the invocation of any resource changing
90      * operation (in any thread). The best time to change rule factories is during resource
91      * change notification when the workspace is locked for modification.
92      *
93      * @param project the project to change the resource rule factory for
94      * @param factory the new resource rule factory
95      * @see #getRuleFactory(IProject)
96      * @see IResourceRuleFactory
97      * @since 3.0
98      */

99     protected final void setRuleFactory(IProject project, IResourceRuleFactory factory) {
100         super.setRuleFactory(project, factory);
101     }
102
103     /**
104      * Validates whether a particular attempt at link creation is allowed. This gives
105      * team providers an opportunity to hook into the beginning of the implementation
106      * of <code>IFile.createLink</code>.
107      * <p>
108      * The implementation of this method runs "below" the resources API and is
109      * therefore very restricted in what resource API method it can call. The
110      * list of useable methods includes most resource operations that read but
111      * do not update the resource tree; resource operations that modify
112      * resources and trigger deltas must not be called from within the dynamic
113      * scope of the invocation of this method.
114      * </p><p>
115      * This method should be overridden by subclasses that want to control what
116      * links are created. The default implementation of this method allows all links
117      * to be created.
118      * </p>
119      *
120      * @param file the file to be linked
121      * @param updateFlags bit-wise or of update flag constants
122      * (only ALLOW_MISSING_LOCAL is relevant here)
123      * @param location a file system path where the file should be linked
124      * @return a status object with code <code>IStatus.OK</code>
125      * if linking is allowed, otherwise a status object with severity
126      * <code>IStatus.ERROR</code> indicating why the creation is not allowed.
127      * @see org.eclipse.core.resources.IResource#ALLOW_MISSING_LOCAL
128      */

129     public IStatus validateCreateLink(IFile file, int updateFlags, IPath location) {
130         return Status.OK_STATUS;
131     }
132
133     /**
134      * Validates whether a particular attempt at link creation is allowed. This gives
135      * team providers an opportunity to hook into the beginning of the implementation
136      * of {@link IFile#createLink(URI, int, IProgressMonitor) }
137      * <p>
138      * The implementation of this method runs "below" the resources API and is
139      * therefore very restricted in what resource API method it can call. The
140      * list of useable methods includes most resource operations that read but
141      * do not update the resource tree; resource operations that modify
142      * resources and trigger deltas must not be called from within the dynamic
143      * scope of the invocation of this method.
144      * </p><p>
145      * This method should be overridden by subclasses that want to control what
146      * links are created. The default implementation of this method allows all links
147      * to be created.
148      * </p>
149      *
150      * @param file the file to be linked
151      * @param updateFlags bit-wise or of update flag constants
152      * (only ALLOW_MISSING_LOCAL is relevant here)
153      * @param location a file system URI where the file should be linked
154      * @return a status object with code <code>IStatus.OK</code>
155      * if linking is allowed, otherwise a status object with severity
156      * <code>IStatus.ERROR</code> indicating why the creation is not allowed.
157      * @see org.eclipse.core.resources.IResource#ALLOW_MISSING_LOCAL
158      * @since 3.2
159      */

160     public IStatus validateCreateLink(IFile file, int updateFlags, URI JavaDoc location) {
161         //forward to old method to ensure old hooks get a chance to validate in the local case
162
if (EFS.SCHEME_FILE.equals(location.getScheme()))
163             return validateCreateLink(file, updateFlags, URIUtil.toPath(location));
164         return Status.OK_STATUS;
165     }
166
167     /**
168      * Validates whether a particular attempt at link creation is allowed. This gives
169      * team providers an opportunity to hook into the beginning of the implementation
170      * of <code>IFolder.createLink</code>.
171      * <p>
172      * The implementation of this method runs "below" the resources API and is
173      * therefore very restricted in what resource API method it can call. The
174      * list of useable methods includes most resource operations that read but
175      * do not update the resource tree; resource operations that modify
176      * resources and trigger deltas must not be called from within the dynamic
177      * scope of the invocation of this method.
178      * </p><p>
179      * This method should be overridden by subclasses that want to control what
180      * links are created. The default implementation of this method allows all links
181      * to be created.
182      * </p>
183      *
184      * @param folder the file to be linked
185      * @param updateFlags bit-wise or of update flag constants
186      * (only ALLOW_MISSING_LOCAL is relevant here)
187      * @param location a file system path where the folder should be linked
188      * @return a status object with code <code>IStatus.OK</code>
189      * if linking is allowed, otherwise a status object with severity
190      * <code>IStatus.ERROR</code> indicating why the creation is not allowed.
191      * @see org.eclipse.core.resources.IResource#ALLOW_MISSING_LOCAL
192      */

193     public IStatus validateCreateLink(IFolder folder, int updateFlags, IPath location) {
194         return Status.OK_STATUS;
195     }
196
197     /**
198      * Validates whether a particular attempt at link creation is allowed. This gives
199      * team providers an opportunity to hook into the beginning of the implementation
200      * of {@link IFolder#createLink(URI, int, IProgressMonitor)}
201      * <p>
202      * The implementation of this method runs "below" the resources API and is
203      * therefore very restricted in what resource API method it can call. The
204      * list of useable methods includes most resource operations that read but
205      * do not update the resource tree; resource operations that modify
206      * resources and trigger deltas must not be called from within the dynamic
207      * scope of the invocation of this method.
208      * </p><p>
209      * This method should be overridden by subclasses that want to control what
210      * links are created. The default implementation of this method allows all links
211      * to be created.
212      * </p>
213      *
214      * @param folder the file to be linked
215      * @param updateFlags bit-wise or of update flag constants
216      * (only ALLOW_MISSING_LOCAL is relevant here)
217      * @param location a file system path where the folder should be linked
218      * @return a status object with code <code>IStatus.OK</code>
219      * if linking is allowed, otherwise a status object with severity
220      * <code>IStatus.ERROR</code> indicating why the creation is not allowed.
221      * @see org.eclipse.core.resources.IResource#ALLOW_MISSING_LOCAL
222      * @since 3.2
223      */

224     public IStatus validateCreateLink(IFolder folder, int updateFlags, URI JavaDoc location) {
225         //forward to old method to ensure old hooks get a chance to validate in the local case
226
if (EFS.SCHEME_FILE.equals(location.getScheme()))
227             return validateCreateLink(folder, updateFlags, URIUtil.toPath(location));
228         return Status.OK_STATUS;
229     }
230 }
231
Popular Tags