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.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 w w . jav a 2 s . co m*/ 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); } }); FoodLookupService.INSTANCE.getSplitSuggestion(EmbeddedData.localeId, food.description, new MethodCallback<SplitSuggestion>() { @Override public void onFailure(Method method, Throwable exception) { BrowserConsole.error( "Split description failed with code " + method.getResponse().getStatusCode()); onComplete.call(disableSplit); } @Override public void onSuccess(Method method, SplitSuggestion result) { if (result.parts.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.parts) { 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.parts) 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, SplitFoodPrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.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//www .j av a2 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, UnknownPortionSizeMethodPrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.rules.AskIfHomeRecipeFlexibleRecall.java
private Prompt<FoodEntry, FoodOperation> buildPrompt(final String foodName, final boolean isDrink) { PVector<String> options = TreePVector.<String>empty().plus(messages.homeRecipe_haveRecipeChoice()) .plus(messages.homeRecipe_noRecipeChoice()); return PromptUtil.asFoodPrompt( new RadioButtonPrompt( SafeHtmlUtils.fromSafeConstant( messages.homeRecipe_promptText(SafeHtmlUtils.htmlEscape(foodName.toLowerCase()))), AskIfHomeRecipeFlexibleRecall.class.getSimpleName(), options, messages.homeRecipe_continueButtonLabel(), "homeRecipeOption", Option.<String>none()), new Function1<String, FoodOperation>() { @Override//from w w w . ja va2 s .c o m public FoodOperation apply(String argument) { if (argument.equals(messages.homeRecipe_haveRecipeChoice())) { GoogleAnalytics.trackMissingFoodHomeRecipe(); return FoodOperation .replaceWith(new CompoundFood(FoodLink.newUnlinked(), foodName, isDrink)); } else { return FoodOperation.update(new Function1<FoodEntry, FoodEntry>() { @Override public FoodEntry apply(FoodEntry argument) { GoogleAnalytics.trackMissingFoodNotHomeRecipe(); return argument.withFlag(MissingFood.NOT_HOME_RECIPE_FLAG); } }); } } }); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.rules.ShowHomeRecipeServingsPrompt.java
@Override public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> apply(final Pair<FoodEntry, Meal> data, SelectionMode selectionType, final PSet<String> surveyFlags) { return data.left.accept(new FoodEntry.Visitor<Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>>>() { private Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> getPromptIfApplicable( final FoodEntry food) { if (forall(Meal.linkedFoods(data.right.foods, data.left), FoodEntry.isPortionSizeComplete) && (!food.customData.containsKey(Recipe.SERVINGS_NUMBER_KEY))) { FractionalQuantityPrompt quantityPrompt = new FractionalQuantityPrompt( SafeHtmlUtils.fromSafeConstant(messages .homeRecipe_servingsPromptText(SafeHtmlUtils.htmlEscape(food.description()))), messages.homeRecipe_servingsButtonLabel()); return Option.some( PromptUtil.asExtendedFoodPrompt(quantityPrompt, new Function1<Double, MealOperation>() { @Override public MealOperation apply(final Double servings) { return MealOperation.update(new Function1<Meal, Meal>() { @Override public Meal apply(Meal meal) { int compoundIndex = meal.foodIndex(data.left); Meal withUpdatedCompoundFood = meal.updateFood(compoundIndex, data.left.withCustomDataField(Recipe.SERVINGS_NUMBER_KEY, Double.toString(servings))); return foldl(Meal.linkedFoods(meal.foods, data.left), withUpdatedCompoundFood, new Function2<Meal, FoodEntry, Meal>() { @Override public Meal apply(Meal meal, FoodEntry food) { if (food.isEncoded()) { EncodedFood encodedFood = food.asEncoded(); CompletedPortionSize updatedPs = encodedFood .completedPortionSize() .multiply(1.0 / servings); return meal.updateFood(meal.foodIndex(food), encodedFood.withPortionSize( new Either.Right(updatedPs))); } else { return meal; } } }); }// ww w . j av a2 s.c o m }); } })); } else { return Option.none(); } } @Override public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitRaw(RawFood food) { return Option.none(); } @Override public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitEncoded(EncodedFood food) { return Option.none(); } @Override public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitTemplate(final TemplateFood food) { if (food.isTemplateComplete()) return getPromptIfApplicable(food); else return Option.none(); } @Override public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitMissing(MissingFood food) { return Option.none(); } @Override public Option<Prompt<Pair<FoodEntry, Meal>, MealOperation>> visitCompound(CompoundFood food) { return getPromptIfApplicable(food); } }); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.scheme.FoodSourcesPrompt.java
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 .j ava 2 s. c om*/ 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, FoodSourcesPrompt.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.survey.scheme.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 www. j a v a2 s .c o m*/ 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, "multipleChoiceCheckboxContinueButton", 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, MultipleChoiceCheckboxQuestion.class.getSimpleName()); }
From source file:uk.ac.ncl.openlab.intake24.client.ui.LoginForm.java
License:Apache License
public void onLoginAttemptFailed() { statusPanel.clear();/* w w w . j a va 2 s. co m*/ statusPanel.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant(messages .loginForm_passwordNotRecognised(SafeHtmlUtils.htmlEscape(EmbeddedData.surveySupportEmail))))); loginButton.setEnabled(true); }
From source file:uk.ac.ncl.openlab.intake24.client.ui.LoginForm.java
License:Apache License
public void onLoginServiceError() { statusPanel.clear();//from w ww . j av a 2 s . c o m statusPanel.add(new HTMLPanel(SafeHtmlUtils.fromSafeConstant( messages.loginForm_serviceException(SafeHtmlUtils.htmlEscape(EmbeddedData.surveySupportEmail))))); loginButton.setEnabled(true); }
From source file:uk.co.threeonefour.ifictionary.engine.client.pages.level9game.Level9GameActivity.java
License:Apache License
private void userCommand(String command) { view.getTextPanel().add(new HTML("<b>> " + SafeHtmlUtils.htmlEscape(command) + "</b>")); view.getTextBox().setText(null);//from ww w. ja v a 2 s . co m icyVm.execute(command); processVmOutput(); }
From source file:uk.co.threeonefour.ifictionary.engine.client.pages.level9game.Level9GameActivity.java
License:Apache License
private void processVmOutput() { view.getTextPanel().add(new HTML(SafeHtmlUtils.htmlEscape(icyVm.getText()))); view.getScrollPanel().scrollToBottom(); graphicsHandler.executeQueuedCommands(); }