KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > mapping > ModelProviderResourceMapping


1 /*******************************************************************************
2  * Copyright (c) 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.mapping;
12
13 import java.util.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.resources.*;
17 import org.eclipse.core.resources.mapping.*;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.team.internal.core.Policy;
21 import org.eclipse.team.internal.core.TeamPlugin;
22
23 public class ModelProviderResourceMapping extends ResourceMapping {
24
25     ModelProvider provider;
26     
27     public ModelProviderResourceMapping(ModelProvider provider) {
28         this.provider = provider;
29     }
30     
31     /* (non-Javadoc)
32      * @see org.eclipse.core.resources.mapping.ResourceMapping#getModelObject()
33      */

34     public Object JavaDoc getModelObject() {
35         return provider;
36     }
37
38     /* (non-Javadoc)
39      * @see org.eclipse.core.resources.mapping.ResourceMapping#getModelProviderId()
40      */

41     public String JavaDoc getModelProviderId() {
42         // Use the resource model provider id. Model providers
43
// can override this by adapting their specific model provider class
44
return ModelProvider.RESOURCE_MODEL_PROVIDER_ID;
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.core.resources.mapping.ResourceMapping#getProjects()
49      */

50     public IProject[] getProjects() {
51         IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
52         try {
53             IResource[] resources = provider.getDescriptor().getMatchingResources(projects);
54             Set JavaDoc result = new HashSet JavaDoc();
55             for (int i = 0; i < resources.length; i++) {
56                 IResource resource = resources[i];
57                 if (resource.isAccessible())
58                     result.add(resource.getProject());
59             }
60             return (IProject[]) result.toArray(new IProject[result.size()]);
61         } catch (CoreException e) {
62             TeamPlugin.log(e);
63         }
64         return projects;
65     }
66
67     /* (non-Javadoc)
68      * @see org.eclipse.core.resources.mapping.ResourceMapping#getTraversals(org.eclipse.core.resources.mapping.ResourceMappingContext, org.eclipse.core.runtime.IProgressMonitor)
69      */

70     public ResourceTraversal[] getTraversals(ResourceMappingContext context,
71             IProgressMonitor monitor) throws CoreException {
72         monitor = Policy.monitorFor(monitor);
73         try {
74             monitor.beginTask(null, 100);
75             ResourceMapping[] mappings = provider.getMappings(getProviderResources(context), context, Policy.subMonitorFor(monitor, 50));
76             return provider.getTraversals(mappings, context, Policy.subMonitorFor(monitor, 50));
77         } finally {
78             monitor.done();
79         }
80     }
81
82     private IResource[] getProviderResources(ResourceMappingContext context) {
83         try {
84             if (context instanceof RemoteResourceMappingContext) {
85                 RemoteResourceMappingContext rrmc = (RemoteResourceMappingContext) context;
86                 return provider.getDescriptor().getMatchingResources(rrmc.getProjects());
87             }
88         } catch (CoreException e) {
89             TeamPlugin.log(e);
90         }
91         return getProjects();
92     }
93     
94     public boolean contains(ResourceMapping mapping) {
95         return (mapping.getModelProviderId().equals(getModelProviderId()));
96     }
97
98 }
99
Popular Tags