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


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 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.search;
011:
012:        import org.eclipse.jface.text.BadLocationException;
013:        import org.eclipse.jface.text.FindReplaceDocumentAdapter;
014:        import org.eclipse.jface.text.IDocument;
015:        import org.eclipse.jface.text.IRegion;
016:        import org.eclipse.jface.text.Region;
017:        import org.eclipse.pde.core.plugin.IFragment;
018:        import org.eclipse.pde.core.plugin.IPlugin;
019:        import org.eclipse.pde.core.plugin.IPluginExtension;
020:        import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
021:        import org.eclipse.pde.core.plugin.IPluginImport;
022:        import org.eclipse.pde.core.plugin.IPluginModelBase;
023:        import org.eclipse.pde.core.plugin.IPluginObject;
024:        import org.eclipse.pde.internal.core.text.plugin.PluginObjectNode;
025:        import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor;
026:        import org.eclipse.search.ui.text.Match;
027:        import org.eclipse.ui.IEditorPart;
028:        import org.eclipse.ui.PartInitException;
029:
030:        public class ManifestEditorOpener {
031:
032:            public static IEditorPart open(Match match, boolean activate)
033:                    throws PartInitException {
034:                IEditorPart editorPart = null;
035:                editorPart = ManifestEditor.open(match.getElement(), true);
036:                if (editorPart != null && editorPart instanceof  ManifestEditor) {
037:                    ManifestEditor editor = (ManifestEditor) editorPart;
038:                    IDocument doc = editor.getDocument(match);
039:                    if (doc != null) {
040:                        Match exact = findExactMatch(doc, match, editor);
041:                        editor.openToSourcePage(match.getElement(), exact
042:                                .getOffset(), exact.getLength());
043:                    }
044:                }
045:                return editorPart;
046:            }
047:
048:            public static Match findExactMatch(IDocument document, Match match,
049:                    IEditorPart editor) {
050:                if (match.getOffset() == -1
051:                        && match.getBaseUnit() == Match.UNIT_LINE)
052:                    return new Match(match.getElement(), Match.UNIT_CHARACTER,
053:                            0, 0);
054:                IPluginObject element = (IPluginObject) match.getElement();
055:                String name = null;
056:                String value = null;
057:                IRegion region = null;
058:                // since Extenion and Extension point matches don't contain line #'s, we need handle them differently (by trying to find matches in UI model)
059:                if (editor instanceof  ManifestEditor
060:                        && (element instanceof  IPluginExtension || element instanceof  IPluginExtensionPoint)) {
061:                    region = getAttributeMatch((ManifestEditor) editor,
062:                            element, document);
063:                } else {
064:                    if (element instanceof  IPluginImport) {
065:                        name = "plugin"; //$NON-NLS-1$
066:                        value = ((IPluginImport) element).getId();
067:                    } else if (element instanceof  IPlugin) {
068:                        name = "id"; //$NON-NLS-1$
069:                        value = ((IPlugin) element).getId();
070:                    } else if (element instanceof  IFragment) {
071:                        name = "id"; //$NON-NLS-1$
072:                        value = ((IFragment) element).getId();
073:                    }
074:
075:                    region = getAttributeRegionForLine(document, name, value,
076:                            match.getOffset());
077:                }
078:                if (region != null) {
079:                    return new Match(element, Match.UNIT_CHARACTER, region
080:                            .getOffset(), region.getLength());
081:                }
082:                return match;
083:            }
084:
085:            private static IRegion getAttributeRegionForLine(
086:                    IDocument document, String name, String value, int line) {
087:                try {
088:                    int offset = document.getLineOffset(line)
089:                            + document.getLineLength(line);
090:                    return getAttributeRegion(document, name, value, offset);
091:                } catch (BadLocationException e) {
092:                }
093:                return null;
094:            }
095:
096:            private static IRegion getAttributeRegion(IDocument document,
097:                    String name, String value, int offset) {
098:                try {
099:                    FindReplaceDocumentAdapter findReplaceAdapter = new FindReplaceDocumentAdapter(
100:                            document);
101:                    IRegion nameRegion = findReplaceAdapter.find(offset, name
102:                            + "\\s*=\\s*\"" + value, false, false, false, true); //$NON-NLS-1$
103:                    if (nameRegion != null) {
104:                        if (document.get(
105:                                nameRegion.getOffset() + nameRegion.getLength()
106:                                        - value.length(), value.length())
107:                                .equals(value))
108:                            return new Region(nameRegion.getOffset()
109:                                    + nameRegion.getLength() - value.length(),
110:                                    value.length());
111:                    }
112:                } catch (BadLocationException e) {
113:                }
114:                return null;
115:            }
116:
117:            // Try to find a match for an Extension or Extension point by looking through the extensions/extension points in UI model for match.
118:            private static IRegion getAttributeMatch(ManifestEditor editor,
119:                    IPluginObject object, IDocument document) {
120:                IPluginObject[] elements = null;
121:                // find equivalent models in UI text model
122:                if (object instanceof  IPluginExtension)
123:                    elements = ((IPluginModelBase) editor.getAggregateModel())
124:                            .getPluginBase().getExtensions();
125:                else
126:                    elements = ((IPluginModelBase) editor.getAggregateModel())
127:                            .getPluginBase().getExtensionPoints();
128:
129:                // iterate through the UI text models to find a match for a Search object.
130:                for (int i = 0; i < elements.length; i++) {
131:                    if (object.equals(elements[i])) {
132:                        int offset = ((PluginObjectNode) elements[i])
133:                                .getOffset();
134:                        offset += ((PluginObjectNode) elements[i]).getLength();
135:                        String name = (object instanceof  IPluginExtension) ? "point" : "id"; //$NON-NLS-1$ //$NON-NLS-2$
136:                        String value = (object instanceof  IPluginExtension) ? ((IPluginExtension) object)
137:                                .getPoint()
138:                                : ((IPluginExtensionPoint) object).getId();
139:                        return getAttributeRegion(document, name, value, offset);
140:                    }
141:                }
142:                return null;
143:            }
144:
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.