KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > cheatsheets > state > MementoStateManager


1 /*******************************************************************************
2  * Copyright (c) 2006 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
12 package org.eclipse.ui.internal.cheatsheets.state;
13
14 import java.util.Hashtable JavaDoc;
15 import java.util.Properties JavaDoc;
16
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.core.runtime.Status;
19 import org.eclipse.ui.IMemento;
20 import org.eclipse.ui.cheatsheets.ICheatSheetManager;
21 import org.eclipse.ui.internal.cheatsheets.data.CheatSheetSaveHelper;
22 import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
23 import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
24 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
25
26 /**
27  * A state manager used to open a cheat sheet whose state comes from a memento.
28  * This is used by the children of composite cheat sheets.
29  */

30
31 public class MementoStateManager implements ICheatSheetStateManager {
32
33     private IMemento memento;
34     private CheatSheetElement element;
35     private CheatSheetSaveHelper saveHelper = new CheatSheetSaveHelper();
36     private Properties JavaDoc props;
37     private ICheatSheetManager parentCsm;
38
39     /**
40      * @param memento The memento which will be used to initialize the state. May be
41      * null to indicate that the state should be initialized.
42      */

43     public MementoStateManager(IMemento memento, ICheatSheetManager parentCsm) {
44         this.memento = memento;
45         this.parentCsm = parentCsm;
46     }
47
48     /**
49      * Load properties from the memento.
50      */

51     public Properties JavaDoc getProperties() {
52         if (memento == null) {
53             return null;
54         }
55         if (props == null) {
56             props = saveHelper.loadFromMemento(memento);
57         }
58         return props;
59     }
60
61     public CheatSheetManager getCheatSheetManager() {
62         CheatSheetManager result = new CheatSheetManager(element);
63         if (getProperties() != null) {
64             result.setData((Hashtable JavaDoc) getProperties().get(IParserTags.MANAGERDATA));
65         }
66         result.setParent(parentCsm);
67         return result;
68     }
69
70     public void setElement(CheatSheetElement element) {
71         this.element = element;
72     }
73
74     public IStatus saveState(Properties JavaDoc properties, CheatSheetManager manager) {
75         // The real save will use a memento, this is an empty method
76
return Status.OK_STATUS;
77     }
78
79 }
80
Popular Tags