KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > resources > mapping > ShallowResourceMapping


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.core.internal.resources.mapping;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.resources.mapping.*;
16 import org.eclipse.core.runtime.IProgressMonitor;
17
18 /**
19  * A resource mapping for a shallow container.
20  */

21 public class ShallowResourceMapping extends ResourceMapping {
22
23     private final ShallowContainer container;
24
25     public ShallowResourceMapping(ShallowContainer container) {
26         this.container = container;
27     }
28
29     public Object JavaDoc getModelObject() {
30         return container;
31     }
32
33     public String JavaDoc getModelProviderId() {
34         return ModelProvider.RESOURCE_MODEL_PROVIDER_ID;
35     }
36
37     public IProject[] getProjects() {
38         return new IProject[] { container.getResource().getProject() };
39     }
40
41     public ResourceTraversal[] getTraversals(ResourceMappingContext context, IProgressMonitor monitor) {
42         return new ResourceTraversal[] { new ResourceTraversal(new IResource[] { container.getResource() }, IResource.DEPTH_ONE, IResource.NONE)};
43     }
44     
45     public boolean contains(ResourceMapping mapping) {
46         if (mapping.getModelProviderId().equals(this.getModelProviderId())) {
47             Object JavaDoc object = mapping.getModelObject();
48             IResource resource = container.getResource();
49             // A shallow mapping only contains direct file children or equal shallow containers
50
if (object instanceof ShallowContainer) {
51                 ShallowContainer sc = (ShallowContainer) object;
52                 return sc.getResource().equals(resource);
53             }
54             if (object instanceof IResource) {
55                 IResource other = (IResource) object;
56                 return other.getType() == IResource.FILE
57                     && resource.getFullPath().equals(other.getFullPath().removeLastSegments(1));
58             }
59         }
60         return false;
61     }
62
63 }
64
Popular Tags