Source Code Cross Referenced for ExternalEditor.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » misc » 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 workbench » org.eclipse.ui.internal.misc 
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.internal.misc;
011:
012:        import java.io.File;
013:        import java.io.IOException;
014:        import java.net.URL;
015:
016:        import org.eclipse.core.runtime.CoreException;
017:        import org.eclipse.core.runtime.IConfigurationElement;
018:        import org.eclipse.core.runtime.IPath;
019:        import org.eclipse.core.runtime.IStatus;
020:        import org.eclipse.core.runtime.Platform;
021:        import org.eclipse.core.runtime.Status;
022:        import org.eclipse.osgi.util.NLS;
023:        import org.eclipse.swt.program.Program;
024:        import org.eclipse.ui.internal.WorkbenchMessages;
025:        import org.eclipse.ui.internal.WorkbenchPlugin;
026:        import org.eclipse.ui.internal.registry.EditorDescriptor;
027:        import org.osgi.framework.Bundle;
028:
029:        public class ExternalEditor {
030:            private IPath filePath;
031:
032:            private EditorDescriptor descriptor;
033:
034:            /**
035:             * Create an external editor.
036:             */
037:            public ExternalEditor(IPath newFilePath,
038:                    EditorDescriptor editorDescriptor) {
039:                this .filePath = newFilePath;
040:                this .descriptor = editorDescriptor;
041:            }
042:
043:            /**
044:             * open the editor. If the descriptor has a program then use it - otherwise build its
045:             * info from the descriptor.
046:             * @exception	Throws a CoreException if the external editor could not be opened.
047:             */
048:            public void open() throws CoreException {
049:
050:                Program program = this .descriptor.getProgram();
051:                if (program == null) {
052:                    openWithUserDefinedProgram();
053:                } else {
054:                    String path = ""; //$NON-NLS-1$
055:                    if (filePath != null) {
056:                        path = filePath.toOSString();
057:                        if (program.execute(path)) {
058:                            return;
059:                        }
060:                    }
061:                    throw new CoreException(
062:                            new Status(
063:                                    IStatus.ERROR,
064:                                    WorkbenchPlugin.PI_WORKBENCH,
065:                                    0,
066:                                    NLS
067:                                            .bind(
068:                                                    WorkbenchMessages.ExternalEditor_errorMessage,
069:                                                    path), null));
070:                }
071:            }
072:
073:            /**
074:             * open the editor.
075:             * @exception	Throws a CoreException if the external editor could not be opened.
076:             */
077:            public void openWithUserDefinedProgram() throws CoreException {
078:                // We need to determine if the command refers to a program in the plugin
079:                // install directory. Otherwise we assume the program is on the path.
080:
081:                String programFileName = null;
082:                IConfigurationElement configurationElement = descriptor
083:                        .getConfigurationElement();
084:
085:                // Check if we have a config element (if we don't it is an
086:                // external editor created on the resource associations page).
087:                if (configurationElement != null) {
088:                    try {
089:                        Bundle bundle = Platform.getBundle(configurationElement
090:                                .getNamespace());
091:                        // See if the program file is in the plugin directory
092:                        URL entry = bundle.getEntry(descriptor.getFileName());
093:                        if (entry != null) {
094:                            // this will bring the file local if the plugin is on a server
095:                            URL localName = Platform.asLocalURL(entry);
096:                            File file = new File(localName.getFile());
097:                            //Check that it exists before we assert it is valid
098:                            if (file.exists()) {
099:                                programFileName = file.getAbsolutePath();
100:                            }
101:                        }
102:                    } catch (IOException e) {
103:                        // Program file is not in the plugin directory
104:                    }
105:                }
106:
107:                if (programFileName == null) {
108:                    // Program file is not in the plugin directory therefore
109:                    // assume it is on the path
110:                    programFileName = descriptor.getFileName();
111:                }
112:
113:                // Get the full path of the file to open
114:                if (filePath == null) {
115:                    throw new CoreException(
116:                            new Status(
117:                                    IStatus.ERROR,
118:                                    WorkbenchPlugin.PI_WORKBENCH,
119:                                    0,
120:                                    NLS
121:                                            .bind(
122:                                                    WorkbenchMessages.ExternalEditor_errorMessage,
123:                                                    programFileName), null));
124:                }
125:                String path = filePath.toOSString();
126:
127:                // Open the file
128:
129:                // ShellCommand was removed in response to PR 23888.  If an exception was 
130:                // thrown, it was not caught in time, and no feedback was given to user
131:
132:                try {
133:                    Runtime.getRuntime().exec(
134:                            new String[] { programFileName, path });
135:                } catch (Exception e) {
136:                    throw new CoreException(
137:                            new Status(
138:                                    IStatus.ERROR,
139:                                    WorkbenchPlugin.PI_WORKBENCH,
140:                                    0,
141:                                    NLS
142:                                            .bind(
143:                                                    WorkbenchMessages.ExternalEditor_errorMessage,
144:                                                    programFileName), e));
145:                }
146:            }
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.