List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml
public SafeHtml toSafeHtml()
From source file:org.opendatakit.common.web.client.UIEnabledValidatingCheckboxCell.java
License:Apache License
@SuppressWarnings("unchecked") @Override// www.ja v a2 s. c o m public void onBrowserEvent(Context context, Element parent, Boolean value, NativeEvent event, ValueUpdater<Boolean> valueUpdater) { String type = event.getType(); boolean enterPressed = "keydown".equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER; if ("change".equals(type) || enterPressed) { InputElement input = parent.getFirstChild().cast(); Boolean isChecked = input.isChecked(); Object key = context.getKey(); if (isEnabledPredicate != null && !isEnabledPredicate.isEnabled((T) key)) { // disabled checkbox -- no changes! return; } /* * Toggle the value if the enter key was pressed; this brings * the key-press event path in line with a mouse-click event path. */ if (enterPressed) { isChecked = !isChecked; input.setChecked(isChecked); } /* * See if this is a valid action for this checkbox. */ boolean changed = true; if (validationPredicate != null && !validationPredicate.isValid(isChecked, (T) key)) { isChecked = !isChecked; changed = false; } /* * Save the new value. */ if (value != isChecked) { setViewData(context.getKey(), isChecked); } else { clearViewData(context.getKey()); } // redraw our parent with the value we ended up with... SafeHtmlBuilder sb = new SafeHtmlBuilder(); render(context, isChecked, sb); parent.setInnerHTML(sb.toSafeHtml().asString()); // apparently the element never gains focus... if (changed) { // do value-change action... if (valueUpdater != null) { valueUpdater.update(isChecked); } } } }
From source file:org.opendatakit.common.web.client.UIEnabledValidatingSelectionCell.java
License:Apache License
@SuppressWarnings("unchecked") @Override/*from www . ja v a 2s .c om*/ public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); String type = event.getType(); if ("change".equals(type)) { Object key = context.getKey(); SelectElement select = parent.getFirstChild().cast(); String newValue = options.get(select.getSelectedIndex()); // Get the prior value of the view data. String lastValue = getViewData(key); boolean changed = true; if (lastValue != null && newValue != null && lastValue.equals(newValue)) { changed = false; } if (validationPredicate != null && !validationPredicate.isValid(newValue, (T) key)) { // either there is no change in value // or the validation failed. // restore drop-down to prior value... newValue = lastValue; changed = false; } // update backing map with whatever we ended up with... setViewData(key, newValue); // redraw our parent with the value we ended up with... SafeHtmlBuilder sb = new SafeHtmlBuilder(); render(context, newValue, sb); parent.setInnerHTML(sb.toSafeHtml().asString()); // remove keyboard focus on this element... finishEditing(parent, newValue, key, valueUpdater); if (changed) { // do value-change action... if (valueUpdater != null) { valueUpdater.update(newValue); } } } }
From source file:org.opendatakit.common.web.client.UIEnabledValidatingTextInputCell.java
License:Apache License
/** * Because of various scoping issues, we need to override the onBrowserEvent * method.//from w w w .j a va 2s . c o m */ @SuppressWarnings("unchecked") @Override public void onBrowserEvent(Context context, Element parent, String value, NativeEvent event, ValueUpdater<String> valueUpdater) { // Ignore events that don't target the input. InputElement input = getInputElement(parent); Element target = event.getEventTarget().cast(); if (!input.isOrHasChild(target)) { super.onBrowserEvent(context, parent, value, event, valueUpdater); return; } String eventType = event.getType(); Object key = context.getKey(); if ("keyup".equals(eventType)) { super.onBrowserEvent(context, parent, value, event, valueUpdater); // Record keys as they are typed. ViewData vd = getViewData(key); if (vd == null) { vd = new ViewData(value); setViewData(key, vd); } vd.setCurrentValue(input.getValue()); } else if ("change".equals(eventType)) { String newValue = input.getValue(); // Get the view data. ViewData vd = getViewData(key); if (vd == null) { // TODO: unclear whether on null we should store value in ViewData // or null vd = new ViewData(value); setViewData(key, vd); } String lastValue = vd.getLastValue(); boolean changed = true; if (lastValue != null && newValue != null && lastValue.equals(newValue)) { changed = false; } // now do the logic to verify the value or restore it... if (validation != null && !validation.isValid(newValue, (T) key)) { // restore to prior value... newValue = lastValue; changed = false; } // restore the incoming value if validation failed // or update to the new value otherwise. input.setValue(newValue); vd.setLastValue(newValue); vd.setCurrentValue(newValue); // redraw our parent with the value we ended up with... SafeHtmlBuilder sb = new SafeHtmlBuilder(); render(context, newValue, sb); parent.setInnerHTML(sb.toSafeHtml().asString()); // Blur the element. super.finishEditing(parent, newValue, key, valueUpdater); if (changed) { // Fire the value updater if the value has changed. if (valueUpdater != null) { valueUpdater.update(newValue); } } } }
From source file:org.openelis.modules.sample1.client.ResultCell.java
License:Open Source License
public SafeHtml bulkRender(Object value) { SafeHtmlBuilder builder; builder = new SafeHtmlBuilder(); builder.appendEscaped(display(value)); return builder.toSafeHtml(); }
From source file:org.openelis.modules.worksheetCompletion1.client.WorksheetCheckBoxCell.java
License:Open Source License
public SafeHtml bulkRender(Object value) { SafeHtmlBuilder builder; String algn;// ww w. j a v a 2 s . c o m builder = new SafeHtmlBuilder(); if (value != null) { if (align.equalsIgnoreCase("left")) algn = HasHorizontalAlignment.ALIGN_LEFT.getTextAlignString(); else if (align.equalsIgnoreCase("right")) algn = HasHorizontalAlignment.ALIGN_RIGHT.getTextAlignString(); else algn = HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString(); builder.appendHtmlConstant("<span align='" + algn + "'>"); builder.appendHtmlConstant(getCheckDiv((String) value).getElement().getString()); builder.appendHtmlConstant("</span>"); } return builder.toSafeHtml(); }
From source file:org.openelis.modules.worksheetCompletion1.client.WorksheetResultCell.java
License:Open Source License
public SafeHtml bulkRender(Object value) { SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.appendEscaped(display(value)); return builder.toSafeHtml(); }
From source file:org.openelis.ui.widget.table.AutoCompleteCell.java
License:Open Source License
public SafeHtml bulkRender(Object value) { SafeHtmlBuilder builder; builder = new SafeHtmlBuilder(); builder.appendEscaped(display(value)); return builder.toSafeHtml(); }
From source file:org.openelis.ui.widget.table.CheckBoxCell.java
License:Open Source License
public SafeHtml bulkRender(Object value) { SafeHtmlBuilder builder = new SafeHtmlBuilder(); String algn;//from w w w.j a v a 2s . c o m if (align.equalsIgnoreCase("left")) algn = HasHorizontalAlignment.ALIGN_LEFT.getTextAlignString(); else if (align.equalsIgnoreCase("right")) algn = HasHorizontalAlignment.ALIGN_RIGHT.getTextAlignString(); else algn = HasHorizontalAlignment.ALIGN_CENTER.getTextAlignString(); builder.appendHtmlConstant("<span align='" + algn + "'>"); builder.appendHtmlConstant(getCheckDiv((String) value).getElement().getString()); builder.appendHtmlConstant("</span>"); return builder.toSafeHtml(); }
From source file:org.openelis.ui.widget.table.CheckCell.java
License:Open Source License
public SafeHtml bulkRender(Object value) { SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.appendHtmlConstant("<span align='" + HasAlignment.ALIGN_CENTER.getTextAlignString() + "'>" + getCheckDiv((String) value).getElement().getString() + "</span>"); return builder.toSafeHtml(); }
From source file:org.openelis.ui.widget.table.CheckLabelCell.java
License:Open Source License
public SafeHtml bulkRender(Object value) { SafeHtmlBuilder builder = new SafeHtmlBuilder(); CheckLabelValue val = (CheckLabelValue) value; builder.appendHtmlConstant(/*from w w w.j a v a2 s. co m*/ getCheckDiv(((CheckLabelValue) value).getChecked(), ((CheckLabelValue) value).label).toString()); return builder.toSafeHtml(); }