package tool.editors.method;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;
import org.eclipse.ui.model.IWorkbenchAdapter;
import org.eclipse.ui.part.FileEditorInput;
import tool.model.ToolClass;
import tool.model.ToolMethod;
public class MethodEditorInput implements IFileEditorInput, IPersistableElement {
private ToolMethod method;
private String fullName;
private IAnnotationModel annotationModel;
public MethodEditorInput(ToolMethod method) {
this.method = method;
this.fullName = ((ToolClass)this.method.getParent()).getToolName() + method.getName();
}
public ToolMethod getMethod() {
return method;
}
@Override
public void saveState(IMemento memento) {
MethodElementFactory.saveState(memento, this );
}
@Override
public String getName() {
return this.method.getToolName();
}
@Override
public IStorage getStorage() throws CoreException {
return this.method.getImplementationFile();
}
@Override
public boolean exists() {
return true;
}
@Override
public ImageDescriptor getImageDescriptor() {
return this.method.getImageDescriptor();
}
@Override
public IPersistableElement getPersistable() {
return this;
}
@Override
public String getToolTipText() {
return this.getMethod().getToolTipText();
}
@Override
public Object getAdapter(Class adapter) {
System.out.println("#### looking for: " + adapter);
if (IWorkbenchAdapter.class.equals(adapter)) {
return new IWorkbenchAdapter() {
public Object[] getChildren(Object object) {
return new Object[0];
}
public ImageDescriptor getImageDescriptor(Object object) {
return MethodEditorInput.this .getImageDescriptor();
}
public String getLabel(Object object) {
return MethodEditorInput.this.getName();
}
public Object getParent(Object object) {
return MethodEditorInput.this.getFile().getParent();
}
};
// } else if (IResource.class.equals(adapter)){
// return getFile();
}
return null;
}
@Override
public IFile getFile() {
return this.method.getFile();
}
@Override
public String getFactoryId() {
return MethodElementFactory.getFactoryId();
}
public void setAnnotationModel(IAnnotationModel model) {
this.annotationModel = model;
}
public IAnnotationModel getAnnotationModel() {
return annotationModel;
}
}