| 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.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 getAdapter(Object o, Class 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 | } |
| 37 | return new ResourcePropertySource((IResource) o); |
| 38 | } |
| 39 | } |
| 40 | return null; |
| 41 | } |
| 42 | |
| 43 | /* (non-Javadoc) |
| 44 | * Method declared on IAdapterFactory. |
| 45 | */ |
| 46 | public Class[] getAdapterList() { |
| 47 | return new Class[] { IPropertySource.class }; |
| 48 | } |
| 49 | } |