idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
18,600 | private WButton newVisibilityToggleForTab ( final int idx ) { WButton toggleButton = new WButton ( "Toggle visibility of tab " + ( idx + 1 ) ) ; toggleButton . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { boolean tabVisible = tabset . isTabVisible ( idx ) ; tabset . setTabVisible ( idx , ! tabVisible ) ; } } ) ; return toggleButton ; } | Creates a button to toggle the visibility of a tab . |
18,601 | private < T extends Enum < T > > EnumerationRadioButtonSelect < T > createRadioButtonGroup ( final T [ ] options ) { EnumerationRadioButtonSelect < T > rbSelect = new EnumerationRadioButtonSelect < > ( options ) ; rbSelect . setButtonLayout ( EnumerationRadioButtonSelect . Layout . FLAT ) ; rbSelect . setFrameless ( true ) ; return rbSelect ; } | Create a radio button select containing the options . |
18,602 | private void displaySelected ( ) { copySelection ( table1 , selected1 ) ; copySelection ( table2 , selected2 ) ; copySelection ( table3 , selected3 ) ; } | Display the rows that have been selected . |
18,603 | private BigDecimal convertValue ( final Object value ) { if ( value == null ) { return null ; } else if ( value instanceof BigDecimal ) { return ( BigDecimal ) value ; } String dataString = value . toString ( ) ; if ( Util . empty ( dataString ) ) { return null ; } try { return new BigDecimal ( dataString ) ; } catch ( NumberFormatException ex ) { throw new SystemException ( "Could not convert data of type " + value . getClass ( ) + " with String value " + dataString + " to BigDecimal" , ex ) ; } } | Attempts to convert a value to a BigDecimal . Throws a SystemException on error . |
18,604 | public void setMinValue ( final BigDecimal minValue ) { BigDecimal currMin = getMinValue ( ) ; if ( ! Objects . equals ( minValue , currMin ) ) { getOrCreateComponentModel ( ) . minValue = minValue ; } } | Sets the minimum allowable value for this number field . |
18,605 | public void setMaxValue ( final BigDecimal maxValue ) { BigDecimal currMax = getMaxValue ( ) ; if ( ! Objects . equals ( maxValue , currMax ) ) { getOrCreateComponentModel ( ) . maxValue = maxValue ; } } | Sets the maximum allowable value for this number field . |
18,606 | protected void validateComponent ( final List < Diagnostic > diags ) { if ( isValidNumber ( ) ) { super . validateComponent ( diags ) ; validateNumber ( diags ) ; } else { diags . add ( createErrorDiagnostic ( InternalMessages . DEFAULT_VALIDATION_ERROR_INVALID , this ) ) ; } } | Override WInput s validateComponent to perform futher validation on email addresses . |
18,607 | private static boolean containsError ( final List < Diagnostic > diags ) { if ( diags == null || diags . isEmpty ( ) ) { return false ; } for ( Diagnostic diag : diags ) { if ( diag . getSeverity ( ) == Diagnostic . ERROR ) { return true ; } } return false ; } | Indicates whether the given list of diagnostics contains any errors . |
18,608 | protected boolean doHandleRequest ( final Request request ) { String value = getRequestValue ( request ) ; String current = getValue ( ) ; boolean changed = ! Util . equals ( value , current ) ; if ( changed ) { setData ( value ) ; } return changed ; } | Override handleRequest in order to perform processing for this component . This implementation updates the text field s text if it has changed . |
18,609 | public void preparePaint ( final Request request ) { UIContext uic = UIContextHolder . getCurrent ( ) ; Headers headers = uic . getUI ( ) . getHeaders ( ) ; headers . reset ( ) ; headers . setContentType ( WebUtilities . CONTENT_TYPE_XML ) ; super . preparePaint ( request ) ; } | Override to set the content type of the response and reset the headers . |
18,610 | public void paint ( final RenderContext renderContext ) { WebXmlRenderContext webRenderContext = ( WebXmlRenderContext ) renderContext ; XmlStringBuilder xml = webRenderContext . getWriter ( ) ; AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; if ( operation == null ) { throw new SystemException ( "Can't paint AJAX response. Couldn't find the expected reference to the AjaxOperation." ) ; } UIContext uic = UIContextHolder . getCurrent ( ) ; String focusId = uic . getFocussedId ( ) ; xml . append ( XMLUtil . getXMLDeclarationWithThemeXslt ( uic ) ) ; xml . appendTagOpen ( "ui:ajaxresponse" ) ; xml . append ( XMLUtil . STANDARD_NAMESPACES ) ; xml . appendOptionalAttribute ( "defaultFocusId" , uic . isFocusRequired ( ) && ! Util . empty ( focusId ) , focusId ) ; xml . appendClose ( ) ; getBackingComponent ( ) . paint ( renderContext ) ; xml . appendEndTag ( "ui:ajaxresponse" ) ; } | Paints the targeted ajax regions . The format of the response is an agreement between the server and the client side handling our AJAX response . |
18,611 | public void add ( final WComponent component , final String tag ) { super . add ( component , tag ) ; } | Add the given component as a child of this component . The tag is used to identify the child in this component s velocity template . |
18,612 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WAudio audioComponent = ( WAudio ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; Audio [ ] audio = audioComponent . getAudio ( ) ; if ( audio == null || audio . length == 0 ) { return ; } WAudio . Controls controls = audioComponent . getControls ( ) ; int duration = audio [ 0 ] . getDuration ( ) ; String alternativeText = audioComponent . getAltText ( ) ; if ( alternativeText == null ) { LOG . warn ( "Audio should have a description." ) ; alternativeText = null ; } else { alternativeText = I18nUtilities . format ( null , alternativeText ) ; } xml . appendTagOpen ( "ui:audio" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "alt" , alternativeText ) ; xml . appendOptionalAttribute ( "autoplay" , audioComponent . isAutoplay ( ) , "true" ) ; xml . appendOptionalAttribute ( "mediagroup" , audioComponent . getMediaGroup ( ) ) ; xml . appendOptionalAttribute ( "loop" , audioComponent . isLoop ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , audioComponent . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "disabled" , audioComponent . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , audioComponent . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "duration" , duration > 0 , duration ) ; switch ( audioComponent . getPreload ( ) ) { case NONE : xml . appendAttribute ( "preload" , "none" ) ; break ; case META_DATA : xml . appendAttribute ( "preload" , "metadata" ) ; break ; case AUTO : default : break ; } if ( controls != null && ! WAudio . Controls . NATIVE . equals ( controls ) ) { switch ( controls ) { case NONE : xml . appendAttribute ( "controls" , "none" ) ; break ; case ALL : xml . appendAttribute ( "controls" , "all" ) ; break ; case PLAY_PAUSE : xml . appendAttribute ( "controls" , "play" ) ; break ; case DEFAULT : xml . appendAttribute ( "controls" , "default" ) ; break ; default : LOG . error ( "Unknown control type: " + controls ) ; } } xml . appendClose ( ) ; String [ ] urls = audioComponent . getAudioUrls ( ) ; for ( int i = 0 ; i < urls . length ; i ++ ) { xml . appendTagOpen ( "ui:src" ) ; xml . appendUrlAttribute ( "uri" , urls [ i ] ) ; xml . appendOptionalAttribute ( "type" , audio [ i ] . getMimeType ( ) ) ; xml . appendEnd ( ) ; } xml . appendEndTag ( "ui:audio" ) ; } | Paints the given WAudio . |
18,613 | private void addResponsiveExample ( ) { add ( new WHeading ( HeadingLevel . H2 , "Default responsive design" ) ) ; add ( new ExplanatoryText ( "This example applies the theme's default responsive design rules for ColumnLayout.\n " + "The columns have width and alignment and there is also a hgap and a vgap." ) ) ; WPanel panel = new WPanel ( ) ; panel . setLayout ( new ColumnLayout ( new int [ ] { 33 , 33 , 33 } , new Alignment [ ] { Alignment . LEFT , Alignment . CENTER , Alignment . RIGHT } , 12 , 18 ) ) ; panel . setHtmlClass ( HtmlClassProperties . RESPOND ) ; add ( panel ) ; panel . add ( new BoxComponent ( "Left" ) ) ; panel . add ( new BoxComponent ( "Center" ) ) ; panel . add ( new BoxComponent ( "Right" ) ) ; panel . add ( new BoxComponent ( "Left" ) ) ; panel . add ( new BoxComponent ( "Center" ) ) ; panel . add ( new BoxComponent ( "Right" ) ) ; } | Add a column layout which will change its rendering on small screens . |
18,614 | private static String getTitle ( final int [ ] widths ) { StringBuffer buf = new StringBuffer ( "Column widths: " ) ; for ( int i = 0 ; i < widths . length ; i ++ ) { if ( i > 0 ) { buf . append ( ", " ) ; } buf . append ( widths [ i ] ) ; } return buf . toString ( ) ; } | Concatenates column widths to form the heading text for the example . |
18,615 | private void addHgapVGapExample ( final Size hgap , final Size vgap ) { add ( new WHeading ( HeadingLevel . H2 , "Column Layout: hgap=" + hgap . toString ( ) + " vgap=" + vgap . toString ( ) ) ) ; WPanel panel = new WPanel ( ) ; panel . setLayout ( new ColumnLayout ( new int [ ] { 25 , 25 , 25 , 25 } , hgap , vgap ) ) ; add ( panel ) ; for ( int i = 0 ; i < 8 ; i ++ ) { panel . add ( new BoxComponent ( "25%" ) ) ; } add ( new WHorizontalRule ( ) ) ; } | Build an example using hgap and vgap . |
18,616 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTableRowRenderer renderer = ( WTableRowRenderer ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WTable table = renderer . getTable ( ) ; TableModel dataModel = table . getTableModel ( ) ; int [ ] columnOrder = table . getColumnOrder ( ) ; final int numCols = columnOrder == null ? table . getColumnCount ( ) : columnOrder . length ; RowIdWrapper wrapper = renderer . getCurrentRowIdWrapper ( ) ; List < Integer > rowIndex = wrapper . getRowIndex ( ) ; boolean tableSelectable = table . getSelectMode ( ) != SelectMode . NONE ; boolean rowSelectable = tableSelectable && dataModel . isSelectable ( rowIndex ) ; boolean rowSelected = rowSelectable && table . getSelectedRows ( ) . contains ( wrapper . getRowKey ( ) ) ; boolean tableExpandable = table . getExpandMode ( ) != WTable . ExpandMode . NONE ; boolean rowExpandable = tableExpandable && dataModel . isExpandable ( rowIndex ) && wrapper . hasChildren ( ) ; boolean rowExpanded = rowExpandable && table . getExpandedRows ( ) . contains ( wrapper . getRowKey ( ) ) ; String rowIndexAsString = TableUtil . rowIndexListToString ( rowIndex ) ; xml . appendTagOpen ( "ui:tr" ) ; xml . appendAttribute ( "rowIndex" , rowIndexAsString ) ; xml . appendOptionalAttribute ( "unselectable" , ! rowSelectable , "true" ) ; xml . appendOptionalAttribute ( "selected" , rowSelected , "true" ) ; xml . appendOptionalAttribute ( "expandable" , rowExpandable && ! rowExpanded , "true" ) ; xml . appendClose ( ) ; boolean isRowHeader = table . isRowHeaders ( ) ; for ( int i = 0 ; i < numCols ; i ++ ) { int colIndex = columnOrder == null ? i : columnOrder [ i ] ; WTableColumn col = table . getColumn ( colIndex ) ; String cellTag = "ui:td" ; if ( col . isVisible ( ) ) { if ( isRowHeader ) { cellTag = "ui:th" ; isRowHeader = false ; } xml . appendTag ( cellTag ) ; renderer . getRenderer ( colIndex ) . paint ( renderContext ) ; xml . appendEndTag ( cellTag ) ; } } if ( rowExpandable ) { xml . appendTagOpen ( "ui:subtr" ) ; xml . appendOptionalAttribute ( "open" , rowExpanded , "true" ) ; xml . appendClose ( ) ; if ( rowExpanded || table . getExpandMode ( ) == ExpandMode . CLIENT ) { renderChildren ( renderer , renderContext , wrapper . getChildren ( ) ) ; } xml . appendEndTag ( "ui:subtr" ) ; } xml . appendEndTag ( "ui:tr" ) ; } | Paints the given WTableRowRenderer . |
18,617 | public static Policy createPolicy ( final String resourceName ) { if ( StringUtils . isBlank ( resourceName ) ) { throw new SystemException ( "AntiSamy Policy resourceName cannot be null " ) ; } URL resource = HtmlSanitizerUtil . class . getClassLoader ( ) . getResource ( resourceName ) ; if ( resource == null ) { throw new SystemException ( "Could not find AntiSamy Policy XML resource." ) ; } try { return Policy . getInstance ( resource ) ; } catch ( PolicyException ex ) { throw new SystemException ( "Could not create AntiSamy Policy" + ex . getMessage ( ) , ex ) ; } } | Create a Policy from a named local resource . |
18,618 | public void handleRequest ( final Request request ) { super . handleRequest ( request ) ; Object data = getData ( ) ; if ( data != null ) { updateData ( data ) ; } } | The handleRequest method has been overridden to keep the data object bound to this wcomponent in sync with any changes the user has entered . |
18,619 | protected void doGet ( final HttpServletRequest req , final HttpServletResponse resp ) throws ServletException , IOException { ServletUtil . handleThemeResourceRequest ( req , resp ) ; } | Serves up a file from the theme . |
18,620 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WCollapsibleToggle toggle = ( WCollapsibleToggle ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:collapsibletoggle" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendAttribute ( "groupName" , toggle . getGroupName ( ) ) ; xml . appendEnd ( ) ; } | Paints the given WCollapsibleToggle . |
18,621 | public static boolean empty ( final String aString ) { if ( aString != null ) { final int len = aString . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( aString . charAt ( i ) > ' ' ) { return false ; } } } return true ; } | Determines whether the given string is null or empty . |
18,622 | public static int compareAllowNull ( final Comparable c1 , final Comparable c2 ) { if ( c1 == null && c2 == null ) { return 0 ; } else if ( c1 == null ) { return - 1 ; } else if ( c2 == null ) { return 1 ; } else { return c1 . compareTo ( c2 ) ; } } | Compares two comparable objects where either may be null . Null is regarded as the smallest value and 2 nulls are considered equal . |
18,623 | public static String rightTrim ( final String aString ) { if ( aString == null ) { return null ; } int end = aString . length ( ) - 1 ; while ( ( end >= 0 ) && ( aString . charAt ( end ) <= ' ' ) ) { end -- ; } if ( end == aString . length ( ) - 1 ) { return aString ; } return aString . substring ( 0 , end + 1 ) ; } | Copies this String removing white space characters from the end of the string . |
18,624 | public static String leftTrim ( final String aString ) { if ( aString == null ) { return null ; } int start = 0 ; while ( ( start < aString . length ( ) ) && ( aString . charAt ( start ) <= ' ' ) ) { start ++ ; } if ( start == 0 ) { return aString ; } return aString . substring ( start ) ; } | Copies this String removing white space characters from the beginning of the string . |
18,625 | public static UIContext getCurrent ( ) { Stack < UIContext > stack = CONTEXT_STACK . get ( ) ; if ( stack == null || stack . isEmpty ( ) ) { return null ; } return getStack ( ) . peek ( ) ; } | Retrieves the current effective UIContext . Note that this method will return null if called from outside normal request processing for example during the intial application UI construction . |
18,626 | private static Stack < UIContext > getStack ( ) { Stack < UIContext > stack = CONTEXT_STACK . get ( ) ; if ( stack == null ) { stack = new Stack < > ( ) ; CONTEXT_STACK . set ( stack ) ; } return stack ; } | Retrieves the internal stack creating it if necessary . |
18,627 | public static List getAllFields ( final Object obj , final boolean excludeStatic , final boolean excludeTransient ) { List fieldList = new ArrayList ( ) ; for ( Class clazz = obj . getClass ( ) ; clazz != null ; clazz = clazz . getSuperclass ( ) ) { Field [ ] declaredFields = clazz . getDeclaredFields ( ) ; for ( int i = 0 ; i < declaredFields . length ; i ++ ) { int mods = declaredFields [ i ] . getModifiers ( ) ; if ( ( ! excludeStatic || ! Modifier . isStatic ( mods ) ) && ( ! excludeTransient || ! Modifier . isTransient ( mods ) ) ) { declaredFields [ i ] . setAccessible ( true ) ; fieldList . add ( declaredFields [ i ] ) ; } } } return fieldList ; } | Retrieves all the fields contained in the given object and its superclasses . |
18,628 | public static void setProperty ( final Object object , final String property , final Class propertyType , final Object value ) { Class [ ] paramTypes = new Class [ ] { propertyType } ; Object [ ] params = new Object [ ] { value } ; String methodName = "set" + property . substring ( 0 , 1 ) . toUpperCase ( ) + property . substring ( 1 ) ; ReflectionUtil . invokeMethod ( object , methodName , params , paramTypes ) ; } | This method sets a property on an object via reflection . |
18,629 | public static Object getProperty ( final Object object , final String property ) { Class [ ] paramTypes = new Class [ ] { } ; Object [ ] params = new Object [ ] { } ; String methodName = "get" + property . substring ( 0 , 1 ) . toUpperCase ( ) + property . substring ( 1 ) ; return ReflectionUtil . invokeMethod ( object , methodName , params , paramTypes ) ; } | This method gets a property from an object via reflection . |
18,630 | public int createRating ( Reference reference , RatingType type , int value ) { return getResourceFactory ( ) . getApiResource ( "/rating/" + reference . toURLFragment ( ) + type ) . entity ( Collections . singletonMap ( "value" , value ) , MediaType . APPLICATION_JSON_TYPE ) . post ( RatingCreateResponse . class ) . getId ( ) ; } | Add a new rating of the user to the object . The rating can be one of many different types . For more details see the area . |
18,631 | public void deleteRating ( Reference reference , RatingType type ) { getResourceFactory ( ) . getApiResource ( "/rating/" + reference . toURLFragment ( ) + type ) . delete ( ) ; } | Deletes the rating of the given type on the object by the active user |
18,632 | public RatingValuesMap getAllRatings ( Reference reference ) { return getResourceFactory ( ) . getApiResource ( "/rating/" + reference . toURLFragment ( ) ) . get ( RatingValuesMap . class ) ; } | Returns all the ratings for the given object . It will only return the ratings that are enabled for the object . |
18,633 | public int getRating ( Reference reference , RatingType type , int userId ) { return getResourceFactory ( ) . getApiResource ( "/rating/" + reference . toURLFragment ( ) + type + "/" + userId ) . get ( SingleRatingValue . class ) . getValue ( ) ; } | Returns the rating value for the given rating type object and user . |
18,634 | private String getMenuType ( final WSubMenu submenu ) { WMenu menu = WebUtilities . getAncestorOfClass ( WMenu . class , submenu ) ; switch ( menu . getType ( ) ) { case BAR : return "bar" ; case FLYOUT : return "flyout" ; case TREE : return "tree" ; case COLUMN : return "column" ; default : throw new IllegalStateException ( "Invalid menu type: " + menu . getType ( ) ) ; } } | Get the string value of a WMenu . MenuType . |
18,635 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WSubMenu menu = ( WSubMenu ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:submenu" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; if ( isTree ( menu ) ) { xml . appendAttribute ( "open" , String . valueOf ( isOpen ( menu ) ) ) ; } xml . appendOptionalAttribute ( "disabled" , menu . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , menu . isHidden ( ) , "true" ) ; if ( menu . isTopLevelMenu ( ) ) { xml . appendOptionalAttribute ( "accessKey" , menu . getAccessKeyAsString ( ) ) ; } else { xml . appendAttribute ( "nested" , "true" ) ; } xml . appendOptionalAttribute ( "type" , getMenuType ( menu ) ) ; switch ( menu . getMode ( ) ) { case CLIENT : xml . appendAttribute ( "mode" , "client" ) ; break ; case LAZY : xml . appendAttribute ( "mode" , "lazy" ) ; break ; case EAGER : xml . appendAttribute ( "mode" , "eager" ) ; break ; case DYNAMIC : case SERVER : xml . appendAttribute ( "mode" , "dynamic" ) ; break ; default : throw new SystemException ( "Unknown menu mode: " + menu . getMode ( ) ) ; } xml . appendClose ( ) ; menu . getDecoratedLabel ( ) . paint ( renderContext ) ; MenuMode mode = menu . getMode ( ) ; xml . appendTagOpen ( "ui:content" ) ; xml . appendAttribute ( "id" , component . getId ( ) + "-content" ) ; xml . appendClose ( ) ; if ( mode != MenuMode . EAGER || AjaxHelper . isCurrentAjaxTrigger ( menu ) ) { menu . paintMenuItems ( renderContext ) ; } xml . appendEndTag ( "ui:content" ) ; xml . appendEndTag ( "ui:submenu" ) ; } | Paints the given WSubMenu . |
18,636 | protected List getNewSelections ( final Request request ) { List selections = super . getNewSelections ( request ) ; if ( selections != null ) { for ( int i = 0 ; i < selections . size ( ) ; i ++ ) { Object selection = selections . get ( i ) ; for ( int j = i + 1 ; j < selections . size ( ) ; j ++ ) { if ( Util . equals ( selection , selections . get ( j ) ) ) { selections . remove ( j -- ) ; } } } } return selections ; } | Override getNewSelections to ensure that the max number of inputs is honoured and that there are no duplicates . This should not normally occur as the client side js should prevent it . |
18,637 | public static String rowIndexListToString ( final List < Integer > row ) { if ( row == null || row . isEmpty ( ) ) { return null ; } StringBuffer index = new StringBuffer ( ) ; boolean addDelimiter = false ; for ( Integer lvl : row ) { if ( addDelimiter ) { index . append ( INDEX_DELIMITER ) ; } index . append ( lvl ) ; addDelimiter = true ; } return index . toString ( ) ; } | Convert the row index to its string representation . |
18,638 | public static List < Integer > rowIndexStringToList ( final String row ) { if ( row == null ) { return null ; } List < Integer > rowIndex = new ArrayList < > ( ) ; try { String [ ] rowIdString = row . split ( INDEX_DELIMITER ) ; for ( int i = 0 ; i < rowIdString . length ; i ++ ) { rowIndex . add ( Integer . parseInt ( rowIdString [ i ] ) ) ; } } catch ( NumberFormatException e ) { LOG . warn ( "Invalid row id: " + row ) ; } return rowIndex ; } | Convert the string representation of a row index to a list . |
18,639 | public static void sortData ( final Object [ ] data , final Comparator < Object > comparator , final boolean ascending , final int lowIndex , final int highIndex , final int [ ] sortIndices ) { if ( lowIndex >= highIndex ) { return ; } Object midValue = data [ sortIndices [ ( lowIndex + highIndex ) >>> 1 ] ] ; int i = lowIndex - 1 ; int j = highIndex + 1 ; int sign = ascending ? 1 : - 1 ; for ( ; ; ) { do { i ++ ; } while ( comparator . compare ( data [ sortIndices [ i ] ] , midValue ) * sign < 0 ) ; do { j -- ; } while ( comparator . compare ( data [ sortIndices [ j ] ] , midValue ) * sign > 0 ) ; if ( i >= j ) { break ; } int temp = sortIndices [ i ] ; sortIndices [ i ] = sortIndices [ j ] ; sortIndices [ j ] = temp ; } if ( i > j ) { i = j ; } sortData ( data , comparator , ascending , lowIndex , i , sortIndices ) ; sortData ( data , comparator , ascending , i + 1 , highIndex , sortIndices ) ; } | Sorts the data using the given comparator using a quick - sort . |
18,640 | private static Date parse ( final String dateString ) { try { return new SimpleDateFormat ( "dd/mm/yyyy" ) . parse ( dateString ) ; } catch ( ParseException e ) { LOG . error ( "Error parsing date: " + dateString , e ) ; return null ; } } | Parses a date string . |
18,641 | private TableDataModel createTableModel ( ) { return new AbstractTableDataModel ( ) { private static final int FIRST_NAME = 0 ; private static final int LAST_NAME = 1 ; private static final int DOB = 2 ; private static final int BUTTON = 3 ; private final List < Person > data = Arrays . asList ( new Person [ ] { new Person ( 123 , "Joe" , "Bloggs" , parse ( "01/02/1973" ) ) , new Person ( 456 , "Jane" , "Bloggs" , parse ( "04/05/1976" ) ) , new Person ( 789 , "Kid" , "Bloggs" , parse ( "31/12/1999" ) ) } ) ; public Object getValueAt ( final int row , final int col ) { Person person = data . get ( row ) ; switch ( col ) { case FIRST_NAME : return person . getFirstName ( ) ; case LAST_NAME : return person . getLastName ( ) ; case DOB : { if ( person . getDateOfBirth ( ) == null ) { return null ; } return person . getDateOfBirth ( ) ; } case BUTTON : { return person ; } default : return null ; } } public int getRowCount ( ) { return data . size ( ) ; } } ; } | Creates a table data model containing some dummy person data . |
18,642 | public static void addAllHeadlines ( final PrintWriter writer , final Headers headers ) { PageContentHelper . addHeadlines ( writer , headers . getHeadLines ( ) ) ; PageContentHelper . addJsHeadlines ( writer , headers . getHeadLines ( Headers . JAVASCRIPT_HEADLINE ) ) ; PageContentHelper . addCssHeadlines ( writer , headers . getHeadLines ( Headers . CSS_HEADLINE ) ) ; } | Shortcut method for adding all the headline entries stored in the WHeaders . |
18,643 | private void paintAjax ( final WButton button , final XmlStringBuilder xml ) { xml . appendTagOpen ( "ui:ajaxtrigger" ) ; xml . appendAttribute ( "triggerId" , button . getId ( ) ) ; xml . appendClose ( ) ; xml . appendTagOpen ( "ui:ajaxtargetid" ) ; xml . appendAttribute ( "targetId" , button . getAjaxTarget ( ) . getId ( ) ) ; xml . appendEnd ( ) ; xml . appendEndTag ( "ui:ajaxtrigger" ) ; } | Paints the AJAX information for the given WButton . |
18,644 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WDialog dialog = ( WDialog ) component ; int state = dialog . getState ( ) ; if ( state == WDialog . ACTIVE_STATE || dialog . getTrigger ( ) != null ) { int width = dialog . getWidth ( ) ; int height = dialog . getHeight ( ) ; String title = dialog . getTitle ( ) ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:dialog" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "width" , width > 0 , width ) ; xml . appendOptionalAttribute ( "height" , height > 0 , height ) ; xml . appendOptionalAttribute ( "modal" , dialog . getMode ( ) == WDialog . MODAL , "true" ) ; xml . appendOptionalAttribute ( "open" , dialog . getState ( ) == WDialog . ACTIVE_STATE , "true" ) ; xml . appendOptionalAttribute ( "title" , title ) ; DialogOpenTrigger trigger = dialog . getTrigger ( ) ; if ( trigger != null ) { xml . appendOptionalAttribute ( "triggerid" , trigger . getId ( ) ) ; if ( dialog . hasLegacyTriggerButton ( ) ) { xml . appendClose ( ) ; trigger . paint ( renderContext ) ; xml . appendEndTag ( "ui:dialog" ) ; } else { xml . appendEnd ( ) ; } } else { xml . appendEnd ( ) ; } } } | Paints the given WDialog . |
18,645 | public void paint ( final RenderContext renderContext ) { if ( ! DebugUtil . isDebugFeaturesEnabled ( ) || ! ( renderContext instanceof WebXmlRenderContext ) ) { getBackingComponent ( ) . paint ( renderContext ) ; return ; } AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; if ( operation == null ) { getBackingComponent ( ) . paint ( renderContext ) ; return ; } getBackingComponent ( ) . paint ( renderContext ) ; XmlStringBuilder xml = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; xml . appendTag ( "ui:debug" ) ; for ( String targetId : operation . getTargets ( ) ) { ComponentWithContext target = WebUtilities . getComponentById ( targetId , true ) ; if ( target != null ) { writeDebugInfo ( target . getComponent ( ) , xml ) ; } } xml . appendEndTag ( "ui:debug" ) ; } | Override paint to only output the debugging info for the current targets . |
18,646 | public void setParameter ( final String key , final String value ) { parameters . put ( key , new String [ ] { value } ) ; } | Sets a parameter . |
18,647 | public void addParameterForButton ( final UIContext uic , final WButton button ) { UIContextHolder . pushContext ( uic ) ; try { setParameter ( button . getId ( ) , "x" ) ; } finally { UIContextHolder . popContext ( ) ; } } | Convenience method that adds a parameter emulating a button press . |
18,648 | public void setFileContents ( final String key , final byte [ ] contents ) { MockFileItem fileItem = new MockFileItem ( ) ; fileItem . set ( contents ) ; files . put ( key , new FileItem [ ] { fileItem } ) ; } | Sets mock file upload contents . |
18,649 | private void addMessage ( final WMessageBox box , final Message message , final boolean encode ) { String code = message . getMessage ( ) ; if ( ! Util . empty ( code ) ) { box . addMessage ( encode , code , message . getArgs ( ) ) ; } } | Convenience method to add a message to a message box . |
18,650 | protected static MessageContainer getMessageContainer ( final WComponent component ) { for ( WComponent c = component ; c != null ; c = c . getParent ( ) ) { if ( c instanceof MessageContainer ) { return ( MessageContainer ) c ; } } return null ; } | Searches the WComponent tree of the given component for an ancestor that implements the MessageContainer interface . |
18,651 | public int addItem ( int appId , ItemCreate create , boolean silent ) { return getResourceFactory ( ) . getApiResource ( "/item/app/" + appId + "/" ) . queryParam ( "silent" , silent ? "1" : "0" ) . entity ( create , MediaType . APPLICATION_JSON_TYPE ) . post ( ItemCreateResponse . class ) . getId ( ) ; } | Adds a new item to the given app . |
18,652 | public void updateItem ( int itemId , ItemUpdate update , boolean silent , boolean hook ) { getResourceFactory ( ) . getApiResource ( "/item/" + itemId ) . queryParam ( "silent" , silent ? "1" : "0" ) . queryParam ( "hook" , hook ? "1" : "0" ) . entity ( update , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Updates the entire item . Only fields which have values specified will be updated . To delete the contents of a field pass an empty array for the value . |
18,653 | public void updateItemValues ( int itemId , List < FieldValuesUpdate > values , boolean silent , boolean hook ) { getResourceFactory ( ) . getApiResource ( "/item/" + itemId + "/value/" ) . queryParam ( "silent" , silent ? "1" : "0" ) . queryParam ( "hook" , hook ? "1" : "0" ) . entity ( values , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Updates all the values for an item |
18,654 | public void updateItemFieldValues ( int itemId , int fieldId , List < Map < String , Object > > values , boolean silent , boolean hook ) { getResourceFactory ( ) . getApiResource ( "/item/" + itemId + "/value/" + fieldId ) . queryParam ( "silent" , silent ? "1" : "0" ) . queryParam ( "hook" , hook ? "1" : "0" ) . entity ( values , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Update the item values for a specific field . |
18,655 | public List < Map < String , Object > > getItemFieldValues ( int itemId , int fieldId ) { return getResourceFactory ( ) . getApiResource ( "/item/" + itemId + "/value/" + fieldId ) . get ( new GenericType < List < Map < String , Object > > > ( ) { } ) ; } | Returns the values for a specified field on an item |
18,656 | public List < FieldValuesView > getItemValues ( int itemId ) { return getResourceFactory ( ) . getApiResource ( "/item/" + itemId + "/value/" ) . get ( new GenericType < List < FieldValuesView > > ( ) { } ) ; } | Returns all the values for an item with the additional data provided by the get item operation . |
18,657 | public List < ItemMini > getItemsByFieldAndTitle ( int fieldId , String text , List < Integer > notItemIds , Integer limit ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/item/field/" + fieldId + "/find" ) ; if ( limit != null ) { resource = resource . queryParam ( "limit" , limit . toString ( ) ) ; } if ( notItemIds != null && notItemIds . size ( ) > 0 ) { resource = resource . queryParam ( "not_item_id" , ToStringUtil . toString ( notItemIds , "," ) ) ; } resource = resource . queryParam ( "text" , text ) ; return resource . get ( new GenericType < List < ItemMini > > ( ) { } ) ; } | Used to find possible items for a given application field . It searches the relevant items for the title given . |
18,658 | public List < ItemReference > getItemReference ( int itemId ) { return getResourceFactory ( ) . getApiResource ( "/item/" + itemId + "/reference/" ) . get ( new GenericType < List < ItemReference > > ( ) { } ) ; } | Returns the items that have a reference to the given item . The references are grouped by app . Both the apps and the items are sorted by title . |
18,659 | public ItemRevision getItemRevision ( int itemId , int revisionId ) { return getResourceFactory ( ) . getApiResource ( "/item/" + itemId + "/revision/" + revisionId ) . get ( ItemRevision . class ) ; } | Returns the data about the specific revision on an item |
18,660 | public List < ItemFieldDifference > getItemRevisionDifference ( int itemId , int revisionFrom , int revisionTo ) { return getResourceFactory ( ) . getApiResource ( "/item/" + itemId + "/revision/" + revisionFrom + "/" + revisionTo ) . get ( new GenericType < List < ItemFieldDifference > > ( ) { } ) ; } | Returns the difference in fields values between the two revisions . |
18,661 | public List < ItemRevision > getItemRevisions ( int itemId ) { return getResourceFactory ( ) . getApiResource ( "/item/" + itemId + "/revision/" ) . get ( new GenericType < List < ItemRevision > > ( ) { } ) ; } | Returns all the revisions that have been made to an item |
18,662 | public ItemsResponse getItems ( int appId , Integer limit , Integer offset , SortBy sortBy , Boolean sortDesc , FilterByValue < ? > ... filters ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/item/app/" + appId + "/v2/" ) ; if ( limit != null ) { resource = resource . queryParam ( "limit" , limit . toString ( ) ) ; } if ( offset != null ) { resource = resource . queryParam ( "offset" , offset . toString ( ) ) ; } if ( sortBy != null ) { resource = resource . queryParam ( "sort_by" , sortBy . getKey ( ) ) ; } if ( sortDesc != null ) { resource = resource . queryParam ( "sort_desc" , sortDesc ? "1" : "0" ) ; } for ( FilterByValue < ? > filter : filters ) { resource = resource . queryParam ( filter . getBy ( ) . getKey ( ) , filter . getFormattedValue ( ) ) ; } return resource . get ( ItemsResponse . class ) ; } | Returns the items on app matching the given filters . |
18,663 | public ItemsResponse getItemsByExternalId ( int appId , String externalId ) { return getItems ( appId , null , null , null , null , new FilterByValue < String > ( new ExternalIdFilterBy ( ) , externalId ) ) ; } | Utility method to get items matching an external id |
18,664 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WAjaxControl ajaxControl = ( WAjaxControl ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WComponent trigger = ajaxControl . getTrigger ( ) == null ? ajaxControl : ajaxControl . getTrigger ( ) ; int delay = ajaxControl . getDelay ( ) ; if ( ajaxControl . getTargets ( ) == null || ajaxControl . getTargets ( ) . isEmpty ( ) ) { return ; } xml . appendTagOpen ( "ui:ajaxtrigger" ) ; xml . appendAttribute ( "triggerId" , trigger . getId ( ) ) ; xml . appendOptionalAttribute ( "loadOnce" , ajaxControl . isLoadOnce ( ) , "true" ) ; xml . appendOptionalAttribute ( "delay" , delay > 0 , delay ) ; xml . appendClose ( ) ; for ( AjaxTarget target : ajaxControl . getTargets ( ) ) { xml . appendTagOpen ( "ui:ajaxtargetid" ) ; xml . appendAttribute ( "targetId" , target . getId ( ) ) ; xml . appendEnd ( ) ; } xml . appendEndTag ( "ui:ajaxtrigger" ) ; } | Paints the given AjaxControl . |
18,665 | public void setNameAction ( final Action action ) { LinkComponent linkComponent = new LinkComponent ( ) ; linkComponent . setNameAction ( action ) ; repeater . setRepeatedComponent ( linkComponent ) ; } | Sets the action to execute when the name link is invoked . |
18,666 | protected Object getNewSelection ( final Request request ) { String paramValue = request . getParameter ( getId ( ) ) ; if ( paramValue == null ) { return null ; } List < ? > options = getOptions ( ) ; if ( options == null || options . isEmpty ( ) ) { if ( ! isEditable ( ) ) { return null ; } options = Collections . EMPTY_LIST ; } int optionIndex = 0 ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { List < ? > groupOptions = ( ( OptionGroup ) option ) . getOptions ( ) ; if ( groupOptions != null ) { for ( Object nestedOption : groupOptions ) { if ( paramValue . equals ( optionToCode ( nestedOption , optionIndex ++ ) ) ) { return nestedOption ; } } } } else if ( paramValue . equals ( optionToCode ( option , optionIndex ++ ) ) ) { return option ; } } if ( isEditable ( ) ) { return paramValue ; } LOG . warn ( "Option \"" + paramValue + "\" on the request is not a valid option. Will be ignored." ) ; Object currentOption = getValue ( ) ; return currentOption ; } | Determines which selection has been included in the given request . |
18,667 | public static Object pipe ( final Object in ) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; ObjectOutputStream os = new ObjectOutputStream ( bos ) ; os . writeObject ( in ) ; os . close ( ) ; byte [ ] bytes = bos . toByteArray ( ) ; ByteArrayInputStream bis = new ByteArrayInputStream ( bytes ) ; ObjectInputStream is = new ObjectInputStream ( bis ) ; Object out = is . readObject ( ) ; return out ; } catch ( Exception ex ) { throw new SystemException ( "Failed to pipe " + in , ex ) ; } } | Takes a copy of an input object via serialization . |
18,668 | public void markAsViewed ( int notificationId ) { getResourceFactory ( ) . getApiResource ( "/notification/" + notificationId + "/viewed" ) . entity ( new Empty ( ) , MediaType . APPLICATION_JSON_TYPE ) . post ( ) ; } | Mark the notification as viewed . This will move the notification from the inbox to the viewed archive . |
18,669 | protected void afterPaint ( final RenderContext renderContext ) { if ( renderContext instanceof WebXmlRenderContext ) { PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; writer . println ( WebUtilities . encode ( message ) ) ; if ( error != null ) { writer . println ( "\n<br/>\n<pre>\n" ) ; StringWriter buf = new StringWriter ( ) ; error . printStackTrace ( new PrintWriter ( buf ) ) ; writer . println ( WebUtilities . encode ( buf . toString ( ) ) ) ; writer . println ( "\n</pre>" ) ; } } } | Override in order to paint the component . Real applications should not emit HTML directly . |
18,670 | protected void serviceInt ( final HttpServletRequest request , final HttpServletResponse response ) throws ServletException , IOException { boolean continueProcess = ServletUtil . checkResourceRequest ( request , response ) ; if ( ! continueProcess ) { return ; } WServletHelper helper = createServletHelper ( request , response ) ; InterceptorComponent interceptorChain = createInterceptorChain ( request ) ; WComponent ui = getUI ( request ) ; ServletUtil . processRequest ( helper , ui , interceptorChain ) ; } | Service internal . This method does the real work in servicing the http request . It integrates wcomponents into a servlet environment via a servlet specific helper class . |
18,671 | protected WServletHelper createServletHelper ( final HttpServletRequest httpServletRequest , final HttpServletResponse httpServletResponse ) { LOG . debug ( "Creating a new WServletHelper instance" ) ; WServletHelper helper = new WServletHelper ( this , httpServletRequest , httpServletResponse ) ; return helper ; } | Create a support class to coordinate the web request . |
18,672 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WPanel panel = ( WPanel ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WButton submitButton = panel . getDefaultSubmitButton ( ) ; String submitId = submitButton == null ? null : submitButton . getId ( ) ; String titleText = panel . getTitleText ( ) ; boolean renderChildren = isRenderContent ( panel ) ; xml . appendTagOpen ( "ui:panel" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; if ( PanelMode . LAZY . equals ( panel . getMode ( ) ) ) { xml . appendOptionalAttribute ( "hidden" , ! renderChildren , "true" ) ; } else { xml . appendOptionalAttribute ( "hidden" , component . isHidden ( ) , "true" ) ; } xml . appendOptionalAttribute ( "buttonId" , submitId ) ; xml . appendOptionalAttribute ( "title" , titleText ) ; xml . appendOptionalAttribute ( "accessKey" , Util . upperCase ( panel . getAccessKeyAsString ( ) ) ) ; xml . appendOptionalAttribute ( "type" , getPanelType ( panel ) ) ; xml . appendOptionalAttribute ( "mode" , getPanelMode ( panel ) ) ; xml . appendClose ( ) ; MarginRendererUtil . renderMargin ( panel , renderContext ) ; if ( renderChildren ) { renderChildren ( panel , renderContext ) ; } else { xml . append ( "<ui:content/>" ) ; } xml . appendEndTag ( "ui:panel" ) ; } | Paints the given container . |
18,673 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WSubordinateControl subordinate = ( WSubordinateControl ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; if ( ! subordinate . getRules ( ) . isEmpty ( ) ) { int seq = 0 ; for ( Rule rule : subordinate . getRules ( ) ) { xml . appendTagOpen ( "ui:subordinate" ) ; xml . appendAttribute ( "id" , subordinate . getId ( ) + "-c" + seq ++ ) ; xml . appendClose ( ) ; paintRule ( rule , xml ) ; xml . appendEndTag ( "ui:subordinate" ) ; } } } | Paints the given SubordinateControl . |
18,674 | private void paintRule ( final Rule rule , final XmlStringBuilder xml ) { if ( rule . getCondition ( ) == null ) { throw new SystemException ( "Rule cannot be painted as it has no condition" ) ; } paintCondition ( rule . getCondition ( ) , xml ) ; for ( Action action : rule . getOnTrue ( ) ) { paintAction ( action , "ui:onTrue" , xml ) ; } for ( Action action : rule . getOnFalse ( ) ) { paintAction ( action , "ui:onFalse" , xml ) ; } } | Paints a single rule . |
18,675 | private void paintCondition ( final Condition condition , final XmlStringBuilder xml ) { if ( condition instanceof And ) { xml . appendTag ( "ui:and" ) ; for ( Condition operand : ( ( And ) condition ) . getConditions ( ) ) { paintCondition ( operand , xml ) ; } xml . appendEndTag ( "ui:and" ) ; } else if ( condition instanceof Or ) { xml . appendTag ( "ui:or" ) ; for ( Condition operand : ( ( Or ) condition ) . getConditions ( ) ) { paintCondition ( operand , xml ) ; } xml . appendEndTag ( "ui:or" ) ; } else if ( condition instanceof Not ) { xml . appendTag ( "ui:not" ) ; paintCondition ( ( ( Not ) condition ) . getCondition ( ) , xml ) ; xml . appendEndTag ( "ui:not" ) ; } else if ( condition instanceof AbstractCompare ) { AbstractCompare compare = ( AbstractCompare ) condition ; xml . appendTagOpen ( "ui:condition" ) ; xml . appendAttribute ( "controller" , compare . getTrigger ( ) . getId ( ) ) ; xml . appendAttribute ( "value" , compare . getComparePaintValue ( ) ) ; xml . appendOptionalAttribute ( "operator" , getCompareTypeName ( compare . getCompareType ( ) ) ) ; xml . appendEnd ( ) ; } else { throw new SystemException ( "Unknown condition: " + condition ) ; } } | Paints a condition . |
18,676 | private void paintAction ( final Action action , final String elementName , final XmlStringBuilder xml ) { switch ( action . getActionType ( ) ) { case SHOW : case HIDE : case ENABLE : case DISABLE : case OPTIONAL : case MANDATORY : paintStandardAction ( action , elementName , xml ) ; break ; case SHOWIN : case HIDEIN : case ENABLEIN : case DISABLEIN : paintInGroupAction ( action , elementName , xml ) ; break ; default : break ; } } | Paints an action . |
18,677 | private void paintStandardAction ( final Action action , final String elementName , final XmlStringBuilder xml ) { xml . appendTagOpen ( elementName ) ; xml . appendAttribute ( "action" , getActionTypeName ( action . getActionType ( ) ) ) ; xml . appendClose ( ) ; xml . appendTagOpen ( "ui:target" ) ; SubordinateTarget target = action . getTarget ( ) ; if ( target instanceof WComponentGroup < ? > ) { xml . appendAttribute ( "groupId" , target . getId ( ) ) ; } else { xml . appendAttribute ( "id" , target . getId ( ) ) ; } xml . appendEnd ( ) ; xml . appendEndTag ( elementName ) ; } | Paint a standard action - where a single item or single group is targeted . |
18,678 | private void paintInGroupAction ( final Action action , final String elementName , final XmlStringBuilder xml ) { xml . appendTagOpen ( elementName ) ; xml . appendAttribute ( "action" , getActionTypeName ( action . getActionType ( ) ) ) ; xml . appendClose ( ) ; xml . appendTagOpen ( "ui:target" ) ; xml . appendAttribute ( "groupId" , action . getTarget ( ) . getId ( ) ) ; xml . appendAttribute ( "id" , ( ( AbstractAction ) action ) . getTargetInGroup ( ) . getId ( ) ) ; xml . appendEnd ( ) ; xml . appendEndTag ( elementName ) ; } | Paint an inGroup action - where a single item is being targeted out of a group of items . |
18,679 | private String getCompareTypeName ( final CompareType type ) { String compare = null ; switch ( type ) { case EQUAL : break ; case NOT_EQUAL : compare = "ne" ; break ; case LESS_THAN : compare = "lt" ; break ; case LESS_THAN_OR_EQUAL : compare = "le" ; break ; case GREATER_THAN : compare = "gt" ; break ; case GREATER_THAN_OR_EQUAL : compare = "ge" ; break ; case MATCH : compare = "rx" ; break ; default : throw new SystemException ( "Invalid compare type: " + type ) ; } return compare ; } | Helper method to determine the compare type name . |
18,680 | private String getActionTypeName ( final ActionType type ) { String action = null ; switch ( type ) { case SHOW : action = "show" ; break ; case SHOWIN : action = "showIn" ; break ; case HIDE : action = "hide" ; break ; case HIDEIN : action = "hideIn" ; break ; case ENABLE : action = "enable" ; break ; case ENABLEIN : action = "enableIn" ; break ; case DISABLE : action = "disable" ; break ; case DISABLEIN : action = "disableIn" ; break ; case OPTIONAL : action = "optional" ; break ; case MANDATORY : action = "mandatory" ; break ; default : break ; } return action ; } | Helper method to determine the action name . |
18,681 | private void buildUI ( ) { add ( messages ) ; add ( tabset ) ; container . add ( new WText ( "Select an example from the menu" ) ) ; container . setIdName ( "eg" ) ; tabset . addTab ( container , "(no selection)" , WTabSet . TAB_MODE_CLIENT ) ; WImage srcImage = new WImage ( new ImageResource ( "/image/text-x-source.png" , "View Source" ) ) ; srcImage . setCacheKey ( "srcTabImage" ) ; tabset . addTab ( source , new WDecoratedLabel ( srcImage ) , WTabSet . TAB_MODE_LAZY ) . setToolTip ( "View Source" ) ; WButton refreshButton = new WButton ( "\u200b" ) ; refreshButton . setToolTip ( "Refresh" ) ; refreshButton . setHtmlClass ( HtmlIconUtil . getIconClasses ( "fa-refresh" ) ) ; refreshButton . setRenderAsLink ( true ) ; refreshButton . setAction ( new ValidatingAction ( messages . getValidationErrors ( ) , refreshButton ) { public void executeOnValid ( final ActionEvent event ) { } } ) ; final WButton resetButton = new WButton ( "\u200b" ) ; resetButton . setToolTip ( "Reset" ) ; resetButton . setHtmlClass ( HtmlIconUtil . getIconClasses ( "fa-times-circle" ) ) ; resetButton . setRenderAsLink ( true ) ; resetButton . setAction ( new ValidatingAction ( messages . getValidationErrors ( ) , resetButton ) { public void executeOnValid ( final ActionEvent event ) { resetExample ( ) ; } } ) ; addToTail ( refreshButton ) ; addToTail ( new WText ( "\u2002" ) ) ; addToTail ( resetButton ) ; } | Add the controls to the section in the right order . |
18,682 | private void addToTail ( final WComponent component ) { WContainer tail = ( WContainer ) getDecoratedLabel ( ) . getTail ( ) ; if ( null != tail ) { tail . add ( component ) ; } } | Add a component to the WDecoratedLabel s tail container . |
18,683 | public void selectExample ( final WComponent example , final String exampleName ) { WComponent currentExample = container . getChildAt ( 0 ) . getParent ( ) ; if ( currentExample != null && currentExample . getClass ( ) . equals ( example . getClass ( ) ) ) { return ; } resetExample ( ) ; container . removeAll ( ) ; this . getDecoratedLabel ( ) . setBody ( new WText ( exampleName ) ) ; WApplication app = WebUtilities . getAncestorOfClass ( WApplication . class , this ) ; if ( app != null ) { app . setTitle ( exampleName ) ; } if ( example instanceof ErrorComponent ) { tabset . getTab ( 0 ) . setText ( "Error" ) ; source . setSource ( null ) ; } else { String className = example . getClass ( ) . getName ( ) ; WDefinitionList list = new WDefinitionList ( WDefinitionList . Type . COLUMN ) ; container . add ( list ) ; list . addTerm ( "Example path" , new WText ( className . replaceAll ( "\\." , " / " ) ) ) ; list . addTerm ( "Example JavaDoc" , new JavaDocText ( getSource ( className ) ) ) ; container . add ( new WHorizontalRule ( ) ) ; tabset . getTab ( 0 ) . setText ( example . getClass ( ) . getSimpleName ( ) ) ; source . setSource ( getSource ( className ) ) ; } container . add ( example ) ; example . setLocked ( true ) ; } | Selects an example . |
18,684 | public void selectExample ( final ExampleData example ) { try { StringBuilder exampleName = new StringBuilder ( ) ; if ( example . getExampleGroupName ( ) != null && ! example . getExampleGroupName ( ) . equals ( "" ) ) { exampleName . append ( example . getExampleGroupName ( ) ) . append ( " - " ) ; } exampleName . append ( example . getExampleName ( ) ) ; selectExample ( example . getExampleClass ( ) . newInstance ( ) , exampleName . toString ( ) ) ; } catch ( Exception e ) { WMessages . getInstance ( this ) . error ( "Error selecting example \"" + example . getExampleName ( ) + '"' ) ; selectExample ( new ErrorComponent ( e . getMessage ( ) , e ) , "Error" ) ; } } | Selects an example . If there is an error instantiating the component an error message will be displayed . |
18,685 | private static String getSource ( final String className ) { String sourceName = '/' + className . replace ( '.' , '/' ) + ".java" ; InputStream stream = null ; try { stream = ExampleSection . class . getResourceAsStream ( sourceName ) ; if ( stream != null ) { byte [ ] sourceBytes = StreamUtil . getBytes ( stream ) ; return new String ( sourceBytes , "UTF-8" ) ; } } catch ( IOException e ) { LOG . warn ( "Unable to read source code for class " + className , e ) ; } finally { if ( stream != null ) { try { stream . close ( ) ; } catch ( IOException e ) { LOG . error ( "Error closing stream" , e ) ; } } } return null ; } | Tries to obtain the source file for the given class . |
18,686 | protected String optionToCode ( final Object option , final int index ) { if ( index < 0 ) { List < ? > options = getOptions ( ) ; if ( options == null || options . isEmpty ( ) ) { Integrity . issue ( this , "No options available, so cannot convert the option \"" + option + "\" to a code." ) ; } else { StringBuffer message = new StringBuffer ( ) ; message . append ( "The option \"" ) . append ( option ) . append ( "\" is not one of the available options." ) ; Object firstOption = SelectListUtil . getFirstOption ( options ) ; if ( firstOption != null && option != null && firstOption . getClass ( ) != option . getClass ( ) ) { message . append ( " The options in this list component are of type \"" ) ; message . append ( firstOption . getClass ( ) . getName ( ) ) . append ( "\", the selection you supplied is of type \"" ) ; message . append ( option . getClass ( ) . getName ( ) ) . append ( "\"." ) ; } Integrity . issue ( this , message . toString ( ) ) ; } return null ; } else if ( option instanceof Option ) { Option opt = ( Option ) option ; return opt . getCode ( ) == null ? "" : opt . getCode ( ) ; } else { String code = APPLICATION_LOOKUP_TABLE . getCode ( getLookupTable ( ) , option ) ; if ( code == null ) { return String . valueOf ( index + 1 ) ; } else { return code ; } } } | Retrieves the code for the given option . Will return null if there is no matching option . |
18,687 | protected int getOptionIndex ( final Object option ) { int optionCount = 0 ; List < ? > options = getOptions ( ) ; if ( options != null ) { for ( Object obj : getOptions ( ) ) { if ( obj instanceof OptionGroup ) { List < ? > groupOptions = ( ( OptionGroup ) obj ) . getOptions ( ) ; int groupIndex = groupOptions . indexOf ( option ) ; if ( groupIndex != - 1 ) { return optionCount + groupIndex ; } optionCount += groupOptions . size ( ) ; } else if ( Util . equals ( option , obj ) ) { return optionCount ; } else { optionCount ++ ; } } } return - 1 ; } | Retrieves the index of the given option . The index is not necessarily the index of the option in the options list as there may be options nested in OptionGroups . |
18,688 | public String getListCacheKey ( ) { Object table = getLookupTable ( ) ; if ( table != null && ConfigurationProperties . getDatalistCaching ( ) ) { String key = APPLICATION_LOOKUP_TABLE . getCacheKeyForTable ( table ) ; return key ; } return null ; } | Retrieves the data list cache key for this component . |
18,689 | public List < ? > getOptions ( ) { if ( getLookupTable ( ) == null ) { SelectionModel model = getComponentModel ( ) ; return model . getOptions ( ) ; } else { return APPLICATION_LOOKUP_TABLE . getTable ( getLookupTable ( ) ) ; } } | Returns the complete list of options available for selection for this user s session . |
18,690 | public void setOptions ( final Object [ ] aArray ) { setOptions ( aArray == null ? null : Arrays . asList ( aArray ) ) ; } | Set the complete list of options available for selection for this users session . |
18,691 | protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( isAjax ( ) && UIContextHolder . getCurrent ( ) . getUI ( ) != null ) { AjaxTarget target = getAjaxTarget ( ) ; AjaxHelper . registerComponent ( target . getId ( ) , getId ( ) ) ; } String cacheKey = getListCacheKey ( ) ; if ( cacheKey != null ) { LookupTableHelper . registerList ( cacheKey , request ) ; } } | Override preparePaintComponent to register an AJAX operation if this list is AJAX enabled . |
18,692 | public String getDesc ( final Object option , final int index ) { String desc = "" ; if ( option instanceof Option ) { String optDesc = ( ( Option ) option ) . getDesc ( ) ; if ( optDesc != null ) { desc = optDesc ; } } else { String tableDesc = APPLICATION_LOOKUP_TABLE . getDescription ( getLookupTable ( ) , option ) ; if ( tableDesc != null ) { desc = tableDesc ; } else if ( option != null ) { desc = option . toString ( ) ; } } return I18nUtilities . format ( null , desc ) ; } | Retrieves the description for the given option . Intended for use by Renderers . |
18,693 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WSingleSelect listBox = ( WSingleSelect ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; String dataKey = listBox . getListCacheKey ( ) ; boolean readOnly = listBox . isReadOnly ( ) ; int rows = listBox . getRows ( ) ; xml . appendTagOpen ( "ui:listbox" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , listBox . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendOptionalAttribute ( "data" , dataKey != null , dataKey ) ; xml . appendOptionalAttribute ( "disabled" , listBox . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , listBox . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "submitOnChange" , listBox . isSubmitOnChange ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , component . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , component . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "rows" , rows >= 2 , rows ) ; String autocomplete = listBox . getAutocomplete ( ) ; xml . appendOptionalAttribute ( "autocomplete" , ! Util . empty ( autocomplete ) , autocomplete ) ; } xml . appendAttribute ( "single" , "true" ) ; xml . appendClose ( ) ; List < ? > options = listBox . getOptions ( ) ; boolean renderSelectionsOnly = readOnly || dataKey != null ; if ( options != null ) { int optionIndex = 0 ; Object selectedOption = listBox . 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 ( listBox , nestedOption , optionIndex ++ , xml , selectedOption , renderSelectionsOnly ) ; } xml . appendEndTag ( "ui:optgroup" ) ; } else { renderOption ( listBox , option , optionIndex ++ , xml , selectedOption , renderSelectionsOnly ) ; } } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( listBox , renderContext ) ; } xml . appendEndTag ( "ui:listbox" ) ; } | Paints the given WSingleSelect . |
18,694 | private void initialiseInstanceVariables ( ) { backing = new HashMap < > ( ) ; booleanBacking = new HashSet < > ( ) ; locations = new HashMap < > ( ) ; subcontextCache = Collections . synchronizedMap ( new HashMap ( ) ) ; runtimeProperties = new IncludeProperties ( "Runtime: added at runtime" ) ; } | This method initialises most of the instance variables . |
18,695 | @ SuppressWarnings ( "checkstyle:emptyblock" ) private void load ( ) { recordMessage ( "Loading parameters" ) ; File cwd = new File ( "." ) ; String workingDir ; try { workingDir = cwd . getCanonicalPath ( ) ; } catch ( IOException ex ) { workingDir = "UNKNOWN" ; } recordMessage ( "Working directory is " + workingDir ) ; for ( String resourceName : PARAMETER_LOAD_ORDER ) { loadTop ( resourceName ) ; } if ( getBoolean ( USE_SYSTEM_PROPERTIES ) ) { recordMessage ( "Loading from system properties" ) ; load ( System . getProperties ( ) , "System Properties" , true ) ; } do { } while ( substitute ( ) ) ; if ( getBoolean ( DUMP ) ) { log ( getDebuggingInfo ( ) ) ; log ( getMessages ( ) ) ; } clearMessages ( ) ; Properties systemProperties = getSubProperties ( SYSTEM_PARAMETERS_PREFIX , true ) ; System . getProperties ( ) . putAll ( systemProperties ) ; } | Load the backing from the properties file visible to our classloader plus the filesystem . |
18,696 | @ SuppressWarnings ( "checkstyle:emptyblock" ) private void loadTop ( final String resourceName ) { try { resources . push ( resourceName ) ; load ( resourceName ) ; String includes = get ( INCLUDE_AFTER ) ; if ( includes != null ) { do { } while ( substitute ( INCLUDE_AFTER ) ) ; String [ ] includeAfter = getString ( INCLUDE_AFTER ) . split ( "," ) ; backing . remove ( INCLUDE_AFTER ) ; for ( String after : includeAfter ) { loadTop ( after ) ; } } } finally { resources . pop ( ) ; } } | Loading of top level resources is different to the general recursive case since it is only at the top level that we check for the includeAfter parameter . |
18,697 | private void load ( final String resourceName ) { boolean found = false ; try { resources . push ( resourceName ) ; ClassLoader classloader = getParamsClassLoader ( ) ; List < URL > urls = new ArrayList < > ( ) ; for ( Enumeration < URL > res = classloader . getResources ( resourceName ) ; res . hasMoreElements ( ) ; ) { urls . add ( res . nextElement ( ) ) ; } recordMessage ( "Resource " + resourceName + " was found " + urls . size ( ) + " times" ) ; Map < String , String > loadedFiles = new HashMap < > ( ) ; List < byte [ ] > contentsList = new ArrayList < > ( ) ; List < URL > urlList = new ArrayList < > ( ) ; for ( int i = 0 ; i < urls . size ( ) ; i ++ ) { URL url = urls . get ( i ) ; found = true ; InputStream urlContentStream = url . openStream ( ) ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; StreamUtil . copy ( urlContentStream , baos ) ; urlContentStream . close ( ) ; byte [ ] urlContentBytes = baos . toByteArray ( ) ; String urlContent = new String ( urlContentBytes , "UTF-8" ) ; if ( loadedFiles . keySet ( ) . contains ( urlContent ) ) { recordMessage ( "Skipped url " + url + " - duplicate of " + loadedFiles . get ( urlContent ) ) ; continue ; } loadedFiles . put ( urlContent , url . toString ( ) ) ; contentsList . add ( urlContentBytes ) ; urlList . add ( url ) ; } for ( int i = contentsList . size ( ) - 1 ; i >= 0 ; i -- ) { byte [ ] buff = contentsList . get ( i ) ; URL url = urlList . get ( i ) ; recordMessage ( "Loading from url " + url + "..." ) ; ByteArrayInputStream in = new ByteArrayInputStream ( buff ) ; IncludeProperties properties = new IncludeProperties ( url . toString ( ) ) ; properties . load ( in ) ; } File file = new File ( resourceName ) ; if ( file . exists ( ) ) { recordMessage ( "Loading from file " + filename ( file ) + "..." ) ; found = true ; IncludeProperties properties = new IncludeProperties ( "file:" + filename ( file ) ) ; properties . load ( new BufferedInputStream ( new FileInputStream ( file ) ) ) ; } if ( ! found ) { recordMessage ( "Did not find resource " + resourceName ) ; } } catch ( IOException ex ) { recordException ( ex ) ; } catch ( IllegalArgumentException ex ) { recordException ( ex ) ; } finally { resources . pop ( ) ; } } | Try loading the given resource name . There may be several resources corresponding to that name ... |
18,698 | private String filename ( final File aFile ) { try { return aFile . getCanonicalPath ( ) ; } catch ( IOException ex ) { recordException ( ex ) ; return "UNKNOWN FILE" ; } } | Retrieves the canonical path for a given file . |
18,699 | private void load ( final Properties properties , final String location , final boolean overwriteOnly ) { for ( Map . Entry < Object , Object > entry : properties . entrySet ( ) ) { String key = ( String ) entry . getKey ( ) ; String already = get ( key ) ; if ( overwriteOnly && already == null && ! INCLUDE . equals ( key ) ) { continue ; } String value = ( String ) entry . getValue ( ) ; load ( key , value , location ) ; } } | Load the properties from the given Properties object recording the origin on those properties as being from the given location . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.