Source Code Cross Referenced for TocPage.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » ui » editor » toc » 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.toc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2007 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.toc;
011:
012:        import org.eclipse.jface.text.source.ISourceViewer;
013:        import org.eclipse.jface.viewers.ISelection;
014:        import org.eclipse.jface.viewers.StructuredSelection;
015:        import org.eclipse.pde.core.IModelChangedEvent;
016:        import org.eclipse.pde.core.IModelChangedListener;
017:        import org.eclipse.pde.internal.core.itoc.ITocConstants;
018:        import org.eclipse.pde.internal.core.text.IDocumentAttributeNode;
019:        import org.eclipse.pde.internal.core.text.IDocumentRange;
020:        import org.eclipse.pde.internal.core.text.IDocumentTextNode;
021:        import org.eclipse.pde.internal.core.text.toc.Toc;
022:        import org.eclipse.pde.internal.core.text.toc.TocModel;
023:        import org.eclipse.pde.internal.core.text.toc.TocObject;
024:        import org.eclipse.pde.internal.core.util.PDETextHelper;
025:        import org.eclipse.pde.internal.ui.IHelpContextIds;
026:        import org.eclipse.pde.internal.ui.IPDEUIConstants;
027:        import org.eclipse.pde.internal.ui.PDEPlugin;
028:        import org.eclipse.pde.internal.ui.PDEPluginImages;
029:        import org.eclipse.pde.internal.ui.PDEUIMessages;
030:        import org.eclipse.pde.internal.ui.editor.PDEFormPage;
031:        import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock;
032:        import org.eclipse.swt.custom.StyledText;
033:        import org.eclipse.ui.PlatformUI;
034:        import org.eclipse.ui.forms.IManagedForm;
035:        import org.eclipse.ui.forms.editor.FormEditor;
036:        import org.eclipse.ui.forms.editor.IFormPage;
037:        import org.eclipse.ui.forms.widgets.ScrolledForm;
038:
039:        /**
040:         * TocPage
041:         *
042:         */
043:        public class TocPage extends PDEFormPage implements 
044:                IModelChangedListener {
045:            public static final String PAGE_ID = "tocPage"; //$NON-NLS-1$
046:
047:            private TocBlock fBlock;
048:
049:            /**
050:             * @param editor
051:             */
052:            public TocPage(FormEditor editor) {
053:                super (editor, PAGE_ID, PDEUIMessages.TocPage_title);
054:
055:                fBlock = new TocBlock(this );
056:            }
057:
058:            /**
059:             * @return
060:             */
061:            public PDEMasterDetailsBlock getBlock() {
062:                return fBlock;
063:            }
064:
065:            /* (non-Javadoc)
066:             * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
067:             */
068:            protected void createFormContent(IManagedForm managedForm) {
069:                ScrolledForm form = managedForm.getForm();
070:                TocModel model = (TocModel) getModel();
071:
072:                // Ensure the model was loaded properly
073:                if ((model == null) || (model.isLoaded() == false)) {
074:                    createErrorContent(managedForm, model);
075:                    return;
076:                }
077:
078:                PlatformUI.getWorkbench().getHelpSystem().setHelp(
079:                        form.getBody(), IHelpContextIds.TOC_EDITOR);
080:                // Create the rest of the actions in the form title area
081:                super .createFormContent(managedForm);
082:                // Form image
083:                form.setImage(PDEPlugin.getDefault().getLabelProvider().get(
084:                        PDEPluginImages.DESC_TOC_OBJ));
085:                setFormTitle(form, model);
086:                // Create the master details block
087:                fBlock.createContent(managedForm);
088:                // Force the selection in the masters tree section to load the 
089:                // proper details section
090:                fBlock.getMasterSection().fireSelection();
091:                // Register this page to be informed of model change events
092:                model.addModelChangedListener(this );
093:            }
094:
095:            private void createErrorContent(IManagedForm managedForm,
096:                    TocModel model) {
097:                Exception e = null;
098:                //e = ((AbstractModel)model).getException();
099:
100:                // Create a formatted error page
101:                createFormErrorContent(managedForm,
102:                        PDEUIMessages.TocPage_msgTOCLoadFailure,
103:                        PDEUIMessages.TocPage_msgTOCParsingFailure, e);
104:            }
105:
106:            private void setFormTitle(ScrolledForm form, TocModel model) {
107:                // Form title
108:                String title = PDETextHelper.translateReadText(model.getToc()
109:                        .getFieldLabel());
110:                if (title.length() > 0) {
111:                    form.setText(title);
112:                } else {
113:                    form.setText(PDEUIMessages.TocPage_title);
114:                }
115:            }
116:
117:            /* (non-Javadoc)
118:             * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#dispose()
119:             */
120:            public void dispose() {
121:
122:                TocModel tocModel = (TocModel) getModel();
123:                if (tocModel != null) {
124:                    tocModel.removeModelChangedListener(this );
125:                }
126:                super .dispose();
127:            }
128:
129:            /* (non-Javadoc)
130:             * @see org.eclipse.pde.core.IModelChangedListener#modelChanged(org.eclipse.pde.core.IModelChangedEvent)
131:             */
132:            public void modelChanged(IModelChangedEvent event) {
133:
134:                if (event.getChangeType() == IModelChangedEvent.CHANGE) {
135:                    Object[] objects = event.getChangedObjects();
136:                    TocObject object = (TocObject) objects[0];
137:                    if (object == null) {
138:                        // Ignore
139:                    } else if (object.getType() == ITocConstants.TYPE_TOC) {
140:                        String changeProperty = event.getChangedProperty();
141:                        if ((changeProperty != null)
142:                                && changeProperty
143:                                        .equals(ITocConstants.ATTRIBUTE_LABEL)) {
144:                            // Has to be a String if the property is a title
145:                            // Update the form page title
146:                            getManagedForm().getForm().setText(
147:                                    PDETextHelper
148:                                            .translateReadText((String) event
149:                                                    .getNewValue()));
150:                        }
151:                    }
152:                } else if (event.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
153:                    handleModelEventWorldChanged(event);
154:                }
155:                // Inform the block
156:                fBlock.modelChanged(event);
157:            }
158:
159:            /**
160:             * @return
161:             */
162:            public ISelection getSelection() {
163:                return fBlock.getSelection();
164:            }
165:
166:            /**
167:             * @param event
168:             */
169:            private void handleModelEventWorldChanged(IModelChangedEvent event) {
170:
171:                Object[] objects = event.getChangedObjects();
172:
173:                if (objects[0] != null && objects[0] instanceof  TocObject) {
174:                    TocObject object = (TocObject) objects[0];
175:                    if (object.getType() == ITocConstants.TYPE_TOC) {
176:                        String newValue = ((Toc) object).getFieldLabel();
177:
178:                        // Update page title
179:                        getManagedForm().getForm().setText(
180:                                PDETextHelper.translateReadText(newValue));
181:                    }
182:                }
183:            }
184:
185:            public void setActive(boolean active) {
186:                super .setActive(active);
187:                if (active) {
188:                    IFormPage page = getPDEEditor().findPage(
189:                            TocInputContext.CONTEXT_ID);
190:                    if (page instanceof  TocSourcePage
191:                            && ((TocSourcePage) page).getInputContext()
192:                                    .isInSourceMode()) {
193:                        ISourceViewer viewer = ((TocSourcePage) page)
194:                                .getViewer();
195:                        if (viewer == null) {
196:                            return;
197:                        }
198:
199:                        StyledText text = viewer.getTextWidget();
200:                        if (text == null) {
201:                            return;
202:                        }
203:
204:                        int offset = text.getCaretOffset();
205:                        if (offset < 0) {
206:                            return;
207:                        }
208:
209:                        IDocumentRange range = ((TocSourcePage) page)
210:                                .getRangeElement(offset, true);
211:                        if (range instanceof  IDocumentAttributeNode) {
212:                            range = ((IDocumentAttributeNode) range)
213:                                    .getEnclosingElement();
214:                        } else if (range instanceof  IDocumentTextNode) {
215:                            range = ((IDocumentTextNode) range)
216:                                    .getEnclosingElement();
217:                        }
218:
219:                        if (range instanceof  TocObject) {
220:                            fBlock.getMasterSection().setSelection(
221:                                    new StructuredSelection(range));
222:                        }
223:                    }
224:                }
225:            }
226:
227:            /* (non-Javadoc)
228:             * @see org.eclipse.pde.internal.ui.editor.PDEFormPage#getHelpResource()
229:             */
230:            protected String getHelpResource() {
231:                return IPDEUIConstants.PLUGIN_DOC_ROOT
232:                        + "guide/tools/editors/toc_editor/page_toc.htm"; //$NON-NLS-1$
233:            }
234:        }
ww_w__.__j___ava___2_s__.__c__o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.