public void setupTabPane()

in src/components/src/main/java/org/apache/jmeter/visualizers/SamplerResultTab.java [249:463]


    public void setupTabPane() {
        // Clear all data before display a new
        this.clearData();
        StyledDocument statsDoc = stats.getStyledDocument();
        try {
            if (userObject instanceof SampleResult) {
                sampleResult = (SampleResult) userObject;
                // We are displaying a SampleResult
                setupTabPaneForSampleResult();
                requestPanel.setSamplerResult(sampleResult);

                final String samplerClass = sampleResult.getClass().getName();
                String typeResult = samplerClass.substring(1 + samplerClass.lastIndexOf('.'));

                StringBuilder statsBuff = new StringBuilder(200);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_thread_name")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getThreadName()).append(NL);
                String startTime = dateFormat
                        .format(Instant.ofEpochMilli(sampleResult.getStartTime()));
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_sample_start")).append(SPACE) //$NON-NLS-1$
                        .append(startTime).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_load_time")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getTime()).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_connect_time")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getConnectTime()).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_latency")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getLatency()).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_size_in_bytes")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getBytesAsLong()).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_sent_bytes")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getSentBytes()).append(NL);
                statsBuff
                        .append(JMeterUtils.getResString(
                                "view_results_size_headers_in_bytes")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getHeadersSize()).append(NL);
                statsBuff
                        .append(JMeterUtils.getResString(
                                "view_results_size_body_in_bytes")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getBodySizeAsLong()).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_sample_count")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getSampleCount()).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_error_count")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getErrorCount()).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_datatype")).append(SPACE) //$NON-NLS-1$
                        .append(sampleResult.getDataType()).append(NL);
                statsDoc.insertString(statsDoc.getLength(),
                        statsBuff.toString(), null);
                statsBuff.setLength(0); // reset for reuse

                String responseCode = sampleResult.getResponseCode();

                int responseLevel = 0;
                if (responseCode != null) {
                    try {
                        responseLevel = Integer.parseInt(responseCode) / 100;
                    } catch (NumberFormatException numberFormatException) {
                        // no need to change the foreground color
                    }
                }

                Style style = null;
                switch (responseLevel) {
                case 3:
                    style = statsDoc.getStyle(STYLE_REDIRECT);
                    break;
                case 4:
                    style = statsDoc.getStyle(STYLE_CLIENT_ERROR);
                    break;
                case 5:
                    style = statsDoc.getStyle(STYLE_SERVER_ERROR);
                    break;
                default: // quieten Findbugs
                    break; // default - do nothing
                }

                statsBuff.append(JMeterUtils.getResString("view_results_response_code")).append(responseCode).append(NL); //$NON-NLS-1$
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), style);
                statsBuff.setLength(0); // reset for reuse

                // response message label
                String responseMsgStr = sampleResult.getResponseMessage();

                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_response_message")) //$NON-NLS-1$
                        .append(responseMsgStr).append(NL);
                statsBuff.append(NL);
                statsBuff.append(NL);
                statsBuff
                        .append(typeResult + " " //$NON-NLS-1$
                                + JMeterUtils
                                        .getResString("view_results_fields"))
                        .append(NL); // $NON-NLS-2$
                statsBuff.append("ContentType: ") //$NON-NLS-1$
                        .append(sampleResult.getContentType()).append(NL);
                statsBuff.append("DataEncoding: ") //$NON-NLS-1$
                        .append(sampleResult.getDataEncodingNoDefault())
                        .append(NL);
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
                statsBuff = null; // NOSONAR Help gc

                // Tabbed results: fill table
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel("view_results_thread_name"), //$NON-NLS-1$
                        sampleResult.getThreadName()));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel("view_results_sample_start"), //$NON-NLS-1$
                        startTime));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel("view_results_load_time"), //$NON-NLS-1$
                        sampleResult.getTime()));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel("view_results_connect_time"), //$NON-NLS-1$
                        sampleResult.getConnectTime()));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel("view_results_latency"), //$NON-NLS-1$
                        sampleResult.getLatency()));
                resultModel.addRow(new RowResult(
                        JMeterUtils
                                .getParsedLabel("view_results_size_in_bytes"), //$NON-NLS-1$
                        sampleResult.getBytesAsLong()));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel("view_results_sent_bytes"), //$NON-NLS-1$
                        sampleResult.getSentBytes()));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel(
                                "view_results_size_headers_in_bytes"), //$NON-NLS-1$
                        sampleResult.getHeadersSize()));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel(
                                "view_results_size_body_in_bytes"), //$NON-NLS-1$
                        sampleResult.getBodySizeAsLong()));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel("view_results_sample_count"), //$NON-NLS-1$
                        sampleResult.getSampleCount()));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel("view_results_error_count"), //$NON-NLS-1$
                        sampleResult.getErrorCount()));
                resultModel
                        .addRow(new RowResult(
                                JMeterUtils.getParsedLabel(
                                        "view_results_response_code"), //$NON-NLS-1$
                                responseCode));
                resultModel.addRow(new RowResult(
                        JMeterUtils.getParsedLabel(
                                "view_results_response_message"), //$NON-NLS-1$
                        responseMsgStr));

                // Parsed response headers
                LinkedHashMap<String, String> lhm = JMeterUtils.parseHeaders(sampleResult.getResponseHeaders());
                Set<Map.Entry<String, String>> keySet = lhm.entrySet();
                for (Map.Entry<String, String> entry : keySet) {
                    resHeadersModel.addRow(new RowResult(entry.getKey(), entry.getValue()));
                }

                headerData.setInitialText(sampleResult.getResponseHeaders());

                // Fields table
                resFieldsModel.addRow(new RowResult("Type Result ", typeResult)); //$NON-NLS-1$
                //not sure needs I18N?
                resFieldsModel.addRow(new RowResult("ContentType", sampleResult.getContentType())); //$NON-NLS-1$
                resFieldsModel.addRow(new RowResult("DataEncoding", sampleResult.getDataEncodingNoDefault())); //$NON-NLS-1$

                // Reset search
                if (activateSearchExtension) {
                    searchTextExtension.resetTextToFind();
                }

            } else if (userObject instanceof AssertionResult) {
                assertionResult = (AssertionResult) userObject;

                // We are displaying an AssertionResult
                setupTabPaneForAssertionResult();

                StringBuilder statsBuff = new StringBuilder(100);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_assertion_error")) //$NON-NLS-1$
                        .append(assertionResult.isError()).append(NL);
                statsBuff
                        .append(JMeterUtils
                                .getResString("view_results_assertion_failure")) //$NON-NLS-1$
                        .append(assertionResult.isFailure()).append(NL);
                statsBuff
                        .append(JMeterUtils.getResString(
                                "view_results_assertion_failure_message")) //$NON-NLS-1$
                        .append(assertionResult.getFailureMessage()).append(NL);
                statsDoc.insertString(statsDoc.getLength(),
                        statsBuff.toString(), null);
            }
            stats.setCaretPosition(1);
        } catch (BadLocationException exc) {
            stats.setText(exc.getLocalizedMessage());
        }
    }