Source Code Cross Referenced for EditorHistory.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 java.util.ArrayList;
013:        import java.util.Iterator;
014:
015:        import org.eclipse.core.runtime.IStatus;
016:        import org.eclipse.core.runtime.Status;
017:        import org.eclipse.ui.IEditorDescriptor;
018:        import org.eclipse.ui.IEditorInput;
019:        import org.eclipse.ui.IMemento;
020:        import org.eclipse.ui.PlatformUI;
021:
022:        /**
023:         * This class is used to record "open editor" actions as they
024:         * happen.  The input and type of each editor are recorded so that
025:         * the user can reopen an item from the recently used files list.
026:         */
027:        public class EditorHistory {
028:            /**
029:             * The maximum of entries in the history.
030:             */
031:            public static final int MAX_SIZE = 15;
032:
033:            /**
034:             * The list of editor entries, in FIFO order.
035:             */
036:            private ArrayList fifoList = new ArrayList(MAX_SIZE);
037:
038:            /**
039:             * Constructs a new history.
040:             */
041:            public EditorHistory() {
042:                super ();
043:            }
044:
045:            /**
046:             * Adds an item to the history.  Added in fifo fashion.
047:             */
048:            public void add(IEditorInput input, IEditorDescriptor desc) {
049:                add(new EditorHistoryItem(input, desc), 0);
050:            }
051:
052:            /**
053:             * Adds an item to the history.
054:             */
055:            private void add(EditorHistoryItem newItem, int index) {
056:                // Remove the item if it already exists so that it will be put 
057:                // at the top of the list.
058:                if (newItem.isRestored()) {
059:                    remove(newItem.getInput());
060:                }
061:
062:                // Remove the oldest one
063:                if (fifoList.size() == MAX_SIZE) {
064:                    fifoList.remove(MAX_SIZE - 1);
065:                }
066:
067:                // Add the new item.
068:                fifoList.add(index < MAX_SIZE ? index : MAX_SIZE - 1, newItem);
069:            }
070:
071:            /**
072:             * Returns an array of editor history items.  The items are returned in order
073:             * of most recent first.
074:             */
075:            public EditorHistoryItem[] getItems() {
076:                refresh();
077:                EditorHistoryItem[] array = new EditorHistoryItem[fifoList
078:                        .size()];
079:                fifoList.toArray(array);
080:                return array;
081:            }
082:
083:            /**
084:             * Refresh the editor list.  Any stale items are removed.
085:             * Only restored items are considered.
086:             */
087:            public void refresh() {
088:                Iterator iter = fifoList.iterator();
089:                while (iter.hasNext()) {
090:                    EditorHistoryItem item = (EditorHistoryItem) iter.next();
091:                    if (item.isRestored()) {
092:                        IEditorInput input = item.getInput();
093:                        if (input != null && !input.exists()) {
094:                            iter.remove();
095:                        }
096:                    }
097:                }
098:            }
099:
100:            /**
101:             * Removes the given history item.
102:             */
103:            public void remove(EditorHistoryItem item) {
104:                fifoList.remove(item);
105:            }
106:
107:            /**
108:             * Removes all traces of an editor input from the history.
109:             */
110:            public void remove(IEditorInput input) {
111:                if (input == null) {
112:                    return;
113:                }
114:                Iterator iter = fifoList.iterator();
115:                while (iter.hasNext()) {
116:                    EditorHistoryItem item = (EditorHistoryItem) iter.next();
117:                    if (item.matches(input)) {
118:                        iter.remove();
119:                    }
120:                }
121:            }
122:
123:            /**
124:             * Restore the most-recently-used history from the given memento.
125:             * 
126:             * @param memento the memento to restore the mru history from
127:             */
128:            public IStatus restoreState(IMemento memento) {
129:                IMemento[] mementos = memento
130:                        .getChildren(IWorkbenchConstants.TAG_FILE);
131:                for (int i = 0; i < mementos.length; i++) {
132:                    EditorHistoryItem item = new EditorHistoryItem(mementos[i]);
133:                    if (!"".equals(item.getName()) || !"".equals(item.getToolTipText())) { //$NON-NLS-1$ //$NON-NLS-2$
134:                        add(item, fifoList.size());
135:                    }
136:                }
137:                return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
138:            }
139:
140:            /**
141:             * Save the most-recently-used history in the given memento.
142:             * 
143:             * @param memento the memento to save the mru history in
144:             */
145:            public IStatus saveState(IMemento memento) {
146:                Iterator iterator = fifoList.iterator();
147:                while (iterator.hasNext()) {
148:                    EditorHistoryItem item = (EditorHistoryItem) iterator
149:                            .next();
150:                    if (item.canSave()) {
151:                        IMemento itemMemento = memento
152:                                .createChild(IWorkbenchConstants.TAG_FILE);
153:                        item.saveState(itemMemento);
154:                    }
155:                }
156:                return new Status(IStatus.OK, PlatformUI.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
157:            }
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.