code
stringlengths 67
466k
| docstring
stringlengths 1
13.2k
|
---|---|
public JQMListItem findItemByTag(Object tag) {
if (tag == null) return null;
List<JQMListItem> lst = getItems();
for (JQMListItem i : lst) {
if (i == null) continue;
if (tag.equals(i.getTag())) return i;
}
return null;
} | Find the list item with the given tag. This method will search all the items and return
the first item found with the given tag.
@return the list item with the given tag (if found, or null otherwise). |
public void removeItem(JQMListItem item) {
if (item != null) {
items.remove(item);
list.remove(item);
}
} | Removes the given item from the list
@param item the item to remove |
public void setHeaderTheme(String value) {
headerTheme = value;
ComplexPanel r = findHeadRow();
if (r != null) setEltHeaderTheme(r.getElement(), value);
r = findHeadGroupsRow();
if (r != null) setEltHeaderTheme(r.getElement(), value);
} | Swatch header color "ui-bar-" + value will be used |
public static <T> T nonNull(T value, T replaceWithIfNull) {
return value != null ? value : replaceWithIfNull;
} | The same as {@link Empty#nvl(Object, Object)} |
public static <S extends HasAttachHandlers> void fire(S source, TabsState tabsState,
Widget newTabHeader, Widget oldTabHeader, Widget newTabContent, Widget oldTabContent) {
if (TYPE != null) {
JQMTabsEvent event = new JQMTabsEvent(tabsState, newTabHeader, oldTabHeader,
newTabContent, oldTabContent);
source.fireEvent(event);
}
} | Fires an {@link JQMTabsEvent} on all registered handlers in the handler source.
@param <S> The handler source type
@param source - the source of the handlers |
protected int getNumOfCols() {
if (!columns.isEmpty()) return getHeadRegularColCnt() + columns.size();
if (loaded && !colTitleWidgets.isEmpty()) return getHeadRegularColCnt() + colTitleWidgets.size();
return getHeadRegularColCnt();
} | important for body, because exact number of columns should be known when populating |
@Override
public Double getValue() {
Double rslt = getUiValue();
if (rslt == null) return internVal;
if (internVal == null) {
Double min = getMin();
if (rslt == min || rslt != null && rslt.equals(min)) return null;
}
internVal = rslt;
return rslt;
} | returns the current value of the slider |
public Double getMax() {
String v = input.getElement().getAttribute("max");
if (v == null || v.isEmpty()) return null;
return Double.valueOf(v);
} | Returns the max value of the slider |
public void setMax(Double max) {
String maxStr = doubleToNiceStr(max);
JQMCommon.setAttribute(input, "max", maxStr);
refreshMax(input.getElement().getId(), maxStr);
validateValue();
} | Sets the new max range for the slider.
@param max the new max range |
public void setMin(Double min) {
String minStr = doubleToNiceStr(min);
JQMCommon.setAttribute(input, "min", minStr);
refreshMin(input.getElement().getId(), minStr);
validateValue();
} | Sets the new min range for the slider
@param min the new min range |
@Override
public void setValue(Double value, boolean fireEvents) {
Double old = getValue();
if (old == value || old != null && old.equals(value)) return;
internVal = value;
setInputValueAttr(value);
ignoreChange = true;
try {
refresh(input.getElement().getId(), doubleToNiceStr(value));
} finally {
ignoreChange = false;
}
if (fireEvents) ValueChangeEvent.fire(this, value);
} | Sets the value of the slider to the given value
@param value the new value of the slider, must be in the range of the slider |
public JQMListItem addHeaderText(int n, String html) {
Element e = Document.get().createHElement(n);
e.setInnerHTML(html);
attachChild(e);
return this;
} | Adds a header element containing the given text.
@param n - the Hn element to use, e.g. if n is 2 then a {@code <h2>} element is created.
@param html - the value to set as the inner html of the {@code <hn>} element. |
public JQMListItem addText(String html) {
Element e = Document.get().createPElement();
e.setInnerHTML(html);
attachChild(e);
return this;
} | Adds a paragraph element containing the given text.
@param html - the value to set as the inner html of the p element. |
public JQMListItem addDiv(String html) {
Element e = Document.get().createDivElement();
e.setInnerHTML(html);
attachChild(e);
return this;
} | Adds a div element containing the given text.
@param html - the value to set as the inner html of the div element. |
public JQMListItem removeImage() {
if (imageElem != null) {
imageElem.removeFromParent();
imageElem = null;
}
getElement().removeClassName(STYLE_UI_LI_HAS_THUMB);
return this;
} | Removes the value of the image element if any. It is safe to call this
method regardless of if an image has been set or not. |
public JQMListItem removeHref() {
if (anchor == null) return this;
if (anchorPanel != null) {
List<Widget> lst = new ArrayList<Widget>();
for (int i = anchorPanel.getWidgetCount() - 1; i >= 0; i--) {
Widget w = anchorPanel.getWidget(i);
anchorPanel.remove(i);
lst.add(0, w);
}
remove(anchorPanel);
cleanUpLI();
for (Widget w : lst) this.add(w);
} else {
moveAnchorChildrenToThis();
getElement().removeChild(anchor);
}
anchor = null;
anchorPanel = null;
setSplitHref(null);
return this;
} | Remove the url from this list item changing the item into a read only
item. |
public void setAside(String text) {
if (text == null)
throw new RuntimeException("Cannot set aside to null. Call removeAside() if you wanted to remove the aside text");
if (asideElem == null)
createAndAttachAsideElem();
asideElem.setInnerText(text);
} | Sets the content of the aside. The aside is supplemental content that
is positioned to the right of the main content. |
public void setCount(Integer count) {
if (count == null)
throw new RuntimeException("Cannot set count to null. Call removeCount() if you wanted to remove the bubble");
if (countElem == null)
createAndAttachCountElement();
countElem.setInnerText(count.toString());
} | Set the count bubble value. If null this will throw a runtime
exception. To remove a count bubble call removeCount() |
public void setIcon(String src) {
setImage(src);
if (imageElem != null) {
imageElem.removeClassName("jqm4gwt-listitem-thumb");
imageElem.addClassName("jqm4gwt-listitem-icon");
}
} | Sets the image to be used to the given source url.
<br> The same as setImage(), but image is marked as icon class. |
public void setThumbnail(String src) {
setImage(src);
if (imageElem != null) {
imageElem.removeClassName("jqm4gwt-listitem-icon");
imageElem.addClassName("jqm4gwt-listitem-thumb");
}
} | Sets the image to be used to the given source url.
<br> The same as setImage(), but image is marked as thumbnail class. |
public void setImage(String src) {
if (src == null) {
throw new RuntimeException("Cannot set image to null. Call removeImage() if you wanted to remove the image");
}
if (imageElem == null) {
imageElem = Document.get().createImageElement();
// must be first child according to jquery.mobile-1.4.x.css
if (anchor != null) anchor.insertFirst(imageElem);
else insertFirstChild(imageElem);
}
imageElem.setAttribute("src", src);
getElement().addClassName(STYLE_UI_LI_HAS_THUMB);
} | Sets the image on this list item to the given source url.
<br> Neither 'jqm4gwt-listitem-thumb' nor 'jqm4gwt-listitem-icon' class is added. |
public ImageElement addSecondaryImage(String src) {
if (src == null) {
throw new RuntimeException("Cannot set secondary image to null.");
}
ImageElement img = Document.get().createImageElement();
img.setAttribute("src", src);
getElement().appendChild(img);
return img;
} | Adds secondary image to this list item. It's forcefully added directly to <li> element.
<br> Additional CSS is needed to control appearance of this image, for example right side
icon on the static band can be implemented, see <b>jqm4gwt-list-static-item-img-right</b> CSS rule. |
@Override
public void setText(String text) {
if (text == null) {
if (headerElem != null) {
removeChild(headerElem);
headerElem = null;
}
return;
}
if (headerElem == null) {
headerElem = Document.get().createHElement(3);
attachChild(headerElem);
}
headerElem.setInnerText(text);
} | Sets the content of the "main" text to the given value. |
public void setHref(String url) {
if (url == null)
throw new RuntimeException("Cannot set URL to null. Call removeUrl() if you wanted to remove the URL");
if (anchor == null) {
if (controlGroupRoot != null) {
//!!! following code is semi-working, it's not reconstructed item correctly
remove(controlGroupRoot);
anchor = Document.get().createAnchorElement();
anchor.setAttribute("href", url);
moveThisChildrenToAnchor();
cleanUpLI();
prepareAnchorForControlGroup();
getElement().appendChild(anchor);
checkAnchorPanel();
} else {
// need to make anchor and move children to it
anchor = Document.get().createAnchorElement();
moveThisChildrenToAnchor();
getElement().appendChild(anchor);
}
addItemActivationHandlers();
}
anchor.setAttribute("href", url);
} | Sets the url to link to for this item. If this item was a read only
item it automatically becomes linkable. |
public void setControlGroup(boolean value, boolean linkable) {
if (value) {
createControlGroup(linkable);
} else if (controlGroup != null) {
if (anchorPanel != null) remove(anchorPanel);
else if (anchor != null) getElement().removeChild(anchor);
anchor = null;
anchorPanel = null;
setSplitHref(null);
controlGroupRoot = null;
controlGroup = null;
checkBoxInput = null;
}
} | true - prepare and allow to add widgets to this list box item.
@param linkable - if true <a> will be forcefully created, so row will be clickable. |
public void setCheckBox(IconPos iconPos) {
if (checkBoxInput != null) {
if (iconPos == null) {
controlGroup.remove(checkBoxInput);
checkBoxInput = null;
// refresh control group
setControlGroup(false);
setControlGroup(true);
} else {
JQMCommon.setIconPos(controlGroupRoot, iconPos);
}
return;
}
if (iconPos == null) return;
TextBox cb = new TextBox();
cb.getElement().setAttribute("type", "checkbox");
checkBoxInput = cb;
// controlGroupRoot needs to be either "label" for checkbox or "div" for other elements (radio group for example)
setControlGroup(false);
setControlGroup(true);
JQMCommon.setIconPos(controlGroupRoot, iconPos);
controlGroup.insert(cb, 0);
} | CheckBox will be created for this list item.
<p>See <a href="http://stackoverflow.com/a/13931919">Checkbox in ListView</a></p> |
public void addWidget(Widget w) {
if (w == null || controlGroup == null) return;
controlGroup.add(w);
} | Currently possible only in checkBox and control group modes.
<p>See {@link JQMListItem#setCheckBox(IconPos)} and {@link JQMListItem#setControlGroup(boolean)} |
@Override
public void setTransition(Transition transition) {
if (anchor == null) {
if (transition != null) {
setUrl("#");
} else {
return;
}
}
if (anchor != null) JQMCommon.setTransition(anchor, transition);
} | Sets the transition to be used by this list item when loading the URL. |
public void setSplitTransition(Transition transition) {
if (split == null) {
if (transition != null) {
setSplitHref("#");
} else {
return;
}
}
if (split != null) JQMCommon.setTransition(split, transition);
} | Sets the transition to be used by this list item split part when loading the URL. |
public static JQMPage findPage(Element elt) {
if (elt == null) return null;
Widget w = JQMCommon.findWidget(elt);
return w instanceof JQMPage ? (JQMPage) w : null;
} | Needed to find out JQMPage widget by its Element received usually from JavaScript.
<br> Only loaded (attached to DOM) pages can be found. |
@Override
public void setContainerId(String containerId) {
if (getId() == null) {
super.setContainerId(containerId);
JQMContext.attachAndEnhance(this);
} else if (! containerId.equals(getId())) {
throw new IllegalStateException("Attempt to change JQMPage with containerId '" + getId() + "' to '" + containerId + "' failed - once set, it cannot be changed.");
}
} | Sets the containerId so it can be referenced by name. This can only be set once. All subsequent attempts on this
instance will result in an IllegalStateException.
@param containerId |
protected void addLogical(Widget child) {
// Detach new child.
child.removeFromParent();
// Logical attach.
getChildren().add(child);
// Adopt.
adopt(child);
} | Logical add operation. If you do this you are responsible for adding it
to the DOM yourself.
@param child
the child widget to be added |
protected boolean removeLogical(Widget w) {
// Validate.
if (w.getParent() != this) {
return false;
}
// Orphan.
try {
orphan(w);
} finally {
// Logical detach.
getChildren().remove(w);
}
return true;
} | Logical remove operation. If you do this you are responsible for removing it
from the DOM yourself.
@param w - the child widget to be removed |
@Override
public void add(Widget widget) {
if (widget instanceof HasJqmHeader) {
setHeader((HasJqmHeader) widget);
return;
} else if (widget instanceof HasJqmFooter) {
setFooter((HasJqmFooter) widget);
return;
} else if (widget instanceof JQMContent) {
throw new RuntimeException("Do not add content widgets here, call createContent() instead");
}
getPrimaryContent().add(widget);
// if page is already enhanced then we need to enhance the content manually
// if (enhanced) triggerCreate();
} | Adds a widget to the primary content container of this page.
@param widget the widget to add to the primary content |
public JQMContent createContent() {
JQMContent content = new JQMContent();
Element elt = getElement();
add(content, elt);
return content;
} | Creates a content container on this page and returns it. Content can
then be added to this secondary container. There is no limit to the
number of secondary content containers that can be created. |
public void setBackButton(boolean value) {
JQMHeader h = getHeader();
if (h != null) h.setBackButton(value);
} | See {@link JQMHeader#setBackButton(boolean)} |
private static void prepareTransparentGoing(boolean add, String transparentPageId) {
Element p = Document.get().getBody();
if (p != null) {
String s = JQM4GWT_DLG_TRANSPARENT_GOING_PREFIX + transparentPageId;
if (add) {
p.addClassName(JQM4GWT_DLG_TRANSPARENT_GOING);
p.addClassName(s);
} else {
p.removeClassName(s);
String ss = JQMCommon.getStyleStartsWith(p, JQM4GWT_DLG_TRANSPARENT_GOING_PREFIX);
// checking for "opened dialog chain" case
if (Empty.is(ss)) p.removeClassName(JQM4GWT_DLG_TRANSPARENT_GOING);
}
}
} | GOING means from beforeShow till afterHide. |
private static void prepareTransparentOpened(boolean add, String transparentPageId) {
Element p = Document.get().getBody();
if (p != null) {
String s = JQM4GWT_DLG_TRANSPARENT_OPENED_PREFIX + transparentPageId;
if (add) {
p.addClassName(JQM4GWT_DLG_TRANSPARENT_OPENED);
p.addClassName(s);
} else {
p.removeClassName(s);
String ss = JQMCommon.getStyleStartsWith(p, JQM4GWT_DLG_TRANSPARENT_OPENED_PREFIX);
// checking for "opened dialog chain" case
if (Empty.is(ss)) p.removeClassName(JQM4GWT_DLG_TRANSPARENT_OPENED);
}
}
} | Needed mostly in case of page container surrounded by external panels, so these panels
could be synchronously disabled/enabled when "modal" dialog shown by jqm application.
<br> from afterShow till beforeHide. |
public void setFooter(HasJqmFooter footer) {
removeFooter();
this.footer = footer;
if (this.footer == null) return;
addLogical(footer.getFooterStage());
getElement().appendChild(footer.getJqmFooter().getElement());
} | Sets the footer element, overriding an existing footer if any. |
public void setHeader(HasJqmHeader header) {
removeHeader();
this.header = header;
if (this.header == null) return;
addLogical(header.getHeaderStage());
if (panel == null) {
getElement().insertBefore(header.getJqmHeader().getElement(), getElement().getFirstChild());
} else {
getElement().insertAfter(header.getJqmHeader().getElement(), panel.getElement());
}
} | Sets the header element, overriding an existing header if any. |
public void setContentAddStyleNames(String value) {
if (value == null || value.isEmpty()) return;
JQMCommon.addStyleNames(content, value);
} | Additional class names can be added directly to content div for better custom styling.
The same idea as UiBinder's embedded addStyleNames functionality.
<br> Example:
<pre><jqm:JQMPage contentAddStyleNames="aaa bbb ccc"/></pre> |
public void setContentCentered(boolean contentCentered) {
boolean oldVal = this.contentCentered;
this.contentCentered = contentCentered;
if (oldVal != this.contentCentered && content != null && content.isAttached()) {
if (this.contentCentered) {
centerContent();
initWindowResize();
} else {
clearCenterContent();
}
}
} | Content band will be centered between Header and Footer
(they must be defined as fixed="true" OR page.pseudoFixedToolbars="true"). |
public void setPseudoFixedToolbars(boolean value) {
boolean oldVal = this.pseudoFixedToolbars;
this.pseudoFixedToolbars = value;
if (oldVal != this.pseudoFixedToolbars && content != null && content.isAttached()) {
if (this.pseudoFixedToolbars) {
centerContent();
initWindowResize();
} else {
centerContent();
}
}
} | If content is short or scrollable (see {@link JQMPage#setContentHeightPercent(double)}),
we can get "fixed" header and footer without using CSS position: fixed (it's not working
quite good in mobile browsers). Just setPseudoFixedToolbars(true) and footer's position will
be calculated to be at the bottom of the page. |
public void setContentHeightPercent(double contentHeightPercent) {
double oldVal = this.contentHeightPercent;
this.contentHeightPercent = contentHeightPercent;
if (oldVal != this.contentHeightPercent && content != null && content.isAttached()) {
recalcContentHeightPercent();
centerContent();
initWindowResize();
}
} | Defines content band's height as percent of available content area's height. |
public void setHideFixedToolbarsIfContentAreaPercentBelow(double value) {
double oldVal = hideFixedToolbarsIfContentAreaPercentBelow;
hideFixedToolbarsIfContentAreaPercentBelow = value;
if (oldVal != hideFixedToolbarsIfContentAreaPercentBelow
&& content != null && content.isAttached()) {
processFixedToolbars();
centerContent();
initWindowResize();
}
} | Fixed Header and Footer will be hidden if content area height percent is below
than specified percent of window height (default is 50%).
<br> Useful in cases with activated virtual keyboard, especially on Android. |
public void setHideFixedToolbarsIfVirtualKeyboard(int value) {
int oldVal = hideFixedToolbarsIfVirtualKeyboard;
hideFixedToolbarsIfVirtualKeyboard = value;
if (oldVal != hideFixedToolbarsIfVirtualKeyboard
&& content != null && content.isAttached()) {
processFixedToolbars();
centerContent();
initWindowResize();
if (hideFixedToolbarsIfVirtualKeyboard > 0) initOrientationChange();
}
} | Fixed Header and Footer will be hidden if virtual/on-screen keyboard is activated.
<br> This property is used as threshold(keyboard's height) in pixels
for keyboard detection (to work must be > 0, default is 0). |
public void centerContent() {
if (stopPartsPositioning) return;
if (!isVisible()) return;
boolean windowHset = false;
int windowH = 0;
int headerH = 0;
int footerH = 0;
int contentH = 0;
int marginTop = 0;
final JQMHeader header = getHeader();
final JQMFooter footer = getFooter();
if (contentCentered) {
boolean isFixedHeader = header != null && (header.isFixed() || pseudoFixedToolbars);
boolean isFixedFooter = footer != null && (footer.isFixed() || pseudoFixedToolbars);
boolean needCentering = (header == null && footer == null)
|| (isFixedHeader && isFixedFooter)
|| (isFixedHeader && footer == null) || (isFixedFooter && header == null);
if (needCentering && !isFixedToolbarsHidden()) {
contentH = content.getOffsetHeight();
if (contentH > 0) {
if (header != null) headerH = header.getOffsetHeight();
if (footer != null) footerH = footer.getOffsetHeight();
windowH = Window.getClientHeight();
windowHset = true;
marginTop = (windowH - headerH - footerH - contentH) / 2;
}
}
}
if (marginTop <= 0) content.getElement().getStyle().clearMarginTop();
else content.getElement().getStyle().setMarginTop(marginTop, Unit.PX);
if (footer != null) {
int footerMarginTop = 0;
footerH = footer.getOffsetHeight();
if (pseudoFixedToolbars && footerH > 0 && !footer.isFixed()) {
if (!windowHset) {
windowH = Window.getClientHeight();
windowHset = true;
contentH = content.getOffsetHeight();
if (header != null) headerH = header.getOffsetHeight();
}
footerMarginTop = windowH - headerH - contentH - marginTop - footerH;
}
if (footerMarginTop <= 0) footer.getElement().getStyle().clearMarginTop();
else footer.getElement().getStyle().setMarginTop(footerMarginTop, Unit.PX);
}
} | Forcefully centers (just once) page content (needed when content size is changed, because
there is no good way to get resize notification for DOM elements).
<p> Warning! - contentCentered property is not affected, you have to change it manually. </p>
<p> See <a href="http://stackoverflow.com/questions/3444719/how-to-know-when-an-dom-element-moves-or-is-resized">
How to know when an DOM element moves or is resized</a></p> |
public void recalcContentHeightPercent() {
if (stopPartsPositioning) return;
if (!isVisible()) return;
Element contentElt = content.getElement();
if (contentHeightPercent > 0) {
final JQMHeader header = getHeader();
final JQMFooter footer = getFooter();
int headerH = header == null || isFixedToolbarsHidden() ? 0 : header.getOffsetHeight();
int footerH = footer == null || isFixedToolbarsHidden() ? 0 : footer.getOffsetHeight();
int windowH = Window.getClientHeight();
int clientH = contentElt.getPropertyInt("clientHeight");
int offsetH = contentElt.getPropertyInt("offsetHeight");
int diff = offsetH - clientH; // border, ...
if (diff < 0) diff = 0;
double h = (windowH - headerH - footerH - diff) * 0.01d * contentHeightPercent;
h = Math.floor(h);
contentElt.getStyle().setProperty("minHeight", String.valueOf(Math.round(h)) + "px");
contentElt.getStyle().setProperty("paddingTop", "0");
contentElt.getStyle().setProperty("paddingBottom", "0");
} else {
contentElt.getStyle().clearProperty("minHeight");
contentElt.getStyle().clearProperty("paddingTop");
contentElt.getStyle().clearProperty("paddingBottom");
}
} | Forcefully recalculates (if defined, and just once) page content height
(needed when content area size is changed, because there is no good way to get resize
notification for DOM elements). |
public void restoreRolePage() {
JQMCommon.setDataRole(this, "page");
JQMCommon.setDataDialog(this, false);
removeStyleName(STYLE_UI_DIALOG);
Element elt = getElement();
Element dlgContain = JQMCommon.findChild(elt, UI_DIALOG_CONTAIN);
if (dlgContain != null) {
JQMCommon.moveChildren(dlgContain, elt);
elt.removeChild(dlgContain);
}
JQMHeader h = getHeader();
if (h != null) {
Element btn = JQMCommon.findChild(h.getElement(), "ui-btn-icon-notext");
if (btn != null && "#".equals(JQMCommon.getAttribute(btn, "href"))
&& (DataIcon.DELETE == JQMCommon.getIcon(btn)
|| DataIcon.DELETE == JQMCommon.getStyleIcon(btn))) {
h.getElement().removeChild(btn);
}
}
} | There is no "correct" way to restore page after it was called as dialog,
so this method is ugly hack, but it's useful and working. |
protected boolean onBeforeActivate(Widget newTabHeader, Widget oldTabHeader,
Widget newTabContent, Widget oldTabContent) {
return true;
} | If the tabs are currently collapsed, oldTabHeader and oldTabContent will be null.
<br> If the tabs are collapsing, newTabHeader and newTabContent will be null.
@param newTabHeader - JQMButton or JQMListItem
@param oldTabHeader - JQMButton or JQMListItem
@param newTabContent - Widget
@param oldTabContent - Widget |
@Override
public HandlerRegistration addBlurHandler(final BlurHandler handler) {
this.blurHandler = handler;
clearBlurHandlers();
addRadiosBlurHandler(handler);
return null;
} | no-op implementation required for {@link JQMFormWidget} |
public JQMRadio addRadio(String value, String text) {
JQMRadio radio = new JQMRadio(value, text);
addRadio(radio);
return radio;
} | Adds a new radio button to this radioset using the given value and text.
Returns a JQMRadio instance which can be used to change the value and
label of the radio button.
@param value
the value to associate with this radio option. This will be
the value returned by methods that query the selected value.
@param text
the label to show for this radio option.
@return a JQMRadio instance to adjust the added radio button |
@UiChild(tagname = "radio")
public void addRadio(JQMRadio radio) {
radio.setName(fieldset.getId());
radios.add(radio);
radio.setTheme(theme);
fieldset.add(radio.getInput());
fieldset.add(radio.getLabel());
} | UiBinder call method to add a radio button
@param radio |
private String getValueForId(String id) {
for (int k = 0; k < fieldset.getWidgetCount(); k++) {
Widget widget = fieldset.getWidget(k);
if (id.equals(widget.getElement().getAttribute("id")))
return widget.getElement().getAttribute("value");
}
return null;
} | Returns the value of the button that has the given id
@return the value of the button with the given id |
public void removeRadio(JQMRadio radio) {
if (radio == null) return;
TextBox inp = radio.getInput();
if (inp != null) {
radios.remove(radio);
fieldset.remove(inp);
}
if (radio.getLabel() != null) fieldset.remove(radio.getLabel());
} | Removes the given {@link JQMRadio} from this radioset
@param radio - the radio to remove |
@Override
public void setValue(String value, boolean fireEvents) {
String oldValue = fireEvents ? getValue() : null;
boolean changed = false;
for (JQMRadio r : radios) { // first we have to uncheck already checked radios (UI refresh issue)
TextBox radio = r.getInput();
if (!isChecked(radio)) continue;
boolean checked = value != null && value.equals(radio.getValue()) ? true : false;
if (!checked) {
setChecked(radio, false);
changed = true;
}
}
for (JQMRadio r : radios) {
TextBox radio = r.getInput();
boolean checked = value != null && value.equals(radio.getValue()) ? true : false;
if (isChecked(radio) != checked) {
setChecked(radio, checked);
changed = true;
}
}
if (fireEvents && changed) {
String newValue = getValue();
boolean eq = newValue == oldValue || newValue != null && newValue.equals(oldValue);
if (!eq) {
SelectionEvent.fire(this, newValue);
ValueChangeEvent.fire(this, newValue);
}
}
} | Sets the currently selected radio to the given value. |
public void setPosOnBand(PosOnBand value) {
if (value == null) {
getElement().removeClassName(STYLE_UI_BTN_RIGHT);
getElement().removeClassName(STYLE_UI_BTN_LEFT);
} else {
switch (value) {
case LEFT:
getElement().addClassName(STYLE_UI_BTN_LEFT);
break;
case RIGHT:
getElement().addClassName(STYLE_UI_BTN_RIGHT);
break;
}
}
} | Works in case of this button placed on Header, Popup, ... |
private PluralRule instantiateCustomPluralRuleClass(Class<? extends PluralRule> clazz) {
PluralRule retVal;
try {
String pluralClassName = clazz.getName() + "_" + this.getLocale().getLanguage();
try {
Class<?> pClass = Class.forName(pluralClassName);
retVal = (PluralRule) pClass.newInstance();
} catch (ClassNotFoundException e) {
retVal = clazz.newInstance();
}
} catch (InstantiationException e) {
throw new RuntimeException("Could not instantiate custom PluralRule class. "
+ "Make sure the class is not an abstract class or interface and has a default constructor.", e);
} catch (IllegalAccessException e) {
throw new RuntimeException("Could not instantiate custom Plural Rule class.", e);
}
return retVal;
} | Instantiates the plural rule class given inside the PluralCount
annotation. The pluralRule class that is instantiated is based on the
language originally given to the library. If that language is not found,
defaults to the given class.
@param clazz The PluralRule class
@return An instantiated PluralRule class |
public void waitInitOpen(String waitForSelector) {
if (waitForSelector == null || waitForSelector.isEmpty()) {
initDynamic();
open();
return;
}
waitInitOpen(waitForSelector, getElement());
} | First wait till some elements are loaded, then initialize and open dynamically added popup.
<br> See <a href="http://demos.jquerymobile.com/1.4.5/popup-dynamic/#&ui-state=dialog&ui-state=dialog&ui-state=dialog">Dynamic popup with images</a> |
public void setArrows(String arrows) {
JQMCommon.setAttribute(this, "data-arrow", arrows);
Element elt = getElement();
if (isInitialized(elt)) _setArrows(elt, arrows);
} | @param arrows - possible values: true, false.
Also comma-separated list of edge abbreviations: l t r b
<br> "l" for left, "t" for top, "r" for right, and "b" for bottom.
<br> <b>The order in which the edges are given matters, see explanation below.</b>
<br> For each edge given in the list, the framework calculates:
<br> 1. the distance between the tip of the arrow and the center of the origin
<br> 2. and whether minimizing the above distance would cause the arrow to appear
too close to one of the corners of the popup along the given edge.
<br> If the second condition applies, the edge is discarded as a possible solution
for placing the arrow. Otherwise, the calculated distance is examined.
If it is 0, meaning that the popup can be placed exactly such that the tip of
the arrow points at the center of the origin, no further edges are examined,
and the popup is positioned along the last examined edge. |
public void setTolerance(String tolerance) {
this.tolerance = tolerance;
Element elt = getElement();
if (isInitialized(elt)) setTolerance(elt, tolerance);
} | @param tolerance - Default: "30,15,30,15"
<br> Sets the minimum distance from the edge of the window for the corresponding edge
of the popup. By default, the values above will be used for the distance from
the top, right, bottom, and left edge of the window, respectively.
<br> You can specify a value for this option in one of four ways:
<br> 1. Empty string, null, or some other falsy value. This will cause the popup to revert
to the above default values.
<br> 2. A single number. This number will be used for all four edge tolerances.
<br> 3. Two numbers separated by a comma. The first number will be used for tolerances
from the top and bottom edge of the window, and the second number will be used for tolerances
from the left and right edge of the window.
<br> 4. Four comma-separated numbers. The first will be used for tolerance from the top edge,
the second for tolerance from the right edge, the third for tolerance from the bottom edge,
and the fourth for tolerance from the left edge. |
private static Consumer<JavaFile> write(ProcessingEnvironment processingEnv) {
return file -> {
try {
file.writeTo(processingEnv.getFiler());
} catch (IOException e) {
JavaFileObject obj = file.toJavaFileObject();
throw new ProcessingException("Can't write", obj.getName(), obj.getKind(), e);
}
};
} | Consumer which writes classes as java files |
private static Stream<Element> asFields(Element element) {
switch (element.getKind()) {
case FIELD:
return Stream.of(element);
case CLASS:
return element.getEnclosedElements().stream().flatMap(MatcherFactoryGenerator::asFields);
}
return Stream.empty();
} | Recursively adds to stream all fields of class of fields of nested class
@param element class/field element
@return stream with fields we want to process |
private void setFilterableElt(Element filterableElt) {
filterable = filterableElt;
if (filterable != null && JQMCommon.isFilterableReady(filterable)) {
JavaScriptObject origFilter = JQMCommon.getFilterCallback(filterable);
JQMCommon.bindFilterCallback(this, filterable, origFilter);
}
} | /* @Override
public Boolean doFiltering(Element elt, Integer index, String searchValue) {
TODO: remove when this bug is fixed: https://github.com/jquery/jquery-mobile/issues/7677
String s = JQMCommon.getFilterText(elt);
if (s == null || s.isEmpty()) {
s = JQMCommon.getAttribute(elt, "data-option-index");
if (s != null && !s.isEmpty()) {
try {
int i = Integer.parseInt(s);
OptionElement opt = getOption(i);
if (opt != null) {
s = JQMCommon.getFilterText(opt);
if (s != null && !s.isEmpty()) {
JQMCommon.setFilterText(elt, s);
}
}
} catch (NumberFormatException ex) {
nothing, can continue safely
}
}
}
return super.doFiltering(elt, index, searchValue);
} |
@UiChild(limit = 1, tagname = "buttonActivePersist")
public void addActivePersist(final JQMButton button) {
if (button == null) return;
addActive(button);
button.getElement().addClassName("ui-state-persist");
} | Restore the button's active state each time the page is shown while it exists in the DOM. |
public void remove(JQMButton button) {
if (button == null || buttons == null) return;
int i = buttons.indexOf(button);
if (i == -1) return;
Widget liPanel = button.getParent();
ulPanel.remove(liPanel);
buttons.remove(i);
} | Works, but only partially! There is no navbar.refresh() in jqm 1.4.x, so CSS classes are
not updated properly and navbar doesn't reuse free/available space after removal. |
public void setIconPos(IconPos pos) {
if (pos == null) {
JQMCommon.setIconPos(this, pos);
} else {
IconPos oldPos = getIconPos();
JQMCommon.setIconPos(this, pos);
for (int i = 0; i < buttons.size(); i++) {
JQMButton btn = buttons.get(i);
IconPos p = btn.getIconPos();
if (p == null || oldPos == null || p.equals(oldPos)) btn.setIconPos(pos);
}
}
} | Sets the position of the icon. If you desire an icon only button then
set the position to IconPos.NOTEXT |
@UiChild(tagname = "cell")
public Widget add(Widget widget, String addStyleNames) {
int size = getElement().getChildCount();
String klass = getCellStyleName(size);
JQMTableCell cell = new JQMTableCell();
Element cellElt = cell.getElement();
cellElt.setId(Document.get().createUniqueId());
removeAllCellStyles(cellElt);
cellElt.addClassName(klass);
prepareCellPercentStyle(size, cell);
if (addStyleNames != null && !addStyleNames.isEmpty()) {
JQMCommon.addStyleNames(cell, addStyleNames);
}
cell.add(widget);
flow.add(cell);
JQMContext.render(cell.getElement().getId());
return cell;
} | Add the given {@link Widget} into the next available cell. This call
will wrap to a new row if the existing row is already filled.
The given widget will be wrapped inside a div with the appropriate
JQuery Mobile class name given (eg, "ui-block-a" for the first cell,
etc). This created div will have an automatically assigned id.
@param addStyleNames - space separated additional style names for this particular cell
@return the widget that was created to wrap the given content |
public Widget insert(Widget w, int beforeIndex) {
FlowPanel widgetWrapper = new FlowPanel();
widgetWrapper.getElement().setId(Document.get().createUniqueId());
widgetWrapper.add(w);
flow.insert(w, beforeIndex);
JQMContext.render(widgetWrapper.getElement().getId());
rebase();
return widgetWrapper;
} | Adds the given {@link Widget} before the given position.
This is an O(n) operation because after the widget is inserted all the
remaining cells need to have their style sheets updated to reflect
their new position. |
private void rebase() {
for (int k = 0; k < flow.getWidgetCount(); k++) {
Widget widget = flow.getWidget(k);
String cellStyleName = getCellStyleName(k);
removeAllCellStyles(widget.getElement());
prepareCellPercentStyle(k, widget);
widget.getElement().addClassName(cellStyleName);
}
} | Update the stylesheets of all cells |
public boolean remove(Widget w) {
int indexOf = indexOf(w);
if (indexOf >= 0) return remove(indexOf);
return false;
} | Removes the given widget from the table, if it is a child of the table.
NOTE: The widget passed in must be a container widget as returned by
the add or insert methods.
This is an O(n) operation because after the widget is removed all the
remaining cells need to have their style sheets updated to reflect
their new position.
@return true if the cell was removed |
public void setColumns(int n) {
if (n < 1) throw new IllegalArgumentException("Min column count is 1");
if (n > 5) throw new IllegalArgumentException("Max column count is 5");
if (n == columns) return;
this.columns = n;
refresh(this.columns);
} | This is an O(n) operation where n is the number of child widgets. This
is because in a jquery mobile table the cell position is determined by
the classname assigned. So all cells in column0 are assigned a
classname of ui-block-a, and so on.
When the relative position of a cell is changed, the classname must be
changed. Therefore all add and remove operations (except for the last
element) and resize operations (such as this method) results in a
shuffle which requires an iteration through all elements to update
their appropriate classname.
If the new column count is the same as the old column count then this
is a no-op call. |
public static <S extends HasAttachHandlers> void fire(S source, FilterableState filterableState,
String filterText) {
if (TYPE != null) {
JQMFilterableEvent event = new JQMFilterableEvent(filterableState, filterText);
source.fireEvent(event);
}
} | Fires an {@link JQMFilterableEvent} on all registered handlers in the handler source.
@param <S> The handler source type
@param source - the source of the handlers |
public static <S extends HasAttachHandlers> void fire(S source, CollapsibleState collapsibleState,
Element eventTarget) {
if (TYPE != null) {
JQMCollapsibleEvent event = new JQMCollapsibleEvent(collapsibleState, eventTarget);
source.fireEvent(event);
}
} | Fires an {@link JQMCollapsibleEvent} on all registered handlers in the handler source.
@param <S> The handler source type
@param source - the source of the handlers |
public static boolean isRealVisible(Widget widget) {
if (widget == null || !widget.isAttached()) return false;
Element elt = widget.getElement();
return UIObject.isVisible(elt) && Mobile.isVisible(elt);
} | Expensive, based on jQuery, but gives realistic visibility (CSS rules, parent chain considered,
width and height are explicitly set to 0, ...)
<br> If you need logical visibility of this particular widget,
use {@link UIObject#isVisible(Element elem)} |
public static boolean isRealHidden(Widget widget) {
if (widget == null || !widget.isAttached()) return true;
Element elt = widget.getElement();
return !UIObject.isVisible(elt) || Mobile.isHidden(elt);
} | Expensive, based on jQuery, realistic visibility check. |
public static String hyphenToCamelCase(String hyphenStr) {
if (hyphenStr == null || hyphenStr.isEmpty()) return hyphenStr;
int p = hyphenStr.indexOf('-');
if (p == -1) return hyphenStr;
StringBuilder sb = new StringBuilder(hyphenStr);
do {
int i = p + 1;
if (i < sb.length()) {
sb.setCharAt(i, Character.toUpperCase(sb.charAt(i)));
}
sb.deleteCharAt(p);
p = sb.indexOf("-", p);
if (p == -1) break;
} while (true);
return sb.toString();
} | Converts aaa-bbb-ccc to aaaBbbCcc |
public static int indexOfName(String nameList, String name) {
int idx = nameList.indexOf(name);
// Calculate matching index.
while (idx != -1) {
if (idx == 0 || nameList.charAt(idx - 1) == ' ') {
int last = idx + name.length();
int lastPos = nameList.length();
if ((last == lastPos) || ((last < lastPos) && (nameList.charAt(last) == ' '))) {
break;
}
}
idx = nameList.indexOf(name, idx + 1);
}
return idx;
} | Exact copy of com.google.gwt.dom.client.Element.indexOfName()
<p> Returns the index of the first occurrence of name in a space-separated list of names,
or -1 if not found. </p>
@param nameList list of space delimited names
@param name a non-empty string. Should be already trimmed. |
public static void moveChildren(Element from, Element to) {
if (from == null || to == null || from == to) return;
for (int k = from.getChildCount() - 1; k >= 0; k--) {
Node node = from.getChild(k);
from.removeChild(node);
to.insertFirst(node);
}
} | Moves all children of "from" element onto "to" element. |
public static Widget findWidget(Element elt) {
if (elt == null) return null;
EventListener listener = DOM.getEventListener(elt);
if (listener == null || !(listener instanceof Widget)) return null;
return (Widget) listener;
} | Needed to find out jqm widget by its Element received usually from JavaScript.
<br> Only loaded (attached to DOM) widgets can be found. |
public static void attachAndEnhance(JQMContainer container) {
if (container == null) return;
RootPanel p = getRootPanel();
if (p == null) return;
p.add(container);
enhance(container);
container.setEnhanced(true);
} | Appends the given {@link JQMPage} to the DOM so that JQueryMobile is
able to manipulate it and render it. This should only be done once per
page, otherwise duplicate HTML would be added to the DOM and this would
result in elements with overlapping IDs. |
public static void changePage(JQMContainer container, TransitionIntf<?> transition, boolean reverse) {
changePage(container, false/*dialog*/, transition, reverse);
} | Change the displayed page to the given {@link JQMPage} instance using
the supplied transition and reverse setting. |
public static void render(String id) {
if (id == null || id.isEmpty()) {
throw new IllegalArgumentException("render() for empty id is not possible");
}
renderImpl(id);
} | Ask JQuery Mobile to "render" the child elements of the element with the given id. |
public static void silentScroll(Element e) {
if (e.getId() != null)
Mobile.silentScroll(getTop(e.getId()));
} | Scroll the page to the y-position of the given element. The element must
be attached to the DOM (obviously!).
This method will not fire jquery mobile scroll events. |
public static List<String> split(String s, String separator) {
if (s == null) return null;
List<String> rslt = null;
if (s.isEmpty() || isEmpty(separator)) {
rslt = new ArrayList<>(1);
rslt.add(s);
return rslt;
}
//return s.split(COMMA_SPLIT); - NOT WORKING when compiled to JS
int start = 0;
int p = start;
do {
int j = s.indexOf(separator, p);
if (j == -1) {
if (rslt == null) {
rslt = new ArrayList<>(1);
rslt.add(s);
return rslt;
}
rslt.add(s.substring(start));
break;
}
if (j > 0 && s.charAt(j - 1) == '\\') {
p = j + 1;
continue;
} else {
if (rslt == null) rslt = new ArrayList<String>();
rslt.add(s.substring(start, j));
start = j + 1;
p = start;
}
} while (true);
return rslt;
} | Splits string by separator, if separator in string is backslashed, i.e. prefixed by \ then
it's ignored(preserved). |
public static Map<String, String> splitKeyValue(List<String> lst) {
if (lst == null || lst.isEmpty()) return null;
Map<String, String> rslt = null;
for (String s : lst) {
s = s.trim();
if (s.isEmpty() || s.equals("=")) continue;
int j = s.indexOf('=');
if (j >= 0) {
String k = s.substring(0, j).trim();
String v = s.substring(j + 1).trim();
if (k.isEmpty() && v.isEmpty()) continue;
if (rslt == null) rslt = new LinkedHashMap<>();
rslt.put(k, v);
} else {
if (rslt == null) rslt = new LinkedHashMap<>();
rslt.put(s, null);
}
}
return rslt;
} | Splits list of a=b pairs, if line doesn't have = then it just goes to keys.
<br> trim() is called for all result keys and values. |
public static String getDigitsOnly(String s) {
if (isEmpty(s)) return s;
String rslt = s.trim();
if (isEmpty(rslt)) return rslt;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < rslt.length(); i++) {
char ch = rslt.charAt(i);
if (Character.isDigit(ch)) sb.append(ch);
}
return sb.toString();
} | Returns only digits from specified string |
public static boolean isDigitsOnly(String s) {
if (isEmpty(s)) return false;
String rslt = s.trim();
if (isEmpty(rslt)) return false;
for (int i = 0; i < rslt.length(); i++) {
char ch = rslt.charAt(i);
if (!Character.isDigit(ch)) return false;
}
return true;
} | Returns true if specified string contains only digits |
private void _doLogicalClear() {
// Only use one orphan command per panel to avoid object creation.
if (orphanCommand == null) {
orphanCommand = new AttachDetachException.Command() {
@Override
public void execute(Widget w) {
orphan(w);
}
};
}
try {
AttachDetachException.tryCommand(this, orphanCommand);
} finally {
children = new WidgetCollection(this);
}
} | ComplexPanel.doLogicalClear() is not available, that's why we need this stupid copy |
public static CustomFlowPanel adoptExternal(ComplexPanel parentPanel, Element externalChild) {
if (parentPanel == null || externalChild == null) return null;
CustomFlowPanel rslt = new CustomFlowPanel(externalChild);
WidgetCollection children = getChildren(parentPanel);
children.add(rslt); // Logical attach
adoptChild(parentPanel, rslt); // Adopt
return rslt;
} | The same as ComplexPanel.add(child, container), but without physical DOM.appendChild() attach.
@param parentPanel - depends on externalChild placement in DOM, in most of the cases it should be RootPanel.get() |
public boolean isSelected(String id) {
for (JQMCheckbox box : checks) {
if (id.equals(box.getId()))
return box.isChecked();
}
return false;
} | Returns true if the checkbox with the given id is selected.
@param id - the id of the checkbox to test |
private void initChangeHandler() {
JQMChangeHandler handler = new JQMChangeHandler() {
@Override
public void onEvent(JQMEvent<?> event) {
DomEvent.fireNativeEvent(Document.get().createChangeEvent(), input);
}};
JQMHandlerRegistration.registerJQueryHandler(new WidgetHandlerCounter() {
@Override
public int getHandlerCountForWidget(GwtEvent.Type<?> type) {
return getHandlerCount(type);
}
}, this, handler, JQMComponentEvents.CHANGE,
JQMEventFactory.getType(JQMComponentEvents.CHANGE, JQMChangeHandler.class));
} | Standard GWT ChangeEvent is not working for search input, that's why we have to activate
it manually by listening jQuery change event. |
public HandlerRegistration addInputHandler(JQMInputHandler handler) {
if (handler == null) return null;
return JQMHandlerRegistration.registerJQueryHandler(new WidgetHandlerCounter() {
@Override
public int getHandlerCountForWidget(GwtEvent.Type<?> type) {
return getHandlerCount(type);
}
}, this, handler, JQMComponentEvents.INPUT,
JQMEventFactory.getType(JQMComponentEvents.INPUT, JQMInputHandler.class));
} | Occurs on every entered/deleted symbol.
<br><b>Warning!</b> Clear button does not raise this event, use
addValueChangeHandler() to react on it. |
public static <S extends HasAttachHandlers> void fire(S source, RowSelChangedData data) {
if (TYPE != null) {
JQMDataTableRowSelChangedEvent event = new JQMDataTableRowSelChangedEvent(data);
source.fireEvent(event);
}
} | Fires an {@link JQMDataTableRowSelChangedEvent} on all registered handlers in the handler source.
@param <S> The handler source type
@param source - the source of the handlers |
@SuppressWarnings("unchecked")
public static <T> T get(Class<T> clazz, String localeStr) throws IOException {
if(clazz == null) {
throw new IllegalArgumentException("Class cannot be null.");
}
ULocale locale = null;
if(localeStr != null && !localeStr.isEmpty()) {
locale = ULocale.createCanonical(localeStr);
}
LocaleMapKey key = new LocaleMapKey(clazz.getName(), locale);
T proxy = (T) cache.get(key);
if(proxy == null) {
proxy = createProxy(clazz, locale);
cache.put(key, proxy);
}
return proxy;
} | For a given interface and locale ,retrieves the GWT i18n interface as a
dynamic proxy for use on the server-side. If no locale is given, the
default properties file will be loaded. This method caches proxy classes
that it has created so it is safe to call multiple times. Locale IDs
are case-sensitive (i.e. en_us is not the same as en_US).
@param clazz The GWT i18n interface to get the proxy for.
@param localeStr The locale ID string for the locale being requested.
@return A dynamic proxy representing the given GWT i18n interface and
locale.
@throws IOException If an error occurs finding, opening, or reading the
GWT properties file associated with the given interface. |
private static <T> InputStream getPropertiesFile(Class<T> clazz, ULocale locale) {
String localeStr = "";
if(locale != null) {
localeStr = '_' + locale.getName();
}
String filePath = clazz.getName().replace(DOT, SLASH) + localeStr + PROPERTIES_EXT;
return clazz.getClassLoader().getResourceAsStream(filePath);
} | Get the properties file associated with the given interface and locale
as an InputStream. Use the return value in an InputStream reader to load
the properties file data into a Properties object.
@param clazz The Class representing one of the i18n interface.
@param locale The locale to get the properties for.
@return Returns an InputStream of the file data suitable for loading
into a Properties object or null if no properties file for the file
path is found. |
public static <S extends HasAttachHandlers> void fire(S source, PopupState popupState,
PopupOptions popupOptions) {
if (TYPE != null) {
JQMPopupEvent event = new JQMPopupEvent(popupState);
if (popupOptions != null) event.setPopupOptions(popupOptions);
source.fireEvent(event);
}
} | Fires an {@link JQMPopupEvent} on all registered handlers in the handler source.
@param <S> The handler source type
@param source - the source of the handlers |
public static <S extends HasAttachHandlers> void fire(S source, boolean before) {
if (TYPE != null) {
JQMDataTableEnhancedEvent event = new JQMDataTableEnhancedEvent(before);
source.fireEvent(event);
}
} | Fires an {@link JQMDataTableEnhancedEvent} on all registered handlers in the handler source.
@param <S> The handler source type
@param source - the source of the handlers |
@Override
public String getValue() {
switch (getSelectedIndex()) {
case 0:
if (internVal == null) return null;
internVal = getValue1();
return internVal;
case 1:
internVal = getValue2();
return internVal;
default:
return null;
}
} | Returns the currently selected value or null if there is no currently
selected button |
@Override
public void setValue(String value, boolean fireEvents) {
int newIdx = value == null ? 0 : value.equals(getValue1()) ? 0
: value.equals(getValue2()) ? 1 : 0;
int oldIdx = getSelectedIndex();
String oldVal = fireEvents ? getValue() : null;
internVal = value;
if (oldIdx != newIdx) {
inSetValue = true;
try {
setSelectedIndex(newIdx);
} finally {
inSetValue = false;
}
}
if (fireEvents) {
boolean eq = internVal == oldVal || internVal != null && internVal.equals(oldVal);
if (!eq) ValueChangeEvent.fire(this, internVal);
}
} | Sets the currently selected value.
@param fireEvents - if false then ValueChangeEvent won't be raised (though ChangeEvent will be raised anyway). |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.