Example usage for com.google.gwt.json.client JSONValue isObject

List of usage examples for com.google.gwt.json.client JSONValue isObject

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isObject.

Prototype

public JSONObject isObject() 

Source Link

Document

Returns non-null if this JSONValue is really a JSONObject.

Usage

From source file:org.ednovo.gooru.client.mvp.assessments.play.collection.end.AssessmentsEndView.java

License:Open Source License

@Override
public void setQuestionsData(final ArrayList<UserDataDo> result) {

    loadingImageLabel.setVisible(false);
    questionsTable.setVisible(true);//from  w  ww  .  j a  va  2  s  . c  o m
    questionsTable.clear();
    if (isTableToDestroy) {
        isTableToDestroy = false;
        destoryTables();
    }

    if (result.size() > 0) {
        final AdvancedFlexTable adTable = new AdvancedFlexTable();
        adTable.removeAllRows();
        adTable.getElement().setId("report-student-assessment-report");
        adTable.addStyleName("table table-bordered reportTableStyle");
        questionsTable.add(adTable);

        Label heading1 = new Label(i18n.GL3259());
        Label heading2 = new Label(i18n.GL0308());
        Label heading3 = new Label(i18n.GL0315());
        Label heading4 = new Label(i18n.GL2288());
        Label heading5 = new Label(i18n.GL2084());
        Label heading6 = new Label(i18n.GL3271());

        heading1.addStyleName("headingLabel");
        heading2.addStyleName("headingLabel");
        heading3.addStyleName("headingLabel");
        heading4.addStyleName("headingLabel");
        heading5.addStyleName("headingLabel");
        heading6.addStyleName("headingLabel");

        adTable.setHeaderWidget(0, heading1);
        adTable.setHeaderWidget(1, heading2);
        adTable.setHeaderWidget(2, heading3);
        adTable.setHeaderWidget(3, heading4);
        adTable.setHeaderWidget(4, heading5);
        adTable.setHeaderWidget(5, heading6);
        for (int i = 0; i < result.size(); i++) {
            Label questionTitle = new Label(
                    AnalyticsUtil.html2text(result.get(i).getTitle() != null ? result.get(i).getTitle() : ""));
            questionTitle.setStyleName(STYLE_TABLE_CENTER);
            questionTitle.setStyleName(STYLE_TXTLEFT);
            adTable.setWidget(i, 0, new Label(String.valueOf(i + 1)));
            adTable.setWidget(i, 1, questionTitle);

            int noOfAttempts = result.get(i).getAttempts();
            String scoreStatus = result.get(i).getStatus();

            //Set Answer choices
            String questionType = result.get(i).getType();
            if (questionType.equalsIgnoreCase("HS")) {
                questionType = result.get(i).getQuestionType();
            }
            if (MC.equalsIgnoreCase(questionType) || TF.equalsIgnoreCase(questionType)
                    || TSLASHF.equalsIgnoreCase(questionType)) {
                Label anserlbl = new Label();
                if (result.get(i).getMetaData() != null && result.get(i).getOptions() != null) {
                    Map<String, Integer> authorObject = result.get(i).getOptions();

                    for (Map.Entry<String, Integer> entry : authorObject.entrySet()) {
                        String userSelectedOption = entry.getKey();
                        // int ansStatus=entry.getValue();
                        if (userSelectedOption != null) {
                            anserlbl.setText(userSelectedOption);
                            if (STATUS_CORRECT.equalsIgnoreCase(scoreStatus) && noOfAttempts == 1) {
                                anserlbl.getElement().getStyle().setColor(CORRECT);
                            } else if (STATUS_CORRECT.equalsIgnoreCase(scoreStatus) && noOfAttempts > 1) {
                                anserlbl.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                            } else {
                                anserlbl.getElement().getStyle().setColor(INCORRECT);
                            }
                        }
                    }
                }
                anserlbl.setStyleName(STYLE_TABLE_CENTER);
                adTable.setWidget(i, 2, anserlbl);
            } else if (FIB.equalsIgnoreCase(questionType)) {
                VerticalPanel answerspnl = new VerticalPanel();
                if (result.get(i).getMetaData() != null && result.get(i).getOptions() != null) {
                    String answerTextFormat = "";
                    String[] answersArry = null;
                    ArrayList<MetaDataDo> questionList = result.get(i).getMetaData();

                    for (MetaDataDo metaDataDo : questionList) {

                        String answerText = "";
                        if ((metaDataDo.getAnswerText() != null)) {
                            String text = StringUtil.removeAllHtmlCss(removeHtmlTags(
                                    InfoUtil.removeQuestionTagsOnBoldClick(metaDataDo.getAnswerText())));
                            answerText = text;
                        }
                        answerTextFormat += '[' + answerText + ']';
                        if (questionList.size() != metaDataDo.getSequence()) {
                            answerTextFormat += ",";
                        }
                    }
                    String[] userFibOption = null;
                    if (result.get(i).getText() != null) {
                        answersArry = answerTextFormat.split(",");
                        userFibOption = result.get(i).getText().split(",");
                    }
                    if (answersArry != null && userFibOption != null) {
                        for (int k = 0; k < answersArry.length; k++) {
                            Label answerChoice = new Label();
                            if (answersArry[k] != null && k < userFibOption.length) {
                                if ((answersArry[k].toLowerCase().trim()
                                        .equalsIgnoreCase(userFibOption[k].toLowerCase().trim()))
                                        && (noOfAttempts == 1)) {
                                    answerChoice.setText(userFibOption[k]);
                                    answerChoice.getElement().getStyle().setColor(CORRECT);
                                } else if ((answersArry[k].toLowerCase().trim()
                                        .equalsIgnoreCase(userFibOption[k].toLowerCase().trim()))
                                        && (noOfAttempts > 1)) {
                                    answerChoice.setText(userFibOption[k]);
                                    answerChoice.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                                } else {
                                    answerChoice.setText(userFibOption[k]);
                                    answerChoice.getElement().getStyle().setColor(INCORRECT);
                                }
                                answerChoice.setStyleName(STYLE_TABLE_CENTER);
                                answerspnl.add(answerChoice);
                            }
                        }
                    }
                }
                answerspnl.setStyleName(STYLE_MARGIN_AUTO);
                adTable.setWidget(i, 2, answerspnl);
                //data.setValue(i, 2, answerspnl.toString());
            } else if (MA.equalsIgnoreCase(questionType)) {
                VerticalPanel answerspnl = new VerticalPanel();
                if (result.get(i).getAnswerObject() != null) {
                    JSONValue value = JSONParser.parseStrict(result.get(i).getAnswerObject());
                    JSONObject answerObject = value.isObject();
                    Set<String> keys = answerObject.keySet();
                    Iterator<String> itr = keys.iterator();
                    while (itr.hasNext()) {
                        answerspnl.clear();
                        JSONArray attemptsObj = (JSONArray) answerObject.get(itr.next().toString());
                        for (int j = 0; j < attemptsObj.size(); j++) {
                            Label answerChoice = new Label();
                            String showMessage = null;
                            boolean skip = attemptsObj.get(j).isObject().get("skip").isBoolean().booleanValue();
                            String status = attemptsObj.get(j).isObject().get("status").isString()
                                    .stringValue();
                            String matext = attemptsObj.get(j).isObject().get("text").isString().stringValue();
                            if (skip == false) {
                                if (ZERO_NUMERIC.equalsIgnoreCase(matext)) {
                                    showMessage = i18n.GL_GRR_NO();
                                } else if (ONE.equalsIgnoreCase(matext)) {
                                    showMessage = i18n.GL_GRR_YES();
                                }
                                answerChoice.setText(showMessage);
                                if (ZERO_NUMERIC.equalsIgnoreCase(status)) {
                                    answerChoice.getElement().getStyle().setColor(INCORRECT);
                                } else if (ONE.equalsIgnoreCase(status) && (noOfAttempts == 1)) {
                                    answerChoice.getElement().getStyle().setColor(CORRECT);
                                } else if (ONE.equalsIgnoreCase(status) && (noOfAttempts > 1)) {
                                    answerChoice.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                                }
                            }
                            answerChoice.setStyleName(STYLE_TABLE_CENTER);
                            answerspnl.add(answerChoice);
                        }
                    }
                }
                answerspnl.setStyleName(STYLE_MARGIN_AUTO);
                adTable.setWidget(i, 2, answerspnl);
            } else if (HT_RO.equalsIgnoreCase(questionType) || HT_HL.equalsIgnoreCase(questionType)
                    || HS_TXT.equalsIgnoreCase(questionType) || HS_IMG.equalsIgnoreCase(questionType)) {
                if (result.get(i).getAnswerObject() != null
                        && !result.get(i).getStatus().equalsIgnoreCase("skipped")) {
                    Label viewResponselbl = new Label(VIEWRESPONSE);
                    viewResponselbl.setStyleName("summaryViewResponse");
                    viewResponselbl.getElement().setAttribute("resourceGooruId",
                            result.get(i).getResourceGooruOId());
                    viewResponselbl.getElement().setAttribute("questionType", result.get(i).getType());
                    viewResponselbl.getElement().setAttribute("answerObj", result.get(i).getAnswerObject());
                    viewResponselbl.getElement().setAttribute("attempts", String.valueOf(noOfAttempts));
                    viewResponselbl.addClickHandler(new SummaryPopupClick(result.get(i)));
                    adTable.setWidget(i, 2, viewResponselbl);
                }
            }

            //Set attempts
            Label attempts = new Label(i18n.GL2269());
            attempts.setStyleName(STYLE_TABLE_CENTER);
            attempts.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);

            if (STATUS_INCORRECT.equalsIgnoreCase(scoreStatus)) {
                adTable.setWidget(i, 3, attempts);
                adTable.getRowFormatter().addStyleName(i, STYLE_WHITE);
            } else if (STATUS_CORRECT.equalsIgnoreCase(scoreStatus)) {
                Image correctImg = new Image();
                correctImg.setUrl(urlDomain + "/images/analytics/tick.png");
                adTable.setWidget(i, 3, correctImg);
                adTable.getRowFormatter().addStyleName(i, STYLE_GREEN);
            }

            //Set time spent
            adTable.setWidget(i, 4, AnalyticsUtil.getTimeStampLabel(result.get(i).getTimeSpent()));

            //Set reactions
            int reaction = result.get(i).getReaction();
            adTable.setWidget(i, 5, new AnalyticsReactionWidget(reaction));
        }
        //         sortAndFixed();

    } else {
        Label erroeMsg = new Label();
        erroeMsg.setStyleName(STYLE_ERROR_MSG);
        erroeMsg.setText(i18n.GL3265());
        questionsTable.add(erroeMsg);
    }

}

