Commit | Line | Data |
---|---|---|
abfad0aa FC |
1 | /*******************************************************************************\r |
2 | * Copyright (c) 2010 Ericsson\r | |
013a5f1c | 3 | *\r |
abfad0aa FC |
4 | * All rights reserved. This program and the accompanying materials are\r |
5 | * made available under the terms of the Eclipse Public License v1.0 which\r | |
6 | * accompanies this distribution, and is available at\r | |
7 | * http://www.eclipse.org/legal/epl-v10.html\r | |
013a5f1c | 8 | *\r |
abfad0aa FC |
9 | * Contributors:\r |
10 | * Patrick Tasse - Initial API and implementation\r | |
11 | *******************************************************************************/\r | |
12 | \r | |
13 | package org.eclipse.linuxtools.tmf.ui.editors;\r | |
14 | \r | |
15 | import org.eclipse.core.resources.IFile;\r | |
abfad0aa FC |
16 | import org.eclipse.core.runtime.content.IContentType;\r |
17 | import org.eclipse.jface.resource.ImageDescriptor;\r | |
6c13869b | 18 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;\r |
abfad0aa | 19 | import org.eclipse.ui.IEditorInput;\r |
abfad0aa FC |
20 | import org.eclipse.ui.IPersistableElement;\r |
21 | import org.eclipse.ui.PlatformUI;\r | |
abfad0aa FC |
22 | import org.eclipse.ui.ide.IDE;\r |
23 | \r | |
013a5f1c AM |
24 | /**\r |
25 | * The input interface for TMF editors.\r | |
26 | *\r | |
27 | * @version 1.0\r | |
28 | * @author Patrick Tasse\r | |
29 | */\r | |
abfad0aa FC |
30 | public class TmfEditorInput implements IEditorInput {\r |
31 | \r | |
013a5f1c AM |
32 | private final IFile fFile;\r |
33 | private final ITmfTrace<?> fTrace;\r | |
abfad0aa | 34 | \r |
013a5f1c AM |
35 | /**\r |
36 | * Standard constructor\r | |
37 | *\r | |
38 | * @param file The IFile pointer\r | |
39 | * @param trace Reference to the trace\r | |
40 | */\r | |
a1091415 PT |
41 | public TmfEditorInput(IFile file, ITmfTrace<?> trace) {\r |
42 | fFile = file;\r | |
abfad0aa FC |
43 | fTrace = trace;\r |
44 | }\r | |
013a5f1c | 45 | \r |
d4011df2 FC |
46 | @Override\r |
47 | public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {\r | |
abfad0aa FC |
48 | return null;\r |
49 | }\r | |
50 | \r | |
d4011df2 FC |
51 | @Override\r |
52 | public boolean exists() {\r | |
a1091415 | 53 | return fFile.exists();\r |
abfad0aa FC |
54 | }\r |
55 | \r | |
d4011df2 FC |
56 | @Override\r |
57 | public ImageDescriptor getImageDescriptor() {\r | |
a1091415 PT |
58 | IContentType contentType = IDE.getContentType(fFile);\r |
59 | return PlatformUI.getWorkbench().getEditorRegistry()\r | |
60 | .getImageDescriptor(fFile.getName(), contentType);\r | |
abfad0aa FC |
61 | }\r |
62 | \r | |
d4011df2 FC |
63 | @Override\r |
64 | public String getName() {\r | |
09d11238 | 65 | return fTrace.getName();\r |
abfad0aa FC |
66 | }\r |
67 | \r | |
d4011df2 FC |
68 | @Override\r |
69 | public IPersistableElement getPersistable() {\r | |
abfad0aa FC |
70 | return null;\r |
71 | }\r | |
72 | \r | |
d4011df2 FC |
73 | @Override\r |
74 | public String getToolTipText() {\r | |
a1091415 | 75 | return fFile.getFullPath().makeRelative().toString();\r |
abfad0aa FC |
76 | }\r |
77 | \r | |
013a5f1c AM |
78 | /**\r |
79 | * Get this editor input's file object\r | |
80 | *\r | |
81 | * @return The IFile\r | |
82 | */\r | |
a1091415 PT |
83 | public IFile getFile() {\r |
84 | return fFile;\r | |
abfad0aa | 85 | }\r |
a1091415 | 86 | \r |
013a5f1c AM |
87 | /**\r |
88 | * Get this editor input's trace\r | |
89 | *\r | |
90 | * @return The trace\r | |
91 | */\r | |
828e5592 | 92 | public ITmfTrace<?> getTrace() {\r |
abfad0aa FC |
93 | return fTrace;\r |
94 | }\r | |
95 | \r | |
1cceddbe | 96 | /* (non-Javadoc)\r |
97 | * @see java.lang.Object#hashCode()\r | |
98 | */\r | |
9ccc6d01 | 99 | @Override\r |
1cceddbe | 100 | public int hashCode() {\r |
101 | final int prime = 31;\r | |
102 | int result = 1;\r | |
a1091415 PT |
103 | result = prime * result + ((fFile == null) ? 0 : fFile.getLocation().hashCode());\r |
104 | result = prime * result + ((fTrace == null) ? 0 : fTrace.getName().hashCode());\r | |
1cceddbe | 105 | return result;\r |
106 | }\r | |
107 | \r | |
108 | /* (non-Javadoc)\r | |
109 | * @see java.lang.Object#equals(java.lang.Object)\r | |
110 | */\r | |
111 | @Override\r | |
112 | public boolean equals(Object obj) {\r | |
013a5f1c | 113 | if (this == obj) {\r |
1cceddbe | 114 | return true;\r |
013a5f1c AM |
115 | }\r |
116 | if (obj == null) {\r | |
a1091415 | 117 | return false;\r |
013a5f1c AM |
118 | }\r |
119 | if (getClass() != obj.getClass()) {\r | |
a1091415 | 120 | return false;\r |
013a5f1c | 121 | }\r |
a1091415 PT |
122 | TmfEditorInput other = (TmfEditorInput) obj;\r |
123 | if (fFile == null) {\r | |
013a5f1c | 124 | if (other.fFile != null) {\r |
a1091415 | 125 | return false;\r |
013a5f1c AM |
126 | }\r |
127 | } else if (!fFile.getLocation().equals(other.fFile.getLocation())) {\r | |
a1091415 | 128 | return false;\r |
013a5f1c | 129 | }\r |
a1091415 | 130 | if (fTrace == null) {\r |
013a5f1c | 131 | if (other.fTrace != null) {\r |
a1091415 | 132 | return false;\r |
013a5f1c AM |
133 | }\r |
134 | } else if (!fTrace.getName().equals(other.fTrace.getName())) {\r | |
1cceddbe | 135 | return false;\r |
013a5f1c | 136 | }\r |
a1091415 | 137 | return true;\r |
abfad0aa | 138 | }\r |
1cceddbe | 139 | \r |
abfad0aa | 140 | }\r |