-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.editors;\r
-\r
-import org.eclipse.core.resources.IFile;\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.core.runtime.content.IContentType;\r
-import org.eclipse.jface.resource.ImageDescriptor;\r
-import org.eclipse.linuxtools.tmf.trace.ITmfTrace;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IFileEditorInput;\r
-import org.eclipse.ui.IPersistableElement;\r
-import org.eclipse.ui.PlatformUI;\r
-import org.eclipse.ui.ide.FileStoreEditorInput;\r
-import org.eclipse.ui.ide.IDE;\r
-\r
-public class TmfEditorInput implements IEditorInput {\r
-\r
- private IResource fResource;\r
- private ITmfTrace fTrace;\r
-\r
- public TmfEditorInput(IResource resource, ITmfTrace trace) {\r
- fResource = resource;\r
- fTrace = trace;\r
- }\r
- \r
- public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {\r
- return null;\r
- }\r
-\r
- public boolean exists() {\r
- return fResource.exists();\r
- }\r
-\r
- public ImageDescriptor getImageDescriptor() {\r
- if (fResource instanceof IFile) {\r
- IFile file = (IFile) fResource;\r
- IContentType contentType = IDE.getContentType(file);\r
- return PlatformUI.getWorkbench().getEditorRegistry()\r
- .getImageDescriptor(file.getName(), contentType);\r
- }\r
- return null;\r
- }\r
-\r
- public String getName() {\r
- return fResource.getName();\r
- }\r
-\r
- public IPersistableElement getPersistable() {\r
- return null;\r
- }\r
-\r
- public String getToolTipText() {\r
- return fResource.getFullPath().makeRelative().toString();\r
- }\r
-\r
- public IResource getResource() {\r
- return fResource;\r
- }\r
- \r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (obj instanceof TmfEditorInput) {\r
- return fResource.equals(((TmfEditorInput) obj).fResource);\r
- } else if (obj instanceof IFileEditorInput) {\r
- return ((IFileEditorInput) obj).getFile().equals(fResource);\r
- } else if (obj instanceof FileStoreEditorInput) {\r
- return ((FileStoreEditorInput) obj).getURI().equals(fResource.getRawLocationURI());\r
- }\r
- return false;\r
- }\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010, 2013 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.editors;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * The input interface for TMF editors.
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ */
+public class TmfEditorInput implements IEditorInput {
+
+ private final IFile fFile;
+ private final ITmfTrace fTrace;
+
+ /**
+ * Standard constructor
+ *
+ * @param file The IFile pointer
+ * @param trace Reference to the trace
+ */
+ public TmfEditorInput(IFile file, ITmfTrace trace) {
+ fFile = file;
+ fTrace = trace;
+ }
+
+ @Override
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ @Override
+ public boolean exists() {
+ /* prevent this input from appearing in "Files Most Recently Used" list,
+ * as this causes lingering reference to ITmfTrace in the platform */
+ return false;
+ }
+
+ @Override
+ public ImageDescriptor getImageDescriptor() {
+ IContentType contentType = IDE.getContentType(fFile);
+ return PlatformUI.getWorkbench().getEditorRegistry()
+ .getImageDescriptor(fFile.getName(), contentType);
+ }
+
+ @Override
+ public String getName() {
+ return fTrace.getName();
+ }
+
+ @Override
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ @Override
+ public String getToolTipText() {
+ return fFile.getFullPath().makeRelative().toString();
+ }
+
+ /**
+ * Get this editor input's file object
+ *
+ * @return The IFile
+ */
+ public IFile getFile() {
+ return fFile;
+ }
+
+ /**
+ * Get this editor input's trace
+ *
+ * @return The trace
+ */
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((fFile == null) ? 0 : fFile.getLocation().hashCode());
+ result = prime * result + ((fTrace == null) ? 0 : fTrace.getName().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ TmfEditorInput other = (TmfEditorInput) obj;
+ if (fFile == null) {
+ if (other.fFile != null) {
+ return false;
+ }
+ } else if (!fFile.getLocation().equals(other.fFile.getLocation())) {
+ return false;
+ }
+ if (fTrace == null) {
+ if (other.fTrace != null) {
+ return false;
+ }
+ } else if (!fTrace.getName().equals(other.fTrace.getName())) {
+ return false;
+ }
+ return true;
+ }
+
+}