View Javadoc

1   package org.eparapher.rcp.editors;
2   
3   import org.eclipse.core.runtime.IPath;
4   import org.eclipse.jface.resource.ImageDescriptor;
5   import org.eclipse.ui.IPathEditorInput;
6   import org.eclipse.ui.IPersistableElement;
7   import org.eparapher.rcp.tools.GUIIcons;
8   
9   
10  public class FileEditorInput implements IPathEditorInput {
11  	
12  	private IPath fPath;
13  	
14  	/**
15  	 * Creates an editor input based of the given file resource.
16  	 *
17  	 * @param path the file
18  	 */
19  	public FileEditorInput(IPath path) {
20  		if (path == null) {
21  			throw new IllegalArgumentException();
22  		}
23  		this.fPath = path;
24  	}
25  	
26  	/*
27  	 * @see java.lang.Object#hashCode()
28  	 */
29  	public int hashCode() {
30  		return fPath.hashCode();
31  	}
32  	
33  	/*
34  	 * @see java.lang.Object#equals(java.lang.Object)
35  	 */
36  	public boolean equals(Object obj) {
37  		if (this == obj)
38  			return true;
39  		if (!(obj instanceof FileEditorInput))
40  			return false;
41  		FileEditorInput other = (FileEditorInput) obj;
42  		return fPath.equals(other.fPath);
43  	}
44  	
45  	/*
46  	 * @see org.eclipse.ui.IEditorInput#exists()
47  	 */
48  	public boolean exists() {
49  		return fPath.toFile().exists();
50  	}
51  	/*
52  	 * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
53  	 */
54  	public ImageDescriptor getImageDescriptor() {
55  		return ImageDescriptor.createFromImage(GUIIcons.FILE_ICON_TXT);
56  	}
57  
58  	/*
59  	 * @see org.eclipse.ui.IEditorInput#getName()
60  	 */
61  	public String getName() {
62  		return fPath.toString();
63  	}
64  	
65  	/*
66  	 * @see org.eclipse.ui.IEditorInput#getToolTipText()
67  	 */
68  	public String getToolTipText() {
69  		return fPath.makeRelative().toOSString();
70  	}
71  	
72  	/*
73  	 * @see org.eclipse.ui.IPathEditorInput#getPath()
74  	 */
75  	public IPath getPath() {
76  		return fPath;
77  	}
78  
79  	public IPersistableElement getPersistable() {
80  		return null;
81  	}
82  
83  	public Object getAdapter(Class adapter) {
84  		return null;
85  	}
86  
87  }