idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
13,400
public CreateIssueParams notifiedUserIds ( List notifiedUserIds ) { for ( Object notifiedUserId : notifiedUserIds ) { parameters . add ( new NameValuePair ( "notifiedUserId[]" , notifiedUserId . toString ( ) ) ) ; } return this ; }
Sets the issue notified users .
64
7
13,401
public CreateIssueParams textCustomFields ( List < CustomFiledValue > customFieldValueList ) { for ( CustomFiledValue customFiledValue : customFieldValueList ) { textCustomField ( customFiledValue ) ; } return this ; }
Sets the text type custom field with Map .
55
10
13,402
public CreateIssueParams multipleListCustomField ( CustomFiledItems customFiledItems ) { for ( Object id : customFiledItems . getCustomFieldItemIds ( ) ) { parameters . add ( new NameValuePair ( "customField_" + customFiledItems . getCustomFieldId ( ) , id . toString ( ) ) ) ; } return this ; }
Sets the multiple list type custom field .
82
9
13,403
public CreateIssueParams multipleListCustomFields ( List < CustomFiledItems > customFiledItemsList ) { for ( CustomFiledItems customFiledItems : customFiledItemsList ) { multipleListCustomField ( customFiledItems ) ; } return this ; }
Sets the multiple list type custom field with Map .
59
11
13,404
public String getSharedFileEndpoint ( Object projectIdOrKey , Object sharedFileId ) throws BacklogException { return buildEndpoint ( "projects/" + projectIdOrKey + "/files/" + sharedFileId ) ; }
Returns the endpoint of shared file .
49
7
13,405
public String getWikiAttachmentEndpoint ( Object wikiId , Object attachmentId ) throws BacklogException { return buildEndpoint ( "wikis/" + wikiId + "/attachments/" + attachmentId ) ; }
Returns the endpoint of Wiki page s attachment file .
45
10
13,406
public CreateWebhookParams description ( String description ) { String value = ( description == null ) ? "" : description ; parameters . add ( new NameValuePair ( "description" , value ) ) ; return this ; }
Sets the description parameter .
47
6
13,407
public AddPullRequestCommentParams notifiedUserIds ( List < Long > notifiedUserIds ) { for ( Long notifiedUserId : notifiedUserIds ) { parameters . add ( new NameValuePair ( "notifiedUserId[]" , String . valueOf ( notifiedUserId ) ) ) ; } return this ; }
Sets the notified users .
70
6
13,408
public UpdatePullRequestParams notifiedUserIds ( List < Long > notifiedUserIds ) { for ( Long notifiedUserId : notifiedUserIds ) { parameters . add ( new NameValuePair ( "notifiedUserId[]" , notifiedUserId . toString ( ) ) ) ; } return this ; }
Sets the pull request notified users .
68
8
13,409
public UpdatePullRequestParams attachmentIds ( List < Long > attachmentIds ) { for ( Long attachmentId : attachmentIds ) { parameters . add ( new NameValuePair ( "attachmentId[]" , attachmentId . toString ( ) ) ) ; } return this ; }
Sets the pull request attachment files .
62
8
13,410
@ Override public void encodeEnd ( final FacesContext context , final UIComponent component ) throws IOException { final ResponseWriter responseWriter = context . getResponseWriter ( ) ; final Sheet sheet = ( Sheet ) component ; // update column mappings on render sheet . updateColumnMappings ( ) ; // sort data sheet . sortAndFilter ( ) ; // encode markup encodeMarkup ( context , sheet , responseWriter ) ; // encode javascript encodeScript ( context , sheet , responseWriter ) ; }
Encodes the Sheet component
104
5
13,411
protected void encodeMarkup ( final FacesContext context , final Sheet sheet , final ResponseWriter responseWriter ) throws IOException { /* * <div id="..." name="..." class="" style=""> */ final String styleClass = sheet . getStyleClass ( ) ; final String clientId = sheet . getClientId ( context ) ; final Integer width = sheet . getWidth ( ) ; final Integer height = sheet . getHeight ( ) ; String style = sheet . getStyle ( ) ; // outer div to wrapper table responseWriter . startElement ( "div" , null ) ; responseWriter . writeAttribute ( "id" , clientId , "id" ) ; responseWriter . writeAttribute ( "name" , clientId , "clientId" ) ; // note: can't use ui-datatable here because it will mess with // handsontable cell rendering String divclass = "ui-handsontable ui-widget" ; if ( styleClass != null ) { divclass = divclass + " " + styleClass ; } if ( ! sheet . isValid ( ) ) { divclass = divclass + " ui-state-error" ; } responseWriter . writeAttribute ( "class" , divclass , "styleClass" ) ; if ( width != null ) { responseWriter . writeAttribute ( "style" , "width: " + width + "px;" , null ) ; } encodeHiddenInputs ( responseWriter , sheet , clientId ) ; encodeFilterValues ( context , responseWriter , sheet , clientId ) ; encodeHeader ( context , responseWriter , sheet ) ; // handsontable div responseWriter . startElement ( "div" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_tbl" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_tbl" , "clientId" ) ; responseWriter . writeAttribute ( "class" , "handsontable-inner" , "styleClass" ) ; if ( style == null ) { style = Constants . EMPTY_STRING ; } if ( width != null ) { style = style + "width: " + width + "px;" ; } if ( height != null ) { style = style + "height: " + height + "px;" ; } else { style = style + "height: 100%;" ; } if ( style . length ( ) > 0 ) { responseWriter . writeAttribute ( "style" , style , null ) ; } responseWriter . endElement ( "div" ) ; encodeFooter ( context , responseWriter , sheet ) ; responseWriter . endElement ( "div" ) ; }
Encodes the HTML markup for the sheet .
564
9
13,412
protected void encodeOptionalAttr ( final WidgetBuilder wb , final String attrName , final String value ) throws IOException { if ( value != null ) { wb . attr ( attrName , value ) ; } }
Encodes an optional attribute to the widget builder specified .
50
11
13,413
protected void encodeInvalidData ( final FacesContext context , final Sheet sheet , final WidgetBuilder wb ) throws IOException { wb . attr ( "errors" , sheet . getInvalidDataValue ( ) ) ; }
Encodes the necessary JS to render invalid data .
47
10
13,414
protected void encodeColHeaders ( final FacesContext context , final Sheet sheet , final WidgetBuilder wb ) throws IOException { final JavascriptVarBuilder vb = new JavascriptVarBuilder ( null , false ) ; for ( final SheetColumn column : sheet . getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } vb . appendArrayValue ( column . getHeaderText ( ) , true ) ; } wb . nativeAttr ( "colHeaders" , vb . closeVar ( ) . toString ( ) ) ; }
Encode the column headers
122
5
13,415
protected void encodeData ( final FacesContext context , final Sheet sheet , final WidgetBuilder wb ) throws IOException { final JavascriptVarBuilder jsData = new JavascriptVarBuilder ( null , false ) ; final JavascriptVarBuilder jsRowKeys = new JavascriptVarBuilder ( null , false ) ; final JavascriptVarBuilder jsStyle = new JavascriptVarBuilder ( null , true ) ; final JavascriptVarBuilder jsRowStyle = new JavascriptVarBuilder ( null , false ) ; final JavascriptVarBuilder jsReadOnly = new JavascriptVarBuilder ( null , true ) ; final JavascriptVarBuilder jsRowHeaders = new JavascriptVarBuilder ( null , false ) ; final boolean isCustomHeader = sheet . getRowHeaderValueExpression ( ) != null ; final List < Object > values = sheet . getSortedValues ( ) ; int row = 0 ; for ( final Object value : values ) { context . getExternalContext ( ) . getRequestMap ( ) . put ( sheet . getVar ( ) , value ) ; final String rowKey = sheet . getRowKeyValueAsString ( context ) ; jsRowKeys . appendArrayValue ( rowKey , true ) ; encodeRow ( context , rowKey , jsData , jsRowStyle , jsStyle , jsReadOnly , sheet , row ) ; // In case of custom row header evaluate the value expression for every row to // set the header if ( sheet . isShowRowHeaders ( ) && isCustomHeader ) { final String rowHeader = sheet . getRowHeaderValueAsString ( context ) ; jsRowHeaders . appendArrayValue ( rowHeader , true ) ; } row ++ ; } sheet . setRowVar ( context , null ) ; wb . nativeAttr ( "data" , jsData . closeVar ( ) . toString ( ) ) ; wb . nativeAttr ( "styles" , jsStyle . closeVar ( ) . toString ( ) ) ; wb . nativeAttr ( "rowStyles" , jsRowStyle . closeVar ( ) . toString ( ) ) ; wb . nativeAttr ( "readOnlyCells" , jsReadOnly . closeVar ( ) . toString ( ) ) ; wb . nativeAttr ( "rowKeys" , jsRowKeys . closeVar ( ) . toString ( ) ) ; // add the row header as a native attribute if ( ! isCustomHeader ) { wb . nativeAttr ( "rowHeaders" , sheet . isShowRowHeaders ( ) . toString ( ) ) ; } else { wb . nativeAttr ( "rowHeaders" , jsRowHeaders . closeVar ( ) . toString ( ) ) ; } }
Encode the row data . Builds row data style data and read only object .
563
17
13,416
protected JavascriptVarBuilder encodeRow ( final FacesContext context , final String rowKey , final JavascriptVarBuilder jsData , final JavascriptVarBuilder jsRowStyle , final JavascriptVarBuilder jsStyle , final JavascriptVarBuilder jsReadOnly , final Sheet sheet , final int rowIndex ) throws IOException { // encode rowStyle (if any) final String rowStyleClass = sheet . getRowStyleClass ( ) ; if ( rowStyleClass == null ) { jsRowStyle . appendArrayValue ( "null" , false ) ; } else { jsRowStyle . appendArrayValue ( rowStyleClass , true ) ; } // data is array of array of data final JavascriptVarBuilder jsRow = new JavascriptVarBuilder ( null , false ) ; int renderCol = 0 ; for ( int col = 0 ; col < sheet . getColumns ( ) . size ( ) ; col ++ ) { final SheetColumn column = sheet . getColumns ( ) . get ( col ) ; if ( ! column . isRendered ( ) ) { continue ; } // render data value final String value = sheet . getRenderValueForCell ( context , rowKey , col ) ; jsRow . appendArrayValue ( value , true ) ; // custom style final String styleClass = column . getStyleClass ( ) ; if ( styleClass != null ) { jsStyle . appendRowColProperty ( rowIndex , renderCol , styleClass , true ) ; } // read only per cell final boolean readOnly = column . isReadonlyCell ( ) ; if ( readOnly ) { jsReadOnly . appendRowColProperty ( rowIndex , renderCol , "true" , true ) ; } renderCol ++ ; } // close row and append to jsData jsData . appendArrayValue ( jsRow . closeVar ( ) . toString ( ) , false ) ; return jsData ; }
Encode a single row .
385
6
13,417
private void encodeHiddenInputs ( final ResponseWriter responseWriter , final Sheet sheet , final String clientId ) throws IOException { responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_input" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_input" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; responseWriter . writeAttribute ( "value" , "" , null ) ; responseWriter . endElement ( "input" ) ; responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_focus" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_focus" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; if ( sheet . getFocusId ( ) == null ) { responseWriter . writeAttribute ( "value" , "" , null ) ; } else { responseWriter . writeAttribute ( "value" , sheet . getFocusId ( ) , null ) ; } responseWriter . endElement ( "input" ) ; responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_selection" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_selection" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; if ( sheet . getSelection ( ) == null ) { responseWriter . writeAttribute ( "value" , "" , null ) ; } else { responseWriter . writeAttribute ( "value" , sheet . getSelection ( ) , null ) ; } responseWriter . endElement ( "input" ) ; // sort col and order if specified and supported final int sortCol = sheet . getSortColRenderIndex ( ) ; responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_sortby" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_sortby" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; responseWriter . writeAttribute ( "value" , sortCol , null ) ; responseWriter . endElement ( "input" ) ; responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_sortorder" , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_sortorder" , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; responseWriter . writeAttribute ( "value" , sheet . getSortOrder ( ) . toLowerCase ( ) , null ) ; responseWriter . endElement ( "input" ) ; }
Encode hidden input fields
644
5
13,418
private void encodeFooter ( final FacesContext context , final ResponseWriter responseWriter , final Sheet sheet ) throws IOException { // footer final UIComponent footer = sheet . getFacet ( "footer" ) ; if ( footer != null ) { responseWriter . startElement ( "div" , null ) ; responseWriter . writeAttribute ( "class" , "ui-datatable-footer ui-widget-header ui-corner-bottom" , null ) ; footer . encodeAll ( context ) ; responseWriter . endElement ( "div" ) ; } }
Encode the sheet footer
127
6
13,419
private void encodeHeader ( final FacesContext context , final ResponseWriter responseWriter , final Sheet sheet ) throws IOException { // header final UIComponent header = sheet . getFacet ( "header" ) ; if ( header != null ) { responseWriter . startElement ( "div" , null ) ; responseWriter . writeAttribute ( "class" , "ui-datatable-header ui-widget-header ui-corner-top" , null ) ; header . encodeAll ( context ) ; responseWriter . endElement ( "div" ) ; } }
Encode the Sheet header
120
5
13,420
protected void encodeFilterValues ( final FacesContext context , final ResponseWriter responseWriter , final Sheet sheet , final String clientId ) throws IOException { int renderCol = 0 ; for ( final SheetColumn column : sheet . getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } if ( column . getValueExpression ( "filterBy" ) != null ) { responseWriter . startElement ( "input" , null ) ; responseWriter . writeAttribute ( "id" , clientId + "_filter_" + renderCol , "id" ) ; responseWriter . writeAttribute ( "name" , clientId + "_filter_" + renderCol , "name" ) ; responseWriter . writeAttribute ( "type" , "hidden" , null ) ; responseWriter . writeAttribute ( "value" , column . getFilterValue ( ) , null ) ; responseWriter . endElement ( "input" ) ; } renderCol ++ ; } }
Encodes the filter values .
206
6
13,421
protected void encodeSortVar ( final FacesContext context , final Sheet sheet , final WidgetBuilder wb ) throws IOException { final JavascriptVarBuilder vb = new JavascriptVarBuilder ( null , false ) ; for ( final SheetColumn column : sheet . getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } if ( column . getValueExpression ( "sortBy" ) == null ) { vb . appendArrayValue ( "false" , false ) ; } else { vb . appendArrayValue ( "true" , false ) ; } } wb . nativeAttr ( "sortable" , vb . closeVar ( ) . toString ( ) ) ; }
Encodes a javascript sort var that informs the col header event of the column s sorting options . The var is an array of boolean indicating whether or not the column is sortable .
152
36
13,422
protected void decodeFilters ( final FacesContext context , final Sheet sheet , final Map < String , String > params , final String clientId ) { int renderCol = 0 ; for ( final SheetColumn column : sheet . getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } if ( column . getValueExpression ( "filterBy" ) != null ) { final String value = params . get ( clientId + "_filter_" + renderCol ) ; column . setFilterValue ( value ) ; } renderCol ++ ; } }
Decodes the filter values
121
5
13,423
private void decodeSelection ( final FacesContext context , final Sheet sheet , final String jsonSelection ) { if ( LangUtils . isValueBlank ( jsonSelection ) ) { return ; } try { // data comes in: [ [row, col, oldValue, newValue] ... ] final JSONArray array = new JSONArray ( jsonSelection ) ; sheet . setSelectedRow ( array . getInt ( 0 ) ) ; sheet . setSelectedColumn ( sheet . getMappedColumn ( array . getInt ( 1 ) ) ) ; sheet . setSelectedLastRow ( array . getInt ( 2 ) ) ; sheet . setSelectedLastColumn ( array . getInt ( 3 ) ) ; sheet . setSelection ( jsonSelection ) ; } catch ( final JSONException e ) { throw new FacesException ( "Failed parsing Ajax JSON message for cell selection event:" + e . getMessage ( ) , e ) ; } }
Decodes the user Selection JSON data
201
7
13,424
private void decodeSubmittedValues ( final FacesContext context , final Sheet sheet , final String jsonData ) { if ( LangUtils . isValueBlank ( jsonData ) ) { return ; } try { // data comes in as a JSON Object with named properties for the row and columns // updated this is so that // multiple updates to the same cell overwrite previous deltas prior to // submission we don't care about // the property names, just the values, which we'll process in turn final JSONObject obj = new JSONObject ( jsonData ) ; final Iterator < String > keys = obj . keys ( ) ; while ( keys . hasNext ( ) ) { final String key = keys . next ( ) ; // data comes in: [row, col, oldValue, newValue, rowKey] final JSONArray update = obj . getJSONArray ( key ) ; // GitHub #586 pasted more values than rows if ( update . isNull ( 4 ) ) { continue ; } final String rowKey = update . getString ( 4 ) ; final int col = sheet . getMappedColumn ( update . getInt ( 1 ) ) ; final String newValue = String . valueOf ( update . get ( 3 ) ) ; sheet . setSubmittedValue ( context , rowKey , col , newValue ) ; } } catch ( final JSONException ex ) { throw new FacesException ( "Failed parsing Ajax JSON message for cell change event:" + ex . getMessage ( ) , ex ) ; } }
Converts the JSON data received from the in the request params into our sumitted values map . The map is cleared first .
314
25
13,425
public RequestParameterBuilder paramJson ( String name , Object value ) throws UnsupportedEncodingException { return paramJson ( name , value , null ) ; }
Adds a request parameter to the URL without specifying a data type of the given parameter value . Parameter s value is converted to JSON notation when adding . Furthermore it will be encoded according to the acquired encoding .
34
41
13,426
public RequestParameterBuilder paramJson ( String name , Object value , String type ) throws UnsupportedEncodingException { String encodedJsonValue = encodeJson ( value , type ) ; if ( added || originalUrl . contains ( "?" ) ) { buffer . append ( "&" ) ; } else { buffer . append ( "?" ) ; } buffer . append ( name ) ; buffer . append ( "=" ) ; buffer . append ( encodedJsonValue ) ; // set a flag that at least one request parameter was added added = true ; return this ; }
Adds a request parameter to the URL with specifying a data type of the given parameter value . Data type is sometimes required especially for Java generic types because type information is erased at runtime and the conversion to JSON will not work properly . Parameter s value is converted to JSON notation when adding . Furthermore it will be encoded according to the acquired encoding .
119
68
13,427
public String encodeJson ( Object value , String type ) throws UnsupportedEncodingException { jsonConverter . setType ( type ) ; String jsonValue ; if ( value == null ) { jsonValue = "null" ; } else { jsonValue = jsonConverter . getAsString ( null , null , value ) ; } return URLEncoder . encode ( jsonValue , encoding ) ; }
Convertes give value to JSON and encodes the converted value with a proper encoding . Data type is sometimes required especially for Java generic types because type information is erased at runtime and the conversion to JSON will not work properly .
86
45
13,428
public String build ( ) { String url = buffer . toString ( ) ; if ( url . length ( ) > 2083 ) { LOG . warning ( "URL " + url + " is longer than 2083 chars (" + buffer . length ( ) + "). It may not work properly in old IE versions." ) ; } return url ; }
Builds the end result .
72
6
13,429
public RequestParameterBuilder reset ( ) { buffer = new StringBuilder ( originalUrl ) ; jsonConverter . setType ( null ) ; added = false ; return this ; }
Resets the internal state in order to be reused .
37
11
13,430
public DynaFormControl addControl ( final Object data , final int colspan , final int rowspan ) { return addControl ( data , DynaFormControl . DEFAULT_TYPE , colspan , rowspan ) ; }
Adds control with given data default type colspan and rowspan .
47
13
13,431
public DynaFormControl addControl ( final Object data , final String type , final int colspan , final int rowspan ) { final DynaFormControl dynaFormControl = new DynaFormControl ( data , type , colspan , rowspan , row , elements . size ( ) + 1 , dynaFormModel . getControls ( ) . size ( ) + 1 , extended ) ; elements . add ( dynaFormControl ) ; dynaFormModel . getControls ( ) . add ( dynaFormControl ) ; totalColspan = totalColspan + colspan ; return dynaFormControl ; }
Adds control with given data type colspan and rowspan .
130
12
13,432
public DynaFormLabel addLabel ( final String value , final int colspan , final int rowspan ) { return addLabel ( value , true , colspan , rowspan ) ; }
Adds a label with given text colspan and rowspan .
39
12
13,433
public DynaFormLabel addLabel ( final String value , final boolean escape , final int colspan , final int rowspan ) { final DynaFormLabel dynaFormLabel = new DynaFormLabel ( value , escape , colspan , rowspan , row , elements . size ( ) + 1 , extended ) ; elements . add ( dynaFormLabel ) ; dynaFormModel . getLabels ( ) . add ( dynaFormLabel ) ; totalColspan = totalColspan + colspan ; return dynaFormLabel ; }
Adds a label with given text escape flag colspan and rowspan .
113
14
13,434
private void getColumns ( final UIComponent parent ) { for ( final UIComponent child : parent . getChildren ( ) ) { if ( child instanceof SheetColumn ) { columns . add ( ( SheetColumn ) child ) ; } } }
Grabs the UIColumn children for the parent specified .
54
13
13,435
public void reset ( ) { resetSubmitted ( ) ; resetSort ( ) ; resetInvalidUpdates ( ) ; localValues . clear ( ) ; for ( final SheetColumn c : getColumns ( ) ) { c . setFilterValue ( null ) ; } }
Resets all filters sorting and submitted values .
56
9
13,436
public void setSubmittedValue ( final FacesContext context , final String rowKey , final int col , final String value ) { submittedValues . put ( new SheetRowColIndex ( rowKey , col ) , value ) ; }
Updates a submitted value .
47
6
13,437
public String getSubmittedValue ( final String rowKey , final int col ) { return submittedValues . get ( new SheetRowColIndex ( rowKey , col ) ) ; }
Retrieves the submitted value for the row and col .
37
12
13,438
public void setLocalValue ( final String rowKey , final int col , final Object value ) { localValues . put ( new SheetRowColIndex ( rowKey , col ) , value ) ; }
Updates a local value .
41
6
13,439
public Object getLocalValue ( final String rowKey , final int col ) { return localValues . get ( new SheetRowColIndex ( rowKey , col ) ) ; }
Retrieves the submitted value for the rowKey and col .
36
13
13,440
public void setRowVar ( final FacesContext context , final String rowKey ) { if ( context == null ) { return ; } if ( rowKey == null ) { context . getExternalContext ( ) . getRequestMap ( ) . remove ( getVar ( ) ) ; } else { final Object value = getRowMap ( ) . get ( rowKey ) ; context . getExternalContext ( ) . getRequestMap ( ) . put ( getVar ( ) , value ) ; } }
Updates the row var for iterations over the list . The var value will be updated to the value for the specified rowKey .
102
26
13,441
public Object getValueForCell ( final FacesContext context , final String rowKey , final int col ) { // if we have a local value, use it // note: can't check for null, as null may be the submitted value final SheetRowColIndex index = new SheetRowColIndex ( rowKey , col ) ; if ( localValues . containsKey ( index ) ) { return localValues . get ( index ) ; } setRowVar ( context , rowKey ) ; final SheetColumn column = getColumns ( ) . get ( col ) ; return column . getValueExpression ( "value" ) . getValue ( context . getELContext ( ) ) ; }
Gets the object value of the row and col specified . If a local value exists that is returned otherwise the actual value is return .
141
27
13,442
public String getRenderValueForCell ( final FacesContext context , final String rowKey , final int col ) { // if we have a submitted value still, use it // note: can't check for null, as null may be the submitted value final SheetRowColIndex index = new SheetRowColIndex ( rowKey , col ) ; if ( submittedValues . containsKey ( index ) ) { return submittedValues . get ( index ) ; } final Object value = getValueForCell ( context , rowKey , col ) ; if ( value == null ) { return null ; } final SheetColumn column = getColumns ( ) . get ( col ) ; final Converter converter = ComponentUtils . getConverter ( context , column ) ; if ( converter == null ) { return value . toString ( ) ; } else { return converter . getAsString ( context , this , value ) ; } }
Gets the render string for the value the given cell . Applys the available converters to convert the value .
188
23
13,443
protected String getRowHeaderValueAsString ( final FacesContext context ) { final ValueExpression veRowHeader = getRowHeaderValueExpression ( ) ; final Object value = veRowHeader . getValue ( context . getELContext ( ) ) ; if ( value == null ) { return Constants . EMPTY_STRING ; } else { return value . toString ( ) ; } }
Gets the row header text value as a string for use in javascript
82
14
13,444
public List < Object > getSortedValues ( ) { List < Object > filtered = getFilteredValue ( ) ; if ( filtered == null || filtered . isEmpty ( ) ) { filtered = sortAndFilter ( ) ; } return filtered ; }
The sorted list of values .
52
6
13,445
public int getSortColRenderIndex ( ) { final ValueExpression veSortBy = getValueExpression ( PropertyKeys . sortBy . name ( ) ) ; if ( veSortBy == null ) { return - 1 ; } final String sortByExp = veSortBy . getExpressionString ( ) ; int colIdx = 0 ; for ( final SheetColumn column : getColumns ( ) ) { if ( ! column . isRendered ( ) ) { continue ; } final ValueExpression veCol = column . getValueExpression ( PropertyKeys . sortBy . name ( ) ) ; if ( veCol != null ) { if ( veCol . getExpressionString ( ) . equals ( sortByExp ) ) { return colIdx ; } } colIdx ++ ; } return - 1 ; }
Gets the rendered col index of the column corresponding to the current sortBy . This is used to keep track of the current sort column in the page .
172
31
13,446
public List < Object > sortAndFilter ( ) { final List filteredList = getFilteredValue ( ) ; filteredList . clear ( ) ; rowMap = new HashMap <> ( ) ; rowNumbers = new HashMap <> ( ) ; final Collection < ? > values = ( Collection < ? > ) getValue ( ) ; if ( values == null || values . isEmpty ( ) ) { return filteredList ; } remapRows ( ) ; boolean filters = false ; for ( final SheetColumn col : getColumns ( ) ) { if ( ! LangUtils . isValueBlank ( col . getFilterValue ( ) ) ) { filters = true ; break ; } } final FacesContext context = FacesContext . getCurrentInstance ( ) ; final Map < String , Object > requestMap = context . getExternalContext ( ) . getRequestMap ( ) ; final String var = getVar ( ) ; if ( filters ) { // iterate and add those matching the filters for ( final Object obj : values ) { requestMap . put ( var , obj ) ; if ( matchesFilter ( obj ) ) { filteredList . add ( obj ) ; } } } else { filteredList . addAll ( values ) ; } final ValueExpression veSortBy = getValueExpression ( PropertyKeys . sortBy . name ( ) ) ; if ( veSortBy != null ) { Collections . sort ( filteredList , new BeanPropertyComparator ( veSortBy , var , convertSortOrder ( ) , null , isCaseSensitiveSort ( ) , Locale . ENGLISH , getNullSortOrder ( ) ) ) ; } // map filtered rows remapFilteredList ( filteredList ) ; return filteredList ; }
Sorts and filters the data
361
6
13,447
@ Override protected Object getRowKeyValue ( final FacesContext context ) { final ValueExpression veRowKey = getValueExpression ( PropertyKeys . rowKey . name ( ) ) ; if ( veRowKey == null ) { throw new RuntimeException ( "RowKey required on sheet!" ) ; } final Object value = veRowKey . getValue ( context . getELContext ( ) ) ; if ( value == null ) { throw new RuntimeException ( "RowKey must resolve to non-null value for updates to work properly" ) ; } return value ; }
Gets the rowKey for the current row
119
9
13,448
protected String getRowKeyValueAsString ( final Object key ) { final String result = key . toString ( ) ; return "r_" + StringUtils . deleteWhitespace ( result ) ; }
Gets the row key value as a String suitable for use in javascript rendering .
44
16
13,449
protected SortOrder convertSortOrder ( ) { final String sortOrder = getSortOrder ( ) ; if ( sortOrder == null ) { return SortOrder . UNSORTED ; } else { final SortOrder result = SortOrder . valueOf ( sortOrder . toUpperCase ( Locale . ENGLISH ) ) ; return result ; } }
Convert to PF SortOrder enum since we are leveraging PF sorting code .
73
15
13,450
@ Override public void validate ( final FacesContext context ) { // iterate over submitted values and attempt to convert to the proper // data type. For successful values, remove from submitted and add to // local values map. for failures, add a conversion message and leave in // the submitted state final Iterator < Entry < SheetRowColIndex , String > > entries = submittedValues . entrySet ( ) . iterator ( ) ; final boolean hadBadUpdates = ! getInvalidUpdates ( ) . isEmpty ( ) ; getInvalidUpdates ( ) . clear ( ) ; while ( entries . hasNext ( ) ) { final Entry < SheetRowColIndex , String > entry = entries . next ( ) ; final SheetColumn column = getColumns ( ) . get ( entry . getKey ( ) . getColIndex ( ) ) ; final String newValue = entry . getValue ( ) ; final String rowKey = entry . getKey ( ) . getRowKey ( ) ; final int col = entry . getKey ( ) . getColIndex ( ) ; setRowVar ( context , rowKey ) ; // attempt to convert new value from string to correct object type // based on column converter. Use PF util as helper final Converter converter = ComponentUtils . getConverter ( context , column ) ; // assume string value if converter not found Object newValueObj = newValue ; if ( converter != null ) { try { newValueObj = converter . getAsObject ( context , this , newValue ) ; } catch ( final ConverterException e ) { // add offending cell to list of bad updates // and to a StringBuilder for error messages (so we have one // message for the component) setValid ( false ) ; FacesMessage message = e . getFacesMessage ( ) ; if ( message == null ) { message = new FacesMessage ( FacesMessage . SEVERITY_ERROR , e . getMessage ( ) , e . getMessage ( ) ) ; } context . addMessage ( this . getClientId ( context ) , message ) ; final String messageText = message . getDetail ( ) ; getInvalidUpdates ( ) . add ( new SheetInvalidUpdate ( getRowKeyValue ( context ) , col , column , newValue , messageText ) ) ; continue ; } } // value is fine, no further validations (again, not to be confused // with validators. until we have a "required" or something like // that, nothing else to do). setLocalValue ( rowKey , col , newValueObj ) ; // process validators on column column . setValue ( newValueObj ) ; try { column . validate ( context ) ; } finally { column . resetValue ( ) ; } entries . remove ( ) ; } setRowVar ( context , null ) ; final boolean newBadUpdates = ! getInvalidUpdates ( ) . isEmpty ( ) ; final String errorMessage = getErrorMessage ( ) ; if ( hadBadUpdates || newBadUpdates ) { // update the bad data var if partial request if ( context . getPartialViewContext ( ) . isPartialRequest ( ) ) { renderBadUpdateScript ( context ) ; } } if ( newBadUpdates && errorMessage != null ) { final FacesMessage message = new FacesMessage ( FacesMessage . SEVERITY_ERROR , errorMessage , errorMessage ) ; context . addMessage ( null , message ) ; } }
Converts each submitted value into a local value and stores it back in the hash . If all values convert without error then the component is valid and we can proceed to the processUpdates .
717
38
13,451
@ Override public Object saveState ( final FacesContext context ) { final Object values [ ] = new Object [ 8 ] ; values [ 0 ] = super . saveState ( context ) ; values [ 1 ] = submittedValues ; values [ 2 ] = localValues ; values [ 3 ] = invalidUpdates ; values [ 4 ] = columnMapping ; values [ 5 ] = getFilteredValue ( ) ; values [ 6 ] = rowMap ; values [ 7 ] = rowNumbers ; return values ; }
Saves the state of the submitted and local values and the bad updates .
105
15
13,452
@ Override public void restoreState ( final FacesContext context , final Object state ) { if ( state == null ) { return ; } final Object values [ ] = ( Object [ ] ) state ; super . restoreState ( context , values [ 0 ] ) ; final Object restoredSubmittedValues = values [ 1 ] ; final Object restoredLocalValues = values [ 2 ] ; final Object restoredInvalidUpdates = values [ 3 ] ; final Object restoredColMappings = values [ 4 ] ; final Object restoredSortedList = values [ 5 ] ; final Object restoredRowMap = values [ 6 ] ; final Object restoredRowNumbers = values [ 7 ] ; if ( restoredSubmittedValues == null ) { submittedValues . clear ( ) ; } else { submittedValues = ( Map < SheetRowColIndex , String > ) restoredSubmittedValues ; } if ( restoredLocalValues == null ) { localValues . clear ( ) ; } else { localValues = ( Map < SheetRowColIndex , Object > ) restoredLocalValues ; } if ( restoredInvalidUpdates == null ) { getInvalidUpdates ( ) . clear ( ) ; } else { invalidUpdates = ( List < SheetInvalidUpdate > ) restoredInvalidUpdates ; } if ( restoredColMappings == null ) { columnMapping = null ; } else { columnMapping = ( Map < Integer , Integer > ) restoredColMappings ; } if ( restoredSortedList == null ) { getFilteredValue ( ) . clear ( ) ; } else { setFilteredValue ( ( List < Object > ) restoredSortedList ) ; } if ( restoredRowMap == null ) { rowMap = null ; } else { rowMap = ( Map < String , Object > ) restoredRowMap ; } if ( restoredRowNumbers == null ) { rowNumbers = null ; } else { rowNumbers = ( Map < String , Integer > ) restoredRowNumbers ; } }
Restores the state for the submitted local and bad values .
401
12
13,453
public int getMappedColumn ( final int renderCol ) { if ( columnMapping == null || renderCol == - 1 ) { return renderCol ; } else { final Integer result = columnMapping . get ( renderCol ) ; if ( result == null ) { throw new IllegalArgumentException ( "Invalid index " + renderCol ) ; } return result ; } }
Maps the rendered column index to the real column index .
78
11
13,454
public int getRenderIndexFromRealIdx ( final int realIdx ) { if ( columnMapping == null || realIdx == - 1 ) { return realIdx ; } for ( final Entry < Integer , Integer > entry : columnMapping . entrySet ( ) ) { if ( entry . getValue ( ) . equals ( realIdx ) ) { return entry . getKey ( ) ; } } return realIdx ; }
Provides the render column index based on the real index
93
11
13,455
public void updateColumnMappings ( ) { columnMapping = new HashMap <> ( ) ; int realIdx = 0 ; int renderCol = 0 ; for ( final SheetColumn column : getColumns ( ) ) { if ( column . isRendered ( ) ) { columnMapping . put ( renderCol , realIdx ) ; renderCol ++ ; } realIdx ++ ; } }
Updates the column mappings based on the rendered attribute
85
11
13,456
public String getInvalidDataValue ( ) { final JavascriptVarBuilder vb = new JavascriptVarBuilder ( null , true ) ; for ( final SheetInvalidUpdate sheetInvalidUpdate : getInvalidUpdates ( ) ) { final Object rowKey = sheetInvalidUpdate . getInvalidRowKey ( ) ; final int col = getRenderIndexFromRealIdx ( sheetInvalidUpdate . getInvalidColIndex ( ) ) ; final String rowKeyProperty = this . getRowKeyValueAsString ( rowKey ) ; vb . appendProperty ( rowKeyProperty + "_c" + col , sheetInvalidUpdate . getInvalidMessage ( ) . replace ( "'" , "&apos;" ) , true ) ; } return vb . closeVar ( ) . toString ( ) ; }
Generates the bad data var value for this sheet .
160
11
13,457
public void renderRowUpdateScript ( final FacesContext context , final Set < String > dirtyRows ) { final String jsVar = resolveWidgetVar ( ) ; final StringBuilder eval = new StringBuilder ( ) ; for ( final String rowKey : dirtyRows ) { setRowVar ( context , rowKey ) ; final int rowIndex = rowNumbers . get ( rowKey ) ; // data is array of array of data final JavascriptVarBuilder jsRow = new JavascriptVarBuilder ( null , false ) ; final JavascriptVarBuilder jsStyle = new JavascriptVarBuilder ( null , true ) ; final JavascriptVarBuilder jsReadOnly = new JavascriptVarBuilder ( null , true ) ; int renderCol = 0 ; for ( int col = 0 ; col < getColumns ( ) . size ( ) ; col ++ ) { final SheetColumn column = getColumns ( ) . get ( col ) ; if ( ! column . isRendered ( ) ) { continue ; } // render data value final String value = getRenderValueForCell ( context , rowKey , col ) ; jsRow . appendArrayValue ( value , true ) ; // custom style final String styleClass = column . getStyleClass ( ) ; if ( styleClass != null ) { jsStyle . appendRowColProperty ( rowIndex , renderCol , styleClass , true ) ; } // read only per cell final boolean readOnly = column . isReadonlyCell ( ) ; if ( readOnly ) { jsReadOnly . appendRowColProperty ( rowIndex , renderCol , "true" , true ) ; } renderCol ++ ; } eval . append ( "PF('" ) . append ( jsVar ) . append ( "')" ) ; eval . append ( ".updateData('" ) ; eval . append ( rowIndex ) ; eval . append ( "'," ) ; eval . append ( jsRow . closeVar ( ) . toString ( ) ) ; eval . append ( "," ) ; eval . append ( jsStyle . closeVar ( ) . toString ( ) ) ; eval . append ( "," ) ; eval . append ( jsReadOnly . closeVar ( ) . toString ( ) ) ; eval . append ( ");" ) ; } eval . append ( "PF('" ) . append ( jsVar ) . append ( "')" ) . append ( ".redraw();" ) ; PrimeFaces . current ( ) . executeScript ( eval . toString ( ) ) ; }
Adds eval scripts to the ajax response to update the rows dirtied by the most recent successful update request .
515
23
13,458
public void renderBadUpdateScript ( final FacesContext context ) { final String widgetVar = resolveWidgetVar ( ) ; final String invalidValue = getInvalidDataValue ( ) ; StringBuilder sb = new StringBuilder ( "PF('" + widgetVar + "')" ) ; sb . append ( ".cfg.errors=" ) ; sb . append ( invalidValue ) ; sb . append ( ";" ) ; sb . append ( "PF('" + widgetVar + "')" ) ; sb . append ( ".ht.render();" ) ; PrimeFaces . current ( ) . executeScript ( sb . toString ( ) ) ; sb = new StringBuilder ( ) ; sb . append ( "PF('" ) . append ( widgetVar ) . append ( "')" ) ; sb . append ( ".sheetDiv.removeClass('ui-state-error')" ) ; if ( ! getInvalidUpdates ( ) . isEmpty ( ) ) { sb . append ( ".addClass('ui-state-error')" ) ; } PrimeFaces . current ( ) . executeScript ( sb . toString ( ) ) ; }
Adds eval scripts to update the bad data array in the sheet to render validation failures produced by the most recent ajax update attempt .
249
27
13,459
public void appendUpdateEvent ( final Object rowKey , final int colIndex , final Object rowData , final Object oldValue , final Object newValue ) { updates . add ( new SheetUpdate ( rowKey , colIndex , rowData , oldValue , newValue ) ) ; }
Appends an update event
58
5
13,460
public Integer getHeight ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . height ) ; if ( result == null ) { return null ; } // this will handle any type so long as its convertable to integer return Integer . valueOf ( result . toString ( ) ) ; }
The height of the sheet . Note this is applied to the inner div which is why it is recommend you use this property instead of a style class .
65
30
13,461
public void setFilteredValue ( final java . util . List _filteredValue ) { getStateHelper ( ) . put ( PropertyKeys . filteredValue , _filteredValue ) ; }
Sets the filtered list .
40
6
13,462
public String getStyle ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . style , null ) ; if ( result == null ) { return null ; } return result . toString ( ) ; }
The style value
47
3
13,463
public String getSortOrder ( ) { // if we have a toggled sort in our state, use it final String result = ( String ) getStateHelper ( ) . eval ( PropertyKeys . sortOrder , SortOrder . ASCENDING . toString ( ) ) ; return result ; }
The sort direction
61
3
13,464
public void setSortOrder ( final java . lang . String sortOrder ) { // when updating, make sure we store off the original so it may be // restored final String orig = ( String ) getStateHelper ( ) . get ( PropertyKeys . origSortOrder ) ; if ( orig == null ) { // do not call getSortOrder as it defaults to ascending, we want // null // if this is the first call and there is no previous value. getStateHelper ( ) . put ( PropertyKeys . origSortOrder , getStateHelper ( ) . eval ( PropertyKeys . sortOrder ) ) ; } getStateHelper ( ) . put ( PropertyKeys . sortOrder , sortOrder ) ; }
Update the sort direction
145
4
13,465
public String getErrorMessage ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . errorMessage ) ; if ( result == null ) { return null ; } return result . toString ( ) ; }
The error message to display when the sheet is in error .
47
12
13,466
private void encodeHandle ( final FacesContext context , final SlideOut slideOut ) throws IOException { final ResponseWriter writer = context . getResponseWriter ( ) ; String styleClass = SlideOut . HANDLE_CLASS ; if ( slideOut . getHandleStyleClass ( ) != null ) { styleClass = styleClass + " " + slideOut . getHandleStyleClass ( ) ; } writer . startElement ( "a" , null ) ; writer . writeAttribute ( "id" , getHandleId ( context , slideOut ) , null ) ; if ( slideOut . getHandleStyle ( ) != null ) { writer . writeAttribute ( "style" , slideOut . getHandleStyle ( ) , "style" ) ; } writer . writeAttribute ( "class" , styleClass , "styleClass" ) ; // icon encodeIcon ( context , slideOut ) ; // handle text if ( slideOut . getTitle ( ) != null ) { writer . writeText ( slideOut . getTitle ( ) , "title" ) ; } writer . endElement ( "a" ) ; }
HTML markup for the tab handle .
228
7
13,467
private void encodeIcon ( final FacesContext context , final SlideOut slideOut ) throws IOException { if ( slideOut . getIcon ( ) == null ) { return ; } // fontawesome icons are OK but themeroller we need to add styles String icon = slideOut . getIcon ( ) . trim ( ) ; if ( icon . startsWith ( "ui" ) ) { icon = "ui-icon " + icon + " ui-slideouttab-icon" ; } // <i class="ui-icon fa fa-television"></i> final ResponseWriter writer = context . getResponseWriter ( ) ; writer . startElement ( "span" , null ) ; writer . writeAttribute ( "class" , icon , null ) ; writer . endElement ( "span" ) ; writer . write ( " " ) ; }
HTML markup for the tab handle icon if defined .
177
10
13,468
public DynaFormRow createRegularRow ( ) { final DynaFormRow dynaFormRow = new DynaFormRow ( regularRows . size ( ) + 1 , false , this ) ; regularRows . add ( dynaFormRow ) ; return dynaFormRow ; }
Creates a new regular row .
61
7
13,469
public DynaFormRow createExtendedRow ( ) { if ( extendedRows == null ) { extendedRows = new ArrayList < DynaFormRow > ( ) ; } final DynaFormRow dynaFormRow = new DynaFormRow ( extendedRows . size ( ) + 1 , true , this ) ; extendedRows . add ( dynaFormRow ) ; return dynaFormRow ; }
Creates a new extended row .
88
7
13,470
public void removeRegularRow ( final DynaFormRow rowToBeRemoved ) { final int idx = rowToBeRemoved != null ? regularRows . indexOf ( rowToBeRemoved ) : - 1 ; if ( idx >= 0 ) { removeRow ( regularRows , rowToBeRemoved , idx ) ; } }
Removes the passed regular row .
71
7
13,471
public void removeExtendedRow ( final DynaFormRow rowToBeRemoved ) { final int idx = rowToBeRemoved != null ? extendedRows . indexOf ( rowToBeRemoved ) : - 1 ; if ( idx >= 0 ) { removeRow ( extendedRows , rowToBeRemoved , idx ) ; } }
Removes the passed extended row .
72
7
13,472
public JavascriptVarBuilder appendRowColProperty ( final int row , final int col , final String propertyValue , final boolean quoted ) { return appendProperty ( "r" + row + "_c" + col , propertyValue , quoted ) ; }
appends a property with the name rYY_cXX where YY is the row and XX is he column .
50
24
13,473
public JavascriptVarBuilder appendText ( final String value , final boolean quoted ) { if ( quoted ) { sb . append ( "\"" ) ; if ( value != null ) { sb . append ( EscapeUtils . forJavaScript ( value ) ) ; } sb . append ( "\"" ) ; } else if ( value != null ) { sb . append ( value ) ; } return this ; }
Appends text to the var string
88
7
13,474
public JavascriptVarBuilder closeVar ( ) { if ( isObject ) { sb . append ( "}" ) ; } else { sb . append ( "]" ) ; } if ( isVar ) { sb . append ( ";" ) ; } return this ; }
Closes the array or object .
57
7
13,475
public String getHeaderText ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . headerText , null ) ; if ( result == null ) { return null ; } return result . toString ( ) ; }
The fixed column count .
49
5
13,476
public Boolean isReadonlyCell ( ) { return Boolean . valueOf ( getStateHelper ( ) . eval ( PropertyKeys . readonlyCell , Boolean . FALSE ) . toString ( ) ) ; }
Flag indicating whether this cell is read only . the var reference will be available .
42
16
13,477
public Integer getColWidth ( ) { final Object result = getStateHelper ( ) . eval ( PropertyKeys . colWidth , null ) ; if ( result == null ) { return null ; } return Integer . valueOf ( result . toString ( ) ) ; }
The column width
55
3
13,478
public Collection < SelectItem > getFilterOptions ( ) { return ( Collection < SelectItem > ) getStateHelper ( ) . eval ( PropertyKeys . filterOptions , null ) ; }
The filterOptions expression
38
4
13,479
public Sheet getSheet ( ) { if ( sheet != null ) { return sheet ; } UIComponent parent = getParent ( ) ; while ( parent != null && ! ( parent instanceof Sheet ) ) { parent = parent . getParent ( ) ; } return ( Sheet ) parent ; }
Get the parent sheet
62
4
13,480
protected boolean validateRequired ( final FacesContext context , final Object newValue ) { // If our value is valid, enforce the required property if present if ( isValid ( ) && isRequired ( ) && isEmpty ( newValue ) ) { final String requiredMessageStr = getRequiredMessage ( ) ; FacesMessage message ; if ( null != requiredMessageStr ) { message = new FacesMessage ( FacesMessage . SEVERITY_ERROR , requiredMessageStr , requiredMessageStr ) ; } else { message = new FacesMessage ( FacesMessage . SEVERITY_ERROR , MESSAGE_REQUIRED , MESSAGE_REQUIRED ) ; } context . addMessage ( getClientId ( context ) , message ) ; final Sheet sheet = getSheet ( ) ; if ( sheet != null ) { sheet . getInvalidUpdates ( ) . add ( new SheetInvalidUpdate ( sheet . getRowKeyValue ( context ) , sheet . getColumns ( ) . indexOf ( this ) , this , newValue , message . getDetail ( ) ) ) ; } setValid ( false ) ; return false ; } return true ; }
Validates the value against the required flags on this column .
238
12
13,481
private void requestCameraPermission ( ) { Log . w ( "BARCODE-SCANNER" , "Camera permission is not granted. Requesting permission" ) ; final String [ ] permissions = new String [ ] { Manifest . permission . CAMERA } ; if ( ! shouldShowRequestPermissionRationale ( Manifest . permission . CAMERA ) ) { requestPermissions ( permissions , RC_HANDLE_CAMERA_PERM ) ; return ; } Snackbar . make ( mGraphicOverlay , R . string . permission_camera_rationale , Snackbar . LENGTH_INDEFINITE ) . setAction ( R . string . ok , new View . OnClickListener ( ) { @ Override public void onClick ( View view ) { requestPermissions ( permissions , RC_HANDLE_CAMERA_PERM ) ; } } ) . show ( ) ; /* new AlertDialog.Builder(getContext()) .setTitle(R.string.perm_required) .setMessage(R.string.permission_camera_rationale) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { //dialogInterface.dismiss(); requestPermissions(permissions, RC_HANDLE_CAMERA_PERM); } }) .setCancelable(false) .show();*/ }
Handles the requesting of the camera permission . This includes showing a Snackbar message of why the permission is needed then sending the request .
313
28
13,482
@ Override public boolean onTouch ( View v , MotionEvent event ) { boolean b = scaleGestureDetector . onTouchEvent ( event ) ; boolean c = gestureDetector . onTouchEvent ( event ) ; return b || c || v . onTouchEvent ( event ) ; }
Called when a touch event is dispatched to a view . This allows listeners to get a chance to respond before the target view .
62
26
13,483
protected boolean onTap ( float rawX , float rawY ) { Log . d ( "CAPTURE-FRAGMENT" , "got tap at: (" + rawX + ", " + rawY + ")" ) ; Barcode barcode = null ; if ( mMode == MVBarcodeScanner . ScanningMode . SINGLE_AUTO ) { BarcodeGraphic graphic = mGraphicOverlay . getFirstGraphic ( ) ; if ( graphic != null ) { barcode = graphic . getBarcode ( ) ; if ( barcode != null && mListener != null ) { mListener . onBarcodeScanned ( barcode ) ; } } } else if ( mMode == MVBarcodeScanner . ScanningMode . SINGLE_MANUAL ) { Set < BarcodeGraphic > graphicSet = mGraphicOverlay . getAllGraphics ( ) ; if ( graphicSet != null && ! graphicSet . isEmpty ( ) ) { for ( BarcodeGraphic graphic : graphicSet ) { if ( graphic != null && graphic . isPointInsideBarcode ( rawX , rawY ) ) { Log . d ( "CAPTURE-FRAGMENT" , "got tap inside barcode" ) ; barcode = graphic . getBarcode ( ) ; break ; } } if ( mListener != null && barcode != null ) { mListener . onBarcodeScanned ( barcode ) ; } } } else { Set < BarcodeGraphic > graphicSet = mGraphicOverlay . getAllGraphics ( ) ; if ( graphicSet != null && ! graphicSet . isEmpty ( ) ) { List < Barcode > barcodes = new ArrayList <> ( ) ; for ( BarcodeGraphic graphic : graphicSet ) { if ( graphic != null && graphic . getBarcode ( ) != null ) { barcode = graphic . getBarcode ( ) ; barcodes . add ( barcode ) ; } } if ( mListener != null && ! barcodes . isEmpty ( ) ) { mListener . onBarcodesScanned ( barcodes ) ; } } } return barcode != null ; }
onTap is called to capture the oldest barcode currently detected and return it to the caller .
466
19
13,484
@ Override public void onNewItem ( int id , Barcode item ) { mGraphic . setId ( id ) ; if ( mListener != null ) mListener . onNewBarcodeDetected ( id , item ) ; }
Start tracking the detected item instance within the item overlay .
51
11
13,485
@ Override public void draw ( Canvas canvas ) { Barcode barcode = mBarcode ; if ( barcode == null ) { return ; } // Draws the bounding box around the barcode. RectF rect = getViewBoundingBox ( barcode ) ; canvas . drawRect ( rect , mOverlayPaint ) ; /** * Draw the top left corner */ canvas . drawLine ( rect . left , rect . top , rect . left + CORNER_WIDTH , rect . top , mRectPaint ) ; canvas . drawLine ( rect . left , rect . top , rect . left , rect . top + CORNER_WIDTH , mRectPaint ) ; /** * Draw the bottom left corner */ canvas . drawLine ( rect . left , rect . bottom , rect . left , rect . bottom - CORNER_WIDTH , mRectPaint ) ; canvas . drawLine ( rect . left , rect . bottom , rect . left + CORNER_WIDTH , rect . bottom , mRectPaint ) ; /** * Draw the top right corner */ canvas . drawLine ( rect . right , rect . top , rect . right - CORNER_WIDTH , rect . top , mRectPaint ) ; canvas . drawLine ( rect . right , rect . top , rect . right , rect . top + CORNER_WIDTH , mRectPaint ) ; /** * Draw the bottom right corner */ canvas . drawLine ( rect . right , rect . bottom , rect . right - CORNER_WIDTH , rect . bottom , mRectPaint ) ; canvas . drawLine ( rect . right , rect . bottom , rect . right , rect . bottom - CORNER_WIDTH , mRectPaint ) ; }
Draws the barcode annotations for position size and raw value on the supplied canvas .
378
17
13,486
protected int addClasspathElements ( Collection < ? > elements , URL [ ] urls , int startPosition ) throws MojoExecutionException { for ( Object object : elements ) { try { if ( object instanceof Artifact ) { urls [ startPosition ] = ( ( Artifact ) object ) . getFile ( ) . toURI ( ) . toURL ( ) ; } else if ( object instanceof Resource ) { urls [ startPosition ] = new File ( ( ( Resource ) object ) . getDirectory ( ) ) . toURI ( ) . toURL ( ) ; } else { urls [ startPosition ] = new File ( ( String ) object ) . toURI ( ) . toURL ( ) ; } } catch ( MalformedURLException e ) { throw new MojoExecutionException ( "Failed to convert original classpath element " + object + " to URL." , e ) ; } startPosition ++ ; } return startPosition ; }
Add classpath elements to a classpath URL set
203
10
13,487
public Collection < File > getClasspath ( String scope ) throws MojoExecutionException { try { Collection < File > files = classpathBuilder . buildClasspathList ( getProject ( ) , scope , getProjectArtifacts ( ) , isGenerator ( ) ) ; if ( getLog ( ) . isDebugEnabled ( ) ) { getLog ( ) . debug ( "GWT SDK execution classpath :" ) ; for ( File f : files ) { getLog ( ) . debug ( " " + f . getAbsolutePath ( ) ) ; } } return files ; } catch ( ClasspathBuilderException e ) { throw new MojoExecutionException ( e . getMessage ( ) , e ) ; } }
Build the GWT classpath for the specified scope
152
10
13,488
private void checkGwtUserVersion ( ) throws MojoExecutionException { InputStream inputStream = Thread . currentThread ( ) . getContextClassLoader ( ) . getResourceAsStream ( "org/codehaus/mojo/gwt/mojoGwtVersion.properties" ) ; Properties properties = new Properties ( ) ; try { properties . load ( inputStream ) ; } catch ( IOException e ) { throw new MojoExecutionException ( "Failed to load plugin properties" , e ) ; } finally { IOUtils . closeQuietly ( inputStream ) ; } Artifact gwtUser = project . getArtifactMap ( ) . get ( GWT_USER ) ; if ( gwtUser != null ) { String mojoGwtVersion = properties . getProperty ( "gwt.version" ) ; //ComparableVersion with an up2date maven version ArtifactVersion mojoGwtArtifactVersion = new DefaultArtifactVersion ( mojoGwtVersion ) ; ArtifactVersion userGwtArtifactVersion = new DefaultArtifactVersion ( gwtUser . getVersion ( ) ) ; if ( userGwtArtifactVersion . compareTo ( mojoGwtArtifactVersion ) < 0 ) { getLog ( ) . warn ( "Your project declares dependency on gwt-user " + gwtUser . getVersion ( ) + ". This plugin is designed for at least gwt version " + mojoGwtVersion ) ; } } }
Check gwt - user dependency matches plugin version
312
9
13,489
public String getProjectName ( MavenProject project ) { File dotProject = new File ( project . getBasedir ( ) , ".project" ) ; try { Xpp3Dom dom = Xpp3DomBuilder . build ( ReaderFactory . newXmlReader ( dotProject ) ) ; return dom . getChild ( "name" ) . getValue ( ) ; } catch ( Exception e ) { getLogger ( ) . warn ( "Failed to read the .project file" ) ; return project . getArtifactId ( ) ; } }
Read the Eclipse project name for . project file . Fall back to artifactId on error
116
17
13,490
private List < Artifact > getScopeArtifacts ( final MavenProject project , final String scope ) { if ( SCOPE_COMPILE . equals ( scope ) ) { return project . getCompileArtifacts ( ) ; } if ( SCOPE_RUNTIME . equals ( scope ) ) { return project . getRuntimeArtifacts ( ) ; } else if ( SCOPE_TEST . equals ( scope ) ) { return project . getTestArtifacts ( ) ; } else { throw new RuntimeException ( "Not allowed scope " + scope ) ; } }
Get artifacts for specific scope .
118
6
13,491
private List < String > getSourceRoots ( final MavenProject project , final String scope ) { if ( SCOPE_COMPILE . equals ( scope ) || SCOPE_RUNTIME . equals ( scope ) ) { return project . getCompileSourceRoots ( ) ; } else if ( SCOPE_TEST . equals ( scope ) ) { List < String > sourceRoots = new ArrayList < String > ( ) ; sourceRoots . addAll ( project . getTestCompileSourceRoots ( ) ) ; sourceRoots . addAll ( project . getCompileSourceRoots ( ) ) ; return sourceRoots ; } else { throw new RuntimeException ( "Not allowed scope " + scope ) ; } }
Get source roots for specific scope .
156
7
13,492
private List < Resource > getResources ( final MavenProject project , final String scope ) { if ( SCOPE_COMPILE . equals ( scope ) || SCOPE_RUNTIME . equals ( scope ) ) { return project . getResources ( ) ; } else if ( SCOPE_TEST . equals ( scope ) ) { List < Resource > resources = new ArrayList < Resource > ( ) ; resources . addAll ( project . getTestResources ( ) ) ; resources . addAll ( project . getResources ( ) ) ; return resources ; } else { throw new RuntimeException ( "Not allowed scope " + scope ) ; } }
Get resources for specific scope .
134
6
13,493
private String getProjectReferenceId ( final String groupId , final String artifactId , final String version ) { return groupId + ":" + artifactId + ":" + version ; }
Cut from MavenProject . java
38
7
13,494
public String [ ] getModules ( ) { // module has higher priority if set by expression if ( module != null ) { return new String [ ] { module } ; } if ( modules == null ) { //Use a Set to avoid duplicate when user set src/main/java as <resource> Set < String > mods = new HashSet < String > ( ) ; Collection < String > sourcePaths = getProject ( ) . getCompileSourceRoots ( ) ; for ( String sourcePath : sourcePaths ) { File sourceDirectory = new File ( sourcePath ) ; if ( sourceDirectory . exists ( ) ) { DirectoryScanner scanner = new DirectoryScanner ( ) ; scanner . setBasedir ( sourceDirectory . getAbsolutePath ( ) ) ; scanner . setIncludes ( new String [ ] { "**/*" + DefaultGwtModuleReader . GWT_MODULE_EXTENSION } ) ; scanner . scan ( ) ; mods . addAll ( Arrays . asList ( scanner . getIncludedFiles ( ) ) ) ; } } Collection < Resource > resources = getProject ( ) . getResources ( ) ; for ( Resource resource : resources ) { File resourceDirectoryFile = new File ( resource . getDirectory ( ) ) ; if ( ! resourceDirectoryFile . exists ( ) ) { continue ; } DirectoryScanner scanner = new DirectoryScanner ( ) ; scanner . setBasedir ( resource . getDirectory ( ) ) ; scanner . setIncludes ( new String [ ] { "**/*" + DefaultGwtModuleReader . GWT_MODULE_EXTENSION } ) ; scanner . scan ( ) ; mods . addAll ( Arrays . asList ( scanner . getIncludedFiles ( ) ) ) ; } if ( mods . isEmpty ( ) ) { getLog ( ) . warn ( "GWT plugin is configured to detect modules, but none were found." ) ; } modules = new String [ mods . size ( ) ] ; int i = 0 ; for ( String fileName : mods ) { String path = fileName . substring ( 0 , fileName . length ( ) - DefaultGwtModuleReader . GWT_MODULE_EXTENSION . length ( ) ) ; modules [ i ++ ] = path . replace ( File . separatorChar , ' ' ) ; } if ( modules . length > 0 ) { getLog ( ) . info ( "auto discovered modules " + Arrays . asList ( modules ) ) ; } } return modules ; }
FIXME move to DefaultGwtModuleReader !
525
10
13,495
private boolean isDeprecated ( JavaMethod method ) { if ( method == null ) return false ; for ( Annotation annotation : method . getAnnotations ( ) ) { if ( "java.lang.Deprecated" . equals ( annotation . getType ( ) . getFullyQualifiedName ( ) ) ) { return true ; } } return method . getTagByName ( "deprecated" ) != null ; }
Determine if a client service method is deprecated .
88
11
13,496
public Set < GwtModule > getInherits ( ) throws GwtModuleReaderException { if ( inherits != null ) { return inherits ; } inherits = new HashSet < GwtModule > ( ) ; addInheritedModules ( inherits , getLocalInherits ( ) ) ; return inherits ; }
Build the set of inhertied modules . Due to xml inheritence mecanism there may be cicles in the inheritence graph so we build a set of inherited modules
71
35
13,497
protected Collection < ResourceFile > getAllResourceFiles ( ) throws MojoExecutionException { try { Set < ResourceFile > sourcesAndResources = new HashSet < ResourceFile > ( ) ; Set < String > sourcesAndResourcesPath = new HashSet < String > ( ) ; sourcesAndResourcesPath . addAll ( getProject ( ) . getCompileSourceRoots ( ) ) ; for ( Resource resource : getProject ( ) . getResources ( ) ) { sourcesAndResourcesPath . add ( resource . getDirectory ( ) ) ; } for ( String name : getModules ( ) ) { GwtModule module = readModule ( name ) ; sourcesAndResources . add ( getDescriptor ( module , sourcesAndResourcesPath ) ) ; int count = 1 ; for ( String source : module . getSources ( ) ) { getLog ( ) . debug ( "GWT sources from " + name + ' ' + source ) ; Collection < ResourceFile > files = getAsResources ( module , source , sourcesAndResourcesPath , "**/*.java" ) ; sourcesAndResources . addAll ( files ) ; count += files . size ( ) ; Collection < ResourceFile > uifiles = getAsResources ( module , source , sourcesAndResourcesPath , "**/*.ui.xml" ) ; sourcesAndResources . addAll ( uifiles ) ; count += uifiles . size ( ) ; } for ( String source : module . getSuperSources ( ) ) { getLog ( ) . debug ( "GWT super-sources from " + name + ' ' + source ) ; Collection < ResourceFile > files = getAsResources ( module , source , sourcesAndResourcesPath , "**/*.java" ) ; sourcesAndResources . addAll ( files ) ; count += files . size ( ) ; Collection < ResourceFile > uifiles = getAsResources ( module , source , sourcesAndResourcesPath , "**/*.ui.xml" ) ; sourcesAndResources . addAll ( uifiles ) ; count += uifiles . size ( ) ; } getLog ( ) . info ( count + " source files from GWT module " + name ) ; } return sourcesAndResources ; } catch ( GwtModuleReaderException e ) { throw new MojoExecutionException ( e . getMessage ( ) , e ) ; } }
Collect GWT java source code and module descriptor to be added as resources .
495
15
13,498
private String escapeHtml ( String html ) { if ( html == null ) { return null ; } return html . replaceAll ( "&" , "&amp;" ) . replaceAll ( "<" , "&lt;" ) . replaceAll ( ">" , "&gt;" ) ; }
Escape an html string . Escaping data received from the client helps to prevent cross - site script vulnerabilities .
62
22
13,499
public boolean parse ( String criteria , Map < String , ? extends Object > attributes ) throws CriteriaParseException { if ( criteria == null ) { return true ; } else { try { return Boolean . parseBoolean ( FREEMARKER_BUILTINS . eval ( criteria , attributes ) ) ; } catch ( TemplateException ex ) { throw new CriteriaParseException ( ex ) ; } } }
Parses the provided criteria expression which must have a boolean value .
86
14