Source Code Cross Referenced for TreeFrame.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » views » framelist » 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 ide » org.eclipse.ui.views.framelist 
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.views.framelist;
011:
012:        import java.util.ArrayList;
013:        import java.util.List;
014:
015:        import org.eclipse.core.runtime.IAdaptable;
016:        import org.eclipse.jface.viewers.AbstractTreeViewer;
017:        import org.eclipse.jface.viewers.ILabelProvider;
018:        import org.eclipse.jface.viewers.ISelection;
019:        import org.eclipse.jface.viewers.IStructuredSelection;
020:        import org.eclipse.jface.viewers.StructuredSelection;
021:        import org.eclipse.ui.IElementFactory;
022:        import org.eclipse.ui.IMemento;
023:        import org.eclipse.ui.IPersistableElement;
024:        import org.eclipse.ui.PlatformUI;
025:
026:        /**
027:         * Frame for tree viewers.  This capture the viewer's input element, selection,
028:         * and expanded elements.
029:         */
030:        public class TreeFrame extends Frame {
031:            private static final String TAG_SELECTION = "selection"; //$NON-NLS-1$
032:
033:            private static final String TAG_EXPANDED = "expanded"; //$NON-NLS-1$
034:
035:            private static final String TAG_ELEMENT = "element"; //$NON-NLS-1$
036:
037:            private static final String TAG_FRAME_INPUT = "frameInput"; //$NON-NLS-1$
038:
039:            private static final String TAG_FACTORY_ID = "factoryID"; //$NON-NLS-1$
040:
041:            private AbstractTreeViewer viewer;
042:
043:            private Object input;
044:
045:            private ISelection selection;
046:
047:            private Object[] expandedElements;
048:
049:            /**
050:             * Constructs a frame for the specified tree viewer.
051:             * The frame's input, name and tool tip text are not set.
052:             * 
053:             * @param viewer the tree viewer
054:             */
055:            public TreeFrame(AbstractTreeViewer viewer) {
056:                this .viewer = viewer;
057:            }
058:
059:            /**
060:             * Constructs a frame for the specified tree viewer.
061:             * The frame's input element is set to the specified input element.
062:             * The frame's name and tool tip text are set to the text for the input 
063:             * element, as provided by the viewer's label provider.
064:             * 
065:             * @param viewer the tree viewer
066:             * @param input the input element
067:             */
068:            public TreeFrame(AbstractTreeViewer viewer, Object input) {
069:                this (viewer);
070:                setInput(input);
071:                ILabelProvider provider = (ILabelProvider) viewer
072:                        .getLabelProvider();
073:                String name = provider.getText(input);
074:                if (name == null) {
075:                    name = "";//$NON-NLS-1$
076:                }
077:                setName(name);
078:                setToolTipText(name);
079:            }
080:
081:            /**
082:             * Returns the expanded elements.
083:             * 
084:             * @return the expanded elements
085:             */
086:            public Object[] getExpandedElements() {
087:                return expandedElements;
088:            }
089:
090:            /**
091:             * Returns the input element.
092:             * 
093:             * @return the input element
094:             */
095:            public Object getInput() {
096:                return input;
097:            }
098:
099:            /**
100:             * Returns the selection.
101:             * 
102:             * @return the selection
103:             */
104:            public ISelection getSelection() {
105:                return selection;
106:            }
107:
108:            /**
109:             * Returns the tree viewer.
110:             * 
111:             * @return the tree viewer
112:             */
113:            public AbstractTreeViewer getViewer() {
114:                return viewer;
115:            }
116:
117:            /**
118:             * Restore IPersistableElements from the specified memento.
119:             * 
120:             * @param memento memento to restore elements from
121:             * @return list of restored elements. May be empty.
122:             */
123:            private List restoreElements(IMemento memento) {
124:                IMemento[] elementMem = memento.getChildren(TAG_ELEMENT);
125:                List elements = new ArrayList(elementMem.length);
126:
127:                for (int i = 0; i < elementMem.length; i++) {
128:                    String factoryID = elementMem[i].getString(TAG_FACTORY_ID);
129:                    if (factoryID != null) {
130:                        IElementFactory factory = PlatformUI.getWorkbench()
131:                                .getElementFactory(factoryID);
132:                        if (factory != null) {
133:                            elements.add(factory.createElement(elementMem[i]));
134:                        }
135:                    }
136:                }
137:                return elements;
138:            }
139:
140:            /**
141:             * Restore the frame from the specified memento.
142:             * 
143:             * @param memento memento to restore frame from
144:             */
145:            public void restoreState(IMemento memento) {
146:                IMemento childMem = memento.getChild(TAG_FRAME_INPUT);
147:
148:                if (childMem == null) {
149:                    return;
150:                }
151:
152:                String factoryID = childMem.getString(TAG_FACTORY_ID);
153:                IAdaptable frameInput = null;
154:                if (factoryID != null) {
155:                    IElementFactory factory = PlatformUI.getWorkbench()
156:                            .getElementFactory(factoryID);
157:                    if (factory != null) {
158:                        frameInput = factory.createElement(childMem);
159:                    }
160:                }
161:                if (frameInput != null) {
162:                    input = frameInput;
163:                }
164:                IMemento expandedMem = memento.getChild(TAG_EXPANDED);
165:                if (expandedMem != null) {
166:                    List elements = restoreElements(expandedMem);
167:                    expandedElements = elements.toArray(new Object[elements
168:                            .size()]);
169:                } else {
170:                    expandedElements = new Object[0];
171:                }
172:                IMemento selectionMem = memento.getChild(TAG_SELECTION);
173:                if (selectionMem != null) {
174:                    List elements = restoreElements(selectionMem);
175:                    selection = new StructuredSelection(elements);
176:                } else {
177:                    selection = StructuredSelection.EMPTY;
178:                }
179:            }
180:
181:            /**
182:             * Save the specified elements to the given memento.
183:             * The elements have to be adaptable to IPersistableElement.
184:             * 
185:             * @param elements elements to persist
186:             * @param memento memento to persist elements in
187:             */
188:            private void saveElements(Object[] elements, IMemento memento) {
189:                for (int i = 0; i < elements.length; i++) {
190:                    if (elements[i] instanceof  IAdaptable) {
191:                        IPersistableElement persistable = (IPersistableElement) ((IAdaptable) elements[i])
192:                                .getAdapter(IPersistableElement.class);
193:                        if (persistable != null) {
194:                            IMemento elementMem = memento
195:                                    .createChild(TAG_ELEMENT);
196:                            elementMem.putString(TAG_FACTORY_ID, persistable
197:                                    .getFactoryId());
198:                            persistable.saveState(elementMem);
199:                        }
200:                    }
201:                }
202:            }
203:
204:            /**
205:             * Save the frame state in the given memento.
206:             * 
207:             * @param memento memento to persist the frame state in.
208:             */
209:            public void saveState(IMemento memento) {
210:                if (!(input instanceof  IAdaptable)) {
211:                    return;
212:                }
213:
214:                IPersistableElement persistable = (IPersistableElement) ((IAdaptable) input)
215:                        .getAdapter(IPersistableElement.class);
216:                if (persistable != null) {
217:                    IMemento frameMemento = memento
218:                            .createChild(TAG_FRAME_INPUT);
219:
220:                    frameMemento.putString(TAG_FACTORY_ID, persistable
221:                            .getFactoryId());
222:                    persistable.saveState(frameMemento);
223:
224:                    if (expandedElements.length > 0) {
225:                        IMemento expandedMem = memento
226:                                .createChild(TAG_EXPANDED);
227:                        saveElements(expandedElements, expandedMem);
228:                    }
229:                    // always IStructuredSelection since we only deal with tree viewers
230:                    if (selection instanceof  IStructuredSelection) {
231:                        Object[] elements = ((IStructuredSelection) selection)
232:                                .toArray();
233:                        if (elements.length > 0) {
234:                            IMemento selectionMem = memento
235:                                    .createChild(TAG_SELECTION);
236:                            saveElements(elements, selectionMem);
237:                        }
238:                    }
239:                }
240:            }
241:
242:            /**
243:             * Sets the input element.
244:             * 
245:             * @param input the input element
246:             */
247:            public void setInput(Object input) {
248:                this .input = input;
249:            }
250:
251:            /**
252:             * Sets the expanded elements.
253:             * 
254:             * @param expandedElements the expanded elements
255:             */
256:            public void setExpandedElements(Object[] expandedElements) {
257:                this .expandedElements = expandedElements;
258:            }
259:
260:            /**
261:             * Sets the selection.
262:             * 
263:             * @param selection the selection
264:             */
265:            public void setSelection(ISelection selection) {
266:                this.selection = selection;
267:            }
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.