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


001:        /*******************************************************************************
002:         * Copyright (c) 2006, 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.actions;
011:
012:        import java.io.File;
013:        import java.net.MalformedURLException;
014:        import java.net.URL;
015:
016:        import org.eclipse.core.resources.IFile;
017:        import org.eclipse.core.resources.IResource;
018:        import org.eclipse.core.resources.IWorkspaceRoot;
019:        import org.eclipse.core.runtime.IPath;
020:        import org.eclipse.jface.action.Action;
021:        import org.eclipse.jface.dialogs.MessageDialog;
022:        import org.eclipse.osgi.util.NLS;
023:        import org.eclipse.pde.core.plugin.IPluginExtension;
024:        import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
025:        import org.eclipse.pde.internal.core.PDECore;
026:        import org.eclipse.pde.internal.core.ischema.ISchema;
027:        import org.eclipse.pde.internal.core.ischema.ISchemaDescriptor;
028:        import org.eclipse.pde.internal.core.schema.SchemaDescriptor;
029:        import org.eclipse.pde.internal.core.schema.SchemaRegistry;
030:        import org.eclipse.pde.internal.ui.PDEPlugin;
031:        import org.eclipse.pde.internal.ui.PDEPluginImages;
032:        import org.eclipse.pde.internal.ui.PDEUIMessages;
033:        import org.eclipse.pde.internal.ui.editor.schema.SchemaEditor;
034:
035:        /**
036:         * OpenSchemaAction
037:         *
038:         */
039:        public class OpenSchemaAction extends Action {
040:
041:            private ISchema fSchema;
042:
043:            private String fFullPointID;
044:
045:            /**
046:             * 
047:             */
048:            public OpenSchemaAction() {
049:                fSchema = null;
050:                fFullPointID = null;
051:
052:                initialize();
053:            }
054:
055:            /**
056:             * 
057:             */
058:            private void initialize() {
059:                setImageDescriptor(PDEPluginImages.DESC_SCHEMA_OBJ);
060:                setText(PDEUIMessages.HyperlinkActionOpenSchema);
061:                setToolTipText(PDEUIMessages.HyperlinkActionOpenSchema);
062:                setEnabled(false);
063:            }
064:
065:            /**
066:             * @param schema
067:             */
068:            public void setInput(ISchema schema) {
069:                // Ensure schema is defined
070:                if (schema == null) {
071:                    fFullPointID = PDEUIMessages.OpenSchemaAction_msgUnknown;
072:                    return;
073:                }
074:                fFullPointID = schema.getQualifiedPointId();
075:                fSchema = schema;
076:            }
077:
078:            /**
079:             * @param point
080:             */
081:            public void setInput(IPluginExtensionPoint point) {
082:                // Ensure the point is defined
083:                if (point == null) {
084:                    fSchema = null;
085:                    fFullPointID = PDEUIMessages.OpenSchemaAction_msgUnknown;
086:                    return;
087:                }
088:                fFullPointID = point.getFullId();
089:                // Ensure the point is fully qualified
090:                if (fFullPointID.indexOf('.') == -1) {
091:                    fSchema = null;
092:                    return;
093:                }
094:                // Find the schema
095:                fSchema = findSchema(point);
096:            }
097:
098:            /**
099:             * @param fullPointID
100:             */
101:            public void setInput(String fullPointID) {
102:                // Ensure point ID is defined
103:                if (fullPointID == null) {
104:                    fSchema = null;
105:                    fFullPointID = PDEUIMessages.OpenSchemaAction_msgUnknown;
106:                    return;
107:                }
108:                fFullPointID = fullPointID;
109:                // Find the corresponding extension point
110:                IPluginExtensionPoint point = PDECore.getDefault()
111:                        .getExtensionsRegistry().findExtensionPoint(
112:                                fFullPointID);
113:                // Ensure the extension point is defined
114:                if (point == null) {
115:                    fSchema = null;
116:                    return;
117:                }
118:                // Find the schema
119:                fSchema = findSchema(point);
120:            }
121:
122:            /**
123:             * @param extension
124:             */
125:            public void setInput(IPluginExtension extension) {
126:                // Ensure the extension is defined
127:                if (extension == null) {
128:                    fSchema = null;
129:                    fFullPointID = PDEUIMessages.OpenSchemaAction_msgUnknown;
130:                    return;
131:                }
132:                // Get the full extension point ID
133:                fFullPointID = extension.getPoint();
134:                // Find the corresponding extension point
135:                IPluginExtensionPoint point = PDECore.getDefault()
136:                        .getExtensionsRegistry().findExtensionPoint(
137:                                fFullPointID);
138:                // Ensure the extension point is defined
139:                if (point == null) {
140:                    fSchema = null;
141:                    return;
142:                }
143:                // Find the schema
144:                fSchema = findSchema(point);
145:            }
146:
147:            /**
148:             * @param point
149:             * @return
150:             */
151:            private ISchema findSchema(IPluginExtensionPoint point) {
152:                // Find the corresponding schema URL for the extension point
153:                URL url = SchemaRegistry.getSchemaURL(point);
154:                // Ensure the URL is defined
155:                if (url == null) {
156:                    return null;
157:                }
158:                // Create a schema descriptor
159:                ISchemaDescriptor descriptor = new SchemaDescriptor(
160:                        fFullPointID, url);
161:                // Get the schema
162:                ISchema schema = descriptor.getSchema(false);
163:                // Ensure schema is defined
164:                if (schema == null) {
165:                    return null;
166:                }
167:                return schema;
168:            }
169:
170:            /**
171:             * @param fullPointID
172:             */
173:            private void displayErrorDialog() {
174:                String title = PDEUIMessages.OpenSchemaAction_titleExtensionPointSchema;
175:                String message = NLS.bind(
176:                        PDEUIMessages.OpenSchemaAction_errorMsgSchemaNotFound,
177:                        fFullPointID);
178:                MessageDialog.openWarning(PDEPlugin.getActiveWorkbenchShell(),
179:                        title, message);
180:            }
181:
182:            /* (non-Javadoc)
183:             * @see org.eclipse.jface.action.Action#run()
184:             */
185:            public void run() {
186:                // Ensure the schema is defined
187:                if (fSchema == null) {
188:                    displayErrorDialog();
189:                    return;
190:                }
191:                // Retrieve the schema URL
192:                URL schemaURL = fSchema.getURL();
193:                // Ensure the URL is defined
194:                if (schemaURL == null) {
195:                    displayErrorDialog();
196:                    return;
197:                }
198:                // Get the raw URL, determine if it is stored in a JAR, and handle 
199:                // accordingly
200:                String rawURL = schemaURL.toString();
201:                if (rawURL.startsWith("jar")) { //$NON-NLS-1$
202:                    // Call to getPath removes the 'jar:' qualifier
203:                    openSchemaJar(schemaURL.getPath());
204:                } else {
205:                    openSchemaFile(schemaURL.getPath());
206:                }
207:
208:            }
209:
210:            /**
211:             * @param path
212:             */
213:            private void openSchemaFile(String path) {
214:                // Open the schema in a new editor
215:                try {
216:                    // see if schema URL is actually in workspace.  If so, open it as we would if users opened file directly
217:                    IWorkspaceRoot root = PDEPlugin.getWorkspace().getRoot();
218:                    IPath workspacePath = root.getLocation();
219:                    String workspaceLoc = workspacePath.toFile().toURL()
220:                            .getPath();
221:                    if (path.startsWith(workspaceLoc)) {
222:                        String relativeLocation = path.substring(workspaceLoc
223:                                .length());
224:                        IResource res = root.findMember(relativeLocation);
225:                        if (res != null && res instanceof  IFile
226:                                && res.getProject().isOpen()) {
227:                            SchemaEditor.openSchema((IFile) res);
228:                            return;
229:                        }
230:                    }
231:                } catch (MalformedURLException e) {
232:                }
233:                SchemaEditor.openSchema(new File(path));
234:            }
235:
236:            /**
237:             * @param path
238:             */
239:            private void openSchemaJar(String path) {
240:                // Remove the 'file:' qualifier
241:                if (path.startsWith("file:") == false) { //$NON-NLS-1$
242:                    displayErrorDialog();
243:                    return;
244:                }
245:                path = path.substring(5);
246:                // An exclaimation point separates the jar filename from the
247:                // schema file entry in the jar file
248:                // Get the index of the '!'
249:                int exclPointIndex = path.indexOf('!');
250:                // Ensure there is an '!' and that the schema file entry is defined
251:                // and the jar file name is defined
252:                if ((exclPointIndex <= 0)
253:                        || ((exclPointIndex + 1) >= path.length())) {
254:                    displayErrorDialog();
255:                    return;
256:                }
257:                // Extract the jar file name - not including '!'
258:                String jarFileName = path.substring(0, exclPointIndex);
259:                // Extract the schema entry name - not including the '!' 
260:                String schemaEntryName = path.substring(exclPointIndex + 1);
261:                // If the schema entry starts with a '/', remove it
262:                if (schemaEntryName.startsWith("/")) { //$NON-NLS-1$
263:                    schemaEntryName = schemaEntryName.substring(1);
264:                }
265:                // Open the schema in a new editor
266:                SchemaEditor.openSchema(new File(jarFileName), schemaEntryName);
267:            }
268:
269:        }
w___ww._j___av_a2___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.