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.flat.PromptUtil.java

License:Apache License

public static void addBackLink(FlowPanel container) {
    if (!History.getToken().equals("0")) {
        FlowPanel anchorDiv = new FlowPanel();
        anchorDiv.addStyleName("intake24-back-link-container");

        Anchor back = new Anchor(SafeHtmlUtils.fromSafeConstant(messages.goBackLabel()));
        back.addClickHandler(new ClickHandler() {
            @Override//from   w  w  w.java  2s .c  om
            public void onClick(ClickEvent event) {
                History.back();
            }
        });

        back.addStyleName("intake24-back-link");

        anchorDiv.add(back);
        container.insert(anchorDiv, 0);
    }
}

From source file:net.scran24.user.client.survey.flat.rules.AskIfHomeRecipe.java

private Prompt<FoodEntry, FoodOperation> buildPrompt(final String foodName, final boolean isDrink) {
    PVector<String> options = TreePVector.<String>empty().plus(messages.homeRecipe_haveRecipeChoice())
            .plus(messages.homeRecipe_noRecipeChoice());

    return PromptUtil.asFoodPrompt(new RadioButtonPrompt(
            SafeHtmlUtils.fromSafeConstant(
                    messages.homeRecipe_promptText(SafeHtmlUtils.htmlEscape(foodName.toLowerCase()))),
            AskIfHomeRecipe.class.getSimpleName(), options, messages.homeRecipe_continueButtonLabel(),
            "homeRecipeOption", Option.<String>none()), new Function1<String, FoodOperation>() {
                @Override/*from   w  w w  .  java  2s.c o m*/
                public FoodOperation apply(String argument) {
                    if (argument.equals(messages.homeRecipe_haveRecipeChoice())) {
                        GoogleAnalytics.trackMissingFoodHomeRecipe();
                        return FoodOperation
                                .replaceWith(new CompoundFood(FoodLink.newUnlinked(), foodName, isDrink));
                    } else {
                        return FoodOperation.update(new Function1<FoodEntry, FoodEntry>() {
                            @Override
                            public FoodEntry apply(FoodEntry argument) {
                                GoogleAnalytics.trackMissingFoodNotHomeRecipe();
                                return argument.withFlag(MissingFood.NOT_HOME_RECIPE_FLAG);
                            }
                        });
                    }
                }
            });
}

From source file:net.scran24.user.client.survey.flat.rules.ShowHomeRecipeServingsPrompt.java

@Override
public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> apply(final Pair<FoodEntry, Meal> data,
        SelectionMode selectionType, final PSet<String> surveyFlags) {
    return data.left.accept(new FoodEntry.Visitor<Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>>>() {

        private Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> getPromptIfApplicable(
                final FoodEntry food) {
            if (forall(Meal.linkedFoods(data.right.foods, data.left), FoodEntry.isPortionSizeComplete)
                    && (!food.customData.containsKey(Recipe.SERVINGS_NUMBER_KEY))) {

                FractionalQuantityPrompt quantityPrompt = new FractionalQuantityPrompt(
                        SafeHtmlUtils.fromSafeConstant(messages
                                .homeRecipe_servingsPromptText(SafeHtmlUtils.htmlEscape(food.description()))),
                        messages.homeRecipe_servingsButtonLabel());

                return Option.some(
                        PromptUtil.asExtendedFoodPrompt(quantityPrompt, new Function1<Double, MealOperation>() {
                            @Override
                            public MealOperation apply(final Double servings) {
                                return MealOperation.updateFood(data.right.foodIndex(food),
                                        new Function1<FoodEntry, FoodEntry>() {
                                            @Override
                                            public FoodEntry apply(FoodEntry argument) {
                                                return argument.withCustomDataField(Recipe.SERVINGS_NUMBER_KEY,
                                                        Double.toString(servings));
                                            }
                                        });

                            }//from   w w  w  .  j a va2s  .c  o m
                        }));
            } else {
                return Option.none();
            }
        }

        @Override
        public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitRaw(RawFood food) {
            return Option.none();
        }

        @Override
        public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitEncoded(EncodedFood food) {
            return Option.none();
        }

        @Override
        public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitTemplate(final TemplateFood food) {
            if (food.isTemplateComplete())
                return getPromptIfApplicable(food);
            else
                return Option.none();
        }

        @Override
        public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitMissing(MissingFood food) {
            return Option.none();
        }

        @Override
        public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitCompound(CompoundFood food) {
            return getPromptIfApplicable(food);
        }

    });
}

