1
/*******************************************************************************
2
* Copyright (c) 2006 IBM Corporation.
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* http://www.eclipse.org/legal/epl-v10.html
9
* IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
10
*******************************************************************************/
12
package org.eclipse.linuxtools.systemtap.ui.editor;
15
import java.io.IOException;
17
import org.eclipse.core.runtime.IPath;
18
import org.eclipse.core.runtime.Path;
20
import org.eclipse.jface.resource.ImageDescriptor;
21
import org.eclipse.linuxtools.internal.systemtap.ui.editor.Localization;
23
import org.eclipse.ui.IPathEditorInput;
24
import org.eclipse.ui.IPersistableElement;
25
import org.eclipse.ui.IWorkbenchWindow;
26
import org.eclipse.ui.PlatformUI;
27
import org.eclipse.ui.editors.text.ILocationProvider;
31
public class PathEditorInput implements IPathEditorInput, ILocationProvider {
33
private IWorkbenchWindow fMainWindow;
34
public boolean temp = false;
36
public PathEditorInput(IPath path) {
38
throw new IllegalArgumentException();
42
public PathEditorInput(IPath path, IWorkbenchWindow window) {
44
this.fMainWindow = window;
47
public PathEditorInput() throws IOException {
49
File file = File.createTempFile(Localization.getString("PathEditorInput.Untitled") , ".stp"); //$NON-NLS-1$ //$NON-NLS-2$
50
fPath = new Path(file.getAbsolutePath());
53
public int hashCode() {
54
return fPath.hashCode();
57
public boolean equals(Object obj) {
60
if (!(obj instanceof PathEditorInput))
62
PathEditorInput other = (PathEditorInput) obj;
64
return fPath.equals(other.fPath);
67
public boolean exists() {
68
return fPath.toFile().exists();
71
public ImageDescriptor getImageDescriptor() {
72
return PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(fPath.toString());
75
public String getName() {
76
String[] substr = fPath.segments();
77
return substr[substr.length -1];
80
public String getToolTipText() {
81
return fPath.makeRelative().toOSString();
84
public IPath getPath() {
88
@SuppressWarnings("unchecked")
89
public Object getAdapter(Class adapter) {
93
public IPersistableElement getPersistable() {
97
public IWorkbenchWindow getMainWindow() {
101
public IPath getPath(Object element) {
102
if(element instanceof PathEditorInput) {
103
return ((PathEditorInput)element).getPath();
108
public void setPath(IPath newPath) {