KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > core > subscribers > ThreeWayBaseTree


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.subscribers;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.team.core.TeamException;
16 import org.eclipse.team.core.variants.IResourceVariant;
17 import org.eclipse.team.core.variants.ResourceVariantByteStore;
18 import org.eclipse.team.core.variants.ResourceVariantTree;
19 import org.eclipse.team.core.variants.ThreeWaySubscriber;
20
21 /**
22  * Allow access to the base resource variants but do not support refresh
23  * or modification.
24  */

25 public final class ThreeWayBaseTree extends ResourceVariantTree {
26
27     private ThreeWaySubscriber subscriber;
28
29     /*
30      * A resource variant byte store that accesses the base bytes from a three-way
31      * synchronizer. The modification methods are disabled as the base should
32      * only be modified in the synchronizer directly.
33      */

34     static class BaseResourceVariantByteStore extends ResourceVariantByteStore {
35         private ThreeWaySubscriber subscriber;
36         public BaseResourceVariantByteStore(ThreeWaySubscriber subscriber) {
37             this.subscriber = subscriber;
38         }
39         public void dispose() {
40             // Nothing to do
41
}
42         public byte[] getBytes(IResource resource) throws TeamException {
43             return subscriber.getSynchronizer().getBaseBytes(resource);
44         }
45         public boolean setBytes(IResource resource, byte[] bytes) throws TeamException {
46             // Base bytes are set directly in the synchronizer
47
return false;
48         }
49         public boolean flushBytes(IResource resource, int depth) throws TeamException {
50             // Base bytes are flushed directly in the synchronizer
51
return false;
52         }
53         public boolean deleteBytes(IResource resource) throws TeamException {
54             // Base bytes are deleted directly in the synchronizer
55
return false;
56         }
57         public IResource[] members(IResource resource) throws TeamException {
58             return subscriber.getSynchronizer().members(resource);
59         }
60     }
61     
62     /**
63      * Create a base resource variant tree that accesses the base bytes
64      * from a three-way synchronizer.
65      * @param subscriber the three-way subscriber
66      */

67     public ThreeWayBaseTree(ThreeWaySubscriber subscriber) {
68         super(new BaseResourceVariantByteStore(subscriber));
69         this.subscriber = subscriber;
70     }
71     
72     /* (non-Javadoc)
73      * @see org.eclipse.team.internal.core.subscribers.caches.AbstractResourceVariantTree#refresh(org.eclipse.core.resources.IResource[], int, org.eclipse.core.runtime.IProgressMonitor)
74      */

75     public IResource[] refresh(IResource[] resources, int depth, IProgressMonitor monitor) throws TeamException {
76         return new IResource[0];
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.team.internal.core.subscribers.caches.AbstractResourceVariantTree#fetchMembers(org.eclipse.team.core.synchronize.IResourceVariant, org.eclipse.core.runtime.IProgressMonitor)
81      */

82     protected IResourceVariant[] fetchMembers(IResourceVariant variant, IProgressMonitor progress) throws TeamException {
83         // Refresh not supported
84
return new IResourceVariant[0];
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.team.internal.core.subscribers.caches.AbstractResourceVariantTree#fetchVariant(org.eclipse.core.resources.IResource, int, org.eclipse.core.runtime.IProgressMonitor)
89      */

90     protected IResourceVariant fetchVariant(IResource resource, int depth, IProgressMonitor monitor) throws TeamException {
91         // Refresh not supported
92
return null;
93     }
94
95     /* (non-Javadoc)
96      * @see org.eclipse.team.internal.core.subscribers.caches.IResourceVariantTree#roots()
97      */

98     public IResource[] roots() {
99         return getSubscriber().roots();
100     }
101
102     /* (non-Javadoc)
103      * @see org.eclipse.team.internal.core.subscribers.caches.IResourceVariantTree#getResourceVariant(org.eclipse.core.resources.IResource)
104      */

105     public IResourceVariant getResourceVariant(IResource resource) throws TeamException {
106         return getSubscriber().getResourceVariant(resource, getByteStore().getBytes(resource));
107     }
108
109     private ThreeWaySubscriber getSubscriber() {
110         return subscriber;
111     }
112     
113 }
114
Popular Tags