Source Code Cross Referenced for EditorHistoryItem.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » 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 workbench » org.eclipse.ui.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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;
011:
012:        import org.eclipse.core.runtime.Assert;
013:        import org.eclipse.core.runtime.IAdaptable;
014:        import org.eclipse.core.runtime.IStatus;
015:        import org.eclipse.core.runtime.Status;
016:        import org.eclipse.ui.IEditorDescriptor;
017:        import org.eclipse.ui.IEditorInput;
018:        import org.eclipse.ui.IEditorRegistry;
019:        import org.eclipse.ui.IElementFactory;
020:        import org.eclipse.ui.IMemento;
021:        import org.eclipse.ui.IPersistableElement;
022:        import org.eclipse.ui.PlatformUI;
023:
024:        /**
025:         * An item in the editor history.
026:         */
027:        public class EditorHistoryItem {
028:
029:            private IEditorInput input;
030:
031:            private IEditorDescriptor descriptor;
032:
033:            private IMemento memento;
034:
035:            /**
036:             * Constructs a new item.
037:             */
038:            public EditorHistoryItem(IEditorInput input,
039:                    IEditorDescriptor descriptor) {
040:                this .input = input;
041:                this .descriptor = descriptor;
042:            }
043:
044:            /**
045:             * Constructs a new item from a memento.
046:             */
047:            public EditorHistoryItem(IMemento memento) {
048:                this .memento = memento;
049:            }
050:
051:            /**
052:             * Returns the editor descriptor.
053:             * 
054:             * @return the editor descriptor.
055:             */
056:            public IEditorDescriptor getDescriptor() {
057:                return descriptor;
058:            }
059:
060:            /**
061:             * Returns the editor input.
062:             * 
063:             * @return the editor input.
064:             */
065:            public IEditorInput getInput() {
066:                return input;
067:            }
068:
069:            /**
070:             * Returns whether this item has been restored from the memento.
071:             */
072:            public boolean isRestored() {
073:                return memento == null;
074:            }
075:
076:            /**
077:             * Returns the name of this item, either from the input if restored,
078:             * otherwise from the memento.
079:             */
080:            public String getName() {
081:                if (isRestored() && getInput() != null) {
082:                    return getInput().getName();
083:                } else if (memento != null) {
084:                    String name = memento
085:                            .getString(IWorkbenchConstants.TAG_NAME);
086:                    if (name != null) {
087:                        return name;
088:                    }
089:                }
090:                return ""; //$NON-NLS-1$
091:            }
092:
093:            /**
094:             * Returns the tooltip text of this item, either from the input if restored,
095:             * otherwise from the memento.
096:             */
097:            public String getToolTipText() {
098:                if (isRestored() && getInput() != null) {
099:                    return getInput().getToolTipText();
100:                } else if (memento != null) {
101:                    String name = memento
102:                            .getString(IWorkbenchConstants.TAG_TOOLTIP);
103:                    if (name != null) {
104:                        return name;
105:                    }
106:                }
107:                return ""; //$NON-NLS-1$
108:            }
109:
110:            /**
111:             * Returns whether this item matches the given editor input.
112:             */
113:            public boolean matches(IEditorInput input) {
114:                if (isRestored()) {
115:                    return input.equals(getInput());
116:                }
117:                // if not restored, compare name, tool tip text and factory id,
118:                // avoiding as much work as possible
119:                if (!getName().equals(input.getName())) {
120:                    return false;
121:                }
122:                if (!getToolTipText().equals(input.getToolTipText())) {
123:                    return false;
124:                }
125:                IPersistableElement persistable = input.getPersistable();
126:                String inputId = persistable == null ? null : persistable
127:                        .getFactoryId();
128:                String myId = getFactoryId();
129:                return myId == null ? inputId == null : myId.equals(inputId);
130:            }
131:
132:            /**
133:             * Returns the factory id of this item, either from the input if restored,
134:             * otherwise from the memento.
135:             * Returns <code>null</code> if there is no factory id.
136:             */
137:            public String getFactoryId() {
138:                if (isRestored()) {
139:                    if (input != null) {
140:                        IPersistableElement persistable = input
141:                                .getPersistable();
142:                        if (persistable != null) {
143:                            return persistable.getFactoryId();
144:                        }
145:                    }
146:                } else if (memento != null) {
147:                    return memento
148:                            .getString(IWorkbenchConstants.TAG_FACTORY_ID);
149:                }
150:                return null;
151:            }
152:
153:            /**
154:             * Restores the object state from the memento. 
155:             */
156:            public IStatus restoreState() {
157:                Assert.isTrue(!isRestored());
158:
159:                Status result = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0,
160:                        "", null); //$NON-NLS-1$
161:                IMemento memento = this .memento;
162:                this .memento = null;
163:
164:                String factoryId = memento
165:                        .getString(IWorkbenchConstants.TAG_FACTORY_ID);
166:                if (factoryId == null) {
167:                    WorkbenchPlugin
168:                            .log("Unable to restore mru list - no input factory ID.");//$NON-NLS-1$
169:                    return result;
170:                }
171:                IElementFactory factory = PlatformUI.getWorkbench()
172:                        .getElementFactory(factoryId);
173:                if (factory == null) {
174:                    return result;
175:                }
176:                IMemento persistableMemento = memento
177:                        .getChild(IWorkbenchConstants.TAG_PERSISTABLE);
178:                if (persistableMemento == null) {
179:                    WorkbenchPlugin
180:                            .log("Unable to restore mru list - no input element state: " + factoryId);//$NON-NLS-1$
181:                    return result;
182:                }
183:                IAdaptable adaptable = factory
184:                        .createElement(persistableMemento);
185:                if (adaptable == null
186:                        || (adaptable instanceof  IEditorInput) == false) {
187:                    return result;
188:                }
189:                input = (IEditorInput) adaptable;
190:                // Get the editor descriptor.
191:                String editorId = memento.getString(IWorkbenchConstants.TAG_ID);
192:                if (editorId != null) {
193:                    IEditorRegistry registry = WorkbenchPlugin.getDefault()
194:                            .getEditorRegistry();
195:                    descriptor = registry.findEditor(editorId);
196:                }
197:                return result;
198:            }
199:
200:            /**
201:             * Returns whether this history item can be saved.
202:             */
203:            public boolean canSave() {
204:                return !isRestored()
205:                        || (getInput() != null && getInput().getPersistable() != null);
206:            }
207:
208:            /**
209:             * Saves the object state in the given memento. 
210:             * 
211:             * @param memento the memento to save the object state in
212:             */
213:            public IStatus saveState(IMemento memento) {
214:                if (!isRestored()) {
215:                    memento.putMemento(this .memento);
216:                } else if (input != null) {
217:
218:                    IPersistableElement persistable = input.getPersistable();
219:                    if (persistable != null) {
220:                        /*
221:                         * Store IPersistable of the IEditorInput in a separate section
222:                         * since it could potentially use a tag already used in the parent 
223:                         * memento and thus overwrite data.
224:                         */
225:                        IMemento persistableMemento = memento
226:                                .createChild(IWorkbenchConstants.TAG_PERSISTABLE);
227:                        persistable.saveState(persistableMemento);
228:                        memento.putString(IWorkbenchConstants.TAG_FACTORY_ID,
229:                                persistable.getFactoryId());
230:                        if (descriptor != null && descriptor.getId() != null) {
231:                            memento.putString(IWorkbenchConstants.TAG_ID,
232:                                    descriptor.getId());
233:                        }
234:                        // save the name and tooltip separately so they can be restored
235:                        // without having to instantiate the input, which can activate plugins
236:                        memento.putString(IWorkbenchConstants.TAG_NAME, input
237:                                .getName());
238:                        memento.putString(IWorkbenchConstants.TAG_TOOLTIP,
239:                                input.getToolTipText());
240:                    }
241:                }
242:                return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
243:            }
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.