KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > TeamAdapterFactory


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.ui;
12
13 import org.eclipse.compare.structuremergeviewer.DiffNode;
14 import org.eclipse.core.resources.mapping.ModelProvider;
15 import org.eclipse.core.runtime.IAdapterFactory;
16 import org.eclipse.team.core.RepositoryProviderType;
17 import org.eclipse.team.core.history.IFileRevision;
18 import org.eclipse.team.core.mapping.IResourceMappingMerger;
19 import org.eclipse.team.core.mapping.ISynchronizationScopeParticipantFactory;
20 import org.eclipse.team.internal.ui.history.FileRevisionEditorInput;
21 import org.eclipse.team.internal.ui.mapping.*;
22 import org.eclipse.team.internal.ui.synchronize.DiffNodeWorkbenchAdapter;
23 import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
24 import org.eclipse.team.ui.mapping.ITeamStateProvider;
25 import org.eclipse.ui.model.IWorkbenchAdapter;
26
27 public class TeamAdapterFactory implements IAdapterFactory {
28
29     private DiffNodeWorkbenchAdapter diffNodeAdapter = new DiffNodeWorkbenchAdapter();
30     
31     private static final ISynchronizationCompareAdapter COMPARE_ADAPTER = new ResourceModelPersistenceAdapter();
32     
33     /* (non-Javadoc)
34      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
35      */

36     public Object JavaDoc getAdapter(Object JavaDoc adaptableObject, Class JavaDoc adapterType) {
37         if(adaptableObject instanceof DiffNode && adapterType == IWorkbenchAdapter.class) {
38             return diffNodeAdapter;
39         }
40         if (adaptableObject instanceof ModelProvider) {
41             ModelProvider provider = (ModelProvider) adaptableObject;
42             if (provider.getDescriptor().getId().equals(ModelProvider.RESOURCE_MODEL_PROVIDER_ID)) {
43                 if (adapterType == IResourceMappingMerger.class) {
44                     return new DefaultResourceMappingMerger((ModelProvider)adaptableObject);
45                 }
46                 if (adapterType == ISynchronizationScopeParticipantFactory.class) {
47                     return new ResourceModelScopeParticipantFactory((ModelProvider)adaptableObject);
48                 }
49             }
50         }
51         if (adaptableObject instanceof ModelProvider && adapterType == ISynchronizationCompareAdapter.class) {
52             return COMPARE_ADAPTER;
53         }
54         if (adaptableObject instanceof RepositoryProviderType && adapterType == ITeamStateProvider.class) {
55             RepositoryProviderType rpt = (RepositoryProviderType) adaptableObject;
56             return TeamUIPlugin.getPlugin().getDecoratedStateProvider(rpt);
57         }
58         
59         if (IFileRevision.class == adapterType && adaptableObject instanceof FileRevisionEditorInput) {
60             return ((FileRevisionEditorInput)adaptableObject).getFileRevision();
61         }
62         return null;
63     }
64
65     /* (non-Javadoc)
66      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
67      */

68     public Class JavaDoc[] getAdapterList() {
69         return new Class JavaDoc[] {
70                 IWorkbenchAdapter.class,
71                 IResourceMappingMerger.class,
72                 ISynchronizationCompareAdapter.class,
73                 ISynchronizationScopeParticipantFactory.class,
74                 ITeamStateProvider.class ,
75                 IFileRevision.class
76             };
77     }
78 }
79
Popular Tags