1 11 package org.eclipse.ui.ide; 12 13 import java.net.URI ; 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 32 public class FileStoreEditorInput implements IURIEditorInput, IPersistableElement { 33 34 39 private static class WorkbenchAdapter implements IWorkbenchAdapter { 40 43 public Object [] getChildren(Object o) { 44 return null; 45 } 46 47 50 public ImageDescriptor getImageDescriptor(Object object) { 51 return null; 52 } 53 54 57 public String getLabel(Object o) { 58 return ((FileStoreEditorInput) o).getName(); 59 } 60 61 64 public Object getParent(Object o) { 65 return null; 66 } 67 } 68 69 private IFileStore fileStore; 70 private WorkbenchAdapter workbenchAdapter = new WorkbenchAdapter(); 71 72 75 public FileStoreEditorInput(IFileStore fileStore) { 76 Assert.isNotNull(fileStore); 77 this.fileStore = fileStore; 78 workbenchAdapter = new WorkbenchAdapter(); 79 } 80 81 84 public boolean exists() { 85 return fileStore.fetchInfo().exists(); 86 } 87 88 91 public ImageDescriptor getImageDescriptor() { 92 return null; 93 } 94 95 98 public String getName() { 99 return fileStore.getName(); 100 } 101 102 105 public IPersistableElement getPersistable() { 106 return this; 107 } 108 109 112 public String getToolTipText() { 113 return fileStore.toString(); 114 } 115 116 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 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 143 public int hashCode() { 144 return fileStore.hashCode(); 145 } 146 147 150 public URI getURI() { 151 return fileStore.toURI(); 152 } 153 154 158 public String getFactoryId() { 159 return FileStoreEditorInputFactory.ID; 160 } 161 162 165 public void saveState(IMemento memento) { 166 FileStoreEditorInputFactory.saveState(memento, this); 167 168 } 169 170 } 171 | Popular Tags |