KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > TeamHookDispatcher


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.team.internal.core;
12
13 import java.net.URI JavaDoc;
14
15 import org.eclipse.core.resources.*;
16 import org.eclipse.core.resources.team.ResourceRuleFactory;
17 import org.eclipse.core.resources.team.TeamHook;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.team.core.RepositoryProvider;
21
22 /**
23  * This class forwards TeamHook callbacks to the proper RepositoryProvider
24  */

25 public class TeamHookDispatcher extends TeamHook {
26     
27     private static final ResourceRuleFactory defaultFactory = new ResourceRuleFactory() {};
28     private static TeamHookDispatcher instance;
29     
30     public static void setProviderRuleFactory(IProject project, IResourceRuleFactory factory) {
31         if (instance != null) {
32             if (factory == null) {
33                 factory = defaultFactory;
34             }
35             instance.setRuleFactory(project, factory);
36         }
37     }
38     
39     public TeamHookDispatcher() {
40         instance = this;
41     }
42
43     /**
44      * @see org.eclipse.core.resources.team.TeamHook#validateCreateLink(org.eclipse.core.resources.IFile, int, org.eclipse.core.runtime.IPath)
45      */

46     public IStatus validateCreateLink(IFile file, int updateFlags, IPath location) {
47         RepositoryProvider provider = getProvider(file);
48         if (provider == null) {
49             return super.validateCreateLink(file, updateFlags, location);
50         } else {
51             return provider.validateCreateLink(file, updateFlags, location);
52         }
53     }
54     
55     /* (non-Javadoc)
56      * @see org.eclipse.core.resources.team.TeamHook#validateCreateLink(org.eclipse.core.resources.IFile, int, java.net.URI)
57      */

58     public IStatus validateCreateLink(IFile file, int updateFlags, URI JavaDoc location) {
59         RepositoryProvider provider = getProvider(file);
60         if (provider == null) {
61             return super.validateCreateLink(file, updateFlags, location);
62         } else {
63             return provider.validateCreateLink(file, updateFlags, location);
64         }
65     }
66
67     /**
68      * @see org.eclipse.core.resources.team.TeamHook#validateCreateLink(org.eclipse.core.resources.IFolder, int, org.eclipse.core.runtime.IPath)
69      */

70     public IStatus validateCreateLink(IFolder folder, int updateFlags, IPath location) {
71         RepositoryProvider provider = getProvider(folder);
72         if (provider == null) {
73             return super.validateCreateLink(folder, updateFlags, location);
74         } else {
75             return provider.validateCreateLink(folder, updateFlags, location);
76         }
77     }
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.core.resources.team.TeamHook#validateCreateLink(org.eclipse.core.resources.IFolder, int, java.net.URI)
81      */

82     public IStatus validateCreateLink(IFolder folder, int updateFlags, URI JavaDoc location) {
83         RepositoryProvider provider = getProvider(folder);
84         if (provider == null) {
85             return super.validateCreateLink(folder, updateFlags, location);
86         } else {
87             return provider.validateCreateLink(folder, updateFlags, location);
88         }
89     }
90     
91     /**
92      * Method getProvider.
93      * @param folder
94      * @return RepositoryProvider
95      */

96     private RepositoryProvider getProvider(IResource resource) {
97         return RepositoryProvider.getProvider(resource.getProject());
98     }
99
100     /* (non-Javadoc)
101      * @see org.eclipse.core.resources.team.TeamHook#getRuleFactory(org.eclipse.core.resources.IProject)
102      */

103     public IResourceRuleFactory getRuleFactory(IProject project) {
104         if (RepositoryProvider.isShared(project)) {
105             RepositoryProvider provider = getProvider(project);
106             // Provider can be null if the provider plugin is not available
107
if (provider != null) {
108                 return provider.getRuleFactory();
109             }
110         }
111         // Use the default provided by the superclass
112
return super.getRuleFactory(project);
113     }
114     
115 }
116
Popular Tags