Search in sources :

Example 1 with ITmfCommonXAxisModel

use of org.eclipse.tracecompass.tmf.core.model.xy.ITmfCommonXAxisModel in project tracecompass by tracecompass.

the class TmfTreeXYCompositeDataProvider method fetchXY.

@Override
public TmfModelResponse<ITmfXyModel> fetchXY(Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) {
    /**
     * <pre>
     * Response status according to the provider's reponse statuses:
     *
     * * Cancelled -> The monitor is cancelled
     * * Failed -> At least one provider has failed
     * * Running -> At least one of the providers is running
     * * Completed -> All providers have completed
     * </pre>
     */
    List<P> providers = getProviders();
    // Get all the responses
    Collection<TmfModelResponse<ITmfXyModel>> responses = getXyResponses(fetchParameters, monitor, providers);
    if (monitor != null && monitor.isCanceled()) {
        return TmfXyResponseFactory.createCancelledResponse(CommonStatusMessage.TASK_CANCELLED);
    }
    // If one response is failed, return a failed response with a concatenation of the messages
    String failedMsg = handleFailedStatus(responses);
    if (failedMsg != null) {
        return TmfXyResponseFactory.createFailedResponse(failedMsg);
    }
    boolean allCommon = Iterables.all(providers, ITmfCommonXAxisModel.class::isInstance);
    // The query is considered complete if all providers are completed
    boolean isComplete = Iterables.all(responses, response -> response.getStatus() == ITmfResponse.Status.COMPLETED);
    if (allCommon) {
        ImmutableList.Builder<IYModel> series = ImmutableList.builder();
        responses.forEach(response -> {
            ITmfCommonXAxisModel model = (ITmfCommonXAxisModel) response.getModel();
            if (model != null) {
                series.addAll(model.getYSeriesData());
            }
        });
        TimeQueryFilter filter = FetchParametersUtils.createTimeQuery(fetchParameters);
        if (filter == null) {
            return TmfXyResponseFactory.createFailedResponse(CommonStatusMessage.INCORRECT_QUERY_PARAMETERS);
        }
        return TmfXyResponseFactory.create(fTitle, filter.getTimesRequested(), series.build(), isComplete);
    }
    ImmutableList.Builder<ISeriesModel> series = ImmutableList.builder();
    responses.forEach(response -> {
        ITmfXyModel model = response.getModel();
        if (model != null) {
            series.addAll(model.getSeriesData());
        }
    });
    return TmfXyResponseFactory.create(fTitle, series.build(), isComplete);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ITmfCommonXAxisModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfCommonXAxisModel) ISeriesModel(org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel) TmfModelResponse(org.eclipse.tracecompass.tmf.core.response.TmfModelResponse) IYModel(org.eclipse.tracecompass.tmf.core.model.xy.IYModel) TimeQueryFilter(org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter) ITmfXyModel(org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 TimeQueryFilter (org.eclipse.tracecompass.tmf.core.model.filters.TimeQueryFilter)1 ISeriesModel (org.eclipse.tracecompass.tmf.core.model.xy.ISeriesModel)1 ITmfCommonXAxisModel (org.eclipse.tracecompass.tmf.core.model.xy.ITmfCommonXAxisModel)1 ITmfXyModel (org.eclipse.tracecompass.tmf.core.model.xy.ITmfXyModel)1 IYModel (org.eclipse.tracecompass.tmf.core.model.xy.IYModel)1 TmfModelResponse (org.eclipse.tracecompass.tmf.core.response.TmfModelResponse)1