1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
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
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 *******************************************************************************/
16 package org
.eclipse
.tracecompass
.tmf
.core
.project
.model
;
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
;
25 * TraceTypeHelper, a helper that can link a few names to a configuration element
28 * @author Matthew Khouzam
30 public class TraceTypeHelper
{
32 private static final String SEP
= " : "; //$NON-NLS-1$
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
;
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.
49 * the category of the trace type
51 * the name of the trace type
53 * an object of the trace type
55 * flag indicating whether the trace type is for a directory or
58 * True if this helper is for an experiment type
60 public TraceTypeHelper(String traceTypeId
, String categoryName
, String name
, @NonNull ITmfTrace trace
, boolean isDir
, TraceElementType elementType
) {
62 fCategoryName
= categoryName
;
63 fTraceTypeId
= traceTypeId
;
66 fElementType
= elementType
;
75 public String
getName() {
80 * Get the category name
82 * @return the category name
84 public String
getCategoryName() {
89 * Get the trace type label "category : name".
91 * @return the trace type label
93 public String
getLabel() {
94 if (fCategoryName
.isEmpty()) {
97 return fCategoryName
+ SEP
+ fName
;
101 * Get the trace type id
103 * @return the trace type id
105 public @NonNull String
getTraceTypeId() {
110 * Is the trace of this type?
113 * the trace to validate
114 * @return whether it passes the validation
116 public IStatus
validate(String path
) {
117 return fTrace
.validate(null, path
);
121 * Validate a trace against this trace type with confidence level
124 * the trace to validate
125 * @return the confidence level (0 is lowest) or -1 if validation fails
127 public int validateWithConfidence(String path
) {
129 IStatus status
= fTrace
.validate(null, path
);
130 if (status
.getSeverity() != IStatus
.ERROR
) {
132 if (status
instanceof TraceValidationStatus
) {
133 result
= ((TraceValidationStatus
) status
).getConfidence();
140 * Get an object of the trace type
141 * @return an object of the trace type
143 public ITmfTrace
getTrace() {
148 * Return whether this helper applies to a trace type or experiment type
150 * @return True if experiment type, false otherwise
152 public boolean isExperimentType() {
153 return fElementType
== TraceElementType
.EXPERIMENT
;
157 * Get the class associated with this trace type
159 * @return The trace class
161 public Class
<@NonNull ?
extends ITmfTrace
> getTraceClass() {
162 return fTrace
.getClass();
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>
169 public boolean isDirectoryTraceType() {
174 * Test whether the trace helper is enabled based on the trace type
177 * @return True if the trace helper is enabled, false otherwise
180 public boolean isEnabled() {
185 * Enable/disable the trace type helper
188 * the new enable state
191 public void setEnabled(boolean enable
) {
196 public String
toString() {