code
stringlengths
67
466k
docstring
stringlengths
1
13.2k
public void done() throws JsonWriterException { super.doneInternal(); if (appendable instanceof Flushable) { try { ((Flushable) appendable).flush(); } catch (IOException e) { throw new JsonWriterException(e); } } }
Closes this JSON writer and flushes the underlying {@link Appendable} if it is also {@link Flushable}. @throws JsonWriterException if the underlying {@link Flushable} {@link Appendable} failed to flush.
public void stroke(Canvas canvas, Align align, float x, float y) { float sy = y + bounds.y(); for (TextLayout line : lines) { float sx = x + bounds.x() + align.getX(line.width(), textWidth()); canvas.strokeText(line, sx, sy); sy += line.ascent() + line.descent() + line.leading(); } }
Strokes {@code lines} into {@code canvas} at the specified coordinates, using the specified alignment.
public CanvasImage toImage(Align align, int fillColor) { float pad = pad(); CanvasImage image = graphics().createImage(bounds.width()+2*pad, bounds.height()+2*pad); image.canvas().setFillColor(fillColor); fill(image.canvas(), align, pad, pad); return image; }
Creates a canvas image large enough to accommodate this text block and renders the lines into it. The image will include padding around the edge to ensure that antialiasing has a bit of extra space to do its work.
public static Result convert(final Object res) throws QConnectorException { if (res == null) { return new EmptyResult(); } // table if (res instanceof c.Flip) { return new FlipResult("", (c.Flip) res); } // dict if (res instanceof c.Dict) { final c.Dict dict = (c.Dict) res; if ((dict.x instanceof c.Flip) && (dict.y instanceof c.Flip)) { final c.Flip key = (c.Flip) dict.x; final c.Flip data = (c.Flip) dict.y; return new FlipFlipResult("", key, data); } } if (res instanceof Object[]) { final Object[] oa = (Object[]) res; if ((oa.length == 2) && (oa[0] instanceof String) && (oa[1] instanceof c.Flip)) { final String table = (String) oa[0]; final c.Flip flip = (c.Flip) oa[1]; return new FlipResult(table, flip); } else if ((oa.length == 3) && (oa[1] instanceof String) && (oa[2] instanceof c.Flip)) { final String table = (String) oa[1]; final c.Flip flip = (c.Flip) oa[2]; return new FlipResult(table, flip); } else { return new ListResult<Object>(oa); } } // list if (res instanceof byte[]) { return new ListResult<Byte>(ArrayUtils.toObject((byte[]) res)); }
Converts an result from the kx c library to a QConnector Result. @param res Result from q @return Result @throws QConnectorException If the result type is not supported
public void add(final String path) { final Set<String> paths = new LinkedHashSet<String>(); paths.addAll(get()); paths.add(path); set(paths); }
See: http://forums.sun.com/thread.jspa?threadID=707176
public String formatAsString(final Cell cell, final boolean isStartDate1904) { return formatAsString(cell, Locale.getDefault(), isStartDate1904); }
セルの値をフォーマットし、文字列として取得する @param cell フォーマット対象のセル @param isStartDate1904 ファイルの設定が1904年始まりかどうか。 {@link JXLUtils#isDateStart1904(jxl.Sheet)}で値を調べます。 @return フォーマットしたセルの値。 @throws IllegalArgumentException cell is null.
public String formatAsString(final Cell cell, final Locale locale, final boolean isStartDate1904) { ArgUtils.notNull(cell, "cell"); return format(cell, locale, isStartDate1904).getText(); }
ロケールを指定してセルの値をフォーマットし、文字列として取得する @param cell フォーマット対象のセル @param locale フォーマットしたロケール。nullでも可能。 ロケールに依存する場合、指定したロケールにより自動的に切り替わります。 @param isStartDate1904 ファイルの設定が1904年始まりかどうか。 {@link JXLUtils#isDateStart1904(jxl.Sheet)}で値を調べます。 @return フォーマットしたセルの値。 @throws IllegalArgumentException cell is null.
public CellFormatResult format(final Cell cell, final boolean isStartDate1904) { ArgUtils.notNull(cell, "cell"); return format(cell, Locale.getDefault(), isStartDate1904); }
セルの値をフォーマットする。 @since 0.3 @param cell フォーマット対象のセル @param isStartDate1904 ファイルの設定が1904年始まりかどうか。 {@link JXLUtils#isDateStart1904(jxl.Sheet)}で値を調べます。 @return フォーマットしたセルの値。 @throws IllegalArgumentException cell is null.
public CellFormatResult format(final Cell cell, final Locale locale, final boolean isStartDate1904) { ArgUtils.notNull(cell, "cell"); final Locale runtimeLocale = locale != null ? locale : Locale.getDefault(); final CellType cellType = cell.getType(); if(cellType == CellType.EMPTY) { final CellFormatResult result = new CellFormatResult(); result.setCellType(FormatCellType.Blank); result.setText(""); return result; } else if(cellType == CellType.LABEL || cellType == CellType.STRING_FORMULA) { return getCellValue(cell, runtimeLocale, isStartDate1904); } else if(cellType == CellType.BOOLEAN || cellType == CellType.BOOLEAN_FORMULA) { return getCellValue(cell, runtimeLocale, isStartDate1904); } else if(cellType == CellType.ERROR || cellType == CellType.FORMULA_ERROR) { return getErrorCellValue(cell, runtimeLocale, isStartDate1904); } else if(cellType == CellType.DATE || cellType == CellType.DATE_FORMULA) { return getCellValue(cell, runtimeLocale, isStartDate1904); } else if(cellType == CellType.NUMBER || cellType == CellType.NUMBER_FORMULA) { return getCellValue(cell, runtimeLocale, isStartDate1904); } else { final CellFormatResult result = new CellFormatResult(); result.setCellType(FormatCellType.Unknown); result.setText(""); return result; } }
ロケールを指定してセルの値をフォーマットする。 @since 0.3 @param cell フォーマット対象のセル @param locale フォーマットしたロケール。nullでも可能。 ロケールに依存する場合、指定したロケールにより自動的に切り替わります。 @param isStartDate1904 ファイルの設定が1904年始まりかどうか。 {@link JXLUtils#isDateStart1904(jxl.Sheet)}で値を調べます。 @return フォーマットしたセルの値。 @throws IllegalArgumentException cell is null.
private CellFormatResult getErrorCellValue(final Cell cell, final Locale locale, final boolean isStartDate1904) { final CellFormatResult result = new CellFormatResult(); result.setCellType(FormatCellType.Error); final ErrorCell errorCell = (ErrorCell) cell; final int errorCode = errorCell.getErrorCode(); result.setValue(errorCode); if(isErrorCellAsEmpty()) { result.setText(""); } else { /* * エラーコードについては、POIクラスを参照。 * ・org.apache.poi.ss.usermodel.FormulaError * ・org.apache.poi.ss.usermodel.ErrorConstants */ switch(errorCode) { case 7: // 0除算 result.setText("#DIV/0!"); break; case 42: // 関数や数式に使用できる値がない result.setText("#N/A"); break; case 29: // 数式が参照している名称がない result.setText("#NAME?"); break; case 0: // 正しくない参照演算子または正しくないセル参照を使っている result.setText("#NULL!"); break; case 36: // 数式または関数の数値が不適切 result.setText("#NUM!"); break; case 23: // 数式が参照しているセルがない result.setText("#REF!"); break; case 15: // 文字列が正しいデータ型に変換されない result.setText("#VALUE!"); break; default: result.setText(""); break; } } return result; }
エラー型のセルの値を取得する。 @since 0.4 @param cell @param locale @param isStartDate1904 @return
private CellFormatResult getCellValue(final Cell cell, final Locale locale, final boolean isStartDate1904) { final JXLCell jxlCell = new JXLCell(cell, isStartDate1904); final short formatIndex = jxlCell.getFormatIndex(); final String formatPattern = jxlCell.getFormatPattern(); if(formatterResolver.canResolve(formatIndex)) { final CellFormatter cellFormatter = formatterResolver.getFormatter(formatIndex); return cellFormatter.format(jxlCell, locale); } else if(formatterResolver.canResolve(formatPattern)) { final CellFormatter cellFormatter = formatterResolver.getFormatter(formatPattern); return cellFormatter.format(jxlCell, locale); } else { // キャッシュに登録する。 final CellFormatter cellFormatter = formatterResolver.createFormatter(formatPattern) ; if(isCache()) { formatterResolver.registerFormatter(formatPattern, cellFormatter); } return cellFormatter.format(jxlCell, locale); } }
セルの値をフォーマットする。 @param cell フォーマット対象のセル @param locale ロケール @param isStartDate1904 1904年始まりかどうか。 @return
public void setPathPrefix(String... components) { assert components.length > 0; for (String component : components) { assert !component.contains("/") && !component.contains("\\") : "Path components must not contain path separators: " + component; } pathPrefix = Path.Combine(components); }
Configures the prefix prepended to asset paths before fetching them from the app directory. Note that you specify path components as an array, <em>not</em> a single string that contains multiple components with embedded path separators.
public void add(Image image) { assert !start || listener == null; ++total; image.addCallback(callback); }
Adds an image resource to be watched.
public void add(Sound sound) { assert !start || listener == null; ++total; sound.addCallback(callback); }
Adds a sound resource to be watched.
public static synchronized void initialize(Application application) { if (sHelper != null) { Log.v(TAG, "already initialized"); } sHelper = new TypefaceHelper(application); }
Initialize the instance. @param application the application context.
public <V extends TextView> void setTypeface(V view, String typefaceName) { Typeface typeface = mCache.get(typefaceName); view.setTypeface(typeface); }
Set the typeface to the target view. @param view to set typeface. @param typefaceName typeface name. @param <V> text view parameter.
public <V extends TextView> void setTypeface(V view, @StringRes int strResId) { setTypeface(view, mApplication.getString(strResId)); }
Set the typeface to the target view. @param view to set typeface. @param strResId string resource containing typeface name. @param <V> text view parameter.
public <V extends ViewGroup> void setTypeface(V viewGroup, @StringRes int strResId) { setTypeface(viewGroup, mApplication.getString(strResId)); }
Set the typeface to the all text views belong to the view group. Note that this method recursively trace the child view groups and set typeface for the text views. @param viewGroup the view group that contains text views. @param strResId string resource containing typeface name. @param <V> view group parameter.
public <V extends ViewGroup> void setTypeface(V viewGroup, String typefaceName, int style) { int count = viewGroup.getChildCount(); for (int i = 0; i < count; i++) { View child = viewGroup.getChildAt(i); if (child instanceof ViewGroup) { setTypeface((ViewGroup) child, typefaceName, style); continue; } if (!(child instanceof TextView)) { continue; } setTypeface((TextView) child, typefaceName, style); } }
Set the typeface to the all text views belong to the view group. Note that this method recursively trace the child view groups and set typeface for the text views. @param viewGroup the view group that contains text views. @param typefaceName typeface name. @param style the typeface style. @param <V> view group parameter.
public void setTypeface(Paint paint, String typefaceName) { Typeface typeface = mCache.get(typefaceName); paint.setTypeface(typeface); }
Set the typeface to the target paint. @param paint the set typeface. @param typefaceName typeface name.
public void setTypeface(Paint paint, @StringRes int strResId) { setTypeface(paint, mApplication.getString(strResId)); }
Set the typeface to the target paint. @param paint the set typeface. @param strResId string resource containing typeface name.
public View setTypeface(Context context, @LayoutRes int layoutRes, ViewGroup parent, @StringRes int strResId) { return setTypeface(context, layoutRes, parent, mApplication.getString(strResId)); }
Set the typeface to the all text views belong to the view group. @param context the context. @param layoutRes the layout resource id. @param parent the parent view group to attach the layout. @param strResId string resource containing typeface name. @return the view.
public View setTypeface(Context context, @LayoutRes int layoutRes, String typefaceName, int style) { return setTypeface(context, layoutRes, null, typefaceName, 0); }
Set the typeface to the all text views belong to the view group. @param context the context. @param layoutRes the layout resource id. @param typefaceName typeface name. @param style the typeface style. @return the view.
public View setTypeface(Context context, @LayoutRes int layoutRes, ViewGroup parent, String typefaceName, int style) { ViewGroup view = (ViewGroup) LayoutInflater.from(context).inflate(layoutRes, parent); setTypeface(view, typefaceName, style); return view; }
Set the typeface to the all text views belong to the view group. @param context the context. @param layoutRes the layout resource id. @param parent the parent view group to attach the layout. @param typefaceName typeface name. @param style the typeface style. @return the view.
public void setTypeface(Activity activity, String typefaceName, int style) { setTypeface((ViewGroup) activity.getWindow().getDecorView(), typefaceName, style); }
Set the typeface to the all text views belong to the activity. Note that we use decor view of the activity so that the typeface will also be applied to action bar. @param activity the activity. @param typefaceName typeface name. @param style the typeface style.
public void setTypeface(Activity activity, @StringRes int strResId, int style) { setTypeface(activity, mApplication.getString(strResId), style); }
Set the typeface to the all text views belong to the activity. Note that we use decor view of the activity so that the typeface will also be applied to action bar. @param activity the activity. @param strResId string resource containing typeface name. @param style the typeface style.
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public <F extends android.app.Fragment> void setTypeface(F fragment, String typefaceName) { setTypeface(fragment, typefaceName, 0); }
Set the typeface to the all text views belong to the fragment. Make sure to call this method after fragment view creation. If you use fragments in the support package, call {@link com.drivemode.android.typeface.TypefaceHelper#supportSetTypeface(android.support.v4.app.Fragment, String)} instead. @param fragment the fragment. @param typefaceName typeface name.
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public <F extends android.app.Fragment> void setTypeface(F fragment, @StringRes int strResId) { setTypeface(fragment, mApplication.getString(strResId)); }
Set the typeface to the all text views belong to the fragment. Make sure to call this method after fragment view creation. If you use fragments in the support package, call {@link com.drivemode.android.typeface.TypefaceHelper#supportSetTypeface(android.support.v4.app.Fragment, String)} instead. @param fragment the fragment. @param strResId string resource containing typeface name.
@TargetApi(Build.VERSION_CODES.HONEYCOMB) public <F extends android.app.Fragment> void setTypeface(F fragment, String typefaceName, int style) { View root = fragment.getView(); if (root instanceof TextView) { setTypeface((TextView) root, typefaceName, style); } else if (root instanceof ViewGroup) { setTypeface((ViewGroup) root, typefaceName, style); } }
Set the typeface to the all text views belong to the fragment. Make sure to call this method after fragment view creation. If you use fragments in the support package, call {@link com.drivemode.android.typeface.TypefaceHelper#supportSetTypeface(android.support.v4.app.Fragment, String, int)} instead. @param fragment the fragment. @param typefaceName typeface name. @param style the typeface style.
public <F extends android.support.v4.app.Fragment> void supportSetTypeface(F fragment, String typefaceName) { supportSetTypeface(fragment, typefaceName, 0); }
Set the typeface to the all text views belong to the fragment. Make sure to call this method after fragment view creation. And this is a support package fragments only. @param fragment the fragment. @param typefaceName typeface name.
public <F extends android.support.v4.app.Fragment> void supportSetTypeface(F fragment, String typefaceName, int style) { View root = fragment.getView(); if (root instanceof TextView) { setTypeface((TextView) root, typefaceName, style); } else if (root instanceof ViewGroup) { setTypeface((ViewGroup) root, typefaceName, style); } }
Set the typeface to the all text views belong to the fragment. Make sure to call this method after fragment view creation. And this is a support package fragments only. @param fragment the fragment. @param typefaceName typeface name. @param style the typeface style.
public <F extends android.support.v4.app.Fragment> void supportSetTypeface(F fragment, @StringRes int strResId, int style) { supportSetTypeface(fragment, mApplication.getString(strResId), style); }
Set the typeface to the all text views belong to the fragment. Make sure to call this method after fragment view creation. And this is a support package fragments only. @param fragment the fragment. @param strResId string resource containing typeface name. @param style the typeface style.
public <D extends Dialog> void setTypeface(D dialog, String typefaceName) { setTypeface(dialog, typefaceName, 0); }
Set the typeface for the dialog view. @param dialog the dialog. @param typefaceName typeface name.
public <D extends Dialog> void setTypeface(D dialog, @StringRes int strResId) { setTypeface(dialog, mApplication.getString(strResId)); }
Set the typeface for the dialog view. @param dialog the dialog. @param strResId string resource containing typeface name.
public <D extends Dialog> void setTypeface(D dialog, String typefaceName, int style) { DialogUtils.setTypeface(this, dialog, typefaceName, style); }
Set the typeface for the dialog view. @param dialog the dialog. @param typefaceName typeface name. @param style the typeface style.
public Toast setTypeface(Toast toast, String typefaceName, int style) { setTypeface((ViewGroup) toast.getView(), typefaceName, style); return toast; }
Set the typeface for the toast view. @param toast toast. @param typefaceName typeface name. @param style the typeface style. @return toast that the typeface is injected.
public Toast setTypeface(Toast toast, @StringRes int strResId, int style) { return setTypeface(toast, mApplication.getString(strResId), style); }
Set the typeface for the toast view. @param toast toast. @param strResId string resource containing typeface name. @param style the typeface style. @return toast that the typeface is injected.
public static int nextPowerOfTwo(int x) { assert x < 0x10000; int bit = 0x8000, highest = -1, count = 0; for (int i = 15; i >= 0; --i, bit >>= 1) { if ((x & bit) != 0) { ++count; if (highest == -1) { highest = i; } } } if (count <= 1) { return 0; } return 1 << (highest + 1); }
Returns the next largest power of two, or zero if x is already a power of two. TODO(jgw): Is there no better way to do this than all this bit twiddling?
public static <S extends HasAttachHandlers> void fire(S source, PageState pageState, JQMPage prevPage, JQMPage nextPage) { if (TYPE != null) { JQMPageEvent event = new JQMPageEvent(pageState, prevPage, nextPage); source.fireEvent(event); } }
Fires an {@link JQMPageEvent} on all registered handlers in the handler source. @param <S> The handler source type @param source - the source of the handlers
@Override public void setInline(boolean value) { inline = value; if (headingToggle != null) { JQMCommon.setInlineEx(headingToggle, value, JQMCommon.STYLE_UI_BTN_INLINE); } }
Sets the header button as inline block.
public boolean isCollapsed() { boolean v = JQMCommon.hasStyle(this, "ui-collapsible-collapsed"); if (v) return v; if (!isInstance(getElement())) { String s = getAttribute("data-collapsed"); if (Empty.is(s)) return true; // true by default, see https://api.jquerymobile.com/collapsible/#option-collapsed if ("false".equalsIgnoreCase(s)) return false; else return true; } return false; }
Returns true if this {@link JQMCollapsible} is currently collapsed.
public void setCollapsed(boolean collapsed) { if (collapsed) { removeAttribute("data-collapsed"); if (isInstance(getElement())) collapse(); } else { setAttribute("data-collapsed", "false"); if (isInstance(getElement())) expand(); } }
Programmatically set the collapsed state of this widget.
@Override public void setText(String text) { if (headingToggle != null) { if (text == null) text = ""; String s = headingToggle.getInnerHTML(); int p = s.indexOf('<'); if (p >= 0) s = text + s.substring(p); else s = text; headingToggle.setInnerHTML(s); } else if (!isInstance(getElement())) { if (headerPanel != null) { super.remove(headerPanel); headerPanel = null; } header.setText(text); } }
Sets the text on the header element
public void discardHeaderClick(ClickEvent event) { if (event == null) return; // Example: we use radioset on collapsible header, so stopPropagation() is needed // to suppress collapsible open/close behavior. // But preventDefault() is not needed, otherwise radios won't switch. // event.preventDefault(); // For example, clicked anchors will not take the browser to a new URL event.stopPropagation(); makeHeaderInactive(header.getElement()); }
Needed for header widgets to prevent expand/collapse on their clicks.
public String formatDate(Date d) { if (d == null) return null; JsDate jsd = JsDate.create(d.getTime()); return internFormat(input.getElement(), getActiveDateFormat(), jsd); }
Doesn't change anything, just formats passed date as string according to widget's current settings.
protected JQMButton createButton(String text, String url, DataIcon icon) { JQMButton button = new JQMButton(text, url); if (icon != null) button.withBuiltInIcon(icon); return button; }
Internal method for creating a button
@UiChild(tagname="backButton", limit=1) public void setBackButton(JQMButton button) { button.setBack(true); setLeftButton(button); }
Sets the given button in the left position and sets that buttons role to back. Any existing left button will be replaced. @param button the new back button
public JQMButton setBackButton(String text) { JQMButton button = new JQMButton(text); button.withBuiltInIcon(DataIcon.LEFT); setBackButton(button); return button; }
Creates an auto back button with the given text and replaces the current left button, if any. @param text the the text for the button @return the created {@link JQMButton}
@UiChild(tagname="leftButton", limit=1) public void setLeftButton(JQMButton button) { if (left != null) remove(left); button.setPosOnBand(PosOnBand.LEFT); left = button; insert(left, 0); }
Sets the left button to be the given button. Any existing button is removed. @param button - the button to set on the left slot
public JQMButton setLeftButton(String text) { return setLeftButton(text, (String) null, (DataIcon) null); }
Creates a new {@link JQMButton} with the given text and then sets that button in the left slot. Any existing right button will be replaced. This button will not link to a page by default and therefore will only react if a click handler is registered. This is useful if you want the button to do something other than navigate. @param text the text for the button @return the created button
public JQMButton setLeftButton(String text, JQMPage page) { return setLeftButton(text, page, null); }
Creates a new {@link JQMButton} with the given text and linking to the given {@link JQMPage} and then sets that button in the left slot. Any existing right button will be replaced. @param text the text for the button @param page the optional page for the button to link to, if null then this button does not navigate by default @return the created button
public JQMButton setLeftButton(String text, JQMPage page, DataIcon icon) { if (page == null) throw new RuntimeException("page cannot be null"); return setLeftButton(text, "#" + page.getId(), icon); }
Creates a new {@link JQMButton} with the given text and linking to the given {@link JQMPage} and with the given icon and then sets that button in the left slot. Any existing right button will be replaced. @param text the text for the button @param page the optional page for the button to link to, if null then this button does not navigate by default @param icon the icon to use or null if no icon is required @return the created button
public JQMButton setLeftButton(String text, String url) { return setLeftButton(text, url, null); }
Creates a new {@link JQMButton} with the given text and linking to the given url and then sets that button in the left slot. Any existing right button will be replaced. @param text the text for the button @param url the optional url for the button, if null then this button does not navigate by default @return the created button
@UiChild(tagname="rightButton", limit=1) public void setRightButton(JQMButton button) { if (right != null) remove(right); button.setPosOnBand(PosOnBand.RIGHT); right = button; add(right); }
Sets the right button to be the given button. Any existing button is removed. @param button - the button to set on the right slot
public JQMButton setRightButton(String text) { return setRightButton(text, (String) null, (DataIcon) null); }
Creates a new {@link JQMButton} with the given text and then sets that button in the right slot. Any existing right button will be replaced. This button will not link to a page by default and therefore will only react if a click handler is registered. This is useful if you want the button to do something other than navigate. @param text the text for the button @return the created button
public JQMButton setRightButton(String text, JQMPage page) { return setRightButton(text, page, null); }
Creates a new {@link JQMButton} with the given text and linking to the given {@link JQMPage} and then sets that button in the right slot. Any existing right button will be replaced. @param text the text for the button @param page the optional page for the button to link to, if null then this button does not navigate by default @return the created button
public JQMButton setRightButton(String text, JQMPage page, DataIcon icon) { return setRightButton(text, "#" + page.getId(), icon); }
Creates a new {@link JQMButton} with the given text and linking to the given {@link JQMPage} and with the given icon and then sets that button in the right slot. Any existing right button will be replaced. @param text the text for the button @param page the optional page for the button to link to, if null then this button does not navigate by default @param icon the icon to use or null if no icon is required @return the created button
public JQMButton setRightButton(String text, String url) { return setRightButton(text, url, null); }
Creates a new {@link JQMButton} with the given text and linking to the given url and then sets that button in the right slot. Any existing right button will be replaced. @param text the text for the button @param url the optional url for the button, if null then this button does not navigate by default @return the created button
public JQMButton setRightButton(String text, String url, DataIcon icon) { JQMButton button = createButton(text, url, icon); setRightButton(button); return button; }
Creates a new {@link JQMButton} with the given text and linking to the given url and with the given icon and then sets that button in the right slot. Any existing right button will be replaced. @param text the text for the button @param url the optional url for the button, if null then this button does not navigate by default @param icon the icon to use or null if no icon is required @return the created button
public static <S extends HasAttachHandlers> void fire(S source, DisplayChangeData data) { if (TYPE != null) { JQMCalBoxEvent event = new JQMCalBoxEvent(data); source.fireEvent(event); } }
Fires an {@link JQMCalBoxEvent} on all registered handlers in the handler source. @param <S> The handler source type @param source - the source of the handlers
public void setHref(String href) { JQMCommon.setAttribute(a, "href", href); if (external == null /*only if not explicitly set*/ && !Empty.is(href) && (href.startsWith("http:") || href.startsWith("https:"))) { setExternal(true); } }
The destination URL of the link @param href
public void setImageResizePriority(Orientation value) { if (value == null) img.removeAttribute(DATA_RESIZE_PRIORITY); else img.setAttribute(DATA_RESIZE_PRIORITY, value.getJqmValue()); }
Defines how to resize image in case of limited/explicit button size. <p> HORIZONTAL - width is 100% and height is auto (default mode). </p> <p> VERTICAL - height is 100% and width is auto. </p> <p> See <a href="http://stackoverflow.com/a/16217391">Flexible images</a></p>
public void add(JQMSubmit submit) { super.add(submit); submit.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { submit(); } }); }
Add the given submit button to the form and automatically have it set to submit the form on a click event.
public void addValidator(Widget notifiedWidget, Validator validator, boolean immediate, Widget positionErrorAfter, JQMFormWidget... firingWidgets) { boolean labelAdded = false; if (firingWidgets != null) { for (JQMFormWidget w : firingWidgets) { Label la = w.addErrorLabel(); if (la == null) continue; labelAdded = true; addErrorLabel(validator, la, w.asWidget()); } } if (!labelAdded) { Label label = new InlineLabel(); // create a label that will show the validation error label.setStyleName(JQM4GWT_ERROR_LABEL_STYLENAME); if (globalValidationErrorStyles != null && !globalValidationErrorStyles.isEmpty()) { JQMCommon.addStyleNames(label, globalValidationErrorStyles); } label.setVisible(false); if (positionErrorAfter == null) { addErrorLabel(validator, label, null/*widget*/); // add the error label to the document as the next child of this form container add(label); } else { boolean inserted = false; Widget w = positionErrorAfter; while (w != null) { int i = getWidgetIndex(w); if (i >= 0) { i++; // next after w while (i < getWidgetCount()) { Widget wi = getWidget(i); if (wi instanceof Label && JQMCommon.hasStyle(wi, JQM4GWT_ERROR_LABEL_STYLENAME)) { i++; // next after previous errors } else { break; } } insert(label, i); inserted = true; break; } w = w.getParent(); } if (!inserted) { addErrorLabel(validator, label, null/*widget*/); add(label); } else { addErrorLabel(validator, label, positionErrorAfter); } } } registerValidatorWithFiringWidgets(validator, firingWidgets, immediate); boolean required = validator instanceof NotNullOrEmptyValidator; String validatorClass = STYLE_FORM_VALIDATOR + getShortClassName(validator.getClass()); if (notifiedWidget != null) { notifiedWidgets.put(validator, notifiedWidget); notifiedWidget.getElement().addClassName(validatorClass); if (required) notifiedWidget.getElement().addClassName(STYLE_FORM_REQUIRED); } else if (firingWidgets != null) { for (JQMFormWidget w : firingWidgets) { w.asWidget().getElement().addClassName(validatorClass); if (required) w.asWidget().getElement().addClassName(STYLE_FORM_REQUIRED); } } }
Adds a validator and binds it to the collection of widgets. The widget list can be empty. @param validator the validator that will be invoked @param notifiedWidget the widget that will be notified of the error. If null then the firing widget will be used. @param firingWidgets the list of widgets that will fire the validator @param immediate - if true then validator will be called during firingWidgets onBlur() event @param positionErrorAfter - optional, if defined then error label will be placed right after this widget, otherwise it will be added as the current last one.
public void clearValidationStyles() { for (JQMFormWidget widget : widgetValidators.keySet()) { UIObject ui = widget.asWidget(); Collection<Validator> validators = widgetValidators.get(widget); for (Validator v : validators) { if (notifiedWidgets.containsKey(v)) { ui = notifiedWidgets.get(v); } removeStyles(v, ui); } } }
Remove all validation styles
public void setError(String string) { Label errorLabel = new Label(string); errorLabel.setStyleName(JQM4GWT_ERROR_LABEL_STYLENAME); errorLabel.addStyleName(JQM4GWT_GENERAL_ERROR_LABEL_STYLENAME); generalErrors.add(errorLabel); generalErrors.getElement().scrollIntoView(); }
Set a general error on the form.
public void submit(String... submitMsgs) { if (submissionHandler == null) throw new IllegalStateException( "No SubmissionHandler has been set for this Form and it is in an invalid " + "state for submit() until one has been defined."); generalErrors.clear(); boolean validated = validate(false/*scrollToFirstError*/); if (validated) { String s = null; if (submitMsgs.length > 0) s = submitMsgs[0]; if (s == null || s.isEmpty()) s = "Submitting form"; showFormProcessingDialog(s); @SuppressWarnings("unchecked") SubmissionHandler<JQMForm> h = (SubmissionHandler<JQMForm>) submissionHandler; h.onSubmit(this); } else { scrollToFirstError(); } }
This method is invoked when the form is ready for submission. Typically this method would be called from one of your submission buttons automatically but it is possible to invoke it programmatically. <br> Before validation, the general errors are cleared. <br> If the validation phase is passed the the submission handler will be invoked. Before the handler is invoked, the page loading dialog will be shown so that async requests can complete in the background. <br> The {@link SubmissionHandler} must hide the loading dialog by calling hideFormProcessingDialog() on the form or by calling Mobile.hideLoadingDialog()
public boolean validate(boolean scrollToFirstError) { boolean validated = true; for (JQMFormWidget widget : widgetValidators.keySet()) { if (!validate(widget)) validated = false; } if (!validated && scrollToFirstError) scrollToFirstError(); return validated; }
Perform validation for all validators, setting error messages where appropriate. @param scrollToFirstError - if true then in case of unsuccessful validation first error widget will be scrolled into view. @return true if validation was successful for all validators, otherwise false.
protected boolean validate(JQMFormWidget widget) { boolean validated = true; Collection<Validator> validators = widgetValidators.get(widget); for (Validator v : validators) if (!validate(v, widget.asWidget())) validated = false; return validated; }
Performs validation for a single widget, first resetting all validation messages on that widget.
protected boolean validate(Validator validator, UIObject ui) { if (notifiedWidgets.containsKey(validator)) ui = notifiedWidgets.get(validator); String msg = validator.validate(); if (msg == null || msg.length() == 0) { validationStyles(validator, null, ui, true); return true; } else { validationStyles(validator, msg, ui, false); return false; } }
Perform validation for a single validator @param ui the {@link UIObject} to change the stylesheet on @return true if this validator was successfully applied or false otherwise
public void repositionPopup() { String id = getSelectElt().getId(); if (!Empty.is(id)) repositionPopup(id); }
Should be used for proper popup positioning in case of lazy/delayed population on first click to JQMSelect, like: <pre>{@code combo.addClickHandler(event -> Scheduler.get().scheduleDeferred(() -> fetchAndPopulateOptions(done -> combo.repositionPopup()))); }</pre>
public void setExternal(boolean value) { if (value == isExternal()) return; if (value) { Widget parent = getParent(); if (parent instanceof JQMPage) unbindLifecycleEvents(((JQMPage) parent).getId()); JQMContext.getRootPanel().add(this); Scheduler.get().scheduleFinally(new ScheduledCommand() { @Override public void execute() { manualInitialize(getElement()); bindLifecycleEventsExternal(JQMPanel.this, getId()); } }); } else { // TODO (not important): implement unbindLifecycleEventsExternal() through static field & method JQMContext.getRootPanel().remove(this); } }
See <a href="http://demos.jquerymobile.com/1.4.5/panel-external/">External Panels</a>
public static Predicate<Element> shouldGenerateMatcher() { return element -> ElementParentsIterable.stream(element) .noneMatch(next -> nonNull(next.getAnnotation(DoNotGenerateMatcher.class))); }
Walks through parent chain and if any contains {@link DoNotGenerateMatcher} annotation, skips this element @return predicate to help filter fields for matcher generation
public static Stream<Element> stream(Element element) { return StreamSupport.stream(new ElementParentsIterable(element).spliterator(), false); }
Creates stream with parent chain @param element element to start with (will be included to chain) @return stream with elements from current with his parents until package (inclusive)
public void setDataItems(List<M> items) { boolean changed = this.dataItems != items; if (items == null) { this.dataItems = null; } else { this.dataItems = items instanceof BindableListWrapper ? (BindableListWrapper<M>) items : new BindableListWrapper<M>(items); if (changed) this.dataItems.addChangeHandler(this); } addDataItems(); }
Sets the list of model objects. The list will be wrapped in an {@link BindableListWrapper} to make direct changes to the list observable. @param items - The list of model objects. If null or empty all existing items will be removed.
public void rerender() { clear(); if (dataItems != null) { for (M m : dataItems) { addDataItem(m); } } doRefresh(); }
Needed in case of renderer changed, so list has to be visually reconstructed by new renderer.
public void setThemeIfCurrentEmpty(String themeName) { if (themeName == null || themeName.isEmpty()) return; String theme = getTheme(); if (theme == null || theme.isEmpty()) { setTheme(themeName); } }
Sets new theme only in case if currently no theme is defined for this widget.
public void setFilterSearchText(String value) { Element elt = getFilterSearchElt(); if (elt == null) return; refreshFilterSearch(elt, value); }
Complimentary to setDataFilter(). Sets filter search text of associated JQMFilterable widget.
public void setDfltTableStylesStr(String classes) { dfltTableStyles.clear(); if (classes == null || classes.isEmpty()) return; List<String> lst = StrUtils.split(classes, " "); for (int k = 0; k < lst.size(); k++) { String s = lst.get(k).trim(); DataTableStyleClass cls; try { cls = DataTableStyleClass.valueOf(s); dfltTableStyles.add(cls); } catch (Exception ex) { continue; } } }
Expected DataTableStyleClass enum values as space separated string.
public void setScrollY(String scrollY) { this.scrollY = scrollY; if (Empty.is(this.scrollY)) this.scrollYnum = 0; else { String s = StrUtils.getDigitsOnly(this.scrollY); if (!Empty.is(s)) this.scrollYnum = Integer.parseInt(s); else this.scrollYnum = 0; } }
Max table's scrolling area vertical height, so actual table's height will be higher: header + scrolling area + footer. <br> Any CSS measurement is acceptable, or just a number which is treated as pixels.
public void setUseParentHeight(boolean useParentHeight) { this.useParentHeight = useParentHeight; if (this.useParentHeight) { if (useParentHeightDrawHandler == null) { useParentHeightDrawHandler = new DrawHandler() { @Override public void afterDraw(Element tableElt, JavaScriptObject settings) { if (JQMDataTable.this.useParentHeight) adjustToParentHeight(); } @Override public boolean beforeDraw(Element tableElt, JavaScriptObject settings) { return true; }}; JsDataTable.addDrawHandler(getElement(), useParentHeightDrawHandler); } if (loaded) { initWindowResize(); initOrientationChange(); } } }
Takes all parent height. Only works when scrollY is set to some value, for example: 1px <br> And scrollY value will be used as min-height for scrolling area.
public void adjustToParentHeight() { Element tableElt = getElement(); Element wrapper = null; Element scrollBody = null; Element elt = tableElt.getParentElement(); while (elt != null) { if (scrollBody == null) { if (JQMCommon.hasStyle(elt, SCROLL_BODY)) { scrollBody = elt; } } else if (wrapper == null) { if (JQMCommon.hasStyle(elt, WRAPPER)) { wrapper = elt; break; } } elt = elt.getParentElement(); } if (wrapper != null && scrollBody != null) { Element wrapParent = wrapper.getParentElement(); if (wrapParent != null) { int h = wrapParent.getClientHeight(); int wrapH = wrapper.getOffsetHeight(); String s = scrollBody.getStyle().getHeight(); s = StrUtils.getDigitsOnly(s); if (!Empty.is(s)) { int scrollBodyH = Integer.parseInt(s); int newH = (h - wrapH) + scrollBodyH - 1; if (newH < 0) newH = 0; if (scrollYnum > 0 && newH < scrollYnum) newH = scrollYnum; scrollBody.getStyle().setHeight(newH, Unit.PX); } } } }
Adjusts height to parent's height. <br> It's one time action, and works regardless of useParentHeight current value. <br> Only works when scrollY is set to some value, for example: 1px <br> And scrollY value will be used as min-height for scrolling area.
public void adjustColumnSizing() { JsDataTable.adjustColumnSizing(getElement()); Element sb = findUpperElement(SCROLL_BODY); if (sb != null) sb.setScrollLeft(0); }
Aligns header to match the columns, useful after resize or orientation changes.
public void setColumns(List<ColumnDefEx> cols) { clearHead(); datacols.clear(); if (!Empty.is(cols)) datacols.addAll(cols); // head will be created later in onLoad() or by refreshColumns() }
You have to call refreshColumns() to update head and body (if widget is already loaded).
public void setColumnVisible(String colName, boolean visible) { ColumnDefEx col = findColumn(colName); if (col == null) return; col.setVisible(visible); JsDataTable.setColVisible(getElement(), colName, visible); }
Works dynamically after dataTable is initialized
public void setColumnTitle(String colName, String title) { ColumnDefEx col = findColumn(colName); if (col == null) return; col.setTitle(title); JsDataTable.setColTitle(getElement(), colName, title); }
Works dynamically after dataTable is initialized
public void refreshColumns() { boolean wasEnhanced = enhanced; if (enhanced) unEnhance(); clearHead(); tBody.clear(); populateHeadAndBody(); if (wasEnhanced) enhance(); }
Refreshes head and body, needed for example after addColumn(). <br>Currently it's slow and completely re-enhances DataTable, because there is no support for dynamic columns in DataTable, see <a href="https://github.com/DataTables/DataTables/issues/273"> Create columns dynamically</a>
public JsArray<Element> doGrouping(JavaScriptObject settings, int colIdx, ColSort... additionalSorts) { if (additionalSorts != null && additionalSorts.length > 0) { List<ColSort> lst = new ArrayList<>(additionalSorts.length); for (int i = 0; i < additionalSorts.length; i++) lst.add(additionalSorts[i]); JsSortItems jsAddnlSorts = prepareJsOrder(lst); return JsDataTable.doGrouping(settings, colIdx, jsAddnlSorts, grpRowHandler); } else { return JsDataTable.doGrouping(settings, colIdx, null/*additionalSorts*/, grpRowHandler); } } public JsArray<Element> getSelRowElements() { return JsDataTable.getSelRowElements(getElement()); } /** Makes no much sense when serverSide is true, use getSelRowIds() in that case. */ public JsArrayInteger getSelRowIndexes() { return JsDataTable.getSelRowIndexes(getElement()); } /** Makes no much sense when serverSide is true, use getSelRowIds() in that case. */ public JsArray<JavaScriptObject> getSelRowDatas() { return JsDataTable.getSelRowDatas(getElement()); } /** Works when serverSide is true. */ public Set<String> getSelRowIds() { return serverRowSelected; } public void unselectAllRows() { JsDataTable.unselectAllRows(getElement()); } /** @param cellOrRowElt - could be cellElt or rowElt */ public void changeRow(Element cellOrRowElt, boolean selected) { JsDataTable.changeRow(cellOrRowElt, selected); } /** @param cellOrRowElt - could be cellElt or rowElt */ public void selectOneRowOnly(Element cellOrRowElt) { JsDataTable.selectOneRowOnly(cellOrRowElt); } public JsArray<Element> getFilteredRowElements() { return JsDataTable.getFilteredRowElements(getElement()); } public JsArrayInteger getFilteredRowIndexes() { return JsDataTable.getFilteredRowIndexes(getElement()); } public JsArray<JavaScriptObject> getFilteredRowDatas() { return JsDataTable.getFilteredRowDatas(getElement()); } public JsArray<Element> getAllRowElements() { return JsDataTable.getAllRowElements(getElement()); } public JsArrayInteger getAllRowIndexes() { return JsDataTable.getAllRowIndexes(getElement()); } public JsArray<JavaScriptObject> getAllRowDatas() { return JsDataTable.getAllRowDatas(getElement()); } public JavaScriptObject getData() { return JsDataTable.getData(getElement()); } public void clearData() { JsDataTable.clearData(getElement()); } public void clearAll() { clearData(); clearSearch(); } /** * Allows multiple additions, like addRow(); addRow(); ...; refreshDraw(); * <br> refreshDraw() or refreshPage() must be called after it to repaint dataTable. */ public void addRow(JavaScriptObject newRow) { JsDataTable.addRow(getElement(), newRow); } /** * Allows multiple removals, like removeRow(); removeRow(); ...; refreshDraw(); * <br> refreshDraw() or refreshPage() must be called after it to repaint dataTable. */ public void removeRow(int rowIndex) { JsDataTable.removeRow(getElement(), rowIndex); } /** * refreshDraw() or refreshPage() must be called after it to repaint dataTable. */ public boolean removeSelRows() { JsArrayInteger sel = JsDataTable.getSelRowIndexes(getElement()); if (sel.length() == 0) return false; int[] idxs = new int[sel.length()]; for (int i = 0; i < idxs.length; i++) idxs[i] = sel.get(i); Arrays.sort(idxs); for (int i = idxs.length - 1; i >= 0; i--) { removeRow(idxs[i]); } return true; } /** Invalidate all rows. refreshDraw() or refreshPage() must be called after it to repaint dataTable. */ public void rowsInvalidate() { JsDataTable.rowsInvalidate(getElement()); } /** Just a synonym for rowsInvalidate() */ public void invalidateRows() { rowsInvalidate(); } public void invalidateRow(int rowIndex) { JsDataTable.invalidateRow(getElement(), rowIndex); } /** @param cellOrRowElt - could be cellElt or rowElt */ public void invalidateRow(Element cellOrRowElt) { JsDataTable.invalidateRow(getElement(), cellOrRowElt); } /** @param cellElt - cell or one of its children */ public void invalidateCell(Element cellElt) { JsDataTable.invalidateCell(getElement(), cellElt); } public RowIdHelper getRowIdHelper() { return rowIdHelper; } /** Could be useful when we need selection support for server side mode, but server doesn't * provide DT_RowId in data for some reason. **/ public void setRowIdHelper(RowIdHelper rowIdHelper) { this.rowIdHelper = rowIdHelper; } public boolean isIndividualColSearches() { return individualColSearches; } /** You must define footer column titles to get this property working, i.e. for each non-empty * title search input widget will be auto-generated. **/ public void setIndividualColSearches(boolean individualColSearches) { this.individualColSearches = individualColSearches; } protected void initIndividualColSearches() { if (!enhanced || !individualColSearches || tFoot == null) return; JsDataTable.createFooterIndividualColumnSearches(getElement(), individualColSearchPrefix); } public RowData getRowData() { return rowData; } /** Custom data accessor, useful in case non-JavaScriptObject data structure, i.e. DTO/POJO. */ public void setRowData(RowData rowData) { this.rowData = rowData; } public CellRender getCellRender() { return cellRender; } /** * Custom widget can be inserted into any cell. */ public void setCellRender(CellRender cellRender) { this.cellRender = cellRender; } public void clearSearch() { JsDataTable.clearSearch(getElement()); } private void processVisible() { if (!enhanced) return; Element tableElt = getElement(); Element elt = tableElt.getParentElement(); while (elt != null) { if (JQMCommon.hasStyle(elt, WRAPPER)) { UIObject.setVisible(elt, visible); return; } elt = elt.getParentElement(); } } @Override public void setVisible(boolean value) { visible = value; processVisible(); } @Override public boolean isVisible() { return visible; } @Override protected void applyColClassNames(boolean add) { // nothing, we don't need super.applyColClassNames() to be called } }
Creates groups bands by specified column. <br> Could be called from afterDraw() event handler, see addDrawHandler() <br> You should define group styling in CSS like this: <br> .dataTable tr.group, .dataTable tr.group:hover { background-color: #ddd !important; } <br> OR you can directly process group row elements, which are returned by this method. @param additionalSorts - optional, will be sorted by colIdx column + additionalSorts @param settings - just taken/passed-through directly from afterDraw() @return - array of group rows, can be used for additional adjustments.
public static <S extends HasAttachHandlers> boolean fire(S source, GroupRowData data) { if (TYPE != null) { JQMDataTableGroupRowEvent event = new JQMDataTableGroupRowEvent(data); source.fireEvent(event); return event.isStopDfltClick(); } return false; }
Fires an {@link JQMDataTableGroupRowEvent} on all registered handlers in the handler source. @param <S> The handler source type @param source - the source of the handlers @return - true means default click processing must be suppressed/skipped.
public HasText addDivider(String text) { JQMListDivider d = new JQMListDivider(text); appendDivider(d); return d; }
Add a new divider with the given text and an automatically assigned id. @return the created divider which can be used to change the text dynamically. Changes to that instance write back to this list.
public JQMListItem addItem(String text, String url, ListItemImageKind imageKind, String imageUrl) { return addItem(items.size(), text, url, imageKind, imageUrl); }
This method is needed as good enough workaround for the following issue: <a href="https://github.com/sksamuel/jqm4gwt/issues/18">List item with icon/thumbnail</a> @param url - could be null in case of non-clickable/readonly item. Empty string means it will be clickable! @param imageUrl - could be null/empty initially, and then set later manually (but imageKind must not be NONE if you are planning to set images for this item).
public JQMListItem addItem(String text, JQMPage page) { return addItem(text, "#" + page.getId()); }
Adds a new {@link JQMListItem} that contains the given @param text as the heading element. <br> The list item is made linkable to the given page @param text the text to use as the content of the header element @param page the page to make the list item link to
public JQMListItem addItem(String text, String url) { JQMListItem item = new JQMListItem(text, url); addItem(items.size(), item); return item; }
Adds a new {@link JQMListItem} that contains the given @param text as the content. Note that if you want to navigate to an internal url (ie, another JQM Page) then you must prefix the url with a hash. IE, the hash is not added automatically. This allows you to navigate to external urls as well. <br> If you add an item after the page has been created then you must call .refresh() to update the layout. <br> The list item is made linkable to the @param url
public JQMList addItems(Collection<String> items) { for (String item : items) addItem(item); return this; }
Add a collection of read only items.
public boolean removeDivider(String text) { for (int k = 0; k < list.getWidgetCount(); k++) { Widget w = list.getWidget(k); if (isDivider(w) && w.getElement().getInnerText().equals(text)) { list.remove(k); items.remove(k); return true; } } return false; }
Remove the divider with the given text. This method will search all the dividers and remove the first divider found with the given text. @return true if a divider with the given text was found and removed, otherwise false.
public boolean removeDividerByTag(Object tag) { if (tag == null) return false; for (int k = 0; k < list.getWidgetCount(); k++) { Widget w = list.getWidget(k); if (isDivider(w) && tag.equals(((JQMListDivider) w).getTag())) { list.remove(k); items.remove(k); return true; } } return false; }
Remove the divider with the given tag. This method will search all the dividers and remove the first divider found with the given tag. @return true if a divider with the given tag was found and removed, otherwise false.
public JQMListDivider findDivider(String text) { for (int k = 0; k < list.getWidgetCount(); k++) { Widget w = list.getWidget(k); if (isDivider(w) && w.getElement().getInnerText().equals(text)) { return (JQMListDivider) w; } } return null; }
Find the divider with the given text. This method will search all the dividers and return the first divider found with the given text. @return the divider with the given text (if found, or null otherwise).
public JQMListDivider findDividerByTag(Object tag) { if (tag == null) return null; for (int k = 0; k < list.getWidgetCount(); k++) { Widget w = list.getWidget(k); if (isDivider(w) && tag.equals(((JQMListDivider) w).getTag())) { return (JQMListDivider) w; } } return null; }
Find the divider with the given tag. This method will search all the dividers and return the first divider found with the given tag. @return the divider with the given tag (if found, or null otherwise).
public int findInsertIdxByDivider(JQMListDivider d) { if (d == null) return -1; int i = findDividerIdx(d); if (i == -1) return -1; List<JQMListItem> lst = getItems(); int rslt = i + 1; while (rslt < lst.size()) { if (lst.get(rslt) == null) { // next divider return rslt; } rslt++; } return rslt; }
For given divider finds the index at which new item should be inserted to become a part of this divider's group. @return - proper index for new item insertion, or -1 in case of error
public int findItemOnlyIdx(JQMListItem item) { if (item == null) return -1; List<JQMListItem> items = getItems(); if (items == null) return -1; int i = items.indexOf(item); if (i == -1) return -1; int j = 0; for (JQMListItem k : items) { if (k == null) continue; if (k == item) return j; j++; } return -1; }
Ignores dividers, only counts JQMListItem bands. @return - logical index of this item among other items (can be useful for matching/sync between underlying data structure and UI in case of dynamic/multiple dividers and JQMListItem's click handlers).