KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > ide > FileStoreEditorInputFactory


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.ide;
12
13 import java.net.URI JavaDoc;
14 import java.net.URISyntaxException JavaDoc;
15
16 import org.eclipse.core.filesystem.EFS;
17
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IAdaptable;
20
21 import org.eclipse.ui.IElementFactory;
22 import org.eclipse.ui.IMemento;
23
24
25 /**
26  * Factory for saving and restoring a <code>FileStoreEditorInput</code>.
27  * The stored representation of a <code>FileStoreEditorInput</code> remembers
28  * the path of the editor input.
29  * <p>
30  * The workbench will automatically create instances of this class as required.
31  * It is not intended to be instantiated or subclassed by the client.</p>
32  *
33  * @since 3.3
34  */

35 public class FileStoreEditorInputFactory implements IElementFactory {
36     
37     /**
38      * This factory's ID.
39      * <p>
40      * The editor plug-in registers a factory by this name with
41      * the <code>"org.eclipse.ui.elementFactories"<code> extension point.
42      */

43     static final String JavaDoc ID = "org.eclipse.ui.ide.FileStoreEditorInputFactory"; //$NON-NLS-1$
44

45     /**
46      * Saves the state of the given editor input into the given memento.
47      *
48      * @param memento the storage area for element state
49      * @param input the file editor input
50      */

51     static void saveState(IMemento memento, FileStoreEditorInput input) {
52         URI JavaDoc uri = input.getURI();
53         memento.putString(TAG_URI, uri.toString());
54     }
55
56     /**
57      * Tag for the URI string.
58      */

59     private static final String JavaDoc TAG_URI = "uri"; //$NON-NLS-1$
60

61     /*
62      * @see org.eclipse.ui.IElementFactory#createElement(org.eclipse.ui.IMemento)
63      */

64     public IAdaptable createElement(IMemento memento) {
65         // Get the file name.
66
String JavaDoc uriString = memento.getString(TAG_URI);
67         if (uriString == null)
68             return null;
69         
70         URI JavaDoc uri;
71         try {
72             uri = new URI JavaDoc(uriString);
73         } catch (URISyntaxException JavaDoc e) {
74             return null;
75         }
76         
77         try {
78             return new FileStoreEditorInput(EFS.getStore(uri));
79         } catch (CoreException e) {
80             return null;
81         }
82     }
83 }
84
Popular Tags