*
* Contributors:
* Alexandre Montplaisir - Initial API and implementation
+ * Patrick Tasse - Add support for folder elements
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
import java.util.TreeSet;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceImportException;
import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType;
+import org.eclipse.linuxtools.tmf.core.project.model.TmfTraceType.TraceElementType;
import org.eclipse.linuxtools.tmf.core.project.model.TraceTypeHelper;
import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
import org.eclipse.linuxtools.tmf.core.util.Pair;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
/** Extension point element 'type' (should match the type in TmfTraceType) */
public static final String TYPE_ELEM = "type"; //$NON-NLS-1$
+ /**
+ * Extension point element 'experiment' (should match the type in
+ * TmfTraceType)
+ */
+ public static final String EXPERIMENT_ELEM = "experiment"; //$NON-NLS-1$
+
/** Extension point element 'Default editor' */
public static final String DEFAULT_EDITOR_ELEM = "defaultEditor"; //$NON-NLS-1$
private static final char SEPARATOR = ':';
- private TmfTraceTypeUIUtils() {}
+ private TmfTraceTypeUIUtils() {
+ }
private static List<Pair<Integer, TraceTypeHelper>> reduce(List<Pair<Integer, TraceTypeHelper>> candidates) {
List<Pair<Integer, TraceTypeHelper>> retVal = new ArrayList<>();
return count == 0;
}
-
/**
* Is the trace type id a custom (user-defined) trace type. These are the
* traces like : text and xml defined by the custom trace wizard.
TreeSet<Pair<Integer, TraceTypeHelper>> validCandidates = new TreeSet<>(comparator);
final Iterable<TraceTypeHelper> traceTypeHelpers = type.getTraceTypeHelpers();
for (TraceTypeHelper traceTypeHelper : traceTypeHelpers) {
+ if (traceTypeHelper.isExperimentType()) {
+ continue;
+ }
int confidence = traceTypeHelper.validateWithConfidence(path);
if (confidence >= 0) {
// insert in the tree map, ordered by confidence (highest confidence first) then name
TraceTypeHelper traceTypeToSet = null;
if (validCandidates.isEmpty()) {
- final String errorMsg = Messages.TmfOpenTraceHelper_NoTraceTypeMatch + path;
+ final String errorMsg = NLS.bind(Messages.TmfOpenTraceHelper_NoTraceTypeMatch, path);
throw new TmfTraceImportException(errorMsg);
} else if (validCandidates.size() != 1) {
List<Pair<Integer, TraceTypeHelper>> candidates = new ArrayList<>(validCandidates);
return traceTypeToSet;
}
-
/**
* Set the trace type of a {@Link TraceTypeHelper}. Should only be
* used internally by this project.
*
- * @param path
- * the {@link IPath} path of the resource to set
+ * @param resource
+ * the resource to set
* @param traceType
* the {@link TraceTypeHelper} to set the trace type to.
* @return Status.OK_Status if successful, error is otherwise.
* @throws CoreException
* An exception caused by accessing eclipse project items.
*/
- public static IStatus setTraceType(IPath path, TraceTypeHelper traceType) throws CoreException {
- IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
+ public static IStatus setTraceType(IResource resource, TraceTypeHelper traceType) throws CoreException {
String traceTypeId = traceType.getCanonicalName();
resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceTypeId);
TmfProjectElement tmfProject = TmfProjectRegistry.getProject(resource.getProject(), true);
- final TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
- List<TmfTraceElement> traces = tracesFolder.getTraces();
- for (TmfTraceElement traceElement : traces) {
- if (traceElement.getName().equals(resource.getName())) {
- traceElement.refreshTraceType();
- break;
+ if (tmfProject.getTracesFolder().getPath().isPrefixOf(resource.getFullPath())) {
+ String elementPath = resource.getFullPath().makeRelativeTo(tmfProject.getTracesFolder().getPath()).toString();
+ refreshTraceElement(tmfProject.getTracesFolder().getTraces(), elementPath);
+ } else if (resource.getParent().equals(tmfProject.getExperimentsFolder().getResource())) {
+ /* The trace type to set is for an experiment */
+ for (TmfExperimentElement experimentElement : tmfProject.getExperimentsFolder().getExperiments()) {
+ if (resource.equals(experimentElement.getResource())) {
+ experimentElement.refreshTraceType();
+ break;
+ }
+ }
+ } else {
+ for (TmfExperimentElement experimentElement : tmfProject.getExperimentsFolder().getExperiments()) {
+ if (experimentElement.getPath().isPrefixOf(resource.getFullPath())) {
+ String elementPath = resource.getFullPath().makeRelativeTo(experimentElement.getPath()).toString();
+ refreshTraceElement(experimentElement.getTraces(), elementPath);
+ break;
+ }
}
}
tmfProject.refresh();
return Status.OK_STATUS;
}
+ private static void refreshTraceElement(List<TmfTraceElement> traceElements, String elementPath) {
+ for (TmfTraceElement traceElement : traceElements) {
+ if (traceElement.getElementPath().equals(elementPath)) {
+ traceElement.refreshTraceType();
+ break;
+ }
+ }
+ }
+
/**
* Retrieves all configuration elements from the platform extension registry
* for the trace type UI extension.
*
+ * @param elType
+ * The type of trace type requested, either TRACE or EXPERIMENT
* @return An array of trace type configuration elements
*/
- public static IConfigurationElement[] getTypeUIElements() {
+ public static IConfigurationElement[] getTypeUIElements(TraceElementType elType) {
+ String elementName = TYPE_ELEM;
+ if (elType == TraceElementType.EXPERIMENT) {
+ elementName = EXPERIMENT_ELEM;
+ }
IConfigurationElement[] elements =
Platform.getExtensionRegistry().getConfigurationElementsFor(TMF_TRACE_TYPE_UI_ID);
List<IConfigurationElement> typeElements = new LinkedList<>();
for (IConfigurationElement element : elements) {
- if (element.getName().equals(TYPE_ELEM)) {
+ if (element.getName().equals(elementName)) {
typeElements.add(element);
}
}
*
* @param traceType
* The tracetype ID
+ * @param elType
+ * The type of trace type requested, either TRACE or EXPERIMENT
* @return The top-level configuration element (access its children with
* .getChildren()). Or null if there is no such element.
*/
@Nullable
- public static IConfigurationElement getTraceUIAttributes(String traceType) {
- IConfigurationElement[] elements = getTypeUIElements();
+ public static IConfigurationElement getTraceUIAttributes(String traceType, TraceElementType elType) {
+ IConfigurationElement[] elements = getTypeUIElements(elType);
for (IConfigurationElement ce : elements) {
if (traceType.equals(ce.getAttribute(TRACETYPE_ATTR))) {
return ce;