Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / editors / TmfEditorInput.java
1 /*******************************************************************************
2 * Copyright (c) 2010 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 return fFile.exists();
54 }
55
56 @Override
57 public ImageDescriptor getImageDescriptor() {
58 IContentType contentType = IDE.getContentType(fFile);
59 return PlatformUI.getWorkbench().getEditorRegistry()
60 .getImageDescriptor(fFile.getName(), contentType);
61 }
62
63 @Override
64 public String getName() {
65 return fTrace.getName();
66 }
67
68 @Override
69 public IPersistableElement getPersistable() {
70 return null;
71 }
72
73 @Override
74 public String getToolTipText() {
75 return fFile.getFullPath().makeRelative().toString();
76 }
77
78 /**
79 * Get this editor input's file object
80 *
81 * @return The IFile
82 */
83 public IFile getFile() {
84 return fFile;
85 }
86
87 /**
88 * Get this editor input's trace
89 *
90 * @return The trace
91 */
92 public ITmfTrace getTrace() {
93 return fTrace;
94 }
95
96 /* (non-Javadoc)
97 * @see java.lang.Object#hashCode()
98 */
99 @Override
100 public int hashCode() {
101 final int prime = 31;
102 int result = 1;
103 result = prime * result + ((fFile == null) ? 0 : fFile.getLocation().hashCode());
104 result = prime * result + ((fTrace == null) ? 0 : fTrace.getName().hashCode());
105 return result;
106 }
107
108 /* (non-Javadoc)
109 * @see java.lang.Object#equals(java.lang.Object)
110 */
111 @Override
112 public boolean equals(Object obj) {
113 if (this == obj) {
114 return true;
115 }
116 if (obj == null) {
117 return false;
118 }
119 if (getClass() != obj.getClass()) {
120 return false;
121 }
122 TmfEditorInput other = (TmfEditorInput) obj;
123 if (fFile == null) {
124 if (other.fFile != null) {
125 return false;
126 }
127 } else if (!fFile.getLocation().equals(other.fFile.getLocation())) {
128 return false;
129 }
130 if (fTrace == null) {
131 if (other.fTrace != null) {
132 return false;
133 }
134 } else if (!fTrace.getName().equals(other.fTrace.getName())) {
135 return false;
136 }
137 return true;
138 }
139
140 }
This page took 0.054404 seconds and 5 git commands to generate.