From source file:org.ednovo.gooru.client.mvp.assessments.play.collection.end.AssessmentsEndView.java

License:Open Source License

@Override
public void setQuestionsPrintData(final ArrayList<UserDataDo> result) {
    loadingImageLabel.setVisible(false);
    try {/*w  w  w .  ja v a2 s  .c  o m*/
        printScoredData.clear();
        boolean isTickdisplay = false;
        DataTable data = DataTable.create();
        data.addColumn(ColumnType.NUMBER, i18n.GL3259());
        data.addColumn(ColumnType.STRING, i18n.GL0308());
        data.addColumn(ColumnType.STRING, i18n.GL2288());
        data.addColumn(ColumnType.STRING, i18n.GL3269());
        //         data.addColumn(ColumnType.STRING, i18n.GL3270());
        data.addColumn(ColumnType.STRING, i18n.GL2084());
        data.addColumn(ColumnType.STRING, i18n.GL3271());

        data.addRows(result.size());
        if (result.size() != 0) {
            for (int i = 0; i < result.size(); i++) {
                isTickdisplay = false;
                data.setCell(i, 0, result.get(i).getSequence(), null, getPropertiesCell());

                Label questionTitle = new Label(AnalyticsUtil
                        .html2text(result.get(i).getTitle() != null ? result.get(i).getTitle() : ""));
                questionTitle.setStyleName(STYLE_TABLE_CENTER);
                questionTitle.setStyleName(STYLE_TXTLEFT);
                data.setValue(i, 1, questionTitle.toString());
                int noOfAttempts = result.get(i).getAttempts();
                String scoreStatus = result.get(i).getStatus();

                //Set Answer choices
                String questionType = result.get(i).getType();
                if (questionType.equalsIgnoreCase("HS")) {
                    questionType = result.get(i).getQuestionType();
                }
                if (questionType.equalsIgnoreCase(MC) || questionType.equalsIgnoreCase(TF)
                        || questionType.equalsIgnoreCase(TSLASHF)) {
                    Label anserlbl = new Label();
                    if (result.get(i).getMetaData() != null && result.get(i).getOptions() != null) {
                        Map<String, Integer> authorObject = result.get(i).getOptions();
                        for (Map.Entry<String, Integer> entry : authorObject.entrySet()) {
                            String userSelectedOption = entry.getKey();

                            if (userSelectedOption != null) {
                                anserlbl.setText(userSelectedOption);
                                if (STATUS_CORRECT.equalsIgnoreCase(scoreStatus) && noOfAttempts == 1) {
                                    anserlbl.getElement().getStyle().setColor(CORRECT);
                                    isTickdisplay = true;
                                } else if (STATUS_CORRECT.equalsIgnoreCase(scoreStatus) && noOfAttempts > 1) {
                                    anserlbl.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                                } else {
                                    anserlbl.getElement().getStyle().setColor(INCORRECT);
                                }
                            }
                        }
                    }
                    anserlbl.setStyleName(STYLE_TABLE_CENTER);
                    data.setValue(i, 3, anserlbl.toString());
                } else if (FIB.equalsIgnoreCase(questionType)) {
                    VerticalPanel answerspnl = new VerticalPanel();
                    if (result.get(i).getMetaData() != null && result.get(i).getOptions() != null) {
                        String answerTextFormat = "";
                        String[] answersArry = null;
                        ArrayList<MetaDataDo> questionList = result.get(i).getMetaData();
                        for (MetaDataDo metaDataDo : questionList) {
                            String answerText = "";
                            if ((metaDataDo.getAnswerText() != null)) {
                                String text = StringUtil.removeAllHtmlCss(removeHtmlTags(
                                        InfoUtil.removeQuestionTagsOnBoldClick(metaDataDo.getAnswerText())));
                                answerText = text;
                            }
                            answerTextFormat += '[' + answerText + ']';
                            if (questionList.size() != metaDataDo.getSequence()) {
                                answerTextFormat += ",";
                            }
                        }
                        String[] userFibOption = null;
                        if (result.get(i).getText() != null) {
                            answersArry = answerTextFormat.split(",");
                            userFibOption = result.get(i).getText().split(",");
                        }
                        if (answersArry != null && userFibOption != null) {
                            boolean isCorrect = false;
                            for (int k = 0; k < answersArry.length; k++) {
                                Label answerChoice = new Label();
                                if (answersArry[k] != null && k < userFibOption.length) {
                                    if ((answersArry[k].toLowerCase().trim()
                                            .equalsIgnoreCase(userFibOption[k].toLowerCase().trim()))
                                            && (noOfAttempts == 1)) {
                                        answerChoice.setText(userFibOption[k]);
                                        answerChoice.getElement().getStyle().setColor(CORRECT);
                                    } else if ((answersArry[k].toLowerCase().trim()
                                            .equalsIgnoreCase(userFibOption[k].toLowerCase().trim()))
                                            && (noOfAttempts > 1)) {
                                        answerChoice.setText(userFibOption[k]);
                                        answerChoice.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                                        isCorrect = true;
                                    } else {
                                        answerChoice.setText(userFibOption[k]);
                                        answerChoice.getElement().getStyle().setColor(INCORRECT);
                                        isCorrect = true;
                                    }
                                    answerChoice.setStyleName(STYLE_TABLE_CENTER);
                                    answerspnl.add(answerChoice);
                                }
                            }
                            if (!isCorrect) {
                                isTickdisplay = true;
                            }
                        }
                    }
                    answerspnl.setStyleName(STYLE_MARGIN_AUTO);
                    data.setValue(i, 3, answerspnl.toString());
                } else if (MA.equalsIgnoreCase(questionType)) {
                    VerticalPanel answerspnl = new VerticalPanel();
                    if (result.get(i).getAnswerObject() != null) {
                        JSONValue value = JSONParser.parseStrict(result.get(i).getAnswerObject());
                        JSONObject answerObject = value.isObject();
                        Set<String> keys = answerObject.keySet();
                        Iterator<String> itr = keys.iterator();
                        boolean isCorrect = false;
                        while (itr.hasNext()) {
                            answerspnl.clear();
                            JSONArray attemptsObj = (JSONArray) answerObject.get(itr.next().toString());
                            for (int j = 0; j < attemptsObj.size(); j++) {
                                Label answerChoice = new Label();
                                String showMessage = null;
                                boolean skip = attemptsObj.get(j).isObject().get("skip").isBoolean()
                                        .booleanValue();
                                String status = attemptsObj.get(j).isObject().get("status").isString()
                                        .stringValue();
                                String matext = attemptsObj.get(j).isObject().get("text").isString()
                                        .stringValue();
                                if (skip == false) {
                                    if (ZERO_NUMERIC.equalsIgnoreCase(matext)) {
                                        showMessage = i18n.GL_GRR_NO();
                                    } else if (ONE.equalsIgnoreCase(matext)) {
                                        showMessage = i18n.GL_GRR_YES();
                                    }
                                    answerChoice.setText(showMessage);
                                    if (ZERO_NUMERIC.equalsIgnoreCase(status)) {
                                        answerChoice.getElement().getStyle().setColor(INCORRECT);
                                        isCorrect = true;
                                    } else if (ONE.equalsIgnoreCase(status) && (noOfAttempts == 1)) {
                                        answerChoice.getElement().getStyle().setColor(CORRECT);
                                    } else if (ONE.equalsIgnoreCase(status) && (noOfAttempts > 1)) {
                                        answerChoice.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                                    }
                                } else {
                                    isCorrect = true;
                                }
                                answerChoice.setStyleName(STYLE_TABLE_CENTER);
                                answerspnl.add(answerChoice);
                            }
                        }
                        if (!isCorrect) {
                            isTickdisplay = true;
                        }
                    }
                    answerspnl.setStyleName(STYLE_MARGIN_AUTO);
                    data.setValue(i, 3, answerspnl.toString());
                } else if (HT_RO.equalsIgnoreCase(questionType) || HT_HL.equalsIgnoreCase(questionType)
                        || HS_TXT.equalsIgnoreCase(questionType) || HS_IMG.equalsIgnoreCase(questionType)) {
                    VerticalPanel answerspnl = new VerticalPanel();
                    if (result.get(i).getAnswerObject() != null
                            && !result.get(i).getStatus().equalsIgnoreCase("skipped")) {
                        Label viewResponselbl = new Label(VIEWRESPONSE);
                        viewResponselbl.setStyleName("summaryViewResponse");
                        viewResponselbl.getElement().setAttribute("resourceGooruId",
                                result.get(i).getResourceGooruOId());
                        viewResponselbl.getElement().setAttribute("questionType", result.get(i).getType());
                        viewResponselbl.getElement().setAttribute("answerObj", result.get(i).getAnswerObject());
                        viewResponselbl.getElement().setAttribute("attempts", String.valueOf(noOfAttempts));
                        answerspnl.add(viewResponselbl);
                    }
                    answerspnl.setStyleName(STYLE_MARGIN_AUTO);
                    data.setValue(i, 3, answerspnl.toString());
                }

                Image correctImg = new Image();
                if (isTickdisplay) {
                    correctImg.setUrl(urlDomain + "/images/analytics/tick.png");
                } else {
                    correctImg.setUrl(urlDomain + "/images/analytics/wrong.png");
                }
                data.setCell(i, 2, correctImg.toString(), null, getPropertiesCell());
                //Set attempts
                //               Label attempts=new Label(Integer.toString(noOfAttempts));
                //               attempts.setStyleName(STYLE_TABLE_CENTER);
                //               data.setValue(i, 4, attempts.toString());

                //Set time spent
                data.setValue(i, 4, AnalyticsUtil.getTimeStampLabel(result.get(i).getTimeSpent()).toString());

                //Set reactions
                int reaction = result.get(i).getReaction();
                data.setValue(i, 5, new AnalyticsReactionWidget(reaction).toString());
            }
        }
        Options options = Options.create();
        options.setAllowHtml(true);
        Table table = new Table(data, options);
        printScoredData.add(table);
        if (result.size() == 0) {
            Label erroeMsg = new Label();
            erroeMsg.setStyleName(STYLE_ERROR_MSG);
            erroeMsg.setText(i18n.GL3265());
            printScoredData.add(erroeMsg);
        }
    } catch (Exception e) {
        AppClientFactory.printSevereLogger("AnalyticsEndview : setQuestionsPrintData : " + e.getMessage());
    }
}

