KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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.editors.text;
12
13 import java.net.URI JavaDoc;
14
15 import org.eclipse.core.filesystem.URIUtil;
16
17 import org.eclipse.core.runtime.IAdapterFactory;
18 import org.eclipse.core.runtime.IPath;
19
20 import org.eclipse.ui.editors.text.ILocationProvider;
21 import org.eclipse.ui.editors.text.ILocationProviderExtension;
22
23 import org.eclipse.ui.IURIEditorInput;
24
25
26 /**
27  * Adapter factory for <code>IURIEditorInput</code>.
28  *
29  * @since 3.3
30  */

31 public class IURIEditorInputAdapterFactory implements IAdapterFactory {
32
33     private static class LocationProvider implements ILocationProvider, ILocationProviderExtension {
34         /*
35          * @see org.eclipse.ui.editors.text.ILocationProvider#getLocation(java.lang.Object)
36          */

37         public IPath getPath(Object JavaDoc element) {
38             URI JavaDoc uri= getURI(element);
39             if (uri != null)
40                 return URIUtil.toPath(uri);
41             return null;
42         }
43         
44         /*
45          * @see org.eclipse.ui.editors.text.ILocationProviderExtension#getURI(java.lang.Object)
46          */

47         public URI JavaDoc getURI(Object JavaDoc element) {
48             if (element instanceof IURIEditorInput) {
49                 IURIEditorInput input= (IURIEditorInput)element;
50                 return input.getURI();
51             }
52             return null;
53         }
54     }
55
56     
57     /** The list of provided adapters. */
58     private static final Class JavaDoc[] ADAPTER_LIST= new Class JavaDoc[] { ILocationProvider.class };
59
60     /** The provided location provider */
61     private ILocationProvider fLocationProvider= new LocationProvider();
62
63     /*
64      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
65      */

66     public Object JavaDoc getAdapter(Object JavaDoc adaptableObject, Class JavaDoc adapterType) {
67         if (ILocationProvider.class.equals(adapterType)) {
68             if (adaptableObject instanceof IURIEditorInput)
69                 return fLocationProvider;
70         }
71         return null;
72     }
73
74     /*
75      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
76      */

77     public Class JavaDoc[] getAdapterList() {
78         return ADAPTER_LIST;
79     }
80 }
81
Popular Tags