Package com.storedobject.vaadin
Class View
java.lang.Object
com.storedobject.vaadin.View
- All Implemented Interfaces:
ClickHandler,ExecutableView,ValueChangeHandler,com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent<? extends com.vaadin.flow.component.Component>>,com.vaadin.flow.component.HasValue.ValueChangeListener,Serializable,Runnable,EventListener
- Direct Known Subclasses:
AbstractDataForm,CalendarViewer,ChatView,ConsumptionDashboard,Dashboard,GridMenu,ImageView,ImageViewer,ModuleMenu,ObjectBlockEditor,SOClient,SteppedView,SystemLogViewer,SystemTableDeployer,SystemUtility,TextView,ValueChart,VerifyOTP,Viewer,WrappedView
View represents an independent piece of information (typically a "data entry form" or some information dashboard)
to be displayed in the content area of the
Application. View implements Runnable interface. So,
it can be associated with a MenuItem. When a MenuItem is clicked, the Runnable.run() method
of the view is invoked, and we say the "view is executed". When a view is executed, its component (specified using
the setComponent(Component)) is displayed in the "content" area of the application.- Author:
- Syam
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.storedobject.vaadin.ClickHandler
ClickHandler.ModifiedClickEvent<C extends com.vaadin.flow.component.Component> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Abort this view.final booleanaborted()See if this view was aborted.com.vaadin.flow.shared.RegistrationaddClosedListener(ViewClosedListener listener) Add a "view closed listener".com.vaadin.flow.shared.RegistrationaddOpenedListener(ViewOpenedListener listener) Add a "view opened listener".voidclean()Close resources if any that are left opened.voidclose()Close this view.static ViewcreateCloseableView(com.vaadin.flow.component.Component component, String caption) Create aCloseableView.protected WindowcreateWindow(com.vaadin.flow.component.Component component) Create the window for embedding the component of this view.voidThis will be invoked by theApplicationjust before making the component of this view visible.final voidexecute()Execute this view.final voidExecute this view by locking another view (the locked view will not be selectable until this view is closed).protected voidOverride this if you want to do something before the View comes up on the screen.final booleanIs if this view is currently being displayed.voidfocus()Focus this view by finding the first focusable component.booleanfocus(com.vaadin.flow.component.Component component) Focus a component (or its focusable child component).booleanfocusAny(com.vaadin.flow.component.Component component) Focus a component (or its focusable child component).<A extends Application>
AGet the application that's tied to this View.Get the caption.final com.vaadin.flow.component.ComponentGet the "content" component of the view.com.vaadin.flow.component.ComponentGet the component that represents the "content" of the view.Get the object that created this view.final ViewGet the embedded view of this view.final ApplicationMenuItemGet the menu item for this view.final ApplicationMenuItemgetMenuItem(Runnable menuAction) Get the menu item for this view.getView(boolean create) Implementation ofExecutableView.getView(boolean).protected voidinitUI()This method is invoked when the view wants to determine its "content" to be displayed and nothing exists at that moment.final voidExecute this view and set its parent too.booleanCheck if this view is a full-screen view or not.booleanSee if this view is scrollable or not.booleanSee if this view is in a "window mode" (means its content is displayed as aDialog).booleanselect()Select this as the active view of the application.voidsetCaption(String caption) Set caption for this view.final voidsetComponent(com.vaadin.flow.component.Component component) Set the "content" of the view.voidsetCreatedBy(Object createdBy) Set the object that created this view.static voidsetDefaultPadding(int padding) Set the default padding to be used by all views.voidsetEmbeddedView(View embeddedView) Set view in which component of this view will be embedded.voidsetFirstFocus(com.vaadin.flow.component.Focusable<?> firstFocus) Set the first focusable component.voidsetFullScreen(boolean fullScreen) Set full-screen mode.voidsetScrollable(boolean scrollable) Specify the scrollable attribute of the view.voidsetWindowMode(boolean windowOn) Set the "window mode".booleanskipFirstFocus(com.vaadin.flow.component.Focusable<?> skipFocus) Check if this component to be skipped while traversing the component tree to find the first focusable component or not.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.storedobject.vaadin.ClickHandler
clicked, doubleClicked, onComponentEvent, rightClickedMethods inherited from interface com.storedobject.vaadin.ExecutableView
clearAlerts, clicked, createMenuItem, error, getMenuIconName, getView, isCloseable, isHomeView, log, log, message, returnedFrom, run, setClickable, speak, trackValueChange, tray, valueChanged, warningMethods inherited from interface com.storedobject.vaadin.ValueChangeHandler
valueChanged
-
Constructor Details
-
View
public View()Create a View with no caption. -
View
-
View
Create a view of the specific component with a caption- Parameters:
component- Component to displaycaption- Caption
-
-
Method Details
-
createCloseableView
public static View createCloseableView(com.vaadin.flow.component.Component component, String caption) Create aCloseableView. A helper method to create aViewthat is closeable.- Parameters:
component- Component of theViewcaption- Caption- Returns:
- A closable view.
-
setScrollable
public void setScrollable(boolean scrollable) Specify the scrollable attribute of the view. Scrollable views will scroll within the "content" area of the application.- Parameters:
scrollable- Scrollable
-
isScrollable
public boolean isScrollable()See if this view is scrollable or not.- Returns:
- True or false.
-
getContent
public com.vaadin.flow.component.Component getContent()Get the component that represents the "content" of the view. It may be different from the actual component displayed by the application. For example, if a view may be displayed as aDialogand in such cases, the "content" of theDialogis the "content" of the view.- Returns:
- The "content" as a component.
-
initUI
protected void initUI()This method is invoked when the view wants to determine its "content" to be displayed and nothing exists at that moment.setComponent(Component)may be called from within this method. -
setComponent
public final void setComponent(com.vaadin.flow.component.Component component) Set the "content" of the view.- Parameters:
component- Component to be displayed.
-
decorateComponent
public void decorateComponent()This will be invoked by theApplicationjust before making the component of this view visible. The default implementation does the following to the component:If it is a
Dialog, just returns without making any changes.Will set the size to 'full' by invoking
HasSize.setSizeFull()if it is an instance ofHasSizeso that it covers the entire content area.Padding will be set to 5px (unless changed via
setDefaultPadding(int)) and box-sizing to border-box. So, if you want to fill the component to the entire content area, you will have to override this method and set the padding to 0px.If the component is an instance of
Div, its "display" style will be set to "flex" and its "flex-direction" will be set to "column". -
getComponent
public final com.vaadin.flow.component.Component getComponent()Get the "content" component of the view.- Returns:
- Component
-
isFullScreen
public boolean isFullScreen()Description copied from interface:ExecutableViewCheck if this view is a full-screen view or not. A full-screen view takes up the whole screen.- Specified by:
isFullScreenin interfaceExecutableView- Returns:
- True if closeable. By default, a view takes up full-screen if it implements
FullScreenor its internal component (getComponent()) implementsFullScreen.
-
setFullScreen
public void setFullScreen(boolean fullScreen) Set full-screen mode. The mode is activated only when it is executed next time.- Parameters:
fullScreen- True/false.
-
setFirstFocus
public void setFirstFocus(com.vaadin.flow.component.Focusable<?> firstFocus) Set the first focusable component. (If this is not set, it will try to find out the first focusable component by traversing the component tree).- Parameters:
firstFocus- Component to be focused
-
skipFirstFocus
public boolean skipFirstFocus(com.vaadin.flow.component.Focusable<?> skipFocus) Check if this component to be skipped while traversing the component tree to find the first focusable component or not.- Parameters:
skipFocus- The focusable component- Returns:
- False if it should not be skipped (Default implementation returns false).
-
focus
public void focus()Focus this view by finding the first focusable component. The "first focus" is set, then it will be focused. -
focus
public boolean focus(com.vaadin.flow.component.Component component) Focus a component (or its focusable child component).- Parameters:
component- Component to focus- Returns:
- False if no focusable component exists (must be a field (
HasValue), must be "visible" and should not be "read only").
-
focusAny
public boolean focusAny(com.vaadin.flow.component.Component component) Focus a component (or its focusable child component).- Parameters:
component- Component to focus- Returns:
- False if no focusable component exists (must be "visible").
-
getMenuItem
Get the menu item for this view. This is the menu item displayed by theApplicationwhen the view is activated.- Returns:
- Menu item. May return
nullit the menu item is not yet created.
-
getMenuItem
Get the menu item for this view. This is the menu item displayed by theApplicationwhen the view is activated. It will create one if it is not yet created. This method is final butExecutableView.createMenuItem(Runnable)can be overridden for customizing it.- Specified by:
getMenuItemin interfaceExecutableView- Parameters:
menuAction- Action for the menu item to be created- Returns:
- Menu item.
-
setCaption
Set caption for this view. Caption is displayed as aMenuItemby theApplicationso that the view can be selected (only one view is displayed at a time) by clicking it.- Specified by:
setCaptionin interfaceExecutableView- Parameters:
caption- Caption
-
getCaption
Get the caption.- Specified by:
getCaptionin interfaceExecutableView- Returns:
- Caption.
-
isWindowMode
public boolean isWindowMode()See if this view is in a "window mode" (means its content is displayed as aDialog).- Returns:
- Window mode.
-
setWindowMode
public void setWindowMode(boolean windowOn) Set the "window mode". Content of the view will be wrapped in aDialogfor "window mode".- Parameters:
windowOn- Window mode
-
createWindow
Create the window for embedding the component of this view. Default implementation returns null.This method is invoked for "window" mode views only. See
setWindowMode(boolean).- Parameters:
component- Component to embed- Returns:
- A window with the given component added to it.
-
setEmbeddedView
Set view in which component of this view will be embedded. This is used when we want to make this view part of another view.- Parameters:
embeddedView- View in which this view is embedded.
-
getEmbeddedView
Get the embedded view of this view.- Returns:
- The view in which this view is embedded in or this itself if the embedded view is not set.
-
getView
Implementation ofExecutableView.getView(boolean).- Specified by:
getViewin interfaceExecutableView- Parameters:
create- Whether to create or not.- Returns:
- Always return this view unless embedded view is set. If embedded view is set,
then,
getEmbeddedView()is returned.
-
select
public boolean select()Select this as the active view of the application.- Returns:
- True if the view is set as the active view of the application.
-
execute
-
execute
Execute this view by locking another view (the locked view will not be selectable until this view is closed). The locked view acts as its "parent" and it will automatically get selected when this view closes.- Specified by:
executein interfaceExecutableView- Parameters:
lock- View to be locked.
-
invoke
Execute this view and set its parent too. (In this case, parent view is not locked). The parent view is automatically selected when this view closes.- Specified by:
invokein interfaceExecutableView- Parameters:
parent- Parent-view to be set
-
execute
Override this if you want to do something before the View comes up on the screen. Call super.execute(parent, doNotLock) to make the View appear on the screen. Parent view is automatically selected when this view closes.- Parameters:
parent- Parent-view to lockdoNotLock- True if parent should not be locked
-
getApplication
Get the application that's tied to this View.- Specified by:
getApplicationin interfaceExecutableView- Type Parameters:
A- Application type- Returns:
- The Application.
-
executing
public final boolean executing()Is if this view is currently being displayed.- Returns:
- True or false.
-
aborted
public final boolean aborted()See if this view was aborted.- Returns:
- True or false.
- See Also:
-
close
-
abort
public void abort()Abort this view. Default implementation sets an "abort flag" and closes the view.- Specified by:
abortin interfaceExecutableView
-
clean
public void clean()Close resources if any that are left opened. This method is invoked when the view is removed from theApplication. The default implementation does nothing.- Specified by:
cleanin interfaceExecutableView
-
addOpenedListener
Add a "view opened listener". TheViewOpenedListener.viewOpened(View)will be invoked whenever this view is executed.- Parameters:
listener- View opened listener- Returns:
- Registration that can be used for removing the listener.
-
addClosedListener
Add a "view closed listener". TheViewClosedListener.viewClosed(View)will be invoked whenever this view is closed/aborted.- Parameters:
listener- View closed listener- Returns:
- Registration that can be used for removing the listener.
-
setDefaultPadding
public static void setDefaultPadding(int padding) Set the default padding to be used by all views. (By default, it is 5 pixels.) SeedecorateComponent().- Parameters:
padding- Padding to be set.
-
getCreatedBy
Get the object that created this view.- Returns:
- The creator of this view if it was set via
setCreatedBy(Object). Otherwise, it will return self-reference.
-
setCreatedBy
Set the object that created this view.- Parameters:
createdBy- Creator.
-