use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.
the class XmlXyDataProviderTest method assertAndGetTree.
private static Map<Long, String> assertAndGetTree(ITmfTreeXYDataProvider<@NonNull ITmfTreeDataModel> xyProvider, ITmfTrace trace, List<String> expectedStrings) {
TmfModelResponse<@NonNull TmfTreeModel<@NonNull ITmfTreeDataModel>> treeResponse = xyProvider.fetchTree(FetchParametersUtils.timeQueryToMap(new TimeQueryFilter(0, Long.MAX_VALUE, 2)), MONITOR);
assertNotNull(treeResponse);
assertEquals(ITmfResponse.Status.COMPLETED, treeResponse.getStatus());
TmfTreeModel<@NonNull ITmfTreeDataModel> treeModel = treeResponse.getModel();
assertNotNull(treeModel);
List<@NonNull ITmfTreeDataModel> treeEntries = treeModel.getEntries();
Map<Long, String> map = new HashMap<>();
for (int i = 0; i < expectedStrings.size(); i++) {
String expectedString = expectedStrings.get(i);
assertTrue("actual entry absent at " + i + ": " + expectedString, treeEntries.size() > i);
String[] split = expectedString.split(",");
ITmfTreeDataModel xmlXyEntry = treeEntries.get(i);
assertEquals("Checking entry name at " + i, split[0], xmlXyEntry.getName());
// Check the parent
long parentId = xmlXyEntry.getParentId();
if (parentId < 0) {
assertEquals("Checking empty parent at " + i, split[1], "null");
} else {
String parentName = map.get(parentId);
assertEquals("Checking parent at " + i, split[1], parentName);
}
map.put(xmlXyEntry.getId(), xmlXyEntry.getName());
}
assertEquals("Extra actual entries", expectedStrings.size(), treeEntries.size());
return map;
}
use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.
the class TmfTreeModelTest method initClass.
/**
* Run once
*/
@BeforeClass
public static void initClass() {
for (int i = 0; i < NB_COLUMNS; i++) {
String headerText = HEADER_PREFIX + String.valueOf(i);
String headerTooltip = TOOLTIP_PREFIX + String.valueOf(i);
fTestHeaders.add(headerText);
fExpectedEmptyTooltips.add("");
fExpectedTooltips.add(headerTooltip);
TableColumnDescriptor.Builder descBuilder = new TableColumnDescriptor.Builder();
descBuilder.setText(headerText);
descBuilder.setTooltip(headerTooltip);
fTestDescriptors.add(descBuilder.build());
}
for (int k = 0; k < NB_ROWS; k++) {
List<String> labels = new ArrayList<>();
for (int i = 0; i < NB_COLUMNS; i++) {
labels.add(LABEL_PREFIX + String.valueOf(i));
}
ITmfTreeDataModel dataModel = new TmfTreeDataModelStub(k, PARENT_ID, labels);
fTestEntries.add(dataModel);
}
}
use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.
the class AbstractSelectTreeViewer2 method modelToTree.
/**
* Algorithm to convert a model (List of {@link TmfTreeDataModel}) to the tree.
*
* @param start
* queried start time
* @param end
* queried end time
* @param model
* model to convert
* @return the resulting {@link TmfTreeViewerEntry}.
*/
protected ITmfTreeViewerEntry modelToTree(long start, long end, List<ITmfTreeDataModel> model) {
TmfTreeViewerEntry root = new TmfTreeViewerEntry(StringUtils.EMPTY);
Map<Long, TmfTreeViewerEntry> map = new HashMap<>();
map.put(-1L, root);
for (ITmfTreeDataModel entry : model) {
TmfGenericTreeEntry<ITmfTreeDataModel> viewerEntry = new TmfGenericTreeEntry<>(entry);
map.put(entry.getId(), viewerEntry);
TmfTreeViewerEntry parent = map.get(entry.getParentId());
if (parent != null && !parent.getChildren().contains(viewerEntry)) {
parent.addChild(viewerEntry);
}
}
return root;
}
use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.
the class AbstractSelectTreeViewer2 method updateContent.
@Override
protected void updateContent(long start, long end, boolean isSelection) {
try (FlowScopeLog scope = new FlowScopeLogBuilder(LOGGER, Level.FINE, UPDATE_CONTENT_JOB_NAME).setCategory(fLogCategory).build()) {
ITmfTrace trace = getTrace();
if (trace == null) {
return;
}
Job thread = new Job(UPDATE_CONTENT_JOB_NAME) {
@Override
public IStatus run(IProgressMonitor monitor) {
try (FlowScopeLog runScope = // $NON-NLS-1$
new FlowScopeLogBuilder(LOGGER, Level.FINE, UPDATE_CONTENT_JOB_NAME + " run").setParentScope(scope).build()) {
ITmfTreeDataProvider<@NonNull ITmfTreeDataModel> provider = getProvider(trace);
if (provider == null) {
return Status.OK_STATUS;
}
Map<String, Object> parameters = getParameters(start, end, isSelection);
if (parameters.isEmpty()) {
return Status.OK_STATUS;
}
boolean isComplete = false;
double factor = 1.0;
do {
TmfModelResponse<@NonNull TmfTreeModel<@NonNull ITmfTreeDataModel>> response;
try (FlowScopeLog iterScope = // $NON-NLS-1$
new FlowScopeLogBuilder(LOGGER, Level.FINE, UPDATE_CONTENT_JOB_NAME + " query").setParentScope(scope).build()) {
response = provider.fetchTree(parameters, monitor);
TmfTreeModel<@NonNull ITmfTreeDataModel> model = response.getModel();
if (model != null) {
updateTree(trace, start, end, model.getEntries());
}
}
ITmfResponse.Status status = response.getStatus();
if (status == ITmfResponse.Status.COMPLETED) {
/* Model is complete, no need to request again the data provider */
isComplete = true;
} else if (status == ITmfResponse.Status.FAILED || status == ITmfResponse.Status.CANCELLED) {
/* Error occurred, return */
isComplete = true;
} else {
/**
* Status is RUNNING. Sleeping current thread to wait before request data
* provider again
*/
try {
Thread.sleep((long) (BUILD_UPDATE_TIMEOUT * factor));
factor = Math.min(20, factor + 1);
} catch (InterruptedException e) {
/**
* InterruptedException is throw by Thread.Sleep and we should retry querying
* the data provider
*/
runScope.addData(FAILED_TO_SLEEP_PREFIX + getName(), e);
Thread.currentThread().interrupt();
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, FAILED_TO_SLEEP_PREFIX + getName());
}
}
} while (!isComplete);
return Status.OK_STATUS;
}
}
};
thread.setSystem(true);
thread.schedule();
}
}
use of org.eclipse.tracecompass.tmf.core.model.tree.ITmfTreeDataModel in project tracecompass by tracecompass.
the class StateSystemPresentationProvider method getStateTableIndex.
@Override
public int getStateTableIndex(ITimeEvent event) {
if (event instanceof TimeEvent) {
TimeEvent timeEvent = (TimeEvent) event;
Object value = timeEvent.getLabel();
if (value != null) {
return Math.floorMod(value.hashCode(), NUM_COLORS);
}
ITimeGraphEntry entry = event.getEntry();
if (entry != null) {
ITmfTreeDataModel model = ((TimeGraphEntry) entry).getEntryModel();
if (model instanceof StateSystemEntryModel || model instanceof ModuleEntryModel) {
// tooltip
return INVISIBLE;
}
}
// grey
return NUM_COLORS;
}
return INVISIBLE;
}
Aggregations