idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
18,500
public int getTabIndex ( final WComponent content ) { List < WTab > tabs = getTabs ( ) ; final int count = tabs . size ( ) ; for ( int i = 0 ; i < count ; i ++ ) { WTab tab = tabs . get ( i ) ; if ( content == tab . getContent ( ) ) { return i ; } } return - 1 ; }
Retrieves the tab index for the given tab content .
18,501
private int clientIndexToTabIndex ( final int clientIndex ) { int childCount = getTotalTabs ( ) ; int serverIndex = clientIndex ; for ( int i = 0 ; i <= serverIndex && i < childCount ; i ++ ) { if ( ! isTabVisible ( i ) ) { serverIndex ++ ; } } return serverIndex ; }
The client - side tab indices will differ from the WTabSet s indices when one or more tabs are invisible .
18,502
public String getGroupName ( ) { if ( TabSetType . ACCORDION . equals ( getType ( ) ) ) { CollapsibleGroup group = getComponentModel ( ) . group ; return ( group == null ? null : group . getGroupName ( ) ) ; } return null ; }
The collapsible group name that this tabset belongs to .
18,503
private WMenu buildColumnMenu ( final WText selectedMenuText ) { WMenu menu = new WMenu ( WMenu . MenuType . COLUMN ) ; menu . setSelectMode ( SelectMode . SINGLE ) ; menu . setRows ( 8 ) ; StringTreeNode root = getOrgHierarchyTree ( ) ; mapColumnHierarchy ( menu , root , selectedMenuText ) ; getSubMenuByText ( "Australia" , menu ) . setAccessKey ( 'A' ) ; getSubMenuByText ( "NSW" , menu ) . setMode ( MenuMode . CLIENT ) ; getSubMenuByText ( "Branch 1" , menu ) . setMode ( MenuMode . DYNAMIC ) ; getSubMenuByText ( "VIC" , menu ) . setMode ( MenuMode . LAZY ) ; WMenuItem itemWithIcon = new WMenuItem ( "Help" ) ; itemWithIcon . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { } } ) ; itemWithIcon . setHtmlClass ( HtmlClassProperties . ICON_HELP_BEFORE ) ; menu . add ( itemWithIcon ) ; return menu ; }
Builds up a column menu for inclusion in the example .
18,504
private StringTreeNode getOrgHierarchyTree ( ) { Object [ ] data = new Object [ ] { "Australia" , new Object [ ] { "ACT" } , new Object [ ] { "NSW" , new Object [ ] { "Paramatta" } , new Object [ ] { "Sydney" , new Object [ ] { "Branch 1" , new Object [ ] { "Processing Team 1" } , new Object [ ] { "Processing Team 2" , new Object [ ] { "Robert Rogriguez" } , new Object [ ] { "Phillip Sedgwick" } , new Object [ ] { "Donald Sullivan" } , new Object [ ] { "All" } } , new Object [ ] { "Processing Team 3" , new Object [ ] { "Jim McCarthy" } , new Object [ ] { "Peter Dunne" } , new Object [ ] { "Nicole Brown" } , new Object [ ] { "All" } } , new Object [ ] { "Processing Team 4" } , new Object [ ] { "Processing Team 5" } , new Object [ ] { "All" } } , new Object [ ] { "Branch 2" } , new Object [ ] { "Branch 3" } } , new Object [ ] { "Broken Hill" } , new Object [ ] { "Tamworth" } , new Object [ ] { "Griffith" } , new Object [ ] { "Wollongong" } , new Object [ ] { "Port Macquarie" } , new Object [ ] { "Moree" } , new Object [ ] { "Orange" } , new Object [ ] { "Richmond" } , new Object [ ] { "Bathurst" } , new Object [ ] { "Newcastle" } , new Object [ ] { "Nowra" } , new Object [ ] { "Woy Woy" } , new Object [ ] { "Maitland" } , new Object [ ] { "Hay" } , new Object [ ] { "Bourke" } , new Object [ ] { "Lightning Ridge" } , new Object [ ] { "Coffs Harbour" } , new Object [ ] { "All" } } , new Object [ ] { "VIC" , new Object [ ] { "Melbourne" } , new Object [ ] { "Wangaratta" } , new Object [ ] { "Broken Hill" } , new Object [ ] { "Albury" } , new Object [ ] { "Ballarat" } , new Object [ ] { "Bendigo" } , new Object [ ] { "Horsham" } , new Object [ ] { "Portland" } , new Object [ ] { "Geelong" } , new Object [ ] { "Shepparton" } , new Object [ ] { "Hamilton" } , new Object [ ] { "Morewell" } } , new Object [ ] { "SA" } , new Object [ ] { "NT" } , new Object [ ] { "QLD" } , new Object [ ] { "WA" } , new Object [ ] { "TAS" } } ; return buildOrgHierarchyTree ( data ) ; }
Builds an organisation hierarchy tree for the column menu example .
18,505
private StringTreeNode buildOrgHierarchyTree ( final Object [ ] data ) { StringTreeNode childNode = new StringTreeNode ( ( String ) data [ 0 ] ) ; if ( data . length > 1 ) { for ( int i = 1 ; i < data . length ; i ++ ) { childNode . add ( buildOrgHierarchyTree ( ( Object [ ] ) data [ i ] ) ) ; } } return childNode ; }
Builds one level of the org hierarchy tree .
18,506
private WSubMenu getSubMenuByText ( final String text , final WComponent node ) { if ( node instanceof WSubMenu ) { WSubMenu subMenu = ( WSubMenu ) node ; if ( text . equals ( subMenu . getText ( ) ) ) { return subMenu ; } for ( MenuItem item : subMenu . getMenuItems ( ) ) { WSubMenu result = getSubMenuByText ( text , item ) ; if ( result != null ) { return result ; } } } else if ( node instanceof WMenu ) { WMenu menu = ( WMenu ) node ; for ( MenuItem item : menu . getMenuItems ( ) ) { WSubMenu result = getSubMenuByText ( text , item ) ; if ( result != null ) { return result ; } } } return null ; }
Retrieves a sub menu by its text .
18,507
public static Size intToSize ( final int convert ) { if ( convert <= 0 ) { return null ; } if ( convert <= MAX_SMALL ) { return Size . SMALL ; } if ( convert <= MAX_MED ) { return Size . MEDIUM ; } if ( convert <= MAX_LARGE ) { return Size . LARGE ; } return Size . XL ; }
Convert an int space to a Size . For backwards compatibility during conversion of int spaces to Size spaces .
18,508
public static int sizeToInt ( final Size size ) { if ( size == null ) { return - 1 ; } switch ( size ) { case ZERO : return 0 ; case SMALL : return MAX_SMALL ; case MEDIUM : return MAX_MED ; case LARGE : return MAX_LARGE ; default : return COMMON_XL ; } }
Convert a size back to a representative int . For testing only during conversion of int spaces to Size spaces .
18,509
public void removeTag ( Reference reference , String tag ) { getResourceFactory ( ) . getApiResource ( "/tag/" + reference . toURLFragment ( ) ) . queryParam ( "text" , tag ) . delete ( ) ; }
Removes a single tag from an object .
18,510
public List < TagReference > getTagsOnAppWithText ( int appId , String text ) { return getResourceFactory ( ) . getApiResource ( "/tag/app/" + appId + "/search/" ) . queryParam ( "text" , text ) . get ( new GenericType < List < TagReference > > ( ) { } ) ; }
Returns the objects that are tagged with the given text on the app . The objects are returned sorted descending by the time the tag was added .
18,511
public List < TagReference > getTagsOnOrgWithText ( int orgId , String text ) { return getResourceFactory ( ) . getApiResource ( "/tag/org/" + orgId + "/search/" ) . queryParam ( "text" , text ) . get ( new GenericType < List < TagReference > > ( ) { } ) ; }
Returns the objects that are tagged with the given text on the org . The objects are returned sorted descending by the time the tag was added .
18,512
public List < TagReference > getTagsOnSpaceWithText ( int spaceId , String text ) { return getResourceFactory ( ) . getApiResource ( "/tag/space/" + spaceId + "/search/" ) . queryParam ( "text" , text ) . get ( new GenericType < List < TagReference > > ( ) { } ) ; }
Returns the objects that are tagged with the given text on the space . The objects are returned sorted descending by the time the tag was added .
18,513
public void addTab ( final WComponent card , final String name ) { WContainer titledCard = new WContainer ( ) ; WText title = new WText ( "<b>[" + name + "]:</b><br/>" ) ; title . setEncodeText ( false ) ; titledCard . add ( title ) ; titledCard . add ( card ) ; deck . add ( titledCard ) ; final TabButton button = new TabButton ( name , titledCard ) ; button . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { deck . makeVisible ( button . getAssociatedCard ( ) ) ; } } ) ; btnPanel . add ( button ) ; }
Adds a tab .
18,514
public static void main ( final String [ ] args ) throws Exception { System . setProperty ( "org.apache.commons.logging.Log" , "com.github.bordertech.wcomponents.lde.StandaloneLauncher$TextAreaLogger" ) ; Configuration internalWComponentConfig = Config . getInstance ( ) ; CompositeConfiguration config = new CompositeConfiguration ( new MapConfiguration ( new HashMap < String , Object > ( ) ) ) ; config . addConfiguration ( internalWComponentConfig ) ; config . setProperty ( ConfigurationProperties . LDE_SERVER_PORT , 0 ) ; Config . setConfiguration ( config ) ; getInstance ( ) . launcher . run ( ) ; getInstance ( ) . log ( "LDE now running on " + getInstance ( ) . launcher . getUrl ( ) + '\n' ) ; }
The entry point when the launcher is run as a java application .
18,515
private void readFields ( ) { plain . setText ( tf1 . getText ( ) ) ; mandatory . setText ( tf2 . getText ( ) ) ; readOnly . setText ( tf3 . getText ( ) ) ; disabled . setText ( tf4 . getText ( ) ) ; width . setText ( tf5 . getText ( ) ) ; }
Read fields is a simple method to read all the fields and populate the encoded text fields .
18,516
public void setSource ( final String sourceText ) { String formattedSource ; if ( sourceText == null ) { formattedSource = "" ; } else { formattedSource = WebUtilities . encode ( sourceText ) ; } source . setText ( formattedSource ) ; }
Sets the source code to be displayed in the panel .
18,517
public static void main ( final String [ ] args ) throws Exception { Server server = new Server ( ) ; SocketConnector connector = new SocketConnector ( ) ; connector . setMaxIdleTime ( 0 ) ; connector . setPort ( 8080 ) ; server . addConnector ( connector ) ; WebAppContext context = new WebAppContext ( ) ; context . setContextPath ( "/" ) ; context . addServlet ( HelloWServlet . class . getName ( ) , "/*" ) ; context . addServlet ( ThemeServlet . class . getName ( ) , "/theme/*" ) ; context . setResourceBase ( "." ) ; server . setHandler ( context ) ; server . start ( ) ; }
This main method exists to make it easy to run this servlet without having to create a web . xml file build a war and deploy it .
18,518
public boolean isDisabled ( ) { if ( isFlagSet ( ComponentModel . DISABLED_FLAG ) ) { return true ; } MenuContainer container = WebUtilities . getAncestorOfClass ( MenuContainer . class , this ) ; if ( container instanceof Disableable && ( ( Disableable ) container ) . isDisabled ( ) ) { return true ; } return false ; }
Indicates whether this sub menu is disabled in the given context .
18,519
public void handleRequest ( final Request request ) { if ( isDisabled ( ) ) { return ; } if ( isMenuPresent ( request ) ) { if ( AjaxHelper . isCurrentAjaxTrigger ( this ) ) { WMenu menu = WebUtilities . getAncestorOfClass ( WMenu . class , this ) ; menu . handleRequest ( request ) ; final Action action = getAction ( ) ; if ( action != null ) { final ActionEvent event = new ActionEvent ( this , this . getActionCommand ( ) , this . getActionObject ( ) ) ; Runnable later = new Runnable ( ) { public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; } } boolean openState = "true" . equals ( request . getParameter ( getId ( ) + ".open" ) ) ; setOpen ( openState ) ; } }
Override handleRequest in order to perform processing for this component . This implementation checks for submenu selection and executes the associated action if it has been set .
18,520
protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; String targetId = getContent ( ) . getId ( ) ; String contentId = getId ( ) + "-content" ; switch ( getComponentModel ( ) . mode ) { case LAZY : { getContent ( ) . setVisible ( isOpen ( ) ) ; AjaxHelper . registerContainer ( getId ( ) , contentId , targetId ) ; break ; } case DYNAMIC : { AjaxHelper . registerContainer ( getId ( ) , contentId , targetId ) ; getContent ( ) . setVisible ( isOpen ( ) ) ; break ; } case EAGER : { AjaxHelper . registerContainer ( getId ( ) , contentId , targetId ) ; break ; } case SERVER : { AjaxHelper . registerContainer ( getId ( ) , contentId , targetId ) ; getContent ( ) . setVisible ( isOpen ( ) ) ; break ; } case CLIENT : { break ; } default : break ; } }
Override preparePaintComponent in order to correct the visibility of the sub - menu s children before they are rendered .
18,521
public String getValueAsString ( ) { String result = null ; String [ ] inputs = getValue ( ) ; if ( inputs != null && inputs . length > 0 ) { StringBuffer stringValues = new StringBuffer ( ) ; for ( int i = 0 ; i < inputs . length ; i ++ ) { if ( i > 0 ) { stringValues . append ( ", " ) ; } stringValues . append ( inputs [ i ] ) ; } result = stringValues . toString ( ) ; } return result ; }
The string is a comma seperated list of the string inputs .
18,522
public void serviceRequest ( final Request request ) { windowId = request . getParameter ( WWindow . WWINDOW_REQUEST_PARAM_KEY ) ; if ( windowId == null ) { super . serviceRequest ( request ) ; } else { ComponentWithContext target = WebUtilities . getComponentById ( windowId , true ) ; if ( target == null ) { throw new SystemException ( "No window component for id " + windowId ) ; } UIContext uic = UIContextHolder . getCurrentPrimaryUIContext ( ) ; Environment originalEnvironment = uic . getEnvironment ( ) ; uic . setEnvironment ( new EnvironmentDelegate ( originalEnvironment , windowId , target ) ) ; if ( attachWindow ) { attachUI ( target . getComponent ( ) ) ; } UIContextHolder . pushContext ( target . getContext ( ) ) ; try { super . serviceRequest ( request ) ; } finally { uic . setEnvironment ( originalEnvironment ) ; UIContextHolder . popContext ( ) ; } } }
Temporarily replaces the environment while the request is being handled .
18,523
public void preparePaint ( final Request request ) { if ( windowId == null ) { super . preparePaint ( request ) ; } else { ComponentWithContext target = WebUtilities . getComponentById ( windowId , true ) ; if ( target == null ) { throw new SystemException ( "No window component for id " + windowId ) ; } UIContext uic = UIContextHolder . getCurrentPrimaryUIContext ( ) ; Environment originalEnvironment = uic . getEnvironment ( ) ; uic . setEnvironment ( new EnvironmentDelegate ( originalEnvironment , windowId , target ) ) ; UIContextHolder . pushContext ( target . getContext ( ) ) ; try { super . preparePaint ( request ) ; } finally { uic . setEnvironment ( originalEnvironment ) ; UIContextHolder . popContext ( ) ; } } }
Temporarily replaces the environment while the UI prepares to render .
18,524
public void paint ( final RenderContext renderContext ) { if ( windowId == null ) { super . paint ( renderContext ) ; } else { ComponentWithContext target = WebUtilities . getComponentById ( windowId , true ) ; if ( target == null ) { throw new SystemException ( "No window component for id " + windowId ) ; } UIContext uic = UIContextHolder . getCurrentPrimaryUIContext ( ) ; Environment originalEnvironment = uic . getEnvironment ( ) ; uic . setEnvironment ( new EnvironmentDelegate ( originalEnvironment , windowId , target ) ) ; UIContextHolder . pushContext ( target . getContext ( ) ) ; try { super . paint ( renderContext ) ; } finally { uic . setEnvironment ( originalEnvironment ) ; UIContextHolder . popContext ( ) ; } } }
Temporarily replaces the environment while the UI is being rendered .
18,525
private void paintPaginationDetails ( final WTable table , final XmlStringBuilder xml ) { TableModel model = table . getTableModel ( ) ; xml . appendTagOpen ( "ui:pagination" ) ; xml . appendAttribute ( "rows" , model . getRowCount ( ) ) ; xml . appendOptionalAttribute ( "rowsPerPage" , table . getRowsPerPage ( ) > 0 , table . getRowsPerPage ( ) ) ; xml . appendAttribute ( "currentPage" , table . getCurrentPage ( ) ) ; switch ( table . getPaginationMode ( ) ) { case CLIENT : xml . appendAttribute ( "mode" , "client" ) ; break ; case DYNAMIC : xml . appendAttribute ( "mode" , "dynamic" ) ; break ; case NONE : break ; default : throw new SystemException ( "Unknown pagination mode: " + table . getPaginationMode ( ) ) ; } if ( table . getPaginationLocation ( ) != WTable . PaginationLocation . AUTO ) { switch ( table . getPaginationLocation ( ) ) { case TOP : xml . appendAttribute ( "controls" , "top" ) ; break ; case BOTTOM : xml . appendAttribute ( "controls" , "bottom" ) ; break ; case BOTH : xml . appendAttribute ( "controls" , "both" ) ; break ; default : throw new SystemException ( "Unknown pagination control location: " + table . getPaginationLocation ( ) ) ; } } xml . appendClose ( ) ; if ( table . getRowsPerPageOptions ( ) != null ) { xml . appendTag ( "ui:rowsselect" ) ; for ( Integer option : table . getRowsPerPageOptions ( ) ) { xml . appendTagOpen ( "ui:option" ) ; xml . appendAttribute ( "value" , option ) ; xml . appendEnd ( ) ; } xml . appendEndTag ( "ui:rowsselect" ) ; } xml . appendEndTag ( "ui:pagination" ) ; }
Paint the pagination aspects of the table .
18,526
private void paintSortDetails ( final WTable table , final XmlStringBuilder xml ) { int col = table . getSortColumnIndex ( ) ; boolean ascending = table . isSortAscending ( ) ; xml . appendTagOpen ( "ui:sort" ) ; if ( col >= 0 ) { int [ ] cols = table . getColumnOrder ( ) ; if ( cols != null ) { for ( int i = 0 ; i < cols . length ; i ++ ) { if ( cols [ i ] == col ) { col = i ; break ; } } } xml . appendAttribute ( "col" , col ) ; xml . appendOptionalAttribute ( "descending" , ! ascending , "true" ) ; } switch ( table . getSortMode ( ) ) { case DYNAMIC : xml . appendAttribute ( "mode" , "dynamic" ) ; break ; default : throw new SystemException ( "Unknown sort mode: " + table . getSortMode ( ) ) ; } xml . appendEnd ( ) ; }
Paints the sort details .
18,527
private void paintTableActions ( final WTable table , final WebXmlRenderContext renderContext ) { XmlStringBuilder xml = renderContext . getWriter ( ) ; List < WButton > tableActions = table . getActions ( ) ; if ( ! tableActions . isEmpty ( ) ) { boolean hasActions = false ; for ( WButton button : tableActions ) { if ( ! button . isVisible ( ) ) { continue ; } if ( ! hasActions ) { hasActions = true ; xml . appendTag ( "ui:actions" ) ; } xml . appendTag ( "ui:action" ) ; List < WTable . ActionConstraint > constraints = table . getActionConstraints ( button ) ; if ( constraints != null ) { for ( WTable . ActionConstraint constraint : constraints ) { int minRows = constraint . getMinSelectedRowCount ( ) ; int maxRows = constraint . getMaxSelectedRowCount ( ) ; String message = constraint . getMessage ( ) ; String type = constraint . isError ( ) ? "error" : "warning" ; xml . appendTagOpen ( "ui:condition" ) ; xml . appendOptionalAttribute ( "minSelectedRows" , minRows > 0 , minRows ) ; xml . appendOptionalAttribute ( "maxSelectedRows" , maxRows > 0 , maxRows ) ; xml . appendAttribute ( "selectedOnOther" , this . selectedOnOther ) ; xml . appendAttribute ( "type" , type ) ; xml . appendAttribute ( "message" , I18nUtilities . format ( null , message ) ) ; xml . appendEnd ( ) ; } } button . paint ( renderContext ) ; xml . appendEndTag ( "ui:action" ) ; } if ( hasActions ) { xml . appendEndTag ( "ui:actions" ) ; } } }
Paints the table actions of the table .
18,528
private void paintColumnHeading ( final WTableColumn col , final boolean sortable , final WebXmlRenderContext renderContext ) { XmlStringBuilder xml = renderContext . getWriter ( ) ; int width = col . getWidth ( ) ; Alignment align = col . getAlign ( ) ; xml . appendTagOpen ( "ui:th" ) ; xml . appendOptionalAttribute ( "width" , width > 0 , width ) ; xml . appendOptionalAttribute ( "sortable" , sortable , "true" ) ; if ( Alignment . RIGHT . equals ( align ) ) { xml . appendAttribute ( "align" , "right" ) ; } else if ( Alignment . CENTER . equals ( align ) ) { xml . appendAttribute ( "align" , "center" ) ; } xml . appendClose ( ) ; col . paint ( renderContext ) ; xml . appendEndTag ( "ui:th" ) ; }
Paints a single column heading .
18,529
public void updateUI ( ) { if ( ! Util . empty ( panelContent . getText ( ) ) ) { panelContentRO . setData ( panelContent . getData ( ) ) ; } else { panelContentRO . setText ( SAMPLE_CONTENT ) ; } panel . setType ( ( WPanel . Type ) panelType . getSelected ( ) ) ; String headingText = tfHeading . getText ( ) ; if ( ! Util . empty ( tfHeading . getText ( ) ) ) { heading . setText ( tfHeading . getText ( ) ) ; panel . setTitleText ( headingText ) ; } else { heading . setText ( SAMPLE_HEADER ) ; panel . setTitleText ( SAMPLE_TITLE_TEXT ) ; } }
Set up the WPanel so that the appropriate items are visible based on configuration settings .
18,530
private void buildUI ( ) { buildTargetPanel ( ) ; buildConfigOptions ( ) ; add ( new WHorizontalRule ( ) ) ; add ( panel ) ; add ( new WHorizontalRule ( ) ) ; WPanel hiddenPanel = new WPanel ( ) { public boolean isHidden ( ) { return true ; } } ; hiddenPanel . add ( selectedMenuText ) ; add ( hiddenPanel ) ; add ( new WAjaxControl ( applyConfigButton , panel ) ) ; buildSubordinates ( ) ; }
Add the components in the required order .
18,531
private void buildConfigOptions ( ) { WFieldLayout layout = new WFieldLayout ( WFieldLayout . LAYOUT_STACKED ) ; layout . setMargin ( new Margin ( null , null , Size . LARGE , null ) ) ; layout . addField ( "Select a WPanel Type" , panelType ) ; contentField = layout . addField ( "Panel content" , panelContent ) ; headingField = layout . addField ( "heading" , tfHeading ) ; showMenuField = layout . addField ( "Show menu" , showMenu ) ; showUtilBarField = layout . addField ( "Show utility bar" , showUtilBar ) ; layout . addField ( ( WLabel ) null , applyConfigButton ) ; add ( layout ) ; }
Set up the UI for the configuration options .
18,532
private void buildTargetPanel ( ) { setUpUtilBar ( ) ; panel . add ( utilBar ) ; panel . add ( heading ) ; panel . add ( panelContentRO ) ; panel . add ( menu ) ; }
Set up the target panel contents .
18,533
private void setUpUtilBar ( ) { utilBar . setLayout ( new ListLayout ( ListLayout . Type . FLAT , ListLayout . Alignment . RIGHT , ListLayout . Separator . NONE , false ) ) ; WTextField selectOther = new WTextField ( ) ; selectOther . setToolTip ( "Enter text." ) ; utilBar . add ( selectOther ) ; utilBar . add ( new WButton ( "Go" ) ) ; utilBar . add ( new WButton ( "A" ) ) ; utilBar . add ( new WButton ( "B" ) ) ; utilBar . add ( new WButton ( "C" ) ) ; utilBar . setVisible ( false ) ; }
Add some UI to a utility bar type structure .
18,534
public void serviceRequest ( final Request request ) { String triggerId = request . getParameter ( WServlet . AJAX_TRIGGER_PARAM_NAME ) ; if ( triggerId == null ) { throw new SystemException ( "No AJAX trigger id to on request" ) ; } ComponentWithContext trigger = WebUtilities . getComponentById ( triggerId , true ) ; if ( trigger == null ) { throw new SystemException ( "No component found for AJAX trigger " + triggerId + "." ) ; } WComponent triggerComponent = trigger . getComponent ( ) ; boolean internal = request . getParameter ( WServlet . AJAX_TRIGGER_INTERNAL_PARAM_NAME ) != null ; AjaxOperation ajaxOperation = null ; if ( internal ) { if ( ! ( triggerComponent instanceof AjaxInternalTrigger ) ) { throw new SystemException ( "AJAX trigger [" + triggerId + "] does not support internal actions." ) ; } ajaxOperation = new AjaxOperation ( triggerId ) ; } else { ajaxOperation = AjaxHelper . getAjaxOperation ( triggerId ) ; if ( ajaxOperation != null && "GET" . equals ( request . getMethod ( ) ) && triggerComponent instanceof AjaxInternalTrigger ) { ajaxOperation = new AjaxOperation ( triggerId ) ; } } if ( ajaxOperation == null && trigger . getComponent ( ) instanceof AjaxInternalTrigger ) { ajaxOperation = new AjaxOperation ( triggerId ) ; } if ( ajaxOperation == null ) { throw new SystemException ( "No AJAX operation has been registered for trigger " + triggerId + "." ) ; } AjaxHelper . setCurrentOperationDetails ( ajaxOperation , trigger ) ; super . serviceRequest ( request ) ; }
Setup the AJAX operation details .
18,535
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WDecoratedLabel label = ( WDecoratedLabel ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WComponent head = label . getHead ( ) ; WComponent body = label . getBody ( ) ; WComponent tail = label . getTail ( ) ; xml . appendTagOpen ( "ui:decoratedlabel" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , label . isHidden ( ) , "true" ) ; xml . appendClose ( ) ; if ( head != null && head . isVisible ( ) ) { xml . appendTagOpen ( "ui:labelhead" ) ; xml . appendAttribute ( "id" , label . getId ( ) + "-head" ) ; xml . appendClose ( ) ; head . paint ( renderContext ) ; xml . appendEndTag ( "ui:labelhead" ) ; } xml . appendTagOpen ( "ui:labelbody" ) ; xml . appendAttribute ( "id" , label . getId ( ) + "-body" ) ; xml . appendClose ( ) ; body . paint ( renderContext ) ; xml . appendEndTag ( "ui:labelbody" ) ; if ( tail != null && tail . isVisible ( ) ) { xml . appendTagOpen ( "ui:labeltail" ) ; xml . appendAttribute ( "id" , label . getId ( ) + "-tail" ) ; xml . appendClose ( ) ; tail . paint ( renderContext ) ; xml . appendEndTag ( "ui:labeltail" ) ; } xml . appendEndTag ( "ui:decoratedlabel" ) ; }
Paints the given WDecoratedLabel .
18,536
public List < Comment > getComments ( Reference reference ) { return getResourceFactory ( ) . getApiResource ( "/comment/" + reference . getType ( ) + "/" + reference . getId ( ) ) . get ( new GenericType < List < Comment > > ( ) { } ) ; }
Used to retrieve all the comments that have been made on an object of the given type and with the given id . It returns a list of all the comments sorted in ascending order by time created .
18,537
public int addComment ( Reference reference , CommentCreate comment , boolean silent , boolean hook ) { return getResourceFactory ( ) . getApiResource ( "/comment/" + reference . getType ( ) + "/" + reference . getId ( ) ) . queryParam ( "silent" , silent ? "1" : "0" ) . queryParam ( "hook" , hook ? "1" : "0" ) . entity ( comment , MediaType . APPLICATION_JSON_TYPE ) . post ( CommentCreateResponse . class ) . getId ( ) ; }
Adds a new comment to the object of the given type and id f . ex . item 1 .
18,538
public void updateComment ( int commentId , CommentUpdate comment ) { getResourceFactory ( ) . getApiResource ( "/comment/" + commentId ) . entity ( comment , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates an already created comment . This should only be used to correct spelling and grammatical mistakes in the comment .
18,539
public void render ( final WComponent component , final RenderContext context ) { PrintWriter out = ( ( WebXmlRenderContext ) context ) . getWriter ( ) ; boolean debugLayout = ConfigurationProperties . getDeveloperVelocityDebug ( ) ; if ( debugLayout ) { String templateUrl = url ; if ( url == null && component instanceof AbstractWComponent ) { templateUrl = ( ( AbstractWComponent ) component ) . getTemplate ( ) ; } out . println ( "<!-- Start " + templateUrl + " ) ; paintXml ( component , out ) ; out . println ( "<!-- End " + templateUrl + " ) ; } else { paintXml ( component , out ) ; } }
Paints the component in HTML using the Velocity Template .
18,540
public void paintXml ( final WComponent component , final Writer writer ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "paintXml called for component class " + component . getClass ( ) ) ; } String templateText = null ; if ( component instanceof AbstractWComponent ) { AbstractWComponent abstractComp = ( ( AbstractWComponent ) component ) ; templateText = abstractComp . getTemplateMarkUp ( ) ; } try { Map < String , WComponent > componentsByKey = new HashMap < > ( ) ; VelocityContext context = new VelocityContext ( ) ; fillContext ( component , context , componentsByKey ) ; VelocityWriter velocityWriter = new VelocityWriter ( writer , componentsByKey , UIContextHolder . getCurrent ( ) ) ; if ( templateText != null ) { VelocityEngine engine = VelocityEngineFactory . getVelocityEngine ( ) ; engine . evaluate ( context , velocityWriter , component . getClass ( ) . getSimpleName ( ) , templateText ) ; } else { Template template = getTemplate ( component ) ; if ( template == null ) { LOG . warn ( "VelocityRenderer invoked for a component with no template: " + component . getClass ( ) . getName ( ) ) ; } else { template . merge ( context , velocityWriter ) ; } } velocityWriter . close ( ) ; if ( component instanceof VelocityProperties ) { ( ( VelocityProperties ) component ) . mapUsed ( ) ; } } catch ( ResourceNotFoundException rnfe ) { LOG . error ( "Could not find template '" + url + "' for component " + component . getClass ( ) . getName ( ) , rnfe ) ; } catch ( ParseErrorException pee ) { LOG . error ( "Parse problems" , pee ) ; } catch ( MethodInvocationException mie ) { Throwable wrapped = mie . getWrappedThrowable ( ) ; LOG . error ( "Problems with velocity" , mie ) ; if ( wrapped != null ) { LOG . error ( "Wrapped exception..." , wrapped ) ; } } catch ( Exception e ) { LOG . error ( "Problems with velocity" , e ) ; } }
Paints the component in XML using the Velocity Template .
18,541
private void fillContext ( final WComponent component , final VelocityContext context , final Map < String , WComponent > componentsByKey ) { context . put ( "this" , component ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; context . put ( "uicontext" , uic ) ; context . put ( "uic" , uic ) ; if ( component instanceof VelocityProperties ) { Map < ? , ? > map = ( ( VelocityProperties ) component ) . getVelocityMap ( ) ; for ( Map . Entry < ? , ? > entry : map . entrySet ( ) ) { String key = ( String ) entry . getKey ( ) ; Object value = entry . getValue ( ) ; context . put ( key , value ) ; } } if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Handling children" ) ; } ArrayList < String > children = new ArrayList < > ( ) ; if ( component instanceof Container ) { Container container = ( Container ) component ; for ( int i = 0 ; i < container . getChildCount ( ) ; i ++ ) { WComponent child = container . getChildAt ( i ) ; String tag = child . getTag ( ) ; if ( tag != null || child . isVisible ( ) ) { String key = "<VelocityLayout" + child . getId ( ) + "/>" ; componentsByKey . put ( key , child ) ; if ( tag != null ) { if ( LOG . isDebugEnabled ( ) ) { LOG . debug ( "Adding child " + tag + " to context" ) ; } addToContext ( context , tag , key ) ; } if ( child . isVisible ( ) ) { children . add ( key ) ; } } } context . put ( "children" , children ) ; } context . put ( "context" , context ) ; }
Fills the given velocity context with data from the component which is being rendered . A map of components is also built up in order to support deferred rendering .
18,542
protected void noTemplatePaintHtml ( final WComponent component , final Writer writer ) { try { writer . write ( "<!-- Start " + url + " not found ) ; new VelocityRenderer ( NO_TEMPLATE_LAYOUT ) . paintXml ( component , writer ) ; writer . write ( "<!-- End " + url + " (template not found) ) ; } catch ( IOException e ) { LOG . error ( "Failed to paint component" , e ) ; } }
Paints the component in HTML using the NoTemplateLayout .
18,543
private Template getTemplate ( final WComponent component ) { String templateUrl = url ; if ( templateUrl == null && component instanceof AbstractWComponent ) { templateUrl = ( ( AbstractWComponent ) component ) . getTemplate ( ) ; } if ( templateUrl != null ) { try { return VelocityEngineFactory . getVelocityEngine ( ) . getTemplate ( templateUrl ) ; } catch ( Exception ex ) { LOG . warn ( "Could not open " + templateUrl , ex ) ; try { return VelocityEngineFactory . getVelocityEngine ( ) . getTemplate ( NO_TEMPLATE_LAYOUT ) ; } catch ( Exception e ) { LOG . error ( "Failed to read no template layout" , e ) ; } } } return null ; }
Retrieves the Velocity template for the given component .
18,544
public List < StreamObject > getGlobalStream ( Integer limit , Integer offset , DateTime dateFrom , DateTime dateTo ) { return getStream ( "/stream/" , limit , offset , dateFrom , dateTo ) ; }
Returns the global stream . This includes items and statuses with comments ratings files and edits .
18,545
public List < StreamObjectV2 > getGlobalStreamV2 ( Integer limit , Integer offset , DateTime dateFrom , DateTime dateTo ) { return getStreamV2 ( "/stream/v2/" , limit , offset , dateFrom , dateTo ) ; }
Returns the global stream . The types of objects in the stream can be either item status or task .
18,546
public List < StreamObjectV2 > getAppStream ( int appId , Integer limit , Integer offset ) { return getStreamV2 ( "/stream/app/" + appId + "/" , limit , offset , null , null ) ; }
Returns the stream for the app . Is identical to the global stream but only returns objects in the app .
18,547
protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( ! isInitialised ( ) ) { setInitialised ( true ) ; setupVideo ( ) ; } }
Set up the initial state of the video component .
18,548
private void setupVideo ( ) { video . setAutoplay ( cbAutoPlay . isSelected ( ) ) ; video . setLoop ( cbLoop . isSelected ( ) ) ; video . setMuted ( ! cbMute . isDisabled ( ) && cbMute . isSelected ( ) ) ; video . setControls ( cbControls . isSelected ( ) ? WVideo . Controls . PLAY_PAUSE : WVideo . Controls . NATIVE ) ; video . setDisabled ( cbControls . isSelected ( ) && cbDisable . isSelected ( ) ) ; }
Set the video configuration options .
18,549
public List < String > getHeadLines ( final String type ) { ArrayList < String > lines = headers . get ( type ) ; return lines == null ? null : Collections . unmodifiableList ( lines ) ; }
Gets the head lines of a specified type .
18,550
public void append ( final Object text ) { if ( text instanceof Message ) { append ( translate ( text ) , true ) ; } else if ( text != null ) { append ( text . toString ( ) , true ) ; } }
Appends the given text to this XmlStringBuilder . XML values are escaped .
18,551
public void append ( final String string , final boolean encode ) { if ( encode ) { appendOptional ( WebUtilities . encode ( string ) ) ; } else { write ( HtmlToXMLUtil . unescapeToXML ( string ) ) ; } }
Appends the string to this XmlStringBuilder . XML values are not escaped .
18,552
private String translate ( final Object messageObject ) { if ( messageObject instanceof Message ) { Message message = ( Message ) messageObject ; return I18nUtilities . format ( locale , message . getMessage ( ) , ( Object [ ] ) message . getArgs ( ) ) ; } else if ( messageObject != null ) { return I18nUtilities . format ( locale , messageObject . toString ( ) ) ; } return null ; }
Translates the given message into the appropriate user text . This takes the current locale into consideration if set .
18,553
public static void addFileItem ( final Map < String , FileItem [ ] > files , final String name , final FileItem item ) { if ( files . containsKey ( name ) ) { FileItem [ ] oldValues = files . get ( name ) ; FileItem [ ] newValues = new FileItem [ oldValues . length + 1 ] ; System . arraycopy ( oldValues , 0 , newValues , 0 , oldValues . length ) ; newValues [ newValues . length - 1 ] = item ; files . put ( name , newValues ) ; } else { files . put ( name , new FileItem [ ] { item } ) ; } }
Add the file data to the files collection . If a file already exists with the given name then the value for this name will be an array of all registered files .
18,554
public static void addParameter ( final Map < String , String [ ] > parameters , final String name , final String value ) { if ( parameters . containsKey ( name ) ) { String [ ] oldValues = parameters . get ( name ) ; String [ ] newValues = new String [ oldValues . length + 1 ] ; System . arraycopy ( oldValues , 0 , newValues , 0 , oldValues . length ) ; newValues [ newValues . length - 1 ] = value ; parameters . put ( name , newValues ) ; } else { parameters . put ( name , new String [ ] { value } ) ; } }
Add the request parameter to the parameters collection . If a parameter already exists with the given name then the Map will contain an array of all registered values .
18,555
protected static void renderTagOpen ( final WImage imageComponent , final XmlStringBuilder xml ) { String alternativeText = imageComponent . getAlternativeText ( ) ; if ( alternativeText == null ) { alternativeText = "" ; } else { alternativeText = I18nUtilities . format ( null , alternativeText ) ; } xml . appendTagOpen ( "img" ) ; xml . appendAttribute ( "id" , imageComponent . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , imageComponent . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , imageComponent . isTracking ( ) , "true" ) ; xml . appendUrlAttribute ( "src" , imageComponent . getTargetUrl ( ) ) ; xml . appendAttribute ( "alt" , alternativeText ) ; xml . appendOptionalAttribute ( "hidden" , imageComponent . isHidden ( ) , "hidden" ) ; Dimension size = imageComponent . getSize ( ) ; if ( size != null ) { if ( size . getHeight ( ) >= 0 ) { xml . appendAttribute ( "height" , size . height ) ; } if ( size . getWidth ( ) >= 0 ) { xml . appendAttribute ( "width" , size . width ) ; } } }
Builds the open tag part of the XML that is the tagname and attributes .
18,556
public static void issue ( final WComponent comp , final String message ) { String debugMessage = message + ' ' + comp ; if ( ConfigurationProperties . getIntegrityErrorMode ( ) ) { throw new IntegrityException ( debugMessage ) ; } else { LogFactory . getLog ( Integrity . class ) . warn ( debugMessage ) ; } }
Raises an integrity issue .
18,557
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { AbstractWFieldIndicator fieldIndicator = ( AbstractWFieldIndicator ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WComponent validationTarget = fieldIndicator . getTargetComponent ( ) ; if ( validationTarget == null || ( validationTarget instanceof Diagnosable && ! ( validationTarget instanceof Input ) ) ) { return ; } if ( validationTarget instanceof Input && ! ( ( Input ) validationTarget ) . isReadOnly ( ) ) { return ; } List < Diagnostic > diags = fieldIndicator . getDiagnostics ( ) ; if ( diags != null && ! diags . isEmpty ( ) ) { xml . appendTagOpen ( "ui:fieldindicator" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; switch ( fieldIndicator . getFieldIndicatorType ( ) ) { case INFO : xml . appendAttribute ( "type" , "info" ) ; break ; case WARN : xml . appendAttribute ( "type" , "warn" ) ; break ; case ERROR : xml . appendAttribute ( "type" , "error" ) ; break ; default : throw new SystemException ( "Cannot paint field indicator due to an invalid field indicator type: " + fieldIndicator . getFieldIndicatorType ( ) ) ; } xml . appendAttribute ( "for" , fieldIndicator . getRelatedFieldId ( ) ) ; xml . appendClose ( ) ; for ( Diagnostic diag : diags ) { xml . appendTag ( "ui:message" ) ; xml . appendEscaped ( diag . getDescription ( ) ) ; xml . appendEndTag ( "ui:message" ) ; } xml . appendEndTag ( "ui:fieldindicator" ) ; } }
Paints the given AbstractWFieldIndicator .
18,558
protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( ! isInitialised ( ) ) { String egVersion = Config . getInstance ( ) . getString ( "wcomponents-examples.version" ) ; String wcVersion = WebUtilities . getProjectVersion ( ) ; if ( egVersion != null && ! egVersion . equals ( wcVersion ) ) { String msg = "WComponents-Examples version (" + egVersion + ") does not match WComponents version (" + wcVersion + ")." ; LOG . error ( msg ) ; messages . addMessage ( new Message ( Message . ERROR_MESSAGE , msg ) ) ; } setInitialised ( true ) ; } }
Override preparePaint in order to set up the resources on first access by a user .
18,559
public void setInputWidth ( final int inputWidth ) { if ( inputWidth > 100 ) { throw new IllegalArgumentException ( "inputWidth (" + inputWidth + ") cannot be greater than 100 percent." ) ; } getOrCreateComponentModel ( ) . inputWidth = Math . max ( 0 , inputWidth ) ; }
Sets the desired width of the input field as a percentage of the available space .
18,560
private void setUp ( ) { addExamples ( "AJAX" , ExampleData . AJAX_EXAMPLES ) ; addExamples ( "Form controls" , ExampleData . FORM_CONTROLS ) ; addExamples ( "Feedback and indicators" , ExampleData . FEEDBACK_AND_INDICATORS ) ; addExamples ( "Layout" , ExampleData . LAYOUT_EXAMPLES ) ; addExamples ( "Menus" , ExampleData . MENU_EXAMPLES ) ; addExamples ( "Links" , ExampleData . LINK_EXAMPLES ) ; addExamples ( "Popups / dialogs" , ExampleData . POPUP_EXAMPLES ) ; addExamples ( "Subordinate" , ExampleData . SUBORDINATE_EXAMPLES ) ; addExamples ( "Tabs" , ExampleData . TABSET_EXAMPLES ) ; addExamples ( "Tables" , ExampleData . WTABLE_EXAMPLES ) ; addExamples ( "Validation" , ExampleData . VALIDATION_EXAMPLES ) ; addExamples ( "Other examples (uncategorised)" , ExampleData . MISC_EXAMPLES ) ; addExamples ( "DataTable (deprecated)" , ExampleData . WDATATABLE_EXAMPLES ) ; }
Add the examples as data in the tree .
18,561
public void addExamples ( final String groupName , final ExampleData [ ] entries ) { data . add ( new ExampleMenuList ( groupName , entries ) ) ; }
Add a set of examples to the WTree .
18,562
public final ExampleData getSelectedExampleData ( ) { Set < String > allSelectedItems = getSelectedRows ( ) ; if ( allSelectedItems == null || allSelectedItems . isEmpty ( ) ) { return null ; } for ( String selectedItem : allSelectedItems ) { List < Integer > rowIndex = TreeItemUtil . rowIndexStringToList ( selectedItem ) ; return getTreeModel ( ) . getExampleData ( rowIndex ) ; } return null ; }
Get the example which is selected in the tree .
18,563
protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; if ( ! isInitialised ( ) ) { setInitialised ( true ) ; setTreeModel ( new MenuTreeModel ( data ) ) ; } }
Set the tree model on first use .
18,564
private WPanel createPanelWithText ( final String title , final String text ) { WPanel panel = new WPanel ( WPanel . Type . CHROME ) ; panel . setTitleText ( title ) ; WText textComponent = new WText ( text ) ; textComponent . setEncodeText ( false ) ; panel . add ( textComponent ) ; return panel ; }
Convenience method to create a WPanel with the given title and text .
18,565
public void setErrors ( final List < Diagnostic > errors ) { if ( errors != null ) { ValidationErrorsModel model = getOrCreateComponentModel ( ) ; for ( Diagnostic error : errors ) { if ( error . getSeverity ( ) == Diagnostic . ERROR ) { model . errors . add ( error ) ; } } } }
Sets the errors for a given user .
18,566
public List < GroupedDiagnositcs > getGroupedErrors ( ) { List < GroupedDiagnositcs > grouped = new ArrayList < > ( ) ; Diagnostic previousError = null ; GroupedDiagnositcs group = null ; for ( Diagnostic theError : getErrors ( ) ) { boolean isNewField = ( ( previousError == null ) || ( previousError . getContext ( ) != theError . getContext ( ) ) || ( previousError . getComponent ( ) != theError . getComponent ( ) ) ) ; if ( group == null || isNewField ) { group = new GroupedDiagnositcs ( ) ; grouped . add ( group ) ; } group . addDiagnostic ( theError ) ; previousError = theError ; } return Collections . unmodifiableList ( grouped ) ; }
Groups the errors by their source field .
18,567
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WDateField dateField = ( WDateField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = dateField . isReadOnly ( ) ; Date date = dateField . getDate ( ) ; xml . appendTagOpen ( "ui:datefield" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , dateField . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendOptionalAttribute ( "disabled" , dateField . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , dateField . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , dateField . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , dateField . getAccessibleText ( ) ) ; WComponent submitControl = dateField . getDefaultSubmitButton ( ) ; String submitControlId = submitControl == null ? null : submitControl . getId ( ) ; xml . appendOptionalAttribute ( "buttonId" , submitControlId ) ; Date minDate = dateField . getMinDate ( ) ; Date maxDate = dateField . getMaxDate ( ) ; if ( minDate != null ) { xml . appendAttribute ( "min" , new SimpleDateFormat ( INTERNAL_DATE_FORMAT ) . format ( minDate ) ) ; } if ( maxDate != null ) { xml . appendAttribute ( "max" , new SimpleDateFormat ( INTERNAL_DATE_FORMAT ) . format ( maxDate ) ) ; } String autocomplete = dateField . getAutocomplete ( ) ; xml . appendOptionalAttribute ( "autocomplete" , ! Util . empty ( autocomplete ) , autocomplete ) ; } if ( date != null ) { xml . appendAttribute ( "date" , new SimpleDateFormat ( INTERNAL_DATE_FORMAT ) . format ( date ) ) ; } xml . appendClose ( ) ; if ( date == null ) { xml . appendEscaped ( dateField . getText ( ) ) ; } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( dateField , renderContext ) ; } xml . appendEndTag ( "ui:datefield" ) ; }
Paints the given WDateField .
18,568
public void updateUser ( UserUpdate update ) { getResourceFactory ( ) . getApiResource ( "/user/" ) . entity ( update , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates the active user . The old and new password can be left out in which case the password will not be changed . If the mail is changed the old password has to be supplied as well .
18,569
public < T , R > List < T > getProfileField ( ProfileField < T , R > field ) { List < R > values = getResourceFactory ( ) . getApiResource ( "/user/profile/" + field . getName ( ) ) . get ( new GenericType < List < R > > ( ) { } ) ; List < T > formatted = new ArrayList < T > ( ) ; for ( R value : values ) { formatted . add ( field . parse ( value ) ) ; } return formatted ; }
Returns the field of the profile for the given key from the active user .
18,570
public void updateProfile ( ProfileUpdate profile ) { getResourceFactory ( ) . getApiResource ( "/user/profile/" ) . entity ( profile , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates the fields of an existing profile . All fields must be filled out as any fields not included will not be part of the new revision .
18,571
public void updateProfile ( ProfileFieldValues values ) { getResourceFactory ( ) . getApiResource ( "/user/profile/" ) . entity ( values , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Updates the fields of an existing profile . Will only update the fields in the values .
18,572
public void setProperty ( String key , boolean value ) { getResourceFactory ( ) . getApiResource ( "/user/property/" + key ) . entity ( new PropertyValue ( value ) , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
Sets the value of the property for the active user with the given name . The property is specific to the auth client used .
18,573
public final TableTreeNode getNodeAtLine ( final int row ) { TableTreeNode node = root . next ( ) ; for ( int index = 0 ; node != null && index < row ; index ++ ) { node = node . next ( ) ; } return node ; }
Returns the node at the given line .
18,574
public void handleRequest ( final Request request ) { if ( isDisabled ( ) ) { return ; } if ( isPresent ( request ) ) { List < MenuItemSelectable > selectedItems = new ArrayList < > ( ) ; findSelections ( request , this , selectedItems ) ; setSelectedMenuItems ( selectedItems ) ; } }
Override handleRequest in order to perform processing specific to WMenu .
18,575
private void findSelections ( final Request request , final MenuSelectContainer selectContainer , final List < MenuItemSelectable > selections ) { if ( ! selectContainer . isVisible ( ) || ( selectContainer instanceof Disableable && ( ( Disableable ) selectContainer ) . isDisabled ( ) ) ) { return ; } List < MenuItemSelectable > selectableItems = getSelectableItems ( selectContainer ) ; for ( MenuItemSelectable selectableItem : selectableItems ) { if ( request . getParameter ( selectableItem . getId ( ) + ".selected" ) != null ) { selections . add ( selectableItem ) ; if ( SelectionMode . SINGLE . equals ( selectContainer . getSelectionMode ( ) ) ) { break ; } } } for ( MenuItem item : selectContainer . getMenuItems ( ) ) { if ( item instanceof MenuItemGroup ) { for ( MenuItem groupItem : ( ( MenuItemGroup ) item ) . getMenuItems ( ) ) { if ( groupItem instanceof MenuSelectContainer ) { findSelections ( request , ( MenuSelectContainer ) groupItem , selections ) ; } } } else if ( item instanceof MenuSelectContainer ) { findSelections ( request , ( MenuSelectContainer ) item , selections ) ; } } }
Finds the selected items in a menu for a request .
18,576
private List < MenuItemSelectable > getSelectableItems ( final MenuSelectContainer selectContainer ) { List < MenuItemSelectable > result = new ArrayList < > ( selectContainer . getMenuItems ( ) . size ( ) ) ; SelectionMode selectionMode = selectContainer . getSelectionMode ( ) ; for ( MenuItem item : selectContainer . getMenuItems ( ) ) { if ( item instanceof MenuItemGroup ) { for ( MenuItem groupItem : ( ( MenuItemGroup ) item ) . getMenuItems ( ) ) { if ( isSelectable ( groupItem , selectionMode ) ) { result . add ( ( MenuItemSelectable ) groupItem ) ; } } } else if ( isSelectable ( item , selectionMode ) ) { result . add ( ( MenuItemSelectable ) item ) ; } } return result ; }
Retrieves the selectable items for the given container .
18,577
private boolean isSelectable ( final MenuItem item , final SelectionMode selectionMode ) { if ( ! ( item instanceof MenuItemSelectable ) || ! item . isVisible ( ) || ( item instanceof Disableable && ( ( Disableable ) item ) . isDisabled ( ) ) ) { return false ; } if ( item instanceof WSubMenu && ! MenuType . COLUMN . equals ( getType ( ) ) ) { return false ; } Boolean itemSelectable = ( ( MenuItemSelectable ) item ) . getSelectability ( ) ; if ( itemSelectable != null ) { return itemSelectable ; } return SelectionMode . SINGLE . equals ( selectionMode ) || SelectionMode . MULTIPLE . equals ( selectionMode ) ; }
Indicates whether the given menu item is selectable .
18,578
public final R in ( T ... values ) { expr ( ) . in ( _name , ( Object [ ] ) values ) ; return _root ; }
Is in a list of values .
18,579
public void write ( final char [ ] cbuf , final int off , final int len ) throws IOException { if ( buffer == null ) { backing . write ( cbuf , off , len ) ; } else { for ( int i = off ; i < off + len ; i ++ ) { buffer [ bufferLen ++ ] = cbuf [ i ] ; if ( bufferLen == buffer . length ) { writeBuf ( buffer . length / 2 ) ; } } } }
Implementation of Writer s write method .
18,580
private void writeBuf ( final int endPos ) throws IOException { String searchTerm ; int pos = 0 ; int lastWritePos = 0 ; while ( pos < endPos ) { searchTerm = findSearchStrings ( pos ) ; if ( searchTerm != null ) { if ( lastWritePos != pos ) { backing . write ( buffer , lastWritePos , pos - lastWritePos ) ; } doReplace ( searchTerm , backing ) ; pos += searchTerm . length ( ) ; lastWritePos = pos ; } else { pos ++ ; } } if ( lastWritePos != pos ) { backing . write ( buffer , lastWritePos , pos - lastWritePos ) ; } System . arraycopy ( buffer , pos , buffer , 0 , buffer . length - pos ) ; bufferLen -= pos ; }
Writes the current contents of the buffer up to the given position . More data may be written from the buffer when there is a search string that crosses over endPos .
18,581
private String findSearchStrings ( final int start ) { String longestMatch = null ; for ( int i = 0 ; i < search . length ; i ++ ) { if ( start + search [ i ] . length ( ) > bufferLen ) { continue ; } boolean found = true ; for ( int j = 0 ; j < search [ i ] . length ( ) && ( start + j < bufferLen ) ; j ++ ) { int diff = buffer [ start + j ] - search [ i ] . charAt ( j ) ; if ( diff < 0 ) { return longestMatch ; } else if ( diff != 0 ) { found = false ; break ; } } if ( found && ( longestMatch == null || longestMatch . length ( ) < search [ i ] . length ( ) ) ) { longestMatch = search [ i ] ; } } return longestMatch ; }
Searches for any search strings in the buffer that start between the specified offsets .
18,582
public int createStatus ( int spaceId , StatusCreate status ) { return getResourceFactory ( ) . getApiResource ( "/status/space/" + spaceId + "/" ) . entity ( status , MediaType . APPLICATION_JSON_TYPE ) . post ( StatusCreateResponse . class ) . getId ( ) ; }
Creates a new status message for a user on a specific space . A status update is simply a short text message that the user wishes to share with the rest of the space .
18,583
public void updateStatus ( int statusId , StatusUpdate update ) { getResourceFactory ( ) . getApiResource ( "/status/" + statusId ) . entity ( update , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; }
This will update an existing status message . This will normally only be used to correct spelling and grammatical mistakes .
18,584
public synchronized void register ( final String key , final WComponent ui ) { if ( isRegistered ( key ) ) { throw new SystemException ( "Cannot re-register a component. Key = " + key ) ; } registry . put ( key , ui ) ; }
Registers the given user interface with the given key .
18,585
private static Object loadUI ( final String key ) { String classname = key . trim ( ) ; try { Class < ? > clas = Class . forName ( classname ) ; if ( WComponent . class . isAssignableFrom ( clas ) ) { Object instance = clas . newInstance ( ) ; LOG . debug ( "WComponent successfully loaded with class name \"" + classname + "\"." ) ; return instance ; } else { LOG . error ( "The resource with the name \"" + classname + "\" is not a WComponent." ) ; } } catch ( Exception ex ) { LOG . error ( "Unable to load a WComponent using the resource name \"" + classname + "\"" , ex ) ; } return Boolean . FALSE ; }
Attemps to load a ui using the key as a class name .
18,586
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WComponentGroup group = ( WComponentGroup ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; List < WComponent > components = group . getComponents ( ) ; if ( components != null && ! components . isEmpty ( ) ) { xml . appendTagOpen ( "ui:componentGroup" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendClose ( ) ; for ( WComponent comp : components ) { xml . appendTagOpen ( "ui:component" ) ; xml . appendAttribute ( "id" , comp . getId ( ) ) ; xml . appendEnd ( ) ; } xml . appendEndTag ( "ui:componentGroup" ) ; } }
Paints the given WComponentGroup .
18,587
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WSection section = ( WSection ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean renderChildren = isRenderContent ( section ) ; xml . appendTagOpen ( "ui:section" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; if ( SectionMode . LAZY . equals ( section . getMode ( ) ) ) { xml . appendOptionalAttribute ( "hidden" , ! renderChildren , "true" ) ; } else { xml . appendOptionalAttribute ( "hidden" , component . isHidden ( ) , "true" ) ; } SectionMode mode = section . getMode ( ) ; if ( mode != null ) { switch ( mode ) { case LAZY : xml . appendAttribute ( "mode" , "lazy" ) ; break ; case EAGER : xml . appendAttribute ( "mode" , "eager" ) ; break ; default : throw new SystemException ( "Unknown section mode: " + section . getMode ( ) ) ; } } xml . appendClose ( ) ; MarginRendererUtil . renderMargin ( section , renderContext ) ; if ( renderChildren ) { section . getDecoratedLabel ( ) . paint ( renderContext ) ; section . getContent ( ) . paint ( renderContext ) ; } xml . appendEndTag ( "ui:section" ) ; }
Paints the given WSection .
18,588
public void remove ( final WComponent aChild ) { super . remove ( aChild ) ; PanelModel model = getOrCreateComponentModel ( ) ; if ( model . layoutConstraints == null ) { Map < WComponent , Serializable > defaultConstraints = ( ( PanelModel ) getDefaultModel ( ) ) . layoutConstraints ; if ( defaultConstraints != null ) { model . layoutConstraints = new HashMap < > ( defaultConstraints ) ; } } if ( model . layoutConstraints != null ) { model . layoutConstraints . remove ( aChild ) ; if ( model . layoutConstraints . isEmpty ( ) ) { model . layoutConstraints = null ; } } }
Removes the given component from this component s list of children . This method has been overriden to remove any associated layout constraints .
18,589
public Serializable getLayoutConstraints ( final WComponent child ) { PanelModel model = getComponentModel ( ) ; if ( model . layoutConstraints != null ) { return model . layoutConstraints . get ( child ) ; } return null ; }
Retrieves the layout constraints for the given component if they have been set .
18,590
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WDefinitionList list = ( WDefinitionList ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:definitionlist" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; switch ( list . getType ( ) ) { case FLAT : xml . appendAttribute ( "type" , "flat" ) ; break ; case COLUMN : xml . appendAttribute ( "type" , "column" ) ; break ; case STACKED : xml . appendAttribute ( "type" , "stacked" ) ; break ; case NORMAL : break ; default : throw new SystemException ( "Unknown layout type: " + list . getType ( ) ) ; } xml . appendClose ( ) ; MarginRendererUtil . renderMargin ( list , renderContext ) ; for ( Duplet < String , ArrayList < WComponent > > term : list . getTerms ( ) ) { xml . appendTagOpen ( "ui:term" ) ; xml . appendAttribute ( "text" , I18nUtilities . format ( null , term . getFirst ( ) ) ) ; xml . appendClose ( ) ; for ( WComponent data : term . getSecond ( ) ) { xml . appendTag ( "ui:data" ) ; data . paint ( renderContext ) ; xml . appendEndTag ( "ui:data" ) ; } xml . appendEndTag ( "ui:term" ) ; } xml . appendEndTag ( "ui:definitionlist" ) ; }
Paints the given definition list .
18,591
private void addAlignedExample ( ) { add ( new WHeading ( HeadingLevel . H2 , "WRow / WCol with column alignment" ) ) ; WRow alignedColsRow = new WRow ( ) ; add ( alignedColsRow ) ; WColumn alignedCol = new WColumn ( ) ; alignedCol . setAlignment ( WColumn . Alignment . LEFT ) ; alignedCol . setWidth ( 25 ) ; alignedColsRow . add ( alignedCol ) ; WPanel box = new WPanel ( Type . BOX ) ; box . add ( new WText ( "Left" ) ) ; alignedCol . add ( box ) ; alignedCol = new WColumn ( ) ; alignedCol . setAlignment ( WColumn . Alignment . CENTER ) ; alignedCol . setWidth ( 25 ) ; alignedColsRow . add ( alignedCol ) ; box = new WPanel ( Type . BOX ) ; box . add ( new WText ( "Center" ) ) ; alignedCol . add ( box ) ; alignedCol = new WColumn ( ) ; alignedCol . setAlignment ( WColumn . Alignment . RIGHT ) ; alignedCol . setWidth ( 25 ) ; alignedColsRow . add ( alignedCol ) ; box = new WPanel ( Type . BOX ) ; box . add ( new WText ( "Right" ) ) ; alignedCol . add ( box ) ; alignedCol = new WColumn ( ) ; alignedCol . setWidth ( 25 ) ; alignedColsRow . add ( alignedCol ) ; box = new WPanel ( Type . BOX ) ; box . add ( new WText ( "Undefined" ) ) ; alignedCol . add ( box ) ; }
Add an example showing column alignment .
18,592
private WRow createRow ( final int hgap , final int [ ] colWidths ) { WRow row = new WRow ( hgap ) ; for ( int i = 0 ; i < colWidths . length ; i ++ ) { WColumn col = new WColumn ( colWidths [ i ] ) ; WPanel box = new WPanel ( WPanel . Type . BOX ) ; box . add ( new WText ( colWidths [ i ] + "%" ) ) ; col . add ( box ) ; row . add ( col ) ; } return row ; }
Creates a row containing columns with the given widths .
18,593
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTextField textField = ( WTextField ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = textField . isReadOnly ( ) ; xml . appendTagOpen ( "ui:textfield" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , component . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { int cols = textField . getColumns ( ) ; int minLength = textField . getMinLength ( ) ; int maxLength = textField . getMaxLength ( ) ; String pattern = textField . getPattern ( ) ; WSuggestions suggestions = textField . getSuggestions ( ) ; String suggestionsId = suggestions == null ? null : suggestions . getId ( ) ; WComponent submitControl = textField . getDefaultSubmitButton ( ) ; String submitControlId = submitControl == null ? null : submitControl . getId ( ) ; xml . appendOptionalAttribute ( "disabled" , textField . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , textField . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "minLength" , minLength > 0 , minLength ) ; xml . appendOptionalAttribute ( "maxLength" , maxLength > 0 , maxLength ) ; xml . appendOptionalAttribute ( "toolTip" , textField . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , textField . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "size" , cols > 0 , cols ) ; xml . appendOptionalAttribute ( "buttonId" , submitControlId ) ; xml . appendOptionalAttribute ( "pattern" , ! Util . empty ( pattern ) , pattern ) ; xml . appendOptionalAttribute ( "list" , suggestionsId ) ; String placeholder = textField . getPlaceholder ( ) ; xml . appendOptionalAttribute ( "placeholder" , ! Util . empty ( placeholder ) , placeholder ) ; String autocomplete = textField . getAutocomplete ( ) ; xml . appendOptionalAttribute ( "autocomplete" , ! Util . empty ( autocomplete ) , autocomplete ) ; } xml . appendClose ( ) ; xml . appendEscaped ( textField . getText ( ) ) ; if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( textField , renderContext ) ; } xml . appendEndTag ( "ui:textfield" ) ; }
Paints the given WTextField .
18,594
private String getTag ( final BorderLayoutConstraint constraint ) { switch ( constraint ) { case EAST : return "ui:east" ; case NORTH : return "ui:north" ; case SOUTH : return "ui:south" ; case WEST : return "ui:west" ; case CENTER : default : return "ui:center" ; } }
Retrieves the name of the element that will contain components with the given constraint .
18,595
private void paintChildrenWithConstraint ( final List < Duplet < WComponent , BorderLayoutConstraint > > children , final WebXmlRenderContext renderContext , final BorderLayoutConstraint constraint ) { String containingTag = null ; XmlStringBuilder xml = renderContext . getWriter ( ) ; final int size = children . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { Duplet < WComponent , BorderLayoutConstraint > child = children . get ( i ) ; if ( constraint . equals ( child . getSecond ( ) ) ) { if ( containingTag == null ) { containingTag = getTag ( constraint ) ; xml . appendTag ( containingTag ) ; } child . getFirst ( ) . paint ( renderContext ) ; } } if ( containingTag != null ) { xml . appendEndTag ( containingTag ) ; } }
Paints all the child components with the given constraint .
18,596
public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTextArea textArea = ( WTextArea ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; boolean readOnly = textArea . isReadOnly ( ) ; xml . appendTagOpen ( "ui:textarea" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , textArea . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { int cols = textArea . getColumns ( ) ; int rows = textArea . getRows ( ) ; int minLength = textArea . getMinLength ( ) ; int maxLength = textArea . getMaxLength ( ) ; WComponent submitControl = textArea . getDefaultSubmitButton ( ) ; String submitControlId = submitControl == null ? null : submitControl . getId ( ) ; xml . appendOptionalAttribute ( "disabled" , textArea . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , textArea . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "minLength" , minLength > 0 , minLength ) ; xml . appendOptionalAttribute ( "maxLength" , maxLength > 0 , maxLength ) ; xml . appendOptionalAttribute ( "toolTip" , textArea . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , textArea . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "rows" , rows > 0 , rows ) ; xml . appendOptionalAttribute ( "cols" , cols > 0 , cols ) ; xml . appendOptionalAttribute ( "buttonId" , submitControlId ) ; String placeholder = textArea . getPlaceholder ( ) ; xml . appendOptionalAttribute ( "placeholder" , ! Util . empty ( placeholder ) , placeholder ) ; String autocomplete = textArea . getAutocomplete ( ) ; xml . appendOptionalAttribute ( "autocomplete" , ! Util . empty ( autocomplete ) , autocomplete ) ; } xml . appendClose ( ) ; if ( textArea . isRichTextArea ( ) ) { xml . append ( "<ui:rtf />" ) ; } String textString = textArea . getText ( ) ; if ( textString != null ) { if ( textArea . isReadOnly ( ) && textArea . isRichTextArea ( ) ) { xml . write ( HtmlToXMLUtil . unescapeToXML ( textString ) ) ; } else { xml . appendEscaped ( textString ) ; } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( textArea , renderContext ) ; } xml . appendEndTag ( "ui:textarea" ) ; }
Paints the given WTextArea .
18,597
private StringBuilder extractJavaDoc ( final String source ) { int docStart = source . indexOf ( "/**" ) ; int docEnd = source . indexOf ( "*/" , docStart ) ; int classStart = source . indexOf ( "public class" ) ; int author = source . indexOf ( "@author" ) ; int since = source . indexOf ( "@since" ) ; if ( classStart == - 1 ) { classStart = docEnd ; } if ( docEnd == - 1 || classStart < docStart ) { return new StringBuilder ( "No JavaDoc provided" ) ; } if ( author != - 1 && author < docEnd ) { docEnd = author ; } if ( since != - 1 && since < docEnd ) { docEnd = since ; } return new StringBuilder ( source . substring ( docStart + 3 , docEnd ) . trim ( ) ) ; }
extracts the javadoc . It assumes that the java doc for the class is the first javadoc in the file .
18,598
private void stripAsterisk ( final StringBuilder javaDoc ) { int index = javaDoc . indexOf ( "*" ) ; while ( index != - 1 ) { javaDoc . replace ( index , index + 1 , "" ) ; index = javaDoc . indexOf ( "*" ) ; } }
This method removes the additional astrisks from the java doc .
18,599
private String parseLink ( final String link ) { String [ ] tokens = link . substring ( 7 , link . length ( ) - 1 ) . split ( "\\s" ) ; if ( tokens . length == 1 ) { return tokens [ 0 ] ; } StringBuilder result = new StringBuilder ( ) ; boolean parametersSeen = false ; boolean inParameters = false ; for ( int index = 0 ; index < tokens . length ; index ++ ) { result . append ( " " ) . append ( tokens [ index ] ) ; if ( tokens [ index ] . indexOf ( '(' ) != - 1 && ! parametersSeen ) { inParameters = true ; } if ( index == 1 && ! inParameters ) { result = new StringBuilder ( tokens [ index ] ) ; } if ( tokens [ index ] . indexOf ( ')' ) != - 1 && ! parametersSeen ) { parametersSeen = true ; if ( index != tokens . length - 1 ) { result = new StringBuilder ( ) ; } } } return result . toString ( ) . trim ( ) ; }
a helper method to process the links as they are found .