List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape
public static String htmlEscape(String s)
From source file:net.scran24.user.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 www . j a v a 2 s . c o m 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.askIfReadyMeal; } @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); }
From source file:net.scran24.user.client.survey.prompts.RecipeBrowser.java
public RecipeBrowser(final Callback1<Recipe> onRecipeChosen, final RecipeManager manager) { this.onRecipeChosen = onRecipeChosen; this.manager = manager; contents.addStyleName("intake24-food-browser"); showAllRecipesButton = WidgetFactory.createButton( SafeHtmlUtils.htmlEscape(promptMessages.recipeBrowser_showAllRecipes()), new ClickHandler() { @Override//from w ww. j a v a 2 s.com public void onClick(ClickEvent event) { showRecipes(manager.getSavedRecipes()); showAllRecipesButton.setVisible(false); } }); showAllRecipesButton.getElement().setId("intake24-recipe-browser-show-all-button"); deleteRecipesButton = WidgetFactory.createButton( SafeHtmlUtils.htmlEscape(promptMessages.recipeBrowser_deleteRecipes()), new ClickHandler() { @Override public void onClick(ClickEvent event) { if (deleting) { deleteRecipesButton.setText( SafeHtmlUtils.htmlEscape(promptMessages.recipeBrowser_deleteRecipes())); deleting = false; for (RecipeButton r : recipeButtons) r.hideDeleteButton(); } else { deleteRecipesButton .setText(SafeHtmlUtils.htmlEscape(promptMessages.recipeBrowser_done())); deleting = true; for (RecipeButton r : recipeButtons) r.showDeleteButton(); } } }); deleteRecipesButton.getElement().getStyle().setFloat(com.google.gwt.dom.client.Style.Float.RIGHT); deleteRecipesButton.getElement().setId("intake24-recipe-browser-delete-button"); initWidget(contents); }
From source file:net.scran24.user.client.survey.prompts.RecipeBrowser.java
private void showRecipes(PVector<Recipe> recipes) { contents.clear();/*from w w w. j a v a2 s . c o m*/ recipeButtons.clear(); showAllRecipesButton.setVisible(true); if (!manager.getSavedRecipes().isEmpty()) { contents.add(showAllRecipesButton); contents.add(deleteRecipesButton); noRecipes = false; } else noRecipes = true; if (!recipes.isEmpty()) { showAllRecipesButton.getElement().getStyle().setFloat(com.google.gwt.dom.client.Style.Float.RIGHT); recipesPanel = new FlowPanel(); recipesPanel.addStyleName("intake24-food-browser-foods-container"); recipesPanel.getElement().setId("intake24-recipe-browser-recipes-panel"); HTMLPanel header = new HTMLPanel("h2", SafeHtmlUtils.htmlEscape(promptMessages.recipeBrowser_yourRecipes())); recipesPanel.add(header); for (final Recipe recipe : recipes) { final RecipeButton recipeBlock = new RecipeButton(recipe.mainFood.description); recipeBlock.link.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { onRecipeChosen.call(recipe); } }); recipeBlock.deleteButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { recipeButtons.remove(recipeBlock); recipesPanel.remove(recipeBlock.container); if (!manager.deleteRecipe(recipe.mainFood.link.id)) contents.clear(); } }); recipesPanel.add(recipeBlock.container); recipeButtons.add(recipeBlock); } contents.add(recipesPanel); } else { recipesPanel = null; showAllRecipesButton.getElement().getStyle().setFloat(com.google.gwt.dom.client.Style.Float.NONE); } }
From source file:net.scran24.user.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);//from w ww.ja va2s .c om 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); }
From source file:net.scran24.user.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/* w ww. j a v a 2s. c om*/ .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(), 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); }
From source file:net.scran24.user.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 . ja v a 2s . c o m*/ 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(), 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); }
From source file:net.scran24.user.client.survey.prompts.SplitFoodPrompt.java
License:Apache License
@Override public SurveyStageInterface getInterface(final Callback1<FoodOperation> onComplete, Callback1<Function1<FoodEntry, FoodEntry>> updateIntermediateState) { final FlowPanel content = new FlowPanel(); content.add(// w ww. j a va 2 s. c om new LoadingPanel(messages.foodLookup_loadingMessage(SafeHtmlUtils.htmlEscape(food.description)))); final FoodOperation disableSplit = FoodOperation.updateRaw(new Function1<RawFood, RawFood>() { @Override public RawFood apply(RawFood argument) { return new RawFood(argument.link, argument.description, argument.flags.plus(RawFood.FLAG_DISABLE_SPLIT), argument.customData); } }); AsyncRequestAuthHandler.execute(new AsyncRequest<List<String>>() { @Override public void execute(AsyncCallback<List<String>> callback) { lookupService.split(food.description, currentLocale, callback); } }, new AsyncCallback<List<String>>() { @Override public void onFailure(Throwable caught) { onComplete.call(disableSplit); } @Override public void onSuccess(final List<String> result) { if (result.size() == 1) onComplete.call(disableSplit); else { StringBuilder sb = new StringBuilder(); sb.append("<p>"); sb.append(messages.splitFood_promptText()); sb.append("</p>"); sb.append("<p>"); sb.append(SafeHtmlUtils.htmlEscape(food.description())); sb.append("</p>"); sb.append("<p>"); sb.append(messages.splitFood_split()); sb.append("<ul>"); for (String s : result) { sb.append("<li>"); sb.append(SafeHtmlUtils.htmlEscape(s)); sb.append("</li>"); } sb.append("</ul>"); sb.append("</p>"); sb.append("<p>"); sb.append(messages.splitFood_keep()); sb.append("</p>"); sb.append("<p>"); sb.append(messages.splitFood_separateSuggestion()); sb.append("</p>"); SafeHtml promptText = SafeHtmlUtils.fromSafeConstant(sb.toString()); content.clear(); content.add(WidgetFactory.createPromptPanel(promptText)); Button yesButton = WidgetFactory.createButton(messages.splitFood_yesButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { PVector<FoodEntry> replacement = TreePVector.<FoodEntry>empty(); for (String s : result) replacement = replacement.plus(new RawFood(FoodLink.newUnlinked(), s, food.flags.plus(RawFood.FLAG_DISABLE_SPLIT), food.customData)); onComplete.call(new FoodOperation.Split(replacement)); } }); Button noButton = WidgetFactory.createButton(messages.splitFood_noButtonLabel(), new ClickHandler() { @Override public void onClick(ClickEvent event) { onComplete.call(disableSplit); } }); content.add(WidgetFactory.createButtonsPanel(yesButton, noButton)); } } }); return new SurveyStageInterface.Aligned(content, HasHorizontalAlignment.ALIGN_LEFT, HasVerticalAlignment.ALIGN_TOP, SurveyStageInterface.DEFAULT_OPTIONS); }
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/*ww w. jav a 2 s . c o 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.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 w w. ja v a 2 s .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.MultipleChoiceCheckboxQuestion.java
@Override public SimpleSurveyStageInterface getInterface(final Callback1<Survey> onComplete, Callback2<Survey, Boolean> onIntermediateStateChange) { final FlowPanel content = new FlowPanel(); content.addStyleName("intake24-multiple-choice-question"); content.addStyleName("intake24-survey-content-container"); content.add(WidgetFactory.createPromptPanel(questionText)); FlowPanel checkboxesDiv = new FlowPanel(); checkboxesDiv.addStyleName("scran24-ready-meals-checkboxes-block"); final ArrayList<CheckBox> checkBoxes = new ArrayList<CheckBox>(); for (String option : options) { FlowPanel rowDiv = new FlowPanel(); CheckBox checkBox = new CheckBox(SafeHtmlUtils.htmlEscape(option)); checkBox.setFormValue(option);//from w w w . j a v a2s . c om checkBox.addStyleName("scran24-ready-meals-checkbox"); checkBoxes.add(checkBox); rowDiv.add(checkBox); checkboxesDiv.add(rowDiv); } if (!otherOptionName.isEmpty()) { FlowPanel otherPanel = new FlowPanel(); otherOption = new CheckBox(otherOptionName.getOrDie() + ": "); otherPanel.add(otherOption); otherBox = new TextBox(); otherPanel.add(otherBox); checkboxesDiv.add(otherPanel); otherBox.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { otherOption.setValue(true); } }); } content.add(checkboxesDiv); Button accept = WidgetFactory.createGreenButton(acceptText, new ClickHandler() { @Override public void onClick(ClickEvent event) { StringBuilder value = new StringBuilder(); boolean first = true; for (CheckBox checkBox : checkBoxes) if (checkBox.getValue()) { if (first) first = false; else value.append(", "); value.append(checkBox.getFormValue()); } if (!otherOptionName.isEmpty()) { if (otherOption.getValue()) { if (!first) value.append(", "); value.append(otherBox.getText()); } } onComplete.call(state.withData(dataField, value.toString())); } }); content.add(checkboxesDiv); content.add(accept); return new SimpleSurveyStageInterface(content); }