Source Code Cross Referenced for TreeViewerFrameSource.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 org.eclipse.jface.util.IPropertyChangeListener;
013:        import org.eclipse.jface.util.PropertyChangeEvent;
014:        import org.eclipse.jface.viewers.AbstractTreeViewer;
015:        import org.eclipse.jface.viewers.IStructuredSelection;
016:        import org.eclipse.jface.viewers.ITreeContentProvider;
017:
018:        /** 
019:         * Frame source for tree viewers, which uses <code>TreeFrame</code> to capture
020:         * the state of the tree viewer.
021:         * 
022:         * @see TreeFrame
023:         */
024:        public class TreeViewerFrameSource implements  IFrameSource {
025:
026:            private AbstractTreeViewer viewer;
027:
028:            /**
029:             * Constructs a new tree viewer frame source for the specified tree viewer.
030:             * 
031:             * @param viewer the tree viewer
032:             */
033:            public TreeViewerFrameSource(AbstractTreeViewer viewer) {
034:                this .viewer = viewer;
035:            }
036:
037:            /**
038:             * Connects this source as a listener on the frame list,
039:             * so that when the current frame changes, the viewer is updated.
040:             */
041:            public void connectTo(FrameList frameList) {
042:                frameList
043:                        .addPropertyChangeListener(new IPropertyChangeListener() {
044:                            public void propertyChange(PropertyChangeEvent event) {
045:                                TreeViewerFrameSource.this 
046:                                        .handlePropertyChange(event);
047:                            }
048:                        });
049:            }
050:
051:            /**
052:             * Returns a new tree frame capturing the specified input element.
053:             * 
054:             * @param input the input element
055:             * @return the tree frame
056:             */
057:            protected TreeFrame createFrame(Object input) {
058:                return new TreeFrame(viewer, input);
059:            }
060:
061:            /**
062:             * Updates the viewer in response to the current frame changing.
063:             * 
064:             * @param frame the new value for the current frame
065:             */
066:            protected void frameChanged(TreeFrame frame) {
067:                viewer.getControl().setRedraw(false);
068:                viewer.setInput(frame.getInput());
069:                viewer.setExpandedElements(frame.getExpandedElements());
070:                viewer.setSelection(frame.getSelection(), true);
071:                viewer.getControl().setRedraw(true);
072:            }
073:
074:            /**
075:             * Returns the current frame.
076:             * 
077:             * @param flags a bit-wise OR of the frame source flag constants
078:             * @return the current frame
079:             */
080:            protected Frame getCurrentFrame(int flags) {
081:                Object input = viewer.getInput();
082:                TreeFrame frame = createFrame(input);
083:                if ((flags & IFrameSource.FULL_CONTEXT) != 0) {
084:                    frame.setSelection(viewer.getSelection());
085:                    frame.setExpandedElements(viewer.getExpandedElements());
086:                }
087:                return frame;
088:            }
089:
090:            /* (non-Javadoc)
091:             * Method declared on IFrameSource.
092:             */
093:            public Frame getFrame(int whichFrame, int flags) {
094:                switch (whichFrame) {
095:                case IFrameSource.CURRENT_FRAME:
096:                    return getCurrentFrame(flags);
097:                case IFrameSource.PARENT_FRAME:
098:                    return getParentFrame(flags);
099:                case IFrameSource.SELECTION_FRAME:
100:                    return getSelectionFrame(flags);
101:                default:
102:                    return null;
103:                }
104:            }
105:
106:            /**
107:             * Returns the parent frame, or <code>null</code> if there is no parent frame.
108:             * 
109:             * @param flags a bit-wise OR of the frame source flag constants
110:             * @return the parent frame, or <code>null</code>
111:             */
112:            protected Frame getParentFrame(int flags) {
113:                Object input = viewer.getInput();
114:                ITreeContentProvider provider = (ITreeContentProvider) viewer
115:                        .getContentProvider();
116:                Object parent = provider.getParent(input);
117:                if (parent == null) {
118:                    return null;
119:                } else {
120:                    TreeFrame frame = createFrame(parent);
121:                    if ((flags & IFrameSource.FULL_CONTEXT) != 0) {
122:                        frame.setSelection(viewer.getSelection());
123:                        // include current input in expanded set
124:                        Object[] expanded = viewer.getExpandedElements();
125:                        Object[] newExpanded = new Object[expanded.length + 1];
126:                        System.arraycopy(expanded, 0, newExpanded, 0,
127:                                expanded.length);
128:                        newExpanded[newExpanded.length - 1] = input;
129:                        frame.setExpandedElements(newExpanded);
130:                    }
131:                    return frame;
132:                }
133:            }
134:
135:            /**
136:             * Returns the frame for the selection, or <code>null</code> if there is no
137:             * frame for the selection.
138:             * 
139:             * @param flags a bit-wise OR of the frame source flag constants
140:             * @return the selection frame, or <code>null</code>
141:             */
142:            protected Frame getSelectionFrame(int flags) {
143:                IStructuredSelection sel = (IStructuredSelection) viewer
144:                        .getSelection();
145:                if (sel.size() == 1) {
146:                    Object o = sel.getFirstElement();
147:                    if (viewer.isExpandable(o)) {
148:                        TreeFrame frame = createFrame(o);
149:                        if ((flags & IFrameSource.FULL_CONTEXT) != 0) {
150:                            frame.setSelection(viewer.getSelection());
151:                            frame.setExpandedElements(viewer
152:                                    .getExpandedElements());
153:                        }
154:                        return frame;
155:                    }
156:                }
157:                return null;
158:            }
159:
160:            /**
161:             * Returns the tree viewer.
162:             * 
163:             * @return the tree viewer
164:             */
165:            public AbstractTreeViewer getViewer() {
166:                return viewer;
167:            }
168:
169:            /**
170:             * Handles a property change event from the frame list.
171:             * Calls <code>frameChanged</code> when the current frame changes.
172:             */
173:            protected void handlePropertyChange(PropertyChangeEvent event) {
174:                if (FrameList.P_CURRENT_FRAME.equals(event.getProperty())) {
175:                    frameChanged((TreeFrame) event.getNewValue());
176:                }
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.