Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5718ac86e8b435e81bdf25e88a8a2ea1241e8d5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*******************************************************************************
 * Copyright (c) 2000, 2018 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.team.internal.ccvs.ui.model;

 
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.team.core.history.IFileRevision;
import org.eclipse.team.internal.ccvs.core.*;
import org.eclipse.team.internal.ccvs.ui.*;
import org.eclipse.team.internal.ccvs.ui.mappings.ChangeSetCompareAdapter;
import org.eclipse.team.internal.ccvs.ui.repo.RepositoryRoot;
import org.eclipse.team.ui.history.IHistoryPageSource;
import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
import org.eclipse.team.ui.mapping.ITeamStateProvider;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.progress.IDeferredWorkbenchAdapter;
import org.eclipse.ui.views.properties.IPropertySource;

public class CVSAdapterFactory implements IAdapterFactory {
	private static Object fileAdapter = new RemoteFileElement();
	private static Object folderAdapter = new RemoteFolderElement();
	private static Object rootAdapter = new CVSRepositoryRootElement();

	private static Object historyParticipant = new CVSHistoryPageSource();
	
	private static Object teamStateProvider;
	
	// Property cache
	private Object cachedPropertyObject = null;
	private Object cachedPropertyValue = null;
	private ChangeSetCompareAdapter compareAdapter;

	public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
		if (IWorkbenchAdapter.class == adapterType) {
			return adapterType.cast(getWorkbenchAdapter(adaptableObject));
		}
		
		if(IDeferredWorkbenchAdapter.class == adapterType) {
			 Object o = getWorkbenchAdapter(adaptableObject);
			 if(o != null && o instanceof IDeferredWorkbenchAdapter) {
			 	return adapterType.cast(o);
			 }
			 return null;
		}		
		
		if (IPropertySource.class == adapterType) {
			return adapterType.cast(getPropertySource(adaptableObject));
		}
		
		if (IHistoryPageSource.class == adapterType){
			return adapterType.cast(historyParticipant);
		}
		
		if (ITeamStateProvider.class == adapterType) {
			synchronized (this) {
				if (teamStateProvider == null)
					teamStateProvider = new CVSTeamStateProvider(CVSProviderPlugin.getPlugin().getCVSWorkspaceSubscriber());
			}
			return adapterType.cast(teamStateProvider);
		}
		
		if (ISynchronizationCompareAdapter.class == adapterType) {
			if (compareAdapter == null)
				compareAdapter = new ChangeSetCompareAdapter();
			return adapterType.cast(compareAdapter);
		}
		
		return null;
	}
	
	protected Object getWorkbenchAdapter(Object o) {
		if (o instanceof ICVSRemoteFile) {
			return fileAdapter;
		} else if (o instanceof ICVSRepositoryLocation) {
			return rootAdapter;
		}  else if (o instanceof RepositoryRoot) {
			return rootAdapter;
		} else if (o instanceof ICVSRemoteFolder) {
			return folderAdapter;
		}
		return null;
	}
	
	public Class<?>[] getAdapterList() {
		return new Class[] { IWorkbenchAdapter.class, IPropertySource.class,
				IDeferredWorkbenchAdapter.class, IHistoryPageSource.class,
				ISynchronizationCompareAdapter.class, ITeamStateProvider.class,
				IFileRevision.class};
	}
	
	/**
	 * Returns the property source for the given object.  Caches
	 * the result because the property sheet is extremely inefficient,
	 * it asks for the source seven times in a row.
	 */
	public Object getPropertySource(Object adaptableObject) {
		if (adaptableObject == cachedPropertyObject) {
			return cachedPropertyValue;
		}
		cachedPropertyObject = adaptableObject;
		if (adaptableObject instanceof ICVSRemoteFile) {
			cachedPropertyValue = new CVSRemoteFilePropertySource((ICVSRemoteFile)adaptableObject);
		} else if (adaptableObject instanceof ICVSRemoteFolder) {
			cachedPropertyValue = new CVSRemoteFolderPropertySource((ICVSRemoteFolder)adaptableObject);
		} else if (adaptableObject instanceof ICVSRepositoryLocation) {
			cachedPropertyValue = new CVSRepositoryLocationPropertySource((ICVSRepositoryLocation)adaptableObject);
		}  else if (adaptableObject instanceof RepositoryRoot) {
			cachedPropertyValue = new CVSRepositoryLocationPropertySource(((RepositoryRoot)adaptableObject).getRoot());
		} else {
			cachedPropertyValue = null;
		}
		return cachedPropertyValue;
	}
}

Back to the top