From source file:net.scran24.user.client.survey.portionsize.experimental.AsServedScript.java

License:Apache License

@Override
public Option<SimplePrompt<UpdateFunc>> nextPrompt(PMap<String, String> data, FoodData foodData) {
    boolean hasLeftoverImages = !leftoversImages.isEmpty();

    /*Logger log = Logger.getLogger("AsServedScript");
            //from   w  ww . ja va2s.c  o m
    log.info("Has leftovers: " + hasLeftoverImages);
            
    for (String k : data.keySet()) {
       log.info (k + " = " + data.get(k));
    }*/

    if (!data.containsKey("servingWeight")) {
        SimplePrompt<UpdateFunc> portionSizePrompt = withBackLink(asServedPrompt(servingImages,
                messages.asServed_servedLessButtonLabel(), messages.asServed_servedMoreButtonLabel(),
                messages.asServed_servedContinueButtonLabel(), "servingChoiceIndex", "servingImage",
                "servingWeight", defaultServingSizePrompt(foodData.description())));

        if (!hasLeftoverImages)
            return Option.some(setAdditionalField(portionSizePrompt, "leftoversWeight", "0"));
        else
            return Option.some(portionSizePrompt);
    } else if (!data.containsKey("leftoversWeight") && hasLeftoverImages) {
        if (!data.containsKey("leftovers"))
            return Option.some(withBackLink(yesNoPromptZeroField(
                    SafeHtmlUtils.fromSafeConstant(messages.asServed_leftoversQuestionPromptText(
                            SafeHtmlUtils.htmlEscape(foodData.description().toLowerCase()))),
                    messages.yesNoQuestion_defaultYesLabel(), messages.yesNoQuestion_defaultNoLabel(),
                    "leftovers", "leftoversWeight")));
        else
            return Option.some(withBackLink(asServedPrompt(leftoversImages.getOrDie(),
                    messages.asServed_leftLessButtonLabel(), messages.asServed_leftMoreButtonLabel(),
                    messages.asServed_leftContinueButtonLabel(), "leftoversChoiceIndex", "leftoversImage",
                    "leftoversWeight", defaultLeftoversPrompt(foodData.description()))));
    } else
        return done();
}

From source file:net.scran24.user.client.survey.portionsize.experimental.CerealPortionSizeScript.java

License:Apache License

