Source Code Cross Referenced for PackageNavigator.java in  » Net » Terracotta » org » terracotta » dso » editors » chooser » 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 » Net » Terracotta » org.terracotta.dso.editors.chooser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package org.terracotta.dso.editors.chooser;
006:
007:        import org.eclipse.core.resources.IFile;
008:        import org.eclipse.core.resources.IProject;
009:        import org.eclipse.core.resources.ResourcesPlugin;
010:        import org.eclipse.jdt.core.IJavaElement;
011:        import org.eclipse.jdt.core.IJavaProject;
012:        import org.eclipse.jdt.core.JavaCore;
013:        import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
014:        import org.eclipse.jdt.internal.core.PackageFragmentRoot;
015:        import org.eclipse.jdt.internal.ui.JavaWorkbenchAdapter;
016:        import org.eclipse.jdt.internal.ui.packageview.PackageExplorerContentProvider;
017:        import org.eclipse.jdt.internal.ui.viewsupport.AppearanceAwareLabelProvider;
018:        import org.eclipse.jdt.internal.ui.viewsupport.JavaElementImageProvider;
019:        import org.eclipse.jdt.internal.ui.viewsupport.JavaUILabelProvider;
020:        import org.eclipse.jdt.ui.JavaElementLabels;
021:        import org.eclipse.jface.dialogs.IDialogConstants;
022:        import org.eclipse.jface.dialogs.MessageDialog;
023:        import org.eclipse.jface.viewers.ISelection;
024:        import org.eclipse.jface.viewers.ISelectionChangedListener;
025:        import org.eclipse.jface.viewers.StructuredSelection;
026:        import org.eclipse.jface.viewers.TreeViewer;
027:        import org.eclipse.jface.viewers.ViewerSorter;
028:        import org.eclipse.swt.SWT;
029:        import org.eclipse.swt.events.MouseAdapter;
030:        import org.eclipse.swt.events.MouseEvent;
031:        import org.eclipse.swt.layout.GridData;
032:        import org.eclipse.swt.layout.GridLayout;
033:        import org.eclipse.swt.widgets.Composite;
034:        import org.eclipse.swt.widgets.Control;
035:        import org.eclipse.swt.widgets.Shell;
036:        import org.eclipse.swt.widgets.Tree;
037:        import org.eclipse.swt.widgets.TreeItem;
038:        import org.eclipse.ui.model.IWorkbenchAdapter;
039:        import org.eclipse.ui.model.WorkbenchContentProvider;
040:        import org.terracotta.ui.util.SWTUtil;
041:
042:        import com.tc.util.event.EventMulticaster;
043:        import com.tc.util.event.UpdateEvent;
044:        import com.tc.util.event.UpdateEventListener;
045:
046:        import java.util.ArrayList;
047:        import java.util.List;
048:
049:        public class PackageNavigator extends MessageDialog {
050:
051:            private final Shell m_parentShell;
052:            private final IProject m_project;
053:            private final EventMulticaster m_valueListener;
054:            private final NavigatorBehavior m_behavior;
055:            private Layout m_layout;
056:
057:            public PackageNavigator(Shell shell, String title,
058:                    IProject project, NavigatorBehavior behavior) {
059:                super (shell, title, null, null, MessageDialog.NONE,
060:                        new String[] { IDialogConstants.OK_LABEL,
061:                                IDialogConstants.CANCEL_LABEL }, 0);
062:                setShellStyle(getShellStyle() | SWT.RESIZE);
063:                this .m_parentShell = shell;
064:                this .m_project = project;
065:                this .m_valueListener = new EventMulticaster();
066:                this .m_behavior = behavior;
067:            }
068:
069:            protected void configureShell(Shell shell) {
070:                super .configureShell(shell);
071:                shell.setSize(400, 300);
072:                if (m_parentShell != null) {
073:                    SWTUtil.placeDialogInCenter(m_parentShell, shell);
074:                }
075:            }
076:
077:            protected Control createDialogArea(Composite parent) {
078:                parent.setLayout(new GridLayout());
079:                return super .createDialogArea(parent);
080:            }
081:
082:            protected Control createButtonBar(Composite parent) {
083:                Composite comp = (Composite) super .createButtonBar(parent);
084:                comp.setLayout(new GridLayout(2, false));
085:                getButton(getDefaultButtonIndex()).setEnabled(false);
086:                return comp;
087:            }
088:
089:            void okButtonEnabled(boolean enable) {
090:                getButton(getDefaultButtonIndex()).setEnabled(enable);
091:            }
092:
093:            void enableSelection(boolean enable,
094:                    ISelectionChangedListener listener) {
095:                if (enable)
096:                    m_layout.m_viewer.addSelectionChangedListener(listener);
097:                else
098:                    m_layout.m_viewer.removeSelectionChangedListener(listener);
099:            }
100:
101:            protected Control createCustomArea(Composite parent) {
102:                m_layout = new Layout(parent, m_behavior.style());
103:                m_layout.m_viewer
104:                        .setContentProvider(new JavaHierarchyContentProvider());
105:                m_layout.m_viewer.setLabelProvider(new JavaUILabelProvider(
106:                        AppearanceAwareLabelProvider.DEFAULT_TEXTFLAGS
107:                                | JavaElementLabels.P_COMPRESSED
108:                                | JavaElementLabels.ALL_CATEGORY,
109:                        AppearanceAwareLabelProvider.DEFAULT_IMAGEFLAGS
110:                                | JavaElementImageProvider.SMALL_ICONS));
111:                m_layout.m_viewer.setSorter(new ViewerSorter());
112:                IJavaProject jproj = JavaCore.create(m_project);
113:                m_layout.m_viewer.setInput(JavaCore.create(ResourcesPlugin
114:                        .getWorkspace().getRoot()));
115:                m_layout.m_viewer.addSelectionChangedListener(m_behavior
116:                        .getSelectionChangedListener(this ));
117:                m_layout.m_viewer.addFilter(m_behavior.getFilter(jproj));
118:
119:                return parent;
120:            }
121:
122:            protected void buttonPressed(int buttonId) {
123:                tearDown();
124:                if (buttonId == IDialogConstants.OK_ID) {
125:                    m_valueListener.fireUpdateEvent(new UpdateEvent(m_behavior
126:                            .getValues()));
127:                }
128:                super .buttonPressed(buttonId);
129:            }
130:
131:            public void addValueListener(UpdateEventListener listener) {
132:                m_valueListener.addListener(listener);
133:            }
134:
135:            private void tearDown() {
136:                m_layout.m_viewer.getTree().setRedraw(false);
137:                m_layout.m_viewer.getTree().setEnabled(false);
138:                m_layout.m_viewer.getTree().removeAll();
139:            }
140:
141:            // --------------------------------------------------------------------------------
142:
143:            private static class JavaHierarchyContentProvider extends
144:                    PackageExplorerContentProvider {
145:                private final WorkbenchContentProvider m_workbench;
146:
147:                public JavaHierarchyContentProvider() {
148:                    super (true);
149:                    setIsFlatLayout(true);
150:                    m_workbench = new WorkbenchContentProvider() {
151:                        protected IWorkbenchAdapter getAdapter(Object element) {
152:                            return new JavaWorkbenchAdapter() {
153:                                public Object[] getChildren(Object parentElement) {
154:                                    List subset = new ArrayList();
155:                                    Object[] children = super 
156:                                            .getChildren(parentElement);
157:                                    for (int i = 0; i < children.length; i++) {
158:                                        if (!(children[i] instanceof  PackageFragmentRoot && !(children[i] instanceof  JarPackageFragmentRoot))) {
159:                                            subset.add(children[i]);
160:                                        }
161:                                    }
162:                                    return subset.toArray();
163:                                }
164:                            };
165:                        }
166:                    };
167:                }
168:
169:                public Object[] getChildren(Object parentElement) {
170:                    List subset = new ArrayList();
171:                    Object[] children = super .getChildren(parentElement);
172:                    for (int i = 0; i < children.length; i++) {
173:                        if (children[i] instanceof  JarPackageFragmentRoot) {
174:                            Object[] workbenchElements = m_workbench
175:                                    .getChildren(((IJavaElement) children[i])
176:                                            .getParent());
177:                            return workbenchElements;
178:                        }
179:                        if (children[i]
180:                                .getClass()
181:                                .getName()
182:                                .equals(
183:                                        "org.eclipse.jdt.internal.core.JarPackageFragment")) {
184:                            Object[] workbenchElements = m_workbench
185:                                    .getChildren(parentElement);
186:                            return workbenchElements;
187:                        }
188:                        subset.add(children[i]);
189:                    }
190:                    return subset.toArray();
191:                }
192:            }
193:
194:            // --------------------------------------------------------------------------------
195:
196:            private class Layout {
197:                final TreeViewer m_viewer;
198:
199:                private Layout(Composite parent, int style) {
200:                    this .m_viewer = new TreeViewer(parent, style | SWT.BORDER);
201:                    m_viewer.setAutoExpandLevel(2);
202:                    m_viewer.getTree().setLayoutData(
203:                            new GridData(GridData.FILL_BOTH));
204:                    m_viewer.getTree().addMouseListener(new MouseAdapter() {
205:                        public void mouseDoubleClick(MouseEvent e) {
206:                            ISelection sel = m_viewer.getSelection();
207:
208:                            if (sel instanceof  StructuredSelection
209:                                    && !sel.isEmpty()) {
210:                                Object o = ((StructuredSelection) sel)
211:                                        .getFirstElement();
212:
213:                                if (o instanceof  IFile) {
214:                                    buttonPressed(IDialogConstants.OK_ID);
215:                                } else {
216:                                    Tree tree = (Tree) e.widget;
217:                                    TreeItem[] selection = tree.getSelection();
218:
219:                                    if (selection.length > 0) {
220:                                        TreeItem item = selection[0];
221:                                        item.setExpanded(!item.getExpanded());
222:                                        m_viewer.refresh();
223:                                    }
224:                                }
225:                            }
226:                        }
227:                    });
228:                }
229:            }
230:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.