01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.ide;
11:
12: import org.eclipse.core.filesystem.EFS;
13: import org.eclipse.core.filesystem.IFileStore;
14: import org.eclipse.core.filesystem.URIUtil;
15:
16: import org.eclipse.core.runtime.CoreException;
17: import org.eclipse.core.runtime.IAdapterFactory;
18: import org.eclipse.core.runtime.IPath;
19:
20: import org.eclipse.ui.IPathEditorInput;
21: import org.eclipse.ui.IURIEditorInput;
22: import org.eclipse.ui.ide.FileStoreEditorInput;
23:
24: /**
25: * Adapter factory for <code>IURIEditorInput</code>.
26: *
27: * @since 3.3
28: */
29: public class IURIEditorInputAdapterFactory implements IAdapterFactory {
30:
31: private static class PathEditorInputAdapter extends
32: FileStoreEditorInput implements IPathEditorInput {
33:
34: /**
35: * Creates a new adapter for the given file store.
36: *
37: * @param fileStore the file store;
38: */
39: public PathEditorInputAdapter(IFileStore fileStore) {
40: super (fileStore);
41: }
42:
43: /* (non-Javadoc)
44: * @see org.eclipse.ui.IPathEditorInput#getPath()
45: */
46: public IPath getPath() {
47: return URIUtil.toPath(getURI());
48: }
49: }
50:
51: /** The list of provided adapters. */
52: private static final Class[] ADAPTER_LIST = new Class[] { IPathEditorInput.class };
53:
54: /* (non-Javadoc)
55: * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class)
56: */
57: public Object getAdapter(Object adaptableObject, Class adapterType) {
58: if (IPathEditorInput.class.equals(adapterType)) {
59: if (adaptableObject instanceof IURIEditorInput) {
60: IFileStore fileStore;
61: try {
62: fileStore = EFS
63: .getStore(((IURIEditorInput) adaptableObject)
64: .getURI());
65: if (fileStore.getFileSystem() == EFS
66: .getLocalFileSystem()) {
67: return new PathEditorInputAdapter(fileStore);
68: }
69: } catch (CoreException e) {
70: return null;
71: }
72: }
73: }
74: return null;
75: }
76:
77: /* (non-Javadoc)
78: * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
79: */
80: public Class[] getAdapterList() {
81: return ADAPTER_LIST;
82: }
83: }
|