KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > model > CVSAdapterFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.ccvs.ui.model;
12
13  
14 import org.eclipse.core.runtime.IAdapterFactory;
15 import org.eclipse.team.core.history.IFileRevision;
16 import org.eclipse.team.internal.ccvs.core.*;
17 import org.eclipse.team.internal.ccvs.ui.*;
18 import org.eclipse.team.internal.ccvs.ui.mappings.ChangeSetCompareAdapter;
19 import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
20 import org.eclipse.team.ui.history.IHistoryPageSource;
21 import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
22 import org.eclipse.team.ui.mapping.ITeamStateProvider;
23 import org.eclipse.ui.model.IWorkbenchAdapter;
24 import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
25 import org.eclipse.ui.views.properties.IPropertySource;
26
27 public class CVSAdapterFactory implements IAdapterFactory {
28     private static Object JavaDoc fileAdapter = new RemoteFileElement();
29     private static Object JavaDoc folderAdapter = new RemoteFolderElement();
30     private static Object JavaDoc rootAdapter = new CVSRepositoryRootElement();
31
32     private static Object JavaDoc historyParticipant = new CVSHistoryPageSource();
33     
34     private static Object JavaDoc teamStateProvider;
35     
36     // Property cache
37
private Object JavaDoc cachedPropertyObject = null;
38     private Object JavaDoc cachedPropertyValue = null;
39     private ChangeSetCompareAdapter compareAdapter;
40
41     /** (Non-javadoc)
42      * Method declared on IAdapterFactory.
43      */

44     public Object JavaDoc getAdapter(Object JavaDoc adaptableObject, Class JavaDoc adapterType) {
45         if (IWorkbenchAdapter.class == adapterType) {
46             return getWorkbenchAdapter(adaptableObject);
47         }
48         
49         if(IDeferredWorkbenchAdapter.class == adapterType) {
50              Object JavaDoc o = getWorkbenchAdapter(adaptableObject);
51              if(o != null && o instanceof IDeferredWorkbenchAdapter) {
52                 return o;
53              }
54              return null;
55         }
56         
57         if (IPropertySource.class == adapterType) {
58             return getPropertySource(adaptableObject);
59         }
60         
61         if (IHistoryPageSource.class == adapterType){
62             return historyParticipant;
63         }
64         
65         if (ITeamStateProvider.class == adapterType) {
66             synchronized (this) {
67                 if (teamStateProvider == null)
68                     teamStateProvider = new CVSTeamStateProvider(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber());
69             }
70             return teamStateProvider;
71         }
72         
73         if (ISynchronizationCompareAdapter.class == adapterType) {
74             if (compareAdapter == null)
75                 compareAdapter = new ChangeSetCompareAdapter();
76             return compareAdapter;
77         }
78         
79         if (IFileRevision.class == adapterType && adaptableObject instanceof RemoteFileEditorInput) {
80             return ((RemoteFileEditorInput)adaptableObject).getFileRevision();
81         }
82         
83         return null;
84     }
85     
86     protected Object JavaDoc getWorkbenchAdapter(Object JavaDoc o) {
87         if (o instanceof ICVSRemoteFile) {
88             return fileAdapter;
89         } else if (o instanceof ICVSRepositoryLocation) {
90             return rootAdapter;
91         } else if (o instanceof RepositoryRoot) {
92             return rootAdapter;
93         } else if (o instanceof ICVSRemoteFolder) {
94             return folderAdapter;
95         }
96         return null;
97     }
98     
99     /** (Non-javadoc)
100      * Method declared on IAdapterFactory.
101      */

102     public Class JavaDoc[] getAdapterList() {
103         return new Class JavaDoc[] { IWorkbenchAdapter.class, IPropertySource.class,
104                 IDeferredWorkbenchAdapter.class, IHistoryPageSource.class,
105                 ISynchronizationCompareAdapter.class, ITeamStateProvider.class,
106                 IFileRevision.class};
107     }
108     
109     /**
110      * Returns the property source for the given object. Caches
111      * the result because the property sheet is extremely inefficient,
112      * it asks for the source seven times in a row.
113      */

114     public Object JavaDoc getPropertySource(Object JavaDoc adaptableObject) {
115         if (adaptableObject == cachedPropertyObject) {
116             return cachedPropertyValue;
117         }
118         cachedPropertyObject = adaptableObject;
119         if (adaptableObject instanceof ICVSRemoteFile) {
120             cachedPropertyValue = new CVSRemoteFilePropertySource((ICVSRemoteFile)adaptableObject);
121         } else if (adaptableObject instanceof ICVSRemoteFolder) {
122             cachedPropertyValue = new CVSRemoteFolderPropertySource((ICVSRemoteFolder)adaptableObject);
123         } else if (adaptableObject instanceof ICVSRepositoryLocation) {
124             cachedPropertyValue = new CVSRepositoryLocationPropertySource((ICVSRepositoryLocation)adaptableObject);
125         } else if (adaptableObject instanceof RepositoryRoot) {
126             cachedPropertyValue = new CVSRepositoryLocationPropertySource(((RepositoryRoot)adaptableObject).getRoot());
127         } else {
128             cachedPropertyValue = null;
129         }
130         return cachedPropertyValue;
131     }
132 }
133
Popular Tags