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
CommitLineData
d04ec5a7 1/*******************************************************************************
38d284eb 2 * Copyright (c) 2013, 2015 Ericsson
d04ec5a7
MK
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
d8aba2e2 11 * Bernd Hufmann - Handling of directory traces types
376fdfbd 12 * Geneviève Bastien - Added support of experiment types
38d284eb 13 * Patrick Tasse - Renamed trace type id
d04ec5a7
MK
14 *******************************************************************************/
15
2bdf0193 16package org.eclipse.tracecompass.tmf.core.project.model;
d04ec5a7 17
350cae41 18import org.eclipse.core.runtime.IStatus;
a8ddd783 19import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
20import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType;
21import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
22import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
d04ec5a7
MK
23
24/**
d8aba2e2 25 * TraceTypeHelper, a helper that can link a few names to a configuration element
d04ec5a7
MK
26 * and a trace
27 *
28 * @author Matthew Khouzam
d04ec5a7
MK
29 */
30public class TraceTypeHelper {
31
2b0005f0
PT
32 private static final String SEP = " : "; //$NON-NLS-1$
33
d04ec5a7
MK
34 private final String fName;
35 private final String fCategoryName;
3adbcf71 36 private final @NonNull String fTraceTypeId;
376fdfbd 37 private final TraceElementType fElementType;
3adbcf71 38 private final @NonNull ITmfTrace fTrace;
d8aba2e2 39 private final boolean fIsDirectory;
3adbcf71 40 private boolean fEnable;
d04ec5a7
MK
41
42 /**
38d284eb
PT
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.
d04ec5a7 45 *
38d284eb
PT
46 * @param traceTypeId
47 * the trace type id
d04ec5a7
MK
48 * @param categoryName
49 * the category of the trace type
50 * @param name
38d284eb 51 * the name of the trace type
d04ec5a7
MK
52 * @param trace
53 * an object of the trace type
d8aba2e2 54 * @param isDir
38d284eb
PT
55 * flag indicating whether the trace type is for a directory or
56 * file trace
376fdfbd
GB
57 * @param elementType
58 * True if this helper is for an experiment type
d04ec5a7 59 */
38d284eb 60 public TraceTypeHelper(String traceTypeId, String categoryName, String name, @NonNull ITmfTrace trace, boolean isDir, TraceElementType elementType) {
d04ec5a7
MK
61 fName = name;
62 fCategoryName = categoryName;
38d284eb 63 fTraceTypeId = traceTypeId;
d04ec5a7 64 fTrace = trace;
d8aba2e2 65 fIsDirectory = isDir;
376fdfbd 66 fElementType = elementType;
3adbcf71 67 fEnable = true;
d04ec5a7
MK
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 /**
2b0005f0
PT
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 /**
38d284eb 101 * Get the trace type id
d04ec5a7 102 *
38d284eb 103 * @return the trace type id
d04ec5a7 104 */
3adbcf71 105 public @NonNull String getTraceTypeId() {
38d284eb 106 return fTraceTypeId;
d04ec5a7
MK
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 */
a8ddd783
GB
116 public IStatus validate(String path) {
117 return fTrace.validate(null, path);
d04ec5a7
MK
118 }
119
350cae41
PT
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
350cae41
PT
126 */
127 public int validateWithConfidence(String path) {
128 int result = -1;
a8ddd783 129 IStatus status = fTrace.validate(null, path);
d16bb0dd 130 if (status.getSeverity() != IStatus.ERROR) {
a8ddd783
GB
131 result = 0;
132 if (status instanceof TraceValidationStatus) {
133 result = ((TraceValidationStatus) status).getConfidence();
350cae41
PT
134 }
135 }
136 return result;
137 }
138
76fccfb0
MK
139 /**
140 * Get an object of the trace type
141 * @return an object of the trace type
76fccfb0 142 */
0a19e2d1 143 public ITmfTrace getTrace() {
76fccfb0
MK
144 return fTrace;
145 }
146
376fdfbd
GB
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
c068a752
GB
156 /**
157 * Get the class associated with this trace type
158 *
159 * @return The trace class
c068a752 160 */
367e2932 161 public Class<@NonNull ? extends ITmfTrace> getTraceClass() {
c068a752
GB
162 return fTrace.getClass();
163 }
164
d8aba2e2
BH
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
3adbcf71
JCK
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
4b40a764 178 * @since 3.0
3adbcf71
JCK
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
4b40a764 189 * @since 3.0
3adbcf71
JCK
190 */
191 public void setEnabled(boolean enable) {
192 fEnable = enable;
193 }
d8aba2e2 194
d04ec5a7
MK
195 @Override
196 public String toString() {
197 return fName;
198 }
199
bcb8c2cb 200}
This page took 0.098267 seconds and 5 git commands to generate.