2010-07-28 Francois Chouinard <fchouinard@gmail.com> Fix for Bug316349 + a bunch...
[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.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 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
38 return null;
39 }
40
41 public boolean exists() {
42 return fResource.exists();
43 }
44
45 public ImageDescriptor getImageDescriptor() {
46 if (fResource instanceof IFile) {
47 IFile file = (IFile) fResource;
48 IContentType contentType = IDE.getContentType(file);
49 return PlatformUI.getWorkbench().getEditorRegistry()
50 .getImageDescriptor(file.getName(), contentType);
51 }
52 return null;
53 }
54
55 public String getName() {
56 return fResource.getName();
57 }
58
59 public IPersistableElement getPersistable() {
60 return null;
61 }
62
63 public String getToolTipText() {
64 return fResource.getFullPath().makeRelative().toString();
65 }
66
67 public IResource getResource() {
68 return fResource;
69 }
70
71 public ITmfTrace getTrace() {
72 return fTrace;
73 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (obj instanceof TmfEditorInput) {
78 return fResource.equals(((TmfEditorInput) obj).fResource);
79 } else if (obj instanceof IFileEditorInput) {
80 return ((IFileEditorInput) obj).getFile().equals(fResource);
81 } else if (obj instanceof FileStoreEditorInput) {
82 return ((FileStoreEditorInput) obj).getURI().equals(fResource.getRawLocationURI());
83 }
84 return false;
85 }
86 }
This page took 0.034503 seconds and 6 git commands to generate.