1 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 fileAdapter = new RemoteFileElement(); 29 private static Object folderAdapter = new RemoteFolderElement(); 30 private static Object rootAdapter = new CVSRepositoryRootElement(); 31 32 private static Object historyParticipant = new CVSHistoryPageSource(); 33 34 private static Object teamStateProvider; 35 36 private Object cachedPropertyObject = null; 38 private Object cachedPropertyValue = null; 39 private ChangeSetCompareAdapter compareAdapter; 40 41 44 public Object getAdapter(Object adaptableObject, Class adapterType) { 45 if (IWorkbenchAdapter.class == adapterType) { 46 return getWorkbenchAdapter(adaptableObject); 47 } 48 49 if(IDeferredWorkbenchAdapter.class == adapterType) { 50 Object 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 getWorkbenchAdapter(Object 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 102 public Class [] getAdapterList() { 103 return new Class [] { IWorkbenchAdapter.class, IPropertySource.class, 104 IDeferredWorkbenchAdapter.class, IHistoryPageSource.class, 105 ISynchronizationCompareAdapter.class, ITeamStateProvider.class, 106 IFileRevision.class}; 107 } 108 109 114 public Object getPropertySource(Object 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 |