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


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 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.examples.javaeditor;
011:
012:        import java.text.MessageFormat;
013:        import java.util.ArrayList;
014:        import java.util.List;
015:
016:        import org.eclipse.jface.text.*;
017:        import org.eclipse.jface.viewers.*;
018:        import org.eclipse.swt.widgets.Composite;
019:        import org.eclipse.swt.widgets.Control;
020:        import org.eclipse.ui.texteditor.IDocumentProvider;
021:        import org.eclipse.ui.texteditor.ITextEditor;
022:        import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
023:
024:        /**
025:         * A content outline page which always represents the content of the
026:         * connected editor in 10 segments.
027:         */
028:        public class JavaContentOutlinePage extends ContentOutlinePage {
029:
030:            /**
031:             * A segment element.
032:             */
033:            protected static class Segment {
034:                public String name;
035:                public Position position;
036:
037:                public Segment(String name, Position position) {
038:                    this .name = name;
039:                    this .position = position;
040:                }
041:
042:                public String toString() {
043:                    return name;
044:                }
045:            }
046:
047:            /**
048:             * Divides the editor's document into ten segments and provides elements for them.
049:             */
050:            protected class ContentProvider implements  ITreeContentProvider {
051:
052:                protected final static String SEGMENTS = "__java_segments"; //$NON-NLS-1$
053:                protected IPositionUpdater fPositionUpdater = new DefaultPositionUpdater(
054:                        SEGMENTS);
055:                protected List fContent = new ArrayList(10);
056:
057:                protected void parse(IDocument document) {
058:
059:                    int lines = document.getNumberOfLines();
060:                    int increment = Math.max(Math.round(lines / 10), 10);
061:
062:                    for (int line = 0; line < lines; line += increment) {
063:
064:                        int length = increment;
065:                        if (line + increment > lines)
066:                            length = lines - line;
067:
068:                        try {
069:
070:                            int offset = document.getLineOffset(line);
071:                            int end = document.getLineOffset(line + length);
072:                            length = end - offset;
073:                            Position p = new Position(offset, length);
074:                            document.addPosition(SEGMENTS, p);
075:                            fContent
076:                                    .add(new Segment(
077:                                            MessageFormat
078:                                                    .format(
079:                                                            JavaEditorMessages
080:                                                                    .getString("OutlinePage.segment.title_pattern"), new Object[] { new Integer(offset) }), p)); //$NON-NLS-1$
081:
082:                        } catch (BadPositionCategoryException x) {
083:                        } catch (BadLocationException x) {
084:                        }
085:                    }
086:                }
087:
088:                /*
089:                 * @see IContentProvider#inputChanged(Viewer, Object, Object)
090:                 */
091:                public void inputChanged(Viewer viewer, Object oldInput,
092:                        Object newInput) {
093:                    if (oldInput != null) {
094:                        IDocument document = fDocumentProvider
095:                                .getDocument(oldInput);
096:                        if (document != null) {
097:                            try {
098:                                document.removePositionCategory(SEGMENTS);
099:                            } catch (BadPositionCategoryException x) {
100:                            }
101:                            document.removePositionUpdater(fPositionUpdater);
102:                        }
103:                    }
104:
105:                    fContent.clear();
106:
107:                    if (newInput != null) {
108:                        IDocument document = fDocumentProvider
109:                                .getDocument(newInput);
110:                        if (document != null) {
111:                            document.addPositionCategory(SEGMENTS);
112:                            document.addPositionUpdater(fPositionUpdater);
113:
114:                            parse(document);
115:                        }
116:                    }
117:                }
118:
119:                /*
120:                 * @see IContentProvider#dispose
121:                 */
122:                public void dispose() {
123:                    if (fContent != null) {
124:                        fContent.clear();
125:                        fContent = null;
126:                    }
127:                }
128:
129:                /*
130:                 * @see IContentProvider#isDeleted(Object)
131:                 */
132:                public boolean isDeleted(Object element) {
133:                    return false;
134:                }
135:
136:                /*
137:                 * @see IStructuredContentProvider#getElements(Object)
138:                 */
139:                public Object[] getElements(Object element) {
140:                    return fContent.toArray();
141:                }
142:
143:                /*
144:                 * @see ITreeContentProvider#hasChildren(Object)
145:                 */
146:                public boolean hasChildren(Object element) {
147:                    return element == fInput;
148:                }
149:
150:                /*
151:                 * @see ITreeContentProvider#getParent(Object)
152:                 */
153:                public Object getParent(Object element) {
154:                    if (element instanceof  Segment)
155:                        return fInput;
156:                    return null;
157:                }
158:
159:                /*
160:                 * @see ITreeContentProvider#getChildren(Object)
161:                 */
162:                public Object[] getChildren(Object element) {
163:                    if (element == fInput)
164:                        return fContent.toArray();
165:                    return new Object[0];
166:                }
167:            }
168:
169:            protected Object fInput;
170:            protected IDocumentProvider fDocumentProvider;
171:            protected ITextEditor fTextEditor;
172:
173:            /**
174:             * Creates a content outline page using the given provider and the given editor.
175:             * 
176:             * @param provider the document provider
177:             * @param editor the editor
178:             */
179:            public JavaContentOutlinePage(IDocumentProvider provider,
180:                    ITextEditor editor) {
181:                super ();
182:                fDocumentProvider = provider;
183:                fTextEditor = editor;
184:            }
185:
186:            /* (non-Javadoc)
187:             * Method declared on ContentOutlinePage
188:             */
189:            public void createControl(Composite parent) {
190:
191:                super .createControl(parent);
192:
193:                TreeViewer viewer = getTreeViewer();
194:                viewer.setContentProvider(new ContentProvider());
195:                viewer.setLabelProvider(new LabelProvider());
196:                viewer.addSelectionChangedListener(this );
197:
198:                if (fInput != null)
199:                    viewer.setInput(fInput);
200:            }
201:
202:            /* (non-Javadoc)
203:             * Method declared on ContentOutlinePage
204:             */
205:            public void selectionChanged(SelectionChangedEvent event) {
206:
207:                super .selectionChanged(event);
208:
209:                ISelection selection = event.getSelection();
210:                if (selection.isEmpty())
211:                    fTextEditor.resetHighlightRange();
212:                else {
213:                    Segment segment = (Segment) ((IStructuredSelection) selection)
214:                            .getFirstElement();
215:                    int start = segment.position.getOffset();
216:                    int length = segment.position.getLength();
217:                    try {
218:                        fTextEditor.setHighlightRange(start, length, true);
219:                    } catch (IllegalArgumentException x) {
220:                        fTextEditor.resetHighlightRange();
221:                    }
222:                }
223:            }
224:
225:            /**
226:             * Sets the input of the outline page
227:             * 
228:             * @param input the input of this outline page
229:             */
230:            public void setInput(Object input) {
231:                fInput = input;
232:                update();
233:            }
234:
235:            /**
236:             * Updates the outline page.
237:             */
238:            public void update() {
239:                TreeViewer viewer = getTreeViewer();
240:
241:                if (viewer != null) {
242:                    Control control = viewer.getControl();
243:                    if (control != null && !control.isDisposed()) {
244:                        control.setRedraw(false);
245:                        viewer.setInput(fInput);
246:                        viewer.expandAll();
247:                        control.setRedraw(true);
248:                    }
249:                }
250:            }
251:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.