Example usage for com.google.gwt.safehtml.shared SafeHtmlUtils fromSafeConstant

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils fromSafeConstant

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlUtils fromSafeConstant.

Prototype

public static SafeHtml fromSafeConstant(String s) 

Source Link

Document

Returns a SafeHtml constructed from a safe string, i.e., without escaping the string.

Usage

From source file:net.scran24.user.client.survey.prompts.UnknownPortionSizeMethodPrompt.java

public SurveyStageInterface getInterface(final Callback1<FoodOperation> onComplete,
        final Callback1<Function1<FoodEntry, FoodEntry>> onIntermediateStateChange) {

    final FlowPanel content = new FlowPanel();

    final Button contButton = WidgetFactory.createButton(messages.noPortionMethod_continueButtonLabel(),
            new ClickHandler() {
                @Override//w  w  w.  ja  v a 2 s.  co m
                public void onClick(ClickEvent event) {
                    onComplete.call(FoodOperation.updateEncoded(new Function1<EncodedFood, EncodedFood>() {
                        @Override
                        public EncodedFood apply(EncodedFood argument) {
                            return argument.withPortionSize(PortionSize.complete(CompletedPortionSize
                                    .ignore("No porton size estimation method defined for " + description)));
                        }
                    }));
                }
            });

    content.add(WidgetFactory.createPromptPanel(SafeHtmlUtils
            .fromSafeConstant(messages.noPortionMethod_promptText(SafeHtmlUtils.htmlEscape(description)))));
    content.add(WidgetFactory.createButtonsPanel(contButton));

    return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS);
}

From source file:net.scran24.user.client.survey.WelcomePage.java

License:Apache License

@Override
public SimpleSurveyStageInterface getInterface(final Callback1<Survey> onComplete,
        Callback2<Survey, Boolean> onIntermediateStateChange) {
    final Button startButton = WidgetFactory.createGreenButton(surveyMessages.welcomePage_ready(),
            new ClickHandler() {
                public void onClick(ClickEvent event) {
                    onComplete.call(initialData.withFlag(FLAG_WELCOME_PAGE_SHOWN));
                }//  www.j  a v a  2  s.c o  m
            });

    HTMLPanel tutorialVideo = new HTMLPanel(SafeHtmlUtils.fromSafeConstant(TutorialVideo.embedHTML));

    FlowPanel contents = new FlowPanel();
    contents.getElement().addClassName("intake24-survey-content-container");
    contents.add(tutorialVideo);
    HTMLPanel htmlPanel = new HTMLPanel(SafeHtmlUtils.fromSafeConstant(welcomeHtml));

    contents.add(htmlPanel);
    contents.add(startButton);

    return new SimpleSurveyStageInterface(contents);
}

From source file:net.scran24.user.client.surveyscheme.FoodSourcesPrompt.java

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        final Callback1<Function1<Meal, Meal>> onIntermediateStateChange) {

    FlowPanel content = new FlowPanel();

    /* PVector<WithIndex<FoodEntry>> foodsToShow = filter(zipWithIndex(meal.foods), new Function1<WithIndex<FoodEntry>, Boolean>() {
       @Override/*from   w ww . ja v a 2s . c  o m*/
       public Boolean apply(WithIndex<FoodEntry> argument) {
    return !argument.value.customData.containsKey("foodSource");
       }
    }); */

    content.add(WidgetFactory.createPromptPanel(
            SafeHtmlUtils.fromSafeConstant("<p>If some of the food items that you had for your <strong>"
                    + meal.safeName() + "</strong> came from a place other than "
                    + SafeHtmlUtils.htmlEscape(mainSourceOption.toLowerCase())
                    + ", please indicate where did you get those.</p>")));

    Grid foodSourceChoice = new Grid(meal.foods.size() + 1, 2);
    foodSourceChoice.setCellPadding(5);
    foodSourceChoice.setWidget(0, 0, new Label("Food"));
    foodSourceChoice.setWidget(0, 1, new Label("Source"));

    final ListBox[] sourceChoices = new ListBox[meal.foods.size()];

    for (int i = 0; i < meal.foods.size(); i++) {
        sourceChoices[i] = createSourceChoice(meal.foods.get(i).customData.get("foodSource"));

        foodSourceChoice.setWidget(i + 1, 0,
                new Label(SafeHtmlUtils.htmlEscape(meal.foods.get(i).description())));
        foodSourceChoice.setWidget(i + 1, 1, sourceChoices[i]);
    }

    content.add(foodSourceChoice);

    Button finished = WidgetFactory.createButton("Continue", new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            onComplete.call(MealOperation.update(new Function1<Meal, Meal>() {
                @Override
                public Meal apply(Meal meal) {
                    return meal.withFoods(
                            map(zipWithIndex(meal.foods), new Function1<WithIndex<FoodEntry>, FoodEntry>() {
                                @Override
                                public FoodEntry apply(WithIndex<FoodEntry> argument) {
                                    return argument.value.withCustomDataField("foodSource",
                                            sourceChoices[argument.index].getValue(
                                                    sourceChoices[argument.index].getSelectedIndex()));
                                }
                            }));
                }
            }));
        }
    });

    content.add(WidgetFactory.createButtonsPanel(finished));

    return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS);
}

