idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
18,900 | public static String format ( final Locale locale , final String text , final Object ... args ) { if ( text == null ) { return null ; } String localisedText = getLocalisedText ( locale , text ) ; String message = localisedText == null ? text : localisedText ; if ( args != null ) { try { return MessageFormat . format ( message , args ) ; } catch ( IllegalArgumentException e ) { LOG . error ( "Invalid message format for message " + message , e ) ; } } return message ; } | Formats the given text optionally using locale - specific text . |
18,901 | public static Locale getEffectiveLocale ( ) { Locale effectiveLocale = null ; UIContext uic = UIContextHolder . getCurrent ( ) ; if ( uic != null ) { effectiveLocale = uic . getLocale ( ) ; } if ( effectiveLocale == null ) { String defaultLocale = ConfigurationProperties . getDefaultLocale ( ) ; effectiveLocale = new Locale ( defaultLocale ) ; } return effectiveLocale ; } | Get the locale currently in use . |
18,902 | public static String getLocalisedText ( final Locale locale , final String text ) { String message = null ; String resourceBundleBaseName = getResourceBundleBaseName ( ) ; if ( ! Util . empty ( resourceBundleBaseName ) ) { Locale effectiveLocale = locale ; if ( effectiveLocale == null ) { effectiveLocale = getEffectiveLocale ( ) ; } try { ResourceBundle bundle = ResourceBundle . getBundle ( resourceBundleBaseName , effectiveLocale ) ; message = bundle . getString ( text ) ; } catch ( MissingResourceException e ) { if ( text != null && text . startsWith ( ConfigurationProperties . INTERNAL_MESSAGE_PREFIX ) ) { message = ConfigurationProperties . getInternalMessage ( text ) ; } if ( message == null && ! MISSING_RESOURCES . contains ( locale ) ) { LOG . error ( "Missing resource mapping for locale: " + locale + ", text: " + text ) ; MISSING_RESOURCES . add ( locale ) ; } } } else if ( text != null && text . startsWith ( ConfigurationProperties . INTERNAL_MESSAGE_PREFIX ) ) { message = ConfigurationProperties . getInternalMessage ( text ) ; } return message ; } | Attempts to retrieve the localized message for the given text . |
18,903 | public static boolean validateFileType ( final FileItemWrap newFile , final List < String > fileTypes ) { if ( newFile == null ) { return false ; } if ( fileTypes == null || fileTypes . isEmpty ( ) ) { return true ; } final List < String > fileExts = fileTypes . stream ( ) . filter ( fileType -> fileType . startsWith ( "." ) ) . collect ( Collectors . toList ( ) ) ; final List < String > fileMimes = fileTypes . stream ( ) . filter ( fileType -> ! fileExts . contains ( fileType ) ) . collect ( Collectors . toList ( ) ) ; if ( fileExts . size ( ) > 0 && newFile . getName ( ) != null ) { String [ ] split = newFile . getName ( ) . split ( ( "\\.(?=[^\\.]+$)" ) ) ; if ( split . length == 2 && fileExts . stream ( ) . anyMatch ( fileExt -> fileExt . equals ( "." + split [ 1 ] ) ) ) { return true ; } } if ( fileMimes . size ( ) > 0 ) { final String mimeType = getFileMimeType ( newFile ) ; LOG . debug ( "File mime-type is: " + mimeType ) ; for ( String fileMime : fileMimes ) { if ( StringUtils . equals ( mimeType , fileMime ) ) { return true ; } if ( fileMime . indexOf ( "*" ) == fileMime . length ( ) - 1 ) { fileMime = fileMime . substring ( 0 , fileMime . length ( ) - 1 ) ; if ( mimeType . indexOf ( fileMime ) == 0 ) { return true ; } } } } return false ; } | Checks if the file item is one among the supplied file types . This first checks against file extensions then against file mime types |
18,904 | public static String getFileMimeType ( final File file ) { if ( file != null ) { try { final Tika tika = new Tika ( ) ; return tika . detect ( file . getInputStream ( ) ) ; } catch ( IOException ex ) { LOG . error ( "Invalid file, name " + file . getName ( ) , ex ) ; } } return null ; } | Identify the mime type of a file . |
18,905 | public static boolean validateFileSize ( final FileItemWrap newFile , final long maxFileSize ) { if ( newFile == null ) { return false ; } if ( maxFileSize < 1 ) { return true ; } return ( newFile . getSize ( ) <= maxFileSize ) ; } | Checks if the file item size is within the supplied max file size . |
18,906 | public static String getInvalidFileTypeMessage ( final List < String > fileTypes ) { if ( fileTypes == null ) { return null ; } return String . format ( I18nUtilities . format ( null , InternalMessages . DEFAULT_VALIDATION_ERROR_FILE_WRONG_TYPE ) , StringUtils . join ( fileTypes . toArray ( new Object [ fileTypes . size ( ) ] ) , "," ) ) ; } | Returns invalid fileTypes error message . |
18,907 | public static String getInvalidFileSizeMessage ( final long maxFileSize ) { return String . format ( I18nUtilities . format ( null , InternalMessages . DEFAULT_VALIDATION_ERROR_FILE_WRONG_SIZE ) , FileUtil . readableFileSize ( maxFileSize ) ) ; } | Returns invalid fileSize error message . |
18,908 | public List < Diagnostic > getDiagnostics ( ) { FieldIndicatorModel model = getComponentModel ( ) ; return Collections . unmodifiableList ( model . diagnostics ) ; } | Return the diagnostics for this indicator . |
18,909 | public void setWidth ( final int width ) { if ( width > 100 ) { throw new IllegalArgumentException ( "Width (" + width + ") cannot be greater than 100 percent" ) ; } getOrCreateComponentModel ( ) . width = Math . max ( 0 , width ) ; } | Sets the column width . |
18,910 | public void paint ( final RenderContext renderContext ) { getResponse ( ) . setHeader ( "Cache-Control" , type . getSettings ( ) ) ; if ( ! type . isCache ( ) ) { getResponse ( ) . setHeader ( "Pragma" , "no-cache" ) ; getResponse ( ) . setHeader ( "Expires" , "-1" ) ; } super . paint ( renderContext ) ; } | Set the appropriate response headers for caching or not caching the response . |
18,911 | public void addMessage ( final boolean encode , final String msg , final Serializable ... args ) { MessageModel model = getOrCreateComponentModel ( ) ; model . messages . add ( new Duplet < > ( I18nUtilities . asMessage ( msg , args ) , encode ) ) ; MemoryUtil . checkSize ( model . messages . size ( ) , this . getClass ( ) . getSimpleName ( ) ) ; } | Adds a message to the message box . |
18,912 | public void removeMessages ( final int index ) { MessageModel model = getOrCreateComponentModel ( ) ; if ( model . messages != null ) { model . messages . remove ( index ) ; } } | Removes a message from the message box . |
18,913 | public void clearMessages ( ) { MessageModel model = getOrCreateComponentModel ( ) ; if ( model . messages != null ) { model . messages . clear ( ) ; } } | Removes all messages from the message box . |
18,914 | public List < String > getMessages ( ) { MessageModel model = getComponentModel ( ) ; List < String > messages = new ArrayList < > ( model . messages . size ( ) ) ; for ( Duplet < Serializable , Boolean > message : model . messages ) { String text = I18nUtilities . format ( null , message . getFirst ( ) ) ; boolean encode = message . getSecond ( ) ; messages . add ( encode ? WebUtilities . encode ( text ) : HtmlToXMLUtil . unescapeToXML ( text ) ) ; } return Collections . unmodifiableList ( messages ) ; } | Retrieves the list of messages . |
18,915 | public void setVideo ( final Video [ ] video ) { List < Video > list = video == null ? null : Arrays . asList ( video ) ; getOrCreateComponentModel ( ) . video = list ; } | Sets the video clip in multiple formats . The client will try to load the first video clip and if it fails or isn t supported it will move on to the next video clip . Only the first clip which can be played on the client will be used . |
18,916 | public Video [ ] getVideo ( ) { List < Video > list = getComponentModel ( ) . video ; return list == null ? null : list . toArray ( new Video [ ] { } ) ; } | Retrieves the video clips associated with this WVideo . |
18,917 | public void setMediaGroup ( final String mediaGroup ) { String currMediaGroup = getMediaGroup ( ) ; if ( ! Objects . equals ( mediaGroup , currMediaGroup ) ) { getOrCreateComponentModel ( ) . mediaGroup = mediaGroup ; } } | Sets the media group . |
18,918 | public void setAltText ( final String altText ) { String currAltText = getAltText ( ) ; if ( ! Objects . equals ( altText , currAltText ) ) { getOrCreateComponentModel ( ) . altText = altText ; } } | Sets the alternative text to display when the video clip can not be played . |
18,919 | public void setTracks ( final Track [ ] tracks ) { List < Track > list = tracks == null ? null : Arrays . asList ( tracks ) ; getOrCreateComponentModel ( ) . tracks = list ; } | Sets the tracks for the video . The tracks are used to provide additional information relating to the video for example subtitles . |
18,920 | public Track [ ] getTracks ( ) { List < Track > list = getComponentModel ( ) . tracks ; return list == null ? null : list . toArray ( new Track [ ] { } ) ; } | Retrieves additional tracks associated with the video . The tracks provide additional information relating to the video for example subtitles . |
18,921 | public boolean isVisible ( ) { if ( ! super . isVisible ( ) ) { return false ; } Video [ ] video = getVideo ( ) ; return video != null && video . length > 0 ; } | Override isVisible to also return false if there are no video clips to play . |
18,922 | public void handleRequest ( final Request request ) { super . handleRequest ( request ) ; String targ = request . getParameter ( Environment . TARGET_ID ) ; boolean contentReqested = ( targ != null && targ . equals ( getTargetId ( ) ) ) ; if ( contentReqested && request . getParameter ( POSTER_REQUEST_PARAM_KEY ) != null ) { handlePosterRequest ( ) ; } if ( isDisabled ( ) ) { return ; } if ( contentReqested ) { if ( request . getParameter ( VIDEO_INDEX_REQUEST_PARAM_KEY ) != null ) { handleVideoRequest ( request ) ; } else if ( request . getParameter ( TRACK_INDEX_REQUEST_PARAM_KEY ) != null ) { handleTrackRequest ( request ) ; } } } | When an video element is rendered to the client the browser will make a second request to get the video content . The handleRequest method has been overridden to detect whether the request is the content fetch request by looking for the parameter that we encode in the content url . |
18,923 | private void handlePosterRequest ( ) { Image poster = getComponentModel ( ) . poster ; if ( poster != null ) { ContentEscape escape = new ContentEscape ( poster ) ; escape . setCacheable ( ! Util . empty ( getCacheKey ( ) ) ) ; throw escape ; } else { LOG . warn ( "Client requested non-existant poster" ) ; } } | Handles a request for the poster . |
18,924 | private void handleVideoRequest ( final Request request ) { String videoRequested = request . getParameter ( VIDEO_INDEX_REQUEST_PARAM_KEY ) ; int videoFileIndex = 0 ; try { videoFileIndex = Integer . parseInt ( videoRequested ) ; } catch ( NumberFormatException e ) { LOG . error ( "Failed to parse video index: " + videoFileIndex ) ; } Video [ ] video = getVideo ( ) ; if ( video != null && videoFileIndex >= 0 && videoFileIndex < video . length ) { ContentEscape escape = new ContentEscape ( video [ videoFileIndex ] ) ; escape . setCacheable ( ! Util . empty ( getCacheKey ( ) ) ) ; throw escape ; } else { LOG . warn ( "Client requested invalid video clip: " + videoFileIndex ) ; } } | Handles a request for a video . |
18,925 | private void handleTrackRequest ( final Request request ) { String trackRequested = request . getParameter ( TRACK_INDEX_REQUEST_PARAM_KEY ) ; int trackIndex = 0 ; try { trackIndex = Integer . parseInt ( trackRequested ) ; } catch ( NumberFormatException e ) { LOG . error ( "Failed to parse track index: " + trackIndex ) ; } Track [ ] tracks = getTracks ( ) ; if ( tracks != null && trackIndex >= 0 && trackIndex < tracks . length ) { ContentEscape escape = new ContentEscape ( tracks [ trackIndex ] ) ; escape . setCacheable ( ! Util . empty ( getCacheKey ( ) ) ) ; throw escape ; } else { LOG . warn ( "Client requested invalid track: " + trackIndex ) ; } } | Handles a request for an auxillary track . |
18,926 | public void setAudio ( final Audio [ ] audio ) { List < Audio > list = audio == null ? null : Arrays . asList ( audio ) ; getOrCreateComponentModel ( ) . audio = list ; } | Sets the audio clip in multiple formats for all users . The client will try to load the first audio clip and if it fails or isn t supported it will move on to the next audio clip . Only the first clip which can be played on the client will be used . |
18,927 | public Audio [ ] getAudio ( ) { List < Audio > list = getComponentModel ( ) . audio ; return list == null ? null : list . toArray ( new Audio [ ] { } ) ; } | Retrieves the audio clips associated with this WAudio . |
18,928 | public boolean isVisible ( ) { if ( ! super . isVisible ( ) ) { return false ; } Audio [ ] audio = getAudio ( ) ; return audio != null && audio . length > 0 ; } | Override isVisible to also return false if there are no audio clips to play . |
18,929 | public void handleRequest ( final Request request ) { super . handleRequest ( request ) ; if ( isDisabled ( ) ) { return ; } String targ = request . getParameter ( Environment . TARGET_ID ) ; String audioFileRequested = request . getParameter ( AUDIO_INDEX_REQUEST_PARAM_KEY ) ; boolean contentReqested = targ != null && targ . equals ( getTargetId ( ) ) ; if ( contentReqested ) { int audioFileIndex = 0 ; try { audioFileIndex = Integer . parseInt ( audioFileRequested ) ; } catch ( NumberFormatException e ) { LOG . error ( "Failed to parse audio index: " + audioFileIndex ) ; } Audio [ ] audio = getAudio ( ) ; if ( audio != null && audioFileIndex >= 0 && audioFileIndex < audio . length ) { ContentEscape escape = new ContentEscape ( audio [ audioFileIndex ] ) ; escape . setCacheable ( ! Util . empty ( getCacheKey ( ) ) ) ; throw escape ; } else { LOG . error ( "Requested invalid audio clip: " + audioFileIndex ) ; } } } | When an audio element is rendered to the client the browser will make a second request to get the audio content . The handleRequest method has been overridden to detect whether the request is the content fetch request by looking for the parameter that we encode in the content url . |
18,930 | private WFieldLayout recursiveFieldLayout ( final int curr , final int startAt ) { WFieldLayout innerLayout = new WFieldLayout ( ) ; innerLayout . setLabelWidth ( 20 ) ; if ( curr == 0 && startAt == 0 ) { innerLayout . setMargin ( new Margin ( Size . LARGE , null , null , null ) ) ; } innerLayout . setOrdered ( true ) ; if ( startAt > 1 ) { innerLayout . setOrderedOffset ( startAt ) ; } innerLayout . addField ( "Test " + String . valueOf ( startAt > 1 ? startAt : 1 ) , new WTextField ( ) ) ; innerLayout . addField ( "Test " + String . valueOf ( startAt > 1 ? startAt + 1 : 2 ) , new WTextField ( ) ) ; innerLayout . addField ( "Test " + String . valueOf ( startAt > 1 ? startAt + 2 : 2 ) , new WTextField ( ) ) ; if ( curr < 4 ) { int next = curr + 1 ; innerLayout . addField ( "indent level " + String . valueOf ( next ) , recursiveFieldLayout ( next , 0 ) ) ; } innerLayout . addField ( "Test after nest" , new WTextField ( ) ) ; return innerLayout ; } | Create a recursive field layout . |
18,931 | protected void handleFileUploadRequest ( final WMultiFileWidget widget , final XmlStringBuilder xml , final String uploadId ) { FileWidgetUpload file = widget . getFile ( uploadId ) ; if ( file == null ) { throw new SystemException ( "Invalid file id [" + uploadId + "] to render uploaded response." ) ; } int idx = widget . getFiles ( ) . indexOf ( file ) ; FileWidgetRendererUtil . renderFileElement ( widget , xml , file , idx ) ; } | Paint the response for the file uploaded in this request . |
18,932 | private String typesToString ( final List < String > types ) { if ( types == null || types . isEmpty ( ) ) { return null ; } StringBuffer typesString = new StringBuffer ( ) ; for ( Iterator < String > iter = types . iterator ( ) ; iter . hasNext ( ) ; ) { typesString . append ( iter . next ( ) ) ; if ( iter . hasNext ( ) ) { typesString . append ( ',' ) ; } } return typesString . toString ( ) ; } | Flattens the list of accepted mime types into a format suitable for rendering . |
18,933 | protected void afterPaint ( final RenderContext renderContext ) { super . afterPaint ( renderContext ) ; if ( this . isPressed ( ) && renderContext instanceof WebXmlRenderContext ) { PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; StringBuffer temp = dumpAll ( ) ; writer . println ( "<br/><br/>" ) ; writer . println ( temp ) ; } } | Override afterPaint to paint the profile information if the button has been pressed . |
18,934 | public StringBuffer dumpAll ( ) { WComponent root = WebUtilities . getTop ( this ) ; Map < String , GroupData > compTallyByClass = new TreeMap < > ( ) ; GroupData compDataOverall = new GroupData ( ) ; StringBuffer out = new StringBuffer ( ) ; String className = root . getClass ( ) . getName ( ) ; out . append ( "<strong>The root of the WComponent tree is:</strong><br/>" ) . append ( className ) . append ( "<br/>" ) ; tally ( root , compTallyByClass , compDataOverall , out ) ; out . append ( "<strong>WComponent usage overall:</strong><br/> " ) ; out . append ( compDataOverall . total ) . append ( " WComponent(s) in the WComponent tree.<br/>" ) ; if ( compDataOverall . total > 0 ) { out . append ( "<strong>WComponent usage by class:</strong><br/>" ) ; for ( Map . Entry < String , GroupData > entry : compTallyByClass . entrySet ( ) ) { className = entry . getKey ( ) ; GroupData dataForClass = entry . getValue ( ) ; out . append ( ' ' ) . append ( dataForClass . total ) . append ( " " ) . append ( className ) . append ( "<br/>" ) ; } out . append ( "<br/><hr/>" ) ; } processUic ( out ) ; return out ; } | Dumps all the profiling information in textual format to a StringBuffer . |
18,935 | public final R inRangeWith ( TQProperty < R > highProperty , T value ) { expr ( ) . inRangeWith ( _name , highProperty . _name , value ) ; return _root ; } | Value in Range between 2 properties . |
18,936 | protected void afterPaint ( final RenderContext renderContext ) { super . afterPaint ( renderContext ) ; UicStats stats = new UicStats ( UIContextHolder . getCurrent ( ) ) ; stats . analyseWC ( this ) ; if ( renderContext instanceof WebXmlRenderContext ) { PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; writer . println ( "<h2>Serialization Profile of UIC</h2>" ) ; UicStatsAsHtml . write ( writer , stats ) ; writer . println ( "<h2>ObjectProfiler - " + getClass ( ) . getName ( ) + "</h2>" ) ; writer . println ( "<pre>" ) ; try { writer . println ( ObjectGraphDump . dump ( this ) . toFlatSummary ( ) ) ; } catch ( Exception e ) { LOG . error ( "Failed to dump component" , e ) ; } writer . println ( "</pre>" ) ; } } | Override afterPaint to write the statistics after the component is painted . |
18,937 | public void setTreeModel ( final TreeItemModel treeModel ) { getOrCreateComponentModel ( ) . treeModel = treeModel ; clearItemIdMaps ( ) ; setSelectedRows ( null ) ; setExpandedRows ( null ) ; setCustomTree ( ( TreeItemIdNode ) null ) ; } | Sets the tree model which provides row data . |
18,938 | protected void clearItemIdMaps ( ) { if ( getScratchMap ( ) != null ) { getScratchMap ( ) . remove ( CUSTOM_IDS_TO_NODE_SCRATCH_MAP_KEY ) ; getScratchMap ( ) . remove ( ALL_IDS_TO_INDEX_SCRATCH_MAP_KEY ) ; getScratchMap ( ) . remove ( EXPANDED_IDS_TO_INDEX_MAPPING_SCRATCH_MAP_KEY ) ; } } | Clear the item id maps from the scratch map . |
18,939 | public Map < String , TreeItemIdNode > getCustomIdNodeMap ( ) { if ( getScratchMap ( ) == null ) { return createCustomIdNodeMapping ( ) ; } Map < String , TreeItemIdNode > map = ( Map < String , TreeItemIdNode > ) getScratchMap ( ) . get ( CUSTOM_IDS_TO_NODE_SCRATCH_MAP_KEY ) ; if ( map == null ) { map = createCustomIdNodeMapping ( ) ; getScratchMap ( ) . put ( CUSTOM_IDS_TO_NODE_SCRATCH_MAP_KEY , map ) ; } return map ; } | Map an item id to its node in the custom tree . As this can be expensive save the map onto the scratch pad . |
18,940 | public Map < String , List < Integer > > getExpandedItemIdIndexMap ( ) { boolean expandedOnly = getExpandMode ( ) != ExpandMode . CLIENT ; if ( getScratchMap ( ) == null ) { if ( getCustomTree ( ) == null ) { return createItemIdIndexMap ( expandedOnly ) ; } else { return createExpandedCustomIdIndexMapping ( expandedOnly ) ; } } Map < String , List < Integer > > map = ( Map < String , List < Integer > > ) getScratchMap ( ) . get ( EXPANDED_IDS_TO_INDEX_MAPPING_SCRATCH_MAP_KEY ) ; if ( map == null ) { if ( getCustomTree ( ) == null ) { map = createItemIdIndexMap ( expandedOnly ) ; } else { map = createExpandedCustomIdIndexMapping ( expandedOnly ) ; } getScratchMap ( ) . put ( EXPANDED_IDS_TO_INDEX_MAPPING_SCRATCH_MAP_KEY , map ) ; } return map ; } | Map expanded item ids to their row index . As this can be expensive save the map onto the scratch pad . |
18,941 | protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( isCurrentAjaxTrigger ( ) ) { AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; if ( operation . isInternalAjaxRequest ( ) ) { operation . setAction ( AjaxOperation . AjaxAction . IN ) ; } } TreeItemIdNode custom = getCustomTree ( ) ; if ( custom != null ) { checkExpandedCustomNodes ( ) ; } clearItemIdMaps ( ) ; if ( getExpandMode ( ) == ExpandMode . LAZY ) { if ( AjaxHelper . getCurrentOperation ( ) == null ) { clearPrevExpandedRows ( ) ; } else { addPrevExpandedCurrent ( ) ; } } } | Override preparePaint to register an AJAX operation . |
18,942 | protected void checkExpandedCustomNodes ( ) { TreeItemIdNode custom = getCustomTree ( ) ; if ( custom == null ) { return ; } Set < String > expanded = getExpandedRows ( ) ; for ( TreeItemIdNode node : custom . getChildren ( ) ) { processCheckExpandedCustomNodes ( node , expanded ) ; } } | Check if custom nodes that are expanded need their child nodes added from the model . |
18,943 | private void handleItemImageRequest ( final Request request ) { String itemId = request . getParameter ( ITEM_REQUEST_KEY ) ; if ( itemId == null ) { throw new SystemException ( "No tree item id provided for image request." ) ; } if ( ! isValidTreeItem ( itemId ) ) { throw new SystemException ( "Tree item id for an image request [" + itemId + "] is not valid." ) ; } List < Integer > index = getExpandedItemIdIndexMap ( ) . get ( itemId ) ; TreeItemImage image = getTreeModel ( ) . getItemImage ( index ) ; if ( image == null ) { throw new SystemException ( "Tree item id [" + itemId + "] does not have an image." ) ; } ContentEscape escape = new ContentEscape ( image . getImage ( ) ) ; throw escape ; } | Handle a targeted request to retrieve the tree item image . |
18,944 | private void handleOpenItemRequest ( final Request request ) { String param = request . getParameter ( ITEM_REQUEST_KEY ) ; if ( param == null ) { throw new SystemException ( "No tree item id provided for open request." ) ; } int offset = getItemIdPrefix ( ) . length ( ) ; if ( param . length ( ) <= offset ) { throw new SystemException ( "Tree item id [" + param + "] does not have the correct prefix value." ) ; } String itemId = param . substring ( offset ) ; if ( ! isValidTreeItem ( itemId ) ) { throw new SystemException ( "Tree item id [" + itemId + "] is not valid." ) ; } TreeItemIdNode custom = getCustomTree ( ) ; if ( custom == null ) { List < Integer > rowIndex = getExpandedItemIdIndexMap ( ) . get ( itemId ) ; if ( ! getTreeModel ( ) . isExpandable ( rowIndex ) ) { throw new SystemException ( "Tree item id [" + itemId + "] is not expandable." ) ; } } else { TreeItemIdNode node = getCustomIdNodeMap ( ) . get ( itemId ) ; if ( ! node . hasChildren ( ) ) { throw new SystemException ( "Tree item id [" + itemId + "] is not expandable in custom tree." ) ; } } setOpenRequestItemId ( itemId ) ; final Action action = getOpenAction ( ) ; if ( action != null ) { final ActionEvent event = new ActionEvent ( this , "openItem" ) ; Runnable later = new Runnable ( ) { public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; } } | Handles a request containing an open request . |
18,945 | private void handleShuffleState ( final Request request ) { String json = request . getParameter ( SHUFFLE_REQUEST_KEY ) ; if ( Util . empty ( json ) ) { return ; } TreeItemIdNode newTree ; try { newTree = TreeItemUtil . convertJsonToTree ( json ) ; } catch ( Exception e ) { LOG . warn ( "Could not parse JSON for shuffle tree items. " + e . getMessage ( ) ) ; return ; } TreeItemIdNode currentTree = getCustomTree ( ) ; boolean changed = ! TreeItemUtil . isTreeSame ( newTree , currentTree ) ; if ( changed ) { setCustomTree ( newTree ) ; final Action action = getShuffleAction ( ) ; if ( action != null ) { final ActionEvent event = new ActionEvent ( this , "shuffle" ) ; Runnable later = new Runnable ( ) { public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; } } } | Handle the tree items that have been shuffled by the client . |
18,946 | private void handleExpandedState ( final Request request ) { String [ ] paramValue = request . getParameterValues ( getId ( ) + OPEN_REQUEST_KEY ) ; if ( paramValue == null ) { paramValue = new String [ 0 ] ; } String [ ] expandedRowIds = removeEmptyStrings ( paramValue ) ; Set < String > newExpansionIds = new HashSet < > ( ) ; if ( expandedRowIds != null ) { int offset = getItemIdPrefix ( ) . length ( ) ; for ( String expandedRowId : expandedRowIds ) { if ( expandedRowId . length ( ) <= offset ) { LOG . warn ( "Expanded row id [" + expandedRowId + "] does not have a valid prefix and will be ignored." ) ; continue ; } String itemId = expandedRowId . substring ( offset ) ; newExpansionIds . add ( itemId ) ; } } setExpandedRows ( newExpansionIds ) ; } | Handle the current expanded state . |
18,947 | private Map < String , List < Integer > > createItemIdIndexMap ( final boolean expandedOnly ) { Map < String , List < Integer > > map = new HashMap < > ( ) ; TreeItemModel treeModel = getTreeModel ( ) ; int rows = treeModel . getRowCount ( ) ; Set < String > expanded = null ; WTree . ExpandMode mode = getExpandMode ( ) ; if ( expandedOnly ) { expanded = getExpandedRows ( ) ; if ( mode == WTree . ExpandMode . LAZY ) { expanded = new HashSet < > ( expanded ) ; expanded . addAll ( getPrevExpandedRows ( ) ) ; } } for ( int i = 0 ; i < rows ; i ++ ) { List < Integer > index = new ArrayList < > ( ) ; index . add ( i ) ; processItemIdIndexMapping ( map , index , treeModel , expanded ) ; } return Collections . unmodifiableMap ( map ) ; } | Map item ids to the row index . |
18,948 | private void processItemIdIndexMapping ( final Map < String , List < Integer > > map , final List < Integer > rowIndex , final TreeItemModel treeModel , final Set < String > expandedRows ) { String id = treeModel . getItemId ( rowIndex ) ; if ( id == null ) { return ; } map . put ( id , rowIndex ) ; if ( ! treeModel . isExpandable ( rowIndex ) ) { return ; } if ( ! treeModel . hasChildren ( rowIndex ) ) { return ; } boolean addChildren = expandedRows == null || expandedRows . contains ( id ) ; if ( ! addChildren ) { return ; } int children = treeModel . getChildCount ( rowIndex ) ; if ( children == 0 ) { return ; } for ( int i = 0 ; i < children ; i ++ ) { List < Integer > nextRow = new ArrayList < > ( rowIndex ) ; nextRow . add ( i ) ; processItemIdIndexMapping ( map , nextRow , treeModel , expandedRows ) ; } } | Iterate through the table model to add the item ids and their row index . |
18,949 | private Map < String , TreeItemIdNode > createCustomIdNodeMapping ( ) { TreeItemIdNode custom = getCustomTree ( ) ; if ( custom == null ) { return Collections . EMPTY_MAP ; } Map < String , TreeItemIdNode > map = new HashMap < > ( ) ; processCustomIdNodeMapping ( map , custom ) ; return Collections . unmodifiableMap ( map ) ; } | Create the map between the custom item id and its node . |
18,950 | private void processCustomIdNodeMapping ( final Map < String , TreeItemIdNode > map , final TreeItemIdNode node ) { String itemId = node . getItemId ( ) ; if ( ! Util . empty ( itemId ) ) { map . put ( itemId , node ) ; } for ( TreeItemIdNode childItem : node . getChildren ( ) ) { processCustomIdNodeMapping ( map , childItem ) ; } } | Iterate over the custom tree structure to add entries to the map . |
18,951 | private Map < String , List < Integer > > createExpandedCustomIdIndexMapping ( final boolean expandedOnly ) { TreeItemIdNode custom = getCustomTree ( ) ; if ( custom == null ) { return Collections . EMPTY_MAP ; } Set < String > expanded = null ; if ( expandedOnly ) { expanded = getExpandedRows ( ) ; } Map < String , List < Integer > > map = new HashMap < > ( ) ; processExpandedCustomIdIndexMapping ( custom , expanded , map ) ; return Collections . unmodifiableMap ( map ) ; } | Crate a map of the expanded custom item ids and their row index . |
18,952 | private void loadCustomNodeChildren ( final TreeItemIdNode node ) { if ( ! node . hasChildren ( ) || ! node . getChildren ( ) . isEmpty ( ) ) { return ; } String itemId = node . getItemId ( ) ; List < Integer > rowIndex = getRowIndexForCustomItemId ( itemId ) ; TreeItemModel model = getTreeModel ( ) ; if ( ! model . isExpandable ( rowIndex ) || ! model . hasChildren ( rowIndex ) ) { node . setHasChildren ( false ) ; return ; } int count = model . getChildCount ( rowIndex ) ; if ( count <= 0 ) { node . setHasChildren ( false ) ; return ; } Map < String , TreeItemIdNode > mapIds = getCustomIdNodeMap ( ) ; boolean childAdded = false ; for ( int i = 0 ; i < count ; i ++ ) { List < Integer > childIdx = new ArrayList < > ( rowIndex ) ; childIdx . add ( i ) ; String childItemId = model . getItemId ( childIdx ) ; if ( mapIds . containsKey ( childItemId ) ) { continue ; } TreeItemIdNode childNode = new TreeItemIdNode ( childItemId ) ; childNode . setHasChildren ( model . hasChildren ( childIdx ) ) ; node . addChild ( childNode ) ; childAdded = true ; if ( childNode . hasChildren ( ) && getExpandMode ( ) == WTree . ExpandMode . CLIENT ) { loadCustomNodeChildren ( childNode ) ; } } if ( ! childAdded ) { node . setHasChildren ( false ) ; } } | Load the children of a custom node that was flagged as having children . |
18,953 | private String getRole ( final WMenuItem item ) { if ( ! item . isSelectAllowed ( ) ) { return null ; } MenuSelectContainer selectContainer = WebUtilities . getAncestorOfClass ( MenuSelectContainer . class , item ) ; if ( selectContainer == null ) { return CHECKBOX_ROLE ; } return MenuSelectContainer . SelectionMode . MULTIPLE . equals ( selectContainer . getSelectionMode ( ) ) ? CHECKBOX_ROLE : RADIO_ROLE ; } | The selection mode of the menu item . |
18,954 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMenuItem item = ( WMenuItem ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:menuitem" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; if ( item . isSubmit ( ) ) { xml . appendAttribute ( "submit" , "true" ) ; } else { xml . appendOptionalUrlAttribute ( "url" , item . getUrl ( ) ) ; xml . appendOptionalAttribute ( "targetWindow" , item . getTargetWindow ( ) ) ; } xml . appendOptionalAttribute ( "disabled" , item . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , item . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "selected" , item . isSelected ( ) , "true" ) ; xml . appendOptionalAttribute ( "role" , getRole ( item ) ) ; xml . appendOptionalAttribute ( "cancel" , item . isCancel ( ) , "true" ) ; xml . appendOptionalAttribute ( "msg" , item . getMessage ( ) ) ; xml . appendOptionalAttribute ( "toolTip" , item . getToolTip ( ) ) ; if ( item . isTopLevelItem ( ) ) { xml . appendOptionalAttribute ( "accessKey" , item . getAccessKeyAsString ( ) ) ; } xml . appendClose ( ) ; item . getDecoratedLabel ( ) . paint ( renderContext ) ; xml . appendEndTag ( "ui:menuitem" ) ; } | Paints the given WMenuItem . |
18,955 | public void show ( ) { StringBuffer out = new StringBuffer ( ) ; for ( Iterator iter = repeater . getBeanList ( ) . iterator ( ) ; iter . hasNext ( ) ; ) { MyData data = ( MyData ) iter . next ( ) ; out . append ( data . getName ( ) ) . append ( " : " ) . append ( data . getCount ( ) ) . append ( '\n' ) ; } selectorText . setText ( out . toString ( ) ) ; } | Show the current list of beans used by the repeater . |
18,956 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMessageBox messageBox = ( WMessageBox ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; if ( messageBox . hasMessages ( ) ) { xml . appendTagOpen ( "ui:messagebox" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; switch ( messageBox . getType ( ) ) { case SUCCESS : xml . appendOptionalAttribute ( "type" , "success" ) ; break ; case INFO : xml . appendOptionalAttribute ( "type" , "info" ) ; break ; case WARN : xml . appendOptionalAttribute ( "type" , "warn" ) ; break ; case ERROR : default : xml . appendOptionalAttribute ( "type" , "error" ) ; break ; } xml . appendOptionalAttribute ( "title" , messageBox . getTitleText ( ) ) ; xml . appendClose ( ) ; for ( String message : messageBox . getMessages ( ) ) { xml . appendTag ( "ui:message" ) ; xml . print ( message ) ; xml . appendEndTag ( "ui:message" ) ; } xml . appendEndTag ( "ui:messagebox" ) ; } } | Paints the given WMessageBox . |
18,957 | protected void preparePaintComponent ( final Request request ) { if ( ! isInitialised ( ) ) { MyDataBean myBean = new MyDataBean ( ) ; myBean . setName ( "My Bean" ) ; myBean . addBean ( new SomeDataBean ( "blah" , "more blah" ) ) ; myBean . addBean ( new SomeDataBean ( ) ) ; repeaterFields . setData ( myBean ) ; setInitialised ( true ) ; } } | Override preparepaint to initialise the data on first acecss by a user . |
18,958 | public void serviceRequest ( final Request request ) { if ( "POST" . equals ( request . getMethod ( ) ) ) { SubordinateControlHelper . applyRegisteredControls ( request , true ) ; } super . serviceRequest ( request ) ; } | Before servicing the request apply the registered subordinate controls to make sure any state changes that have occurred on the client are applied . |
18,959 | public void preparePaint ( final Request request ) { SubordinateControlHelper . clearAllRegisteredControls ( ) ; super . preparePaint ( request ) ; SubordinateControlHelper . applyRegisteredControls ( request , false ) ; } | After the prepare paint phase apply the registered subordinate controls to make sure all the components are in the correct state before being rendered to the client . |
18,960 | public synchronized WComponent getUI ( final Object httpServletRequest ) { String configuredUIClassName = getComponentToLaunchClassName ( ) ; if ( sharedUI == null || ! Util . equals ( configuredUIClassName , uiClassName ) ) { uiClassName = configuredUIClassName ; WComponent ui = createUI ( ) ; if ( ui instanceof WApplication ) { sharedUI = ( WApplication ) ui ; } else { LOG . warn ( "Top-level component should be a WApplication." + " Creating WApplication wrapper..." ) ; sharedUI = new WApplication ( ) ; ui . setLocked ( false ) ; sharedUI . add ( ui ) ; sharedUI . setLocked ( true ) ; } if ( ConfigurationProperties . getLdeServerShowMemoryProfile ( ) ) { ProfileContainer profiler = new ProfileContainer ( ) ; sharedUI . setLocked ( false ) ; sharedUI . add ( profiler ) ; sharedUI . setLocked ( true ) ; } } return sharedUI ; } | This method has been overridden to load a WComponent from parameters . |
18,961 | protected WComponent createUI ( ) { WComponent sharedApp ; uiClassName = getComponentToLaunchClassName ( ) ; if ( uiClassName == null ) { sharedApp = new WText ( "You need to set the class name of the WComponent you want to run.<br />" + "Do this by setting the parameter \"" + COMPONENT_TO_LAUNCH_PARAM_KEY + "\" in your \"local_app.properties\" file.<br />" + "Eg. <code>" + COMPONENT_TO_LAUNCH_PARAM_KEY + "=com.github.bordertech.wcomponents.examples.picker.ExamplePicker</code>" ) ; ( ( WText ) sharedApp ) . setEncodeText ( false ) ; } else { UIRegistry registry = UIRegistry . getInstance ( ) ; sharedApp = registry . getUI ( uiClassName ) ; if ( sharedApp == null ) { sharedApp = new WText ( "Unable to load the component \"" + uiClassName + "\".<br />" + "Either the component does not exist as a resource in the classpath," + " or is not a WComponent.<br />" + "Check that the parameter \"" + COMPONENT_TO_LAUNCH_PARAM_KEY + "\" is set correctly." ) ; ( ( WText ) sharedApp ) . setEncodeText ( false ) ; } } return sharedApp ; } | Creates the UI which the launcher displays . If there is misconfiguration or error a UI containing an error message is returned . |
18,962 | private void createExampleUi ( ) { add ( new WHeading ( HeadingLevel . H2 , "Contacts" ) ) ; add ( repeater ) ; WButton addBtn = new WButton ( "Add" ) ; addBtn . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { addNewContact ( ) ; } } ) ; newNameField . setDefaultSubmitButton ( addBtn ) ; WButton printBtn = new WButton ( "Print" ) ; printBtn . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { printEditedDetails ( ) ; } } ) ; WFieldLayout layout = new WFieldLayout ( ) ; add ( layout ) ; layout . addField ( "New contact name" , newNameField ) ; layout . addField ( ( WLabel ) null , addBtn ) ; layout . addField ( "Print output" , console ) ; layout . addField ( ( WLabel ) null , printBtn ) ; add ( new WAjaxControl ( addBtn , new AjaxTarget [ ] { repeater , newNameField } ) ) ; add ( new WAjaxControl ( printBtn , console ) ) ; } | Add all the required UI artefacts for this example . |
18,963 | private void printEditedDetails ( ) { StringBuilder buf = new StringBuilder ( ) ; for ( Object contact : repeater . getBeanList ( ) ) { buf . append ( contact ) . append ( '\n' ) ; } console . setText ( buf . toString ( ) ) ; } | Write the list of contacts into the textarea console . Any modified phone numbers should be printed out . |
18,964 | public List < ? > getNotSelected ( ) { List options = getOptions ( ) ; if ( options == null || options . isEmpty ( ) ) { return Collections . EMPTY_LIST ; } List notSelected = new ArrayList ( options ) ; notSelected . removeAll ( getSelected ( ) ) ; return Collections . unmodifiableList ( notSelected ) ; } | Returns the options which are not selected . |
18,965 | protected List < ? > getNewSelections ( final Request request ) { String [ ] paramValues = request . getParameterValues ( getId ( ) ) ; if ( paramValues == null || paramValues . length == 0 ) { return NO_SELECTION ; } List < String > values = Arrays . asList ( paramValues ) ; List < Object > newSelections = new ArrayList < > ( values . size ( ) ) ; List < ? > options = getOptions ( ) ; if ( options == null || options . isEmpty ( ) ) { if ( ! isEditable ( ) ) { return NO_SELECTION ; } options = Collections . EMPTY_LIST ; } for ( Object value : values ) { boolean found = false ; int optionIndex = 0 ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { List < ? > groupOptions = ( ( OptionGroup ) option ) . getOptions ( ) ; if ( groupOptions != null ) { for ( Object nestedOption : groupOptions ) { if ( value . equals ( optionToCode ( nestedOption , optionIndex ++ ) ) ) { newSelections . add ( nestedOption ) ; found = true ; break ; } } } } else if ( value . equals ( optionToCode ( option , optionIndex ++ ) ) ) { newSelections . add ( option ) ; found = true ; break ; } } if ( ! found ) { if ( isEditable ( ) ) { newSelections . add ( value ) ; } else { LOG . warn ( "Option \"" + value + "\" on the request is not a valid option. Will be ignored." ) ; } } } if ( newSelections . isEmpty ( ) ) { LOG . warn ( "No options on the request are valid. Will be ignored." ) ; return getValue ( ) ; } if ( ! isAllowNoSelection ( ) && newSelections . size ( ) > 1 ) { List < Object > filtered = new ArrayList < > ( ) ; Object nullOption = null ; for ( Object option : newSelections ) { boolean isNull = option == null ? true : option . toString ( ) . length ( ) == 0 ; if ( isNull ) { nullOption = option ; } else { filtered . add ( option ) ; } } if ( filtered . isEmpty ( ) ) { filtered . add ( nullOption ) ; } return filtered ; } else { return newSelections ; } } | Determines which selections have been added in the given request . |
18,966 | protected void validateComponent ( final List < Diagnostic > diags ) { super . validateComponent ( diags ) ; List < ? > selected = getValue ( ) ; if ( ! selected . isEmpty ( ) ) { int value = selected . size ( ) ; int min = getMinSelect ( ) ; int max = getMaxSelect ( ) ; if ( min > 0 && value < min ) { diags . add ( createErrorDiagnostic ( InternalMessages . DEFAULT_VALIDATION_ERROR_MIN_SELECT , this , min ) ) ; } if ( max > 0 && value > max ) { diags . add ( createErrorDiagnostic ( InternalMessages . DEFAULT_VALIDATION_ERROR_MAX_SELECT , this , max ) ) ; } } } | Override WInput s validateComponent to perform further validation on the options selected . |
18,967 | public void handleRequest ( final Request request ) { String clientState = request . getParameter ( getId ( ) ) ; if ( clientState != null ) { setCollapsed ( clientState . equalsIgnoreCase ( "closed" ) ) ; } } | Override handleRequest to perform processing necessary for this component . This is used to handle the server - side collapsible mode and to synchronise with the client - side state for the other modes . |
18,968 | protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( content != null ) { switch ( getMode ( ) ) { case EAGER : { content . setVisible ( true ) ; AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; break ; } case LAZY : content . setVisible ( ! isCollapsed ( ) ) ; if ( isCollapsed ( ) ) { AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; } break ; case DYNAMIC : { content . setVisible ( ! isCollapsed ( ) ) ; AjaxHelper . registerContainer ( getId ( ) , getId ( ) + "-content" , content . getId ( ) ) ; break ; } case SERVER : { content . setVisible ( ! isCollapsed ( ) ) ; break ; } case CLIENT : { content . setVisible ( true ) ; break ; } default : { throw new SystemException ( "Unknown mode: " + getMode ( ) ) ; } } } } | Override preparePaintComponent in order to toggle the visibility of the content or to register the appropriate ajax operation . |
18,969 | public final void setMax ( final int max ) { if ( max < 0 ) { throw new IllegalArgumentException ( ILLEGAL_MAX ) ; } if ( max != getMax ( ) ) { getOrCreateComponentModel ( ) . max = max ; } } | Sets the maximum value of the progress bar . |
18,970 | public int getValue ( ) { int max = getMax ( ) ; Integer data = ( Integer ) getData ( ) ; return data == null ? 0 : Math . max ( 0 , Math . min ( max , data ) ) ; } | Retrieves the value of the progress bar . |
18,971 | public final void setProgressBarType ( final ProgressBarType type ) { ProgressBarType currentType = getProgressBarType ( ) ; ProgressBarType typeToSet = type == null ? DEFAULT_TYPE : type ; if ( typeToSet != currentType ) { getOrCreateComponentModel ( ) . barType = typeToSet ; } } | Sets the progress bar type . |
18,972 | private void buildControl ( ) { buildControlPanel . reset ( ) ; buildTargetPanel . reset ( ) ; setupTrigger ( ) ; SubordinateTarget target = setupTarget ( ) ; com . github . bordertech . wcomponents . subordinate . Action trueAction ; com . github . bordertech . wcomponents . subordinate . Action falseAction ; switch ( ( ControlActionType ) drpActionType . getSelected ( ) ) { case ENABLE_DISABLE : trueAction = new Enable ( target ) ; falseAction = new Disable ( target ) ; break ; case SHOW_HIDE : trueAction = new Show ( target ) ; falseAction = new Hide ( target ) ; break ; case MAN_OPT : trueAction = new Mandatory ( target ) ; falseAction = new Optional ( target ) ; break ; case SHOWIN_HIDEIN : trueAction = new ShowInGroup ( target , targetGroup ) ; falseAction = new HideInGroup ( target , targetGroup ) ; break ; case ENABLEIN_DISABLEIN : trueAction = new EnableInGroup ( target , targetGroup ) ; falseAction = new DisableInGroup ( target , targetGroup ) ; break ; default : throw new SystemException ( "ControlAction type not valid" ) ; } Condition condition = createCondition ( ) ; if ( cbNot . isSelected ( ) ) { condition = new Not ( condition ) ; } Rule rule = new Rule ( condition , trueAction , falseAction ) ; WSubordinateControl control = new WSubordinateControl ( ) ; control . addRule ( rule ) ; buildControlPanel . add ( control ) ; if ( targetCollapsible . getDecoratedLabel ( ) != null ) { targetCollapsible . getDecoratedLabel ( ) . setTail ( new WText ( control . toString ( ) ) ) ; } control = new WSubordinateControl ( ) ; rule = new Rule ( new Equal ( cbClientDisableTrigger , true ) , new Disable ( ( SubordinateTarget ) trigger ) , new Enable ( ( SubordinateTarget ) trigger ) ) ; control . addRule ( rule ) ; buildControlPanel . add ( control ) ; } | Build the subordinate control . |
18,973 | private void setupTrigger ( ) { String label = drpTriggerType . getSelected ( ) + " Trigger" ; WFieldLayout layout = new WFieldLayout ( ) ; layout . setLabelWidth ( LABEL_WIDTH ) ; buildControlPanel . add ( layout ) ; switch ( ( TriggerType ) drpTriggerType . getSelected ( ) ) { case RadioButtonGroup : trigger = new RadioButtonGroup ( ) ; WFieldSet rbSet = new WFieldSet ( "Select an option" ) ; RadioButtonGroup group = ( RadioButtonGroup ) trigger ; WRadioButton rb1 = group . addRadioButton ( "A" ) ; WRadioButton rb2 = group . addRadioButton ( "B" ) ; WRadioButton rb3 = group . addRadioButton ( "C" ) ; rbSet . add ( group ) ; rbSet . add ( rb1 ) ; rbSet . add ( new WLabel ( "A" , rb1 ) ) ; rbSet . add ( new WText ( "\u00a0" ) ) ; rbSet . add ( rb2 ) ; rbSet . add ( new WLabel ( "B" , rb2 ) ) ; rbSet . add ( new WText ( "\u00a0" ) ) ; rbSet . add ( rb3 ) ; rbSet . add ( new WLabel ( "C" , rb3 ) ) ; layout . addField ( label , rbSet ) ; return ; case CheckBox : trigger = new WCheckBox ( ) ; break ; case CheckBoxSelect : trigger = new WCheckBoxSelect ( LOOKUP_TABLE_NAME ) ; break ; case DateField : trigger = new WDateField ( ) ; break ; case Dropdown : trigger = new WDropdown ( new TableWithNullOption ( LOOKUP_TABLE_NAME ) ) ; break ; case EmailField : trigger = new WEmailField ( ) ; break ; case MultiSelect : trigger = new WMultiSelect ( LOOKUP_TABLE_NAME ) ; break ; case MultiSelectPair : trigger = new WMultiSelectPair ( LOOKUP_TABLE_NAME ) ; break ; case NumberField : trigger = new WNumberField ( ) ; break ; case PartialDateField : trigger = new WPartialDateField ( ) ; break ; case PasswordField : trigger = new WPasswordField ( ) ; break ; case PhoneNumberField : trigger = new WPhoneNumberField ( ) ; break ; case RadioButtonSelect : trigger = new WRadioButtonSelect ( LOOKUP_TABLE_NAME ) ; break ; case SingleSelect : trigger = new WSingleSelect ( LOOKUP_TABLE_NAME ) ; break ; case TextArea : trigger = new WTextArea ( ) ; ( ( WTextArea ) trigger ) . setMaxLength ( 1000 ) ; break ; case TextField : trigger = new WTextField ( ) ; break ; default : throw new SystemException ( "Trigger type not valid" ) ; } layout . addField ( label , trigger ) ; } | Setup the trigger for the subordinate control . |
18,974 | private void setPresets ( ) { TriggerType selectedTrigger = ( TriggerType ) drpTriggerType . getSelected ( ) ; comboField . setVisible ( selectedTrigger != TriggerType . DateField && selectedTrigger != TriggerType . NumberField ) ; dateField . setVisible ( selectedTrigger == TriggerType . DateField ) ; numberField . setVisible ( selectedTrigger == TriggerType . NumberField ) ; switch ( ( ControlActionType ) drpActionType . getSelected ( ) ) { case ENABLEIN_DISABLEIN : case SHOWIN_HIDEIN : drpTargetType . setSelected ( TargetType . WFIELD ) ; drpTargetType . setDisabled ( true ) ; break ; default : drpTargetType . setDisabled ( false ) ; } } | Setup the default values for the configuration options . |
18,975 | public R jsonEqualTo ( String path , Object value ) { expr ( ) . jsonEqualTo ( _name , path , value ) ; return _root ; } | Value at the given JSON path is equal to the given value . |
18,976 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WProgressBar progressBar = ( WProgressBar ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "html:progress" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendAttribute ( "class" , getHtmlClass ( progressBar ) ) ; xml . appendOptionalAttribute ( "hidden" , progressBar . isHidden ( ) , "hidden" ) ; xml . appendOptionalAttribute ( "title" , progressBar . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "aria-label" , progressBar . getAccessibleText ( ) ) ; xml . appendAttribute ( "value" , progressBar . getValue ( ) ) ; xml . appendOptionalAttribute ( "max" , progressBar . getMax ( ) > 0 , progressBar . getMax ( ) ) ; xml . appendClose ( ) ; xml . appendEndTag ( "html:progress" ) ; } | Paints the given WProgressBar . |
18,977 | private void applySettings ( ) { buttonContainer . reset ( ) ; WButton exampleButton = new WButton ( tfButtonLabel . getText ( ) ) ; exampleButton . setRenderAsLink ( cbRenderAsLink . isSelected ( ) ) ; exampleButton . setText ( tfButtonLabel . getText ( ) ) ; if ( cbSetImage . isSelected ( ) ) { exampleButton . setImage ( "/image/pencil.png" ) ; exampleButton . setImagePosition ( ( ImagePosition ) ddImagePosition . getSelected ( ) ) ; } exampleButton . setDisabled ( cbDisabled . isSelected ( ) ) ; if ( tfAccesskey . getText ( ) != null && tfAccesskey . getText ( ) . length ( ) > 0 ) { exampleButton . setAccessKey ( tfAccesskey . getText ( ) . toCharArray ( ) [ 0 ] ) ; } buttonContainer . add ( exampleButton ) ; } | this is were the majority of the work is done for building the button . Note that it is in a container that is reset effectively creating a new button . this is only done to enable to dynamically change the button to a link and back . |
18,978 | public void setLeftColumn ( final String heading , final WComponent content ) { setLeftColumn ( new WHeading ( WHeading . MINOR , heading ) , content ) ; } | Sets the left column content . |
18,979 | public void setRightColumn ( final String heading , final WComponent content ) { setRightColumn ( new WHeading ( WHeading . MINOR , heading ) , content ) ; } | Sets the right column content . |
18,980 | private void setContent ( final WColumn column , final WHeading heading , final WComponent content ) { column . removeAll ( ) ; if ( heading != null ) { column . add ( heading ) ; } if ( content != null ) { column . add ( content ) ; } if ( hasLeftContent ( ) && hasRightContent ( ) ) { leftColumn . setWidth ( 50 ) ; rightColumn . setWidth ( 50 ) ; leftColumn . setVisible ( true ) ; rightColumn . setVisible ( true ) ; } else { leftColumn . setWidth ( 100 ) ; rightColumn . setWidth ( 100 ) ; leftColumn . setVisible ( hasLeftContent ( ) ) ; rightColumn . setVisible ( hasRightContent ( ) ) ; } } | Sets the content of the given column and updates the column widths and visibilities . |
18,981 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTab tab = ( WTab ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:tab" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "open" , tab . isOpen ( ) , "true" ) ; xml . appendOptionalAttribute ( "disabled" , tab . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , tab . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , tab . getToolTip ( ) ) ; switch ( tab . getMode ( ) ) { case CLIENT : xml . appendAttribute ( "mode" , "client" ) ; break ; case LAZY : xml . appendAttribute ( "mode" , "lazy" ) ; break ; case EAGER : xml . appendAttribute ( "mode" , "eager" ) ; break ; case DYNAMIC : xml . appendAttribute ( "mode" , "dynamic" ) ; break ; case SERVER : xml . appendAttribute ( "mode" , "server" ) ; break ; default : throw new SystemException ( "Unknown tab mode: " + tab . getMode ( ) ) ; } if ( tab . getAccessKey ( ) != 0 ) { xml . appendAttribute ( "accessKey" , String . valueOf ( Character . toUpperCase ( tab . getAccessKey ( ) ) ) ) ; } xml . appendClose ( ) ; tab . getTabLabel ( ) . paint ( renderContext ) ; WComponent content = tab . getContent ( ) ; xml . appendTagOpen ( "ui:tabcontent" ) ; xml . appendAttribute ( "id" , tab . getId ( ) + "-content" ) ; xml . appendClose ( ) ; if ( content != null && ( TabMode . EAGER != tab . getMode ( ) || AjaxHelper . isCurrentAjaxTrigger ( tab ) ) ) { content . paint ( renderContext ) ; } xml . appendEndTag ( "ui:tabcontent" ) ; xml . appendEndTag ( "ui:tab" ) ; } | Paints the given WTab . |
18,982 | public String getText ( ) { String text = super . getText ( ) ; FilterTextModel model = getComponentModel ( ) ; if ( text != null && model . search != null && model . replace != null ) { text = text . replaceAll ( model . search , model . replace ) ; } return text ; } | Override in order to filter the encoded text . |
18,983 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTree tree = ( WTree ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; String openId = tree . getOpenRequestItemId ( ) ; if ( openId != null ) { handleOpenItemRequest ( tree , xml , openId ) ; return ; } TreeItemModel model = tree . getTreeModel ( ) ; if ( model == null || model . getRowCount ( ) <= 0 ) { LOG . warn ( "Tree not rendered as it has no items." ) ; return ; } xml . appendTagOpen ( "ui:tree" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "htree" , WTree . Type . HORIZONTAL == tree . getType ( ) , "true" ) ; xml . appendOptionalAttribute ( "multiple" , WTree . SelectMode . MULTIPLE == tree . getSelectMode ( ) , "true" ) ; xml . appendOptionalAttribute ( "disabled" , tree . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , tree . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , tree . isMandatory ( ) , "true" ) ; switch ( tree . getExpandMode ( ) ) { case CLIENT : xml . appendAttribute ( "mode" , "client" ) ; break ; case DYNAMIC : xml . appendAttribute ( "mode" , "dynamic" ) ; break ; case LAZY : xml . appendAttribute ( "mode" , "lazy" ) ; break ; default : throw new IllegalStateException ( "Invalid expand mode: " + tree . getType ( ) ) ; } xml . appendClose ( ) ; MarginRendererUtil . renderMargin ( tree , renderContext ) ; if ( tree . getCustomTree ( ) == null ) { handlePaintItems ( tree , xml ) ; } else { handlePaintCustom ( tree , xml ) ; } DiagnosticRenderUtil . renderDiagnostics ( tree , renderContext ) ; xml . appendEndTag ( "ui:tree" ) ; } | Paints the given WTree . |
18,984 | protected void handleOpenItemRequest ( final WTree tree , final XmlStringBuilder xml , final String itemId ) { TreeItemModel model = tree . getTreeModel ( ) ; Set < String > selectedRows = new HashSet ( tree . getSelectedRows ( ) ) ; WTree . ExpandMode mode = tree . getExpandMode ( ) ; Set < String > expandedRows = new HashSet ( ) ; expandedRows . add ( itemId ) ; if ( tree . getCustomTree ( ) == null ) { List < Integer > rowIndex = tree . getExpandedItemIdIndexMap ( ) . get ( itemId ) ; paintItem ( tree , mode , model , rowIndex , xml , selectedRows , expandedRows ) ; } else { TreeItemIdNode node = tree . getCustomIdNodeMap ( ) . get ( itemId ) ; paintCustomItem ( tree , mode , model , node , xml , selectedRows , expandedRows ) ; } } | Paint the item that was on the open request . |
18,985 | protected void handlePaintItems ( final WTree tree , final XmlStringBuilder xml ) { TreeItemModel model = tree . getTreeModel ( ) ; int rows = model . getRowCount ( ) ; if ( rows > 0 ) { Set < String > selectedRows = new HashSet ( tree . getSelectedRows ( ) ) ; Set < String > expandedRows = new HashSet ( tree . getExpandedRows ( ) ) ; WTree . ExpandMode mode = tree . getExpandMode ( ) ; for ( int i = 0 ; i < rows ; i ++ ) { List < Integer > rowIndex = new ArrayList < > ( ) ; rowIndex . add ( i ) ; paintItem ( tree , mode , model , rowIndex , xml , selectedRows , expandedRows ) ; } } } | Paint the tree items . |
18,986 | protected void paintItem ( final WTree tree , final WTree . ExpandMode mode , final TreeItemModel model , final List < Integer > rowIndex , final XmlStringBuilder xml , final Set < String > selectedRows , final Set < String > expandedRows ) { String itemId = model . getItemId ( rowIndex ) ; boolean selected = selectedRows . remove ( itemId ) ; boolean expandable = model . isExpandable ( rowIndex ) && model . hasChildren ( rowIndex ) ; boolean expanded = expandedRows . remove ( itemId ) ; TreeItemImage image = model . getItemImage ( rowIndex ) ; String url = null ; if ( image != null ) { url = tree . getItemImageUrl ( image , itemId ) ; } xml . appendTagOpen ( "ui:treeitem" ) ; xml . appendAttribute ( "id" , tree . getItemIdPrefix ( ) + itemId ) ; xml . appendAttribute ( "label" , model . getItemLabel ( rowIndex ) ) ; xml . appendOptionalUrlAttribute ( "imageUrl" , url ) ; xml . appendOptionalAttribute ( "selected" , selected , "true" ) ; xml . appendOptionalAttribute ( "expandable" , expandable , "true" ) ; xml . appendOptionalAttribute ( "open" , expandable && expanded , "true" ) ; xml . appendClose ( ) ; if ( expandable && ( mode == WTree . ExpandMode . CLIENT || expanded ) ) { int children = model . getChildCount ( rowIndex ) ; if ( children > 0 ) { for ( int i = 0 ; i < children ; i ++ ) { List < Integer > nextRow = new ArrayList < > ( rowIndex ) ; nextRow . add ( i ) ; paintItem ( tree , mode , model , nextRow , xml , selectedRows , expandedRows ) ; } } } xml . appendEndTag ( "ui:treeitem" ) ; } | Iterate of over the rows to render the tree items . |
18,987 | protected void handlePaintCustom ( final WTree tree , final XmlStringBuilder xml ) { TreeItemModel model = tree . getTreeModel ( ) ; TreeItemIdNode root = tree . getCustomTree ( ) ; Set < String > selectedRows = new HashSet ( tree . getSelectedRows ( ) ) ; Set < String > expandedRows = new HashSet ( tree . getExpandedRows ( ) ) ; WTree . ExpandMode mode = tree . getExpandMode ( ) ; for ( TreeItemIdNode node : root . getChildren ( ) ) { paintCustomItem ( tree , mode , model , node , xml , selectedRows , expandedRows ) ; } } | Paint the custom tree layout . |
18,988 | protected void paintCustomItem ( final WTree tree , final WTree . ExpandMode mode , final TreeItemModel model , final TreeItemIdNode node , final XmlStringBuilder xml , final Set < String > selectedRows , final Set < String > expandedRows ) { String itemId = node . getItemId ( ) ; List < Integer > rowIndex = tree . getRowIndexForCustomItemId ( itemId ) ; boolean selected = selectedRows . remove ( itemId ) ; boolean expandable = node . hasChildren ( ) ; boolean expanded = expandedRows . remove ( itemId ) ; TreeItemImage image = model . getItemImage ( rowIndex ) ; String url = null ; if ( image != null ) { url = tree . getItemImageUrl ( image , itemId ) ; } xml . appendTagOpen ( "ui:treeitem" ) ; xml . appendAttribute ( "id" , tree . getItemIdPrefix ( ) + itemId ) ; xml . appendAttribute ( "label" , model . getItemLabel ( rowIndex ) ) ; xml . appendOptionalUrlAttribute ( "imageUrl" , url ) ; xml . appendOptionalAttribute ( "selected" , selected , "true" ) ; xml . appendOptionalAttribute ( "expandable" , expandable , "true" ) ; xml . appendOptionalAttribute ( "open" , expandable && expanded , "true" ) ; xml . appendClose ( ) ; if ( expandable && ( mode == WTree . ExpandMode . CLIENT || expanded ) ) { for ( TreeItemIdNode childNode : node . getChildren ( ) ) { paintCustomItem ( tree , mode , model , childNode , xml , selectedRows , expandedRows ) ; } } xml . appendEndTag ( "ui:treeitem" ) ; } | Iterate of over the nodes to render the custom layout of the tree items . |
18,989 | private Action buttonAction ( final String preface ) { return new Action ( ) { public void execute ( final ActionEvent event ) { StringBuffer buf = new StringBuffer ( preface ) ; buf . append ( "\n" ) ; for ( Object selected : wTable . getSelectedRows ( ) ) { PersonBean person = ( PersonBean ) selected ; buf . append ( person . toString ( ) ) . append ( "\n" ) ; } selectionText . setText ( buf . toString ( ) ) ; } } ; } | Common action for the table buttons . |
18,990 | public static Map < String , WComponent > mapTaggedComponents ( final Map < String , Object > context , final Map < String , WComponent > taggedComponents ) { Map < String , WComponent > componentsByKey = new HashMap < > ( ) ; for ( Map . Entry < String , WComponent > tagged : taggedComponents . entrySet ( ) ) { String tag = tagged . getKey ( ) ; WComponent comp = tagged . getValue ( ) ; String key = "[WC-TemplateLayout-" + tag + "]" ; componentsByKey . put ( key , comp ) ; context . put ( tag , key ) ; } return componentsByKey ; } | Replace each component tag with the key so it can be used in the replace writer . |
18,991 | public void setHead ( final WComponent head ) { DecoratedLabelModel model = getOrCreateComponentModel ( ) ; if ( model . head != null ) { remove ( model . head ) ; } model . head = head ; if ( head != null ) { add ( head ) ; } } | Sets the label head content . |
18,992 | public void setBody ( final WComponent body ) { DecoratedLabelModel model = getOrCreateComponentModel ( ) ; if ( body == null ) { throw new IllegalArgumentException ( "Body content must not be null" ) ; } if ( model . body != null ) { remove ( model . body ) ; } model . body = body ; add ( body ) ; } | Sets the label body content . |
18,993 | public void setTail ( final WComponent tail ) { DecoratedLabelModel model = getOrCreateComponentModel ( ) ; if ( model . tail != null ) { remove ( model . tail ) ; } model . tail = tail ; if ( tail != null ) { add ( tail ) ; } } | Sets the label tail content . |
18,994 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTimeoutWarning warning = ( WTimeoutWarning ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; final int timoutPeriod = warning . getTimeoutPeriod ( ) ; if ( timoutPeriod > 0 ) { xml . appendTagOpen ( "ui:session" ) ; xml . appendAttribute ( "timeout" , String . valueOf ( timoutPeriod ) ) ; int warningPeriod = warning . getWarningPeriod ( ) ; xml . appendOptionalAttribute ( "warn" , warningPeriod > 0 , warningPeriod ) ; xml . appendEnd ( ) ; } } | Paints the given WTimeoutWarning if the component s timeout period is greater than 0 . |
18,995 | public void render ( final WComponent component , final RenderContext renderContext ) { if ( renderContext instanceof WebXmlRenderContext ) { doRender ( component , ( WebXmlRenderContext ) renderContext ) ; } else { throw new SystemException ( "Unable to render web xml output to " + renderContext ) ; } } | Renders the component . |
18,996 | protected final void paintChildren ( final Container container , final WebXmlRenderContext renderContext ) { final int size = container . getChildCount ( ) ; for ( int i = 0 ; i < size ; i ++ ) { WComponent child = container . getChildAt ( i ) ; child . paint ( renderContext ) ; } } | Paints the children of the given component . |
18,997 | public void logVelocityMessage ( final int level , final String message ) { switch ( level ) { case LogSystem . WARN_ID : LOG . warn ( message ) ; break ; case LogSystem . INFO_ID : LOG . info ( message ) ; break ; case LogSystem . DEBUG_ID : LOG . debug ( message ) ; break ; case LogSystem . ERROR_ID : LOG . error ( message ) ; break ; default : LOG . debug ( message ) ; break ; } } | Log velocity engine messages . |
18,998 | public static String getCombinedForSection ( final String sectionName , final String ... args ) { return getCombinedAutocomplete ( getNamedSection ( sectionName ) , args ) ; } | Combine autocomplete values into a single String suitable to apply to a named auto - fill section . |
18,999 | public void addToGroup ( final T component ) { ComponentGroupModel model = getOrCreateComponentModel ( ) ; model . components . add ( component ) ; MemoryUtil . checkSize ( model . components . size ( ) , this . getClass ( ) . getSimpleName ( ) ) ; } | Add a component to this group . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.