idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
18,900 | @ Override 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 . | 99 | 16 |
18,901 | 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 . | 329 | 14 |
18,902 | public final R inRangeWith ( TQProperty < R > highProperty , T value ) { expr ( ) . inRangeWith ( _name , highProperty . _name , value ) ; return _root ; } | Value in Range between 2 properties . | 45 | 7 |
18,903 | @ Override protected void afterPaint ( final RenderContext renderContext ) { super . afterPaint ( renderContext ) ; // UIC serialization stats 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 ) ; // ObjectProfiler 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 . | 234 | 14 |
18,904 | 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 . | 67 | 10 |
18,905 | 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 . | 112 | 10 |
18,906 | public Map < String , TreeItemIdNode > getCustomIdNodeMap ( ) { // No user context present 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 . | 151 | 25 |
18,907 | public Map < String , List < Integer > > getExpandedItemIdIndexMap ( ) { // CLIENT MODE is include ALL 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 . | 240 | 23 |
18,908 | @ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; // If is an internal AJAX action, set the action type. if ( isCurrentAjaxTrigger ( ) ) { AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; if ( operation . isInternalAjaxRequest ( ) ) { // Want to replace children in the target (Internal defaults to REPLACE target) operation . setAction ( AjaxOperation . AjaxAction . IN ) ; } } // Check if a custom tree needs the expanded rows checked TreeItemIdNode custom = getCustomTree ( ) ; if ( custom != null ) { checkExpandedCustomNodes ( ) ; } // Make sure the ID maps are up to date clearItemIdMaps ( ) ; if ( getExpandMode ( ) == ExpandMode . LAZY ) { if ( AjaxHelper . getCurrentOperation ( ) == null ) { clearPrevExpandedRows ( ) ; } else { addPrevExpandedCurrent ( ) ; } } } | Override preparePaint to register an AJAX operation . | 221 | 11 |
18,909 | protected void checkExpandedCustomNodes ( ) { TreeItemIdNode custom = getCustomTree ( ) ; if ( custom == null ) { return ; } // Get the expanded rows Set < String > expanded = getExpandedRows ( ) ; // Process Top Level for ( TreeItemIdNode node : custom . getChildren ( ) ) { processCheckExpandedCustomNodes ( node , expanded ) ; } } | Check if custom nodes that are expanded need their child nodes added from the model . | 87 | 16 |
18,910 | private void handleItemImageRequest ( final Request request ) { // Check for tree item id String itemId = request . getParameter ( ITEM_REQUEST_KEY ) ; if ( itemId == null ) { throw new SystemException ( "No tree item id provided for image request." ) ; } // Check valid item id 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 . | 198 | 11 |
18,911 | private void handleOpenItemRequest ( final Request request ) { // Check for tree item id String param = request . getParameter ( ITEM_REQUEST_KEY ) ; if ( param == null ) { throw new SystemException ( "No tree item id provided for open request." ) ; } // Remove the prefix to get the item id 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 ) ; // Check is a valid item id if ( ! isValidTreeItem ( itemId ) ) { throw new SystemException ( "Tree item id [" + itemId + "] is not valid." ) ; } // Check expandable 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." ) ; } } // Save the open id setOpenRequestItemId ( itemId ) ; // Run the open action (if set) final Action action = getOpenAction ( ) ; if ( action != null ) { final ActionEvent event = new ActionEvent ( this , "openItem" ) ; Runnable later = new Runnable ( ) { @ Override public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; } } | Handles a request containing an open request . | 424 | 9 |
18,912 | private void handleShuffleState ( final Request request ) { String json = request . getParameter ( SHUFFLE_REQUEST_KEY ) ; if ( Util . empty ( json ) ) { return ; } // New TreeItemIdNode newTree ; try { newTree = TreeItemUtil . convertJsonToTree ( json ) ; } catch ( Exception e ) { LOG . warn ( "Could not parse JSON for shuffle tree items. " + e . getMessage ( ) ) ; return ; } // Current TreeItemIdNode currentTree = getCustomTree ( ) ; boolean changed = ! TreeItemUtil . isTreeSame ( newTree , currentTree ) ; if ( changed ) { setCustomTree ( newTree ) ; // Run the shuffle action (if set) final Action action = getShuffleAction ( ) ; if ( action != null ) { final ActionEvent event = new ActionEvent ( this , "shuffle" ) ; Runnable later = new Runnable ( ) { @ Override public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; } } } | Handle the tree items that have been shuffled by the client . | 238 | 13 |
18,913 | 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 ; } // Remove prefix to get item id String itemId = expandedRowId . substring ( offset ) ; // Assume the item id is valid newExpansionIds . add ( itemId ) ; } } setExpandedRows ( newExpansionIds ) ; } | Handle the current expanded state . | 231 | 6 |
18,914 | 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 . | 212 | 9 |
18,915 | private void processItemIdIndexMapping ( final Map < String , List < Integer > > map , final List < Integer > rowIndex , final TreeItemModel treeModel , final Set < String > expandedRows ) { // Add current item String id = treeModel . getItemId ( rowIndex ) ; if ( id == null ) { return ; } map . put ( id , rowIndex ) ; // Check row is expandable if ( ! treeModel . isExpandable ( rowIndex ) ) { return ; } // Check has children if ( ! treeModel . hasChildren ( rowIndex ) ) { return ; } // Add children if expanded ROWS null or contains ID boolean addChildren = expandedRows == null || expandedRows . contains ( id ) ; if ( ! addChildren ) { return ; } // Get actual child count int children = treeModel . getChildCount ( rowIndex ) ; if ( children == 0 ) { // Could be there are no children even though hasChildren returned true return ; } // Add children by processing each child row for ( int i = 0 ; i < children ; i ++ ) { // Add next level 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 . | 286 | 17 |
18,916 | 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 . | 90 | 12 |
18,917 | 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 . | 97 | 14 |
18,918 | 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 . | 125 | 16 |
18,919 | private void loadCustomNodeChildren ( final TreeItemIdNode node ) { // Check node was flagged as having children or already has children if ( ! node . hasChildren ( ) || ! node . getChildren ( ) . isEmpty ( ) ) { return ; } // Get the row index for the node String itemId = node . getItemId ( ) ; List < Integer > rowIndex = getRowIndexForCustomItemId ( itemId ) ; // Get the tree item model TreeItemModel model = getTreeModel ( ) ; // Check tree item is expandable and has children if ( ! model . isExpandable ( rowIndex ) || ! model . hasChildren ( rowIndex ) ) { node . setHasChildren ( false ) ; return ; } // Check actual child count (could have no children even though hasChildren returned true) int count = model . getChildCount ( rowIndex ) ; if ( count <= 0 ) { node . setHasChildren ( false ) ; return ; } // Get the map of item ids already in the custom tree Map < String , TreeItemIdNode > mapIds = getCustomIdNodeMap ( ) ; // Add children of item to the node tree boolean childAdded = false ; for ( int i = 0 ; i < count ; i ++ ) { List < Integer > childIdx = new ArrayList <> ( rowIndex ) ; childIdx . add ( i ) ; String childItemId = model . getItemId ( childIdx ) ; // Check the child item is not already in the custom tree if ( mapIds . containsKey ( childItemId ) ) { continue ; } TreeItemIdNode childNode = new TreeItemIdNode ( childItemId ) ; childNode . setHasChildren ( model . hasChildren ( childIdx ) ) ; node . addChild ( childNode ) ; childAdded = true ; // For client mode we have to drill down all the children if ( childNode . hasChildren ( ) && getExpandMode ( ) == WTree . ExpandMode . CLIENT ) { loadCustomNodeChildren ( childNode ) ; } } // This could happen if all the children have been used in the custom map if ( ! childAdded ) { node . setHasChildren ( false ) ; } } | Load the children of a custom node that was flagged as having children . | 475 | 14 |
18,920 | 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 . | 112 | 8 |
18,921 | @ Override 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 . | 412 | 8 |
18,922 | 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 ( ' ' ) ; } selectorText . setText ( out . toString ( ) ) ; } | Show the current list of beans used by the repeater . | 110 | 12 |
18,923 | @ Override 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 . | 323 | 8 |
18,924 | @ Override 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 . | 119 | 17 |
18,925 | @ Override public void serviceRequest ( final Request request ) { // Only apply for POST if ( "POST" . equals ( request . getMethod ( ) ) ) { // Apply Controls (Use values on request) SubordinateControlHelper . applyRegisteredControls ( request , true ) ; } // Service Request 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 . | 72 | 24 |
18,926 | @ Override public void preparePaint ( final Request request ) { // Clear all registered controls on Session SubordinateControlHelper . clearAllRegisteredControls ( ) ; super . preparePaint ( request ) ; // Apply Controls (Use values from the component models) 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 . | 70 | 28 |
18,927 | @ Override 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 . | 231 | 14 |
18,928 | protected WComponent createUI ( ) { // Check if the parameter COMPONENT_TO_LAUNCH_PARAM_KEY has been // configured with the name of a component to launch. 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 . | 355 | 26 |
18,929 | private void createExampleUi ( ) { add ( new WHeading ( HeadingLevel . H2 , "Contacts" ) ) ; add ( repeater ) ; WButton addBtn = new WButton ( "Add" ) ; addBtn . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { addNewContact ( ) ; } } ) ; newNameField . setDefaultSubmitButton ( addBtn ) ; WButton printBtn = new WButton ( "Print" ) ; printBtn . setAction ( new Action ( ) { @ Override 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 ) ; // Ajax controls to make things zippier add ( new WAjaxControl ( addBtn , new AjaxTarget [ ] { repeater , newNameField } ) ) ; add ( new WAjaxControl ( printBtn , console ) ) ; } | Add all the required UI artefacts for this example . | 282 | 11 |
18,930 | private void printEditedDetails ( ) { StringBuilder buf = new StringBuilder ( ) ; for ( Object contact : repeater . getBeanList ( ) ) { buf . append ( contact ) . append ( ' ' ) ; } console . setText ( buf . toString ( ) ) ; } | Write the list of contacts into the textarea console . Any modified phone numbers should be printed out . | 62 | 20 |
18,931 | 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 . | 83 | 8 |
18,932 | 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 ( ) ) ; // Figure out which options have been selected. List < ? > options = getOptions ( ) ; if ( options == null || options . isEmpty ( ) ) { if ( ! isEditable ( ) ) { // User could not have made a selection. 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 no valid options found, then return the current settings if ( newSelections . isEmpty ( ) ) { LOG . warn ( "No options on the request are valid. Will be ignored." ) ; return getValue ( ) ; } // If must have selection and more than 1 option selected, remove the "null" entry if it was selected. if ( ! isAllowNoSelection ( ) && newSelections . size ( ) > 1 ) { List < Object > filtered = new ArrayList <> ( ) ; Object nullOption = null ; for ( Object option : newSelections ) { // Check option is null or empty boolean isNull = option == null ? true : option . toString ( ) . length ( ) == 0 ; if ( isNull ) { // Hold the option as it could be "null" or "empty" nullOption = option ; } else { filtered . add ( option ) ; } } // In the case where only null options were selected, then add one nullOption if ( filtered . isEmpty ( ) ) { filtered . add ( nullOption ) ; } return filtered ; } else { return newSelections ; } } | Determines which selections have been added in the given request . | 612 | 13 |
18,933 | @ Override protected void validateComponent ( final List < Diagnostic > diags ) { super . validateComponent ( diags ) ; List < ? > selected = getValue ( ) ; // Only validate max and min if options have been selected 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 . | 181 | 15 |
18,934 | @ Override 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 . | 56 | 38 |
18,935 | @ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( content != null ) { switch ( getMode ( ) ) { case EAGER : { // Always visible 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 : { // Will always be visible 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 . | 267 | 24 |
18,936 | 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 . | 58 | 10 |
18,937 | 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 . | 50 | 10 |
18,938 | 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 . | 73 | 7 |
18,939 | private void buildControl ( ) { buildControlPanel . reset ( ) ; buildTargetPanel . reset ( ) ; // Setup Trigger setupTrigger ( ) ; // Create target SubordinateTarget target = setupTarget ( ) ; // Create Actions 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" ) ; } // Create Condition Condition condition = createCondition ( ) ; if ( cbNot . isSelected ( ) ) { condition = new Not ( condition ) ; } // Create Rule Rule rule = new Rule ( condition , trueAction , falseAction ) ; // Create Subordinate 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 . | 478 | 5 |
18,940 | 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 . | 660 | 8 |
18,941 | 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 ) ; // If a group action selected, then target can only be the field (as it is defined in a group) 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 . | 194 | 9 |
18,942 | 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 . | 36 | 13 |
18,943 | @ Override 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 . | 233 | 8 |
18,944 | 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 . | 208 | 48 |
18,945 | public void setLeftColumn ( final String heading , final WComponent content ) { setLeftColumn ( new WHeading ( WHeading . MINOR , heading ) , content ) ; } | Sets the left column content . | 39 | 7 |
18,946 | public void setRightColumn ( final String heading , final WComponent content ) { setRightColumn ( new WHeading ( WHeading . MINOR , heading ) , content ) ; } | Sets the right column content . | 39 | 7 |
18,947 | 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 ) ; } // Update column widths & visibility if ( hasLeftContent ( ) && hasRightContent ( ) ) { // Set columns 50% leftColumn . setWidth ( 50 ) ; rightColumn . setWidth ( 50 ) ; // Set both visible leftColumn . setVisible ( true ) ; rightColumn . setVisible ( true ) ; } else { // Set columns 100% (only one visible) leftColumn . setWidth ( 100 ) ; rightColumn . setWidth ( 100 ) ; // Set visibility leftColumn . setVisible ( hasLeftContent ( ) ) ; rightColumn . setVisible ( hasRightContent ( ) ) ; } } | Sets the content of the given column and updates the column widths and visibilities . | 192 | 18 |
18,948 | @ Override 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 ( ) ; // Paint label tab . getTabLabel ( ) . paint ( renderContext ) ; // Paint content WComponent content = tab . getContent ( ) ; xml . appendTagOpen ( "ui:tabcontent" ) ; xml . appendAttribute ( "id" , tab . getId ( ) + "-content" ) ; xml . appendClose ( ) ; // Render content if not EAGER Mode or is EAGER and is the current AJAX trigger if ( content != null && ( TabMode . EAGER != tab . getMode ( ) || AjaxHelper . isCurrentAjaxTrigger ( tab ) ) ) { // Visibility of content set in prepare paint content . paint ( renderContext ) ; } xml . appendEndTag ( "ui:tabcontent" ) ; xml . appendEndTag ( "ui:tab" ) ; } | Paints the given WTab . | 576 | 7 |
18,949 | @ Override 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 . | 71 | 9 |
18,950 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTree tree = ( WTree ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; // Check if rendering an open item request String openId = tree . getOpenRequestItemId ( ) ; if ( openId != null ) { handleOpenItemRequest ( tree , xml , openId ) ; return ; } // Check the tree has tree items (WCAG requirement) 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 ( ) ; // Render margin 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 . | 558 | 7 |
18,951 | 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 ( ) ; // Only want to render the children of the "open item" so only include the open item id in the expanded rows 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 . | 236 | 11 |
18,952 | 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 . | 177 | 6 |
18,953 | 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 ) ) { // Get actual child count int children = model . getChildCount ( rowIndex ) ; if ( children > 0 ) { for ( int i = 0 ; i < children ; i ++ ) { // Add next level 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 . | 428 | 12 |
18,954 | 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 ( ) ; // Process root nodes for ( TreeItemIdNode node : root . getChildren ( ) ) { paintCustomItem ( tree , mode , model , node , xml , selectedRows , expandedRows ) ; } } | Paint the custom tree layout . | 154 | 7 |
18,955 | 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 ( ) ; // Paint child items 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 . | 386 | 16 |
18,956 | private Action buttonAction ( final String preface ) { return new Action ( ) { @ Override public void execute ( final ActionEvent event ) { StringBuffer buf = new StringBuffer ( preface ) ; buf . append ( "\n" ) ; for ( Object selected : wTable . getSelectedRows ( ) ) { // The Model uses the "bean" as the key PersonBean person = ( PersonBean ) selected ; buf . append ( person . toString ( ) ) . append ( "\n" ) ; } selectionText . setText ( buf . toString ( ) ) ; } } ; } | Common action for the table buttons . | 129 | 7 |
18,957 | public static Map < String , WComponent > mapTaggedComponents ( final Map < String , Object > context , final Map < String , WComponent > taggedComponents ) { Map < String , WComponent > componentsByKey = new HashMap <> ( ) ; // Replace each component tag with the key so it can be used in the replace writer for ( Map . Entry < String , WComponent > tagged : taggedComponents . entrySet ( ) ) { String tag = tagged . getKey ( ) ; WComponent comp = tagged . getValue ( ) ; // The key needs to be something which would never be output by a Template. String key = "[WC-TemplateLayout-" + tag + "]" ; componentsByKey . put ( key , comp ) ; // Map the tag to the key in the context context . put ( tag , key ) ; } return componentsByKey ; } | Replace each component tag with the key so it can be used in the replace writer . | 185 | 18 |
18,958 | 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 . | 63 | 7 |
18,959 | 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 . | 80 | 7 |
18,960 | 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 . | 64 | 7 |
18,961 | @ Override 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 . | 153 | 18 |
18,962 | @ Override 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 . | 73 | 5 |
18,963 | 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 . | 70 | 9 |
18,964 | @ Override 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 . | 105 | 5 |
18,965 | 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 . | 41 | 21 |
18,966 | 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 . | 63 | 7 |
18,967 | private static WComponent loadUI ( final String key ) { String classname = key . trim ( ) ; try { Class < ? > clas = Class . forName ( classname ) ; if ( WComponent . class . isAssignableFrom ( clas ) ) { WComponent instance = ( WComponent ) clas . newInstance ( ) ; LOG . debug ( "WComponent successfully loaded with class name \"" + classname + "\"." ) ; return instance ; } else { throw new SystemException ( "The resource with the name \"" + classname + "\" is not a WComponent." ) ; } } catch ( Exception ex ) { LOG . error ( "Unable to load a WComponent using the resource name \"" + classname + "\"" , ex ) ; // Are we in developer friendly error mode? boolean friendly = ConfigurationProperties . getDeveloperErrorHandling ( ) ; FatalErrorPageFactory factory = Factory . newInstance ( FatalErrorPageFactory . class ) ; WComponent errorPage = factory . createErrorPage ( friendly , ex ) ; return errorPage ; } } | Attempts to load a UI using the key as a class name . | 232 | 13 |
18,968 | private void addList ( final WList . Type type , final WList . Separator separator , final boolean renderBorder , final WComponent renderer ) { WList list = new WList ( type ) ; if ( separator != null ) { list . setSeparator ( separator ) ; } list . setRenderBorder ( renderBorder ) ; list . setRepeatedComponent ( renderer ) ; add ( list ) ; lists . add ( list ) ; } | Adds a list to the example . | 99 | 7 |
18,969 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMenu menu = ( WMenu ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; int rows = menu . getRows ( ) ; xml . appendTagOpen ( "ui:menu" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; switch ( menu . getType ( ) ) { case BAR : xml . appendAttribute ( "type" , "bar" ) ; break ; case FLYOUT : xml . appendAttribute ( "type" , "flyout" ) ; break ; case TREE : xml . appendAttribute ( "type" , "tree" ) ; break ; case COLUMN : xml . appendAttribute ( "type" , "column" ) ; break ; default : throw new IllegalStateException ( "Invalid menu type: " + menu . getType ( ) ) ; } xml . appendOptionalAttribute ( "disabled" , menu . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , menu . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "rows" , rows > 0 , rows ) ; switch ( menu . getSelectionMode ( ) ) { case NONE : break ; case SINGLE : xml . appendAttribute ( "selectMode" , "single" ) ; break ; case MULTIPLE : xml . appendAttribute ( "selectMode" , "multiple" ) ; break ; default : throw new IllegalStateException ( "Invalid select mode: " + menu . getSelectMode ( ) ) ; } xml . appendClose ( ) ; // Render margin MarginRendererUtil . renderMargin ( menu , renderContext ) ; paintChildren ( menu , renderContext ) ; xml . appendEndTag ( "ui:menu" ) ; } | Paints the given WMenu . | 448 | 7 |
18,970 | public SearchInAppResponse searchInApp ( int appId , String query , Boolean counts , Boolean highlights , Integer limit , Integer offset , ReferenceTypeSearchInApp refType , String searchFields ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/search/app/" + appId + "/v2" ) ; resource = resource . queryParam ( "query" , query ) ; if ( counts != null ) { resource = resource . queryParam ( "counts" , counts ? "1" : "0" ) ; } if ( highlights != null ) { resource = resource . queryParam ( "highlights" , highlights ? "1" : "0" ) ; } if ( limit != null ) { resource = resource . queryParam ( "limit" , limit . toString ( ) ) ; } if ( offset != null ) { resource = resource . queryParam ( "offset" , offset . toString ( ) ) ; } if ( refType != null ) { resource = resource . queryParam ( "ref_type" , refType . toString ( ) ) ; } if ( searchFields != null && ! searchFields . equals ( "" ) ) { resource = resource . queryParam ( "search_fields" , searchFields ) ; } return resource . get ( SearchInAppResponse . class ) ; } | Searches in all items files and tasks in the application . The objects will be returned sorted descending by the time the object had any update . | 285 | 29 |
18,971 | private void renderOption ( final WMultiSelect listBox , final Object option , final int optionIndex , final XmlStringBuilder html , final List < ? > selections , final boolean renderSelectionsOnly ) { boolean selected = selections . contains ( option ) ; if ( selected || ! renderSelectionsOnly ) { // Get Code and Desc String code = listBox . getCode ( option , optionIndex ) ; String desc = listBox . getDesc ( option , optionIndex ) ; // Render Option html . appendTagOpen ( "ui:option" ) ; html . appendAttribute ( "value" , code ) ; html . appendOptionalAttribute ( "selected" , selected , "true" ) ; html . appendClose ( ) ; html . appendEscaped ( desc ) ; html . appendEndTag ( "ui:option" ) ; } } | Renders a single option within the list box . | 175 | 10 |
18,972 | @ Override public void paint ( final RenderContext renderContext ) { super . paint ( renderContext ) ; if ( ! DebugUtil . isDebugFeaturesEnabled ( ) || ! ( renderContext instanceof WebXmlRenderContext ) ) { return ; } XmlStringBuilder xml = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; xml . appendTag ( "ui:debug" ) ; writeDebugInfo ( getUI ( ) , xml ) ; xml . appendEndTag ( "ui:debug" ) ; } | Override paint to render additional information for debugging purposes . | 114 | 10 |
18,973 | protected void writeDebugInfo ( final WComponent component , final XmlStringBuilder xml ) { if ( component != null && ( component . isVisible ( ) || component instanceof WInvisibleContainer ) ) { xml . appendTagOpen ( "ui:debugInfo" ) ; xml . appendAttribute ( "for" , component . getId ( ) ) ; xml . appendAttribute ( "class" , component . getClass ( ) . getName ( ) ) ; xml . appendOptionalAttribute ( "type" , getType ( component ) ) ; xml . appendClose ( ) ; xml . appendTagOpen ( "ui:debugDetail" ) ; xml . appendAttribute ( "key" , "defaultState" ) ; xml . appendAttribute ( "value" , component . isDefaultState ( ) ) ; xml . appendEnd ( ) ; xml . appendEndTag ( "ui:debugInfo" ) ; if ( component instanceof WRepeater ) { // special case for WRepeaters - we must paint the info for each row. WRepeater repeater = ( WRepeater ) component ; List < UIContext > contexts = repeater . getRowContexts ( ) ; for ( int i = 0 ; i < contexts . size ( ) ; i ++ ) { UIContextHolder . pushContext ( contexts . get ( i ) ) ; try { writeDebugInfo ( repeater . getRepeatedComponent ( i ) , xml ) ; } finally { UIContextHolder . popContext ( ) ; } } } else if ( component instanceof WCardManager ) { writeDebugInfo ( ( ( WCardManager ) component ) . getVisible ( ) , xml ) ; } else if ( component instanceof Container ) { final int size = ( ( Container ) component ) . getChildCount ( ) ; for ( int i = 0 ; i < size ; i ++ ) { writeDebugInfo ( ( ( Container ) component ) . getChildAt ( i ) , xml ) ; } } } } | Writes debugging information for the given component . | 424 | 9 |
18,974 | private String getType ( final WComponent component ) { for ( Class < ? > clazz = component . getClass ( ) ; clazz != null && WComponent . class . isAssignableFrom ( clazz ) ; clazz = clazz . getSuperclass ( ) ) { if ( "com.github.bordertech.wcomponents" . equals ( clazz . getPackage ( ) . getName ( ) ) ) { return clazz . getName ( ) ; } } return null ; } | Tries to return the type of component . | 107 | 9 |
18,975 | public static void deserializeSessionAttributes ( final HttpSession session ) { File file = new File ( SERIALIZE_SESSION_NAME ) ; FileInputStream fis = null ; ObjectInputStream ois = null ; if ( file . canRead ( ) ) { try { fis = new FileInputStream ( file ) ; ois = new ObjectInputStream ( fis ) ; List data = ( List ) ois . readObject ( ) ; for ( Iterator i = data . iterator ( ) ; i . hasNext ( ) ; ) { String key = ( String ) i . next ( ) ; Object value = i . next ( ) ; session . setAttribute ( key , value ) ; } } catch ( Exception e ) { LOG . error ( "Failed to read serialized session from " + file , e ) ; } finally { if ( ois != null ) { StreamUtil . safeClose ( ois ) ; } else { StreamUtil . safeClose ( fis ) ; } } } else { LOG . warn ( "Unable to read serialized session from " + file ) ; } } | Attempts to deserialize the persisted session attributes into the given session . | 238 | 14 |
18,976 | public static synchronized void serializeSessionAttributes ( final HttpSession session ) { if ( session != null ) { File file = new File ( SERIALIZE_SESSION_NAME ) ; if ( ! file . exists ( ) || file . canWrite ( ) ) { // Retrieve the session attributes List data = new ArrayList ( ) ; for ( Enumeration keyEnum = session . getAttributeNames ( ) ; keyEnum . hasMoreElements ( ) ; ) { String attributeName = ( String ) keyEnum . nextElement ( ) ; Object attributeValue = session . getAttribute ( attributeName ) ; if ( attributeValue instanceof Serializable ) { data . add ( attributeName ) ; data . add ( attributeValue ) ; } else { LOG . error ( "Skipping attribute \"" + attributeName + "\" as it is not Serializable" ) ; } } // Write them to the file FileOutputStream fos = null ; ObjectOutputStream oos = null ; try { fos = new FileOutputStream ( file ) ; oos = new ObjectOutputStream ( fos ) ; oos . writeObject ( data ) ; } catch ( Exception e ) { LOG . error ( "Failed to write serialized session to " + file , e ) ; } finally { if ( oos != null ) { StreamUtil . safeClose ( oos ) ; } else { StreamUtil . safeClose ( fos ) ; } } } else { LOG . warn ( "Unable to write serialized session to " + file ) ; } } } | Serializes the session attributes of the given session . | 332 | 10 |
18,977 | public static void incrementSessionStep ( final UIContext uic ) { int step = uic . getEnvironment ( ) . getStep ( ) ; uic . getEnvironment ( ) . setStep ( step + 1 ) ; } | Increments the step that is recorded in session . | 49 | 10 |
18,978 | public static int getRequestStep ( final Request request ) { String val = request . getParameter ( Environment . STEP_VARIABLE ) ; if ( val == null ) { return 0 ; } try { return Integer . parseInt ( val ) ; } catch ( NumberFormatException ex ) { return - 1 ; } } | Retrieves the value of the step variable from the given request . | 67 | 14 |
18,979 | public static boolean isStepOnRequest ( final Request request ) { String val = request . getParameter ( Environment . STEP_VARIABLE ) ; return val != null ; } | Checks if the step count is on the request . | 37 | 11 |
18,980 | public static boolean isCachedContentRequest ( final Request request ) { // Get target id on request String targetId = request . getParameter ( Environment . TARGET_ID ) ; if ( targetId == null ) { return false ; } // Get target ComponentWithContext targetWithContext = WebUtilities . getComponentById ( targetId , true ) ; if ( targetWithContext == null ) { return false ; } // Check for caching key WComponent target = targetWithContext . getComponent ( ) ; UIContextHolder . pushContext ( targetWithContext . getContext ( ) ) ; try { // TODO Look at implementing CacheableTarget interface String key = null ; if ( target instanceof WContent ) { key = ( ( WContent ) target ) . getCacheKey ( ) ; } else if ( target instanceof WImage ) { key = ( ( WImage ) target ) . getCacheKey ( ) ; } else if ( target instanceof WVideo ) { key = ( ( WVideo ) target ) . getCacheKey ( ) ; } else if ( target instanceof WAudio ) { key = ( ( WAudio ) target ) . getCacheKey ( ) ; } return ! Util . empty ( key ) ; } finally { UIContextHolder . popContext ( ) ; } } | Check if the request is for cached content . | 275 | 9 |
18,981 | private synchronized HttpSubSession getSubSession ( ) { HttpSession backingSession = super . getSession ( ) ; Map < Integer , HttpSubSession > subsessions = ( Map < Integer , HttpSubSession > ) backingSession . getAttribute ( SESSION_MAP_KEY ) ; HttpSubSession subsession = subsessions . get ( sessionId ) ; subsession . setLastAccessedTime ( System . currentTimeMillis ( ) ) ; return subsession ; } | Retrieves the subsession for this request . If there is no existing subsession a new one is created . | 102 | 23 |
18,982 | private void addSubordinate ( ) { // Set up subordinate (to make mandatory/optional) WComponentGroup < SubordinateTarget > inputs = new WComponentGroup <> ( ) ; add ( inputs ) ; inputs . addToGroup ( checkBoxSelect ) ; inputs . addToGroup ( multiDropdown ) ; inputs . addToGroup ( multiSelect ) ; inputs . addToGroup ( multiSelectPair ) ; inputs . addToGroup ( dropdown ) ; inputs . addToGroup ( radioButtonSelect ) ; inputs . addToGroup ( singleSelect ) ; inputs . addToGroup ( checkBox ) ; inputs . addToGroup ( dateField ) ; inputs . addToGroup ( emailField ) ; inputs . addToGroup ( fileWidget ) ; inputs . addToGroup ( multiFileWidget ) ; inputs . addToGroup ( multiTextField ) ; inputs . addToGroup ( numberField ) ; inputs . addToGroup ( partialDateField ) ; inputs . addToGroup ( phoneNumberField ) ; inputs . addToGroup ( radioButton ) ; inputs . addToGroup ( shuffler ) ; inputs . addToGroup ( textField ) ; inputs . addToGroup ( textArea ) ; inputs . addToGroup ( radioButton1 ) ; inputs . addToGroup ( radioButton2 ) ; inputs . addToGroup ( radioButton3 ) ; WSubordinateControl control = new WSubordinateControl ( ) ; add ( control ) ; // Mandatory Rule rule = new Rule ( ) ; rule . setCondition ( new Equal ( mandatory , "true" ) ) ; rule . addActionOnTrue ( new Mandatory ( inputs ) ) ; rule . addActionOnFalse ( new Optional ( inputs ) ) ; control . addRule ( rule ) ; // Disabled rule = new Rule ( ) ; rule . setCondition ( new Equal ( disabled , "true" ) ) ; rule . addActionOnTrue ( new Disable ( inputs ) ) ; rule . addActionOnFalse ( new Enable ( inputs ) ) ; control . addRule ( rule ) ; } | Setup the subordinate control . | 428 | 5 |
18,983 | private void addButtons ( ) { // Validation Button WButton buttonValidate = new WButton ( "Validate and Update Bean" ) ; add ( buttonValidate ) ; buttonValidate . setAction ( new ValidatingAction ( messages . getValidationErrors ( ) , layout ) { @ Override public void executeOnValid ( final ActionEvent event ) { WebUtilities . updateBeanValue ( layout ) ; messages . success ( "OK" ) ; } } ) ; // Update Bean WButton buttonUpdate = new WButton ( "Update Bean" ) ; add ( buttonUpdate ) ; buttonUpdate . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { WebUtilities . updateBeanValue ( layout ) ; } } ) ; // Reset Inputs WButton buttonReset = new WButton ( "Reset Inputs" ) ; add ( buttonReset ) ; buttonReset . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { layout . reset ( ) ; } } ) ; // Reset Bean WButton buttonBean = new WButton ( "Reset Bean" ) ; add ( buttonBean ) ; buttonBean . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { InputBeanBindingExample . this . setBean ( new MyDemoBean ( ) ) ; } } ) ; add ( new WButton ( "submit" ) ) ; } | Setup the action buttons . | 323 | 5 |
18,984 | @ Override public String getWServletPath ( ) { final String configValue = ConfigurationProperties . getServletSupportPath ( ) ; return configValue == null ? getPostPath ( ) : getServletPath ( configValue ) ; } | Construct the path to the support servlet . Web components that need to construct a URL to target this servlet will use this method . | 52 | 27 |
18,985 | private String getServletPath ( final String relativePath ) { if ( relativePath == null ) { LOG . error ( "relativePath must not be null" ) ; } String context = getHostFreeBaseUrl ( ) ; if ( ! Util . empty ( context ) ) { return context + relativePath ; } return relativePath ; } | Constructs the path to one of the various helper servlets . This is used by the more specific getXXXPath methods . | 71 | 25 |
18,986 | private static WComponent build ( ) { WContainer root = new WContainer ( ) ; WSubordinateControl control = new WSubordinateControl ( ) ; root . add ( control ) ; WFieldLayout layout = new WFieldLayout ( ) ; layout . setLabelWidth ( 25 ) ; layout . setMargin ( new com . github . bordertech . wcomponents . Margin ( 0 , 0 , 12 , 0 ) ) ; WCheckBox checkBox = new WCheckBox ( ) ; layout . addField ( "Set Mandatory" , checkBox ) ; WTextField text = new WTextField ( ) ; layout . addField ( "Might need this field" , text ) ; WTextField mandatoryField = new WTextField ( ) ; layout . addField ( "Another field always mandatory" , mandatoryField ) ; mandatoryField . setMandatory ( true ) ; final WRadioButtonSelect rbSelect = new WRadioButtonSelect ( "australian_state" ) ; layout . addField ( "Select a state" , rbSelect ) ; root . add ( layout ) ; Rule rule = new Rule ( ) ; rule . setCondition ( new Equal ( checkBox , Boolean . TRUE . toString ( ) ) ) ; rule . addActionOnTrue ( new Mandatory ( text ) ) ; rule . addActionOnFalse ( new Optional ( text ) ) ; rule . addActionOnTrue ( new Mandatory ( rbSelect ) ) ; rule . addActionOnFalse ( new Optional ( rbSelect ) ) ; control . addRule ( rule ) ; return root ; } | Creates the component to be added to the validation container . This is doen in a static method because the component is passed into the superclass constructor . | 337 | 31 |
18,987 | @ Override public void paint ( final RenderContext renderContext ) { // Check interceptor is enabled if ( ! DebugValidateXML . isEnabled ( ) ) { super . paint ( renderContext ) ; return ; } if ( ! ( renderContext instanceof WebXmlRenderContext ) ) { LOG . warn ( "Unable to validate against a " + renderContext ) ; super . paint ( renderContext ) ; return ; } LOG . debug ( "Validate XML Interceptor: Start" ) ; WebXmlRenderContext webRenderContext = ( WebXmlRenderContext ) renderContext ; PrintWriter writer = webRenderContext . getWriter ( ) ; // Generate XML StringWriter tempBuffer = new StringWriter ( ) ; PrintWriter tempWriter = new PrintWriter ( tempBuffer ) ; WebXmlRenderContext tempContext = new WebXmlRenderContext ( tempWriter , UIContextHolder . getCurrent ( ) . getLocale ( ) ) ; super . paint ( tempContext ) ; String xml = tempBuffer . toString ( ) ; // If no errors, check against the schema String error = DebugValidateXML . validateXMLAgainstSchema ( xml ) ; if ( error != null ) { // XML is NOT valid, so Report Errors and Wrap the original XML LOG . debug ( "Validate XML Interceptor: XML Has Errors" ) ; writer . println ( "<div>" ) ; writer . println ( "<div>" ) ; writer . println ( "Invalid XML" ) ; writer . println ( "<ul><li>" + WebUtilities . encode ( error ) + "</li></ul>" ) ; writer . println ( "<br/>" ) ; writer . println ( "</div>" ) ; // If a schema error detected, Wrap XML so line numbers reported in validation message are correct String testXML = DebugValidateXML . wrapXMLInRootElement ( xml ) ; paintOriginalXML ( testXML , writer ) ; writer . println ( "</div>" ) ; } else { // XML is valid writer . write ( xml ) ; } LOG . debug ( "Validate XML Interceptor: Finished" ) ; } | Override paint to include XML Validation . | 453 | 8 |
18,988 | private void paintOriginalXML ( final String originalXML , final PrintWriter writer ) { // Replace any CDATA Sections embedded in XML String xml = originalXML . replaceAll ( "<!\\[CDATA\\[" , "CDATASTART" ) ; xml = xml . replaceAll ( "\\]\\]>" , "CDATAFINISH" ) ; // Paint Output writer . println ( "<div>" ) ; writer . println ( "<!-- VALIDATE XML ERROR - START XML -->" ) ; writer . println ( "<![CDATA[" ) ; writer . println ( xml ) ; writer . println ( "]]>" ) ; writer . println ( "<!-- VALIDATE XML ERROR - END XML -->" ) ; writer . println ( "</div>" ) ; } | Paint the original XML wrapped in a CDATA Section . | 165 | 12 |
18,989 | @ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( ! this . isInitialised ( ) ) { List recent = loadRecentList ( ) ; if ( recent != null && ! recent . isEmpty ( ) ) { String selection = ( String ) recent . get ( 0 ) ; displaySelection ( selection ) ; } this . setInitialised ( true ) ; } updateTitle ( ) ; } | When the example picker starts up we want to display the last selection the user made in their previous session . We can do this because the list of recent selections is stored in a file on the file system . | 98 | 42 |
18,990 | private void updateTitle ( ) { String title ; if ( this . getCurrentComponent ( ) == null ) { title = "Example Picker" ; } else { title = this . getCurrentComponent ( ) . getClass ( ) . getName ( ) ; } WApplication app = WebUtilities . getAncestorOfClass ( WApplication . class , this ) ; if ( app != null ) { app . setTitle ( title ) ; } } | Updates the title based on the selected example . | 95 | 10 |
18,991 | @ Override protected void afterPaint ( final RenderContext renderContext ) { super . afterPaint ( renderContext ) ; if ( profileBtn . isPressed ( ) ) { // UIC serialization stats UicStats stats = new UicStats ( UIContextHolder . getCurrent ( ) ) ; WComponent currentComp = this . getCurrentComponent ( ) ; if ( currentComp != null ) { stats . analyseWC ( currentComp ) ; } if ( renderContext instanceof WebXmlRenderContext ) { PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; writer . println ( "<hr />" ) ; writer . println ( "<h2>Serialization Profile of UIC</h2>" ) ; UicStatsAsHtml . write ( writer , stats ) ; if ( currentComp != null ) { writer . println ( "<hr />" ) ; writer . println ( "<h2>ObjectProfiler - " + currentComp + "</h2>" ) ; writer . println ( "<pre>" ) ; try { writer . println ( ObjectGraphDump . dump ( currentComp ) . toFlatSummary ( ) ) ; } catch ( Exception e ) { LOG . error ( "Failed to dump component" , e ) ; } writer . println ( "</pre>" ) ; } } } } | Override afterPaint in order to paint the UIContext serialization statistics if the profile button has been pressed . | 290 | 24 |
18,992 | private List loadRecentList ( ) { try { InputStream in = new BufferedInputStream ( new FileInputStream ( RECENT_FILE_NAME ) ) ; XMLDecoder d = new XMLDecoder ( in ) ; Object result = d . readObject ( ) ; d . close ( ) ; return ( List ) result ; } catch ( FileNotFoundException ex ) { // This is ok, it's probably the first time the picker has been used. return new ArrayList ( ) ; } } | Retrieves the list of recently selected examples from a file on the file system . | 106 | 17 |
18,993 | public Container getCurrentComponent ( ) { Container currentComponent = null ; if ( ( ( Container ) ( container . getChildAt ( 0 ) ) ) . getChildCount ( ) > 0 ) { currentComponent = ( Container ) container . getChildAt ( 0 ) ; } return currentComponent ; } | Retrieves the component that is currently being displayed by the example picker . | 62 | 16 |
18,994 | public void displaySelection ( final String selection ) { WComponent selectedComponent = UIRegistry . getInstance ( ) . getUI ( selection ) ; if ( selectedComponent == null ) { // Can't load selected component. WMessages . getInstance ( this ) . error ( "Unable to load example: " + selection + ", see log for details." ) ; return ; } displaySelection ( selectedComponent ) ; } | Get the example picker to display the given selection . | 90 | 11 |
18,995 | public void displaySelection ( final WComponent selectedComponent ) { WComponent currentComponent = getCurrentComponent ( ) ; if ( selectedComponent == currentComponent ) { // We are already displaying this component, so nothing to do. return ; } // We have a new selection so display it. container . removeAll ( ) ; container . add ( selectedComponent ) ; } | Get the example picker to display the given selected component . | 75 | 12 |
18,996 | private void storeRecentList ( final List recent ) { try { if ( recent == null ) { return ; } // Only keep the last 8 entries. while ( recent . size ( ) > 8 ) { recent . remove ( recent . size ( ) - 1 ) ; } OutputStream out = new BufferedOutputStream ( new FileOutputStream ( RECENT_FILE_NAME ) ) ; XMLEncoder e = new XMLEncoder ( out ) ; e . writeObject ( recent ) ; e . close ( ) ; } catch ( IOException ex ) { LOG . error ( "Unable to save recent list" , ex ) ; } } | Store the list of recent selections to a file on the file system . | 137 | 14 |
18,997 | public static void setCurrentOperationDetails ( final AjaxOperation operation , final ComponentWithContext trigger ) { if ( operation == null ) { THREAD_LOCAL_OPERATION . remove ( ) ; } else { THREAD_LOCAL_OPERATION . set ( operation ) ; } if ( trigger == null ) { THREAD_LOCAL_COMPONENT_WITH_CONTEXT . remove ( ) ; } else { THREAD_LOCAL_COMPONENT_WITH_CONTEXT . set ( trigger ) ; } } | Sets the current AJAX operation details . | 113 | 9 |
18,998 | public static AjaxOperation registerComponents ( final List < String > targetIds , final String triggerId ) { AjaxOperation operation = new AjaxOperation ( triggerId , targetIds ) ; registerAjaxOperation ( operation ) ; return operation ; } | Registers one or more components as being AJAX capable . | 52 | 12 |
18,999 | public static AjaxOperation registerComponent ( final String targetId , final String triggerId ) { AjaxOperation operation = new AjaxOperation ( triggerId , targetId ) ; registerAjaxOperation ( operation ) ; return operation ; } | Registers a single component as being AJAX capable . | 46 | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.