From source file:org.ednovo.gooru.client.mvp.classpage.studentclassview.reports.assessmentreport.AssessmentProgressReportChildView.java

License:Open Source License

@Override
public void setQuestionsData(final ArrayList<UserDataDo> result, String contentType) {
    loadingImageLabel.setVisible(false);
    questionsTable.setVisible(true);//from  w  ww.  j a  va 2s.c o m
    questionsTable.clear();
    if (isTableToDestroy) {
        isTableToDestroy = false;
        destoryTables();
    }

    if (result.size() > 0) {
        final AdvancedFlexTable adTable = new AdvancedFlexTable();
        adTable.removeAllRows();
        adTable.getElement().setId("report-student-assessment-report");
        adTable.addStyleName("table table-bordered reportTableStyle");
        questionsTable.add(adTable);

        Label heading1 = new Label(i18n.GL3259());
        Label heading2 = new Label(i18n.GL0308());

        String heading3Str = i18n.GL0315();
        if (contentType.equalsIgnoreCase(OE)) {
            heading3Str = i18n.GL3262();
        }
        Label heading3 = new Label(heading3Str);

        String heading4Str = i18n.GL2288();
        if (contentType.equalsIgnoreCase(OE)) {
            heading4Str = i18n.GL3260();
        }
        Label heading4 = new Label(heading4Str);

        Label heading5 = new Label(i18n.GL2084());
        Label heading6 = new Label(i18n.GL3271());

        heading1.addStyleName("headingLabel");
        heading2.addStyleName("headingLabel");
        heading3.addStyleName("headingLabel");
        heading4.addStyleName("headingLabel");
        heading5.addStyleName("headingLabel");
        heading6.addStyleName("headingLabel");

        adTable.setHeaderWidget(0, heading1);
        adTable.setHeaderWidget(1, heading2);
        adTable.setHeaderWidget(2, heading3);
        adTable.setHeaderWidget(3, heading4);
        adTable.setHeaderWidget(4, heading5);
        adTable.setHeaderWidget(5, heading6);
        for (int i = 0; i < result.size(); i++) {
            Label questionTitle = new Label(AnalyticsUtil.html2text(result.get(i).getTitle()));
            questionTitle.setStyleName(STYLE_TABLE_CENTER);
            questionTitle.setStyleName(STYLE_TXTLEFT);
            adTable.setWidget(i, 0, new Label(String.valueOf(result.get(i).getSequence())));
            adTable.setWidget(i, 1, questionTitle);

            int noOfAttempts = result.get(i).getAttempts();
            String scoreStatus = result.get(i).getStatus();

            //Set Answer choices
            String questionType = result.get(i).getType();
            if (questionType.equalsIgnoreCase("HS")) {
                questionType = result.get(i).getQuestionType();
            }
            if (MC.equalsIgnoreCase(questionType) || TF.equalsIgnoreCase(questionType)
                    || TSLASHF.equalsIgnoreCase(questionType)) {
                Label anserlbl = new Label();
                if (result.get(i).getMetaData() != null && result.get(i).getOptions() != null) {
                    Map<String, Integer> authorObject = result.get(i).getOptions();

                    for (Map.Entry<String, Integer> entry : authorObject.entrySet()) {
                        String userSelectedOption = entry.getKey();
                        // int ansStatus=entry.getValue();
                        if (userSelectedOption != null) {
                            anserlbl.setText(userSelectedOption);
                            if (STATUS_CORRECT.equalsIgnoreCase(scoreStatus) && noOfAttempts == 1) {
                                anserlbl.getElement().getStyle().setColor(CORRECT);
                            } else if (STATUS_CORRECT.equalsIgnoreCase(scoreStatus) && noOfAttempts > 1) {
                                anserlbl.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                            } else {
                                anserlbl.getElement().getStyle().setColor(INCORRECT);
                            }
                        }
                    }
                }
                anserlbl.setStyleName(STYLE_TABLE_CENTER);
                adTable.setWidget(i, 2, anserlbl);
            } else if (FIB.equalsIgnoreCase(questionType)) {
                VerticalPanel answerspnl = new VerticalPanel();

                if (result.get(i).getAnswerObject() != null) {
                    JSONValue value = JSONParser.parseStrict(result.get(i).getAnswerObject());
                    JSONObject answerObject = value.isObject();
                    Set<String> keys = answerObject.keySet();
                    Iterator<String> itr = keys.iterator();
                    while (itr.hasNext()) {
                        answerspnl.clear();
                        JSONArray attemptsObj = (JSONArray) answerObject.get(itr.next().toString());
                        for (int j = 0; j < attemptsObj.size(); j++) {
                            Label answerChoice = new Label();
                            boolean skip = attemptsObj.get(j).isObject().get("skip").isBoolean().booleanValue();
                            String status = attemptsObj.get(j).isObject().get("status").isString()
                                    .stringValue();
                            String fibtext = attemptsObj.get(j).isObject().get("text").isString().stringValue();
                            if (skip == false) {
                                answerChoice.setText(fibtext);
                                if (ZERO_NUMERIC.equalsIgnoreCase(status)) {
                                    answerChoice.getElement().getStyle().setColor(INCORRECT);
                                } else if (ONE.equalsIgnoreCase(status) && (noOfAttempts == 1)) {
                                    answerChoice.getElement().getStyle().setColor(CORRECT);
                                } else if (ONE.equalsIgnoreCase(status) && (noOfAttempts > 1)) {
                                    answerChoice.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                                }
                            }
                            answerChoice.setStyleName(STYLE_TABLE_CENTER);
                            answerspnl.add(answerChoice);
                        }
                    }
                }
                answerspnl.setStyleName(STYLE_MARGIN_AUTO);
                adTable.setWidget(i, 2, answerspnl);
                //data.setValue(i, 2, answerspnl.toString());
            } else if (MA.equalsIgnoreCase(questionType)) {
                VerticalPanel answerspnl = new VerticalPanel();
                if (result.get(i).getAnswerObject() != null) {
                    JSONValue value = JSONParser.parseStrict(result.get(i).getAnswerObject());
                    JSONObject answerObject = value.isObject();
                    Set<String> keys = answerObject.keySet();
                    Iterator<String> itr = keys.iterator();
                    while (itr.hasNext()) {
                        answerspnl.clear();
                        JSONArray attemptsObj = (JSONArray) answerObject.get(itr.next().toString());
                        for (int j = 0; j < attemptsObj.size(); j++) {
                            Label answerChoice = new Label();
                            String showMessage = null;
                            boolean skip = attemptsObj.get(j).isObject().get("skip").isBoolean().booleanValue();
                            String status = attemptsObj.get(j).isObject().get("status").isString()
                                    .stringValue();
                            String matext = attemptsObj.get(j).isObject().get("text").isString().stringValue();
                            if (skip == false) {
                                if (ZERO_NUMERIC.equalsIgnoreCase(matext)) {
                                    showMessage = i18n.GL_GRR_NO();
                                } else if (ONE.equalsIgnoreCase(matext)) {
                                    showMessage = i18n.GL_GRR_YES();
                                }
                                answerChoice.setText(showMessage);
                                if (ZERO_NUMERIC.equalsIgnoreCase(status)) {
                                    answerChoice.getElement().getStyle().setColor(INCORRECT);
                                } else if (ONE.equalsIgnoreCase(status) && (noOfAttempts == 1)) {
                                    answerChoice.getElement().getStyle().setColor(CORRECT);
                                } else if (ONE.equalsIgnoreCase(status) && (noOfAttempts > 1)) {
                                    answerChoice.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);
                                }
                            }
                            answerChoice.setStyleName(STYLE_TABLE_CENTER);
                            answerspnl.add(answerChoice);
                        }
                    }
                }
                answerspnl.setStyleName(STYLE_MARGIN_AUTO);
                adTable.setWidget(i, 2, answerspnl);
            } else if (HT_RO.equalsIgnoreCase(questionType) || HT_HL.equalsIgnoreCase(questionType)
                    || HS_TXT.equalsIgnoreCase(questionType) || HS_IMG.equalsIgnoreCase(questionType)
                    || OE.equalsIgnoreCase(questionType)) {
                if (result.get(i).getAnswerObject() != null
                        && !result.get(i).getStatus().equalsIgnoreCase("skipped")) {
                    Label viewResponselbl = new Label(VIEWRESPONSE);
                    viewResponselbl.setStyleName("summaryViewResponse");
                    viewResponselbl.getElement().setAttribute("resourceGooruId",
                            result.get(i).getResourceGooruOId());
                    viewResponselbl.getElement().setAttribute("questionType", result.get(i).getType());
                    viewResponselbl.getElement().setAttribute("answerObj", result.get(i).getAnswerObject());
                    viewResponselbl.getElement().setAttribute("attempts", String.valueOf(noOfAttempts));
                    viewResponselbl.addClickHandler(new SummaryPopupClick(result.get(i)));
                    adTable.setWidget(i, 2, viewResponselbl);
                }
            }
            //Set attempts
            Label attempts = new Label(i18n.GL2269());
            attempts.setStyleName(STYLE_TABLE_CENTER);
            attempts.getElement().getStyle().setColor(ONMULTIPULEATTEMPTS);

            if (OE.equalsIgnoreCase(questionType)) {
                Label completion = new Label();
                completion.setStyleName("alignCenterAndBackground");
                if (noOfAttempts > 0) {
                    completion.setText(i18n.GL_GRR_YES());
                } else {
                    completion.setText(i18n.GL_GRR_NO());
                }
                adTable.setWidget(i, 3, completion);
            } else {
                if (STATUS_INCORRECT.equalsIgnoreCase(scoreStatus)) {
                    adTable.setWidget(i, 3, attempts);
                    adTable.getRowFormatter().addStyleName(i, STYLE_WHITE);
                } else if (STATUS_CORRECT.equalsIgnoreCase(scoreStatus)) {
                    Image correctImg = new Image();
                    correctImg.setUrl(urlDomain + "/images/analytics/tick.png");
                    adTable.setWidget(i, 3, correctImg);
                    adTable.getRowFormatter().addStyleName(i, STYLE_GREEN);
                }
            }

            //Set time spent
            adTable.setWidget(i, 4, AnalyticsUtil.getTimeStampLabel(result.get(i).getTimeSpent()));

            //Set reactions
            int reaction = result.get(i).getReaction();
            adTable.setWidget(i, 5, new AnalyticsReactionWidget(reaction));
        }
        //         sortAndFixed();
    } else {
        setErrorData(questionsTable);
    }
}

