lttng: Convert CreateSessionDialog to a TitleAreaDialog
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / project / model / TraceTypeHelper.java
CommitLineData
d04ec5a7 1/*******************************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 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
d04ec5a7
MK
13 *******************************************************************************/
14
47aafe74 15package org.eclipse.linuxtools.tmf.core.project.model;
d04ec5a7 16
350cae41 17import org.eclipse.core.runtime.IStatus;
376fdfbd 18import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType.TraceElementType;
d04ec5a7 19import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
350cae41 20import org.eclipse.linuxtools.tmf.core.trace.TraceValidationStatus;
d04ec5a7
MK
21
22/**
d8aba2e2 23 * TraceTypeHelper, a helper that can link a few names to a configuration element
d04ec5a7
MK
24 * and a trace
25 *
26 * @author Matthew Khouzam
47aafe74 27 * @since 3.0
d04ec5a7
MK
28 */
29public class TraceTypeHelper {
30
31 private final String fName;
32 private final String fCategoryName;
33 private final String fCanonicalName;
376fdfbd 34 private final TraceElementType fElementType;
d04ec5a7 35 private final ITmfTrace fTrace;
d8aba2e2 36 private final boolean fIsDirectory;
d04ec5a7
MK
37
38 /**
39 * Constructor for a trace type helper. It is a link between a canonical
40 * (hard to read) name, a category name, a name and a trace object. It is
41 * used for trace validation.
42 *
43 * @param canonicalName
44 * The "path" of the tracetype
45 * @param categoryName
46 * the category of the trace type
47 * @param name
48 * the name of the trace
49 * @param trace
50 * an object of the trace type
d8aba2e2
BH
51 * @param isDir
52 * flag indicating whether the trace type is for a directory or file trace
376fdfbd
GB
53 * @param elementType
54 * True if this helper is for an experiment type
d04ec5a7 55 */
376fdfbd 56 public TraceTypeHelper(String canonicalName, String categoryName, String name, ITmfTrace trace, boolean isDir, TraceElementType elementType) {
d04ec5a7
MK
57 fName = name;
58 fCategoryName = categoryName;
59 fCanonicalName = canonicalName;
60 fTrace = trace;
d8aba2e2 61 fIsDirectory = isDir;
376fdfbd 62 fElementType = elementType;
d04ec5a7
MK
63 }
64
65 /**
66 * Get the name
67 *
68 * @return the name
69 */
70 public String getName() {
71 return fName;
72 }
73
74 /**
75 * Get the category name
76 *
77 * @return the category name
78 */
79 public String getCategoryName() {
80 return fCategoryName;
81 }
82
83 /**
84 * Get the canonical name
85 *
86 * @return the canonical Name
87 */
88 public String getCanonicalName() {
89 return fCanonicalName;
90 }
91
92 /**
93 * Is the trace of this type?
94 *
95 * @param path
96 * the trace to validate
97 * @return whether it passes the validation
98 */
99 public boolean validate(String path) {
100 boolean valid = false;
101 if (fTrace != null) {
102 valid = standardValidate(path);
d04ec5a7
MK
103 }
104 return valid;
105 }
106
350cae41
PT
107 /**
108 * Validate a trace against this trace type with confidence level
109 *
110 * @param path
111 * the trace to validate
112 * @return the confidence level (0 is lowest) or -1 if validation fails
113 * @since 3.0
114 */
115 public int validateWithConfidence(String path) {
116 int result = -1;
117 if (fTrace != null) {
118 IStatus status = fTrace.validate(null, path);
119 if (status.isOK()) {
120 result = 0;
121 if (status instanceof TraceValidationStatus) {
122 result = ((TraceValidationStatus) status).getConfidence();
123 }
124 }
125 }
126 return result;
127 }
128
76fccfb0
MK
129 /**
130 * Get an object of the trace type
131 * @return an object of the trace type
132 * @since 2.1
133 */
0a19e2d1 134 public ITmfTrace getTrace() {
76fccfb0
MK
135 return fTrace;
136 }
137
376fdfbd
GB
138 /**
139 * Return whether this helper applies to a trace type or experiment type
140 *
141 * @return True if experiment type, false otherwise
142 */
143 public boolean isExperimentType() {
144 return fElementType == TraceElementType.EXPERIMENT;
145 }
146
d04ec5a7 147 private boolean standardValidate(String path) {
bcb8c2cb 148 final boolean valid = fTrace.validate(null, path).isOK();
d04ec5a7
MK
149 return valid;
150 }
151
c068a752
GB
152 /**
153 * Get the class associated with this trace type
154 *
155 * @return The trace class
156 * @since 3.0
157 */
158 public Class<? extends ITmfTrace> getTraceClass() {
159 return fTrace.getClass();
160 }
161
d8aba2e2
BH
162 /**
163 * Returns whether trace type is for a directory trace or a single file trace
164 * @return <code>true</code> if trace type is for a directory trace else <code>false</code>
165 */
166 public boolean isDirectoryTraceType() {
167 return fIsDirectory;
168 }
169
170
d04ec5a7
MK
171 @Override
172 public String toString() {
173 return fName;
174 }
175
bcb8c2cb 176}
This page took 0.059069 seconds and 5 git commands to generate.