KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > io > FileEditorInput


1 /**
2  * <p> Project: com.nightlabs.base </p>
3  * <p> Copyright: Copyright (c) 2005 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 20.06.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.rcp.io;
9
10 import java.io.File JavaDoc;
11 import java.io.IOException JavaDoc;
12
13 import org.eclipse.core.runtime.IPath;
14 import org.eclipse.core.runtime.Path;
15 import org.eclipse.jface.resource.ImageDescriptor;
16 import org.eclipse.ui.IEditorInput;
17 import org.eclipse.ui.IPathEditorInput;
18 import org.eclipse.ui.IPersistableElement;
19
20 public class FileEditorInput
21 implements IEditorInput,
22                      IPathEditorInput
23 {
24     protected File JavaDoc file;
25     
26     public FileEditorInput(File JavaDoc f)
27     {
28         if (f == null)
29             throw new IllegalArgumentException JavaDoc("Param f must not be null!");
30         
31         this.file = f;
32     }
33     
34     public boolean exists()
35     {
36         return file.exists();
37     }
38
39     public File JavaDoc getFile() {
40         return file;
41     }
42     
43   public String JavaDoc getName()
44   {
45         return file.getName();
46   }
47   
48     public ImageDescriptor getImageDescriptor()
49     {
50         // TODO Auto-generated method stub
51
return null;
52     }
53
54     public IPersistableElement getPersistable()
55     {
56         // TODO Auto-generated method stub
57
return null;
58     }
59
60     public String JavaDoc getToolTipText()
61     {
62         return file.getAbsolutePath();
63     }
64
65     public Object JavaDoc getAdapter(Class JavaDoc adapter)
66     {
67         // TODO Auto-generated method stub
68
return null;
69     }
70     
71     public IPath getPath()
72     {
73         try {
74             String JavaDoc path = file.getCanonicalPath();
75             return new Path(path);
76         } catch (IOException JavaDoc e) {
77             // TODO Auto-generated catch block
78
e.printStackTrace();
79         }
80         return null;
81     }
82     
83     public int hashCode()
84     {
85         return file.hashCode();
86     }
87     
88     public boolean equals(Object JavaDoc o)
89     {
90         if (o == this)
91             return true;
92         
93         if (o instanceof FileEditorInput) {
94             FileEditorInput input = (FileEditorInput) o;
95             return file.equals(input.getFile());
96         }
97         
98         return false;
99     }
100         
101     protected boolean saved = true;
102     public boolean isSaved()
103     {
104         if (!exists())
105             return false;
106         
107         return saved;
108     }
109     public void setSaved(boolean saved) {
110         this.saved = saved;
111     }
112 }
113
Popular Tags