@Override
public Option<SimplePrompt<UpdateFunc>> nextPrompt(PMap<String, String> data, FoodData foodData) {
    if (!data.containsKey("bowl")) {
        return Option
                .some(PromptUtil.map(//from  w  ww.j  av a 2 s.c om
                        withBackLink(
                                guidePrompt(SafeHtmlUtils.fromSafeConstant(messages.cereal_bowlPromptText()),
                                        bowlImageDef, "bowlIndex", "imageUrl")),
                        new Function1<UpdateFunc, UpdateFunc>() {
                            @Override
                            public UpdateFunc apply(final UpdateFunc f) {
                                return new UpdateFunc() {
                                    @Override
                                    public PMap<String, String> apply(PMap<String, String> argument) {
                                        PMap<String, String> a = f.apply(argument);
                                        return a.plus("bowl",
                                                bowlCodes.get(Integer.parseInt(a.get("bowlIndex")) - 1));
                                    }
                                };
                            }
                        }));
    }
    if (!data.containsKey("servingWeight")) {
        String asServedSetId = "cereal_" + data.get("type") + data.get("bowl");

        SimplePrompt<UpdateFunc> portionSizePrompt = withBackLink(
                asServedPrompt(asServedDefs.get(asServedSetId), messages.asServed_servedLessButtonLabel(),
                        messages.asServed_servedMoreButtonLabel(),
                        messages.asServed_servedContinueButtonLabel(), "servingChoiceIndex", "servingImage",
                        "servingWeight", defaultServingSizePrompt(foodData.description())));
        return Option.some(portionSizePrompt);
    } else if (!data.containsKey("leftoversWeight")) {
        if (!data.containsKey("leftovers"))
            return Option.some(withBackLink(yesNoPromptZeroField(
                    SafeHtmlUtils.fromSafeConstant(messages.asServed_leftoversQuestionPromptText(
                            SafeHtmlUtils.htmlEscape(foodData.description().toLowerCase()))),
                    messages.yesNoQuestion_defaultYesLabel(), messages.yesNoQuestion_defaultNoLabel(),
                    "leftovers", "leftoversWeight")));
        else {
            String leftoversSetId = "cereal_" + data.get("type") + data.get("bowl") + "_leftovers";

            return Option.some(withBackLink(asServedPrompt(asServedDefs.get(leftoversSetId),
                    messages.asServed_leftLessButtonLabel(), messages.asServed_leftMoreButtonLabel(),
                    messages.asServed_leftContinueButtonLabel(), "leftoversChoiceIndex", "leftoversImage",
                    "leftoversWeight", defaultLeftoversPrompt(foodData.description()))));
        }
    } else
        return done();
}

From source file:net.scran24.user.client.survey.portionsize.experimental.DrinkScaleScript.java

License:Apache License

@Override
public Option<SimplePrompt<UpdateFunc>> nextPrompt(final PMap<String, String> data, FoodData foodData) {
    String escapedFoodDesc = SafeHtmlUtils.htmlEscape(foodData.description().toLowerCase());

    if (!data.containsKey("containerIndex")) {
        return Option
                .some(PromptUtil/*w  w  w  . j ava 2 s  . c  o  m*/
                        .map(withBackLink(
                                withHeader(
                                        guidePrompt(
                                                SafeHtmlUtils.fromSafeConstant(messages
                                                        .drinkScale_containerPromptText(escapedFoodDesc)),
                                                guideImage, "containerIndex", "imageUrl"),
                                        foodData.description())),
                                calcFillVolumeIfSkip));
    } else if (!data.containsKey("fillLevel")) {
        return Option.some(PromptUtil.map(withBackLink(withHeader(
                drinkScalePrompt(SafeHtmlUtils.fromSafeConstant(messages.drinkScale_servedPromptText()),
                        getScaleDef(Integer.parseInt(data.get("containerIndex"))),
                        messages.drinkScale_servedLessButtonLabel(),
                        messages.drinkScale_servedMoreButtonLabel(),
                        messages.drinkScale_servedContinueButtonLabel(), 1.0,
                        Double.parseDouble(data.get("initial-fill-level")), "fillLevel"),
                foodData.description())), calcFillVolume));
    } else if (!data.containsKey("leftoversLevel")) {
        if (!data.containsKey("leftovers"))
            return Option.some(PromptUtil.map(withBackLink(withHeader(yesNoPromptZeroField(
                    SafeHtmlUtils
                            .fromSafeConstant(messages.drinkScale_leftoversQuestionPromptText(escapedFoodDesc)),
                    messages.yesNoQuestion_defaultYesLabel(), messages.yesNoQuestion_defaultNoLabel(),
                    "leftovers", "leftoversLevel"), foodData.description())), calcLeftoversVolume));
        else
            return Option.some(PromptUtil.map(withBackLink(withHeader(drinkScalePrompt(
                    SafeHtmlUtils.fromSafeConstant(messages.drinkScale_leftPromptText(escapedFoodDesc)),
                    getScaleDef(Integer.parseInt(data.get("containerIndex"))),
                    messages.drinkScale_leftLessButtonLabel(), messages.drinkScale_leftMoreButtonLabel(),
                    messages.drinkScale_leftContinueButtonLabel(), Double.parseDouble(data.get("fillLevel")),
                    Double.parseDouble(data.get("fillLevel")), "leftoversLevel"), foodData.description())),
                    calcLeftoversVolume));
    } else
        return done();
}

From source file:net.scran24.user.client.survey.portionsize.experimental.GuideScript.java

License:Apache License

@Override
public Option<SimplePrompt<UpdateFunc>> nextPrompt(PMap<String, String> data, FoodData foodData) {
    if (!data.containsKey("objectWeight")) {
        return Option.some(PromptUtil.map(
                withBackLink(guidePrompt(SafeHtmlUtils.fromSafeConstant(messages.guide_choicePromptText()),
                        guideDef.imageMap, "objectIndex", "imageUrl")),
                new Function1<UpdateFunc, UpdateFunc>() {
                    @Override//from   w w  w. ja v a2s.com
                    public UpdateFunc apply(final UpdateFunc f) {
                        return new UpdateFunc() {
                            @Override
                            public PMap<String, String> apply(PMap<String, String> argument) {
                                PMap<String, String> a = f.apply(argument);
                                return a.plus("objectWeight", Double.toString(
                                        guideDef.weights.get(Integer.parseInt(a.get("objectIndex")))));
                            }
                        };
                    }
                }));

    } else if (!data.containsKey("quantity")) {

        return Option.some(withBackLink(PromptUtil.map(
                quantityPrompt(SafeHtmlUtils.fromSafeConstant(messages.guide_quantityPromptText()),
                        messages.guide_quantityContinueButtonLabel(), "quantity"),
                new Function1<UpdateFunc, UpdateFunc>() {
                    @Override
                    public UpdateFunc apply(final UpdateFunc f) {
                        return new UpdateFunc() {
                            @Override
                            public PMap<String, String> apply(PMap<String, String> argument) {
                                PMap<String, String> a = f.apply(argument);
                                return a.plus("servingWeight",
                                        Double.toString(Double.parseDouble(a.get("objectWeight"))
                                                * Double.parseDouble(a.get("quantity"))))
                                        .plus("leftoversWeight", Double.toString(0));
                            }
                        };
                    }
                })));
    } else
        return done();
}

From source file:net.scran24.user.client.survey.portionsize.experimental.MilkInHotDrinkPortionSizeScript.java

License:Apache License

@Override
public Option<SimplePrompt<UpdateFunc>> nextPrompt(PMap<String, String> data, final FoodData foodData) {
    if (!data.containsKey("milkPartIndex"))
        return Option.some(withBackLink(standardUnitChoicePrompt(
                SafeHtmlUtils.fromSafeConstant(messages
                        .milkInHotDrink_promptText(foodData.description().toLowerCase(), "tea or coffee")),
                messages.milkInHotDrink_confirmButtonLabel(), amounts,
                new Function1<StandardUnitDef, String>() {
                    @Override/*from ww w .java 2  s .co m*/
                    public String apply(StandardUnitDef argument) {
                        return argument.name;
                    }
                }, "milkPartIndex")));
    else
        return done();
}

From source file:net.scran24.user.client.survey.portionsize.experimental.MilkOnCerealPortionSizeScript.java

@Override
public Option<SimplePrompt<UpdateFunc>> nextPrompt(PMap<String, String> data, final FoodData foodData) {
    if (!data.containsKey("bowl")) {
        return Option
                .some(PromptUtil.map(/*from  www. j  a  v a 2 s . c  o m*/
                        withBackLink(
                                guidePrompt(SafeHtmlUtils.fromSafeConstant(messages.cereal_bowlPromptText()),
                                        bowlImageMap, "bowlIndex", "imageUrl")),
                        new Function1<UpdateFunc, UpdateFunc>() {
                            @Override
                            public UpdateFunc apply(final UpdateFunc f) {
                                return new UpdateFunc() {
                                    @Override
                                    public PMap<String, String> apply(PMap<String, String> argument) {
                                        PMap<String, String> a = f.apply(argument);
                                        return a.plus("bowl", CerealPortionSizeScript.bowlCodes
                                                .get(Integer.parseInt(a.get("bowlIndex")) - 1));
                                    }
                                };
                            }
                        }));
    }
    if (!data.containsKey("servingWeight")) {
        String imageMapId = milkLevelImageMapPrefix + data.get("bowl");

        SimplePrompt<UpdateFunc> portionSizePrompt = PromptUtil.map(
                withBackLink(guidePrompt(SafeHtmlUtils.fromSafeConstant(messages.cereal_milkLevelPromptText()),
                        milkLevelImageMaps.get(imageMapId), "milkLevelChoice", "milkLevelImage")),
                new Function1<UpdateFunc, UpdateFunc>() {
                    @Override
                    public UpdateFunc apply(final UpdateFunc f) {
                        return new UpdateFunc() {
                            public PMap<String, String> apply(PMap<String, String> argument) {
                                PMap<String, String> a = f.apply(argument);
                                return a.plus("servingWeight",
                                        Double.toString(milkWeight(a.get("bowl"),
                                                Integer.parseInt(a.get("milkLevelChoice")))))
                                        .plus("leftoversWeight", "0");
                            }
                        };
                    }
                });

        return Option.some(portionSizePrompt);
    }
    return done();
}

From source file:net.scran24.user.client.survey.portionsize.experimental.PizzaPortionSizeScript.java

@Override
public Option<SimplePrompt<UpdateFunc>> nextPrompt(PMap<String, String> data, final FoodData foodData) {
    if (!data.containsKey("pizzaType")) {
        return Option
                .some(withBackLink(guidePrompt(SafeHtmlUtils.fromSafeConstant(messages.pizza_typePromptText()),
                        pizzaTypeImageMap, "pizzaType", "imageUrl")));
    } else if (!data.containsKey("pizzaThickness")) {
        return Option.some(
                withBackLink(guidePrompt(SafeHtmlUtils.fromSafeConstant(messages.pizza_thicknessPromptText()),
                        pizzaThicknessImageMap, "pizzaThickness", "imageUrl")));
    } else if (!data.containsKey("sliceType")) {
        Integer pizzaType = Integer.parseInt(data.get("pizzaType"));

        Function1<Callback1<Integer>, Panel> wholePizzaButton = new Function1<Callback1<Integer>, Panel>() {
            @Override/*from w  w  w  .  ja  v a  2  s. com*/
            public Panel apply(final Callback1<Integer> onComplete) {
                return WidgetFactory.createButtonsPanel(
                        WidgetFactory.createButton(messages.pizza_sliceWholePizza(), new ClickHandler() {
                            @Override
                            public void onClick(ClickEvent event) {
                                onComplete.call(0);
                            }
                        }));
            }
        };

        SimplePrompt<UpdateFunc> portionSizePrompt = withBackLink(
                guidePromptEx(SafeHtmlUtils.fromSafeConstant(messages.pizza_sliceSizePromptText()),
                        sliceSizeImageMap.get(pizzaType), "sliceType", "sliceImage", wholePizzaButton));
        return Option.some(portionSizePrompt);
    } else if (!data.containsKey("sliceQuantity")) {
        return Option.some(PromptUtil.map(
                withBackLink(
                        quantityPrompt(SafeHtmlUtils.fromSafeConstant(messages.pizza_sliceQuantityPromptText()),
                                messages.pizza_sliceQuantityContinueButtonLabel(), "sliceQuantity")),
                new Function1<UpdateFunc, UpdateFunc>() {
                    @Override
                    public UpdateFunc apply(final UpdateFunc f) {
                        return new UpdateFunc() {
                            @Override
                            public PMap<String, String> apply(PMap<String, String> argument) {
                                PMap<String, String> a = f.apply(argument);
                                return a.plus("servingWeight",
                                        Double.toString(sliceWeight(Integer.parseInt(a.get("pizzaType")),
                                                Integer.parseInt(a.get("sliceType")),
                                                Integer.parseInt(a.get("pizzaThickness")))
                                                * Double.parseDouble(a.get("sliceQuantity"))))
                                        .plus("leftoversWeight", Double.toString(0));
                            }
                        };
                    }
                }));
    } else
        return done();
}