From source file:org.emfjson.gwt.common.AsyncIterator.java

License:Open Source License

public static void forEach(final Resource resource, final int position, final JSONArray array,
        final JsonReader reader, final Callback<Resource> callback) {

    if (position >= array.size()) {

        callback.onSuccess(resource);//w ww .j a  v a 2s .c o  m

    } else {

        final JSONValue current = array.get(position);
        final JSONObject currentObject = current.isObject();

        if (currentObject != null) {

            reader.parseObject(currentObject, null, new Callback<EObject>() {
                @Override
                public void onFailure(Throwable caught) {
                    callback.onFailure(caught);
                }

                @Override
                public void onSuccess(EObject result) {
                    if (result != null) {
                        resource.getContents().add(result);
                    }
                    forEach(resource, position + 1, array, reader, callback);
                }
            });

        } else {

            callback.onFailure(new ClassCastException());

        }
    }
}

From source file:org.emfjson.gwt.common.AsyncIterator.java

License:Open Source License

private void forEach() {
    if (it.hasNext()) {
        final EReference reference = it.next();
        final JSONValue value = map.get(reference);
        final JSONArray array = value.isArray();

        if (array != null) {

            forEach(0, array, reference);

        } else {/*from   ww  w .  j  a  v  a 2 s. c  o  m*/

            JSONObject obj = value.isObject();
            if (obj == null) {

                done.onFailure(new ClassCastException());

            } else {

                reader.parseObject(value.isObject(), reference, new Callback<EObject>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        done.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(EObject result) {
                        setOrAdd(object, reference, result);
                        forEach();
                    }
                });

            }

        }

    } else {

        done.onSuccess(object);

    }
}

