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


001:        package org.eclipse.ui.tutorials.rcp.part3;
002:
003:        import java.util.ArrayList;
004:
005:        import org.eclipse.jface.viewers.IStructuredContentProvider;
006:        import org.eclipse.jface.viewers.ITreeContentProvider;
007:        import org.eclipse.jface.viewers.LabelProvider;
008:        import org.eclipse.jface.viewers.TreeViewer;
009:        import org.eclipse.jface.viewers.Viewer;
010:        import org.eclipse.swt.SWT;
011:        import org.eclipse.swt.graphics.Image;
012:        import org.eclipse.swt.widgets.Composite;
013:        import org.eclipse.ui.ISharedImages;
014:        import org.eclipse.ui.PlatformUI;
015:        import org.eclipse.ui.part.ViewPart;
016:
017:        public class NavigationView extends ViewPart {
018:            public static final String ID = "org.eclipse.ui.tutorials.rcp.part3.navigationView";
019:            private TreeViewer viewer;
020:
021:            class TreeObject {
022:                private String name;
023:                private TreeParent parent;
024:
025:                public TreeObject(String name) {
026:                    this .name = name;
027:                }
028:
029:                public String getName() {
030:                    return name;
031:                }
032:
033:                public void setParent(TreeParent parent) {
034:                    this .parent = parent;
035:                }
036:
037:                public TreeParent getParent() {
038:                    return parent;
039:                }
040:
041:                public String toString() {
042:                    return getName();
043:                }
044:            }
045:
046:            class TreeParent extends TreeObject {
047:                private ArrayList children;
048:
049:                public TreeParent(String name) {
050:                    super (name);
051:                    children = new ArrayList();
052:                }
053:
054:                public void addChild(TreeObject child) {
055:                    children.add(child);
056:                    child.setParent(this );
057:                }
058:
059:                public void removeChild(TreeObject child) {
060:                    children.remove(child);
061:                    child.setParent(null);
062:                }
063:
064:                public TreeObject[] getChildren() {
065:                    return (TreeObject[]) children
066:                            .toArray(new TreeObject[children.size()]);
067:                }
068:
069:                public boolean hasChildren() {
070:                    return children.size() > 0;
071:                }
072:            }
073:
074:            class ViewContentProvider implements  IStructuredContentProvider,
075:                    ITreeContentProvider {
076:
077:                public void inputChanged(Viewer v, Object oldInput,
078:                        Object newInput) {
079:                }
080:
081:                public void dispose() {
082:                }
083:
084:                public Object[] getElements(Object parent) {
085:                    return getChildren(parent);
086:                }
087:
088:                public Object getParent(Object child) {
089:                    if (child instanceof  TreeObject) {
090:                        return ((TreeObject) child).getParent();
091:                    }
092:                    return null;
093:                }
094:
095:                public Object[] getChildren(Object parent) {
096:                    if (parent instanceof  TreeParent) {
097:                        return ((TreeParent) parent).getChildren();
098:                    }
099:                    return new Object[0];
100:                }
101:
102:                public boolean hasChildren(Object parent) {
103:                    if (parent instanceof  TreeParent)
104:                        return ((TreeParent) parent).hasChildren();
105:                    return false;
106:                }
107:            }
108:
109:            class ViewLabelProvider extends LabelProvider {
110:
111:                public String getText(Object obj) {
112:                    return obj.toString();
113:                }
114:
115:                public Image getImage(Object obj) {
116:                    String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
117:                    if (obj instanceof  TreeParent)
118:                        imageKey = ISharedImages.IMG_OBJ_FOLDER;
119:                    return PlatformUI.getWorkbench().getSharedImages()
120:                            .getImage(imageKey);
121:                }
122:            }
123:
124:            /**
125:             * We will set up a dummy model to initialize tree heararchy. In real
126:             * code, you will connect to a real model and expose its hierarchy.
127:             */
128:            private TreeObject createDummyModel() {
129:                TreeObject to1 = new TreeObject("Inbox");
130:                TreeObject to2 = new TreeObject("Drafts");
131:                TreeObject to3 = new TreeObject("Sent");
132:                TreeParent p1 = new TreeParent("me@this.com");
133:                p1.addChild(to1);
134:                p1.addChild(to2);
135:                p1.addChild(to3);
136:
137:                TreeObject to4 = new TreeObject("Inbox");
138:                TreeParent p2 = new TreeParent("other@aol.com");
139:                p2.addChild(to4);
140:
141:                TreeParent root = new TreeParent("");
142:                root.addChild(p1);
143:                root.addChild(p2);
144:                return root;
145:            }
146:
147:            /**
148:             * This is a callback that will allow us to create the viewer and initialize
149:             * it.
150:             */
151:            public void createPartControl(Composite parent) {
152:                viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL
153:                        | SWT.V_SCROLL | SWT.BORDER);
154:                viewer.setContentProvider(new ViewContentProvider());
155:                viewer.setLabelProvider(new ViewLabelProvider());
156:                viewer.setInput(createDummyModel());
157:            }
158:
159:            /**
160:             * Passing the focus request to the viewer's control.
161:             */
162:            public void setFocus() {
163:                viewer.getControl().setFocus();
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.