Merge branch 'master' into lttng_2_0_control_dev
[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 public class TmfEditorInput implements IEditorInput {
25
26 private IFile fFile;
27 private ITmfTrace<?> fTrace;
28
29 public TmfEditorInput(IFile file, ITmfTrace<?> trace) {
30 fFile = file;
31 fTrace = trace;
32 }
33
34 @Override
35 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
36 return null;
37 }
38
39 @Override
40 public boolean exists() {
41 return fFile.exists();
42 }
43
44 @Override
45 public ImageDescriptor getImageDescriptor() {
46 IContentType contentType = IDE.getContentType(fFile);
47 return PlatformUI.getWorkbench().getEditorRegistry()
48 .getImageDescriptor(fFile.getName(), contentType);
49 }
50
51 @Override
52 public String getName() {
53 return fTrace.getName();
54 }
55
56 @Override
57 public IPersistableElement getPersistable() {
58 return null;
59 }
60
61 @Override
62 public String getToolTipText() {
63 return fFile.getFullPath().makeRelative().toString();
64 }
65
66 public IFile getFile() {
67 return fFile;
68 }
69
70 public ITmfTrace<?> getTrace() {
71 return fTrace;
72 }
73
74 /* (non-Javadoc)
75 * @see java.lang.Object#hashCode()
76 */
77 @Override
78 public int hashCode() {
79 final int prime = 31;
80 int result = 1;
81 result = prime * result + ((fFile == null) ? 0 : fFile.getLocation().hashCode());
82 result = prime * result + ((fTrace == null) ? 0 : fTrace.getName().hashCode());
83 return result;
84 }
85
86 /* (non-Javadoc)
87 * @see java.lang.Object#equals(java.lang.Object)
88 */
89 @Override
90 public boolean equals(Object obj) {
91 if (this == obj)
92 return true;
93 if (obj == null)
94 return false;
95 if (getClass() != obj.getClass())
96 return false;
97 TmfEditorInput other = (TmfEditorInput) obj;
98 if (fFile == null) {
99 if (other.fFile != null)
100 return false;
101 } else if (!fFile.getLocation().equals(other.fFile.getLocation()))
102 return false;
103 if (fTrace == null) {
104 if (other.fTrace != null)
105 return false;
106 } else if (!fTrace.getName().equals(other.fTrace.getName()))
107 return false;
108 return true;
109 }
110
111 }
This page took 0.035489 seconds and 6 git commands to generate.