KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > model > JavaModelAdapterFactory


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.jdt.internal.ui.model;
12
13 import org.eclipse.core.runtime.IAdapterFactory;
14
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.resources.mapping.ModelProvider;
17 import org.eclipse.core.resources.mapping.ResourceMapping;
18
19 import org.eclipse.team.core.mapping.IResourceMappingMerger;
20
21 import org.eclipse.team.ui.mapping.ISynchronizationCompareAdapter;
22 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy;
23 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory;
24
25 /**
26  * Adaptor factory for model support.
27  *
28  * @since 3.2
29  */

30 public final class JavaModelAdapterFactory implements IAdapterFactory {
31
32     /**
33      * {@inheritDoc}
34      */

35     public Object JavaDoc getAdapter(final Object JavaDoc adaptable, final Class JavaDoc adapter) {
36         if (adaptable instanceof JavaModelProvider) {
37             if (adapter == IResourceMappingMerger.class)
38                 return new JavaModelMerger((ModelProvider) adaptable);
39             else if (adapter == ISynchronizationCompareAdapter.class)
40                 return new JavaSynchronizationCompareAdapter();
41         } else if (adaptable instanceof RefactoringHistory) {
42             if (adapter == ResourceMapping.class)
43                 return new JavaRefactoringHistoryResourceMapping((RefactoringHistory) adaptable);
44             else if (adapter == IResource.class)
45                 return new JavaRefactoringHistoryResourceMapping((RefactoringHistory) adaptable).getResource();
46         } else if (adaptable instanceof RefactoringDescriptorProxy) {
47             if (adapter == ResourceMapping.class)
48                 return new JavaRefactoringDescriptorResourceMapping((RefactoringDescriptorProxy) adaptable);
49         }
50         return null;
51     }
52
53     /**
54      * {@inheritDoc}
55      */

56     public Class JavaDoc[] getAdapterList() {
57         return new Class JavaDoc[] { ResourceMapping.class, ISynchronizationCompareAdapter.class, IResource.class};
58     }
59 }
60
Popular Tags