From source file:net.scran24.user.client.surveyscheme.LunchFrequenciesQuestion.java

@Override
public SimpleSurveyStageInterface getInterface(final Callback1<Survey> onComplete,
        Callback2<Survey, Boolean> onIntermediateStateChange) {
    final FlowPanel content = new FlowPanel();
    content.addStyleName("intake24-survey-content-container");

    final RadioButtonQuestion shopFreq = new RadioButtonQuestion(SafeHtmlUtils.fromSafeConstant(
            "<p>In a normal school week how often do you go out to the shops for <strong>lunch</strong>?</p>"),
            frequencyOptions, "shopFreq", Option.<String>none());
    final RadioButtonQuestion packFreq = new RadioButtonQuestion(SafeHtmlUtils.fromSafeConstant(
            "<p>In a normal school week how often do you bring in a packed <strong>lunch</strong> from home?</p>"),
            frequencyOptions, "packFreq", Option.<String>none());
    final RadioButtonQuestion schoolLunchFreq = new RadioButtonQuestion(
            SafeHtmlUtils.fromSafeConstant(
                    "<p>In a normal school week how often do you have a school <strong>lunch</strong>?</p>"),
            frequencyOptions, "schoolLunchFreq", Option.<String>none());
    final RadioButtonQuestion homeFreq = new RadioButtonQuestion(SafeHtmlUtils.fromSafeConstant(
            "<p>In a normal school week how often do you go home/to a friend's house for <strong>lunch</strong>?</p>"),
            frequencyOptions, "homeFreq", Option.<String>none());
    final RadioButtonQuestion skipFreq = new RadioButtonQuestion(
            SafeHtmlUtils.fromSafeConstant(
                    "<p>In a normal school week how often do you skip <strong>lunch</strong>?</p>"),
            frequencyOptions, "skipFreq", Option.<String>none());
    final RadioButtonQuestion workFreq = new RadioButtonQuestion(
            SafeHtmlUtils.fromSafeConstant(
                    "<p>In a normal school week how often do you work through <strong>lunch</strong>?</p>"),
            frequencyOptions, "workFreq", Option.<String>none());

    content.add(shopFreq);/*from   w  w w .  ja v a2 s  . c o  m*/
    content.add(packFreq);
    content.add(schoolLunchFreq);
    content.add(homeFreq);
    content.add(skipFreq);
    content.add(workFreq);

    final Button accept = WidgetFactory.createButton("Continue");

    accept.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            for (RadioButtonQuestion q : new RadioButtonQuestion[] { shopFreq, packFreq, schoolLunchFreq,
                    homeFreq, skipFreq, workFreq })
                if (q.getChoice().isEmpty()) {
                    q.showWarning();
                    return;
                } else
                    q.clearWarning();

            PMap<String, String> data = state.customData;
            data = data.plus("shopFreq", shopFreq.getChoice().getOrDie())
                    .plus("packFreq", packFreq.getChoice().getOrDie())
                    .plus("schoolLunchFreq", schoolLunchFreq.getChoice().getOrDie())
                    .plus("homeFreq", homeFreq.getChoice().getOrDie())
                    .plus("skipFreq", skipFreq.getChoice().getOrDie())
                    .plus("workFreq", workFreq.getChoice().getOrDie());

            accept.setEnabled(false);
            onComplete.call(state.withData(data));
        }
    });

    content.add(WidgetFactory.createButtonsPanel(accept));

    return new SimpleSurveyStageInterface(content);
}

