Source Code Cross Referenced for MultiPageEditorExample.java in  » IDE-Eclipse » ui-examples » org » eclipse » ui » examples » multipageeditor » 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.multipageeditor 
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.examples.multipageeditor;
011:
012:        import java.io.StringWriter;
013:        import java.text.Collator;
014:        import java.util.ArrayList;
015:        import java.util.Collections;
016:        import java.util.StringTokenizer;
017:
018:        import org.eclipse.core.resources.IMarker;
019:        import org.eclipse.core.runtime.IProgressMonitor;
020:        import org.eclipse.jface.dialogs.ErrorDialog;
021:        import org.eclipse.swt.SWT;
022:        import org.eclipse.swt.custom.StyledText;
023:        import org.eclipse.swt.events.SelectionAdapter;
024:        import org.eclipse.swt.events.SelectionEvent;
025:        import org.eclipse.swt.graphics.Font;
026:        import org.eclipse.swt.graphics.FontData;
027:        import org.eclipse.swt.layout.FillLayout;
028:        import org.eclipse.swt.layout.GridData;
029:        import org.eclipse.swt.layout.GridLayout;
030:        import org.eclipse.swt.widgets.Button;
031:        import org.eclipse.swt.widgets.Composite;
032:        import org.eclipse.swt.widgets.FontDialog;
033:        import org.eclipse.ui.IEditorInput;
034:        import org.eclipse.ui.IEditorPart;
035:        import org.eclipse.ui.IEditorSite;
036:        import org.eclipse.ui.IFileEditorInput;
037:        import org.eclipse.ui.PartInitException;
038:        import org.eclipse.ui.editors.text.TextEditor;
039:        import org.eclipse.ui.ide.IDE;
040:        import org.eclipse.ui.ide.IGotoMarker;
041:        import org.eclipse.ui.part.MultiPageEditorPart;
042:
043:        /**
044:         * An example showing how to create a multi-page editor.
045:         * This example has 3 pages:
046:         * <ul>
047:         * <li>page 0 contains a nested text editor.
048:         * <li>page 1 allows you to change the font used in page 2
049:         * <li>page 2 shows the words in page 0 in sorted order
050:         * </ul>
051:         */
052:        public class MultiPageEditorExample extends MultiPageEditorPart
053:                implements  IGotoMarker {
054:
055:            /** The text editor used in page 0. */
056:            private TextEditor editor;
057:
058:            /** The index of the page containing the text editor */
059:            private int editorIndex = 0;
060:
061:            /** The font chosen in page 1. */
062:            private Font font;
063:
064:            /** The text widget used in page 2. */
065:            private StyledText text;
066:
067:            /**
068:             * Creates a multi-page editor example.
069:             */
070:            public MultiPageEditorExample() {
071:                super ();
072:            }
073:
074:            /**
075:             * Creates page 0 of the multi-page editor,
076:             * which contains a text editor.
077:             */
078:            void createPage0() {
079:                try {
080:                    editor = new TextEditor();
081:                    editorIndex = addPage(editor, getEditorInput());
082:                    setPageText(editorIndex, MessageUtil.getString("Source")); //$NON-NLS-1$
083:                } catch (PartInitException e) {
084:                    ErrorDialog
085:                            .openError(
086:                                    getSite().getShell(),
087:                                    MessageUtil
088:                                            .getString("ErrorCreatingNestedEditor"), null, e.getStatus()); //$NON-NLS-1$
089:                }
090:            }
091:
092:            /**
093:             * Creates page 1 of the multi-page editor,
094:             * which allows you to change the font used in page 2.
095:             */
096:            void createPage1() {
097:
098:                Composite composite = new Composite(getContainer(), SWT.NONE);
099:                GridLayout layout = new GridLayout();
100:                composite.setLayout(layout);
101:                layout.numColumns = 2;
102:
103:                Button fontButton = new Button(composite, SWT.NONE);
104:                GridData gd = new GridData(GridData.BEGINNING);
105:                gd.horizontalSpan = 2;
106:                fontButton.setLayoutData(gd);
107:                fontButton.setText(MessageUtil.getString("ChangeFont")); //$NON-NLS-1$
108:
109:                fontButton.addSelectionListener(new SelectionAdapter() {
110:                    public void widgetSelected(SelectionEvent event) {
111:                        setFont();
112:                    }
113:                });
114:
115:                int index = addPage(composite);
116:                setPageText(index, MessageUtil.getString("Properties")); //$NON-NLS-1$
117:            }
118:
119:            /**
120:             * Creates page 2 of the multi-page editor,
121:             * which shows the sorted text.
122:             */
123:            void createPage2() {
124:                Composite composite = new Composite(getContainer(), SWT.NONE);
125:                FillLayout layout = new FillLayout();
126:                composite.setLayout(layout);
127:                text = new StyledText(composite, SWT.H_SCROLL | SWT.V_SCROLL);
128:                text.setEditable(false);
129:
130:                int index = addPage(composite);
131:                setPageText(index, MessageUtil.getString("Preview")); //$NON-NLS-1$
132:            }
133:
134:            /**
135:             * Creates the pages of the multi-page editor.
136:             */
137:            protected void createPages() {
138:                createPage0();
139:                createPage1();
140:                createPage2();
141:            }
142:
143:            /**
144:             * Saves the multi-page editor's document.
145:             */
146:            public void doSave(IProgressMonitor monitor) {
147:                getEditor(0).doSave(monitor);
148:            }
149:
150:            /**
151:             * Saves the multi-page editor's document as another file.
152:             * Also updates the text for page 0's tab, and updates this multi-page editor's input
153:             * to correspond to the nested editor's.
154:             */
155:            public void doSaveAs() {
156:                IEditorPart editor = getEditor(0);
157:                editor.doSaveAs();
158:                setPageText(0, editor.getTitle());
159:                setInput(editor.getEditorInput());
160:            }
161:
162:            /**
163:             * The <code>MultiPageEditorExample</code> implementation of this method
164:             * checks that the input is an instance of <code>IFileEditorInput</code>.
165:             */
166:            public void init(IEditorSite site, IEditorInput editorInput)
167:                    throws PartInitException {
168:                if (!(editorInput instanceof  IFileEditorInput))
169:                    throw new PartInitException(MessageUtil
170:                            .getString("InvalidInput")); //$NON-NLS-1$
171:                super .init(site, editorInput);
172:            }
173:
174:            /* (non-Javadoc)
175:             * Method declared on IEditorPart.
176:             */
177:            public boolean isSaveAsAllowed() {
178:                return true;
179:            }
180:
181:            /**
182:             * Calculates the contents of page 2 when the it is activated.
183:             */
184:            protected void pageChange(int newPageIndex) {
185:                super .pageChange(newPageIndex);
186:                if (newPageIndex == 2) {
187:                    sortWords();
188:                }
189:            }
190:
191:            /**
192:             * Sets the font related data to be applied to the text in page 2.
193:             */
194:            void setFont() {
195:                FontDialog fontDialog = new FontDialog(getSite().getShell());
196:                fontDialog.setFontList(text.getFont().getFontData());
197:                FontData fontData = fontDialog.open();
198:                if (fontData != null) {
199:                    if (font != null)
200:                        font.dispose();
201:                    font = new Font(text.getDisplay(), fontData);
202:                    text.setFont(font);
203:                }
204:            }
205:
206:            /**
207:             * Sorts the words in page 0, and shows them in page 2.
208:             */
209:            void sortWords() {
210:
211:                String editorText = editor.getDocumentProvider().getDocument(
212:                        editor.getEditorInput()).get();
213:
214:                StringTokenizer tokenizer = new StringTokenizer(editorText,
215:                        " \t\n\r\f!@#$%^&*()-_=+`~[]{};:'\",.<>/?|\\"); //$NON-NLS-1$
216:                ArrayList editorWords = new ArrayList();
217:                while (tokenizer.hasMoreTokens()) {
218:                    editorWords.add(tokenizer.nextToken());
219:                }
220:
221:                Collections.sort(editorWords, Collator.getInstance());
222:                StringWriter displayText = new StringWriter();
223:                for (int i = 0; i < editorWords.size(); i++) {
224:                    displayText.write(((String) editorWords.get(i)));
225:                    displayText.write("\n"); //$NON-NLS-1$
226:                }
227:                text.setText(displayText.toString());
228:            }
229:
230:            /* (non-Javadoc)
231:             * @see org.eclipse.ui.ide.IGotoMarker
232:             */
233:            public void gotoMarker(IMarker marker) {
234:                setActivePage(editorIndex);
235:                IDE.gotoMarker(editor, marker);
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.