01: /*******************************************************************************
02: * Copyright (c) 2006 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.internal.cheatsheets.state;
11:
12: import java.util.Hashtable;
13: import java.util.Properties;
14:
15: import org.eclipse.core.runtime.IStatus;
16: import org.eclipse.core.runtime.Status;
17: import org.eclipse.ui.IMemento;
18: import org.eclipse.ui.cheatsheets.ICheatSheetManager;
19: import org.eclipse.ui.internal.cheatsheets.data.CheatSheetSaveHelper;
20: import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
21: import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
22: import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
23:
24: /**
25: * A state manager used to open a cheat sheet whose state comes from a memento.
26: * This is used by the children of composite cheat sheets.
27: */
28:
29: public class MementoStateManager implements ICheatSheetStateManager {
30:
31: private IMemento memento;
32: private CheatSheetElement element;
33: private CheatSheetSaveHelper saveHelper = new CheatSheetSaveHelper();
34: private Properties props;
35: private ICheatSheetManager parentCsm;
36:
37: /**
38: * @param memento The memento which will be used to initialize the state. May be
39: * null to indicate that the state should be initialized.
40: */
41: public MementoStateManager(IMemento memento,
42: ICheatSheetManager parentCsm) {
43: this .memento = memento;
44: this .parentCsm = parentCsm;
45: }
46:
47: /**
48: * Load properties from the memento.
49: */
50: public Properties getProperties() {
51: if (memento == null) {
52: return null;
53: }
54: if (props == null) {
55: props = saveHelper.loadFromMemento(memento);
56: }
57: return props;
58: }
59:
60: public CheatSheetManager getCheatSheetManager() {
61: CheatSheetManager result = new CheatSheetManager(element);
62: if (getProperties() != null) {
63: result.setData((Hashtable) getProperties().get(
64: 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 properties,
75: CheatSheetManager manager) {
76: // The real save will use a memento, this is an empty method
77: return Status.OK_STATUS;
78: }
79:
80: }
|