From source file:net.scran24.user.client.surveyscheme.shesjun15.SHeSJun15.java

License:Apache License

@Override
public void showNextPage() {
    final Survey state = stateManager.getCurrentState();

    /*    new CustomFieldDef("dayOfWeek", "Day of week"),
       new CustomFieldDef("usualFoods", "Usual foods"),
       new CustomFieldDef("foodAmount", "Food amount"),
       new CustomFieldDef("supplements", "Supplements"),
       new CustomFieldDef("diet", "Diet")});*/

    if (!state.flags.contains(WelcomePage.FLAG_WELCOME_PAGE_SHOWN)) {
        interfaceManager.show(new WelcomePage(surveyMessages.welcomePage_welcomeText(), state));
    } else if (!state.completionConfirmed()) {
        if (cachedSurveyPage == null)
            cachedSurveyPage = new IntakeSurvey(stateManager, defaultPromptManager, defaultSelectionManager,
                    defaultScriptManager);
        interfaceManager.show(cachedSurveyPage);
    } else if (!state.customData.containsKey("dayOfWeek")) {
        interfaceManager.show(new MultipleChoiceRadioButtonQuestion(state,
                SafeHtmlUtils
                        .fromSafeConstant("<p>Which day did you enter your food and drink intake for?</p>"),
                "Continue", dayOfWeekOptions, "dayOfWeek", Option.<String>none()));
    } else if (!state.customData.containsKey("usualFoods")) {
        interfaceManager.show(new MultipleChoiceRadioButtonQuestion(state, SafeHtmlUtils.fromSafeConstant(
                "<p>Were the types of foods and drinks you had yesterday similar to what you normally have?</p>"),
                "Continue", foodTypeOptions, "usualFoods", Option.some("No (please explain why)")));
    } else if (!state.customData.containsKey("foodAmount")) {
        interfaceManager.show(new MultipleChoiceRadioButtonQuestion(state, SafeHtmlUtils.fromSafeConstant(
                "<p>Was the amount of food that you had yesterday similar to what you normally have? </p>"),
                "Continue", foodAmountOptions, "foodAmount", Option.<String>none()));
    } else if (!state.customData.containsKey("supplements")) {
        interfaceManager.show(new MultipleChoiceCheckboxQuestion(state,
                SafeHtmlUtils//from   w  w  w . j ava2s  . c  o m
                        .fromSafeConstant("<p>Do you take any dietary supplements e.g. Multivitamins?</p>"),
                "Continue", supplementOptions, "supplements", Option.some("Other")));
    } else if (!state.customData.containsKey("diet")) {
        interfaceManager.show(new MultipleChoiceRadioButtonQuestion(state,
                SafeHtmlUtils.fromSafeConstant("<p>Are you currently following a particular diet?</p>"),
                "Continue", dietOptions, "diet", Option.some("Other")));
    } else {
        interfaceManager
                .show(new FlatFinalPage(
                        HtmlResources.INSTANCE.getFinalHtml().getText().replace("[intake24_username_value]",
                                CurrentUser.getUserInfo().userName),
                        postProcess(state, basicPostProcess), log.log));
    }
}

From source file:net.scran24.user.client.surveyscheme.UserDataQuestion.java

