tmf: remove deprecated methods from tmf
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / project / model / TraceTypeHelper.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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 * Matthew Khouzam - Initial API and implementation
11 * Bernd Hufmann - Handling of directory traces types
12 * Geneviève Bastien - Added support of experiment types
13 * Patrick Tasse - Renamed trace type id
14 *******************************************************************************/
15
16 package org.eclipse.tracecompass.tmf.core.project.model;
17
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType;
21 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
23
24 /**
25 * TraceTypeHelper, a helper that can link a few names to a configuration element
26 * and a trace
27 *
28 * @author Matthew Khouzam
29 */
30 public class TraceTypeHelper {
31
32 private static final String SEP = " : "; //$NON-NLS-1$
33
34 private final String fName;
35 private final String fCategoryName;
36 private final @NonNull String fTraceTypeId;
37 private final TraceElementType fElementType;
38 private final @NonNull ITmfTrace fTrace;
39 private final boolean fIsDirectory;
40 private boolean fEnable;
41
42 /**
43 * Constructor for a trace type helper. It is a link between a trace type
44 * id, a category name, a name and a trace object.
45 *
46 * @param traceTypeId
47 * the trace type id
48 * @param categoryName
49 * the category of the trace type
50 * @param name
51 * the name of the trace type
52 * @param trace
53 * an object of the trace type
54 * @param isDir
55 * flag indicating whether the trace type is for a directory or
56 * file trace
57 * @param elementType
58 * True if this helper is for an experiment type
59 */
60 public TraceTypeHelper(String traceTypeId, String categoryName, String name, @NonNull ITmfTrace trace, boolean isDir, TraceElementType elementType) {
61 fName = name;
62 fCategoryName = categoryName;
63 fTraceTypeId = traceTypeId;
64 fTrace = trace;
65 fIsDirectory = isDir;
66 fElementType = elementType;
67 fEnable = true;
68 }
69
70 /**
71 * Get the name
72 *
73 * @return the name
74 */
75 public String getName() {
76 return fName;
77 }
78
79 /**
80 * Get the category name
81 *
82 * @return the category name
83 */
84 public String getCategoryName() {
85 return fCategoryName;
86 }
87
88 /**
89 * Get the trace type label "category : name".
90 *
91 * @return the trace type label
92 */
93 public String getLabel() {
94 if (fCategoryName.isEmpty()) {
95 return fName;
96 }
97 return fCategoryName + SEP + fName;
98 }
99
100 /**
101 * Get the trace type id
102 *
103 * @return the trace type id
104 */
105 public @NonNull String getTraceTypeId() {
106 return fTraceTypeId;
107 }
108
109 /**
110 * Is the trace of this type?
111 *
112 * @param path
113 * the trace to validate
114 * @return whether it passes the validation
115 */
116 public IStatus validate(String path) {
117 return fTrace.validate(null, path);
118 }
119
120 /**
121 * Validate a trace against this trace type with confidence level
122 *
123 * @param path
124 * the trace to validate
125 * @return the confidence level (0 is lowest) or -1 if validation fails
126 */
127 public int validateWithConfidence(String path) {
128 int result = -1;
129 IStatus status = fTrace.validate(null, path);
130 if (status.getSeverity() != IStatus.ERROR) {
131 result = 0;
132 if (status instanceof TraceValidationStatus) {
133 result = ((TraceValidationStatus) status).getConfidence();
134 }
135 }
136 return result;
137 }
138
139 /**
140 * Get an object of the trace type
141 * @return an object of the trace type
142 */
143 public ITmfTrace getTrace() {
144 return fTrace;
145 }
146
147 /**
148 * Return whether this helper applies to a trace type or experiment type
149 *
150 * @return True if experiment type, false otherwise
151 */
152 public boolean isExperimentType() {
153 return fElementType == TraceElementType.EXPERIMENT;
154 }
155
156 /**
157 * Get the class associated with this trace type
158 *
159 * @return The trace class
160 */
161 public Class<@NonNull ? extends ITmfTrace> getTraceClass() {
162 return fTrace.getClass();
163 }
164
165 /**
166 * Returns whether trace type is for a directory trace or a single file trace
167 * @return <code>true</code> if trace type is for a directory trace else <code>false</code>
168 */
169 public boolean isDirectoryTraceType() {
170 return fIsDirectory;
171 }
172
173 /**
174 * Test whether the trace helper is enabled based on the trace type
175 * preferences or not
176 *
177 * @return True if the trace helper is enabled, false otherwise
178 * @since 3.0
179 */
180 public boolean isEnabled() {
181 return fEnable;
182 }
183
184 /**
185 * Enable/disable the trace type helper
186 *
187 * @param enable
188 * the new enable state
189 * @since 3.0
190 */
191 public void setEnabled(boolean enable) {
192 fEnable = enable;
193 }
194
195 @Override
196 public String toString() {
197 return fName;
198 }
199
200 }
This page took 0.03477 seconds and 5 git commands to generate.