KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > model > StandardPropertiesAdapterFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.internal.ide.model;
12
13 import org.eclipse.core.resources.IFile;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.IAdapterFactory;
16 import org.eclipse.ui.views.properties.FilePropertySource;
17 import org.eclipse.ui.views.properties.IPropertySource;
18 import org.eclipse.ui.views.properties.ResourcePropertySource;
19
20 /**
21  * Dispenses an <code>IPropertySource</code> adapter for the core resource objects.
22  */

23 /* package */class StandardPropertiesAdapterFactory implements IAdapterFactory {
24     /* (non-Javadoc)
25      * Method declared on IAdapterFactory.
26      */

27     public Object JavaDoc getAdapter(Object JavaDoc o, Class JavaDoc adapterType) {
28         if (adapterType.isInstance(o)) {
29             return o;
30         }
31         if (adapterType == IPropertySource.class) {
32             if (o instanceof IResource) {
33                 IResource resource = (IResource) o;
34                 if (resource.getType() == IResource.FILE) {
35                     return new FilePropertySource((IFile) o);
36                 } else {
37                     return new ResourcePropertySource((IResource) o);
38                 }
39             }
40         }
41         return null;
42     }
43
44     /* (non-Javadoc)
45      * Method declared on IAdapterFactory.
46      */

47     public Class JavaDoc[] getAdapterList() {
48         return new Class JavaDoc[] { IPropertySource.class };
49     }
50 }
51
Popular Tags