@Override
public SimpleSurveyStageInterface getInterface(final Callback1<Survey> onComplete,
        Callback2<Survey, Boolean> onIntermediateStateChange) {
    final FlowPanel content = new FlowPanel();
    content.addStyleName("intake24-survey-content-container");

    content.add(new HTMLPanel("<p>Before you continue, please answer a few questions about yourself.</p>"));

    final PVector<String> ageOptions = TreePVector.<String>empty().plus("11").plus("12").plus("13").plus("14")
            .plus("15").plus("16").plus("17").plus("18");

    final PVector<String> genderOptions = TreePVector.<String>empty().plus("Male").plus("Female");

    final RadioButtonQuestion ageBlock = new RadioButtonQuestion(
            SafeHtmlUtils.fromSafeConstant("<p>What age are you?</p>"), ageOptions, "ageGroup",
            Option.<String>none());
    content.add(ageBlock);//from   w ww.  j  ava 2s  .co  m
    final RadioButtonQuestion genderBlock = new RadioButtonQuestion(
            SafeHtmlUtils.fromSafeConstant("<p>Are you...</p>"), genderOptions, "genderGroup",
            Option.<String>none());
    content.add(genderBlock);

    final TextBoxQuestion postCode = new TextBoxQuestion(
            SafeHtmlUtils.fromSafeConstant("<p>What is your post code?</p>"));

    content.add(postCode);

    final TextBoxQuestion schoolName = new TextBoxQuestion(
            SafeHtmlUtils.fromSafeConstant("<p>What is the name of the School you go to?</p>"));

    content.add(schoolName);

    final TextBoxQuestion townName = new TextBoxQuestion(
            SafeHtmlUtils.fromSafeConstant("<p>What is the name of your town?</p>"));

    content.add(townName);

    final Button accept = WidgetFactory.createButton("Continue");

    accept.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            Option<String> ageChoice = ageBlock.getChoice();

            if (ageChoice.isEmpty()) {
                ageBlock.showWarning();
                return;
            } else
                ageBlock.clearWarning();

            Option<String> genderChoice = genderBlock.getChoice();

            if (genderChoice.isEmpty()) {
                genderBlock.showWarning();
                return;
            } else
                genderBlock.clearWarning();

            if (postCode.textBox.getText().isEmpty()) {
                postCode.showWarning();
                return;
            } else
                postCode.clearWarning();

            if (schoolName.textBox.getText().isEmpty()) {
                schoolName.showWarning();
                return;
            } else
                schoolName.clearWarning();

            if (townName.textBox.getText().isEmpty()) {
                townName.showWarning();
                return;
            } else
                townName.clearWarning();

            final HashMap<String, String> data = new HashMap<String, String>();
            data.put("age", ageChoice.getOrDie());
            data.put("gender", genderChoice.getOrDie());
            data.put("postCode", postCode.textBox.getText());
            data.put("schoolName", schoolName.textBox.getText());
            data.put("townName", townName.textBox.getText());

            accept.setEnabled(false);

            AsyncRequestAuthHandler.execute(new AsyncRequest<Void>() {
                @Override
                public void execute(AsyncCallback<Void> callback) {
                    userDataService.submit(data, callback);
                }
            }, new AsyncCallback<Void>() {
                @Override
                public void onFailure(Throwable caught) {
                    onComplete.call(state.withFlag(FLAG_SKIP_USERDATA_UPLOAD));
                }

                @Override
                public void onSuccess(Void result) {
                    UserInfo userInfo = CurrentUser.getUserInfo();
                    CurrentUser.setUserInfo(new UserInfo(userInfo.userName, userInfo.surveyId,
                            userInfo.surveyParameters, data));
                    onComplete.call(state);
                }
            });

            userDataService.submit(data, new AsyncCallback<Void>() {
                @Override
                public void onSuccess(Void result) {
                }

                @Override
                public void onFailure(Throwable caught) {
                    Window.alert(caught.getMessage());
                }
            });
        }
    });

    content.add(WidgetFactory.createButtonsPanel(accept));

    return new SimpleSurveyStageInterface(content);
}

From source file:net.scran24.user.client.surveyscheme.YoungScot2014Scheme.java

License:Apache License