From source file:org.emfjson.gwt.common.AsyncIterator.java

License:Open Source License

private void forEach(final int pos, final JSONArray array, final EReference reference) {
    if (pos >= array.size()) {

        forEach();//from  ww w  . j  a  va2s.  c  om

    } else {

        JSONValue current = array.get(pos);
        JSONObject obj = current.isObject();
        if (obj == null) {

            done.onFailure(new ClassCastException());

        } else {

            reader.parseObject(obj, reference, new Callback<EObject>() {
                @Override
                public void onFailure(Throwable caught) {
                    done.onFailure(caught);
                }

                @Override
                public void onSuccess(EObject result) {
                    setOrAdd(object, reference, result);
                    forEach(pos + 1, array, reference);
                }
            });

        }

    }
}

From source file:org.emfjson.gwt.map.JsonReader.java

License:Open Source License

public void parse(JSONValue value, final Callback<Resource> done) {
    final JSONObject object = value.isObject();
    if (object != null) {
        parseObject(object, null, new Callback<EObject>() {
            @Override/*from   ww w  . ja  v  a 2 s  . com*/
            public void onFailure(Throwable caught) {
                done.onFailure(caught);
            }

            @Override
            public void onSuccess(EObject result) {
                resource.getContents().add(result);
                resolveEntries(new Callback<Resource>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        done.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(Resource resource) {
                        done.onSuccess(resource);
                    }
                });
            }
        });
    }

    final JSONArray array = value.isArray();
    if (array != null) {
        parseArray(array, new Callback<Resource>() {
            @Override
            public void onFailure(Throwable caught) {
                done.onFailure(caught);
            }

            @Override
            public void onSuccess(final Resource result) {
                resolveEntries(new Callback<Resource>() {
                    @Override
                    public void onFailure(Throwable caught) {
                        done.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(Resource resource) {
                        done.onSuccess(result);
                    }
                });
            }
        });
    }
}

