Source Code Cross Referenced for ReadmeModelFactory.java in  » IDE-Eclipse » ui-examples » org » eclipse » ui » examples » readmetool » 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.readmetool 
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:         *     Joe Bowbeer (jozart@blarg.net) - removed dependency on runtime compatibility layer (bug 74526)
011:         *******************************************************************************/package org.eclipse.ui.examples.readmetool;
012:
013:        import org.eclipse.core.resources.IFile;
014:        import org.eclipse.core.runtime.CoreException;
015:        import org.eclipse.core.runtime.IAdaptable;
016:        import org.eclipse.core.runtime.IConfigurationElement;
017:        import org.eclipse.core.runtime.IExtension;
018:        import org.eclipse.core.runtime.IExtensionPoint;
019:        import org.eclipse.core.runtime.Platform;
020:        import org.eclipse.jface.viewers.ISelection;
021:        import org.eclipse.jface.viewers.IStructuredSelection;
022:
023:        /**
024:         * Creates the sections used in the <code>ContentOutline</code>
025:         *
026:         * @see ReadmeContentOutlinePage#getContentOutline(IAdaptable)
027:         */
028:        public class ReadmeModelFactory {
029:            private static ReadmeModelFactory instance = new ReadmeModelFactory();
030:
031:            private boolean registryLoaded = false;
032:
033:            IReadmeFileParser parser = null;
034:
035:            /**
036:             * Creates a new ReadmeModelFactory.
037:             */
038:            private ReadmeModelFactory() {
039:                // do nothing
040:            }
041:
042:            /**
043:             * Adds all mark elements to the list for the subtree rooted
044:             * at the given mark element.
045:             */
046:            protected void addSections(AdaptableList list, MarkElement element) {
047:                list.add(element);
048:                Object[] children = element.getChildren(element);
049:                for (int i = 0; i < children.length; ++i) {
050:                    addSections(list, (MarkElement) children[i]);
051:                }
052:            }
053:
054:            /**
055:             * Returns the content outline for the given Readme file.
056:             *
057:             * @param adaptable  the element for which to return the content outline
058:             * @return the content outline for the argument
059:             */
060:            public AdaptableList getContentOutline(IAdaptable adaptable) {
061:                return new AdaptableList(getToc((IFile) adaptable));
062:            }
063:
064:            /**
065:             * Returns the singleton readme adapter.
066:             */
067:            public static ReadmeModelFactory getInstance() {
068:                return instance;
069:            }
070:
071:            /**
072:             * Returns a list of all sections in this readme file.
073:             *
074:             * @param file  the file for which to return section heading and subheadings
075:             * @return A list containing headings and subheadings
076:             */
077:            public AdaptableList getSections(IFile file) {
078:                MarkElement[] topLevel = getToc(file);
079:                AdaptableList list = new AdaptableList();
080:                for (int i = 0; i < topLevel.length; i++) {
081:                    addSections(list, topLevel[i]);
082:                }
083:                return list;
084:            }
085:
086:            /**
087:             * Convenience method.  Looks for a readme file in the selection,
088:             * and if one is found, returns the sections for it.  Returns null
089:             * if there is no readme file in the selection.
090:             */
091:            public AdaptableList getSections(ISelection sel) {
092:                // If sel is not a structured selection just return.
093:                if (!(sel instanceof  IStructuredSelection))
094:                    return null;
095:                IStructuredSelection structured = (IStructuredSelection) sel;
096:
097:                //if the selection is a readme file, get its sections.
098:                Object object = structured.getFirstElement();
099:                if (object instanceof  IFile) {
100:                    IFile file = (IFile) object;
101:                    String extension = file.getFileExtension();
102:                    if (extension != null
103:                            && extension.equals(IReadmeConstants.EXTENSION)) {
104:                        return getSections(file);
105:                    }
106:                }
107:
108:                //the selected object is not a readme file
109:                return null;
110:            }
111:
112:            /**
113:             * Parses the contents of the Readme file by looking for lines 
114:             * that start with a number.
115:             *
116:             * @param file  the file representing the Readme file
117:             * @return an element collection representing the table of contents
118:             */
119:            private MarkElement[] getToc(IFile file) {
120:                if (registryLoaded == false)
121:                    loadParser();
122:                return parser.parse(file);
123:            }
124:
125:            /**
126:             * Loads the parser from the registry by searching for
127:             * extensions that satisfy our published extension point.
128:             * For the sake of simplicity, we will pick the last extension,
129:             * allowing tools to override what is used. In a more
130:             * elaborate tool, all the extensions would be processed.
131:             */
132:            private void loadParser() {
133:                IExtensionPoint point = Platform.getExtensionRegistry()
134:                        .getExtensionPoint(IReadmeConstants.PLUGIN_ID,
135:                                IReadmeConstants.PP_SECTION_PARSER);
136:                if (point != null) {
137:                    IExtension[] extensions = point.getExtensions();
138:                    for (int i = 0; i < extensions.length; i++) {
139:                        IExtension currentExtension = extensions[i];
140:                        // in a real application, we would collection
141:                        // the entire list and probably expose it
142:                        // as a drop-down list. For the sake
143:                        // of simplicity, we will pick the last extension only.
144:                        if (i == extensions.length - 1) {
145:                            IConfigurationElement[] configElements = currentExtension
146:                                    .getConfigurationElements();
147:                            for (int j = 0; j < configElements.length; j++) {
148:                                IConfigurationElement config = configElements[i];
149:                                if (config.getName().equals(
150:                                        IReadmeConstants.TAG_PARSER)) {
151:                                    // process the first 'parser' element and stop
152:                                    processParserElement(config);
153:                                    break;
154:                                }
155:                            }
156:                        }
157:                    }
158:                }
159:                if (parser == null)
160:                    parser = new DefaultSectionsParser();
161:                registryLoaded = true;
162:            }
163:
164:            /**
165:             * Tries to create the Readme file parser. If an error occurs during
166:             * the creation of the parser, print an error and set the parser
167:             * to null.
168:             *
169:             * @param element  the element to process
170:             */
171:            private void processParserElement(IConfigurationElement element) {
172:                try {
173:                    parser = (IReadmeFileParser) element
174:                            .createExecutableExtension(IReadmeConstants.ATT_CLASS);
175:                } catch (CoreException e) {
176:                    // since this is an example just write to the console
177:                    System.out
178:                            .println(MessageUtil
179:                                    .getString("Unable_to_create_file_parser") + e.getStatus().getMessage()); //$NON-NLS-1$
180:                    parser = null;
181:                }
182:            }
183:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.