Commit | Line | Data |
---|---|---|
6151d86c | 1 | /******************************************************************************* |
11252342 | 2 | * Copyright (c) 2010, 2013 Ericsson |
6151d86c PT |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Patrick Tasse - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.editors; | |
14 | ||
15 | import org.eclipse.core.resources.IFile; | |
16 | import org.eclipse.core.runtime.content.IContentType; | |
17 | import org.eclipse.jface.resource.ImageDescriptor; | |
18 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; | |
19 | import org.eclipse.ui.IEditorInput; | |
20 | import org.eclipse.ui.IPersistableElement; | |
21 | import org.eclipse.ui.PlatformUI; | |
22 | import org.eclipse.ui.ide.IDE; | |
23 | ||
24 | /** | |
25 | * The input interface for TMF editors. | |
26 | * | |
27 | * @version 1.0 | |
28 | * @author Patrick Tasse | |
29 | */ | |
30 | public class TmfEditorInput implements IEditorInput { | |
31 | ||
32 | private final IFile fFile; | |
33 | private final ITmfTrace fTrace; | |
34 | ||
35 | /** | |
36 | * Standard constructor | |
37 | * | |
38 | * @param file The IFile pointer | |
39 | * @param trace Reference to the trace | |
40 | */ | |
41 | public TmfEditorInput(IFile file, ITmfTrace trace) { | |
42 | fFile = file; | |
43 | fTrace = trace; | |
44 | } | |
45 | ||
46 | @Override | |
faa38350 | 47 | public Object getAdapter(Class adapter) { |
6151d86c PT |
48 | return null; |
49 | } | |
50 | ||
51 | @Override | |
faa38350 PT |
52 | public boolean exists() { |
53 | /* prevent this input from appearing in "Files Most Recently Used" list, | |
54 | * as this causes lingering reference to ITmfTrace in the platform */ | |
55 | return false; | |
6151d86c PT |
56 | } |
57 | ||
58 | @Override | |
faa38350 | 59 | public ImageDescriptor getImageDescriptor() { |
6151d86c PT |
60 | IContentType contentType = IDE.getContentType(fFile); |
61 | return PlatformUI.getWorkbench().getEditorRegistry() | |
62 | .getImageDescriptor(fFile.getName(), contentType); | |
63 | } | |
64 | ||
65 | @Override | |
faa38350 | 66 | public String getName() { |
6151d86c PT |
67 | return fTrace.getName(); |
68 | } | |
69 | ||
70 | @Override | |
faa38350 | 71 | public IPersistableElement getPersistable() { |
6151d86c PT |
72 | return null; |
73 | } | |
74 | ||
75 | @Override | |
faa38350 | 76 | public String getToolTipText() { |
6151d86c PT |
77 | return fFile.getFullPath().makeRelative().toString(); |
78 | } | |
79 | ||
80 | /** | |
81 | * Get this editor input's file object | |
82 | * | |
83 | * @return The IFile | |
84 | */ | |
85 | public IFile getFile() { | |
86 | return fFile; | |
87 | } | |
88 | ||
89 | /** | |
90 | * Get this editor input's trace | |
91 | * | |
92 | * @return The trace | |
93 | */ | |
94 | public ITmfTrace getTrace() { | |
95 | return fTrace; | |
96 | } | |
97 | ||
6151d86c PT |
98 | @Override |
99 | public int hashCode() { | |
100 | final int prime = 31; | |
101 | int result = 1; | |
102 | result = prime * result + ((fFile == null) ? 0 : fFile.getLocation().hashCode()); | |
103 | result = prime * result + ((fTrace == null) ? 0 : fTrace.getName().hashCode()); | |
104 | return result; | |
105 | } | |
106 | ||
6151d86c PT |
107 | @Override |
108 | public boolean equals(Object obj) { | |
109 | if (this == obj) { | |
110 | return true; | |
111 | } | |
112 | if (obj == null) { | |
113 | return false; | |
114 | } | |
115 | if (getClass() != obj.getClass()) { | |
116 | return false; | |
117 | } | |
118 | TmfEditorInput other = (TmfEditorInput) obj; | |
119 | if (fFile == null) { | |
120 | if (other.fFile != null) { | |
121 | return false; | |
122 | } | |
123 | } else if (!fFile.getLocation().equals(other.fFile.getLocation())) { | |
124 | return false; | |
125 | } | |
126 | if (fTrace == null) { | |
127 | if (other.fTrace != null) { | |
128 | return false; | |
129 | } | |
130 | } else if (!fTrace.getName().equals(other.fTrace.getName())) { | |
131 | return false; | |
132 | } | |
133 | return true; | |
134 | } | |
135 | ||
136 | } |