Re-structure LTTng sub-project as per the Linux Tools guidelines
[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.resources.IResource;
17 import org.eclipse.core.runtime.content.IContentType;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
20 import org.eclipse.ui.IEditorInput;
21 import org.eclipse.ui.IFileEditorInput;
22 import org.eclipse.ui.IPersistableElement;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.ide.FileStoreEditorInput;
25 import org.eclipse.ui.ide.IDE;
26
27 public class TmfEditorInput implements IEditorInput {
28
29 private IResource fResource;
30 private ITmfTrace fTrace;
31
32 public TmfEditorInput(IResource resource, ITmfTrace trace) {
33 fResource = resource;
34 fTrace = trace;
35 }
36
37 @Override
38 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
39 return null;
40 }
41
42 @Override
43 public boolean exists() {
44 return fResource.exists();
45 }
46
47 @Override
48 public ImageDescriptor getImageDescriptor() {
49 if (fResource instanceof IFile) {
50 IFile file = (IFile) fResource;
51 IContentType contentType = IDE.getContentType(file);
52 return PlatformUI.getWorkbench().getEditorRegistry()
53 .getImageDescriptor(file.getName(), contentType);
54 }
55 return null;
56 }
57
58 @Override
59 public String getName() {
60 return fResource.getName();
61 }
62
63 @Override
64 public IPersistableElement getPersistable() {
65 return null;
66 }
67
68 @Override
69 public String getToolTipText() {
70 return fResource.getFullPath().makeRelative().toString();
71 }
72
73 public IResource getResource() {
74 return fResource;
75 }
76
77 public ITmfTrace getTrace() {
78 return fTrace;
79 }
80
81 @Override
82 public boolean equals(Object obj) {
83 if (obj instanceof TmfEditorInput) {
84 return fResource.equals(((TmfEditorInput) obj).fResource);
85 } else if (obj instanceof IFileEditorInput) {
86 return ((IFileEditorInput) obj).getFile().equals(fResource);
87 } else if (obj instanceof FileStoreEditorInput) {
88 return ((FileStoreEditorInput) obj).getURI().equals(fResource.getRawLocationURI());
89 }
90 return false;
91 }
92 }
This page took 0.044121 seconds and 6 git commands to generate.