KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > editors > text > NonExistingFileEditorInput


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.editors.text;
12
13 import org.eclipse.core.filesystem.EFS;
14 import org.eclipse.core.filesystem.IFileStore;
15
16 import org.eclipse.core.runtime.Assert;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.core.runtime.Platform;
20
21 import org.eclipse.jface.resource.ImageDescriptor;
22
23
24 import org.eclipse.ui.editors.text.ILocationProvider;
25
26 import org.eclipse.ui.IEditorInput;
27 import org.eclipse.ui.IPersistableElement;
28
29 /**
30  * @since 3.1
31  */

32 public class NonExistingFileEditorInput implements IEditorInput, ILocationProvider {
33
34     private static int fgNonExisting= 0;
35
36     private IFileStore fFileStore;
37     private String JavaDoc fName;
38
39     public NonExistingFileEditorInput(IFileStore fileStore, String JavaDoc namePrefix) {
40         Assert.isNotNull(fileStore);
41         Assert.isTrue(EFS.SCHEME_FILE.equals(fileStore.getFileSystem().getScheme()));
42         fFileStore= fileStore;
43         ++fgNonExisting;
44         fName= namePrefix + " " + fgNonExisting; //$NON-NLS-1$
45
}
46
47     /*
48      * @see org.eclipse.ui.IEditorInput#exists()
49      */

50     public boolean exists() {
51         return false;
52     }
53
54     /*
55      * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
56      */

57     public ImageDescriptor getImageDescriptor() {
58         return null;
59     }
60
61     /*
62      * @see org.eclipse.ui.IEditorInput#getName()
63      */

64     public String JavaDoc getName() {
65         return fName;
66     }
67
68     /*
69      * @see org.eclipse.ui.IEditorInput#getPersistable()
70      */

71     public IPersistableElement getPersistable() {
72         return null;
73     }
74
75     /*
76      * @see org.eclipse.ui.IEditorInput#getToolTipText()
77      */

78     public String JavaDoc getToolTipText() {
79         return fName;
80     }
81
82     /*
83      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
84      */

85     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
86         if (ILocationProvider.class.equals(adapter))
87             return this;
88         return Platform.getAdapterManager().getAdapter(this, adapter);
89     }
90
91     /*
92      * @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object)
93      */

94     public IPath getPath(Object JavaDoc element) {
95         if (element instanceof NonExistingFileEditorInput) {
96             NonExistingFileEditorInput input= (NonExistingFileEditorInput)element;
97             return new Path(input.fFileStore.toURI().getPath());
98         }
99         return null;
100     }
101
102     /*
103      * @see java.lang.Object#equals(java.lang.Object)
104      */

105     public boolean equals(Object JavaDoc o) {
106         if (o == this)
107             return true;
108
109         if (o instanceof NonExistingFileEditorInput) {
110             NonExistingFileEditorInput input = (NonExistingFileEditorInput) o;
111             return fFileStore.equals(input.fFileStore);
112         }
113
114         return false;
115     }
116
117     /*
118      * @see java.lang.Object#hashCode()
119      */

120     public int hashCode() {
121         return fFileStore.hashCode();
122     }
123 }
124
Popular Tags