KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > ide > FileStoreEditorInput


1 /*******************************************************************************
2  * Copyright (c) 2007 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.ide;
12
13 import java.net.URI JavaDoc;
14
15 import org.eclipse.core.filesystem.IFileStore;
16 import org.eclipse.core.runtime.Assert;
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.ui.IMemento;
20 import org.eclipse.ui.IPersistableElement;
21 import org.eclipse.ui.IURIEditorInput;
22 import org.eclipse.ui.model.IWorkbenchAdapter;
23
24 /**
25  * Implements an IEditorInput instance appropriate for
26  * <code>IFileStore</code> elements that represent files
27  * that are not part of the current workspace.
28  *
29  * @since 3.3
30  *
31  */

32 public class FileStoreEditorInput implements IURIEditorInput, IPersistableElement {
33
34     /**
35      * The workbench adapter which simply provides the label.
36      *
37      * @since 3.3
38      */

39     private static class WorkbenchAdapter implements IWorkbenchAdapter {
40         /*
41          * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
42          */

43         public Object JavaDoc[] getChildren(Object JavaDoc o) {
44             return null;
45         }
46
47         /*
48          * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
49          */

50         public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
51             return null;
52         }
53
54         /*
55          * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
56          */

57         public String JavaDoc getLabel(Object JavaDoc o) {
58             return ((FileStoreEditorInput) o).getName();
59         }
60
61         /*
62          * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
63          */

64         public Object JavaDoc getParent(Object JavaDoc o) {
65             return null;
66         }
67     }
68
69     private IFileStore fileStore;
70     private WorkbenchAdapter workbenchAdapter = new WorkbenchAdapter();
71
72     /**
73      * @param fileStore
74      */

75     public FileStoreEditorInput(IFileStore fileStore) {
76         Assert.isNotNull(fileStore);
77         this.fileStore = fileStore;
78         workbenchAdapter = new WorkbenchAdapter();
79     }
80
81     /*
82      * @see org.eclipse.ui.IEditorInput#exists()
83      */

84     public boolean exists() {
85         return fileStore.fetchInfo().exists();
86     }
87
88     /*
89      * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
90      */

91     public ImageDescriptor getImageDescriptor() {
92         return null;
93     }
94
95     /*
96      * @see org.eclipse.ui.IEditorInput#getName()
97      */

98     public String JavaDoc getName() {
99         return fileStore.getName();
100     }
101
102     /*
103      * @see org.eclipse.ui.IEditorInput#getPersistable()
104      */

105     public IPersistableElement getPersistable() {
106         return this;
107     }
108
109     /*
110      * @see org.eclipse.ui.IEditorInput#getToolTipText()
111      */

112     public String JavaDoc getToolTipText() {
113         return fileStore.toString();
114     }
115
116     /*
117      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
118      */

119     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
120         if (IWorkbenchAdapter.class.equals(adapter))
121             return workbenchAdapter;
122         return Platform.getAdapterManager().getAdapter(this, adapter);
123     }
124
125     /*
126      * @see java.lang.Object#equals(java.lang.Object)
127      */

128     public boolean equals(Object JavaDoc o) {
129         if (o == this)
130             return true;
131
132         if (o instanceof FileStoreEditorInput) {
133             FileStoreEditorInput input = (FileStoreEditorInput) o;
134             return fileStore.equals(input.fileStore);
135         }
136
137         return false;
138     }
139
140     /*
141      * @see java.lang.Object#hashCode()
142      */

143     public int hashCode() {
144         return fileStore.hashCode();
145     }
146
147     /* (non-Javadoc)
148      * @see org.eclipse.ui.IURIEditorInput#getURI()
149      */

150     public URI JavaDoc getURI() {
151         return fileStore.toURI();
152     }
153
154     /*
155      * (non-Javadoc)
156      * @see org.eclipse.ui.IPersistableElement#getFactoryId()
157      */

158     public String JavaDoc getFactoryId() {
159         return FileStoreEditorInputFactory.ID;
160     }
161
162     /* (non-Javadoc)
163      * @see org.eclipse.ui.IPersistable#saveState(org.eclipse.ui.IMemento)
164      */

165     public void saveState(IMemento memento) {
166         FileStoreEditorInputFactory.saveState(memento, this);
167         
168     }
169
170 }
171
Popular Tags