blob: 0e56118e2bfdd02a07de819406f975af3a3fe4b5 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
*******************************************************************************/
package org.eclipse.dltk.internal.debug.ui;
import java.io.File;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.editors.text.ILocationProvider;
public class ExternalFileEditorInput implements IPathEditorInput,
ILocationProvider {
private File file;
public ExternalFileEditorInput(File file) {
super();
this.file = file;
}
public boolean exists() {
return file.exists();
}
public ImageDescriptor getImageDescriptor() {
return null;
}
public String getName() {
return file.getName();
}
public IPersistableElement getPersistable() {
return null;
}
public String getToolTipText() {
return file.getAbsolutePath();
}
public Object getAdapter(Class adapter) {
if (ILocationProvider.class.equals(adapter)) {
return this;
}
if (IResource.class.equals(adapter)) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
IFile[] files = root.findFilesForLocation(getPath());
if (files.length > 0) {
return files[0];
}
}
return Platform.getAdapterManager().getAdapter(this, adapter);
}
public IPath getPath(Object element) {
if (element instanceof ExternalFileEditorInput) {
ExternalFileEditorInput input = (ExternalFileEditorInput) element;
return input.getPath();
}
return null;
}
public IPath getPath() {
return Path.fromOSString(file.getAbsolutePath());
}
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o instanceof ExternalFileEditorInput) {
ExternalFileEditorInput input = (ExternalFileEditorInput) o;
return file.equals(input.file);
}
if (o instanceof IPathEditorInput) {
IPathEditorInput input = (IPathEditorInput) o;
return getPath().equals(input.getPath());
}
return false;
}
public int hashCode() {
return file.hashCode();
}
}