KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > FileEditorInputAdapterFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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
12 package org.eclipse.ui.internal.editors.text;
13
14 import org.eclipse.core.resources.IFile;
15 import org.eclipse.core.runtime.IAdapterFactory;
16 import org.eclipse.core.runtime.IPath;
17
18 import org.eclipse.ui.IFileEditorInput;
19 import org.eclipse.ui.editors.text.ILocationProvider;
20
21 /**
22  * @since 3.0
23  */

24 public class FileEditorInputAdapterFactory implements IAdapterFactory {
25
26     private static class LocationProvider implements ILocationProvider {
27         /*
28          * @see org.eclipse.ui.editors.text.ILocationProvider#getLocation(java.lang.Object)
29          */

30         public IPath getPath(Object JavaDoc element) {
31             if (element instanceof IFileEditorInput) {
32                 IFileEditorInput input= (IFileEditorInput) element;
33                 return input.getFile().getFullPath();
34             }
35             return null;
36         }
37     }
38
39     /** The list of provided adapters. */
40     private static final Class JavaDoc[] ADAPTER_LIST= new Class JavaDoc[] { ILocationProvider.class };
41
42     /** The provided location provider */
43     private ILocationProvider fLocationProvider= new LocationProvider();
44
45     /*
46      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
47      */

48     public Object JavaDoc getAdapter(Object JavaDoc adaptableObject, Class JavaDoc adapterType) {
49         if (ILocationProvider.class.equals(adapterType)) {
50             if (adaptableObject instanceof IFile)
51                 return fLocationProvider;
52         }
53         return null;
54     }
55
56     /*
57      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
58      */

59     public Class JavaDoc[] getAdapterList() {
60         return ADAPTER_LIST;
61     }
62 }
63
Popular Tags