Source Code Cross Referenced for FileEditorInput.java in  » IDE-Eclipse » ui-ide » org » eclipse » ui » part » 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 ide » org.eclipse.ui.part 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 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.ui.part;
011:
012:        import java.net.URI;
013:
014:        import org.eclipse.core.filesystem.EFS;
015:        import org.eclipse.core.filesystem.IFileStore;
016:        import org.eclipse.core.resources.IFile;
017:        import org.eclipse.core.resources.IStorage;
018:        import org.eclipse.core.runtime.CoreException;
019:        import org.eclipse.core.runtime.IPath;
020:        import org.eclipse.core.runtime.Path;
021:        import org.eclipse.core.runtime.content.IContentType;
022:        import org.eclipse.jface.resource.ImageDescriptor;
023:        import org.eclipse.ui.IFileEditorInput;
024:        import org.eclipse.ui.IMemento;
025:        import org.eclipse.ui.IPathEditorInput;
026:        import org.eclipse.ui.IPersistableElement;
027:        import org.eclipse.ui.IURIEditorInput;
028:        import org.eclipse.ui.PlatformUI;
029:        import org.eclipse.ui.ide.IDE;
030:        import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
031:
032:        /**
033:         * Adapter for making a file resource a suitable input for an editor.
034:         * <p>
035:         * This class may be instantiated; it is not intended to be subclassed.
036:         * </p>
037:         */
038:        public class FileEditorInput implements  IFileEditorInput,
039:                IPathEditorInput, IURIEditorInput, IPersistableElement {
040:            private IFile file;
041:
042:            /**
043:             * Return whether or not file is local. Only {@link IFile}s with a local
044:             * value should call {@link IPathEditorInput#getPath()}
045:             * @param file
046:             * @return boolean <code>true</code> if the file has a local implementation.
047:             */
048:            public static boolean isLocalFile(IFile file) {
049:
050:                IPath location = file.getLocation();
051:                if (location != null)
052:                    return true;
053:                //this is not a local file, so try to obtain a local file
054:                try {
055:                    final URI locationURI = file.getLocationURI();
056:                    if (locationURI == null)
057:                        return false;
058:                    IFileStore store = EFS.getStore(locationURI);
059:                    //first try to obtain a local file directly fo1r this store
060:                    java.io.File localFile = store.toLocalFile(EFS.NONE, null);
061:                    //if no local file is available, obtain a cached file
062:                    if (localFile == null)
063:                        localFile = store.toLocalFile(EFS.CACHE, null);
064:                    if (localFile == null)
065:                        return false;
066:                    return true;
067:                } catch (CoreException e) {
068:                    //this can only happen if the file system is not available for this scheme
069:                    IDEWorkbenchPlugin.log(
070:                            "Failed to obtain file store for resource", e); //$NON-NLS-1$
071:                    return false;
072:                }
073:
074:            }
075:
076:            /**
077:             * Creates an editor input based of the given file resource.
078:             *
079:             * @param file the file resource
080:             */
081:            public FileEditorInput(IFile file) {
082:                if (file == null)
083:                    throw new IllegalArgumentException();
084:                this .file = file;
085:
086:            }
087:
088:            /* (non-Javadoc)
089:             * Method declared on Object.
090:             */
091:            public int hashCode() {
092:                return file.hashCode();
093:            }
094:
095:            /* (non-Javadoc)
096:             * Method declared on Object.
097:             *
098:             * The <code>FileEditorInput</code> implementation of this <code>Object</code>
099:             * method bases the equality of two <code>FileEditorInput</code> objects on the
100:             * equality of their underlying <code>IFile</code> resources.
101:             */
102:            public boolean equals(Object obj) {
103:                if (this  == obj) {
104:                    return true;
105:                }
106:                if (!(obj instanceof  IFileEditorInput)) {
107:                    return false;
108:                }
109:                IFileEditorInput other = (IFileEditorInput) obj;
110:                return file.equals(other.getFile());
111:            }
112:
113:            /* (non-Javadoc)
114:             * Method declared on IEditorInput.
115:             */
116:            public boolean exists() {
117:                return file.exists();
118:            }
119:
120:            /* (non-Javadoc)
121:             * Method declared on IAdaptable.
122:             */
123:            public Object getAdapter(Class adapter) {
124:                if (adapter == IFile.class) {
125:                    return file;
126:                }
127:                return file.getAdapter(adapter);
128:            }
129:
130:            /* (non-Javadoc)
131:             * Method declared on IPersistableElement.
132:             */
133:            public String getFactoryId() {
134:                return FileEditorInputFactory.getFactoryId();
135:            }
136:
137:            /* (non-Javadoc)
138:             * Method declared on IFileEditorInput.
139:             */
140:            public IFile getFile() {
141:                return file;
142:            }
143:
144:            /* (non-Javadoc)
145:             * Method declared on IEditorInput.
146:             */
147:            public ImageDescriptor getImageDescriptor() {
148:                IContentType contentType = IDE.getContentType(file);
149:                return PlatformUI.getWorkbench().getEditorRegistry()
150:                        .getImageDescriptor(file.getName(), contentType);
151:            }
152:
153:            /* (non-Javadoc)
154:             * Method declared on IEditorInput.
155:             */
156:            public String getName() {
157:                return file.getName();
158:            }
159:
160:            /* (non-Javadoc)
161:             * Method declared on IEditorInput.
162:             */
163:            public IPersistableElement getPersistable() {
164:                return this ;
165:            }
166:
167:            /* (non-Javadoc)
168:             * Method declared on IStorageEditorInput.
169:             */
170:            public IStorage getStorage() {
171:                return file;
172:            }
173:
174:            /* (non-Javadoc)
175:             * Method declared on IEditorInput.
176:             */
177:            public String getToolTipText() {
178:                return file.getFullPath().makeRelative().toString();
179:            }
180:
181:            /* (non-Javadoc)
182:             * Method declared on IPersistableElement.
183:             */
184:            public void saveState(IMemento memento) {
185:                FileEditorInputFactory.saveState(memento, this );
186:            }
187:
188:            /* (non-Javadoc)
189:             * @see org.eclipse.ui.IURIEditorInput#getURI()
190:             */
191:            public URI getURI() {
192:                return file.getLocationURI();
193:            }
194:
195:            /* (non-Javadoc)
196:             * @see org.eclipse.ui.IPathEditorInput#getPath()
197:             */
198:            public IPath getPath() {
199:                IPath location = file.getLocation();
200:                if (location != null)
201:                    return location;
202:                //this is not a local file, so try to obtain a local file
203:                try {
204:                    final URI locationURI = file.getLocationURI();
205:                    if (locationURI == null)
206:                        throw new IllegalArgumentException();
207:                    IFileStore store = EFS.getStore(locationURI);
208:                    //first try to obtain a local file directly fo1r this store
209:                    java.io.File localFile = store.toLocalFile(EFS.NONE, null);
210:                    //if no local file is available, obtain a cached file
211:                    if (localFile == null)
212:                        localFile = store.toLocalFile(EFS.CACHE, null);
213:                    if (localFile == null)
214:                        throw new IllegalArgumentException();
215:                    return Path.fromOSString(localFile.getAbsolutePath());
216:                } catch (CoreException e) {
217:                    //this can only happen if the file system is not available for this scheme
218:                    IDEWorkbenchPlugin.log(
219:                            "Failed to obtain file store for resource", e); //$NON-NLS-1$
220:                    throw new RuntimeException(e);
221:                }
222:            }
223:
224:            /* (non-Javadoc)
225:             * @see java.lang.Object#toString()
226:             */
227:            public String toString() {
228:                return getClass().getName()
229:                        + "(" + getFile().getFullPath() + ")"; //$NON-NLS-1$ //$NON-NLS-2$
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.