KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > PersistableJavaElementFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jdt.internal.ui;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.jdt.core.IJavaElement;
15 import org.eclipse.jdt.core.JavaCore;
16 import org.eclipse.ui.IElementFactory;
17 import org.eclipse.ui.IMemento;
18 import org.eclipse.ui.IPersistableElement;
19
20 /**
21  * The JavaElementFactory is used to save and recreate an IJavaElement object.
22  * As such, it implements the IPersistableElement interface for storage
23  * and the IElementFactory interface for recreation.
24  *
25  * @see IMemento
26  * @see IPersistableElement
27  * @see IElementFactory
28  */

29 public class PersistableJavaElementFactory implements IElementFactory, IPersistableElement {
30
31     private static final String JavaDoc KEY= "elementID"; //$NON-NLS-1$
32
private static final String JavaDoc FACTORY_ID= "org.eclipse.jdt.ui.PersistableJavaElementFactory"; //$NON-NLS-1$
33

34     private IJavaElement fElement;
35     
36     /**
37      * Create a JavaElementFactory.
38      */

39     public PersistableJavaElementFactory() {
40     }
41
42     /**
43      * Create a JavaElementFactory. This constructor is typically used
44      * for our IPersistableElement side.
45      */

46     public PersistableJavaElementFactory(IJavaElement element) {
47         fElement= element;
48     }
49
50     /*
51      * @see IElementFactory
52      */

53     public IAdaptable createElement(IMemento memento) {
54     
55         String JavaDoc identifier= memento.getString(KEY);
56         if (identifier != null) {
57             return JavaCore.create(identifier);
58         }
59         return null;
60     }
61     
62     /*
63      * @see IPersistableElement.
64      */

65     public String JavaDoc getFactoryId() {
66         return FACTORY_ID;
67     }
68     /*
69      * @see IPersistableElement
70      */

71     public void saveState(IMemento memento) {
72         memento.putString(KEY, fElement.getHandleIdentifier());
73     }
74 }
75
Popular Tags