Source Code Cross Referenced for CompositeCheatSheetSaveHelper.java in  » IDE-Eclipse » ui » org » eclipse » ui » internal » cheatsheets » composite » model » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui » org.eclipse.ui.internal.cheatsheets.composite.model 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.cheatsheets.composite.model;
011:
012:        import java.util.HashMap;
013:        import java.util.Iterator;
014:        import java.util.Map;
015:
016:        import org.eclipse.core.runtime.IStatus;
017:        import org.eclipse.core.runtime.Status;
018:        import org.eclipse.ui.IMemento;
019:        import org.eclipse.ui.XMLMemento;
020:        import org.eclipse.ui.cheatsheets.ICheatSheetManager;
021:        import org.eclipse.ui.internal.cheatsheets.CheatSheetPlugin;
022:        import org.eclipse.ui.internal.cheatsheets.composite.parser.ICompositeCheatsheetTags;
023:        import org.eclipse.ui.internal.cheatsheets.data.IParserTags;
024:        import org.eclipse.ui.internal.cheatsheets.state.ICheatSheetStateManager;
025:        import org.eclipse.ui.internal.cheatsheets.state.NoSaveStateManager;
026:        import org.eclipse.ui.internal.cheatsheets.views.CheatSheetManager;
027:        import org.eclipse.ui.internal.provisional.cheatsheets.ICompositeCheatSheetTask;
028:        import org.eclipse.ui.internal.provisional.cheatsheets.IEditableTask;
029:        import org.eclipse.ui.internal.provisional.cheatsheets.TaskEditor;
030:
031:        /**
032:         * Class to save and restore composite cheatsheet state using a memento
033:         * There is a child memento for each task which contains keys for the
034:         * state complete. There is also a grandchild memento for 
035:         * each task that has been started.
036:         */
037:
038:        public class CompositeCheatSheetSaveHelper {
039:            private static final String DOT_XML = ".xml"; //$NON-NLS-1$
040:            private Map taskMementoMap;
041:            private ICheatSheetStateManager stateManager;
042:
043:            /**
044:             * Constructor 
045:             */
046:            public CompositeCheatSheetSaveHelper(
047:                    ICheatSheetStateManager stateManager) {
048:                super ();
049:                this .stateManager = stateManager;
050:            }
051:
052:            public IStatus loadCompositeState(CompositeCheatSheetModel model,
053:                    Map layoutData) {
054:                if (stateManager instanceof  NoSaveStateManager)
055:                    return Status.OK_STATUS;
056:                XMLMemento readMemento = CheatSheetPlugin.getPlugin()
057:                        .readMemento(model.getId() + DOT_XML);
058:                if (readMemento == null) {
059:                    return Status.OK_STATUS;
060:                }
061:                taskMementoMap = createTaskMap(readMemento);
062:                loadTaskState(taskMementoMap, (AbstractTask) model
063:                        .getRootTask());
064:                loadCheatsheetManagerData(readMemento, model
065:                        .getCheatSheetManager());
066:                loadLayoutData(readMemento, layoutData);
067:                model.sendTaskChangeEvents();
068:                return Status.OK_STATUS;
069:            }
070:
071:            private Map createTaskMap(XMLMemento readMemento) {
072:                Map map = new HashMap();
073:                IMemento[] tasks = readMemento
074:                        .getChildren(ICompositeCheatsheetTags.TASK);
075:                for (int i = 0; i < tasks.length; i++) {
076:                    String taskId = tasks[i]
077:                            .getString(ICompositeCheatsheetTags.TASK_ID);
078:                    if (taskId != null) {
079:                        map.put(taskId, tasks[i]);
080:                    }
081:                }
082:                return map;
083:            }
084:
085:            private void loadTaskState(Map taskMap, AbstractTask task) {
086:                ICompositeCheatSheetTask[] children = task.getSubtasks();
087:                IMemento memento = (IMemento) taskMap.get(task.getId());
088:                if (memento != null) {
089:                    String state = memento
090:                            .getString(ICompositeCheatsheetTags.STATE);
091:                    if (state != null) {
092:                        task.setStateNoNotify(Integer.parseInt(state));
093:                    }
094:                }
095:                if (task instanceof  TaskGroup) {
096:                    for (int i = 0; i < children.length; i++) {
097:                        loadTaskState(taskMap, (AbstractTask) children[i]);
098:                    }
099:                    ((TaskGroup) task).checkState();
100:                }
101:            }
102:
103:            private void loadCheatsheetManagerData(XMLMemento readMemento,
104:                    ICheatSheetManager manager) {
105:                if (manager == null) {
106:                    return;
107:                }
108:                IMemento[] children = readMemento
109:                        .getChildren(ICompositeCheatsheetTags.CHEAT_SHEET_MANAGER);
110:                for (int i = 0; i < children.length; i++) {
111:                    IMemento childMemento = children[i];
112:                    String key = childMemento
113:                            .getString(ICompositeCheatsheetTags.KEY);
114:                    String value = childMemento
115:                            .getString(ICompositeCheatsheetTags.VALUE);
116:                    manager.setData(key, value);
117:                }
118:            }
119:
120:            private void loadLayoutData(XMLMemento readMemento, Map layoutData) {
121:                if (layoutData == null) {
122:                    return;
123:                }
124:                IMemento[] children = readMemento
125:                        .getChildren(ICompositeCheatsheetTags.LAYOUT_DATA);
126:                for (int i = 0; i < children.length; i++) {
127:                    IMemento childMemento = children[i];
128:                    String key = childMemento
129:                            .getString(ICompositeCheatsheetTags.KEY);
130:                    String value = childMemento
131:                            .getString(ICompositeCheatsheetTags.VALUE);
132:                    layoutData.put(key, value);
133:                }
134:            }
135:
136:            /**
137:             * Save the state of a composite cheat sheet model
138:             * @param model
139:             * @param selectedTask 
140:             * @param layoutData Will contain pairs of name/value Strings used to save and restore layout
141:             * @return
142:             */
143:            public IStatus saveCompositeState(CompositeCheatSheetModel model,
144:                    Map layoutData) {
145:                if (stateManager instanceof  NoSaveStateManager)
146:                    return Status.OK_STATUS;
147:                XMLMemento writeMemento = XMLMemento
148:                        .createWriteRoot(ICompositeCheatsheetTags.COMPOSITE_CHEATSHEET_STATE);
149:                writeMemento.putString(IParserTags.ID, model.getId());
150:                saveTaskState(writeMemento, (AbstractTask) model.getRootTask());
151:                saveCheatSheetManagerData(writeMemento, model
152:                        .getCheatSheetManager());
153:                taskMementoMap = createTaskMap(writeMemento);
154:                if (layoutData != null) {
155:                    saveMap(writeMemento, layoutData,
156:                            ICompositeCheatsheetTags.LAYOUT_DATA);
157:                }
158:                return CheatSheetPlugin.getPlugin().saveMemento(writeMemento,
159:                        model.getId() + DOT_XML);
160:            }
161:
162:            private void saveCheatSheetManagerData(XMLMemento writeMemento,
163:                    ICheatSheetManager manager) {
164:                if (!(manager instanceof  CheatSheetManager)) {
165:                    return;
166:                }
167:                Map data = ((CheatSheetManager) manager).getData();
168:                saveMap(writeMemento, data,
169:                        ICompositeCheatsheetTags.CHEAT_SHEET_MANAGER);
170:            }
171:
172:            private void saveMap(XMLMemento writeMemento, Map data, String tag) {
173:                for (Iterator iter = data.keySet().iterator(); iter.hasNext();) {
174:                    String key = (String) iter.next();
175:                    String value = (String) data.get(key);
176:                    IMemento childMemento = writeMemento.createChild(tag);
177:                    childMemento.putString(ICompositeCheatsheetTags.KEY, key);
178:                    childMemento.putString(ICompositeCheatsheetTags.VALUE,
179:                            value);
180:                }
181:            }
182:
183:            private void saveTaskState(IMemento writeMemento, AbstractTask task) {
184:                IMemento childMemento = writeMemento
185:                        .createChild(ICompositeCheatsheetTags.TASK);
186:                childMemento.putString(ICompositeCheatsheetTags.TASK_ID, task
187:                        .getId());
188:                childMemento.putString(ICompositeCheatsheetTags.STATE, Integer
189:                        .toString(task.getState()));
190:
191:                // If this is an editable task that has been started, completed or skipped save the editor state
192:                if (task instanceof  IEditableTask
193:                        && task.getState() != ICompositeCheatSheetTask.NOT_STARTED) {
194:                    TaskEditor editor = getEditor(task);
195:                    if (editor != null) {
196:                        IMemento taskDataMemento = childMemento
197:                                .createChild(ICompositeCheatsheetTags.TASK_DATA);
198:                        editor.saveState(taskDataMemento);
199:                    } else {
200:                        // The editor has not been started so save its previously loaded state
201:                        IMemento taskData = getTaskMemento(task.getId());
202:                        if (taskData != null) {
203:                            IMemento previousDataMemento = childMemento
204:                                    .createChild(ICompositeCheatsheetTags.TASK_DATA);
205:                            previousDataMemento.putMemento(taskData);
206:                        }
207:                    }
208:                }
209:                ICompositeCheatSheetTask[] subtasks = task.getSubtasks();
210:                for (int i = 0; i < subtasks.length; i++) {
211:                    saveTaskState(writeMemento, (AbstractTask) subtasks[i]);
212:                }
213:            }
214:
215:            private TaskEditor getEditor(AbstractTask task) {
216:                if (task instanceof  EditableTask) {
217:                    return ((EditableTask) task).getEditor();
218:                }
219:                return null;
220:            }
221:
222:            public IMemento getTaskMemento(String id) {
223:                if (taskMementoMap == null) {
224:                    return null;
225:                }
226:                IMemento childMemento = (IMemento) taskMementoMap.get(id);
227:                if (childMemento == null) {
228:                    return null;
229:                }
230:                return childMemento
231:                        .getChild(ICompositeCheatsheetTags.TASK_DATA);
232:            }
233:
234:            public void clearTaskMementos() {
235:                taskMementoMap = null;
236:            }
237:
238:            public void clearTaskMemento(String id) {
239:                if (taskMementoMap != null) {
240:                    taskMementoMap.remove(id);
241:                }
242:            }
243:
244:        }
ww_w_.j___av__a___2__s.___c___o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.