idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
19,100
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMenuItemGroup group = ( WMenuItemGroup ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:menugroup" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendClose ( ) ; paintChildren ( group , renderContext ) ; xml . appendEndTag ( "ui:menugroup" ) ; }
Paints the given WMenuItemGroup .
19,101
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMultiDropdown dropdown = ( WMultiDropdown ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; String dataKey = dropdown . getListCacheKey ( ) ; boolean readOnly = dropdown . isReadOnly ( ) ; xml . appendTagOpen ( "ui:multidropdown" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , dropdown . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendOptionalAttribute ( "data" , dataKey != null && ! readOnly , dataKey ) ; xml . appendOptionalAttribute ( "disabled" , dropdown . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , dropdown . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "submitOnChange" , dropdown . isSubmitOnChange ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , component . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , component . getAccessibleText ( ) ) ; int min = dropdown . getMinSelect ( ) ; int max = dropdown . getMaxSelect ( ) ; xml . appendOptionalAttribute ( "min" , min > 0 , min ) ; xml . appendOptionalAttribute ( "max" , max > 0 , max ) ; xml . appendOptionalAttribute ( "title" , I18nUtilities . format ( null , InternalMessages . DEFAULT_MULTIDROPDOWN_TIP ) ) ; } xml . appendClose ( ) ; List < ? > options = dropdown . getOptions ( ) ; boolean renderSelectionsOnly = dropdown . isReadOnly ( ) || dataKey != null ; if ( options != null ) { int optionIndex = 0 ; List < ? > selections = dropdown . getSelected ( ) ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { xml . appendTagOpen ( "ui:optgroup" ) ; xml . appendAttribute ( "label" , ( ( OptionGroup ) option ) . getDesc ( ) ) ; xml . appendClose ( ) ; for ( Object nestedOption : ( ( OptionGroup ) option ) . getOptions ( ) ) { renderOption ( dropdown , nestedOption , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } xml . appendEndTag ( "ui:optgroup" ) ; } else { renderOption ( dropdown , option , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( dropdown , renderContext ) ; } xml . appendEndTag ( "ui:multidropdown" ) ; }
Paints the given WMultiDropdown .
19,102
public void setData ( final List data ) { String [ ] properties = new String [ ] { "colour" , "shape" , "animal" } ; simpleTable . setDataModel ( new SimpleBeanListTableDataModel ( properties , data ) ) ; }
Sets the table data .
19,103
public void setMandatory ( final boolean mandatory , final String message ) { setFlag ( ComponentModel . MANDATORY_FLAG , mandatory ) ; getOrCreateComponentModel ( ) . errorMessage = message ; }
Set whether or not this field set is mandatory and customise the error message that will be displayed .
19,104
private boolean hasInputWithValue ( ) { AbstractVisitorWithResult < Boolean > visitor = new AbstractVisitorWithResult < Boolean > ( ) { public WComponentTreeVisitor . VisitorResult visit ( final WComponent comp ) { if ( comp instanceof Input && ! ( ( Input ) comp ) . isEmpty ( ) ) { setResult ( true ) ; return VisitorResult . ABORT ; } return VisitorResult . CONTINUE ; } } ; visitor . setResult ( false ) ; TreeUtil . traverseVisible ( this , visitor ) ; return visitor . getResult ( ) ; }
Checks at least one input component has a value .
19,105
private static void processJsonToTree ( final TreeItemIdNode parentNode , final JsonObject json ) { String id = json . getAsJsonPrimitive ( "id" ) . getAsString ( ) ; JsonPrimitive expandableJson = json . getAsJsonPrimitive ( "expandable" ) ; TreeItemIdNode node = new TreeItemIdNode ( id ) ; if ( expandableJson != null && expandableJson . getAsBoolean ( ) ) { node . setHasChildren ( true ) ; } parentNode . addChild ( node ) ; JsonArray children = json . getAsJsonArray ( "items" ) ; if ( children != null ) { for ( int i = 0 ; i < children . size ( ) ; i ++ ) { JsonObject child = children . get ( i ) . getAsJsonObject ( ) ; processJsonToTree ( node , child ) ; } } }
Iterate over the JSON objects to create the tree structure .
19,106
public R fetchQuery ( String path , String properties ) { query . fetchQuery ( path , properties ) ; return root ; }
Specify a path and properties to load using a query join .
19,107
private R pushExprList ( ExpressionList < T > list ) { if ( textMode ) { textStack . push ( list ) ; } else { whereStack . push ( list ) ; } return root ; }
Push the expression list onto the appropriate stack .
19,108
protected ExpressionList < T > peekExprList ( ) { if ( textMode ) { return _peekText ( ) ; } if ( whereStack == null ) { whereStack = new ArrayStack < > ( ) ; whereStack . push ( query . where ( ) ) ; } return whereStack . peek ( ) ; }
Return the current expression list that expressions should be added to .
19,109
public ExpressionBuilder notEquals ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . NOT_EQUAL , trigger , compare ) ; appendExpression ( exp ) ; return this ; }
Appends a not equals test to the condition .
19,110
public ExpressionBuilder lessThan ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . LESS_THAN , trigger , compare ) ; appendExpression ( exp ) ; return this ; }
Appends a less than test to the condition .
19,111
public ExpressionBuilder lessThanOrEquals ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . LESS_THAN_OR_EQUAL , trigger , compare ) ; appendExpression ( exp ) ; return this ; }
Appends a less than or equals test to the condition .
19,112
public ExpressionBuilder greaterThan ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . GREATER_THAN , trigger , compare ) ; appendExpression ( exp ) ; return this ; }
Appends a greater than test to the condition .
19,113
public ExpressionBuilder greaterThanOrEquals ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . GREATER_THAN_OR_EQUAL , trigger , compare ) ; appendExpression ( exp ) ; return this ; }
Appends a greater than or equals test to the condition .
19,114
public ExpressionBuilder matches ( final SubordinateTrigger trigger , final String compare ) { BooleanExpression exp = new CompareExpression ( CompareType . MATCH , trigger , compare ) ; appendExpression ( exp ) ; return this ; }
Appends a matches test to the condition .
19,115
public ExpressionBuilder or ( ) { GroupExpression lastGroupExpression = stack . isEmpty ( ) ? null : stack . peek ( ) ; if ( lhsExpression == null ) { throw new SyntaxException ( "Syntax exception: OR missing LHS operand" ) ; } else if ( lastGroupExpression == null ) { GroupExpression or = new GroupExpression ( GroupExpression . Type . OR ) ; or . add ( lhsExpression ) ; stack . push ( or ) ; expression . setExpression ( or ) ; lhsExpression = null ; } else if ( lastGroupExpression . getType ( ) . equals ( GroupExpression . Type . OR ) ) { lhsExpression = null ; return this ; } else if ( lastGroupExpression . getType ( ) . equals ( GroupExpression . Type . AND ) ) { GroupExpression and = stack . pop ( ) ; GroupExpression or = new GroupExpression ( GroupExpression . Type . OR ) ; if ( stack . isEmpty ( ) ) { expression . setExpression ( or ) ; or . add ( and ) ; } else { GroupExpression parent = stack . pop ( ) ; parent . remove ( and ) ; parent . add ( or ) ; or . add ( and ) ; } stack . push ( and ) ; stack . push ( or ) ; lhsExpression = null ; } return this ; }
Appends an OR expression to the RHS of the expression . The current RHS of the expression must be an Operand .
19,116
public ExpressionBuilder and ( ) { GroupExpression lastGroupExpression = stack . isEmpty ( ) ? null : stack . peek ( ) ; if ( lhsExpression == null ) { throw new SyntaxException ( "Syntax exception: AND missing LHS operand" ) ; } else if ( lastGroupExpression == null ) { GroupExpression and = new GroupExpression ( GroupExpression . Type . AND ) ; and . add ( lhsExpression ) ; stack . push ( and ) ; expression . setExpression ( and ) ; lhsExpression = null ; } else if ( lastGroupExpression . getType ( ) . equals ( GroupExpression . Type . AND ) ) { lhsExpression = null ; return this ; } else if ( lastGroupExpression . getType ( ) . equals ( GroupExpression . Type . OR ) ) { GroupExpression or = lastGroupExpression ; GroupExpression and = new GroupExpression ( GroupExpression . Type . AND ) ; or . remove ( lhsExpression ) ; and . add ( lhsExpression ) ; or . add ( and ) ; stack . push ( and ) ; lhsExpression = null ; } return this ; }
Appends an AND expression to the RHS of the expression . The current RHS of the expression must be an Operand .
19,117
public ExpressionBuilder not ( final ExpressionBuilder exp ) { GroupExpression not = new GroupExpression ( Type . NOT ) ; not . add ( exp . expression . getExpression ( ) ) ; appendExpression ( not ) ; return this ; }
Appends a NOT expression to this expression .
19,118
private void appendExpression ( final BooleanExpression newExpression ) { if ( lhsExpression != null ) { throw new SyntaxException ( "Syntax exception: use AND or OR to join expressions" ) ; } lhsExpression = newExpression ; GroupExpression currentExpression = stack . isEmpty ( ) ? null : stack . peek ( ) ; if ( currentExpression == null ) { this . expression . setExpression ( newExpression ) ; } else { currentExpression . add ( newExpression ) ; } }
Appends the given expression to this expression .
19,119
public boolean validate ( ) { try { BooleanExpression built = expression . getExpression ( ) ; if ( built == null ) { return false ; } checkNesting ( built , new ArrayList < BooleanExpression > ( ) ) ; built . evaluate ( ) ; } catch ( Exception e ) { LogFactory . getLog ( getClass ( ) ) . warn ( "Invalid expression: " + e . getMessage ( ) ) ; return false ; } return true ; }
Determines whether the current expression is syntactically correct .
19,120
private static void checkNesting ( final BooleanExpression expression , final List < BooleanExpression > visitedExpressions ) { if ( visitedExpressions . contains ( expression ) ) { throw new SyntaxException ( "An expression can not contain itself." ) ; } visitedExpressions . add ( expression ) ; if ( expression instanceof GroupExpression ) { GroupExpression group = ( GroupExpression ) expression ; for ( BooleanExpression operand : group . getOperands ( ) ) { checkNesting ( operand , visitedExpressions ) ; } } }
Checks nesting of expressions to ensure we don t end up in an infinite recursive loop during evaluation .
19,121
private WFieldSet getDropDownControls ( ) { WFieldSet fieldSet = new WFieldSet ( "Drop down configuration" ) ; WFieldLayout layout = new WFieldLayout ( ) ; layout . setLabelWidth ( 25 ) ; fieldSet . add ( layout ) ; rbsDDType . setButtonLayout ( WRadioButtonSelect . LAYOUT_FLAT ) ; rbsDDType . setSelected ( WDropdown . DropdownType . NATIVE ) ; rbsDDType . setFrameless ( true ) ; layout . addField ( "Dropdown Type" , rbsDDType ) ; nfWidth . setMinValue ( 0 ) ; nfWidth . setDecimalPlaces ( 0 ) ; layout . addField ( "Width" , nfWidth ) ; layout . addField ( "ToolTip" , tfToolTip ) ; layout . addField ( "Include null option" , cbNullOption ) ; rgDefaultOption . setButtonLayout ( WRadioButtonSelect . LAYOUT_COLUMNS ) ; rgDefaultOption . setButtonColumns ( 2 ) ; rgDefaultOption . setSelected ( NONE ) ; rgDefaultOption . setFrameless ( true ) ; layout . addField ( "Default Option" , rgDefaultOption ) ; layout . addField ( "Action on change" , cbActionOnChange ) ; layout . addField ( "Ajax" , cbAjax ) ; WField subField = layout . addField ( "Subordinate" , cbSubordinate ) ; layout . addField ( "Submit on change" , cbSubmitOnChange ) ; layout . addField ( "Visible" , cbVisible ) ; layout . addField ( "Disabled" , cbDisabled ) ; WButton apply = new WButton ( "Apply" ) ; fieldSet . add ( apply ) ; WSubordinateControl subSubControl = new WSubordinateControl ( ) ; Rule rule = new Rule ( ) ; subSubControl . addRule ( rule ) ; rule . setCondition ( new Equal ( rbsDDType , WDropdown . DropdownType . COMBO ) ) ; rule . addActionOnTrue ( new Disable ( subField ) ) ; rule . addActionOnFalse ( new Enable ( subField ) ) ; fieldSet . add ( subSubControl ) ; apply . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { applySettings ( ) ; } } ) ; return fieldSet ; }
build the drop down controls .
19,122
private void applySettings ( ) { container . reset ( ) ; infoPanel . reset ( ) ; List < String > options = new ArrayList < > ( Arrays . asList ( OPTIONS_ARRAY ) ) ; if ( cbNullOption . isSelected ( ) ) { options . add ( 0 , "" ) ; } final WDropdown dropdown = new WDropdown ( options ) ; dropdown . setType ( ( DropdownType ) rbsDDType . getSelected ( ) ) ; String selected = ( String ) rgDefaultOption . getSelected ( ) ; if ( selected != null && ! NONE . equals ( selected ) ) { dropdown . setSelected ( selected ) ; } if ( nfWidth . getValue ( ) != null ) { dropdown . setOptionWidth ( nfWidth . getValue ( ) . intValue ( ) ) ; } if ( tfToolTip . getText ( ) != null && tfToolTip . getText ( ) . length ( ) > 0 ) { dropdown . setToolTip ( tfToolTip . getText ( ) ) ; } dropdown . setVisible ( cbVisible . isSelected ( ) ) ; dropdown . setDisabled ( cbDisabled . isSelected ( ) ) ; if ( cbActionOnChange . isSelected ( ) || cbAjax . isSelected ( ) || cbSubmitOnChange . isSelected ( ) ) { final WStyledText info = new WStyledText ( ) ; info . setWhitespaceMode ( WhitespaceMode . PRESERVE ) ; infoPanel . add ( info ) ; dropdown . setActionOnChange ( new Action ( ) { public void execute ( final ActionEvent event ) { String selectedOption = ( String ) dropdown . getSelected ( ) ; info . setText ( selectedOption ) ; } } ) ; } dropdown . setSubmitOnChange ( cbSubmitOnChange . isSelected ( ) ) ; if ( cbAjax . isSelected ( ) ) { WAjaxControl update = new WAjaxControl ( dropdown ) ; update . addTarget ( infoPanel ) ; container . add ( update ) ; } if ( rbsDDType . getValue ( ) == WDropdown . DropdownType . COMBO ) { cbSubordinate . setSelected ( false ) ; } if ( cbSubordinate . isSelected ( ) ) { WComponentGroup < SubordinateTarget > group = new WComponentGroup < > ( ) ; container . add ( group ) ; WSubordinateControl control = new WSubordinateControl ( ) ; container . add ( control ) ; for ( String option : OPTIONS_ARRAY ) { buildSubordinatePanel ( dropdown , option , group , control ) ; } Rule rule = new Rule ( ) ; control . addRule ( rule ) ; rule . setCondition ( new Equal ( dropdown , "" ) ) ; rule . addActionOnTrue ( new Hide ( group ) ) ; } WFieldLayout flay = new WFieldLayout ( ) ; flay . setLabelWidth ( 25 ) ; container . add ( flay ) ; flay . addField ( "Configured dropdown" , dropdown ) ; flay . addField ( ( WLabel ) null , new WButton ( "Submit" ) ) ; }
Apply the settings from the control table to the drop down .
19,123
private void buildSubordinatePanel ( final WDropdown dropdown , final String value , final WComponentGroup < SubordinateTarget > group , final WSubordinateControl control ) { WPanel panel = new WPanel ( ) ; WStyledText subordinateInfo = new WStyledText ( ) ; subordinateInfo . setWhitespaceMode ( WhitespaceMode . PRESERVE ) ; subordinateInfo . setText ( value + " - Subordinate" ) ; panel . add ( subordinateInfo ) ; infoPanel . add ( panel ) ; group . addToGroup ( panel ) ; Rule rule = new Rule ( ) ; control . addRule ( rule ) ; rule . setCondition ( new Equal ( dropdown , value ) ) ; rule . addActionOnTrue ( new ShowInGroup ( panel , group ) ) ; }
Builds a panel for the subordinate control including the rule for that particular option .
19,124
public void setDateHeader ( final String name , final long value ) { headers . put ( name , String . valueOf ( value ) ) ; }
Sets a date header .
19,125
public void setIntHeader ( final String name , final int value ) { headers . put ( name , String . valueOf ( value ) ) ; }
Sets an integer header .
19,126
public void execute ( ) { if ( target instanceof WComponentGroup < ? > ) { for ( WComponent component : ( ( WComponentGroup < WComponent > ) target ) . getComponents ( ) ) { if ( component instanceof SubordinateTarget ) { applyAction ( ( SubordinateTarget ) component , value ) ; } } } else { applyAction ( target , value ) ; } }
Execute the action .
19,127
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WStyledText text = ( WStyledText ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; String textString = text . getText ( ) ; if ( textString != null && textString . length ( ) > 0 ) { xml . appendTagOpen ( "ui:text" ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; switch ( text . getType ( ) ) { case EMPHASISED : xml . appendAttribute ( "type" , "emphasised" ) ; break ; case HIGH_PRIORITY : xml . appendAttribute ( "type" , "highPriority" ) ; break ; case LOW_PRIORITY : xml . appendAttribute ( "type" , "lowPriority" ) ; break ; case MEDIUM_PRIORITY : xml . appendAttribute ( "type" , "mediumPriority" ) ; break ; case ACTIVE_INDICATOR : xml . appendAttribute ( "type" , "activeIndicator" ) ; break ; case MATCH_INDICATOR : xml . appendAttribute ( "type" , "matchIndicator" ) ; break ; case INSERT : xml . appendAttribute ( "type" , "insert" ) ; break ; case DELETE : xml . appendAttribute ( "type" , "delete" ) ; break ; case MANDATORY_INDICATOR : xml . appendAttribute ( "type" , "mandatoryIndicator" ) ; break ; case PLAIN : default : xml . appendAttribute ( "type" , "plain" ) ; break ; } switch ( text . getWhitespaceMode ( ) ) { case PARAGRAPHS : xml . appendAttribute ( "space" , "paragraphs" ) ; break ; case PRESERVE : xml . appendAttribute ( "space" , "preserve" ) ; break ; case DEFAULT : break ; default : throw new IllegalArgumentException ( "Unknown white space mode: " + text . getWhitespaceMode ( ) ) ; } xml . appendClose ( ) ; if ( WStyledText . WhitespaceMode . PARAGRAPHS . equals ( text . getWhitespaceMode ( ) ) ) { textString = text . isEncodeText ( ) ? WebUtilities . encode ( textString ) : HtmlToXMLUtil . unescapeToXML ( textString ) ; writeParagraphs ( textString , xml ) ; } else { xml . append ( textString , text . isEncodeText ( ) ) ; } xml . appendEndTag ( "ui:text" ) ; } }
Paints the given WStyledText .
19,128
private static void writeParagraphs ( final String text , final XmlStringBuilder xml ) { if ( ! Util . empty ( text ) ) { int start = 0 ; int end = text . length ( ) - 1 ; for ( ; start < end ; start ++ ) { char c = text . charAt ( start ) ; if ( c != '\n' && c != '\r' ) { break ; } } for ( ; start < end ; end -- ) { char c = text . charAt ( end ) ; if ( c != '\n' && c != '\r' ) { break ; } } char lastChar = 0 ; for ( int i = start ; i <= end ; i ++ ) { char c = text . charAt ( i ) ; if ( c == '\n' || c == '\r' ) { if ( lastChar != 0 ) { xml . write ( "<ui:nl/>" ) ; } lastChar = 0 ; } else { xml . write ( c ) ; lastChar = c ; } } } }
Writes out paragraph delimited content .
19,129
public static void write ( final PrintWriter writer , final UicStats stats ) { writer . println ( "<dl>" ) ; writer . print ( "<dt>Total root wcomponents found in UIC</dt>" ) ; writer . println ( "<dd>" + stats . getRootWCs ( ) . size ( ) + "</dd>" ) ; writer . print ( "<dt>Size of UIC (by serialization)</dt>" ) ; writer . println ( "<dd>" + stats . getOverallSerializedSize ( ) + "</dd>" ) ; writer . print ( "<dt>UI</dt>" ) ; writer . println ( "<dd>" + stats . getUI ( ) . getClass ( ) . getName ( ) + "</dd>" ) ; writer . println ( "</dl>" ) ; for ( Iterator < WComponent > it = stats . getWCsAnalysed ( ) ; it . hasNext ( ) ; ) { WComponent comp = it . next ( ) ; Map < WComponent , UicStats . Stat > treeStats = stats . getWCTreeStats ( comp ) ; writer . println ( "<br /><strong>Analysed component:</strong> " + comp ) ; writer . println ( "<br /><strong>Number of components in tree:</strong> " + treeStats . size ( ) ) ; writeHeader ( writer ) ; writeProfileForTree ( writer , treeStats ) ; writeFooter ( writer ) ; } }
Writes out the given statistics in HTML format .
19,130
private static void writeProfileForTree ( final PrintWriter writer , final Map < WComponent , UicStats . Stat > treeStats ) { List < UicStats . Stat > statList = new ArrayList < > ( treeStats . values ( ) ) ; Comparator < UicStats . Stat > comparator = new Comparator < UicStats . Stat > ( ) { public int compare ( final UicStats . Stat stat1 , final UicStats . Stat stat2 ) { if ( stat1 . getModelState ( ) > stat2 . getModelState ( ) ) { return - 1 ; } else if ( stat1 . getModelState ( ) < stat2 . getModelState ( ) ) { return 1 ; } else { int diff = stat1 . getClassName ( ) . compareTo ( stat2 . getClassName ( ) ) ; if ( diff == 0 ) { diff = stat1 . getName ( ) . compareTo ( stat2 . getName ( ) ) ; } return diff ; } } } ; Collections . sort ( statList , comparator ) ; for ( int i = 0 ; i < statList . size ( ) ; i ++ ) { UicStats . Stat stat = statList . get ( i ) ; writeRow ( writer , stat ) ; } }
Writes the stats for a single component .
19,131
private static void writeHeader ( final PrintWriter writer ) { writer . println ( "<table>" ) ; writer . println ( "<thead>" ) ; writer . print ( "<tr>" ) ; writer . print ( "<th>Class</th>" ) ; writer . print ( "<th>Model</th>" ) ; writer . print ( "<th>Size</th>" ) ; writer . print ( "<th>Ref.</th>" ) ; writer . print ( "<th>Name</th>" ) ; writer . print ( "<th>Comment</th>" ) ; writer . println ( "</tr>" ) ; writer . println ( "</thead>" ) ; }
Writes the stats header HTML .
19,132
private static void writeRow ( final PrintWriter writer , final UicStats . Stat stat ) { writer . print ( "<tr>" ) ; writer . print ( "<td>" + stat . getClassName ( ) + "</td>" ) ; writer . print ( "<td>" + stat . getModelStateAsString ( ) + "</td>" ) ; if ( stat . getSerializedSize ( ) > 0 ) { writer . print ( "<td>" + stat . getSerializedSize ( ) + "</td>" ) ; } else { writer . print ( "<td>&#160;</td>" ) ; } writer . print ( "<td>" + stat . getRef ( ) + "</td>" ) ; writer . print ( "<td>" + stat . getName ( ) + "</td>" ) ; if ( stat . getComment ( ) == null ) { writer . print ( "<td>&#160;</td>" ) ; } else { writer . print ( "<td>" + stat . getComment ( ) + "</td>" ) ; } writer . println ( "</tr>" ) ; }
Writes a row containing a single stat .
19,133
private void changePage ( final int direction ) { int currentPage = pages . indexOf ( cardManager . getVisible ( ) ) ; currentPage = Math . min ( 2 , Math . max ( 0 , currentPage + direction ) ) ; cardManager . makeVisible ( pages . get ( currentPage ) ) ; prevButton . setDisabled ( currentPage == 0 ) ; nextButton . setDisabled ( currentPage == 2 ) ; finishButton . setDisabled ( currentPage != 2 ) ; cancelButton . setUnsavedChanges ( currentPage > 0 ) ; }
Handles a pagination request .
19,134
private String trackKindToString ( final Track . Kind kind ) { if ( kind == null ) { return null ; } switch ( kind ) { case SUBTITLES : return "subtitles" ; case CAPTIONS : return "captions" ; case DESCRIPTIONS : return "descriptions" ; case CHAPTERS : return "chapters" ; case METADATA : return "metadata" ; default : LOG . error ( "Unknown track kind " + kind ) ; return null ; } }
Converts a Track kind to the client track kind identifier .
19,135
public void processAction ( ) throws IOException { if ( isDisposed ( ) ) { LOG . error ( "Skipping action phase. Attempt to reuse disposed ContainerHelper instance" ) ; return ; } try { if ( getNewConversation ( ) == null ) { throw new IllegalStateException ( "User context has not been prepared before the action phase" ) ; } prepareAction ( ) ; UIContext uic = getUIContext ( ) ; if ( uic == null ) { throw new IllegalStateException ( "No user context set for the action phase." ) ; } UIContextHolder . pushContext ( uic ) ; uic . clearScratchMap ( ) ; uic . clearRequestScratchMap ( ) ; prepareRequest ( ) ; Request req = getRequest ( ) ; getInterceptor ( ) . attachResponse ( getResponse ( ) ) ; getInterceptor ( ) . serviceRequest ( req ) ; if ( req . isLogout ( ) ) { handleLogout ( ) ; dispose ( ) ; } } catch ( ActionEscape esc ) { LOG . debug ( "ActionEscape performed." ) ; handleEscape ( esc ) ; dispose ( ) ; } catch ( Escape esc ) { LOG . debug ( "Escape performed during action phase." ) ; } catch ( Throwable t ) { String message = "Caught exception during action phase." ; LOG . error ( message , t ) ; propogateError ( t ) ; } finally { UIContextHolder . reset ( ) ; } }
Support standard processing of the action phase of a request .
19,136
public void render ( ) throws IOException { if ( isDisposed ( ) ) { LOG . debug ( "Skipping render phase." ) ; return ; } try { if ( getNewConversation ( ) == null ) { throw new IllegalStateException ( "User context has not been prepared before the render phase" ) ; } prepareRender ( ) ; UIContext uic = getUIContext ( ) ; if ( uic == null ) { throw new IllegalStateException ( "No user context set for the render phase." ) ; } UIContextHolder . pushContext ( uic ) ; prepareRequest ( ) ; if ( havePropogatedError ( ) ) { handleError ( getPropogatedError ( ) ) ; return ; } WComponent uiComponent = getUI ( ) ; if ( uiComponent == null ) { throw new SystemException ( "No UI Component exists." ) ; } Environment environment = uiComponent . getEnvironment ( ) ; if ( environment == null ) { throw new SystemException ( "No WEnvironment exists." ) ; } getInterceptor ( ) . attachResponse ( getResponse ( ) ) ; getInterceptor ( ) . preparePaint ( getRequest ( ) ) ; String contentType = getUI ( ) . getHeaders ( ) . getContentType ( ) ; Response response = getResponse ( ) ; response . setContentType ( contentType ) ; addGenericHeaders ( uic , getUI ( ) ) ; PrintWriter writer = getPrintWriter ( ) ; getInterceptor ( ) . paint ( new WebXmlRenderContext ( writer , uic . getLocale ( ) ) ) ; String title = uiComponent instanceof WApplication ? ( ( WApplication ) uiComponent ) . getTitle ( ) : null ; if ( title != null ) { setTitle ( title ) ; } } catch ( Escape esc ) { LOG . debug ( "Escape performed during render phase." ) ; handleEscape ( esc ) ; } catch ( Throwable t ) { String message = "Caught exception during render phase." ; LOG . error ( message , t ) ; handleError ( t ) ; } finally { UIContextHolder . reset ( ) ; dispose ( ) ; } }
Support standard processing of the render phase of a request .
19,137
protected void cycleUIContext ( ) { boolean cycleIt = ConfigurationProperties . getDeveloperClusterEmulation ( ) ; if ( cycleIt ) { UIContext uic = getUIContext ( ) ; if ( uic instanceof UIContextWrap ) { LOG . info ( "Cycling the UIContext to simulate clustering" ) ; ( ( UIContextWrap ) uic ) . cycle ( ) ; } } }
Call this method to simulate what would happen if the UIContext was serialized due to clustering of servers .
19,138
protected void prepareRequest ( ) { LOG . debug ( "Preparing for request by adding headers and environment to top wcomponent" ) ; UIContext uiContext = getUIContext ( ) ; Environment env ; if ( uiContext . isDummyEnvironment ( ) ) { env = createEnvironment ( ) ; uiContext . setEnvironment ( env ) ; } else { env = uiContext . getEnvironment ( ) ; } updateEnvironment ( env ) ; if ( getRequest ( ) == null ) { setRequest ( createRequest ( ) ) ; } updateRequest ( getRequest ( ) ) ; }
Prepare the session for the current request .
19,139
private void propogateError ( final Throwable error ) { if ( getRequest ( ) == null ) { LOG . error ( "Unable to remember error from action phase beyond this request" ) ; } else { LOG . debug ( "Remembering error from action phase" ) ; getRequest ( ) . setAttribute ( ACTION_ERROR_KEY , error ) ; } }
Propogates an error from the action phase to the render phase .
19,140
private boolean havePropogatedError ( ) { Request req = getRequest ( ) ; return req != null && req . getAttribute ( ACTION_ERROR_KEY ) != null ; }
Indicates whether there is an error which has been propogated from the action to the render phase .
19,141
private Throwable getPropogatedError ( ) { Request req = getRequest ( ) ; if ( req != null ) { return ( Throwable ) req . getAttribute ( ACTION_ERROR_KEY ) ; } return null ; }
Retrieves an error which has been propogated from the action to the render phase .
19,142
public void handleError ( final Throwable error ) throws IOException { LOG . debug ( "Start handleError..." ) ; boolean terminate = ConfigurationProperties . getTerminateSessionOnError ( ) ; if ( terminate ) { invalidateSession ( ) ; } boolean friendly = ConfigurationProperties . getDeveloperErrorHandling ( ) ; FatalErrorPageFactory factory = Factory . newInstance ( FatalErrorPageFactory . class ) ; WComponent errorPage = factory . createErrorPage ( friendly , error ) ; String html = renderErrorPageToHTML ( errorPage ) ; Response response = getResponse ( ) ; response . setContentType ( WebUtilities . CONTENT_TYPE_HTML ) ; getResponse ( ) . setHeader ( "Cache-Control" , CacheType . NO_CACHE . getSettings ( ) ) ; getResponse ( ) . setHeader ( "Pragma" , "no-cache" ) ; getResponse ( ) . setHeader ( "Expires" , "-1" ) ; getPrintWriter ( ) . println ( html ) ; LOG . debug ( "End handleError" ) ; }
Last resort error handling .
19,143
protected String renderErrorPageToHTML ( final WComponent errorPage ) { boolean defaultErrorPage = errorPage instanceof FatalErrorPage ; String html = null ; if ( ! defaultErrorPage ) { UIContext uic = new UIContextImpl ( ) ; uic . setEnvironment ( createEnvironment ( ) ) ; UIContextHolder . pushContext ( uic ) ; try { html = WebUtilities . renderWithTransformToHTML ( errorPage ) ; } catch ( Exception e ) { LOG . warn ( "Could not transform error page." , e ) ; } finally { UIContextHolder . popContext ( ) ; } } if ( html == null ) { UIContextHolder . pushContext ( new UIContextImpl ( ) ) ; try { html = WebUtilities . render ( errorPage ) ; } catch ( Exception e ) { LOG . warn ( "Could not render error page." , e ) ; html = "System error occurred but could not render error page." ; } finally { UIContextHolder . popContext ( ) ; } } return html ; }
Render the error page component to HTML .
19,144
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WFieldLayout fieldLayout = ( WFieldLayout ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; int labelWidth = fieldLayout . getLabelWidth ( ) ; String title = fieldLayout . getTitle ( ) ; xml . appendTagOpen ( "ui:fieldlayout" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , fieldLayout . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "labelWidth" , labelWidth > 0 , labelWidth ) ; xml . appendAttribute ( "layout" , fieldLayout . getLayoutType ( ) ) ; xml . appendOptionalAttribute ( "title" , title ) ; if ( fieldLayout . isOrdered ( ) ) { xml . appendAttribute ( "ordered" , fieldLayout . getOrderedOffset ( ) ) ; } xml . appendClose ( ) ; MarginRendererUtil . renderMargin ( fieldLayout , renderContext ) ; paintChildren ( fieldLayout , renderContext ) ; xml . appendEndTag ( "ui:fieldlayout" ) ; }
Paints the given WFieldLayout .
19,145
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WAbbrText abbrText = ( WAbbrText ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "abbr" ) ; xml . appendOptionalAttribute ( "title" , abbrText . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "class" , abbrText . getHtmlClass ( ) ) ; xml . appendClose ( ) ; xml . append ( abbrText . getText ( ) , abbrText . isEncodeText ( ) ) ; xml . appendEndTag ( "abbr" ) ; }
Paints the given WAbbrText .
19,146
public Cookie [ ] getCookies ( ) { Collection < Cookie > entries = cookies . values ( ) ; return entries . toArray ( new Cookie [ 0 ] ) ; }
Get all the cookies on this request .
19,147
public void setCookie ( final String name , final String value ) { if ( name != null ) { Cookie cookie = new Cookie ( name , value ) ; cookies . put ( name , cookie ) ; } }
Sets a cookie on this request instance .
19,148
public void setParameter ( final String name , final String value ) { String [ ] currentValue = ( String [ ] ) parameters . get ( name ) ; if ( currentValue == null ) { currentValue = new String [ ] { value } ; } else { String [ ] newValues = new String [ currentValue . length + 1 ] ; System . arraycopy ( currentValue , 0 , newValues , 0 , currentValue . length ) ; newValues [ newValues . length - 1 ] = value ; currentValue = newValues ; } parameters . put ( name , currentValue ) ; }
Sets a parameter . If the parameter already exists another value will be added to the parameter values .
19,149
public static < T > T newInstance ( final Class < T > interfaz ) { String classname = ConfigurationProperties . getFactoryImplementation ( interfaz . getName ( ) ) ; if ( classname == null ) { LOG . fatal ( "No implementing class for " + interfaz . getName ( ) ) ; LOG . fatal ( "There needs to be a parameter defined for " + ConfigurationProperties . FACTORY_PREFIX + interfaz . getName ( ) ) ; throw new SystemException ( "No implementing class for " + interfaz . getName ( ) + "; " + "There needs to be a parameter defined for " + ConfigurationProperties . FACTORY_PREFIX + interfaz . getName ( ) ) ; } try { Class < T > clas = ( Class < T > ) Class . forName ( classname . trim ( ) ) ; return clas . newInstance ( ) ; } catch ( Exception ex ) { throw new SystemException ( "Failed to instantiate object of class " + classname , ex ) ; } }
Given an interface instantiate a class implementing that interface .
19,150
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMultiSelectPair multiSelectPair = ( WMultiSelectPair ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = multiSelectPair . isReadOnly ( ) ; xml . appendTagOpen ( "ui:multiselectpair" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , multiSelectPair . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { int rows = multiSelectPair . getRows ( ) ; int min = multiSelectPair . getMinSelect ( ) ; int max = multiSelectPair . getMaxSelect ( ) ; xml . appendAttribute ( "size" , rows < 2 ? WMultiSelectPair . DEFAULT_ROWS : rows ) ; xml . appendOptionalAttribute ( "disabled" , multiSelectPair . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , multiSelectPair . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "shuffle" , multiSelectPair . isShuffle ( ) , "true" ) ; xml . appendOptionalAttribute ( "fromListName" , multiSelectPair . getAvailableListName ( ) ) ; xml . appendOptionalAttribute ( "toListName" , multiSelectPair . getSelectedListName ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , multiSelectPair . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "min" , min > 0 , min ) ; xml . appendOptionalAttribute ( "max" , max > 0 , max ) ; } xml . appendClose ( ) ; List < ? > options = multiSelectPair . getOptions ( ) ; boolean renderSelectionsOnly = readOnly ; if ( options != null ) { if ( multiSelectPair . isShuffle ( ) ) { renderOrderedOptions ( multiSelectPair , options , 0 , xml , renderSelectionsOnly ) ; } else { renderUnorderedOptions ( multiSelectPair , options , 0 , xml , renderSelectionsOnly ) ; } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( multiSelectPair , renderContext ) ; } xml . appendEndTag ( "ui:multiselectpair" ) ; }
Paints the given WMultiSelectPair .
19,151
private int renderOrderedOptions ( final WMultiSelectPair multiSelectPair , final List < ? > options , final int startIndex , final XmlStringBuilder xml , final boolean renderSelectionsOnly ) { List < ? > selections = multiSelectPair . getSelected ( ) ; int optionIndex = startIndex ; Map < Integer , Integer > currentSelectionIndices = new HashMap < > ( ) ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { xml . appendTagOpen ( "ui:optgroup" ) ; xml . appendAttribute ( "label" , ( ( OptionGroup ) option ) . getDesc ( ) ) ; xml . appendClose ( ) ; List < ? > nestedOptions = ( ( OptionGroup ) option ) . getOptions ( ) ; optionIndex += renderOrderedOptions ( multiSelectPair , nestedOptions , optionIndex , xml , renderSelectionsOnly ) ; xml . appendEndTag ( "ui:optgroup" ) ; } else { int index = selections . indexOf ( option ) ; if ( index == - 1 ) { renderOption ( multiSelectPair , option , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } else { currentSelectionIndices . put ( index , optionIndex ++ ) ; } } } if ( ! currentSelectionIndices . isEmpty ( ) ) { List < Integer > sortedSelectedIndices = new ArrayList < > ( currentSelectionIndices . keySet ( ) ) ; Collections . sort ( sortedSelectedIndices ) ; for ( int selectionIndex : sortedSelectedIndices ) { int selectionOptionIndex = currentSelectionIndices . get ( selectionIndex ) ; renderOption ( multiSelectPair , selections . get ( selectionIndex ) , selectionOptionIndex , xml , selections , renderSelectionsOnly ) ; } } return optionIndex - startIndex ; }
Renders the options in selection order . Note though that this does not support the legacy allowNull or setSelected using String representations .
19,152
private int renderUnorderedOptions ( final WMultiSelectPair multiSelectPair , final List < ? > options , final int startIndex , final XmlStringBuilder xml , final boolean renderSelectionsOnly ) { List < ? > selections = multiSelectPair . getSelected ( ) ; int optionIndex = startIndex ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { xml . appendTagOpen ( "ui:optgroup" ) ; xml . appendAttribute ( "label" , ( ( OptionGroup ) option ) . getDesc ( ) ) ; xml . appendClose ( ) ; List < ? > nestedOptions = ( ( OptionGroup ) option ) . getOptions ( ) ; optionIndex += renderUnorderedOptions ( multiSelectPair , nestedOptions , optionIndex , xml , renderSelectionsOnly ) ; xml . appendEndTag ( "ui:optgroup" ) ; } else { renderOption ( multiSelectPair , option , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } } return optionIndex - startIndex ; }
Renders the options in list order .
19,153
public List < Conversation > getConversationsOnObject ( Reference object ) { return getResourceFactory ( ) . getApiResource ( "/conversation/" + object . toURLFragment ( ) ) . get ( new GenericType < List < Conversation > > ( ) { } ) ; }
Returns a list of all the conversations on the object that the active user is part of .
19,154
public int addReply ( int conversationId , String text ) { return getResourceFactory ( ) . getApiResource ( "/conversation/" + conversationId + "/reply" ) . entity ( new MessageCreate ( text ) , MediaType . APPLICATION_JSON_TYPE ) . get ( MessageCreateResponse . class ) . getMessageId ( ) ; }
Creates a reply to the conversation .
19,155
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WApplication application = ( WApplication ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; String focusId = uic . getFocussedId ( ) ; if ( application . getParent ( ) != null ) { LOG . warn ( "WApplication component should be the top level component." ) ; } xml . appendTagOpen ( "ui:application" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendUrlAttribute ( "applicationUrl" , uic . getEnvironment ( ) . getPostPath ( ) ) ; xml . appendUrlAttribute ( "ajaxUrl" , uic . getEnvironment ( ) . getWServletPath ( ) ) ; xml . appendOptionalAttribute ( "unsavedChanges" , application . hasUnsavedChanges ( ) , "true" ) ; xml . appendOptionalAttribute ( "title" , application . getTitle ( ) ) ; xml . appendOptionalAttribute ( "defaultFocusId" , uic . isFocusRequired ( ) && ! Util . empty ( focusId ) , focusId ) ; xml . appendOptionalUrlAttribute ( "icon" , WApplication . getIcon ( ) ) ; xml . appendClose ( ) ; if ( TrackingUtil . isTrackingEnabled ( ) ) { xml . appendTagOpen ( "ui:analytic" ) ; xml . appendAttribute ( "clientId" , TrackingUtil . getClientId ( ) ) ; xml . appendOptionalAttribute ( "cd" , TrackingUtil . getCookieDomain ( ) ) ; xml . appendOptionalAttribute ( "dcd" , TrackingUtil . getDataCollectionDomain ( ) ) ; xml . appendOptionalAttribute ( "name" , TrackingUtil . getApplicationName ( ) ) ; xml . appendEnd ( ) ; } Map < String , String > hiddenFields = uic . getEnvironment ( ) . getHiddenParameters ( ) ; if ( hiddenFields != null ) { for ( Map . Entry < String , String > entry : hiddenFields . entrySet ( ) ) { xml . appendTagOpen ( "ui:param" ) ; xml . appendAttribute ( "name" , entry . getKey ( ) ) ; xml . appendAttribute ( "value" , entry . getValue ( ) ) ; xml . appendEnd ( ) ; } } for ( WApplication . ApplicationResource resource : application . getCssResources ( ) ) { String url = resource . getTargetUrl ( ) ; if ( ! Util . empty ( url ) ) { xml . appendTagOpen ( "ui:css" ) ; xml . appendUrlAttribute ( "url" , url ) ; xml . appendEnd ( ) ; } } for ( WApplication . ApplicationResource resource : application . getJsResources ( ) ) { String url = resource . getTargetUrl ( ) ; if ( ! Util . empty ( url ) ) { xml . appendTagOpen ( "ui:js" ) ; xml . appendUrlAttribute ( "url" , url ) ; xml . appendEnd ( ) ; } } paintChildren ( application , renderContext ) ; xml . appendEndTag ( "ui:application" ) ; }
Paints the given WApplication .
19,156
protected void preparePaintComponent ( final Request request ) { StringBuffer text = new StringBuffer ( "Options: " ) ; for ( Object option : shuffler . getOptions ( ) ) { text . append ( option ) . append ( ", " ) ; } order . setText ( text . toString ( ) ) ; }
Concatenate the options to display in the text field .
19,157
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMultiTextField textField = ( WMultiTextField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = textField . isReadOnly ( ) ; String [ ] values = textField . getTextInputs ( ) ; xml . appendTagOpen ( "ui:multitextfield" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , textField . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { int cols = textField . getColumns ( ) ; int minLength = textField . getMinLength ( ) ; int maxLength = textField . getMaxLength ( ) ; int maxInputs = textField . getMaxInputs ( ) ; String pattern = textField . getPattern ( ) ; xml . appendOptionalAttribute ( "disabled" , textField . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , textField . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , textField . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , textField . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "size" , cols > 0 , cols ) ; xml . appendOptionalAttribute ( "minLength" , minLength > 0 , minLength ) ; xml . appendOptionalAttribute ( "maxLength" , maxLength > 0 , maxLength ) ; xml . appendOptionalAttribute ( "max" , maxInputs > 0 , maxInputs ) ; xml . appendOptionalAttribute ( "pattern" , ! Util . empty ( pattern ) , pattern ) ; String placeholder = textField . getPlaceholder ( ) ; xml . appendOptionalAttribute ( "placeholder" , ! Util . empty ( placeholder ) , placeholder ) ; xml . appendOptionalAttribute ( "title" , I18nUtilities . format ( null , InternalMessages . DEFAULT_MULTITEXTFIELD_TIP ) ) ; } xml . appendClose ( ) ; if ( values != null ) { for ( String value : values ) { xml . appendTag ( "ui:value" ) ; xml . appendEscaped ( value ) ; xml . appendEndTag ( "ui:value" ) ; } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( textField , renderContext ) ; } xml . appendEndTag ( "ui:multitextfield" ) ; }
Paints the given WMultiTextField .
19,158
private static ExampleBean fakeServiceCall ( final String text ) { ExampleBean exampleBean = new ExampleBean ( ) ; exampleBean . setBeanAttribute ( "(beanAttribute) " + text ) ; ExampleBean . DummyInnerBean dummyInnerBean = new ExampleBean . DummyInnerBean ( ) ; dummyInnerBean . setInnerAttribute ( "(innerBean.innerAttribute) " + text ) ; exampleBean . setInnerBean ( dummyInnerBean ) ; return exampleBean ; }
Fakes a service call and just returns dummy data .
19,159
public static void processRequest ( final HttpServletHelper helper , final WComponent ui , final InterceptorComponent interceptorChain ) throws ServletException , IOException { try { if ( interceptorChain == null ) { helper . setWebComponent ( ui ) ; } else { interceptorChain . attachUI ( ui ) ; helper . setWebComponent ( interceptorChain ) ; } UIContext uic = helper . prepareUserContext ( ) ; synchronized ( uic ) { helper . processAction ( ) ; helper . render ( ) ; } } finally { AjaxHelper . clearCurrentOperationDetails ( ) ; } }
This method does the real work in servicing the http request . It integrates wcomponents into a servlet environment via a servlet specific helper class .
19,160
public static void handleStaticResourceRequest ( final HttpServletRequest request , final HttpServletResponse response ) { String staticRequest = request . getParameter ( WServlet . STATIC_RESOURCE_PARAM_NAME ) ; try { InternalResource staticResource = InternalResourceMap . getResource ( staticRequest ) ; boolean headersOnly = "HEAD" . equals ( request . getMethod ( ) ) ; if ( staticResource == null ) { LOG . warn ( "Static resource [" + staticRequest + "] not found." ) ; response . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } InputStream resourceStream = staticResource . getStream ( ) ; if ( resourceStream == null ) { LOG . warn ( "Static resource [" + staticRequest + "] not found. Stream for content is null." ) ; response . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } int size = resourceStream . available ( ) ; String fileName = WebUtilities . encodeForContentDispositionHeader ( staticRequest . substring ( staticRequest . lastIndexOf ( '/' ) + 1 ) ) ; if ( size > 0 ) { response . setContentLength ( size ) ; } response . setContentType ( WebUtilities . getContentType ( staticRequest ) ) ; response . setHeader ( "Cache-Control" , CacheType . CONTENT_CACHE . getSettings ( ) ) ; String param = request . getParameter ( WContent . URL_CONTENT_MODE_PARAMETER_KEY ) ; if ( "inline" . equals ( param ) ) { response . setHeader ( "Content-Disposition" , "inline; filename=" + fileName ) ; } else if ( "attach" . equals ( param ) ) { response . setHeader ( "Content-Disposition" , "attachment; filename=" + fileName ) ; } else { response . setHeader ( "Content-Disposition" , "filename=" + fileName ) ; } if ( ! headersOnly ) { StreamUtil . copy ( resourceStream , response . getOutputStream ( ) ) ; } } catch ( IOException e ) { LOG . warn ( "Could not process static resource [" + staticRequest + "]. " , e ) ; response . reset ( ) ; response . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; } }
Handles a request for static resources .
19,161
public static void handleThemeResourceRequest ( final HttpServletRequest req , final HttpServletResponse resp ) throws ServletException , IOException { if ( req . getHeader ( "If-Modified-Since" ) != null ) { resp . reset ( ) ; resp . setStatus ( HttpServletResponse . SC_NOT_MODIFIED ) ; return ; } String fileName = req . getParameter ( "f" ) ; String path = req . getPathInfo ( ) ; if ( fileName == null && ! Util . empty ( path ) ) { int offset = path . startsWith ( THEME_RESOURCE_PATH_PARAM ) ? THEME_RESOURCE_PATH_PARAM . length ( ) : 1 ; fileName = path . substring ( offset ) ; } if ( fileName == null || ! checkThemeFile ( fileName ) ) { resp . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; return ; } InputStream resourceStream = null ; try { URL url = null ; if ( fileName . startsWith ( THEME_TRANSLATION_RESOURCE_PREFIX ) ) { String resourceFileName = fileName . substring ( THEME_TRANSLATION_RESOURCE_PREFIX . length ( ) ) ; url = ServletUtil . class . getResource ( THEME_PROJECT_TRANSLATION_RESOURCE_PATH + resourceFileName ) ; } if ( url == null ) { String resourceName = ThemeUtil . getThemeBase ( ) + fileName ; url = ServletUtil . class . getResource ( resourceName ) ; } if ( url == null ) { resp . setStatus ( HttpServletResponse . SC_NOT_FOUND ) ; } else { URLConnection connection = url . openConnection ( ) ; resourceStream = connection . getInputStream ( ) ; int size = resourceStream . available ( ) ; if ( size > 0 ) { resp . setContentLength ( size ) ; } resp . setContentType ( WebUtilities . getContentType ( fileName ) ) ; resp . setHeader ( "Cache-Control" , CacheType . THEME_CACHE . getSettings ( ) ) ; resp . setHeader ( "Expires" , "31536000" ) ; resp . setHeader ( "ETag" , "\"" + WebUtilities . getProjectVersion ( ) + "\"" ) ; long modified = connection . getLastModified ( ) ; resp . setDateHeader ( "Last-Modified" , modified ) ; StreamUtil . copy ( resourceStream , resp . getOutputStream ( ) ) ; } } finally { StreamUtil . safeClose ( resourceStream ) ; } }
Serves up a file from the theme . In practice it is generally a bad idea to use this servlet to serve up static resources . Instead it would make more sense to move CSS JS HTML resources to a CDN or similar .
19,162
private static boolean checkThemeFile ( final String name ) { return ! ( Util . empty ( name ) || name . contains ( ".." ) || name . charAt ( 0 ) == '/' || name . indexOf ( ':' ) != - 1 ) ; }
Performs basic sanity checks on the file being requested .
19,163
public static InterceptorComponent createInterceptorChain ( final HttpServletRequest request ) { Map < String , String [ ] > parameters = getRequestParameters ( request ) ; InterceptorComponent [ ] chain ; if ( parameters . get ( WServlet . DATA_LIST_PARAM_NAME ) != null ) { chain = new InterceptorComponent [ ] { new TransformXMLInterceptor ( ) , new DataListInterceptor ( ) } ; } else if ( parameters . get ( WServlet . AJAX_TRIGGER_PARAM_NAME ) != null ) { chain = new InterceptorComponent [ ] { new TemplateRenderInterceptor ( ) , new TransformXMLInterceptor ( ) , new ValidateXMLInterceptor ( ) , new AjaxErrorInterceptor ( ) , new SessionTokenAjaxInterceptor ( ) , new ResponseCacheInterceptor ( CacheType . NO_CACHE ) , new UIContextDumpInterceptor ( ) , new AjaxSetupInterceptor ( ) , new WWindowInterceptor ( true ) , new WrongStepAjaxInterceptor ( ) , new ContextCleanupInterceptor ( ) , new WhitespaceFilterInterceptor ( ) , new SubordinateControlInterceptor ( ) , new AjaxPageShellInterceptor ( ) , new AjaxDebugStructureInterceptor ( ) , new AjaxInterceptor ( ) } ; } else if ( parameters . get ( WServlet . TARGET_ID_PARAM_NAME ) != null ) { chain = new InterceptorComponent [ ] { new TargetableErrorInterceptor ( ) , new SessionTokenContentInterceptor ( ) , new UIContextDumpInterceptor ( ) , new TargetableInterceptor ( ) , new WWindowInterceptor ( false ) , new WrongStepContentInterceptor ( ) } ; } else { chain = new InterceptorComponent [ ] { new TemplateRenderInterceptor ( ) , new TransformXMLInterceptor ( ) , new ValidateXMLInterceptor ( ) , new SessionTokenInterceptor ( ) , new ResponseCacheInterceptor ( CacheType . NO_CACHE ) , new UIContextDumpInterceptor ( ) , new WWindowInterceptor ( true ) , new WrongStepServerInterceptor ( ) , new AjaxCleanupInterceptor ( ) , new ContextCleanupInterceptor ( ) , new WhitespaceFilterInterceptor ( ) , new SubordinateControlInterceptor ( ) , new PageShellInterceptor ( ) , new FormInterceptor ( ) , new DebugStructureInterceptor ( ) } ; } for ( int i = 0 ; i < chain . length - 1 ; i ++ ) { chain [ i ] . setBackingComponent ( chain [ i + 1 ] ) ; } return chain [ 0 ] ; }
Creates a new interceptor chain to handle the given request .
19,164
public static Map < String , String [ ] > getRequestParameters ( final HttpServletRequest request ) { if ( request . getAttribute ( REQUEST_PROCESSED_KEY ) == null ) { setupRequestParameters ( request ) ; } return ( Map < String , String [ ] > ) request . getAttribute ( REQUEST_PARAMETERS_KEY ) ; }
Get a map of request parameters allowing for multi part form fields .
19,165
public static String getRequestParameterValue ( final HttpServletRequest request , final String key ) { String [ ] values = getRequestParameterValues ( request , key ) ; return values == null || values . length == 0 ? null : values [ 0 ] ; }
Get a value for a request parameter allowing for multi part form fields .
19,166
public static String [ ] getRequestParameterValues ( final HttpServletRequest request , final String key ) { return getRequestParameters ( request ) . get ( key ) ; }
Get the values for a request parameter allowing for multi part form fields .
19,167
public static Map < String , FileItem [ ] > getRequestFileItems ( final HttpServletRequest request ) { if ( request . getAttribute ( REQUEST_PROCESSED_KEY ) == null ) { setupRequestParameters ( request ) ; } return ( Map < String , FileItem [ ] > ) request . getAttribute ( REQUEST_FILES_KEY ) ; }
Get a map of file items in the request allowing for multi part form fields .
19,168
public static FileItem getRequestFileItemValue ( final HttpServletRequest request , final String key ) { FileItem [ ] values = getRequestFileItemValues ( request , key ) ; return values == null || values . length == 0 ? null : values [ 0 ] ; }
Get a file item value from the request allowing for multi part form fields .
19,169
public static FileItem [ ] getRequestFileItemValues ( final HttpServletRequest request , final String key ) { return getRequestFileItems ( request ) . get ( key ) ; }
Get file item values from the request allowing for multi part form fields .
19,170
public static void setupRequestParameters ( final HttpServletRequest request ) { if ( request . getAttribute ( REQUEST_PROCESSED_KEY ) != null ) { return ; } Map < String , String [ ] > parameters = new HashMap < > ( ) ; Map < String , FileItem [ ] > files = new HashMap < > ( ) ; extractParameterMap ( request , parameters , files ) ; request . setAttribute ( REQUEST_PROCESSED_KEY , "Y" ) ; request . setAttribute ( REQUEST_PARAMETERS_KEY , Collections . unmodifiableMap ( parameters ) ) ; request . setAttribute ( REQUEST_FILES_KEY , Collections . unmodifiableMap ( files ) ) ; }
Process the request parameters allowing for multi part form fields .
19,171
public static void extractParameterMap ( final HttpServletRequest request , final Map < String , String [ ] > parameters , final Map < String , FileItem [ ] > files ) { if ( isMultipart ( request ) ) { ServletFileUpload upload = new ServletFileUpload ( ) ; upload . setFileItemFactory ( new DiskFileItemFactory ( ) ) ; try { List fileItems = upload . parseRequest ( request ) ; uploadFileItems ( fileItems , parameters , files ) ; } catch ( FileUploadException ex ) { throw new SystemException ( ex ) ; } for ( Object entry : request . getParameterMap ( ) . entrySet ( ) ) { Map . Entry < String , String [ ] > param = ( Map . Entry < String , String [ ] > ) entry ; if ( ! parameters . containsKey ( param . getKey ( ) ) ) { parameters . put ( param . getKey ( ) , param . getValue ( ) ) ; } } } else { parameters . putAll ( request . getParameterMap ( ) ) ; } }
Extract the parameters and file items allowing for multi part form fields .
19,172
public static String extractCookie ( final HttpServletRequest request , final String name ) { for ( Cookie cookie : request . getCookies ( ) ) { if ( cookie . getName ( ) . equals ( name ) ) { return cookie . getValue ( ) ; } } return null ; }
Find the value of a cookie on the request by name .
19,173
private void updateRegion ( ) { actMessagePanel . setVisible ( false ) ; if ( rbtACT . isSelected ( ) ) { actMessagePanel . setVisible ( true ) ; regionFields . setVisible ( true ) ; regionSelector . setOptions ( new String [ ] { null , "Belconnen" , "City" , "Woden" } ) ; regionSelector . setVisible ( true ) ; } else if ( rbtNSW . isSelected ( ) ) { regionFields . setVisible ( true ) ; regionSelector . setOptions ( new String [ ] { null , "Hunter" , "Riverina" , "Southern Tablelands" } ) ; regionSelector . setVisible ( true ) ; } else if ( rbtVIC . isSelected ( ) ) { regionFields . setVisible ( true ) ; regionSelector . setOptions ( new String [ ] { null , "Gippsland" , "Melbourne" , "Mornington Peninsula" } ) ; regionSelector . setVisible ( true ) ; } else { regionSelector . setOptions ( new Object [ ] { null } ) ; regionSelector . setVisible ( false ) ; regionFields . setVisible ( false ) ; } }
Updates the visibility and options present in the region selector depending on the state selector s value .
19,174
public void setContent ( final WComponent content ) { WindowModel model = getOrCreateComponentModel ( ) ; if ( model . wrappedContent != null && model . wrappedContent != model . content ) { model . wrappedContent . removeAll ( ) ; } model . content = content ; if ( content instanceof WApplication ) { model . wrappedContent = ( WApplication ) content ; } else { model . wrappedContent = new WApplication ( ) ; model . wrappedContent . add ( content ) ; } holder . removeAll ( ) ; holder . add ( model . wrappedContent ) ; }
Set the WComponent that will handle the content for this pop up window .
19,175
public void setTitle ( final String title ) { String currTitle = getTitle ( ) ; if ( ! Objects . equals ( title , currTitle ) ) { getOrCreateComponentModel ( ) . title = title ; } }
Sets the window title .
19,176
public String getUrl ( ) { Environment env = getEnvironment ( ) ; Map < String , String > parameters = env . getHiddenParameters ( ) ; parameters . put ( WWINDOW_REQUEST_PARAM_KEY , getId ( ) ) ; parameters . put ( Environment . STEP_VARIABLE , String . valueOf ( getStep ( ) ) ) ; String url = env . getWServletPath ( ) ; return WebUtilities . getPath ( url , parameters , true ) ; }
Returns a dynamic URL that this wwindow component can be accessed from .
19,177
protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; boolean targeted = isPresent ( request ) ; setTargeted ( targeted ) ; if ( getState ( ) == ACTIVE_STATE && isTargeted ( ) ) { getComponentModel ( ) . wrappedContent . preparePaint ( request ) ; } }
Override preparePaintComponent to clear the scratch map before the window content is being painted .
19,178
protected void paintComponent ( final RenderContext renderContext ) { if ( getState ( ) == DISPLAY_STATE ) { setState ( ACTIVE_STATE ) ; showWindow ( renderContext ) ; } else if ( getState ( ) == ACTIVE_STATE && isTargeted ( ) ) { getComponentModel ( ) . wrappedContent . paint ( renderContext ) ; } }
Override paintComponent in order to paint the window or its content depending on the window state .
19,179
protected void showWindow ( final RenderContext renderContext ) { int current = UIContextHolder . getCurrent ( ) . getEnvironment ( ) . getStep ( ) ; int window = getStep ( ) ; setStep ( window + current ) ; if ( renderContext instanceof WebXmlRenderContext ) { PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; writer . print ( "\n<ui:popup" ) ; writer . print ( " url=\"" + WebUtilities . encode ( getUrl ( ) ) + '"' ) ; writer . print ( " width=\"" + getWidth ( ) + '"' ) ; writer . print ( " height=\"" + getHeight ( ) + '"' ) ; if ( isResizable ( ) ) { writer . print ( " resizable=\"true\"" ) ; } if ( isScrollable ( ) ) { writer . print ( " showScrollbars=\"true\"" ) ; } if ( isShowMenuBar ( ) ) { writer . print ( " showMenubar=\"true\"" ) ; } if ( isShowToolbar ( ) ) { writer . print ( " showToolbar=\"true\"" ) ; } if ( isShowLocation ( ) ) { writer . print ( " showLocation=\"true\"" ) ; } if ( isShowStatus ( ) ) { writer . print ( " showStatus=\"true\"" ) ; } if ( getTop ( ) >= 0 ) { writer . print ( " top=\"" + getTop ( ) + '\'' ) ; } if ( getLeft ( ) >= 0 ) { writer . print ( " left=\"" + getLeft ( ) + '\'' ) ; } writer . println ( "/>" ) ; } }
Emits the mark - up which pops up the window .
19,180
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WFileWidget fileWidget = ( WFileWidget ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = fileWidget . isReadOnly ( ) ; xml . appendTagOpen ( TAG_NAME ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , component . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; xml . appendEnd ( ) ; return ; } xml . appendOptionalAttribute ( "disabled" , fileWidget . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , fileWidget . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , fileWidget . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , fileWidget . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "acceptedMimeTypes" , typesToString ( fileWidget . getFileTypes ( ) ) ) ; long maxFileSize = fileWidget . getMaxFileSize ( ) ; xml . appendOptionalAttribute ( "maxFileSize" , maxFileSize > 0 , maxFileSize ) ; List < Diagnostic > diags = fileWidget . getDiagnostics ( Diagnostic . ERROR ) ; if ( diags == null || diags . isEmpty ( ) ) { xml . appendEnd ( ) ; return ; } xml . appendClose ( ) ; DiagnosticRenderUtil . renderDiagnostics ( fileWidget , renderContext ) ; xml . appendEndTag ( TAG_NAME ) ; }
Paints the given WFileWidget .
19,181
public OrganizationCreateResponse createOrganization ( OrganizationCreate data ) { return getResourceFactory ( ) . getApiResource ( "/org/" ) . entity ( data , MediaType . APPLICATION_JSON_TYPE ) . post ( OrganizationCreateResponse . class ) ; }
Creates a new organization
19,182
public void updateOrganization ( int orgId , OrganizationCreate data ) { getResourceFactory ( ) . getApiResource ( "/org/" + orgId ) . entity ( data , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates an organization with new name and logo . Note that the URL of the organization will not change even though the name changes .
19,183
public OrganizationMini getOrganizationByURL ( String url ) { return getResourceFactory ( ) . getApiResource ( "/org/url" ) . queryParam ( "url" , url ) . get ( OrganizationMini . class ) ; }
Returns the organization with the given full URL . The URL does not have to be truncated to the root it can be to any resource on the URL .
19,184
public List < OrganizationWithSpaces > getSharedOrganizations ( int userId ) { return getResourceFactory ( ) . getApiResource ( "/org/shared/" + userId ) . get ( new GenericType < List < OrganizationWithSpaces > > ( ) { } ) ; }
Returns the organizations and spaces that the logged in user shares with the specified user . The organizations and spaces will be returned sorted by name .
19,185
public List < Space > getSpaces ( int orgId ) { return getResourceFactory ( ) . getApiResource ( "/org/" + orgId + "/space/" ) . get ( new GenericType < List < Space > > ( ) { } ) ; }
Returns all the spaces for the organization .
19,186
public EndMemberInfo getEndMemberInfo ( int orgId , int userId ) { return getResourceFactory ( ) . getApiResource ( "/org/" + orgId + "/member/" + userId + "/end_member_info" ) . get ( EndMemberInfo . class ) ; }
Returns information about what would happen if this user would be removed from the org
19,187
public void setUseCamera ( final boolean useCamera ) { if ( useCamera != getUseCamera ( ) ) { ImageEditModel model = getOrCreateComponentModel ( ) ; model . useCamera = useCamera ; } }
Set to true if you wish to allow the user to capture an image from an attached camera . This feature is completely dependent on browser support and will essentially be ignored if the browser does not provide the necessary APIs .
19,188
public void setIsFace ( final boolean isFace ) { if ( isFace != getIsFace ( ) ) { ImageEditModel model = getOrCreateComponentModel ( ) ; model . isFace = isFace ; } }
Set to true to turn on face detection .
19,189
public void setRenderInline ( final boolean renderInline ) { if ( renderInline != getRenderInline ( ) ) { ImageEditModel model = getOrCreateComponentModel ( ) ; model . renderInline = renderInline ; } }
If true then the image editor will render where it is added in the tree instead of in a popup .
19,190
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WFigure figure = ( WFigure ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean renderChildren = isRenderContent ( figure ) ; xml . appendTagOpen ( "ui:figure" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; if ( FigureMode . LAZY . equals ( figure . getMode ( ) ) ) { xml . appendOptionalAttribute ( "hidden" , ! renderChildren , "true" ) ; } else { xml . appendOptionalAttribute ( "hidden" , component . isHidden ( ) , "true" ) ; } FigureMode mode = figure . getMode ( ) ; if ( mode != null ) { switch ( mode ) { case LAZY : xml . appendAttribute ( "mode" , "lazy" ) ; break ; case EAGER : xml . appendAttribute ( "mode" , "eager" ) ; break ; default : throw new SystemException ( "Unknown figure mode: " + figure . getMode ( ) ) ; } } xml . appendClose ( ) ; MarginRendererUtil . renderMargin ( figure , renderContext ) ; if ( renderChildren ) { figure . getDecoratedLabel ( ) . paint ( renderContext ) ; xml . appendTagOpen ( "ui:content" ) ; xml . appendAttribute ( "id" , component . getId ( ) + "-content" ) ; xml . appendClose ( ) ; figure . getContent ( ) . paint ( renderContext ) ; xml . appendEndTag ( "ui:content" ) ; } xml . appendEndTag ( "ui:figure" ) ; }
Paints the given WFigure .
19,191
public void preparePaintComponent ( final Request request ) { if ( ! this . isInitialised ( ) || resetButton . isPressed ( ) ) { String preferredState = request . getAppPreferenceParameter ( "example.preferred.state" ) ; stateSelector . setSelected ( preferredState ) ; this . setInitialised ( true ) ; } }
Override preparePaintComponent to set the initial selection from the app preferences . The selection is set the first time the example is accessed or when the reset button is used .
19,192
public void addColumn ( final WTableColumn column ) { columns . add ( column ) ; WDataTableRowRenderer renderer = ( WDataTableRowRenderer ) repeater . getRepeatedComponent ( ) ; renderer . addColumn ( column , columns . getChildCount ( ) - 1 ) ; }
Adds a column to the table .
19,193
public void setDataModel ( final TableDataModel dataModel ) { getOrCreateComponentModel ( ) . dataModel = dataModel ; getOrCreateComponentModel ( ) . rowIndexMapping = null ; if ( dataModel instanceof BeanTableDataModel ) { ( ( BeanTableDataModel ) dataModel ) . setBeanProvider ( new DataTableBeanProvider ( this ) ) ; ( ( BeanTableDataModel ) dataModel ) . setBeanProperty ( "." ) ; } if ( dataModel instanceof ScrollableTableDataModel ) { int startIndex = getCurrentPage ( ) * getRowsPerPage ( ) ; int endIndex = startIndex + getRowsPerPage ( ) - 1 ; ( ( ScrollableTableDataModel ) dataModel ) . setCurrentRows ( startIndex , endIndex ) ; } repeater . reset ( ) ; }
Sets the data model .
19,194
public void setPaginationMode ( final PaginationMode paginationMode ) { getOrCreateComponentModel ( ) . paginationMode = PaginationMode . SERVER . equals ( paginationMode ) ? PaginationMode . DYNAMIC : paginationMode ; }
Sets the pagination mode . Mode . SERVER mapped to Mode . DYNAMIC to overcome accessibility problem .
19,195
public void setExpandMode ( final ExpandMode expandMode ) { getOrCreateComponentModel ( ) . expandMode = ExpandMode . SERVER . equals ( expandMode ) ? ExpandMode . DYNAMIC : expandMode ; }
Sets the row expansion mode . ExpandMode . SERVER mapped to ExpandMode . DYNAMIC to overcome accessibility problems .
19,196
public void handleRequest ( final Request request ) { super . handleRequest ( request ) ; if ( isPresent ( request ) ) { if ( getExpandMode ( ) != ExpandMode . NONE ) { handleExpansionRequest ( request ) ; } if ( getSelectMode ( ) != SelectMode . NONE ) { handleSelectionRequest ( request ) ; } if ( getPaginationMode ( ) != PaginationMode . NONE ) { handlePaginationRequest ( request ) ; } if ( isFilterable ( ) ) { handleFilterRequest ( request ) ; } if ( isSortable ( ) ) { handleSortRequest ( request ) ; } } }
Override handleRequest to add table - specific functionality such as pagination and row selection .
19,197
private void handleFilterRequest ( final Request request ) { String [ ] paramValues = request . getParameterValues ( getId ( ) + ".filters" ) ; if ( paramValues == null ) { setActiveFilters ( new ArrayList < String > ( 0 ) ) ; } else { List < String > filters = Arrays . asList ( paramValues ) ; setActiveFilters ( filters ) ; } }
Handles a request containing filtering data .
19,198
private int getCurrentPageStartRow ( ) { int startRow = 0 ; if ( getPaginationMode ( ) != PaginationMode . NONE ) { int rowsPerPage = getRowsPerPage ( ) ; TableDataModel model = getDataModel ( ) ; if ( model instanceof TreeTableDataModel ) { TreeTableDataModel treeModel = ( TreeTableDataModel ) model ; TreeNode root = treeModel . getNodeAtLine ( 0 ) . getRoot ( ) ; int startNode = getCurrentPage ( ) * rowsPerPage ; startRow = ( ( TableTreeNode ) root . getChildAt ( startNode ) ) . getRowIndex ( ) - 1 ; } else { startRow = getCurrentPage ( ) * rowsPerPage ; } } return startRow ; }
Retrieves the starting row index for the current page . Will always return zero for tables which are not paginated .
19,199
private int getCurrentPageEndRow ( ) { TableDataModel model = getDataModel ( ) ; int rowsPerPage = getRowsPerPage ( ) ; int endRow = model . getRowCount ( ) - 1 ; if ( getPaginationMode ( ) != PaginationMode . NONE ) { if ( model instanceof TreeTableDataModel ) { TreeTableDataModel treeModel = ( TreeTableDataModel ) model ; TreeNode root = treeModel . getNodeAtLine ( 0 ) . getRoot ( ) ; int endNode = Math . min ( root . getChildCount ( ) - 1 , ( getCurrentPage ( ) + 1 ) * rowsPerPage - 1 ) ; endRow = ( ( TableTreeNode ) root . getChildAt ( endNode ) ) . getRowIndex ( ) - 1 + ( ( TableTreeNode ) root . getChildAt ( endNode ) ) . getNodeCount ( ) ; } else { endRow = Math . min ( model . getRowCount ( ) - 1 , ( getCurrentPage ( ) + 1 ) * rowsPerPage - 1 ) ; } } return endRow ; }
Retrieves the ending row index for the current page . Will always return the row count minus 1 for tables which are not paginated .