List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape
public static String htmlEscape(String s)
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.EditMealPrompt.java
License:Apache License
@Override public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete, final Callback1<Function1<Meal, Meal>> onIntermediateStateChange) { final SafeHtml promptText = SafeHtmlUtils .fromSafeConstant(messages.editMeal_promptText(SafeHtmlUtils.htmlEscape(meal.name.toLowerCase()))); final Function1<FoodEntry, Boolean> foodFilter = new Function1<FoodEntry, Boolean>() { @Override/*from w ww . j av a 2s. c om*/ public Boolean apply(FoodEntry argument) { return !argument.isDrink(); } }; final Function1<FoodEntry, Boolean> drinkFilter = new Function1<FoodEntry, Boolean>() { @Override public Boolean apply(FoodEntry argument) { return argument.isDrink(); } }; final Button done = WidgetFactory.createGreenButton(messages.editMeal_finishButtonLabel(), "editMealFinishButton", new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(new MealOperation() { @Override public <R> R accept(Visitor<R> visitor) { return visitor.visitUpdate(new Function1<Meal, Meal>() { @Override public Meal apply(Meal argument) { return argument .withFoods(TreePVector.<FoodEntry>empty() .plusAll(foodList.getEnteredItems()) .plusAll(drinkList.getEnteredItems())) .markFreeEntryComplete().clearAssociatedFoodsComplete(); } }); } }); } }); done.getElement().setId("intake24-done-button"); final Callback1<List<FoodEntry>> onChange = new Callback1<List<FoodEntry>>() { @Override public void call(List<FoodEntry> arg1) { TreePVector<FoodEntry> newItems = TreePVector.<FoodEntry>empty().plusAll(foodList.getEnteredItems()) .plusAll(drinkList.getEnteredItems()); onIntermediateStateChange.call(Meal.updateFoodsFunc(newItems)); } }; // Food list foodList = new EditableFoodList(meal.foods, foodFilter, messages.editMeal_addFoodButtonLabel(), false, onChange); final HTMLPanel foodHeader = new HTMLPanel("h2", SafeHtmlUtils.htmlEscape(messages.editMeal_foodHeader())); final FlowPanel foodListContainer = new FlowPanel(); foodListContainer.getElement().setId("intake24-food-list"); foodListContainer.add(foodHeader); foodListContainer.add(foodList); ShepherdTour.makeShepherdTarget(foodListContainer); // Drinks list drinkList = new EditableFoodList(meal.foods, drinkFilter, messages.editMeal_addDrinkButtonLabel(), true, onChange); final HTMLPanel drinksHeader = new HTMLPanel("h2", SafeHtmlUtils.htmlEscape(messages.editMeal_drinksHeader())); drinkList.getElement().setId("intake24-drink-list"); final FlowPanel drinkListContainer = new FlowPanel(); drinkListContainer.getElement().setId("intake24-drink-list"); drinkListContainer.add(drinksHeader); drinkListContainer.add(drinkList); ShepherdTour.makeShepherdTarget(drinkListContainer); Button changeTime = WidgetFactory.createButton(messages.editMeal_changeTimeButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.editTimeRequest); } }); changeTime.getElement().setId("intake24-change-time-button"); Button delete = WidgetFactory.createButton(messages.editMeal_deleteMealButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.deleteRequest(true)); } }); delete.getElement().setId("intake24-delete-button"); final HTMLPanel header = new HTMLPanel("h1", LocaleUtil.capitaliseFirstCharacter(meal.safeNameWithTime())); header.getElement().setId("intake24-meal-name"); ShepherdTour.makeShepherdTarget(header); FlowPanel contents = new FlowPanel(); contents.addStyleName("intake24-edit-meal-prompt"); contents.add(header); Panel promptPanel = WidgetFactory.createPromptPanel(promptText, ShepherdTour.createTourButton(tour, EditMealPrompt.class.getSimpleName())); contents.add(promptPanel); ShepherdTour.makeShepherdTarget(promptPanel); contents.add(foodListContainer); contents.add(drinkListContainer); contents.add(WidgetFactory.createButtonsPanel(changeTime, delete, done)); ShepherdTour.makeShepherdTarget(changeTime, delete, done); return new SurveyStageInterface.Aligned(contents, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, EditMealPrompt.class.getSimpleName(), Option.<Callback>some(new Callback() { @Override public void call() { if (addDrink) drinkList.focusNew(); } })); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.EditRecipeIngredientsPrompt.java
@Override public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete, final Callback1<Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>> onIntermediateStateChange) { final SafeHtml promptText = SafeHtmlUtils.fromSafeConstant(messages.editRecipeIngredientsPrompt_promptText( SafeHtmlUtils.htmlEscape(meal.foods.get(foodIndex).description()))); final UUID compoundFoodId = meal.foods.get(foodIndex).link.id; final Function1<FoodEntry, Boolean> noLinkedFoodsFilter = new Function1<FoodEntry, Boolean>() { @Override// ww w.j a v a 2s . c om public Boolean apply(FoodEntry argument) { return argument.link.linkedTo.accept(new Option.Visitor<UUID, Boolean>() { @Override public Boolean visitSome(UUID item) { return !item.equals(compoundFoodId); } @Override public Boolean visitNone() { return true; } }); } }; final Button done = WidgetFactory.createGreenButton( messages.editRecipeIngredientsPrompt_continueButtonLabel(), "editRecipeContinueButton", new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.update(new Function1<Meal, Meal>() { @Override public Meal apply(Meal argument) { ArrayList<FoodEntry> linkedFoods = new ArrayList<FoodEntry>(); for (FoodEntry e : ingredientList.getEnteredItems()) linkedFoods.add(e.relink(FoodLink.newLinked(compoundFoodId)) .withFlag(RawFood.FLAG_RECIPE_INGREDIENT)); return argument.withFoods(filter(argument.foods, noLinkedFoodsFilter)) .plusAllFoods(linkedFoods).updateFood(foodIndex, argument.foods .get(foodIndex).withFlag(CompoundFood.FLAG_INGREDIENTS_COMPLETE)); } })); } }); done.getElement().setId("intake24-done-button"); ingredientList = new EditableFoodList(messages.editMeal_addFoodButtonLabel(), false, new Callback1<List<FoodEntry>>() { @Override public void call(List<FoodEntry> arg1) { onIntermediateStateChange .call(new Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>() { @Override public Pair<FoodEntry, Meal> apply(Pair<FoodEntry, Meal> argument) { ArrayList<FoodEntry> linkedFoods = new ArrayList<FoodEntry>(); for (FoodEntry e : ingredientList.getEnteredItems()) linkedFoods.add(e.relink(FoodLink.newLinked(compoundFoodId)) .withFlag(RawFood.FLAG_RECIPE_INGREDIENT)); return Pair.create(null, argument.right .withFoods( filter(argument.right.foods, noLinkedFoodsFilter)) .plusAllFoods(linkedFoods)); } }); } }); ingredientList.disableLinkedFoodsIndentation(); for (FoodEntry f : Meal.linkedFoods(meal.foods, meal.foods.get(foodIndex))) ingredientList.addItem(Option.some(f)); final HTMLPanel foodHeader = new HTMLPanel("h2", SafeHtmlUtils.htmlEscape(messages.editRecipeIngredientsPrompt_ingredientsHeader())); final FlowPanel foodListContainer = new FlowPanel(); foodListContainer.getElement().setId("intake24-ingredient-list"); foodListContainer.add(foodHeader); foodListContainer.add(ingredientList); ShepherdTour.makeShepherdTarget(foodListContainer); FlowPanel contents = new FlowPanel(); contents.addStyleName("intake24-edit-meal-prompt"); Panel promptPanel = WidgetFactory.createPromptPanel(promptText, ShepherdTour.createTourButton(tour, EditRecipeIngredientsPrompt.class.getSimpleName())); contents.add(promptPanel); ShepherdTour.makeShepherdTarget(promptPanel); contents.add(foodListContainer); contents.add(WidgetFactory.createButtonsPanel(done)); ShepherdTour.makeShepherdTarget(done); return new SurveyStageInterface.Aligned(contents, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, EditRecipeIngredientsPrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.FoodCompletePrompt.java
@Override public SurveyStageInterface getInterface(final Callback1<FoodOperation> onComplete, final Callback1<Function1<FoodEntry, FoodEntry>> onIntermediateStateChange) { final SafeHtml promptText = SafeHtmlUtils.fromSafeConstant( messages.foodComplete_promptText(SafeHtmlUtils.htmlEscape(food.description().toLowerCase()))); Button contButton = WidgetFactory.createButton(messages.foodComplete_continueButtonLabel(), new ClickHandler() { @Override//from w w w . j a v a 2 s.c o m public void onClick(ClickEvent event) { onComplete.call(FoodOperation.noChange); } }); Button addButton = WidgetFactory.createButton(messages.foodComplete_editMealButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(FoodOperation.editFoodsRequest); } }); Button editIngredients = WidgetFactory.createButton(messages.foodComplete_editIngredients(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(FoodOperation.update(new Function1<FoodEntry, FoodEntry>() { @Override public FoodEntry apply(FoodEntry argument) { return argument .withFlags(argument.flags.minus(CompoundFood.FLAG_INGREDIENTS_COMPLETE)); } })); } }); Button deleteButton = WidgetFactory.createRedButton(messages.foodComplete_deleteFoodButtonLabel(), "deleteFoodButton", new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(FoodOperation.deleteRequest); } }); FlowPanel contents = new FlowPanel(); contents.add(WidgetFactory.createPromptPanel(promptText)); if (food.isCompound() && food.flags.contains(CompoundFood.FLAG_INGREDIENTS_COMPLETE)) contents.add(WidgetFactory.createButtonsPanel(contButton, editIngredients, deleteButton)); else contents.add(WidgetFactory.createButtonsPanel(contButton, addButton, deleteButton)); return new SurveyStageInterface.Aligned(contents, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, FoodCompletePrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.FoodLookupPrompt.java
License:Apache License
@Override public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete, Callback1<Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>> updateIntermediateState) { LookupInterface ui = new LookupInterface(meal, food, onComplete); String browseCategory = food.customData.get(RawFood.KEY_BROWSE_CATEGORY_INSTEAD_OF_LOOKUP); if (browseCategory != null) { ui.browse(browseCategory, SafeHtmlUtils.htmlEscape(food.description())); } else//from w ww. ja va 2 s . com ui.lookup(food.description()); return ui; }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.MealCompletePrompt.java
@Override public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete, final Callback1<Function1<Meal, Meal>> onIntermediateStateChange) { final SafeHtml promptText = SafeHtmlUtils.fromSafeConstant( messages.mealComplete_promptText(SafeHtmlUtils.htmlEscape(meal.name.toLowerCase()))); Button contButton = WidgetFactory.createButton(messages.mealComplete_continueButtonLabel(), new ClickHandler() { @Override/*from ww w. j ava2 s.com*/ public void onClick(ClickEvent event) { onComplete.call(MealOperation.noChange); } }); Button addButton = WidgetFactory.createButton(messages.mealComplete_editMealButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.editFoodsRequest(false)); } }); Button timeButton = WidgetFactory.createButton(messages.mealComplete_editTimeButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.editTimeRequest); } }); Button deleteButton = WidgetFactory.createRedButton(messages.mealComplete_deleteButtonLabel(), "mealCompleteDeleteButton", new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.deleteRequest(true)); } }); FlowPanel contents = new FlowPanel(); contents.add(WidgetFactory.createPromptPanel(promptText)); contents.add(WidgetFactory.createButtonsPanel(contButton, addButton, timeButton, deleteButton)); return new SurveyStageInterface.Aligned(contents, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, MealCompletePrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.MissingFoodDescriptionPrompt.java
@Override public SurveyStageInterface getInterface(final Callback1<FoodOperation> onComplete, final Callback1<Function1<FoodEntry, FoodEntry>> onIntermediateStateChange) { final FlowPanel content = new FlowPanel(); Panel questionPanel;//from ww w. j a v a 2s . c o m if (food.customData.containsKey(MissingFood.KEY_ASSOC_FOOD_NAME)) { questionPanel = WidgetFactory.createPromptPanel( SafeHtmlUtils.fromSafeConstant( messages.missingFood_assocFoodPrompt(SafeHtmlUtils.htmlEscape(food.name.toLowerCase()), SafeHtmlUtils.htmlEscape( food.customData.get(MissingFood.KEY_ASSOC_FOOD_NAME).toLowerCase()))), ShepherdTour.createTourButton(tour, MissingFoodDescriptionPrompt.class.getSimpleName())); } else { questionPanel = WidgetFactory.createPromptPanel( SafeHtmlUtils.fromSafeConstant( messages.missingFood_prompt(SafeHtmlUtils.htmlEscape(food.name.toLowerCase()))), ShepherdTour.createTourButton(tour, MissingFoodDescriptionPrompt.class.getSimpleName())); } content.add(questionPanel); FlowPanel foodName = new FlowPanel(); foodName.getElement().setId("intake24-missing-food-name"); Label foodNameLabel = WidgetFactory.createLabel(messages.missingFood_nameLabel()); content.add(foodNameLabel); final TextBox foodNameTextBox = new TextBox(); foodNameTextBox.getElement().addClassName("intake24-missing-food-textbox"); foodNameTextBox.setText(food.name); foodName.add(foodNameLabel); foodName.add(foodNameTextBox); content.add(foodName); if (food.name.equals("Missing food")) { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { foodNameTextBox.setFocus(true); foodNameTextBox.selectAll(); } }); } FlowPanel brand = new FlowPanel(); brand.getElement().setId("intake24-missing-food-brand"); Label brandLabel = WidgetFactory.createLabel(messages.missingFood_brandLabel()); brand.add(brandLabel); final TextBox brandTextBox = new TextBox(); brandTextBox.getElement().addClassName("intake24-missing-food-textbox"); brand.add(brandTextBox); content.add(brand); FlowPanel description = new FlowPanel(); description.getElement().setId("intake24-missing-food-description"); Label descriptionLabel = WidgetFactory.createLabel(messages.missingFood_descriptionLabel()); description.add(descriptionLabel); final TextArea descriptionTextArea = new TextArea(); descriptionTextArea.getElement().addClassName("intake24-missing-food-textarea"); description.add(descriptionTextArea); content.add(description); FlowPanel portionSize = new FlowPanel(); portionSize.getElement().setId("intake24-missing-food-portion-size"); Label portionSizeLabel = WidgetFactory.createLabel(messages.missingFood_portionSizeLabel()); portionSize.add(portionSizeLabel); final TextArea portionSizeTextArea = new TextArea(); portionSizeTextArea.getElement().addClassName("intake24-missing-food-textarea"); portionSize.add(portionSizeTextArea); content.add(portionSize); FlowPanel leftovers = new FlowPanel(); leftovers.getElement().setId("intake24-missing-food-leftovers"); Label leftoversLabel = WidgetFactory.createLabel(messages.missingFood_leftoversLabel()); leftovers.add(leftoversLabel); final TextArea leftoversTextArea = new TextArea(); leftoversTextArea.getElement().addClassName("intake24-missing-food-textarea"); leftovers.add(leftoversTextArea); content.add(leftovers); Button cont = WidgetFactory.createGreenButton(messages.missingFood_continueButtonLabel(), "missingFoodContinueButton", new ClickHandler() { @Override public void onClick(ClickEvent event) { String name = foodNameTextBox.getText(); if (name.isEmpty()) name = food.name; onComplete.call(FoodOperation.replaceWith( new MissingFood(food.link, name, food.isDrink, Option.some(new MissingFoodDescription(mkOption(brandTextBox.getText()), mkOption(descriptionTextArea.getText()), mkOption(portionSizeTextArea.getText()), mkOption(leftoversTextArea.getText()))), food.flags, food.customData))); } }); cont.getElement().setId("intake24-missing-food-continue-button"); content.add(WidgetFactory.createButtonsPanel(cont)); ShepherdTour.makeShepherdTarget(questionPanel, foodName, description, brand, portionSize, leftovers, cont); return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, MissingFoodDescriptionPrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.ReadyMealsPrompt.java
@Override public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete, final Callback1<Function1<Meal, Meal>> onIntermediateStateChange) { FlowPanel content = new FlowPanel(); FlowPanel promptPanel = WidgetFactory.createPromptPanel( SafeHtmlUtils.fromSafeConstant( messages.readyMeals_promptText(SafeHtmlUtils.htmlEscape(meal.name.toLowerCase()))), ShepherdTour.createTourButton(tour, ReadyMealsPrompt.class.getSimpleName())); ShepherdTour.makeShepherdTarget(promptPanel); content.add(promptPanel);//from ww w . j a v a 2s.c om PVector<WithIndex<FoodEntry>> potentialReadyMeals = filter(zipWithIndex(meal.foods), new Function1<WithIndex<FoodEntry>, Boolean>() { @Override public Boolean apply(WithIndex<FoodEntry> argument) { return argument.value.accept(new FoodEntry.Visitor<Boolean>() { @Override public Boolean visitRaw(RawFood food) { return false; } @Override public Boolean visitEncoded(EncodedFood food) { return !food.isDrink() && !food.link.isLinked() && food.data.readyMealOption; } @Override public Boolean visitTemplate(TemplateFood food) { return false; } @Override public Boolean visitMissing(MissingFood food) { return false; } @Override public Boolean visitCompound(CompoundFood food) { return false; } }); } }); final Map<CheckBox, Integer> checkBoxToIndex = new HashMap<CheckBox, Integer>(); FlowPanel checkboxesDiv = new FlowPanel(); checkboxesDiv.addStyleName("scran24-ready-meals-checkboxes-block"); checkboxesDiv.getElement().setId("intake24-ready-meals-list"); for (WithIndex<FoodEntry> f : potentialReadyMeals) { FlowPanel rowDiv = new FlowPanel(); CheckBox readyMealCheck = new CheckBox(SafeHtmlUtils.htmlEscape(f.value.description())); readyMealCheck.addStyleName("scran24-ready-meals-checkbox"); checkBoxToIndex.put(readyMealCheck, f.index); rowDiv.add(readyMealCheck); checkboxesDiv.add(rowDiv); } content.add(checkboxesDiv); Button finishedButton = WidgetFactory.createButton(messages.editMeal_finishButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.update(new Function1<Meal, Meal>() { @Override public Meal apply(Meal argument) { Meal result = argument; for (CheckBox check : checkBoxToIndex.keySet()) { int index = checkBoxToIndex.get(check); result = (check.getValue()) ? result.updateFood(index, result.foods.get(index).markReadyMeal()) : result; } return result.markReadyMealsComplete(); } })); } }); finishedButton.getElement().setId("intake24-ready-meals-finished-button"); ShepherdTour.makeShepherdTarget(checkboxesDiv, finishedButton); content.add(WidgetFactory.createButtonsPanel(finishedButton)); return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, ReadyMealsPrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.SameAsBeforePrompt.java
@Override public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete, Callback1<Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>> updateIntermediateState) { final FlowPanel content = new FlowPanel(); PromptUtil.addBackLink(content);/* w w w .j a v a 2 s . c o m*/ final Panel promptPanel = WidgetFactory.createPromptPanel( SafeHtmlUtils.fromSafeConstant(messages .sameAsBefore_promptText(SafeHtmlUtils.htmlEscape(food.description().toLowerCase()))), ShepherdTour.createTourButton(tour, SameAsBeforePrompt.class.getSimpleName())); content.add(promptPanel); final EncodedFood mainFoodAsBefore = asBefore.mainFood; final PVector<FoodEntry> assocFoodsAsBefore = asBefore.linkedFoods; final double leftoversWeight = mainFoodAsBefore.completedPortionSize().leftoversWeight(); final double servingWeight = mainFoodAsBefore.completedPortionSize().servingWeight(); final int leftoversPercent = (int) (leftoversWeight * 100.0 / servingWeight); final int leftoversPercentRounded = (leftoversPercent + 4) / 5 * 5; final String portionSize = messages.sameAsBefore_servingSize( Integer.toString((int) servingWeight) + (mainFoodAsBefore.isDrink() ? " ml" : " g")); final String leftovers = (leftoversWeight < 0.01) ? (mainFoodAsBefore.isDrink() ? messages.sameAsBefore_noLeftoversDrink() : messages.sameAsBefore_noLeftoversFood()) : messages.sameAsBefore_leftovers(leftoversPercentRounded + "%"); HTMLPanel portionSizePanel = new HTMLPanel(portionSize); portionSizePanel.getElement().setId("intake24-sab-portion-size"); content.add(portionSizePanel); HTMLPanel leftoversPanel = new HTMLPanel(leftovers); leftoversPanel.getElement().setId("intake24-sab-leftovers"); content.add(leftoversPanel); String assocFoodsHTML = messages.sameAsBefore_hadItWith(); if (!assocFoodsAsBefore.isEmpty()) assocFoodsHTML += "<ul>"; for (FoodEntry f : assocFoodsAsBefore) { EncodedFood assocFood = f.asEncoded(); String assocFoodDescription; if (assocFood.isInCategory(SpecialData.FOOD_CODE_MILK_IN_HOT_DRINK)) assocFoodDescription = SafeHtmlUtils.htmlEscape(assocFood.description()) + " (" + SafeHtmlUtils.htmlEscape(MilkInHotDrinkPortionSizeScript.amounts.get( Integer.parseInt(assocFood.completedPortionSize().data.get("milkPartIndex"))).name) + ")"; else assocFoodDescription = SafeHtmlUtils.htmlEscape(assocFood.description()) + " (" + Integer.toString((int) assocFood.completedPortionSize().servingWeight()) + (assocFood.isDrink() ? " ml" : " g") + ")"; assocFoodsHTML += "<li>" + assocFoodDescription + "</li>"; } HTMLPanel assocFoodsPanel; if (!assocFoodsAsBefore.isEmpty()) { assocFoodsHTML += "</ul>"; assocFoodsPanel = new HTMLPanel(assocFoodsHTML); } else { assocFoodsPanel = new HTMLPanel(messages.sameAsBefore_noAddedFoods()); } assocFoodsPanel.getElement().setId("intake24-sab-assoc-foods"); content.add(assocFoodsPanel); Button yes = WidgetFactory.createButton(messages.sameAsBefore_confirmButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.update(new Function1<Meal, Meal>() { @Override public Meal apply(final Meal meal) { PVector<FoodEntry> updatedFoods = meal.foods .with(foodIndex, food.withPortionSize( PortionSize.complete(mainFoodAsBefore.completedPortionSize())) .disableAllPrompts()) .plusAll(map(assocFoodsAsBefore, new Function1<FoodEntry, FoodEntry>() { @Override public FoodEntry apply(FoodEntry assocFood) { return assocFood.relink(FoodLink.newLinked(food.link.id)); } })); return meal.withFoods(updatedFoods); } })); } }); yes.getElement().setId("intake24-sab-yes-button"); Button no = WidgetFactory.createButton(messages.sameAsBefore_rejectButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete .call(MealOperation.updateEncodedFood(foodIndex, new Function1<EncodedFood, EncodedFood>() { @Override public EncodedFood apply(EncodedFood argument) { return argument.markNotSameAsBefore(); } })); } }); no.getElement().setId("intake24-sab-no-button"); content.add(WidgetFactory.createButtonsPanel(yes, no)); ShepherdTour.makeShepherdTarget(promptPanel, portionSizePanel, leftoversPanel, assocFoodsPanel, yes, no); return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, SameAsBeforePrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.SaveHomeRecipePrompt.java
@Override public SurveyStageInterface getInterface(final Callback1<MealOperation> onComplete, final Callback1<Function1<Pair<FoodEntry, Meal>, Pair<FoodEntry, Meal>>> onIntermediateStateChange) { SafeHtml promptText = SafeHtmlUtils/*from w w w . j a v a 2 s .c o m*/ .fromSafeConstant(messages.homeRecipe_savePromptText(SafeHtmlUtils.htmlEscape(food.description()))); HorizontalPanel recipeNamePanel = new HorizontalPanel(); recipeNamePanel.setSpacing(5); recipeNamePanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); recipeName.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { recipeName.selectAll(); } }); recipeName.addKeyUpHandler(new KeyUpHandler() { @Override public void onKeyUp(KeyUpEvent event) { if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) { if (!recipeName.getText().isEmpty()) onComplete.call(MealOperation.update(saveRecipeFunction)); } } }); recipeNamePanel.add(new Label(messages.homeRecipe_recipeNameLabel())); recipeNamePanel.add(recipeName); Button yesButton = WidgetFactory.createGreenButton(messages.yesNoQuestion_defaultYesLabel(), "saveRecipeYesButton", new ClickHandler() { @Override public void onClick(ClickEvent event) { if (!recipeName.getText().isEmpty()) onComplete.call(MealOperation.update(saveRecipeFunction)); } }); Button noButton = WidgetFactory.createButton(messages.yesNoQuestion_defaultNoLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(MealOperation.update(dontSaveRecipeFunction)); } }); FlowPanel contents = new FlowPanel(); contents.add(WidgetFactory.createPromptPanel(promptText)); contents.add(recipeNamePanel); contents.add(WidgetFactory.createButtonsPanel(yesButton, noButton)); return new SurveyStageInterface.Aligned(contents, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, SaveHomeRecipePrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.prompts.SimpleHomeRecipePrompt.java
@Override public SurveyStageInterface getInterface(final Callback1<FoodOperation> onComplete, final Callback1<Function1<FoodEntry, FoodEntry>> onIntermediateStateChange) { final FlowPanel content = new FlowPanel(); Panel questionPanel;//from w w w. j a v a 2 s . c om if (food.customData.containsKey(MissingFood.KEY_ASSOC_FOOD_NAME)) { questionPanel = WidgetFactory.createPromptPanel( SafeHtmlUtils.fromSafeConstant(messages.missingFood_simpleRecipe_assocFoodPrompt( SafeHtmlUtils.htmlEscape(food.name.toLowerCase()), SafeHtmlUtils.htmlEscape( food.customData.get(MissingFood.KEY_ASSOC_FOOD_NAME).toLowerCase()))), ShepherdTour.createTourButton(tour, SimpleHomeRecipePrompt.class.getSimpleName())); } else { questionPanel = WidgetFactory.createPromptPanel( SafeHtmlUtils.fromSafeConstant(messages .missingFood_simpleRecipe_prompt(SafeHtmlUtils.htmlEscape(food.name.toLowerCase()))), ShepherdTour.createTourButton(tour, SimpleHomeRecipePrompt.class.getSimpleName())); } content.add(questionPanel); FlowPanel foodName = new FlowPanel(); foodName.getElement().setId("intake24-missing-food-name"); Label foodNameLabel = WidgetFactory.createLabel(messages.missingFood_simpleRecipe_nameLabel()); content.add(foodNameLabel); final TextBox foodNameTextBox = new TextBox(); foodNameTextBox.getElement().addClassName("intake24-missing-food-textbox"); foodNameTextBox.setText(food.name); foodName.add(foodNameLabel); foodName.add(foodNameTextBox); content.add(foodName); if (food.name.equals("Missing food")) { Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { foodNameTextBox.setFocus(true); foodNameTextBox.selectAll(); } }); } FlowPanel recipe = new FlowPanel(); recipe.getElement().setId("intake24-missing-food-recipe"); Label recipeLabel = WidgetFactory.createLabel(messages.missingFood_recipeLabel()); recipe.add(recipeLabel); final TextArea recipeTextArea = new TextArea(); recipe.add(recipeTextArea); recipeTextArea.getElement().addClassName("intake24-missing-food-textarea"); content.add(recipe); FlowPanel portionSize = new FlowPanel(); portionSize.getElement().setId("intake24-missing-food-portion-size"); Label portionSizeLabel = WidgetFactory.createLabel(messages.missingFood_simpleRecipe_servedLabel()); portionSize.add(portionSizeLabel); final TextBox portionSizeTextBox = new TextBox(); portionSizeTextBox.getElement().addClassName("intake24-missing-food-textbox"); portionSize.add(portionSizeTextBox); content.add(portionSize); FlowPanel leftovers = new FlowPanel(); leftovers.getElement().setId("intake24-missing-food-leftovers"); Label leftoversLabel = WidgetFactory.createLabel(messages.missingFood_simpleRecipe_leftoversLabel()); leftovers.add(leftoversLabel); final TextArea leftoversTextArea = new TextArea(); leftoversTextArea.getElement().addClassName("intake24-missing-food-textarea"); leftovers.add(leftoversTextArea); content.add(leftovers); Button cont = WidgetFactory.createGreenButton(messages.missingFood_continueButtonLabel(), "simpleRecipeContinueButton", new ClickHandler() { @Override public void onClick(ClickEvent event) { String name = foodNameTextBox.getText(); if (name.isEmpty()) name = food.name; onComplete.call(FoodOperation.replaceWith( new MissingFood(food.link, name, food.isDrink, Option.some(new MissingFoodDescription(mkOption("Home recipe"), mkOption(recipeTextArea.getText()), mkOption(portionSizeTextBox.getText()), mkOption(leftoversTextArea.getText()))), food.flags, food.customData))); } }); cont.getElement().setId("intake24-missing-food-continue-button"); content.add(WidgetFactory.createButtonsPanel(cont)); ShepherdTour.makeShepherdTarget(questionPanel, foodName, recipeTextArea, portionSize, leftovers, cont); return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS, SimpleHomeRecipePrompt.class.getSimpleName()); }