1 11 package org.eclipse.team.internal.ccvs.ui; 12 13 14 import org.eclipse.core.resources.IStorage; 15 import org.eclipse.core.runtime.*; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.team.core.TeamException; 19 import org.eclipse.team.core.history.IFileRevision; 20 import org.eclipse.team.core.variants.IResourceVariant; 21 import org.eclipse.team.internal.ccvs.core.*; 22 import org.eclipse.team.internal.ccvs.core.filehistory.CVSResourceVariantFileRevision; 23 import org.eclipse.team.ui.history.IHistoryPageSource; 24 import org.eclipse.ui.IPersistableElement; 25 import org.eclipse.ui.IStorageEditorInput; 26 import org.eclipse.ui.model.IWorkbenchAdapter; 27 28 31 public class RemoteFileEditorInput extends PlatformObject implements IWorkbenchAdapter, IStorageEditorInput { 32 ICVSRemoteFile file; 33 IStorage storage; 34 35 38 public RemoteFileEditorInput(ICVSRemoteFile file, IProgressMonitor monitor) { 39 this.file = file; 40 try { 41 initializeStorage(file, monitor); 42 } catch (TeamException e) { 43 CVSUIPlugin.log(e); 45 } 46 } 47 48 53 protected void initializeStorage(ICVSRemoteFile file, IProgressMonitor monitor) throws TeamException { 54 storage = ((IResourceVariant)file).getStorage(monitor); 56 } 57 58 69 public boolean exists() { 70 return true; 71 } 72 public boolean equals(Object o) { 73 if (!(o instanceof RemoteFileEditorInput)) return false; 74 RemoteFileEditorInput input = (RemoteFileEditorInput)o; 75 return file.equals(input.file); 76 } 77 87 public Object getAdapter(Class adapter) { 88 if (adapter == IWorkbenchAdapter.class) { 89 return this; 90 } 91 92 if (adapter == IHistoryPageSource.class) 93 return file.getAdapter(IHistoryPageSource.class); 94 95 if (adapter == ICVSFile.class || adapter == IResourceVariant.class) 96 return file; 97 98 if (adapter == IFileRevision.class) 99 return getFileRevision(); 100 101 return super.getAdapter(adapter); 102 } 103 104 public CVSResourceVariantFileRevision getFileRevision() { 105 return new CVSResourceVariantFileRevision((IResourceVariant)file); 106 } 107 115 public Object [] getChildren(Object o) { 116 return new Object [0]; 117 } 118 125 public String getContentType() { 126 String name = file.getName(); 127 return name.substring(name.lastIndexOf('.')+1); 128 } 129 132 public String getFullPath() { 133 ICVSRepositoryLocation location = file.getRepository(); 135 IPath path = new Path(null, location.getRootDirectory()); 136 path = path.setDevice(location.getHost() + IPath.DEVICE_SEPARATOR); 137 path = path.append(file.getRepositoryRelativePath()); 138 String fullPath; 139 try { 140 String revision = file.getRevision(); 141 fullPath = NLS.bind(CVSUIMessages.RemoteFileEditorInput_fullPathAndRevision, new String [] { path.toString(), revision }); 142 } catch (TeamException e) { 143 CVSUIPlugin.log(e); 144 fullPath = path.toString(); 145 } 146 return fullPath; 147 } 148 153 public ImageDescriptor getImageDescriptor() { 154 IWorkbenchAdapter fileAdapter = (IWorkbenchAdapter)file.getAdapter(IWorkbenchAdapter.class); 155 return fileAdapter == null ? null : fileAdapter.getImageDescriptor(file); 156 } 157 160 public ImageDescriptor getImageDescriptor(Object object) { 161 IWorkbenchAdapter fileAdapter = (IWorkbenchAdapter)file.getAdapter(IWorkbenchAdapter.class); 162 return fileAdapter == null ? null : fileAdapter.getImageDescriptor(file); 163 } 164 167 public String getLabel(Object o) { 168 return file.getName(); 169 } 170 175 public String getName() { 176 String name = file.getName(); 177 try { 178 return NLS.bind(CVSUIMessages.nameAndRevision, new String [] { name, file.getRevision() }); 179 } catch (TeamException e) { 180 return name; 181 } 182 } 183 190 public Object getParent(Object o) { 191 return null; 192 } 193 197 public IPersistableElement getPersistable() { 198 return null; 200 } 201 207 public IStorage getStorage() throws CoreException { 208 if (storage == null) { 209 initializeStorage(file, new NullProgressMonitor()); 210 } 211 return storage; 212 } 213 225 public String getToolTipText() { 226 return getFullPath(); 227 } 228 229 233 public ICVSRemoteFile getCVSRemoteFile() { 234 return file; 235 } 236 237 } 238 | Popular Tags |