From source file:org.emfjson.gwt.map.JsonReader.java

License:Open Source License

private void parseEntry(EObject owner, EReference reference, JSONValue value) {
    final JSONObject entryObject = value.isObject();
    if (entryObject != null) {
        setEntryObject(entryObject, owner, reference);
    } else {/*w  w  w.j  ava 2s  .  c om*/
        final JSONArray array = value.isArray();
        if (array != null) {
            for (int i = 0; i < array.size(); i++) {
                JSONValue current = array.get(i);
                if (current.isObject() != null) {
                    setEntryObject(current.isObject(), owner, reference);
                }
            }
        }
    }
}

From source file:org.emfjson.gwt.map.JsonReader.java

License:Open Source License

private String getRef(JSONValue value) {
    final JSONObject refObject = value.isObject();
    if (refObject != null) {
        final JSONValue refValue = refObject.get(options.refField);
        if (refValue != null) {
            final JSONString string = refValue.isString();
            if (string != null) {
                return string.stringValue();
            }//ww w. j  a v  a  2 s.  c  om
        }
    }
    return null;
}

From source file:org.eurekastreams.web.client.ui.common.stream.StreamJsonRequestFactory.java

License:Apache License

/**
 * Sets (or clears) the excluded activity id.
 *
 * @param inExcludeId//from   ww  w .j  a  va2s  . co  m
 *            ID to exclude (null for none).
 * @param json
 *            the request.
 * @return The request
 */
public static JSONObject setExcludeId(final Long inExcludeId, final JSONObject json) {
    if (inExcludeId == null || inExcludeId == 0) {
        // ok to clobber the entire "exclude" field, since the ids are the only thing that goes in it at this point
        if (json.containsKey("exclude")) {
            json.put("exclude", new JSONObject());
        }
    } else {
        JSONValue raw = json.get("exclude");
        JSONObject exclude = raw == null ? null : raw.isObject();
        if (exclude == null) {
            exclude = new JSONObject();
            json.put("exclude", exclude);
        }
        JSONArray array = new JSONArray();
        array.set(0, new JSONString(inExcludeId.toString()));
        exclude.put("ids", array);
    }

    return json;
}