private Rules rules(PortionSizeScriptManager scriptManager, CompoundFoodTemplateManager templateManager) {
    PromptRule<Meal, MealOperation> showMealLocationPrompt = new PromptRule<Meal, MealOperation>() {
        @Override//w w  w.j  av  a2  s. c  om
        public Option<Prompt<Meal, MealOperation>> apply(Meal state, SelectionMode selectionType,
                PSet<String> surveyFlags) {
            if (state.customData.containsKey("mealLocation") || !state.encodingComplete()
                    || !surveyFlags.contains(FLAG_ENABLE_FINAL_RUN))
                return Option.none();
            else
                return Option.some(PromptUtil.asMealPrompt(new RadioButtonPrompt(
                        SafeHtmlUtils
                                .fromSafeConstant("<p>Where did you eat your " + state.safeName() + "?</p>"),
                        "MealLocationPrompt", mealLocationOptions, "Continue", "mealLocation",
                        Option.some("Other")), new Function1<String, MealOperation>() {
                            @Override
                            public MealOperation apply(String location) {
                                return MealOperation.setCustomDataField("mealLocation", location);
                            }
                        }));
        }
    };

    PromptRule<Meal, MealOperation> showShopPricePrompt = new PromptRule<Meal, MealOperation>() {
        @Override
        public Option<Prompt<Meal, MealOperation>> apply(Meal state, SelectionMode selectionType,
                PSet<String> surveyFlags) {
            if (!foodSourcesComplete(state) || !hasShopItems(state)
                    || state.customData.containsKey("shopSpending"))
                return Option.none();
            else
                return Option.some(PromptUtil.asMealPrompt(new RadioButtonPrompt(
                        SafeHtmlUtils.fromSafeConstant("<p>How much did you spend on your " + state.safeName()
                                + " at the shop or restaurant?</p>"),
                        "ShopPricePrompt", spendingOptions, "Continue", "shopSpending", Option.<String>none()),
                        new Function1<String, MealOperation>() {
                            @Override
                            public MealOperation apply(String spending) {
                                return MealOperation.setCustomDataField("shopSpending", spending);
                            }
                        }));
        }
    };

    PromptRule<Meal, MealOperation> showSchoolPricePrompt = new PromptRule<Meal, MealOperation>() {
        @Override
        public Option<Prompt<Meal, MealOperation>> apply(Meal state, SelectionMode selectionType,
                PSet<String> surveyFlags) {
            if (!foodSourcesComplete(state) || !hasSchoolItems(state)
                    || state.customData.containsKey("schoolSpending"))
                return Option.none();
            else
                return Option.some(PromptUtil.asMealPrompt(
                        new RadioButtonPrompt(
                                SafeHtmlUtils.fromSafeConstant("<p>How much did you spend on your "
                                        + state.safeName() + " at school?</p>"),
                                "SchoolPricePrompt", spendingOptions, "Continue", "schoolSpending",
                                Option.<String>none()),
                        new Function1<String, MealOperation>() {
                            @Override
                            public MealOperation apply(String spending) {
                                return MealOperation.setCustomDataField("schoolSpending", spending);
                            }
                        }));
        }
    };

    PromptRule<Meal, MealOperation> showMealSourcePrompt = new PromptRule<Meal, MealOperation>() {
        @Override
        public Option<Prompt<Meal, MealOperation>> apply(Meal state, SelectionMode selectionType,
                PSet<String> surveyFlags) {
            if (state.customData.containsKey("mealSource") || !state.encodingComplete()
                    || !surveyFlags.contains(FLAG_ENABLE_FINAL_RUN))
                return Option.none();
            else
                return Option.some(PromptUtil.asMealPrompt(
                        new RadioButtonPrompt(
                                SafeHtmlUtils.fromSafeConstant(
                                        "<p>Where did most of your food that you had for your <strong>"
                                                + state.safeName() + "</strong> come from?</p>"),
                                "MealSourcePrompt", foodSourceOptions, "Continue", "mealSource",
                                Option.some("Other")),
                        new Function1<String, MealOperation>() {
                            @Override
                            public MealOperation apply(final String source) {
                                return MealOperation.update(new Function1<Meal, Meal>() {
                                    @Override
                                    public Meal apply(Meal argument) {
                                        Meal withSource = argument.withCustomDataField("mealSource", source);

                                        if (argument.foods.size() == 1)
                                            return withSource.withFoods(
                                                    map(argument.foods, new Function1<FoodEntry, FoodEntry>() {
                                                        @Override
                                                        public FoodEntry apply(FoodEntry argument) {
                                                            return argument.withCustomDataField("foodSource",
                                                                    source);
                                                        }
                                                    }));
                                        else
                                            return withSource;
                                    }
                                });
                            }
                        }));
        }
    };

    PromptRule<Meal, MealOperation> showFoodSourcePrompt = new PromptRule<Meal, MealOperation>() {
        @Override
        public Option<Prompt<Meal, MealOperation>> apply(Meal state, SelectionMode selectionType,
                PSet<String> surveyFlags) {
            if (!state.customData.containsKey("mealSource") || !state.encodingComplete()
                    || foodSourcesComplete(state))
                return Option.none();
            else
                return Option.<Prompt<Meal, MealOperation>>some(
                        new FoodSourcesPrompt(state, foodSourceOptions, state.customData.get("mealSource")));
        }
    };

    PromptRule<Survey, SurveyOperation> confirmCompletion = new PromptRule<Survey, SurveyOperation>() {
        @Override
        public Option<Prompt<Survey, SurveyOperation>> apply(Survey state, SelectionMode selectionType,
                PSet<String> surveyFlags) {
            if (state.completionConfirmed() || !state.flags.contains(FLAG_ENABLE_FINAL_RUN))
                return Option.none();
            else
                return Option.<Prompt<Survey, SurveyOperation>>some(new YoungScotConfirmCompletionPrompt());
        }
    };

    return new Rules(
            // meal prompts
            TreePVector.<WithPriority<PromptRule<Meal, MealOperation>>>empty()
                    .plus(AskForMealTime.withPriority(8)).plus(ShowEditMeal.withPriority(7))
                    .plus(ShowDrinkReminderPrompt.withPriority(6)).plus(ShowReadyMealsPrompt.withPriority(5))
                    .plus(new WithPriority<PromptRule<Meal, MealOperation>>(showMealSourcePrompt, 4))
                    .plus(new WithPriority<PromptRule<Meal, MealOperation>>(showFoodSourcePrompt, 3))
                    .plus(new WithPriority<PromptRule<Meal, MealOperation>>(showMealLocationPrompt, 2))
                    .plus(new WithPriority<PromptRule<Meal, MealOperation>>(showShopPricePrompt, 1))
                    .plus(new WithPriority<PromptRule<Meal, MealOperation>>(showSchoolPricePrompt, 0)),

            // food prompts
            TreePVector.<WithPriority<PromptRule<FoodEntry, FoodOperation>>>empty()
                    .plus(ShowBrandNamePrompt.withPriority(-1))
                    .plus(ShowNextPortionSizeStep.withPriority(scriptManager, 0))
                    .plus(ChoosePortionSizeMethod.withPriority(1)).plus(SplitFood.withPriority(3))
                    .plus(InformFoodComplete.withPriority(-100)),

            // extended food propmts
            TreePVector.<WithPriority<PromptRule<Pair<FoodEntry, Meal>, MealOperation>>>empty()
                    .plus(AskToLookupFood.withPriority(2, locale, recipeManager))
                    .plus(ShowSameAsBeforePrompt.withPriority(2, getSchemeId(), getDataVersion(), scriptManager,
                            templateManager))
                    .plus(ShowCompoundFoodPrompt.withPriority(0, locale))
                    .plus(ShowAssociatedFoodPrompt.withPriority(0, locale))

            ,
            // global prompts

            TreePVector.<WithPriority<PromptRule<Survey, SurveyOperation>>>empty()
                    .plus(new WithPriority<PromptRule<Survey, SurveyOperation>>(confirmCompletion, 0))
                    .plus(ShowEnergyValidationPrompt.withPriority(1, 500.0))
                    .plus(ShowEmptySurveyPrompt.withPriority(1))
                    .plus(ShowTimeGapPrompt.withPriority(2, 180, new Time(9, 0), new Time(21, 0)))

            ,

            // selection rules
            TreePVector.<WithPriority<SelectionRule>>empty().plus(SelectForPortionSize.withPriority(3))
                    .plus(SelectRawFood.withPriority(2)).plus(SelectFoodForAssociatedPrompts.withPriority(1))
                    .plus(SelectIncompleteFreeEntryMeal.withPriority(1))
                    .plus(SelectMealWithNoDrink.withPriority(1)).plus(SelectUnconfirmedMeal.withPriority(1))
                    .plus(SelectMealForReadyMeals.withPriority(1)));
}

