001: /*******************************************************************************
002: * Copyright (c) 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.ide;
011:
012: import java.net.URI;
013:
014: import org.eclipse.core.filesystem.IFileStore;
015: import org.eclipse.core.runtime.Assert;
016: import org.eclipse.core.runtime.Platform;
017: import org.eclipse.jface.resource.ImageDescriptor;
018: import org.eclipse.ui.IMemento;
019: import org.eclipse.ui.IPersistableElement;
020: import org.eclipse.ui.IURIEditorInput;
021: import org.eclipse.ui.model.IWorkbenchAdapter;
022:
023: /**
024: * Implements an IEditorInput instance appropriate for
025: * <code>IFileStore</code> elements that represent files
026: * that are not part of the current workspace.
027: *
028: * @since 3.3
029: *
030: */
031: public class FileStoreEditorInput implements IURIEditorInput,
032: IPersistableElement {
033:
034: /**
035: * The workbench adapter which simply provides the label.
036: *
037: * @since 3.3
038: */
039: private static class WorkbenchAdapter implements IWorkbenchAdapter {
040: /*
041: * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object)
042: */
043: public Object[] getChildren(Object o) {
044: return null;
045: }
046:
047: /*
048: * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object)
049: */
050: public ImageDescriptor getImageDescriptor(Object object) {
051: return null;
052: }
053:
054: /*
055: * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object)
056: */
057: public String getLabel(Object o) {
058: return ((FileStoreEditorInput) o).getName();
059: }
060:
061: /*
062: * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object)
063: */
064: public Object getParent(Object o) {
065: return null;
066: }
067: }
068:
069: private IFileStore fileStore;
070: private WorkbenchAdapter workbenchAdapter = new WorkbenchAdapter();
071:
072: /**
073: * @param fileStore
074: */
075: public FileStoreEditorInput(IFileStore fileStore) {
076: Assert.isNotNull(fileStore);
077: this .fileStore = fileStore;
078: workbenchAdapter = new WorkbenchAdapter();
079: }
080:
081: /*
082: * @see org.eclipse.ui.IEditorInput#exists()
083: */
084: public boolean exists() {
085: return fileStore.fetchInfo().exists();
086: }
087:
088: /*
089: * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
090: */
091: public ImageDescriptor getImageDescriptor() {
092: return null;
093: }
094:
095: /*
096: * @see org.eclipse.ui.IEditorInput#getName()
097: */
098: public String getName() {
099: 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 getToolTipText() {
113: return fileStore.toString();
114: }
115:
116: /*
117: * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
118: */
119: public Object getAdapter(Class 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 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 getURI() {
151: return fileStore.toURI();
152: }
153:
154: /*
155: * (non-Javadoc)
156: * @see org.eclipse.ui.IPersistableElement#getFactoryId()
157: */
158: public String 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: }
|