ss: Move plugins to Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / editors / TmfEditorInput.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 Ericsson
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
47 public Object getAdapter(Class adapter) {
48 return null;
49 }
50
51 @Override
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;
56 }
57
58 @Override
59 public ImageDescriptor getImageDescriptor() {
60 IContentType contentType = IDE.getContentType(fFile);
61 return PlatformUI.getWorkbench().getEditorRegistry()
62 .getImageDescriptor(fFile.getName(), contentType);
63 }
64
65 @Override
66 public String getName() {
67 return fTrace.getName();
68 }
69
70 @Override
71 public IPersistableElement getPersistable() {
72 return null;
73 }
74
75 @Override
76 public String getToolTipText() {
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
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
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 }
This page took 0.035018 seconds and 5 git commands to generate.