From source file:net.scran24.user.client.surveyscheme.YoungScot2014Scheme.java

License:Apache License

@Override
public void showNextPage() {
    final Survey state = stateManager.getCurrentState();

    // Logger log = Logger.getLogger("showNextPage");
    // log.info(SurveyXmlSerialiser.toXml(state));

    if (!state.flags.contains(WelcomePage.FLAG_WELCOME_PAGE_SHOWN)) {
        interfaceManager.show(new WelcomePage(surveyMessages.welcomePage_welcomeText(), state));
    } else if (!checkUserData() && !state.flags.contains(UserDataQuestion.FLAG_SKIP_USERDATA_UPLOAD)) {
        interfaceManager.show(new UserDataQuestion(state));
    } else if (!state.completionConfirmed()) {

        if (state.flags.contains(Survey.FLAG_NO_MORE_PROMPTS) && !state.flags.contains(FLAG_ENABLE_FINAL_RUN))
            stateManager// w  ww  .  ja va  2s .co  m
                    .updateState(
                            state.clearFlag(Survey.FLAG_NO_MORE_PROMPTS).withFlag(FLAG_ENABLE_FINAL_RUN)
                                    .withSelection(new Selection.SelectedMeal(0, SelectionMode.AUTO_SELECTION)),
                            false);

        if (cachedSurveyPage == null) {
            RuleBasedPromptManager promptManager = new RuleBasedPromptManager(
                    rules(defaultScriptManager, defaultTemplateManager));
            PromptAvailabilityBasedSelectionManager selectionManager = new PromptAvailabilityBasedSelectionManager(
                    promptManager);

            cachedSurveyPage = new IntakeSurvey(stateManager, promptManager, selectionManager,
                    defaultScriptManager);
        }

        interfaceManager.show(cachedSurveyPage);

    } else if (!state.customData.containsKey("lunchSpend")) {
        interfaceManager.show(new MultipleChoiceRadioButtonQuestion(state,
                SafeHtmlUtils.fromSafeConstant(
                        "<p>How much do you usually spend on <strong>lunch</strong> on a school day?</p>"),
                "Continue", spendingOptions, "lunchSpend", Option.<String>none()));
    } else if (!frequencyComplete(state)) {
        interfaceManager.show(new LunchFrequenciesQuestion(state, frequencyOptions));
    } else if (!state.customData.containsKey("reason")) {
        interfaceManager.show(new MultipleChoiceRadioButtonQuestion(state,
                SafeHtmlUtils
                        .fromSafeConstant("<p>What determines where you go for <strong>lunch</strong>?</p>"),
                "Continue", reasonOptions, "reason", Option.some("Other")));
    } else if (!state.customData.containsKey("freeMeals")) {
        interfaceManager.show(new MultipleChoiceRadioButtonQuestion(state,
                SafeHtmlUtils.fromSafeConstant("<p>Are you entitled to free school meals?</p>"), "Continue",
                freeMealsOptions, "freeMeals", Option.<String>none()));
    } else {
        interfaceManager.show(new FlatFinalPage(surveyMessages.finalPage_text(),
                postProcess(state, basicPostProcess), log.log));
    }
}

