~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.editor/src/org/eclipse/linuxtools/systemtap/ui/editor/PathEditorInput.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 *
 
8
 * Contributors:
 
9
 *     IBM Corporation - Jeff Briggs, Henry Hughes, Ryan Morse
 
10
 *******************************************************************************/
 
11
 
 
12
package org.eclipse.linuxtools.systemtap.ui.editor;
 
13
 
 
14
import java.io.File;
 
15
import java.io.IOException;
 
16
 
 
17
import org.eclipse.core.runtime.IPath;
 
18
import org.eclipse.core.runtime.Path;
 
19
 
 
20
import org.eclipse.jface.resource.ImageDescriptor;
 
21
import org.eclipse.linuxtools.internal.systemtap.ui.editor.Localization;
 
22
 
 
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;
 
28
 
 
29
 
 
30
 
 
31
public class PathEditorInput implements IPathEditorInput, ILocationProvider {
 
32
        private IPath fPath;
 
33
        private IWorkbenchWindow fMainWindow;
 
34
        public boolean temp = false;
 
35
 
 
36
        public PathEditorInput(IPath path) {
 
37
                if (path == null) {
 
38
                        throw new IllegalArgumentException();
 
39
                }
 
40
                this.fPath = path;
 
41
        }
 
42
        public PathEditorInput(IPath path, IWorkbenchWindow window) {
 
43
                this(path);
 
44
                this.fMainWindow = window;
 
45
        }
 
46
 
 
47
        public PathEditorInput() throws IOException     {
 
48
                temp = true;
 
49
                File file = File.createTempFile(Localization.getString("PathEditorInput.Untitled") , ".stp"); //$NON-NLS-1$ //$NON-NLS-2$
 
50
                fPath = new Path(file.getAbsolutePath());
 
51
        }
 
52
 
 
53
        public int hashCode() {
 
54
                return fPath.hashCode();
 
55
        }
 
56
        
 
57
        public boolean equals(Object obj) {
 
58
                if (this == obj)
 
59
                        return true;
 
60
                if (!(obj instanceof PathEditorInput))
 
61
                        return false;
 
62
                PathEditorInput other = (PathEditorInput) obj;
 
63
 
 
64
                return fPath.equals(other.fPath);
 
65
        }
 
66
        
 
67
        public boolean exists() {
 
68
                return fPath.toFile().exists();
 
69
        }
 
70
        
 
71
        public ImageDescriptor getImageDescriptor() {
 
72
                return PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(fPath.toString());
 
73
        }
 
74
        
 
75
        public String getName() {
 
76
                String[] substr = fPath.segments();
 
77
                return substr[substr.length -1];
 
78
        }
 
79
        
 
80
        public String getToolTipText() {
 
81
                return fPath.makeRelative().toOSString();
 
82
        }
 
83
        
 
84
        public IPath getPath() {
 
85
                return fPath;
 
86
        }
 
87
 
 
88
        @SuppressWarnings("unchecked")
 
89
        public Object getAdapter(Class adapter) {
 
90
                return null;
 
91
        }
 
92
 
 
93
        public IPersistableElement getPersistable() {
 
94
                return null;
 
95
        }
 
96
 
 
97
        public IWorkbenchWindow getMainWindow() {
 
98
                return fMainWindow;
 
99
        }
 
100
 
 
101
        public IPath getPath(Object element) {
 
102
                if(element instanceof PathEditorInput) {
 
103
                        return ((PathEditorInput)element).getPath();
 
104
                }
 
105
                return null;
 
106
        }
 
107
 
 
108
        public void setPath(IPath newPath) {
 
109
                fPath = newPath;
 
110
        }
 
111
}