| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2010, 2012 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 | /* (non-Javadoc) |
| 99 | * @see java.lang.Object#hashCode() |
| 100 | */ |
| 101 | @Override |
| 102 | public int hashCode() { |
| 103 | final int prime = 31; |
| 104 | int result = 1; |
| 105 | result = prime * result + ((fFile == null) ? 0 : fFile.getLocation().hashCode()); |
| 106 | result = prime * result + ((fTrace == null) ? 0 : fTrace.getName().hashCode()); |
| 107 | return result; |
| 108 | } |
| 109 | |
| 110 | /* (non-Javadoc) |
| 111 | * @see java.lang.Object#equals(java.lang.Object) |
| 112 | */ |
| 113 | @Override |
| 114 | public boolean equals(Object obj) { |
| 115 | if (this == obj) { |
| 116 | return true; |
| 117 | } |
| 118 | if (obj == null) { |
| 119 | return false; |
| 120 | } |
| 121 | if (getClass() != obj.getClass()) { |
| 122 | return false; |
| 123 | } |
| 124 | TmfEditorInput other = (TmfEditorInput) obj; |
| 125 | if (fFile == null) { |
| 126 | if (other.fFile != null) { |
| 127 | return false; |
| 128 | } |
| 129 | } else if (!fFile.getLocation().equals(other.fFile.getLocation())) { |
| 130 | return false; |
| 131 | } |
| 132 | if (fTrace == null) { |
| 133 | if (other.fTrace != null) { |
| 134 | return false; |
| 135 | } |
| 136 | } else if (!fTrace.getName().equals(other.fTrace.getName())) { |
| 137 | return false; |
| 138 | } |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | } |