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

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

Introduction

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

Prototype

public static String htmlEscape(String s) 

Source Link

Document

HTML-escapes a string.

Usage

From source file:uk.ac.ncl.openlab.intake24.client.survey.portionsize.AsServedScript.java

License:Apache License

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

    /*Logger log = Logger.getLogger("AsServedScript");
            /*from w  w  w  . j  a v a2 s. co  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, PromptMessages.INSTANCE.asServed_servedLessButtonLabel(),
                        PromptMessages.INSTANCE.asServed_servedMoreButtonLabel(),
                        PromptMessages.INSTANCE.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(PromptMessages.INSTANCE.asServed_leftoversQuestionPromptText(
                            SafeHtmlUtils.htmlEscape(foodData.description().toLowerCase()))),
                    PromptMessages.INSTANCE.yesNoQuestion_defaultYesLabel(),
                    PromptMessages.INSTANCE.yesNoQuestion_defaultNoLabel(), "leftovers", "leftoversWeight")));
        else
            return Option.some(withBackLink(asServedPrompt(leftoversImages.getOrDie(),
                    PromptMessages.INSTANCE.asServed_leftLessButtonLabel(),
                    PromptMessages.INSTANCE.asServed_leftMoreButtonLabel(),
                    PromptMessages.INSTANCE.asServed_leftContinueButtonLabel(), "leftoversChoiceIndex",
                    "leftoversImage", "leftoversWeight", defaultLeftoversPrompt(foodData.description()))));
    } else
        return done();
}

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.AssociatedFoodPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        Callback1<Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>> updateIntermediateState) {
    final EncodedFood food = (EncodedFood) pair.left;
    final AssociatedFood prompt = food.enabledPrompts.get(promptIndex);

    final FlowPanel content = new FlowPanel();
    PromptUtil.addBackLink(content);//from w  w  w  .  ja  v  a  2 s .c om
    final Panel promptPanel = WidgetFactory.createPromptPanel(
            SafeHtmlUtils.fromSafeConstant("<p>" + SafeHtmlUtils.htmlEscape(prompt.promptText) + "</p>"),
            WidgetFactory.createHelpButton(new ClickHandler() {
                @Override
                public void onClick(ClickEvent arg0) {
                    String promptType = AssociatedFoodPrompt.class.getSimpleName();
                    GoogleAnalytics.trackHelpButtonClicked(promptType);
                    ShepherdTour.startTour(getShepherdTourSteps(), promptType);
                }
            }));
    content.add(promptPanel);
    ShepherdTour.makeShepherdTarget(promptPanel);

    UxEventsHelper.postManualAssociatedFoodReceived(
            new ManualReceivedData(new FoodHeader(food.data.code, food.data.localDescription), prompt));

    final Callback1<FoodData> addNewFood = new Callback1<FoodData>() {
        @Override
        public void call(final FoodData result) {
            onComplete.call(MealOperation.update(new Function1<Meal, Meal>() {
                @Override
                public Meal apply(final Meal meal) {
                    // Special case for cereal:
                    // if a "milk on cereal" food is linked to a cereal food
                    // copy bowl type from the parent food
                    Option<String> bowl_id = getParamValue(food, "bowl");

                    FoodData foodData = bowl_id.accept(new Option.Visitor<String, FoodData>() {
                        @Override
                        public FoodData visitSome(String bowl_id) {
                            return result.withPortionSizeMethods(
                                    appendPotionSizeParameter(result.portionSizeMethods, "bowl", bowl_id));
                        }

                        @Override
                        public FoodData visitNone() {
                            return result;
                        }
                    });

                    EncodedFood assocFood = new EncodedFood(foodData, FoodLink.newUnlinked(),
                            "associated food prompt");

                    return linkAssociatedFood(meal.plusFood(assocFood), food, assocFood, prompt.linkAsMain);
                }

                ;
            }));
        }
    };

    final Callback addMissingFood = new Callback() {
        @Override
        public void call() {
            onComplete.call(MealOperation.update(new Function1<Meal, Meal>() {
                @Override
                public Meal apply(final Meal meal) {
                    FoodEntry missingFood = new MissingFood(FoodLink.newUnlinked(),
                            prompt.genericName.substring(0, 1).toUpperCase() + prompt.genericName.substring(1),
                            false, Option.<MissingFoodDescription>none())
                                    .withCustomDataField(MissingFood.KEY_ASSOC_FOOD_NAME, food.description())
                                    .withCustomDataField(MissingFood.KEY_ASSOC_FOOD_CATEGORY,
                                            prompt.foodOrCategoryCode.getRightOrDie());

                    return linkAssociatedFood(meal.plusFood(missingFood), food, missingFood, prompt.linkAsMain);
                }
            }));
        }
    };

    final Callback1<FoodEntry> addExistingFood = new Callback1<FoodEntry>() {
        @Override
        public void call(final FoodEntry existing) {
            onComplete.call(MealOperation.update(new Function1<Meal, Meal>() {
                @Override
                public Meal apply(final Meal meal) {
                    return linkAssociatedFood(meal, food, existing, prompt.linkAsMain);
                }

                ;
            }));
        }
    };

    foodBrowser = new FoodBrowser(locale, new Callback2<FoodData, Integer>() {
        @Override
        public void call(FoodData result, Integer index) {

            UxEventsHelper.postManualAssociatedFoodConfirmed(
                    new ManualConfirmedData(new FoodHeader(food.data.code, food.data.localDescription),
                            getSelectedFoods(), prompt, new FoodHeader(result.code, result.localDescription)));

            addNewFood.call(result);
        }
    }, new Callback1<String>() {
        @Override
        public void call(String code) {
            throw new RuntimeException("Special foods are not allowed as associated foods");
        }
    }, new Callback() {
        @Override
        public void call() {
            addMissingFood.call();
        }
    }, Option.<SkipFoodHandler>none(), false, Option.<Pair<String, String>>none(), Option.none(),
            Option.none());

    Button no = WidgetFactory.createButton(messages.assocFoods_noButtonLabel(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {

            UxEventsHelper.postManualAssociatedFoodRejected(
                    new ManualRejectedData(new FoodHeader(food.data.code, food.data.localDescription), prompt));

            onComplete
                    .call(MealOperation.updateEncodedFood(foodIndex, new Function1<EncodedFood, EncodedFood>() {
                        @Override
                        public EncodedFood apply(EncodedFood argument) {
                            return argument.minusPrompt(promptIndex);
                        }
                    }));
        }
    });

    Button yes = WidgetFactory.createButton(messages.assocFoods_yesButtonLabel(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (prompt.foodOrCategoryCode.isRight()) {
                content.clear();
                PromptUtil.addBackLink(content);
                content.add(promptPanel);
                content.add(new HTMLPanel(
                        SafeHtmlUtils.fromSafeConstant(messages.assocFoods_specificFoodPrompt())));
                content.add(interf);

                content.add(foodBrowser);
                isInBrowserMode = true;

                foodBrowser.browse(prompt.foodOrCategoryCode.getRightOrDie(),
                        messages.assocFoods_allFoodsDataSetName());
            } else {
                content.clear();
                content.add(new LoadingPanel(messages.foodBrowser_loadingMessage()));

                FoodDataService.INSTANCE.getFoodData(locale, prompt.foodOrCategoryCode.getLeftOrDie(),
                        new MethodCallback<FoodData>() {
                            @Override
                            public void onFailure(Method method, Throwable exception) {
                                content.clear();
                                content.add(WidgetFactory.createDefaultErrorMessage());
                                content.add(WidgetFactory.createBackLink());
                            }

                            @Override
                            public void onSuccess(Method method, FoodData response) {

                                UxEventsHelper.postManualAssociatedFoodConfirmed(new ManualConfirmedData(
                                        new FoodHeader(food.data.code, food.data.localDescription),
                                        getSelectedFoods(), prompt,
                                        new FoodHeader(response.code, response.localDescription)));

                                addNewFood.call(response);
                            }
                        });
            }
        }
    });

    yes.getElement().setId("intake24-assoc-food-yes-button");

    final int existingIndex = CollectionUtils.indexOf(pair.right.foods, new Function1<FoodEntry, Boolean>() {
        @Override
        public Boolean apply(FoodEntry argument) {
            return argument.accept(new FoodEntry.Visitor<Boolean>() {
                @Override
                public Boolean visitRaw(RawFood food) {
                    return false;
                }

                @Override
                public Boolean visitEncoded(EncodedFood food) {
                    // don't suggest foods that are already linked to other
                    // foods
                    if (food.link.isLinked())
                        return false;
                    // don't suggest linking the food to itself
                    else if (food.link.id.equals(pair.left.link.id))
                        return false;
                    // don't suggest if the food has foods linked to it
                    else if (!Meal.linkedFoods(pair.right.foods, food).isEmpty())
                        return false;
                    else if (prompt.foodOrCategoryCode.isRight())
                        return food.isInCategory(prompt.foodOrCategoryCode.getRightOrDie());
                    else
                        return food.data.code.equals(prompt.foodOrCategoryCode.getLeftOrDie());
                }

                @Override
                public Boolean visitTemplate(TemplateFood food) {
                    return false;
                }

                @Override
                public Boolean visitMissing(MissingFood food) {
                    return false;
                }

                @Override
                public Boolean visitCompound(CompoundFood food) {
                    return false;
                }
            });
        }
    });

    no.getElement().setId("intake24-assoc-food-no-button");

    tour = TreePVector.<ShepherdTour.Step>empty()
            .plus(new ShepherdTour.Step("noButton", "#intake24-assoc-food-no-button",
                    helpMessages.assocFood_noButtonTitle(), helpMessages.assocFood_noButtonDescription()))
            .plus(new ShepherdTour.Step("yesButton", "#intake24-assoc-food-yes-button",
                    helpMessages.assocFood_yesButtonTitle(), helpMessages.assocFood_yesButtonDescription()));

    if (existingIndex != -1) {
        Button yesExisting = WidgetFactory.createButton(messages.assocFoods_alreadyEntered(),
                new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        UxEventsHelper.postManualAssociatedFoodAlreadyReported(new ManualAlreadyReportedData(
                                new FoodHeader(food.data.code, food.data.localDescription), prompt));
                        addExistingFood.call(pair.right.foods.get(existingIndex));
                    }
                });

        yesExisting.getElement().setId("intake24-assoc-food-yes-existing-button");

        tour = tour.plus(new ShepherdTour.Step("yesButton", "#intake24-assoc-food-yes-existing-button",
                helpMessages.assocFood_yesExistingButtonTitle(),
                helpMessages.assocFood_yesExistingButtonDescription(), "top right", "bottom right"));

        ShepherdTour.makeShepherdTarget(yesExisting);

        buttonsPanel = WidgetFactory.createButtonsPanel(no, yes, yesExisting);
    } else {
        buttonsPanel = WidgetFactory.createButtonsPanel(no, yes);
    }

    content.add(buttonsPanel);

    ShepherdTour.makeShepherdTarget(yes, no);

    interf = new FlowPanel();

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.AutomaticAssociatedFoodsPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        Callback1<Function1<Meal, Meal>> updateIntermediateState) {
    final FlowPanel content = new FlowPanel();
    PromptUtil.addBackLink(content);/* www.j a  v  a 2  s .c o  m*/

    final FlowPanel promptPanel = WidgetFactory.createPromptPanel(SafeHtmlUtils.fromSafeConstant(
            messages.assocFoods_automaticPrompt(SafeHtmlUtils.htmlEscape(meal.name.toLowerCase()))));

    content.add(promptPanel);

    final LoadingPanel loading = new LoadingPanel(messages.foodBrowser_loadingMessage());

    content.add(loading);

    final ArrayList<FoodHeader> encodedFoods = new ArrayList<>();
    final ArrayList<String> foodCodes = new ArrayList<>();

    for (FoodEntry e : meal.foods) {
        if (e.isEncoded()) {

            EncodedFood ef = e.asEncoded();

            encodedFoods.add(new FoodHeader(ef.data.code, ef.data.localDescription));
            foodCodes.add(ef.data.code);
        }
    }

    FoodDataService.INSTANCE.getAutomaticAssociatedFoods(locale, foodCodes,
            new MethodCallback<AutomaticAssociatedFoods>() {
                @Override
                public void onFailure(Method method, Throwable exception) {
                    content.remove(loading);
                    content.add(WidgetFactory.createDefaultErrorMessage());
                }

                @Override
                public void onSuccess(Method method, AutomaticAssociatedFoods response) {
                    content.remove(loading);

                    final List<CheckBox> checkBoxes = new ArrayList<>();
                    final Map<CheckBox, CategoryHeader> foodMap = new LinkedHashMap<>();

                    List<CategoryHeader> categories = response.categories.stream()
                            .filter(c -> milkIsRerevant(c)).collect(Collectors.toList());

                    List<String> codes = categories.stream().map(c -> c.code).collect(Collectors.toList());

                    if (!cachedAssociatedFoodsChanged(codes) || codes.size() == 0) {
                        cacheAssociatedFoods(listToJsArray(new ArrayList<>()));
                        onComplete.call(MealOperation.update(m -> m.markAssociatedFoodsComplete()));
                    } else {
                        cacheAssociatedFoods(listToJsArray(codes));
                        UxEventsHelper.postAutomaticAssociatedFoodsReceived(new AutomaticData(
                                Viewport.getCurrent(), encodedFoods, response.categories, new ArrayList<>()));
                    }

                    for (CategoryHeader category : categories) {
                        CheckBox cb = new CheckBox(SafeHtmlUtils.fromString(category.description()));

                        FlowPanel div = new FlowPanel();
                        div.getElement().getStyle().setPaddingBottom(4, Style.Unit.PX);
                        div.add(cb);
                        cb.getElement().getFirstChildElement().getStyle().setMargin(0, Style.Unit.PX);
                        content.add(div);

                        checkBoxes.add(cb);
                        foodMap.put(cb, category);
                    }

                    Button continueButton = WidgetFactory.createGreenButton("Continue", "continue-button",
                            new ClickHandler() {
                                @Override
                                public void onClick(ClickEvent clickEvent) {

                                    ArrayList<String> selectedCategories = new ArrayList<>();

                                    for (CheckBox cb : checkBoxes) {
                                        if (cb.getValue()) {
                                            selectedCategories.add(foodMap.get(cb).code);
                                        }
                                    }

                                    UxEventsHelper.postAutomaticAssociatedFoodsResponse(
                                            new AutomaticData(Viewport.getCurrent(), encodedFoods,
                                                    response.categories, selectedCategories));

                                    onComplete.call(MealOperation.update(m -> {
                                        List<FoodEntry> newFoodEntries = new ArrayList<>();

                                        for (CheckBox cb : checkBoxes) {
                                            if (cb.getValue()) {
                                                Optional<FoodEntry> assocFood;
                                                CategoryHeader ch = foodMap.get(cb);
                                                switch (ch.code) {
                                                case SpecialData.FOOD_CODE_MILK_ON_CEREAL:
                                                    assocFood = meal.foods.stream()
                                                            .filter(f -> isCerealWithMilk(f)).findFirst();
                                                    if (assocFood.isPresent()) {
                                                        addFood(newFoodEntries, ch, assocFood);
                                                    }
                                                    break;
                                                case SpecialData.FOOD_CODE_MILK_IN_HOT_DRINK:
                                                    assocFood = meal.foods.stream()
                                                            .filter(f -> isHotDrinkWithMilk(f)).findFirst();
                                                    if (assocFood.isPresent()) {
                                                        addFood(newFoodEntries, ch, assocFood);
                                                    }
                                                    break;
                                                default:
                                                    addFood(newFoodEntries, ch, Optional.empty());
                                                    break;

                                                }
                                            }
                                        }

                                        if (newFoodEntries.size() > 0) {
                                            return m.withFoods(m.foods.plusAll(newFoodEntries));
                                        } else {
                                            cacheAssociatedFoods(listToJsArray(new ArrayList<>()));
                                            return m.withFoods(m.foods.plusAll(newFoodEntries))
                                                    .markAssociatedFoodsComplete();
                                        }

                                    }));
                                }
                            });

                    content.add(WidgetFactory.createButtonsPanel(continueButton));
                }
            });

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.BrandNamePrompt.java

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

    final FlowPanel content = new FlowPanel();

    FlowPanel promptPanel = WidgetFactory.createPromptPanel(
            SafeHtmlUtils.fromSafeConstant(
                    messages.brandName_promptText(SafeHtmlUtils.htmlEscape(description.toLowerCase()))),
            ShepherdTour.createTourButton(tour, BrandNamePrompt.class.getSimpleName()));
    ShepherdTour.makeShepherdTarget(promptPanel);

    content.add(promptPanel);//from w ww.  j a  v  a 2 s. c  om

    final Button contButton = WidgetFactory.createGreenButton(messages.brandName_continueButtonLabel(),
            "brandNameContinueButton", new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    onComplete.call(FoodOperation.updateEncoded(new Function1<EncodedFood, EncodedFood>() {
                        @Override
                        public EncodedFood apply(EncodedFood argument) {
                            return argument.withBrand(choice);
                        }
                    }));
                }
            });

    contButton.setEnabled(false);
    contButton.getElement().setId("intake24-brand-continue-button");
    ShepherdTour.makeShepherdTarget(contButton);

    VerticalPanel panel = new VerticalPanel();

    for (final String name : brandNames) {
        RadioButton btn = new RadioButton("brand", name);
        btn.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
            @Override
            public void onValueChange(ValueChangeEvent<Boolean> event) {
                if (event.getValue())
                    choice = name;
                contButton.setEnabled(true);
            }
        });
        panel.add(btn);
    }

    panel.setSpacing(4);
    panel.addStyleName("scran24-brand-name-choice-panel");
    panel.getElement().setId("intake24-brand-choice-panel");
    ShepherdTour.makeShepherdTarget(panel);

    content.add(panel);
    content.add(WidgetFactory.createButtonsPanel(contButton));

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.BreadLinkedFoodAmountPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        Callback1<Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>> updateIntermediateState) {
    FlowPanel content = new FlowPanel();

    final EncodedFood food = meal.foods.get(foodIndex).asEncoded();
    final EncodedFood mainFood = meal.foods.get(mainFoodIndex).asEncoded();

    final String foodDescription = SafeHtmlUtils.htmlEscape(food.description().toLowerCase());
    final String mainFoodDescription = SafeHtmlUtils.htmlEscape(mainFood.description().toLowerCase());

    final String quantityStr = NumberFormat.getDecimalFormat().format(quantity);

    final FlowPanel quantityPanel = new FlowPanel();

    FlowPanel promptPanel = WidgetFactory.createPromptPanel(
            SafeHtmlUtils.fromSafeConstant(
                    messages.breadLinkedFood_promptText(foodDescription, mainFoodDescription, quantityStr)),
            ShepherdTour.createTourButton(shepherdTour, BreadLinkedFoodAmountPrompt.class.getSimpleName()));

    PromptUtil.addBackLink(content);//from w  ww. j  a  va  2s.c om
    content.add(promptPanel);
    ShepherdTour.makeShepherdTarget(promptPanel);

    Button allButton = WidgetFactory.createButton(messages.breadLinkedFood_allButtonLabel(),
            new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    onComplete.call(MealOperation.updateFood(foodIndex, new Function1<FoodEntry, FoodEntry>() {
                        @Override
                        public FoodEntry apply(FoodEntry argument) {
                            EncodedFood f = argument.asEncoded();
                            return f.withPortionSize(
                                    PortionSize.complete(f.completedPortionSize().multiply(quantity))).withFlag(
                                            ShowBreadLinkedFoodAmountPrompt.FLAG_BREAD_LINKED_FOOD_AMOUNT_SHOWN);
                        }
                    }));
                }
            });

    allButton.getElement().setId("intake24-all-button");
    ShepherdTour.makeShepherdTarget(allButton);

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

    final QuantityCounter counter = new QuantityCounter(0.25, quantity, Math.max(1.0, quantity));

    ShepherdTour.makeShepherdTarget(counter.fractionalCounter);
    ShepherdTour.makeShepherdTarget(counter.wholeLabel);
    ShepherdTour.makeShepherdTarget(counter.wholeCounter);

    Button confirmQuantityButton = WidgetFactory.createGreenButton(messages.quantity_continueButtonLabel(),
            "quantityPromptContinueButton", new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    onComplete.call(MealOperation.updateFood(foodIndex, new Function1<FoodEntry, FoodEntry>() {
                        @Override
                        public FoodEntry apply(FoodEntry argument) {
                            EncodedFood f = argument.asEncoded();
                            return f.withPortionSize(
                                    PortionSize.complete(f.completedPortionSize().multiply(counter.getValue())))
                                    .withFlag(
                                            ShowBreadLinkedFoodAmountPrompt.FLAG_BREAD_LINKED_FOOD_AMOUNT_SHOWN);
                        }
                    }));
                }
            });

    quantityPanel.add(counter);
    quantityPanel.add(confirmQuantityButton);

    ShepherdTour.makeShepherdTarget(confirmQuantityButton);

    content.add(quantityPanel);

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.ChoosePortionSizeMethodPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<FoodOperation> onComplete,
        Callback1<Function1<FoodEntry, FoodEntry>> updateIntermediateState) {
    final FlowPanel content = new FlowPanel();
    content.addStyleName("intake24-choose-portion-method-prompt");

    PromptUtil.addBackLink(content);/*from   w w w.j  av a2s  .com*/

    final HTMLPanel header = new HTMLPanel("h2", food.description());

    content.add(header);

    FlowPanel promptPanel = WidgetFactory.createPromptPanel(
            SafeHtmlUtils.fromSafeConstant(messages.choosePortionMethod_promptText(food.description())),
            ShepherdTour.createTourButton(tour, ChoosePortionSizeMethodPrompt.class.getSimpleName()));
    content.add(promptPanel);
    ShepherdTour.makeShepherdTarget(promptPanel);

    final FlowPanel methodPanel = new FlowPanel();
    methodPanel.getElement().setId("intake24-choose-portion-panel");
    ShepherdTour.makeShepherdTarget(methodPanel);

    int index = 0;

    for (final PortionSizeMethod m : food.data.portionSizeMethods) {

        Image img = new Image(m.imageUrl);

        final int indexClosure = index;
        index++;

        ClickHandler clickHandler = new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                onComplete.call(FoodOperation.updateEncoded(new Function1<EncodedFood, EncodedFood>() {
                    @Override
                    public EncodedFood apply(EncodedFood argument) {
                        return argument.withSelectedPortionSizeMethod(indexClosure);
                    }
                }));
            }
        };

        img.addClickHandler(clickHandler);

        img.addStyleName("intake24-choose-portion-image");

        FlowPanel container = new FlowPanel();
        container.addStyleName("intake24-choose-portion-container");

        container.add(img);

        Label label = new Label(SafeHtmlUtils.htmlEscape(descriptions.getString(m.description)));
        label.addStyleName("intake24-choose-portion-label");
        label.addClickHandler(clickHandler);

        container.add(label);

        methodPanel.add(container);
    }

    content.add(methodPanel);

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.ConfirmMealPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        final Callback1<Function1<Meal, Meal>> onIntermediateStateChange) {
    final SafeHtml promptText = SafeHtmlUtils.fromSafeConstant(selectPromptMessage(meal.name));
    final String skipText = SafeHtmlUtils.htmlEscape(selectDeleteButtonMessage(meal.name));
    final String acceptText = SafeHtmlUtils.htmlEscape(messages.confirmMeal_confirmButtonLabel());
    final Time initialTime = meal.guessTime();

    FlowPanel content = new FlowPanel();

    TimeQuestion timeQuestion = new TimeQuestion(promptText, acceptText, skipText, initialTime,
            new TimeQuestion.ResultHandler() {
                @Override/*from w  w  w .j a va2  s . c o  m*/
                public void handleSkip() {
                    onComplete.call(MealOperation.deleteRequest(false));
                }

                @Override
                public void handleAccept(Time time) {
                    onComplete.call(MealOperation.update(Meal.updateTimeFunc(time)));
                }
            }, false);

    Button helpButton = ShepherdTour.createTourButton(tour, ConfirmMealPrompt.class.getSimpleName());
    helpButton.getElement().addClassName("intake24-prompt-float-widget");
    timeQuestion.promptPanel.insert(helpButton, 0);

    content.add(timeQuestion);

    ShepherdTour.makeShepherdTarget(timeQuestion.promptPanel, timeQuestion.timePicker.hourCounter,
            timeQuestion.timePicker.minuteCounter, timeQuestion.skipButton, timeQuestion.confirmButton);

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.ConfirmMealPromptFlexibleRecall.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        final Callback1<Function1<Meal, Meal>> onIntermediateStateChange) {
    final SafeHtml promptText = SafeHtmlUtils.fromSafeConstant(selectPromptMessage(meal.name));
    final String skipText = SafeHtmlUtils.htmlEscape(selectDeleteButtonMessage(meal.name));
    final String acceptText = SafeHtmlUtils.htmlEscape(messages.confirmMeal_confirmButtonLabel());
    final Time initialTime = meal.guessTime();

    FlowPanel content = new FlowPanel();

    TimeQuestionFlexibleRecall timeQuestion = new TimeQuestionFlexibleRecall(promptText, acceptText, skipText,
            initialTime, new TimeQuestionFlexibleRecall.ResultHandler() {
                @Override/*from   w w w  .  jav  a 2  s  .  c o m*/
                public void handleSkip() {
                    onComplete.call(MealOperation.deleteRequest(false));
                }

                @Override
                public void handleAccept(Time time) {
                    onComplete.call(MealOperation.update(Meal.updateTimeFunc(time)));
                }
            }, false, stateManager);

    Button helpButton = ShepherdTour.createTourButton(tour,
            ConfirmMealPromptFlexibleRecall.class.getSimpleName());
    helpButton.getElement().addClassName("intake24-prompt-float-widget");
    timeQuestion.promptPanel.insert(helpButton, 0);

    content.add(timeQuestion);

    ShepherdTour.makeShepherdTarget(timeQuestion.promptPanel, timeQuestion.timePicker.hourCounter,
            timeQuestion.timePicker.minuteCounter, timeQuestion.skipButton, timeQuestion.confirmButton);

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

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.DeleteMealPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<SurveyOperation> onComplete,
        final Callback1<Function1<Survey, Survey>> onIntermediateStateChange) {
    SafeHtml promptText = SafeHtmlUtils.fromSafeConstant(
            messages.deleteMeal_promptText(SafeHtmlUtils.htmlEscape(meal.name.toLowerCase())));

    Button deleteButton = WidgetFactory.createRedButton(messages.deleteMeal_deleteButtonLabel(),
            "deleteMealButton", new ClickHandler() {
                @Override// w  w  w  .j  a  v  a2 s  . c o  m
                public void onClick(ClickEvent event) {
                    onComplete.call(SurveyOperation.update(new Function1<Survey, Survey>() {
                        @Override
                        public Survey apply(Survey argument) {
                            return argument.minusMeal(mealIndex)
                                    .withSelection(new Selection.EmptySelection(SelectionMode.AUTO_SELECTION));
                        }
                    }));
                }
            });

    Button cancelButton = WidgetFactory.createButton(messages.deleteMeal_keepButtonLabel(), new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            onComplete.call(SurveyOperation.noChange);
        }
    });

    FlowPanel contents = new FlowPanel();
    contents.add(new HTMLPanel("h1", meal.safeNameWithTimeCapitalised()));
    contents.add(WidgetFactory.createPromptPanel(promptText));
    contents.add(WidgetFactory.createButtonsPanel(deleteButton, cancelButton));

    return new SurveyStageInterface.Aligned(contents, HasHorizontalAlignment.ALIGN_LEFT,
            HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS,
            DeleteMealPrompt.class.getSimpleName());
}

From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.DrinkReminderPrompt.java

License:Apache License

@Override
public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete,
        final Callback1<Function1<Meal, Meal>> onIntermediateStateChange) {
    final SafeHtml promptText = SafeHtmlUtils.fromSafeConstant(
            messages.drinkReminder_promptText((SafeHtmlUtils.htmlEscape(meal.name.toLowerCase()))));
    final String addDrinkText = SafeHtmlUtils.htmlEscape(messages.drinkReminder_addDrinkButtonLabel());
    final String noDrinkText = SafeHtmlUtils.htmlEscape(messages.drinkReminder_noDrinkButtonLabel());

    FlowPanel content = new FlowPanel();

    final HTMLPanel header = new HTMLPanel("h1",
            meal.name + " (" + meal.time.map(argument -> argument.toString()).getOrElse("Time unknown") + ")");

    content.add(header);/*from   w w w.  ja  v a 2  s  .  c  o m*/

    content.add(new YesNoQuestion(promptText, addDrinkText, noDrinkText, new YesNoQuestion.ResultHandler() {
        @Override
        public void handleYes() {
            onComplete.call(MealOperation.editFoodsRequest(true));
        }

        @Override
        public void handleNo() {
            onComplete.call(MealOperation.update(argument -> argument.markConfirmedNoDrinks()));
        }
    }));

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