
public class TWTSearchView extends AbstractEntityView
View for the twitter search form including the search field and autocomplete suggestions and recent searches.
The view model should conform to the TWTSearch
schema. This schema includes properties which are lists of results.
private static class ViewModel extends Entity {
private static final EntityType TYPE = new EntityType() {{
string(tags(query));
list(EntityList.class, tags(autocompleteKeywords));
list(EntityList.class, tags(autocompleteProfiles));
list(EntityList.class, tags(recentSearchKeywords));
list(EntityList.class, tags(recentSearchProfiles));
}};
{
setEntityType(TYPE);
set(query, "");
set(autocompleteKeywords, new EntityList());
set(autocompleteProfiles, new EntityList());
set(recentSearchKeywords, new EntityList());
set(recentSearchProfiles, new EntityList());
}
}
....
private static ViewModel createViewModel() {
ViewModel model = new ViewModel();
EntityList recentKeywords = model.getEntityList(recentSearchKeywords);
for (String kw : new String[]{"iOS", "Mobiledev", "Android", "Codename One", "UI design"}) {
recentKeywords.add(createKeyword(kw));
}
EntityList recentProfiles = model.getEntityList(recentSearchProfiles);
recentProfiles.add(createProfile("George", "@kostanza", "https://weblite.ca/cn1tests/radchat/george.jpg"));
recentProfiles.add(createProfile("Kramer", "@cosmo", "https://weblite.ca/cn1tests/radchat/kramer.jpg"));
recentProfiles.add(createProfile("Jerry", "@jerrys", null));
recentProfiles.add(createProfile("Elaine", "@benes1", null));
recentProfiles.add(createProfile("ReallyLong Name That should get clipped", "@longidshouldbeclipped", null));
return model;
}
SEARCH_ACTIONS
- Actions rendered to the right of the search field.
CLEAR_RECENT_SEARCHES
- Action triggered when the user presses the "Clear recent searches" button.
CANCEL_ACTION
- Action that can be registered to override the default cancel behaviour. Default behaviour is to go back to the previous form.
TWTSearchView
- UIID for the component.
TWTSearchViewRecentSearchesHeader
- UIID for the recent searches header.
TWTSearchViewRecentSearchesClearButton
- UIID for clear recent searches button.
TWTSearchViewRecentSearchesClearButtonCharged
- UIID for clear recent searches button when it is "charged". I.e. after user has clicked on it once. This gives the user an option to cancel.
TWTSearchViewTitleBar
- UIID for the top title bar.
TWTSearchAction
- UIID for the SEARCH_ACTIONS
buttons.
TWTSearchViewCancelAction
- UIID for the cancel button.
package com.codename1.demos.twitterui;
import com.codename1.twitterui.TwitterUIDemo.AppNavigationEvent;
import com.codename1.rad.controllers.Controller;
import com.codename1.rad.controllers.FormController;
import com.codename1.rad.models.Entity;
import com.codename1.rad.models.EntityList;
import com.codename1.rad.models.EntityType;
import com.codename1.rad.nodes.ViewNode;
import com.codename1.rad.schemas.Thing;
import com.codename1.twitterui.views.TWTSearchView;
import com.codename1.twitterui.schemas.TWTKeyword;
import com.codename1.twitterui.schemas.TWTSearch;
import com.codename1.ui.Form;
import com.codename1.ui.layouts.BorderLayout;
public class SearchFormController extends FormController implements TWTSearch, TWTKeyword {
public SearchFormController(Controller parent) {
super(parent);
Form form = new Form(new BorderLayout());
TWTSearchView view = new TWTSearchView(createViewModel(), new ViewNode());
form.getToolbar().hideToolbar();
form.getContentPane().add(BorderLayout.CENTER, view);
setView(form);
}
private static class ViewModel extends Entity {
private static final EntityType TYPE = new EntityType() {{
string(tags(query));
list(EntityList.class, tags(autocompleteKeywords));
list(EntityList.class, tags(autocompleteProfiles));
list(EntityList.class, tags(recentSearchKeywords));
list(EntityList.class, tags(recentSearchProfiles));
}};
{
setEntityType(TYPE);
set(query, "");
set(autocompleteKeywords, new EntityList());
set(autocompleteProfiles, new EntityList());
set(recentSearchKeywords, new EntityList());
set(recentSearchProfiles, new EntityList());
}
}
private static class KeywordModel extends Entity {
private static final EntityType TYPE = new EntityType() {{
string(tags(keyword));
}};
{
setEntityType(TYPE);
}
}
private static class ProfileModel extends Entity {
private static final EntityType TYPE = new EntityType() {{
string(tags(Thing.name));
string(tags(Thing.identifier));
string(tags(Thing.thumbnailUrl));
}};
{
setEntityType(TYPE);
}
}
private static ViewModel createViewModel() {
ViewModel model = new ViewModel();
EntityList recentKeywords = model.getEntityList(recentSearchKeywords);
for (String kw : new String[]{"iOS", "Mobiledev", "Android", "Codename One", "UI design"}) {
recentKeywords.add(createKeyword(kw));
}
EntityList recentProfiles = model.getEntityList(recentSearchProfiles);
recentProfiles.add(createProfile("George", "@kostanza", "https://weblite.ca/cn1tests/radchat/george.jpg"));
recentProfiles.add(createProfile("Kramer", "@cosmo", "https://weblite.ca/cn1tests/radchat/kramer.jpg"));
recentProfiles.add(createProfile("Jerry", "@jerrys", null));
recentProfiles.add(createProfile("Elaine", "@benes1", null));
recentProfiles.add(createProfile("ReallyLong Name That should get clipped", "@longidshouldbeclipped", null));
return model;
}
private static KeywordModel createKeyword(String kw) {
KeywordModel out = new KeywordModel();
out.setText(keyword, kw);
return out;
}
private static ProfileModel createProfile(String name, String id, String icon) {
ProfileModel out = new ProfileModel();
out.setText(Thing.name, name);
out.setText(Thing.identifier, id);
out.setText(Thing.thumbnailUrl, icon);
return out;
}
@Override
public void initController() {
super.initController();
dispatchEvent(new AppNavigationEvent(this, AppNavigationViewModel.NavSection.Search));
}
}
Modifier and Type | Field and Description |
---|---|
static ActionNode.Category |
CANCEL_ACTION
A cancel action.
|
static ActionNode.Category |
CLEAR_RECENT_SEARCHES
Action to handle "clear recent" searches button clicks.
|
static ActionNode.Category |
SEARCH_ACTIONS
Actions to be rendered to the right of the search field.
|
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR
Constructor and Description |
---|
TWTSearchView(Entity entity,
ViewNode node) |
Modifier and Type | Method and Description |
---|---|
void |
commit() |
protected void |
deinitialize() |
Node |
getViewNode() |
protected void |
initComponent() |
void |
update() |
activate, addBindListener, addUnbindListener, addUpdateListener, bind, bindImpl, findProperty, getContext, getEntity, getParam, isBindOnPropertyChangeEvents, removeUpdateListener, setBindOnPropertyChangeEvents, setEntity, unbind, unbindImpl
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, iterator, iterator, keyPressed, keyReleased, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndices
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, parsePreferredSize, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public static final ActionNode.Category SEARCH_ACTIONS
Actions to be rendered to the right of the search field.
public static final ActionNode.Category CLEAR_RECENT_SEARCHES
Action to handle "clear recent" searches button clicks.
public static final ActionNode.Category CANCEL_ACTION
A cancel action. Register this action to override the behaviour of the cancel button. IF this is not registered, then the default behaviour will be used, which will be to navigate back to the previous form.
public void update()
public void commit()
public Node getViewNode()
getViewNode
in interface EntityView
getViewNode
in class AbstractEntityView
protected void initComponent()
initComponent
in class AbstractEntityView
protected void deinitialize()
deinitialize
in class AbstractEntityView
Copyright © 2021. All Rights Reserved.