KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > ide > 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.ide;
12
13 import org.eclipse.core.filesystem.EFS;
14 import org.eclipse.core.filesystem.IFileStore;
15 import org.eclipse.core.filesystem.URIUtil;
16
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IAdapterFactory;
19 import org.eclipse.core.runtime.IPath;
20
21 import org.eclipse.ui.IPathEditorInput;
22 import org.eclipse.ui.IURIEditorInput;
23 import org.eclipse.ui.ide.FileStoreEditorInput;
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 PathEditorInputAdapter extends FileStoreEditorInput implements IPathEditorInput {
34
35         /**
36          * Creates a new adapter for the given file store.
37          *
38          * @param fileStore the file store;
39          */

40         public PathEditorInputAdapter(IFileStore fileStore) {
41             super(fileStore);
42         }
43
44         /* (non-Javadoc)
45          * @see org.eclipse.ui.IPathEditorInput#getPath()
46          */

47         public IPath getPath() {
48             return URIUtil.toPath(getURI());
49         }
50     }
51
52     
53     /** The list of provided adapters. */
54     private static final Class JavaDoc[] ADAPTER_LIST= new Class JavaDoc[] { IPathEditorInput.class };
55
56     
57     
58     /* (non-Javadoc)
59      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
60      */

61     public Object JavaDoc getAdapter(Object JavaDoc adaptableObject, Class JavaDoc adapterType) {
62         if (IPathEditorInput.class.equals(adapterType)) {
63             if (adaptableObject instanceof IURIEditorInput) {
64                 IFileStore fileStore;
65                 try {
66                     fileStore= EFS.getStore(((IURIEditorInput) adaptableObject).getURI());
67                     if (fileStore.getFileSystem() == EFS.getLocalFileSystem()) {
68                         return new PathEditorInputAdapter(fileStore);
69                     }
70                 } catch (CoreException e) {
71                     return null;
72                 }
73             }
74         }
75         return null;
76     }
77
78     
79     /* (non-Javadoc)
80      * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
81      */

82     public Class JavaDoc[] getAdapterList() {
83         return ADAPTER_LIST;
84     }
85 }
86
Popular Tags