idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
19,200
protected void paintComponent ( final RenderContext renderContext ) { if ( renderContext instanceof WebXmlRenderContext ) { PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; writer . println ( getMessage ( ) ) ; if ( developerFriendly ) { writer . println ( "<pre style=\"background: lightgrey\">" ) ; writer . println ( "Additional details for the developer:" ) ; writer . println ( ) ; error . printStackTrace ( writer ) ; writer . println ( "</pre>" ) ; } } }
Renders this FatalErrorPage .
19,201
public void setText ( final String text , final Serializable ... args ) { Serializable currText = getComponentModel ( ) . text ; Serializable textToBeSet = I18nUtilities . asMessage ( text , args ) ; if ( ! Objects . equals ( textToBeSet , currText ) ) { getOrCreateComponentModel ( ) . text = textToBeSet ; } }
Sets the label s text .
19,202
public void setHint ( final String hint , final Serializable ... args ) { Serializable currHint = getComponentModel ( ) . hint ; Serializable hintToBeSet = I18nUtilities . asMessage ( hint , args ) ; if ( ! Objects . equals ( hintToBeSet , currHint ) ) { getOrCreateComponentModel ( ) . hint = hintToBeSet ; } }
Sets the label hint text which can be used to provide additional information to the user .
19,203
public void setForComponent ( final WComponent forComponent ) { getOrCreateComponentModel ( ) . forComponent = forComponent ; if ( forComponent instanceof AbstractWComponent ) { ( ( AbstractWComponent ) forComponent ) . setLabel ( this ) ; } }
Sets the component that this label is associated with .
19,204
protected void preparePaintComponent ( final Request request ) { if ( ! isInitialised ( ) ) { repeat . setData ( getNames ( ) ) ; setInitialised ( true ) ; } }
Initialise the WRepeater data .
19,205
private void setupUI ( final String labelText ) { WButton dupBtn = new WButton ( "Duplicate" ) ; dupBtn . setAction ( new DuplicateAction ( ) ) ; WButton clrBtn = new WButton ( "Clear" ) ; clrBtn . setAction ( new ClearAction ( ) ) ; add ( new WLabel ( labelText , textFld ) ) ; add ( textFld ) ; add ( dupBtn ) ; add ( clrBtn ) ; add ( new WAjaxControl ( dupBtn , this ) ) ; add ( new WAjaxControl ( clrBtn , this ) ) ; }
Add the controls to the UI .
19,206
private void addRecentExample ( final String text , final ExampleData data , final boolean select ) { WMenuItem item = new WMenuItem ( text , new SelectExampleAction ( ) ) ; item . setCancel ( true ) ; menu . add ( item ) ; item . setActionObject ( data ) ; if ( select ) { menu . setSelectedMenuItem ( item ) ; } }
Adds an example to the recent subMenu .
19,207
private ExampleData getMatch ( final WComponent node , final String name , final boolean partial ) { if ( node instanceof WMenuItem ) { ExampleData data = ( ExampleData ) ( ( WMenuItem ) node ) . getActionObject ( ) ; Class < ? extends WComponent > clazz = data . getExampleClass ( ) ; if ( clazz . getName ( ) . equals ( name ) || data . getExampleName ( ) . equals ( name ) || ( partial && clazz . getSimpleName ( ) . toLowerCase ( ) . contains ( name . toLowerCase ( ) ) ) || ( partial && data . getExampleName ( ) . toLowerCase ( ) . contains ( name . toLowerCase ( ) ) ) ) { return data ; } } else if ( node instanceof Container ) { for ( int i = 0 ; i < ( ( Container ) node ) . getChildCount ( ) ; i ++ ) { ExampleData result = getMatch ( ( ( Container ) node ) . getChildAt ( i ) , name , partial ) ; if ( result != null ) { return result ; } } } return null ; }
Recursively searches the menu for a match to a WComponent with the given name .
19,208
private void loadRecentList ( ) { recent . clear ( ) ; File file = new File ( RECENT_FILE_NAME ) ; if ( file . exists ( ) ) { try { InputStream inputStream = new BufferedInputStream ( new FileInputStream ( file ) ) ; XMLDecoder decoder = new XMLDecoder ( inputStream ) ; List result = ( List ) decoder . readObject ( ) ; decoder . close ( ) ; for ( Object obj : result ) { if ( obj instanceof ExampleData ) { recent . add ( ( ExampleData ) obj ) ; } } } catch ( IOException ex ) { LogFactory . getLog ( getClass ( ) ) . error ( "Unable to load recent list" , ex ) ; } } }
Reads the list of recently selected examples from a file on the file system .
19,209
private void storeRecentList ( ) { synchronized ( recent ) { try { OutputStream out = new BufferedOutputStream ( new FileOutputStream ( RECENT_FILE_NAME ) ) ; XMLEncoder encoder = new XMLEncoder ( out ) ; encoder . writeObject ( recent ) ; encoder . close ( ) ; } catch ( IOException ex ) { LogFactory . getLog ( getClass ( ) ) . error ( "Unable to save recent list" , ex ) ; } } }
Writes the list of recent selections to a file on the file system .
19,210
public void addToRecent ( final ExampleData example ) { synchronized ( recent ) { recent . remove ( example ) ; recent . add ( 0 , example ) ; while ( recent . size ( ) > MAX_RECENT_ITEMS ) { recent . remove ( MAX_RECENT_ITEMS ) ; } storeRecentList ( ) ; setInitialised ( false ) ; } }
Adds an example to the list of recently accessed examples . The list of recently examples will be persisted to the file system .
19,211
private void updateRecentMenu ( ) { menu . removeAllMenuItems ( ) ; int index = 1 ; boolean first = true ; for ( Iterator < ExampleData > i = recent . iterator ( ) ; i . hasNext ( ) ; ) { ExampleData data = i . next ( ) ; try { StringBuilder builder = new StringBuilder ( Integer . toString ( index ++ ) ) . append ( ". " ) ; if ( data . getExampleGroupName ( ) != null ) { builder . append ( data . getExampleGroupName ( ) ) . append ( " - " ) ; } builder . append ( data . getExampleName ( ) ) ; addRecentExample ( builder . toString ( ) , data , first ) ; first = false ; } catch ( Exception e ) { i . remove ( ) ; LogFactory . getLog ( getClass ( ) ) . error ( "Unable to read recent class: " + data . getExampleName ( ) ) ; } } }
Updates the entries in the Recent sub - menu .
19,212
public void setContent ( final WComponent content ) { WComponent oldContent = getContent ( ) ; if ( oldContent != null ) { remove ( oldContent ) ; } if ( content != null ) { add ( content ) ; } }
Sets the tab content .
19,213
protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; WComponent content = getContent ( ) ; if ( content != null ) { switch ( getMode ( ) ) { case EAGER : { content . setVisible ( true ) ; AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; break ; } case LAZY : { content . setVisible ( isOpen ( ) ) ; if ( ! isOpen ( ) ) { AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; } break ; } case DYNAMIC : { content . setVisible ( isOpen ( ) ) ; AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; break ; } case SERVER : { content . setVisible ( isOpen ( ) ) ; break ; } case CLIENT : { content . setVisible ( true ) ; break ; } default : break ; } } }
Override preparePaintComponent in order to correct the visibility of the tab s content before it is rendered .
19,214
public SpaceCreateResponse createSpace ( SpaceCreate data ) { return getResourceFactory ( ) . getApiResource ( "/space/" ) . entity ( data , MediaType . APPLICATION_JSON_TYPE ) . post ( SpaceCreateResponse . class ) ; }
Add a new space to an organization .
19,215
public void updateSpace ( int spaceId , SpaceUpdate data ) { getResourceFactory ( ) . getApiResource ( "/space/" + spaceId ) . entity ( data , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates the space with the given id
19,216
public SpaceWithOrganization getSpaceByURL ( String url ) { return getResourceFactory ( ) . getApiResource ( "/space/url" ) . queryParam ( "url" , url ) . get ( SpaceWithOrganization . class ) ; }
Returns the space and organization with the given full URL .
19,217
public SpaceMember getSpaceMembership ( int spaceId , int userId ) { return getResourceFactory ( ) . getApiResource ( "/space/" + spaceId + "/member/" + userId ) . get ( SpaceMember . class ) ; }
Used to get the details of an active users membership of a space .
19,218
public void updateSpaceMembership ( int spaceId , int userId , Role role ) { getResourceFactory ( ) . getApiResource ( "/space/" + spaceId + "/member/" + userId ) . entity ( new SpaceMemberUpdate ( role ) , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates a space membership with another role
19,219
public List < SpaceMember > getActiveMembers ( int spaceId ) { return getResourceFactory ( ) . getApiResource ( "/space/" + spaceId + "/member/" ) . get ( new GenericType < List < SpaceMember > > ( ) { } ) ; }
Returns the active members of the given space .
19,220
public List < SpaceMember > getEndedMembers ( int spaceId ) { return getResourceFactory ( ) . getApiResource ( "/space/" + spaceId + "/member/ended/" ) . get ( new GenericType < List < SpaceMember > > ( ) { } ) ; }
Returns a list of the members that have been removed from the space .
19,221
public List < SpaceWithOrganization > getTopSpaces ( Integer limit ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/space/top/" ) ; if ( limit != null ) { resource = resource . queryParam ( "limit" , limit . toString ( ) ) ; } return resource . get ( new GenericType < List < SpaceWithOrganization > > ( ) { } ) ; }
Returns the top spaces for the user
19,222
public static void registerList ( final String key , final Request request ) { request . setSessionAttribute ( DATA_LIST_UIC_SESSION_KEY , UIContextHolder . getCurrentPrimaryUIContext ( ) ) ; }
Registers a data list with the servlet .
19,223
public static UIContext getContext ( final String key , final Request request ) { return ( UIContext ) request . getSessionAttribute ( DATA_LIST_UIC_SESSION_KEY ) ; }
Retrieves the UIContext for the given data list .
19,224
public static List < ComponentWithContext > collateVisibles ( final WComponent comp ) { final List < ComponentWithContext > list = new ArrayList < > ( ) ; WComponentTreeVisitor visitor = new WComponentTreeVisitor ( ) { public VisitorResult visit ( final WComponent comp ) { if ( comp . isVisible ( ) ) { list . add ( new ComponentWithContext ( comp , UIContextHolder . getCurrent ( ) ) ) ; } return VisitorResult . CONTINUE ; } } ; traverseVisible ( comp , visitor ) ; return list ; }
Obtains a list of components which are visible in the given tree . Repeated components will be returned multiple times one for each row which they are visible in .
19,225
public static WComponent getRoot ( final UIContext uic , final WComponent comp ) { UIContextHolder . pushContext ( uic ) ; try { return WebUtilities . getTop ( comp ) ; } finally { UIContextHolder . popContext ( ) ; } }
Retrieves the root component of a WComponent hierarchy .
19,226
public static List < ComponentWithContext > findComponentsByClass ( final WComponent root , final String className , final boolean includeRoot , final boolean visibleOnly ) { FindComponentsByClassVisitor visitor = new FindComponentsByClassVisitor ( root , className , includeRoot ) ; doTraverse ( root , visibleOnly , visitor ) ; return visitor . getResult ( ) == null ? Collections . EMPTY_LIST : visitor . getResult ( ) ; }
Search for components implementing a particular class name .
19,227
public static WComponent getComponentWithId ( final WComponent root , final String id , final boolean visibleOnly ) { ComponentWithContext comp = getComponentWithContextForId ( root , id , visibleOnly ) ; return comp == null ? null : comp . getComponent ( ) ; }
Retrieves the component with the given Id .
19,228
public static UIContext getClosestContextForId ( final WComponent root , final String id , final boolean visibleOnly ) { FindComponentByIdVisitor visitor = new FindComponentByIdVisitor ( id ) { public VisitorResult visit ( final WComponent comp ) { VisitorResult result = super . visit ( comp ) ; if ( result == VisitorResult . CONTINUE ) { setResult ( new ComponentWithContext ( comp , UIContextHolder . getCurrent ( ) ) ) ; } return result ; } } ; doTraverse ( root , visibleOnly , visitor ) ; return visitor . getResult ( ) == null ? null : visitor . getResult ( ) . getContext ( ) ; }
Retrieves the closest context for the component with the given Id .
19,229
private static VisitorResult doTraverse ( final WComponent node , final boolean visibleOnly , final WComponentTreeVisitor visitor ) { if ( visibleOnly ) { if ( node instanceof WInvisibleContainer ) { WComponent parent = node . getParent ( ) ; if ( parent instanceof WCardManager ) { WComponent visible = ( ( WCardManager ) node . getParent ( ) ) . getVisible ( ) ; if ( visible == null ) { return VisitorResult . ABORT_BRANCH ; } return doTraverse ( visible , visibleOnly , visitor ) ; } else if ( parent instanceof WWindow ) { if ( ( ( WWindow ) parent ) . getState ( ) != WWindow . ACTIVE_STATE ) { return VisitorResult . ABORT_BRANCH ; } } } else if ( node instanceof WRepeatRoot ) { } else if ( ! node . isVisible ( ) ) { return VisitorResult . ABORT_BRANCH ; } } VisitorResult result = visitor . visit ( node ) ; switch ( result ) { case ABORT_BRANCH : return VisitorResult . CONTINUE ; case CONTINUE : if ( node instanceof WRepeater ) { WRepeater repeater = ( WRepeater ) node ; List < UIContext > rowContextList = repeater . getRowContexts ( ) ; WRepeatRoot repeatRoot = ( WRepeatRoot ) repeater . getRepeatedComponent ( ) . getParent ( ) ; for ( UIContext rowContext : rowContextList ) { UIContextHolder . pushContext ( rowContext ) ; try { result = doTraverse ( repeatRoot , visibleOnly , visitor ) ; } finally { UIContextHolder . popContext ( ) ; } if ( VisitorResult . ABORT . equals ( result ) ) { return VisitorResult . ABORT ; } } } else if ( node instanceof Container ) { Container container = ( Container ) node ; for ( int i = 0 ; i < container . getChildCount ( ) ; i ++ ) { result = doTraverse ( container . getChildAt ( i ) , visibleOnly , visitor ) ; if ( VisitorResult . ABORT . equals ( result ) ) { return VisitorResult . ABORT ; } } } return VisitorResult . CONTINUE ; default : return VisitorResult . ABORT ; } }
Internal implementation of tree traversal method .
19,230
public void setText ( final String text , final Serializable ... args ) { getOrCreateComponentModel ( ) . text = I18nUtilities . asMessage ( text , args ) ; }
Sets the text displayed on the link .
19,231
public void handleRequest ( final Request request ) { AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; boolean pressed = ( operation != null && getId ( ) . equals ( operation . getTriggerId ( ) ) ) ; if ( isDisabled ( ) && pressed ) { LOG . warn ( "A disabled link has been triggered. " + getText ( ) + ". " + getId ( ) ) ; return ; } final Action action = getAction ( ) ; if ( pressed && action != null ) { final ActionEvent event = new ActionEvent ( this , getActionCommand ( ) , getActionObject ( ) ) ; Runnable later = new Runnable ( ) { public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; } }
Override handleRequest in order to perform processing for this component . This implementation checks whether the link has been pressed via the current ajax operation .
19,232
protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; final Action action = getAction ( ) ; final AjaxTarget [ ] actionTargets = getActionTargets ( ) ; if ( action != null && uic . getUI ( ) != null ) { if ( actionTargets != null && actionTargets . length > 0 ) { List < String > targetIds = new ArrayList < > ( ) ; for ( AjaxTarget target : actionTargets ) { targetIds . add ( target . getId ( ) ) ; } AjaxHelper . registerComponents ( targetIds , getId ( ) ) ; } } }
Override preparePaintComponent to register an AJAX operation if this link has an action .
19,233
public void setImage ( final Image image ) { LinkModel model = getOrCreateComponentModel ( ) ; model . image = image ; model . imageUrl = null ; }
Sets the image to display on the link .
19,234
public void setImageUrl ( final String imageUrl ) { LinkModel model = getOrCreateComponentModel ( ) ; model . imageUrl = imageUrl ; model . image = null ; }
Sets the URL of the image to display on the link .
19,235
public void addFile ( final FileWidgetUpload file ) { List < FileWidgetUpload > files = ( List < FileWidgetUpload > ) getData ( ) ; if ( files == null ) { files = new ArrayList < > ( ) ; setData ( files ) ; } files . add ( file ) ; MemoryUtil . checkSize ( files . size ( ) , this . getClass ( ) . getSimpleName ( ) ) ; }
Add a file item to this widget .
19,236
public void removeFile ( final FileWidgetUpload file ) { List < FileWidgetUpload > files = ( List < FileWidgetUpload > ) getData ( ) ; if ( files != null ) { files . remove ( file ) ; if ( files . isEmpty ( ) ) { setData ( null ) ; } } }
Remove the file .
19,237
private boolean isValid ( final String fileType ) { boolean result = false ; if ( fileType != null && fileType . length ( ) > 1 ) { if ( fileType . startsWith ( "." ) ) { result = true ; } else if ( fileType . length ( ) > 2 && fileType . indexOf ( '/' ) > 0 ) { result = true ; } } return result ; }
Check that the file type SEEMS to be legit .
19,238
public List < String > getFileTypes ( ) { Set < String > fileTypes = getComponentModel ( ) . fileTypes ; List < String > result ; if ( fileTypes == null || fileTypes . isEmpty ( ) ) { return Collections . emptyList ( ) ; } result = new ArrayList < > ( fileTypes ) ; return result ; }
Returns a list of file types accepted by the file input .
19,239
public void setColumns ( final Integer cols ) { if ( cols != null && cols < 0 ) { throw new IllegalArgumentException ( "Must have zero or more columns" ) ; } Integer currColumns = getColumns ( ) ; if ( ! Objects . equals ( cols , currColumns ) ) { getOrCreateComponentModel ( ) . cols = cols ; } }
Sets the layout of uploaded files to be a certain number of columns . Null uses the theme default .
19,240
protected void doHandleFileAjaxActionRequest ( final Request request ) { if ( isDisabled ( ) ) { throw new SystemException ( "File widget is disabled." ) ; } String fileId = request . getParameter ( FILE_UPLOAD_ID_KEY ) ; if ( fileId == null ) { throw new SystemException ( "No file id provided for ajax action." ) ; } FileWidgetUpload file = getFile ( fileId ) ; if ( file == null ) { throw new SystemException ( "Invalid file id [" + fileId + "]." ) ; } final Action action = getFileAjaxAction ( ) ; if ( action == null ) { throw new SystemException ( "No action set for file ajax action request." ) ; } final ActionEvent event = new ActionEvent ( this , "fileajax" , fileId ) ; Runnable later = new Runnable ( ) { public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; }
Handle a file action AJAX request .
19,241
protected void doHandleTargetedRequest ( final Request request ) { String fileId = request . getParameter ( FILE_UPLOAD_ID_KEY ) ; if ( fileId == null ) { throw new SystemException ( "No file id provided for content request." ) ; } FileWidgetUpload file = getFile ( fileId ) ; if ( file == null ) { throw new SystemException ( "Invalid file id [" + fileId + "]." ) ; } boolean thumbNail = request . getParameter ( FILE_UPLOAD_THUMB_NAIL_KEY ) != null ; if ( thumbNail ) { doHandleThumbnailRequest ( file ) ; } else { doHandleFileContentRequest ( file ) ; } }
Handle a targeted request . Can be a file upload thumbnail request or file content request .
19,242
protected void doHandleUploadRequest ( final Request request ) { if ( isDisabled ( ) || isReadOnly ( ) ) { throw new SystemException ( "File widget cannot be updated." ) ; } if ( ! "POST" . equals ( request . getMethod ( ) ) ) { throw new SystemException ( "File widget cannot be updated by " + request . getMethod ( ) + "." ) ; } FileItem [ ] items = request . getFileItems ( getId ( ) ) ; if ( items . length > 1 ) { throw new SystemException ( "More than one file item received on the request." ) ; } String fileId = request . getParameter ( FILE_UPLOAD_MULTI_PART_ID_KEY ) ; if ( fileId == null ) { throw new SystemException ( "No file id provided for file upload." ) ; } FileItemWrap wrap = new FileItemWrap ( items [ 0 ] ) ; if ( hasFileTypes ( ) && ! FileUtil . validateFileType ( wrap , getFileTypes ( ) ) ) { String invalidMessage = FileUtil . getInvalidFileTypeMessage ( getFileTypes ( ) ) ; throw new SystemException ( invalidMessage ) ; } if ( hasMaxFileSize ( ) && ! FileUtil . validateFileSize ( wrap , getMaxFileSize ( ) ) ) { String invalidMessage = FileUtil . getInvalidFileSizeMessage ( getMaxFileSize ( ) ) ; throw new SystemException ( invalidMessage ) ; } FileWidgetUpload file = new FileWidgetUpload ( fileId , wrap ) ; addFile ( file ) ; setFileUploadRequestId ( fileId ) ; setNewUpload ( true ) ; }
The request is a targeted file upload request . Upload the file and respond with the file information .
19,243
protected void doHandleThumbnailRequest ( final FileWidgetUpload file ) { if ( file . getThumbnail ( ) == null ) { Image thumbnail = createThumbNail ( file . getFile ( ) ) ; file . setThumbnail ( thumbnail ) ; } ContentEscape escape = new ContentEscape ( file . getThumbnail ( ) ) ; throw escape ; }
Handle the thumb nail request .
19,244
public String getFileUrl ( final String fileId ) { FileWidgetUpload file = getFile ( fileId ) ; if ( file == null ) { return null ; } Environment env = getEnvironment ( ) ; Map < String , String > parameters = env . getHiddenParameters ( ) ; parameters . put ( Environment . TARGET_ID , getTargetId ( ) ) ; if ( Util . empty ( file . getFileCacheKey ( ) ) ) { String random = WebUtilities . generateRandom ( ) ; parameters . put ( Environment . UNIQUE_RANDOM_PARAM , random ) ; } else { parameters . remove ( Environment . STEP_VARIABLE ) ; parameters . remove ( Environment . SESSION_TOKEN_VARIABLE ) ; parameters . put ( Environment . CONTENT_CACHE_KEY , file . getFileCacheKey ( ) ) ; } parameters . put ( FILE_UPLOAD_ID_KEY , fileId ) ; String url = env . getWServletPath ( ) ; return WebUtilities . getPath ( url , parameters , true ) ; }
Retrieves a URL for the uploaded file content .
19,245
public String getFileThumbnailUrl ( final String fileId ) { FileWidgetUpload file = getFile ( fileId ) ; if ( file == null ) { return null ; } Image thumbnail = file . getThumbnail ( ) ; if ( thumbnail instanceof InternalResource ) { return ( ( InternalResource ) thumbnail ) . getTargetUrl ( ) ; } Environment env = getEnvironment ( ) ; Map < String , String > parameters = env . getHiddenParameters ( ) ; parameters . put ( Environment . TARGET_ID , getTargetId ( ) ) ; if ( Util . empty ( file . getThumbnailCacheKey ( ) ) ) { String random = WebUtilities . generateRandom ( ) ; parameters . put ( Environment . UNIQUE_RANDOM_PARAM , random ) ; } else { parameters . remove ( Environment . STEP_VARIABLE ) ; parameters . remove ( Environment . SESSION_TOKEN_VARIABLE ) ; parameters . put ( Environment . CONTENT_CACHE_KEY , file . getThumbnailCacheKey ( ) ) ; } parameters . put ( FILE_UPLOAD_ID_KEY , fileId ) ; parameters . put ( FILE_UPLOAD_THUMB_NAIL_KEY , "Y" ) ; String url = env . getWServletPath ( ) ; return WebUtilities . getPath ( url , parameters , true ) ; }
Retrieves a URL for the thumbnail of an uploaded file .
19,246
public void serviceRequest ( final Request request ) { UIContext uic = UIContextHolder . getCurrent ( ) ; uic . setFocussed ( null , null ) ; uic . setFocusRequired ( true ) ; super . serviceRequest ( request ) ; }
Override serviceRequest in order to perform processing specific to this interceptor .
19,247
public void paint ( final RenderContext renderContext ) { getBackingComponent ( ) . paint ( renderContext ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; if ( uic . isFocusRequired ( ) ) { boolean sticky = ConfigurationProperties . getStickyFocus ( ) ; if ( ! sticky ) { uic . setFocussed ( null , null ) ; uic . setFocusRequired ( false ) ; } } }
Override paint in order to perform processing specific to this interceptor .
19,248
private void applyEnableAction ( final WComponent target , final boolean enabled ) { if ( target instanceof Disableable ) { target . setValidate ( enabled ) ; ( ( Disableable ) target ) . setDisabled ( ! enabled ) ; } else if ( target instanceof Container ) { Container cont = ( Container ) target ; final int size = cont . getChildCount ( ) ; for ( int i = 0 ; i < size ; i ++ ) { WComponent child = cont . getChildAt ( i ) ; applyEnableAction ( child , enabled ) ; } } }
Apply the enable action against the target and its children .
19,249
private void startLoad ( ) { tableLayout . setVisible ( true ) ; List < PersonBean > beans = ExampleDataUtil . createExampleData ( numRows . getNumber ( ) . intValue ( ) , numDocs . getNumber ( ) . intValue ( ) ) ; if ( isLoadWTable ( ) ) { table . setBean ( beans ) ; } if ( isLoadWDataTable ( ) ) { TableTreeNode tree = createTree ( beans ) ; datatable . setDataModel ( new SimpleBeanTreeTableDataModel ( new String [ ] { "firstName" , "lastName" , "dateOfBirth" } , tree ) ) ; } if ( isLoadWTable ( ) ) { ajax2 . setVisible ( true ) ; tableShim . setVisible ( isLoadWTable ( ) ) ; } else { ajax4 . setVisible ( true ) ; dataShim . setVisible ( isLoadWDataTable ( ) ) ; } }
Start load .
19,250
private void applyMandatoryAction ( final WComponent target , final boolean mandatory ) { if ( target instanceof Mandatable ) { ( ( Mandatable ) target ) . setMandatory ( mandatory ) ; } else if ( target instanceof Container ) { Container cont = ( Container ) target ; final int size = cont . getChildCount ( ) ; for ( int i = 0 ; i < size ; i ++ ) { WComponent child = cont . getChildAt ( i ) ; applyMandatoryAction ( child , mandatory ) ; } } }
Apply the mandatory action against the target and its children .
19,251
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WShuffler shuffler = ( WShuffler ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = shuffler . isReadOnly ( ) ; xml . appendTagOpen ( "ui:shuffler" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , shuffler . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendOptionalAttribute ( "disabled" , shuffler . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , shuffler . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , shuffler . getAccessibleText ( ) ) ; int rows = shuffler . getRows ( ) ; xml . appendOptionalAttribute ( "rows" , rows > 0 , rows ) ; } xml . appendClose ( ) ; List < ? > options = shuffler . getOptions ( ) ; if ( options != null && ! options . isEmpty ( ) ) { for ( int i = 0 ; i < options . size ( ) ; i ++ ) { String stringOption = String . valueOf ( options . get ( i ) ) ; xml . appendTagOpen ( "ui:option" ) ; xml . appendAttribute ( "value" , stringOption ) ; xml . appendClose ( ) ; xml . appendEscaped ( stringOption ) ; xml . appendEndTag ( "ui:option" ) ; } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( shuffler , renderContext ) ; } xml . appendEndTag ( "ui:shuffler" ) ; }
Paints the given WShuffler .
19,252
private String deriveId ( final String idName ) { NamingContextable parent = WebUtilities . getParentNamingContext ( this ) ; if ( parent == null ) { return idName ; } String prefix = parent . getNamingContextId ( ) ; if ( prefix . length ( ) == 0 ) { return idName ; } StringBuffer nameBuf = new StringBuffer ( prefix . length ( ) + idName . length ( ) + 1 ) ; nameBuf . append ( prefix ) ; nameBuf . append ( ID_CONTEXT_SEPERATOR ) ; nameBuf . append ( idName ) ; return nameBuf . toString ( ) ; }
Derive the full id from its naming context .
19,253
void registerInContext ( ) { if ( ! ConfigurationProperties . getCheckDuplicateIds ( ) ) { return ; } if ( getIdName ( ) != null ) { NamingContextable context = WebUtilities . getParentNamingContext ( this ) ; if ( context == null ) { if ( WebUtilities . isActiveNamingContext ( this ) ) { this . registerId ( this ) ; } else { LOG . warn ( "Component with id name [" + getIdName ( ) + "] is not in a naming context and cannot be verified for duplicate id." ) ; } return ; } ( ( AbstractWComponent ) context ) . registerId ( this ) ; } }
Register this component s ID in its naming context .
19,254
protected void invokeLaters ( ) { if ( getParent ( ) == null ) { UIContext uic = UIContextHolder . getCurrent ( ) ; if ( uic != null ) { uic . doInvokeLaters ( ) ; } } }
The framework calls this method at the end of the serviceRequest method . The default implementation is that only a root wcomponent actually runs them .
19,255
protected void paintComponent ( final RenderContext renderContext ) { Renderer renderer = UIManager . getRenderer ( this , renderContext ) ; if ( getTemplate ( ) != null || getTemplateMarkUp ( ) != null ) { Renderer templateRenderer = UIManager . getTemplateRenderer ( renderContext ) ; templateRenderer . render ( this , renderContext ) ; } else if ( renderer == null ) { List < WComponent > children = getComponentModel ( ) . getChildren ( ) ; if ( children != null ) { final int size = children . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { children . get ( i ) . paint ( renderContext ) ; } } } else { renderer . render ( this , renderContext ) ; } }
This is where most of the painting work is normally done . If a layout has been supplied either directly or by supplying a velocity template then painting is delegated to the layout manager . If there is no layout the default behaviour is to paint the child components in sequence .
19,256
protected Diagnostic createErrorDiagnostic ( final WComponent source , final String message , final Serializable ... args ) { return new DiagnosticImpl ( Diagnostic . ERROR , source , message , args ) ; }
Create and return an error diagnostic associated to the given error source .
19,257
protected void setFlag ( final int mask , final boolean flag ) { if ( flag != isFlagSet ( mask ) ) { ComponentModel model = getOrCreateComponentModel ( ) ; model . setFlags ( switchFlag ( model . getFlags ( ) , mask , flag ) ) ; } }
Sets or clears one or more component flags in the component model for the given context ..
19,258
private static int switchFlag ( final int flags , final int mask , final boolean value ) { int newFlags = value ? flags | mask : flags & ~ mask ; return newFlags ; }
A utility method to set or clear one or more bits in the given set of flags .
19,259
protected ComponentModel getComponentModel ( ) { UIContext effectiveContext = UIContextHolder . getCurrent ( ) ; if ( effectiveContext == null ) { return sharedModel ; } else { ComponentModel model = ( ComponentModel ) effectiveContext . getModel ( this ) ; if ( model == null ) { return sharedModel ; } else if ( model . getSharedModel ( ) == null ) { model . setSharedModel ( sharedModel ) ; } return model ; } }
Returns the effective component model for this component . Subclass may override this method to narrow the return type to their specific model type .
19,260
protected ComponentModel getOrCreateComponentModel ( ) { ComponentModel model = getComponentModel ( ) ; if ( locked && model == sharedModel ) { UIContext effectiveContext = UIContextHolder . getCurrent ( ) ; if ( effectiveContext != null ) { model = newComponentModel ( ) ; model . setSharedModel ( sharedModel ) ; effectiveContext . setModel ( this , model ) ; initialiseComponentModel ( ) ; } } return model ; }
Retrieves the model for this component so that it can be modified . If this method is called during request processing and a session specific model does not yet exist then a new model is created . Subclasses may override this method to narrow the return type to their specific model type .
19,261
WComponent getChildAt ( final int index ) { ComponentModel model = getComponentModel ( ) ; return model . getChildren ( ) . get ( index ) ; }
Retrieves a child component by its index .
19,262
int getIndexOfChild ( final WComponent childComponent ) { ComponentModel model = getComponentModel ( ) ; List < WComponent > children = model . getChildren ( ) ; return children == null ? - 1 : children . indexOf ( childComponent ) ; }
Retrieves the index of the given child .
19,263
List < WComponent > getChildren ( ) { List < WComponent > children = getComponentModel ( ) . getChildren ( ) ; return children != null && ! children . isEmpty ( ) ? Collections . unmodifiableList ( children ) : Collections . < WComponent > emptyList ( ) ; }
Retrieves the children of this component .
19,264
void add ( final WComponent component ) { assertAddSupported ( component ) ; assertNotReparenting ( component ) ; if ( ! ( this instanceof Container ) ) { throw new UnsupportedOperationException ( "Components can only be added to a container" ) ; } ComponentModel model = getOrCreateComponentModel ( ) ; if ( model . getChildren ( ) == null ) { model . setChildren ( new ArrayList < WComponent > ( 1 ) ) ; } model . getChildren ( ) . add ( component ) ; if ( isLocked ( ) ) { component . setLocked ( true ) ; } if ( component instanceof AbstractWComponent ) { ( ( AbstractWComponent ) component ) . getOrCreateComponentModel ( ) . setParent ( ( Container ) this ) ; ( ( AbstractWComponent ) component ) . addNotify ( ) ; } }
Adds the given component as a child of this component .
19,265
void remove ( final WComponent aChild ) { ComponentModel model = getOrCreateComponentModel ( ) ; if ( model . getChildren ( ) == null ) { model . setChildren ( copyChildren ( getComponentModel ( ) . getChildren ( ) ) ) ; } if ( model . getChildren ( ) . remove ( aChild ) ) { if ( model . getChildren ( ) . isEmpty ( ) ) { model . setChildren ( null ) ; } aChild . reset ( ) ; if ( aChild . getParent ( ) != null && aChild instanceof AbstractWComponent ) { ( ( AbstractWComponent ) aChild ) . getOrCreateComponentModel ( ) . setParent ( null ) ; ( ( AbstractWComponent ) aChild ) . removeNotify ( ) ; } } }
Removes the given component from this component s list of children .
19,266
private static List < WComponent > copyChildren ( final List < WComponent > children ) { ArrayList < WComponent > copy ; if ( children == null ) { copy = new ArrayList < > ( 1 ) ; } else { copy = new ArrayList < > ( children ) ; } return copy ; }
Creates a copy of the given list of components .
19,267
protected Object writeReplace ( ) throws ObjectStreamException { WComponent top = WebUtilities . getTop ( this ) ; String repositoryKey ; if ( top instanceof WApplication ) { repositoryKey = ( ( WApplication ) top ) . getUiVersionKey ( ) ; } else { repositoryKey = top . getClass ( ) . getName ( ) ; } if ( UIRegistry . getInstance ( ) . isRegistered ( repositoryKey ) && top == UIRegistry . getInstance ( ) . getUI ( repositoryKey ) ) { ArrayList < Integer > reversedIndexList = new ArrayList < > ( ) ; WComponent node = this ; Container parent = node . getParent ( ) ; try { while ( parent != null ) { int index = getIndexOfChild ( parent , node ) ; reversedIndexList . add ( index ) ; node = parent ; parent = node . getParent ( ) ; } } catch ( Exception ex ) { LOG . error ( "Unable to determine component index relative to top." , ex ) ; } final int depth = reversedIndexList . size ( ) ; int [ ] nodeLocation = new int [ depth ] ; for ( int i = 0 ; i < depth ; i ++ ) { Integer index = reversedIndexList . get ( depth - i - 1 ) ; nodeLocation [ i ] = index . intValue ( ) ; } WComponentRef ref = new WComponentRef ( repositoryKey , nodeLocation ) ; if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "WComponent converted to reference. Ref = " + ref + ". Component = " + getClass ( ) . getName ( ) ) ; } return ref ; } else { LOG . debug ( "WComponent not accessible via the repository, so it will be serialised. Component = " + getClass ( ) . getName ( ) ) ; return this ; } }
Implement writeReplace so that on serialization WComponents that are registered in the UIRegistry write a reference to the registered component rather than the component itself . This ensures that on deserialization only one copy of the registered component will be present in the VM .
19,268
private void addLink ( final WSubMenu subMenu , final WLink link ) { subMenu . add ( new WMenuItem ( new WDecoratedLabel ( link ) ) ) ; }
Adds a WLink to a sub - menu .
19,269
public void setLabelWidth ( final int labelWidth ) { if ( labelWidth > 100 ) { throw new IllegalArgumentException ( "labelWidth (" + labelWidth + ") cannot be greater than 100 percent." ) ; } getOrCreateComponentModel ( ) . labelWidth = Math . max ( 0 , labelWidth ) ; }
Sets the label width .
19,270
public WField addField ( final WButton button ) { WField field = new WField ( ( WLabel ) null , button ) ; add ( field ) ; return field ; }
Add a field consisting of a WButton with a null label .
19,271
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WPartialDateField dateField = ( WPartialDateField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = dateField . isReadOnly ( ) ; String date = formatDate ( dateField ) ; xml . appendTagOpen ( "ui:datefield" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , dateField . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "date" , date ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendAttribute ( "allowPartial" , "true" ) ; xml . appendOptionalAttribute ( "disabled" , dateField . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , dateField . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , dateField . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , dateField . getAccessibleText ( ) ) ; WComponent submitControl = dateField . getDefaultSubmitButton ( ) ; String submitControlId = submitControl == null ? null : submitControl . getId ( ) ; xml . appendOptionalAttribute ( "buttonId" , submitControlId ) ; } xml . appendClose ( ) ; if ( date == null ) { xml . appendEscaped ( dateField . getText ( ) ) ; } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( dateField , renderContext ) ; } xml . appendEndTag ( "ui:datefield" ) ; }
Paints the given WPartialDateField .
19,272
private String formatDate ( final WPartialDateField dateField ) { Integer day = dateField . getDay ( ) ; Integer month = dateField . getMonth ( ) ; Integer year = dateField . getYear ( ) ; if ( day != null || month != null || year != null ) { StringBuffer buf = new StringBuffer ( 10 ) ; append ( buf , year , 4 ) ; buf . append ( '-' ) ; append ( buf , month , 2 ) ; buf . append ( '-' ) ; append ( buf , day , 2 ) ; return buf . toString ( ) ; } return null ; }
Formats a partial date to the format required by the schema .
19,273
private void append ( final StringBuffer buf , final Integer num , final int digits ) { if ( num == null ) { for ( int i = 0 ; i < digits ; i ++ ) { buf . append ( '?' ) ; } } else { for ( int digit = 1 , test = 10 ; digit < digits ; digit ++ , test *= 10 ) { if ( num < test ) { buf . append ( '0' ) ; } } buf . append ( num ) ; } }
Appends a single date component to the given StringBuffer . Nulls are replaced with question marks and numbers are padded with zeros .
19,274
protected void validateComponent ( final List < Diagnostic > diags ) { String text1 = field1 . getText ( ) ; String text2 = field2 . getText ( ) ; String text3 = field3 . getText ( ) ; if ( text1 != null && text1 . length ( ) > 0 && text1 . equals ( text2 ) ) { diags . add ( createErrorDiagnostic ( field2 , "Fields 1 and 2 cannot be the same." ) ) ; } int len = 0 ; if ( text1 != null ) { len += text1 . length ( ) ; } if ( text2 != null ) { len += text2 . length ( ) ; } if ( len > 20 ) { diags . add ( createErrorDiagnostic ( "The total length of Field 1 plus Field 2 can exceed 20 characters." ) ) ; } if ( Util . empty ( text3 ) ) { diags . add ( new DiagnosticImpl ( Diagnostic . WARNING , UIContextHolder . getCurrent ( ) , field3 , "Warning that this should not be blank" ) ) ; } }
An example of cross field validation .
19,275
public StateChange nextState ( final char c ) { StateChange change = currentState . getChange ( c ) ; currentState = change . getNewState ( ) ; return change ; }
Moves the machine to the next state based on the input character .
19,276
protected boolean doHandleRequest ( final Request request ) { if ( request . getParameter ( getId ( ) ) != null ) { return false ; } if ( getValue ( ) != null ) { setData ( null ) ; return true ; } return false ; }
This method will only processes a request where the group is on the request and has no value . If the group has no value then none of the group s radio buttons will be triggered to process the request .
19,277
private void addDateRangeExample ( ) { add ( new WHeading ( HeadingLevel . H2 , "Example of a date range component" ) ) ; WFieldSet dateRange = new WFieldSet ( "Enter the expected arrival and departure dates." ) ; add ( dateRange ) ; WPanel dateRangePanel = new WPanel ( ) ; dateRangePanel . setLayout ( new FlowLayout ( FlowLayout . LEFT , Size . MEDIUM ) ) ; dateRange . add ( dateRangePanel ) ; final WDateField arrivalDate = new WDateField ( ) ; final WDateField departureDate = new WDateField ( ) ; WLabel arrivalLabel = new WLabel ( "Arrival" , arrivalDate ) ; arrivalLabel . setHint ( "dd MMM yyyy" ) ; WLabel departureLabel = new WLabel ( "Departure" , departureDate ) ; departureLabel . setHint ( "dd MMM yyyy" ) ; dateRangePanel . add ( arrivalLabel ) ; dateRangePanel . add ( arrivalDate ) ; dateRangePanel . add ( departureLabel ) ; dateRangePanel . add ( departureDate ) ; WSubordinateControl control = new WSubordinateControl ( ) ; add ( control ) ; Rule rule = new Rule ( new Equal ( arrivalDate , null ) ) ; control . addRule ( rule ) ; rule . addActionOnTrue ( new Disable ( departureDate ) ) ; rule . addActionOnFalse ( new Enable ( departureDate ) ) ; control . addRule ( rule ) ; }
Add date range example .
19,278
private void addContraintExamples ( ) { add ( new WHeading ( HeadingLevel . H2 , "Date fields with input constraints" ) ) ; WFieldLayout layout = new WFieldLayout ( ) ; layout . setLabelWidth ( 33 ) ; add ( layout ) ; WDateField constrainedDateField = new WDateField ( ) ; constrainedDateField . setMandatory ( true ) ; layout . addField ( "Mandatory date field" , constrainedDateField ) ; constrainedDateField = new WDateField ( ) ; constrainedDateField . setMinDate ( new Date ( ) ) ; layout . addField ( "Minimum date today" , constrainedDateField ) ; constrainedDateField = new WDateField ( ) ; constrainedDateField . setMaxDate ( new Date ( ) ) ; layout . addField ( "Maximum date today" , constrainedDateField ) ; constrainedDateField = new WDateField ( ) ; constrainedDateField . setBirthdayAutocomplete ( ) ; layout . addField ( "With autocomplete hint" , constrainedDateField ) ; constrainedDateField = new WDateField ( ) ; constrainedDateField . setAutocompleteOff ( ) ; layout . addField ( "With autocomplete off" , constrainedDateField ) ; }
Add constraint example .
19,279
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WSelectToggle toggle = ( WSelectToggle ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:selecttoggle" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; State state = toggle . getState ( ) ; if ( State . ALL . equals ( state ) ) { xml . appendAttribute ( "selected" , "all" ) ; } else if ( State . NONE . equals ( state ) ) { xml . appendAttribute ( "selected" , "none" ) ; } else { xml . appendAttribute ( "selected" , "some" ) ; } xml . appendOptionalAttribute ( "disabled" , toggle . isDisabled ( ) , "true" ) ; xml . appendAttribute ( "target" , toggle . getTarget ( ) . getId ( ) ) ; xml . appendAttribute ( "renderAs" , toggle . isRenderAsText ( ) ? "text" : "control" ) ; xml . appendOptionalAttribute ( "roundTrip" , ! toggle . isClientSide ( ) , "true" ) ; xml . appendEnd ( ) ; }
Paints the given WSelectToggle .
19,280
private void buildUI ( ) { WFieldLayout layout = new WFieldLayout ( WFieldLayout . LAYOUT_STACKED ) ; layout . setMargin ( new Margin ( null , null , Size . LARGE , null ) ) ; add ( layout ) ; layout . addField ( "Autoplay" , cbAutoPlay ) ; layout . addField ( "Loop" , cbLoop ) ; layout . addField ( "Disable" , cbDisable ) ; layout . addField ( "Show only play/pause" , cbControls ) ; layout . addField ( ( WLabel ) null , btnApply ) ; WSubordinateControl control = new WSubordinateControl ( ) ; add ( control ) ; Rule rule = new Rule ( ) ; rule . setCondition ( new Equal ( cbControls , Boolean . TRUE . toString ( ) ) ) ; rule . addActionOnTrue ( new Enable ( cbDisable ) ) ; rule . addActionOnFalse ( new Disable ( cbDisable ) ) ; control . addRule ( rule ) ; add ( new WAjaxControl ( btnApply , audio ) ) ; add ( audio ) ; }
Build the UI for this example .
19,281
protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( ! isInitialised ( ) ) { setInitialised ( true ) ; setupAudio ( ) ; } }
Set up the initial state of the audio component .
19,282
private void setupAudio ( ) { audio . setAutoplay ( cbAutoPlay . isSelected ( ) ) ; audio . setLoop ( ! cbLoop . isDisabled ( ) && cbLoop . isSelected ( ) ) ; audio . setControls ( cbControls . isSelected ( ) ? WAudio . Controls . PLAY_PAUSE : WAudio . Controls . NATIVE ) ; audio . setDisabled ( cbControls . isSelected ( ) && cbDisable . isSelected ( ) ) ; }
Set the audio configuration options .
19,283
protected void afterPaint ( final RenderContext renderContext ) { super . afterPaint ( renderContext ) ; final int size = getChildCount ( ) ; for ( int i = 0 ; i < size ; i ++ ) { WComponent child = getChildAt ( i ) ; child . reset ( ) ; } }
After the component has been painted the UIContexts for this component and all its children are cleared .
19,284
public String getGroupName ( ) { if ( collapsibleToggle != null ) { return collapsibleToggle . getId ( ) ; } else if ( ! collapsibleList . isEmpty ( ) ) { return collapsibleList . get ( 0 ) . getId ( ) ; } return "" ; }
Retrieves the common name used by all collapsible components in the group .
19,285
private void addComponent ( final WComponent component ) { collapsibleList . add ( component ) ; MemoryUtil . checkSize ( collapsibleList . size ( ) , this . getClass ( ) . getSimpleName ( ) ) ; }
Responsible for updating the underlying group store .
19,286
private List < ? > getNewOptions ( final String [ ] paramValues ) { List < ? > copyOldOptions = new ArrayList ( getOptions ( ) ) ; List < Object > newOptions = new ArrayList < > ( paramValues . length ) ; for ( String param : paramValues ) { for ( Object oldOption : copyOldOptions ) { String stringOldOption = String . valueOf ( oldOption ) ; if ( Util . equals ( stringOldOption , param ) ) { newOptions . add ( oldOption ) ; copyOldOptions . remove ( oldOption ) ; break ; } } } return newOptions ; }
Shuffle the options .
19,287
private void addListItems ( final WDefinitionList list ) { list . addTerm ( "Colours" , new WText ( "Red" ) , new WText ( "Green" ) , new WText ( "Blue" ) ) ; list . addTerm ( "Shapes" , new WText ( "Circle" ) ) ; list . addTerm ( "Shapes" , new WText ( "Square" ) , new WText ( "Triangle" ) ) ; }
Adds some items to a definition list .
19,288
private void applySettings ( ) { container . reset ( ) ; WPanel gridLayoutPanel = new WPanel ( ) ; if ( cbResponsive . isSelected ( ) ) { gridLayoutPanel . setHtmlClass ( HtmlClassProperties . RESPOND ) ; } GridLayout layout = new GridLayout ( rowCount . getValue ( ) . intValue ( ) , columnCount . getValue ( ) . intValue ( ) , hGap . getValue ( ) . intValue ( ) , vGap . getValue ( ) . intValue ( ) ) ; gridLayoutPanel . setLayout ( layout ) ; addBoxes ( gridLayoutPanel , boxCount . getValue ( ) . intValue ( ) ) ; container . add ( gridLayoutPanel ) ; gridLayoutPanel . setVisible ( cbVisible . isSelected ( ) ) ; }
reset the container that holds the grid layout and create a new grid layout with the appropriate properties .
19,289
public Subscription getSubscription ( Reference reference ) { return getResourceFactory ( ) . getApiResource ( "/subscription/" + reference . toURLFragment ( false ) ) . get ( Subscription . class ) ; }
Get the subscription for the given object
19,290
public void subscribe ( Reference reference ) { getResourceFactory ( ) . getApiResource ( "/subscription/" + reference . toURLFragment ( false ) ) . entity ( new Empty ( ) , MediaType . APPLICATION_JSON_TYPE ) . post ( ) ; }
Subscribes the user to the given object . Based on the object type the user will receive notifications when actions are performed on the object . See the area for more details .
19,291
public void paint ( final RenderContext renderContext ) { AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; if ( operation == null ) { throw new SystemException ( "Can't paint AJAX response. Couldn't find the expected reference to the AjaxOperation." ) ; } if ( operation . getTargetContainerId ( ) != null ) { paintContainerResponse ( renderContext , operation ) ; } else { paintResponse ( renderContext , operation ) ; } }
Paints the targeted ajax regions . The format of the response is an agreement between the server and the client side JavaScript handling our ajax response .
19,292
private void paintContainerResponse ( final RenderContext renderContext , final AjaxOperation operation ) { WebXmlRenderContext webRenderContext = ( WebXmlRenderContext ) renderContext ; XmlStringBuilder xml = webRenderContext . getWriter ( ) ; ComponentWithContext trigger = AjaxHelper . getCurrentTriggerAndContext ( ) ; if ( trigger == null ) { throw new SystemException ( "No context available for trigger " + operation . getTriggerId ( ) ) ; } xml . appendTagOpen ( "ui:ajaxtarget" ) ; xml . appendAttribute ( "id" , operation . getTargetContainerId ( ) ) ; xml . appendAttribute ( "action" , AjaxOperation . AjaxAction . REPLACE_CONTENT . getDesc ( ) ) ; xml . appendClose ( ) ; UIContextHolder . pushContext ( trigger . getContext ( ) ) ; try { for ( String targetId : operation . getTargets ( ) ) { ComponentWithContext target ; if ( targetId . equals ( operation . getTriggerId ( ) ) ) { target = trigger ; } else { target = WebUtilities . getComponentById ( targetId , true ) ; if ( target == null ) { LOG . warn ( "Could not find ajax target to render [" + targetId + "]" ) ; continue ; } } target . getComponent ( ) . paint ( renderContext ) ; } } finally { UIContextHolder . popContext ( ) ; } xml . appendEndTag ( "ui:ajaxtarget" ) ; }
Paint the ajax container response .
19,293
private boolean isProcessTriggerOnly ( final ComponentWithContext triggerWithContext , final AjaxOperation operation ) { if ( operation . getTargetContainerId ( ) != null || operation . isInternalAjaxRequest ( ) ) { return true ; } WComponent trigger = triggerWithContext . getComponent ( ) ; if ( trigger instanceof WAjaxControl ) { UIContext uic = triggerWithContext . getContext ( ) ; UIContextHolder . pushContext ( uic ) ; try { WAjaxControl ajax = ( WAjaxControl ) trigger ; if ( ajax . getDelay ( ) > 0 ) { return true ; } } finally { UIContextHolder . popContext ( ) ; } } return false ; }
Check if process this trigger only .
19,294
public static boolean getHandleErrorWithFatalErrorPageFactory ( ) { Boolean parameterValue = get ( ) . getBoolean ( HANDLE_ERROR_WITH_FATAL_PAGE_FACTORY , null ) ; if ( parameterValue != null ) { return parameterValue ; } return get ( ) . getBoolean ( HANDLE_ERROR_WITH_FATAL_PAGE_FACTORY_DEPRECATED , false ) ; }
The flag indicating whether to handle an error with a fatal error page factory .
19,295
public static String getRendererOverride ( final String classname ) { if ( StringUtils . isBlank ( classname ) ) { throw new IllegalArgumentException ( "classname cannot be blank." ) ; } return get ( ) . getString ( RENDERER_OVERRIDE_PREFIX + classname ) ; }
The overridden renderer class for the given fully qualified classname .
19,296
public static String getResponseCacheHeaderSettings ( final String contentType ) { String parameter = MessageFormat . format ( RESPONSE_CACHE_HEADER_SETTINGS , contentType ) ; return get ( ) . getString ( parameter ) ; }
The response cache header settings for the given contentType .
19,297
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WSuggestions suggestions = ( WSuggestions ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; String dataKey = suggestions . getListCacheKey ( ) ; boolean useAjax = dataKey == null && suggestions . getRefreshAction ( ) != null ; xml . appendTagOpen ( "ui:suggestions" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "min" , suggestions . getMinRefresh ( ) > 0 , suggestions . getMinRefresh ( ) ) ; xml . appendOptionalAttribute ( "ajax" , useAjax , "true" ) ; xml . appendOptionalAttribute ( "data" , dataKey ) ; WSuggestions . Autocomplete autocomplete = suggestions . getAutocomplete ( ) ; if ( autocomplete == WSuggestions . Autocomplete . LIST ) { xml . appendOptionalAttribute ( "autocomplete" , "list" ) ; } xml . appendClose ( ) ; boolean isTrigger = useAjax && AjaxHelper . isCurrentAjaxTrigger ( suggestions ) ; if ( isTrigger || ( dataKey == null && ! useAjax ) ) { for ( String suggestion : suggestions . getSuggestions ( ) ) { xml . appendTagOpen ( "ui:suggestion" ) ; xml . appendAttribute ( "value" , suggestion ) ; xml . appendEnd ( ) ; } } xml . appendEndTag ( "ui:suggestions" ) ; }
Paints the given WSuggestions .
19,298
public void handleRequest ( final Request request ) { if ( ! isDisabled ( ) ) { final SelectToggleModel model = getComponentModel ( ) ; String requestParam = request . getParameter ( getId ( ) ) ; final State newValue ; if ( "all" . equals ( requestParam ) ) { newValue = State . ALL ; } else if ( "none" . equals ( requestParam ) ) { newValue = State . NONE ; } else if ( "some" . equals ( requestParam ) ) { newValue = State . SOME ; } else { newValue = model . state ; } if ( ! newValue . equals ( model . state ) ) { setState ( newValue ) ; } if ( ! model . clientSide && model . target != null && ! State . SOME . equals ( newValue ) ) { invokeLater ( new Runnable ( ) { public void run ( ) { setSelections ( model . target , State . ALL . equals ( newValue ) ) ; } } ) ; } } }
Override handleRequest to handle selection toggling if server - side processing is being used .
19,299
private static void setSelections ( final WComponent component , final boolean selected ) { if ( component instanceof WCheckBox ) { ( ( WCheckBox ) component ) . setSelected ( selected ) ; } else if ( component instanceof WCheckBoxSelect ) { WCheckBoxSelect select = ( WCheckBoxSelect ) component ; select . setSelected ( selected ? select . getOptions ( ) : new ArrayList ( 0 ) ) ; } else if ( component instanceof WMultiSelect ) { WMultiSelect list = ( WMultiSelect ) component ; list . setSelected ( selected ? list . getOptions ( ) : new ArrayList ( 0 ) ) ; } else if ( component instanceof WDataTable ) { WDataTable table = ( WDataTable ) component ; if ( table . getSelectMode ( ) == SelectMode . MULTIPLE ) { if ( selected ) { TableDataModel model = table . getDataModel ( ) ; int rowCount = model . getRowCount ( ) ; List < Integer > indices = new ArrayList < > ( rowCount ) ; for ( int i = 0 ; i < rowCount ; i ++ ) { if ( model . isSelectable ( i ) ) { indices . add ( i ) ; } } table . setSelectedRows ( indices ) ; } else { table . setSelectedRows ( new ArrayList < Integer > ( 0 ) ) ; } } } else if ( component instanceof Container ) { Container container = ( Container ) component ; final int childCount = container . getChildCount ( ) ; for ( int i = 0 ; i < childCount ; i ++ ) { WComponent child = container . getChildAt ( i ) ; setSelections ( child , selected ) ; } } }
Sets the selections for the given context .