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.ide;
11:
12: import java.net.URI;
13: import java.net.URISyntaxException;
14:
15: import org.eclipse.core.filesystem.EFS;
16:
17: import org.eclipse.core.runtime.CoreException;
18: import org.eclipse.core.runtime.IAdaptable;
19:
20: import org.eclipse.ui.IElementFactory;
21: import org.eclipse.ui.IMemento;
22:
23: /**
24: * Factory for saving and restoring a <code>FileStoreEditorInput</code>.
25: * The stored representation of a <code>FileStoreEditorInput</code> remembers
26: * the path of the editor input.
27: * <p>
28: * The workbench will automatically create instances of this class as required.
29: * It is not intended to be instantiated or subclassed by the client.</p>
30: *
31: * @since 3.3
32: */
33: public class FileStoreEditorInputFactory implements IElementFactory {
34:
35: /**
36: * This factory's ID.
37: * <p>
38: * The editor plug-in registers a factory by this name with
39: * the <code>"org.eclipse.ui.elementFactories"<code> extension point.
40: */
41: static final String ID = "org.eclipse.ui.ide.FileStoreEditorInputFactory"; //$NON-NLS-1$
42:
43: /**
44: * Saves the state of the given editor input into the given memento.
45: *
46: * @param memento the storage area for element state
47: * @param input the file editor input
48: */
49: static void saveState(IMemento memento, FileStoreEditorInput input) {
50: URI uri = input.getURI();
51: memento.putString(TAG_URI, uri.toString());
52: }
53:
54: /**
55: * Tag for the URI string.
56: */
57: private static final String TAG_URI = "uri"; //$NON-NLS-1$
58:
59: /*
60: * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
61: */
62: public IAdaptable createElement(IMemento memento) {
63: // Get the file name.
64: String uriString = memento.getString(TAG_URI);
65: if (uriString == null)
66: return null;
67:
68: URI uri;
69: try {
70: uri = new URI(uriString);
71: } catch (URISyntaxException e) {
72: return null;
73: }
74:
75: try {
76: return new FileStoreEditorInput(EFS.getStore(uri));
77: } catch (CoreException e) {
78: return null;
79: }
80: }
81: }
|