Source code: com/port80/eclipse/util/GraphEditorInputFactory.java
1 package com.port80.eclipse.util;
2
3 import org.eclipse.core.runtime.IAdaptable;
4 import org.eclipse.ui.IElementFactory;
5 import org.eclipse.ui.IMemento;
6
7 import com.port80.util.Msg;
8
9 /**
10 * Factory for saving and restoring a <code>GraphEditorInput</code>.
11 * The stored representation of a <code>GraphEditorInput</code> remembers
12 * the .dot file name for the IGraph.
13 * <p>
14 * The workbench will automatically create instances of this class as required.
15 * It is not intended to be instantiated or subclassed by the client.
16 * </p>
17 *
18 * @author chrisl
19 */
20 public class GraphEditorInputFactory implements IElementFactory {
21
22 /**
23 * Factory id. The workbench plug-in registers a factory by this name
24 * with the "org.eclipse.ui.elementFactories" extension point.
25 */
26 public static final String ID_FACTORY = "com.port80.eclipse.util.GraphEditorInputFactory";
27 //$NON-NLS-1$
28
29 /**
30 * Tag for the IFile.fullPath of the file resource.
31 */
32 private static final String TAG_PATH = "path"; //$NON-NLS-1$
33
34 /**
35 * Creates a new factory.
36 */
37 public GraphEditorInputFactory() {
38 Msg.println(ID_FACTORY);
39 }
40
41 /* (non-Javadoc)
42 * Method declared on IElementFactory.
43 */
44 public IAdaptable createElement(IMemento memento) {
45 Msg.println(ID_FACTORY+".createElement()");
46 // Get the file name.
47 String filepath = memento.getString(TAG_PATH);
48 if (filepath == null)
49 return new GraphEditorInput(null);
50 return new GraphEditorInput(filepath);
51 }
52
53 /**
54 * Returns the element factory id for this class.
55 *
56 * @return the element factory id
57 */
58 public static String getFactoryId() {
59 return ID_FACTORY;
60 }
61
62 /**
63 * Saves the state of the given file editor input into the given memento.
64 *
65 * @param memento the storage area for element state
66 * @param input the file editor input
67 */
68 public static void saveState(IMemento memento, GraphEditorInput input) {
69 memento.putString(TAG_PATH, input.getFilepath());
70 }
71
72 }