KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
13  * The default state manager for a cheat sheet. The data will be saved and restored
14  * using a file in metadata whose name is derived from the id
15  */

16
17 package org.eclipse.ui.internal.cheatsheets.state;
18
19 import java.util.Hashtable JavaDoc;
20 import java.util.Properties JavaDoc;
21
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.ui.internal.cheatsheets.data.CheatSheetSaveHelper;
24 import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
25 import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement;
26 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
27
28 /**
29  * The default state manager saves the state in an xml file whose name is the
30  * same as the id of the cheatsheet.
31  */

32
33 public class DefaultStateManager implements ICheatSheetStateManager {
34
35     private CheatSheetSaveHelper saveHelper = new CheatSheetSaveHelper();
36     private Properties JavaDoc props;
37     private CheatSheetElement element;
38     private boolean propertiesRead = false;
39
40     public Properties JavaDoc getProperties() {
41         if (!propertiesRead) {
42             props = saveHelper.loadState(element.getID());
43             propertiesRead = true;
44         }
45         return props;
46     }
47
48     public CheatSheetManager getCheatSheetManager() {
49         CheatSheetManager result = new CheatSheetManager(element);
50         if (getProperties() != null) {
51             result.setData((Hashtable JavaDoc) getProperties().get(IParserTags.MANAGERDATA));
52         }
53         return result;
54     }
55
56     public void setElement(CheatSheetElement element) {
57         this.element = element;
58     }
59
60     public IStatus saveState(Properties JavaDoc properties, CheatSheetManager manager) {
61         return saveHelper.saveState(properties, manager);
62     }
63 }
64
Popular Tags