Source Code Cross Referenced for FormOutlinePage.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » 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 » Eclipse plug in development » org.eclipse.pde.internal.ui.editor 
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.pde.internal.ui.editor;
011:
012:        import java.util.ArrayList;
013:
014:        import org.eclipse.jface.viewers.AbstractTreeViewer;
015:        import org.eclipse.jface.viewers.ILabelProvider;
016:        import org.eclipse.jface.viewers.ISelection;
017:        import org.eclipse.jface.viewers.IStructuredSelection;
018:        import org.eclipse.jface.viewers.ITreeContentProvider;
019:        import org.eclipse.jface.viewers.LabelProvider;
020:        import org.eclipse.jface.viewers.SelectionChangedEvent;
021:        import org.eclipse.jface.viewers.StructuredSelection;
022:        import org.eclipse.jface.viewers.TreeViewer;
023:        import org.eclipse.jface.viewers.ViewerComparator;
024:        import org.eclipse.pde.core.IBaseModel;
025:        import org.eclipse.pde.core.IModelChangeProvider;
026:        import org.eclipse.pde.core.IModelChangedEvent;
027:        import org.eclipse.pde.core.IModelChangedListener;
028:        import org.eclipse.pde.internal.core.plugin.ImportObject;
029:        import org.eclipse.pde.internal.core.text.IDocumentElementNode;
030:        import org.eclipse.pde.internal.ui.PDEPlugin;
031:        import org.eclipse.pde.internal.ui.PDEPluginImages;
032:        import org.eclipse.pde.internal.ui.elements.DefaultContentProvider;
033:        import org.eclipse.swt.SWT;
034:        import org.eclipse.swt.graphics.Image;
035:        import org.eclipse.swt.widgets.Composite;
036:        import org.eclipse.swt.widgets.Control;
037:        import org.eclipse.swt.widgets.Tree;
038:        import org.eclipse.ui.forms.editor.IFormPage;
039:
040:        public class FormOutlinePage extends PDEOutlinePage implements 
041:                IModelChangedListener, ISortableContentOutlinePage {
042:
043:            private boolean fStale;
044:            private ViewerComparator fViewerComparator;
045:            private boolean fSorted;
046:
047:            public class BasicContentProvider extends DefaultContentProvider
048:                    implements  ITreeContentProvider {
049:                public Object[] getElements(Object obj) {
050:                    return getPages();
051:                }
052:
053:                public Object[] getChildren(Object obj) {
054:                    return FormOutlinePage.this .getChildren(obj);
055:                }
056:
057:                public boolean hasChildren(Object obj) {
058:                    return getChildren(obj).length > 0;
059:                }
060:
061:                public Object getParent(Object obj) {
062:                    return null;
063:                }
064:            }
065:
066:            public class BasicLabelProvider extends LabelProvider {
067:                public String getText(Object obj) {
068:                    if (obj instanceof  IFormPage)
069:                        return ((IFormPage) obj).getTitle();
070:                    return PDEPlugin.getDefault().getLabelProvider().getText(
071:                            obj);
072:                }
073:
074:                public Image getImage(Object obj) {
075:                    if (obj instanceof  IFormPage)
076:                        return PDEPlugin.getDefault().getLabelProvider().get(
077:                                PDEPluginImages.DESC_PAGE_OBJ);
078:                    return PDEPlugin.getDefault().getLabelProvider().getImage(
079:                            obj);
080:                }
081:            }
082:
083:            public class BasicComparator extends ViewerComparator {
084:                /* (non-Javadoc)
085:                 * @see org.eclipse.jface.viewers.ViewerSorter#category(java.lang.Object)
086:                 */
087:                public int category(Object element) {
088:                    Object[] pages = getPages();
089:                    for (int i = 0; i < pages.length; i++) {
090:                        if (pages[i] == element) {
091:                            return i;
092:                        }
093:                    }
094:                    return Integer.MAX_VALUE;
095:                }
096:            }
097:
098:            protected TreeViewer fTreeViewer;
099:            protected boolean fEditorSelection = false;
100:            protected boolean fOutlineSelection = false;
101:
102:            public FormOutlinePage(PDEFormEditor editor) {
103:                super (editor);
104:            }
105:
106:            /**
107:             * @return
108:             */
109:            public ITreeContentProvider createContentProvider() {
110:                return new BasicContentProvider();
111:            }
112:
113:            /**
114:             * @return
115:             */
116:            public ViewerComparator createOutlineSorter() {
117:                return new BasicComparator();
118:            }
119:
120:            public void createControl(Composite parent) {
121:                Tree widget = new Tree(parent, SWT.MULTI | SWT.H_SCROLL
122:                        | SWT.V_SCROLL);
123:                fTreeViewer = new TreeViewer(widget);
124:                fTreeViewer.addSelectionChangedListener(this );
125:                fTreeViewer.setContentProvider(createContentProvider());
126:                fTreeViewer.setLabelProvider(createLabelProvider());
127:                fViewerComparator = createOutlineSorter();
128:                if (fSorted)
129:                    fTreeViewer.setComparator(fViewerComparator);
130:                else
131:                    fTreeViewer.setComparator(null);
132:                fTreeViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS);
133:                fTreeViewer.setUseHashlookup(true);
134:                fTreeViewer.setInput(fEditor);
135:                IBaseModel model = fEditor.getAggregateModel();
136:                if (model instanceof  IModelChangeProvider)
137:                    ((IModelChangeProvider) model)
138:                            .addModelChangedListener(this );
139:            }
140:
141:            /**
142:             * @return
143:             */
144:            public ILabelProvider createLabelProvider() {
145:                return new BasicLabelProvider();
146:            }
147:
148:            public void dispose() {
149:                IBaseModel model = fEditor.getAggregateModel();
150:                if (model instanceof  IModelChangeProvider)
151:                    ((IModelChangeProvider) model)
152:                            .removeModelChangedListener(this );
153:                super .dispose();
154:            }
155:
156:            public Control getControl() {
157:                return fTreeViewer != null ? fTreeViewer.getControl() : null;
158:            }
159:
160:            private Object[] getPages() {
161:                ArrayList formPages = new ArrayList();
162:                IFormPage[] pages = fEditor.getPages();
163:                for (int i = 0; i < pages.length; i++) {
164:                    if (pages[i].isEditor() == false)
165:                        formPages.add(pages[i]);
166:                }
167:                return formPages.toArray();
168:            }
169:
170:            public void modelChanged(IModelChangedEvent event) {
171:                IFormPage page = fEditor.getActivePageInstance();
172:                fStale = true;
173:                if (page.isEditor() == false)
174:                    refresh();
175:            }
176:
177:            public void refresh() {
178:                if (fStale) {
179:                    final Control control = getControl();
180:                    if (control == null || control.isDisposed())
181:                        return;
182:                    control.getDisplay().asyncExec(new Runnable() {
183:                        public void run() {
184:                            if (!fTreeViewer.getControl().isDisposed()) {
185:                                fTreeViewer.refresh();
186:                                fTreeViewer.expandAll();
187:                                fStale = false;
188:                            }
189:                        }
190:                    });
191:                }
192:            }
193:
194:            protected String getParentPageId(Object item) {
195:                if (item instanceof  IFormPage)
196:                    return ((IFormPage) item).getId();
197:                return null;
198:            }
199:
200:            protected Object[] getChildren(Object parent) {
201:                return new Object[0];
202:            }
203:
204:            public void selectionChanged(Object item) {
205:                IFormPage page = fEditor.getActivePageInstance();
206:                String id = getParentPageId(item);
207:                IFormPage newPage = null;
208:                if (id != null && (page == null || !page.getId().equals(id)))
209:                    newPage = fEditor.setActivePage(id);
210:                IFormPage revealPage = newPage != null ? newPage : page;
211:                if (revealPage != null && !(item instanceof  IFormPage))
212:                    revealPage.selectReveal(item);
213:            }
214:
215:            public void selectionChanged(SelectionChangedEvent event) {
216:                if (fEditorSelection)
217:                    return;
218:                fOutlineSelection = true;
219:                try {
220:                    ISelection selection = event.getSelection();
221:                    if (selection.isEmpty() == false
222:                            && selection instanceof  IStructuredSelection) {
223:                        IStructuredSelection ssel = (IStructuredSelection) selection;
224:                        Object item = ssel.getFirstElement();
225:                        selectionChanged(item);
226:                    }
227:                    fireSelectionChanged(selection);
228:                } finally {
229:                    fOutlineSelection = false;
230:                }
231:            }
232:
233:            public void setFocus() {
234:                if (fTreeViewer != null)
235:                    fTreeViewer.getTree().setFocus();
236:            }
237:
238:            public ISelection getSelection() {
239:                if (fTreeViewer == null)
240:                    return StructuredSelection.EMPTY;
241:                return fTreeViewer.getSelection();
242:            }
243:
244:            public void sort(boolean sorting) {
245:                fSorted = sorting;
246:                if (fTreeViewer != null)
247:                    if (sorting)
248:                        fTreeViewer.setComparator(fViewerComparator);
249:                    else
250:                        fTreeViewer.setComparator(null);
251:            }
252:
253:            /*
254:             * (non-Javadoc) Method declared on ISelectionProvider.
255:             */
256:            public void setSelection(ISelection selection) {
257:                if (fOutlineSelection)
258:                    return;
259:                fEditorSelection = true;
260:                try {
261:                    if (fTreeViewer == null)
262:                        return;
263:                    if (selection != null && !selection.isEmpty()
264:                            && selection instanceof  IStructuredSelection) {
265:                        Object item = ((IStructuredSelection) selection)
266:                                .getFirstElement();
267:                        if (item instanceof  ImportObject) {
268:                            selection = new StructuredSelection(
269:                                    ((ImportObject) item).getImport());
270:                        }
271:                        if (item instanceof  IDocumentElementNode) {
272:                            while (null == fTreeViewer.testFindItem(item)) {
273:                                item = ((IDocumentElementNode) item)
274:                                        .getParentNode();
275:                                if (item == null) {
276:                                    break;
277:                                }
278:                                selection = new StructuredSelection(item);
279:                            }
280:                        }
281:                    }
282:                    fTreeViewer.setSelection(selection);
283:                } finally {
284:                    fEditorSelection = false;
285:                }
286:            }
287:
288:            protected TreeViewer getTreeViewer() {
289:                return fTreeViewer;
290:            }
291:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.