From source file:net.scran24.user.client.surveyscheme.YoungScotConfirmCompletionPrompt.java

@Override
public SurveyStageInterface getInterface(final Callback1<SurveyOperation> onComplete,
        final Callback1<Function1<Survey, Survey>> onIntermediateStateChange) {
    final SafeHtml promptText = SafeHtmlUtils.fromSafeConstant(
            "<p>We now have all the information we need concerning the foods you have entered.</p>"
                    + "<p>Please review all the meals and foods listed in the panel on the left side of this page.</p>"
                    + "<p>You can add or remove foods from your meals by clicking on a meal, or you can add another meal using the \"Add meal\" button if you had something else.</p>"
                    + "<p>If you are sure that you have listed everything you have eaten during the previous 24 hours, please press the button below.");

    FlowPanel content = new FlowPanel();

    content.add(WidgetFactory.createPromptPanel(promptText));

    Button confirm = WidgetFactory.createGreenButton("Continue", new ClickHandler() {
        @Override//from w  w  w. jav a2s.  co m
        public void onClick(ClickEvent event) {
            onComplete.call(SurveyOperation.update(new Function1<Survey, Survey>() {
                @Override
                public Survey apply(Survey argument) {
                    return argument.markCompletionConfirmed();
                }
            }));
        }
    });

    content.add(WidgetFactory.createButtonsPanel(confirm));

    return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS);
}

From source file:nl.sense_os.commonsense.login.client.forgotpassword.ForgotPasswordActivity.java

License:Open Source License

private void onForgotPasswordFailure(int code, Throwable error) {
    errorDialog = new DialogBox();
    errorDialog.setHTML(SafeHtmlUtils.fromSafeConstant("<b>Request failed</b>"));

    AlertDialogContent content = new AlertDialogContent();
    content.setMessage(/*from w  ww  . j a va 2  s  . c o  m*/
            "The request to reset your password failed! Error: " + code + " (" + error.getMessage() + ")");
    content.setPresenter(this);

    errorDialog.setWidget(content);
    errorDialog.center();
}