idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
19,000 | public static AjaxOperation getAjaxOperation ( final String triggerId ) { Map < String , AjaxOperation > operations = getRegisteredOperations ( ) ; return operations == null ? null : operations . get ( triggerId ) ; } | Retrieves the AjaxOperation that has been registered for the given trigger . This method will return null if there is no corresponding operation registered . | 48 | 28 |
19,001 | public static void clearAllRegisteredOperations ( ) { UIContext uic = UIContextHolder . getCurrentPrimaryUIContext ( ) ; if ( uic != null ) { uic . setFwkAttribute ( AJAX_OPERATIONS_SESSION_KEY , null ) ; } } | Clear the registered AJAX operations for this user context . | 67 | 11 |
19,002 | private static void registerAjaxOperation ( final AjaxOperation operation ) { UIContext uic = UIContextHolder . getCurrentPrimaryUIContext ( ) ; if ( uic == null ) { throw new SystemException ( "No User Context Available to Register AJAX Operations." ) ; } Map < String , AjaxOperation > operations = ( Map < String , AjaxOperation > ) uic . getFwkAttribute ( AJAX_OPERATIONS_SESSION_KEY ) ; if ( operations == null ) { operations = new HashMap <> ( ) ; uic . setFwkAttribute ( AJAX_OPERATIONS_SESSION_KEY , operations ) ; } operations . put ( operation . getTriggerId ( ) , operation ) ; } | The Ajax servlet needs access to the AjaxOperation Store the operation in the user context using the trigger Id as this will be present in the Servlet HttpRequest . agreed key . The ajax id is passed in the url to the servlet so it can then access the context . | 160 | 59 |
19,003 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WCheckBoxSelect select = ( WCheckBoxSelect ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; int cols = select . getButtonColumns ( ) ; boolean readOnly = select . isReadOnly ( ) ; xml . appendTagOpen ( "ui:checkboxselect" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , select . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { int min = select . getMinSelect ( ) ; int max = select . getMaxSelect ( ) ; xml . appendOptionalAttribute ( "disabled" , select . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , select . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "submitOnChange" , select . isSubmitOnChange ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , component . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , component . getAccessibleText ( ) ) ; xml . appendOptionalAttribute ( "min" , min > 0 , min ) ; xml . appendOptionalAttribute ( "max" , max > 0 , max ) ; } xml . appendOptionalAttribute ( "frameless" , select . isFrameless ( ) , "true" ) ; switch ( select . getButtonLayout ( ) ) { case COLUMNS : xml . appendAttribute ( "layout" , "column" ) ; xml . appendOptionalAttribute ( "layoutColumnCount" , cols > 0 , cols ) ; break ; case FLAT : xml . appendAttribute ( "layout" , "flat" ) ; break ; case STACKED : xml . appendAttribute ( "layout" , "stacked" ) ; break ; default : throw new SystemException ( "Unknown layout type: " + select . getButtonLayout ( ) ) ; } xml . appendClose ( ) ; // Options List < ? > options = select . getOptions ( ) ; boolean renderSelectionsOnly = readOnly ; if ( options != null ) { int optionIndex = 0 ; List < ? > selections = select . getSelected ( ) ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { throw new SystemException ( "Option groups not supported in WCheckBoxSelect." ) ; } else { renderOption ( select , option , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( select , renderContext ) ; } xml . appendEndTag ( "ui:checkboxselect" ) ; } | Paints the given WCheckBoxSelect . | 671 | 9 |
19,004 | public WSubordinateControl build ( ) { if ( ! condition ( ) . validate ( ) ) { throw new SystemException ( "Invalid condition: " + condition ) ; } if ( getActionsWhenTrue ( ) . isEmpty ( ) && getActionsWhenFalse ( ) . isEmpty ( ) ) { throw new SystemException ( "No actions to execute" ) ; } WSubordinateControl subordinate = new WSubordinateControl ( ) ; Rule rule = new Rule ( ) ; BooleanExpression expression = getCondition ( ) ; rule . setCondition ( expression . build ( ) ) ; for ( Action action : getActionsWhenTrue ( ) ) { rule . addActionOnTrue ( action . build ( ) ) ; } for ( Action action : getActionsWhenFalse ( ) ) { rule . addActionOnFalse ( action . build ( ) ) ; } subordinate . addRule ( rule ) ; return subordinate ; } | This builds the SubordinateControl . This method will throw a SystemException if the condition is invalid or there are no actions specified . | 193 | 26 |
19,005 | @ Override public void preparePaint ( final Request request ) { Headers headers = this . getUI ( ) . getHeaders ( ) ; headers . reset ( ) ; headers . setContentType ( WebUtilities . CONTENT_TYPE_XML ) ; super . preparePaint ( request ) ; } | Override preparePaint in order to prepare the headers . | 66 | 11 |
19,006 | @ Override public void paint ( final RenderContext renderContext ) { WebXmlRenderContext webRenderContext = ( WebXmlRenderContext ) renderContext ; PrintWriter writer = webRenderContext . getWriter ( ) ; beforePaint ( writer ) ; getBackingComponent ( ) . paint ( renderContext ) ; afterPaint ( writer ) ; } | Produce the html output . | 74 | 6 |
19,007 | protected void beforePaint ( final PrintWriter writer ) { PageShell pageShell = Factory . newInstance ( PageShell . class ) ; pageShell . openDoc ( writer ) ; pageShell . writeHeader ( writer ) ; } | Renders the content before the backing component . | 47 | 9 |
19,008 | protected void afterPaint ( final PrintWriter writer ) { PageShell pageShell = Factory . newInstance ( PageShell . class ) ; pageShell . writeFooter ( writer ) ; pageShell . closeDoc ( writer ) ; } | Renders the content after the backing component . | 48 | 9 |
19,009 | @ Override public void handleRequest ( final Request request ) { // Clear pressed clearPressed ( ) ; String requestValue = request . getParameter ( getId ( ) ) ; boolean pressed = "x" . equals ( requestValue ) ; // Only process on a POST if ( pressed && ! "POST" . equals ( request . getMethod ( ) ) ) { LOG . warn ( "Button pressed on a request that is not a POST. Will be ignored." ) ; return ; } setPressed ( pressed , request ) ; } | Override handleRequest in order to perform processing for this component . This implementation checks whether the button has been pressed in the request . | 111 | 25 |
19,010 | @ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; if ( isAjax ( ) && uic . getUI ( ) != null ) { AjaxTarget target = getAjaxTarget ( ) ; AjaxHelper . registerComponent ( target . getId ( ) , getId ( ) ) ; } } | Override preparePaintComponent to register an AJAX operation if this button is AJAX enabled . | 97 | 19 |
19,011 | public String getValue ( ) { Object value = getData ( ) ; if ( value != null ) { return value . toString ( ) ; } String text = getText ( ) ; return text == null ? NO_VALUE : text ; } | Return the button value . By default the value is the same as the text placed on the button . | 51 | 20 |
19,012 | public void setImage ( final Image image ) { ButtonModel model = getOrCreateComponentModel ( ) ; model . image = image ; model . imageUrl = null ; } | Sets the image to display on the button . The text alternative for the image is generated from the button text . | 36 | 23 |
19,013 | @ Override protected void preparePaintComponent ( final Request request ) { if ( OPTION_CONTENT1 . equals ( rbSelect . getSelected ( ) ) ) { content . setText ( "This is content 1" ) ; } else if ( OPTION_CONTENT2 . equals ( rbSelect . getSelected ( ) ) ) { content . setText ( "This is content 2" ) ; } else if ( OPTION_CONTENT3 . equals ( rbSelect . getSelected ( ) ) ) { content . setText ( "This is content 3" ) ; } else { content . setText ( null ) ; } } | Set the content of the text field depending on the selected option in the radio button select . | 140 | 18 |
19,014 | public void execute ( ) { if ( condition == null ) { throw new SystemException ( "Rule cannot be executed as it has no condition" ) ; } if ( condition . isTrue ( ) ) { for ( Action action : onTrue ) { action . execute ( ) ; } } else { for ( Action action : onFalse ) { action . execute ( ) ; } } } | Executes the rule . | 79 | 5 |
19,015 | public static void applyRegisteredControls ( final Request request , final boolean useRequestValues ) { Set < String > controls = getRegisteredSubordinateControls ( ) ; if ( controls == null ) { return ; } // Process Controls for ( String controlId : controls ) { // Find the Component for this ID ComponentWithContext controlWithContext = WebUtilities . getComponentById ( controlId , true ) ; if ( controlWithContext == null ) { LOG . warn ( "Subordinate control for id " + controlId + " is no longer in the tree." ) ; continue ; } if ( ! ( controlWithContext . getComponent ( ) instanceof WSubordinateControl ) ) { LOG . warn ( "Component for id " + controlId + " is not a subordinate control." ) ; continue ; } WSubordinateControl control = ( WSubordinateControl ) controlWithContext . getComponent ( ) ; UIContext uic = controlWithContext . getContext ( ) ; UIContextHolder . pushContext ( uic ) ; try { if ( useRequestValues ) { control . applyTheControls ( request ) ; } else { control . applyTheControls ( ) ; } } finally { UIContextHolder . popContext ( ) ; } } } | Apply the registered Subordinate Controls . | 268 | 7 |
19,016 | public static void clearAllRegisteredControls ( ) { UIContext uic = UIContextHolder . getCurrentPrimaryUIContext ( ) ; if ( uic != null ) { uic . setFwkAttribute ( SUBORDINATE_CONTROL_SESSION_KEY , null ) ; } } | Clear all registered Subordinate Controls on the session . | 70 | 10 |
19,017 | public void setContent ( final WComponent content ) { getOrCreateComponentModel ( ) . content = content ; // There should only be one content. holder . removeAll ( ) ; holder . add ( content ) ; } | Set the WComponent which will handle the content for this dialog . | 46 | 13 |
19,018 | public void setTitle ( final String title , final Serializable ... args ) { getOrCreateComponentModel ( ) . title = I18nUtilities . asMessage ( title , args ) ; } | Sets the dialog title . | 41 | 6 |
19,019 | public void setTrigger ( final DialogOpenTrigger trigger ) { // pre-1.2.3 compatibilty only: if ( this . hasLegacyTriggerButton ( ) ) { DialogOpenTrigger theTrigger = getTrigger ( ) ; if ( theTrigger instanceof WButton ) { remove ( theTrigger ) ; } setLegacyTriggerButton ( false ) ; } // end of backwards compatibility code. getOrCreateComponentModel ( ) . trigger = trigger ; } | Set the component which will open the WDialog . | 98 | 10 |
19,020 | protected void handleTriggerOpenAction ( final Request request ) { // Run the action (if set) final Action action = getTriggerOpenAction ( ) ; if ( action != null ) { final ActionEvent event = new ActionEvent ( this , OPEN_DIALOG_ACTION ) ; Runnable later = new Runnable ( ) { @ Override public void run ( ) { action . execute ( event ) ; } } ; invokeLater ( later ) ; } } | Run the trigger open action . | 97 | 6 |
19,021 | public final boolean isAjaxTargeted ( ) { // If the AJAX target is within the dialog, it should be visible. AjaxOperation operation = AjaxHelper . getCurrentOperation ( ) ; if ( operation == null ) { return false ; } String dialogId = getId ( ) ; String containerId = operation . getTargetContainerId ( ) ; if ( containerId != null && containerId . startsWith ( dialogId ) ) { // target is the dialog, or somewhere within the dialog return true ; } if ( operation . getTargets ( ) != null && UIContextHolder . getCurrent ( ) != null ) { for ( String targetId : operation . getTargets ( ) ) { if ( targetId . startsWith ( dialogId ) ) { return true ; } } } return false ; } | Indicates whether the dialog is currently the target of an AJAX operation . | 174 | 15 |
19,022 | public List < Application > getAppsOnSpace ( int spaceId ) { return getResourceFactory ( ) . getApiResource ( "/app/space/" + spaceId + "/" ) . get ( new GenericType < List < Application > > ( ) { } ) ; } | Returns all the apps on the space that are visible . The apps are sorted by any custom ordering and else by name . | 58 | 24 |
19,023 | public List < Application > getTopApps ( Integer limit ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/app/top/" ) ; if ( limit != null ) { resource = resource . queryParam ( "limit" , limit . toString ( ) ) ; } return resource . get ( new GenericType < List < Application > > ( ) { } ) ; } | Returns the top apps for the active user . This is the apps that the user have interacted with the most . | 83 | 22 |
19,024 | public int addApp ( ApplicationCreate app ) { return getResourceFactory ( ) . getApiResource ( "/app/" ) . entity ( app , MediaType . APPLICATION_JSON_TYPE ) . post ( ApplicationCreateResponse . class ) . getId ( ) ; } | Creates a new app on a space . | 57 | 9 |
19,025 | public void updateApp ( int appId , ApplicationUpdate app ) { getResourceFactory ( ) . getApiResource ( "/app/" + appId ) . entity ( app , MediaType . APPLICATION_JSON ) . put ( ) ; } | Updates an app . The update can contain an new configuration for the app addition of new fields as well as updates to the configuration of existing fields . Fields not included will not be deleted . To delete a field use the delete field operation . | 51 | 48 |
19,026 | public int addField ( int appId , ApplicationFieldCreate field ) { return getResourceFactory ( ) . getApiResource ( "/app/" + appId + "/field/" ) . entity ( field , MediaType . APPLICATION_JSON_TYPE ) . post ( ApplicationFieldCreateResponse . class ) . getId ( ) ; } | Adds a new field to an app | 70 | 7 |
19,027 | public void updateField ( int appId , int fieldId , ApplicationFieldConfiguration configuration ) { getResourceFactory ( ) . getApiResource ( "/app/" + appId + "/field/" + fieldId ) . entity ( configuration , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Updates the configuration of an app field . The type of the field cannot be updated only the configuration . | 65 | 21 |
19,028 | public int install ( int appId , int spaceId ) { return getResourceFactory ( ) . getApiResource ( "/app/" + appId + "/install" ) . entity ( new ApplicationInstall ( spaceId ) , MediaType . APPLICATION_JSON_TYPE ) . post ( ApplicationCreateResponse . class ) . getId ( ) ; } | Installs the app with the given id on the space . | 73 | 12 |
19,029 | public void updateOrder ( int spaceId , List < Integer > appIds ) { getResourceFactory ( ) . getApiResource ( "/app/space/" + spaceId + "/order" ) . entity ( appIds , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Updates the order of the apps on the space . It should post all the apps from the space in the order required . | 65 | 25 |
19,030 | public void deactivateApp ( int appId ) { getResourceFactory ( ) . getApiResource ( "/app/" + appId + "/deactivate" ) . entity ( new Empty ( ) , MediaType . APPLICATION_JSON_TYPE ) . post ( ) ; } | Deactivates the app with the given id . This removes the app from the app navigator and disables insertion of new items . | 58 | 27 |
19,031 | public void downloadFile ( int fileId , java . io . File target , FileSize size ) throws IOException { WebResource builder = getResourceFactory ( ) . getFileResource ( "/" + fileId ) ; if ( size != null ) { builder = builder . path ( "/" + size . name ( ) . toLowerCase ( ) ) ; } byte [ ] data = builder . get ( byte [ ] . class ) ; FileUtils . writeByteArrayToFile ( target , data ) ; } | Downloads the file and saves it to given file | 107 | 10 |
19,032 | public int uploadFile ( String name , java . io . File file ) { FileDataBodyPart filePart = new FileDataBodyPart ( "source" , file ) ; // Work around for bug in cherrypy FormDataContentDisposition . FormDataContentDispositionBuilder builder = FormDataContentDisposition . name ( filePart . getName ( ) ) ; builder . fileName ( file . getName ( ) ) ; builder . size ( file . length ( ) ) ; filePart . setFormDataContentDisposition ( builder . build ( ) ) ; FormDataMultiPart multiPart = new FormDataMultiPart ( ) ; multiPart . bodyPart ( filePart ) ; multiPart . field ( "filename" , name ) ; Builder resource = getResourceFactory ( ) . getApiResource ( "/file/v2/" ) . entity ( multiPart , new MediaType ( "multipart" , "form-data" , Collections . singletonMap ( "boundary" , "AaB03x" ) ) ) ; return resource . post ( File . class ) . getId ( ) ; } | Uploads the file to the API | 234 | 7 |
19,033 | public void updateFile ( int fileId , FileUpdate update ) { getResourceFactory ( ) . getApiResource ( "/file/" + fileId ) . entity ( update , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Used to update the description of the file . | 53 | 9 |
19,034 | public List < File > getOnApp ( int appId , Integer limit , Integer offset ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/file/app/" + appId + "/" ) ; if ( limit != null ) { resource = resource . queryParam ( "limit" , limit . toString ( ) ) ; } if ( offset != null ) { resource = resource . queryParam ( "offset" , offset . toString ( ) ) ; } return resource . get ( new GenericType < List < File > > ( ) { } ) ; } | Returns all the files related to the items in the application . This includes files both on the item itself and in comments on the item . | 123 | 27 |
19,035 | public List < File > getOnSpace ( int spaceId , Integer limit , Integer offset ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/file/space/" + spaceId + "/" ) ; if ( limit != null ) { resource = resource . queryParam ( "limit" , limit . toString ( ) ) ; } if ( offset != null ) { resource = resource . queryParam ( "offset" , offset . toString ( ) ) ; } return resource . get ( new GenericType < List < File > > ( ) { } ) ; } | Returns all the files on the space order by the file name . | 123 | 13 |
19,036 | @ Override public List < Diagnostic > validate ( final List < Diagnostic > diags ) { if ( ! isValid ( ) ) { List < Serializable > argList = getMessageArguments ( ) ; Serializable [ ] args = argList . toArray ( new Serializable [ argList . size ( ) ] ) ; diags . add ( new DiagnosticImpl ( Diagnostic . ERROR , input , getErrorMessage ( ) , args ) ) ; } return diags ; } | Validates the input field . | 103 | 6 |
19,037 | public R between ( int lower , int upper ) { expr ( ) . between ( _name , lower , upper ) ; return _root ; } | Between lower and upper values . | 30 | 6 |
19,038 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WFieldSet fieldSet = ( WFieldSet ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:fieldset" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , fieldSet . isHidden ( ) , "true" ) ; switch ( fieldSet . getFrameType ( ) ) { case NO_BORDER : xml . appendOptionalAttribute ( "frame" , "noborder" ) ; break ; case NO_TEXT : xml . appendOptionalAttribute ( "frame" , "notext" ) ; break ; case NONE : xml . appendOptionalAttribute ( "frame" , "none" ) ; break ; case NORMAL : default : break ; } xml . appendOptionalAttribute ( "required" , fieldSet . isMandatory ( ) , "true" ) ; xml . appendClose ( ) ; // Render margin MarginRendererUtil . renderMargin ( fieldSet , renderContext ) ; // Label WDecoratedLabel label = fieldSet . getTitle ( ) ; label . paint ( renderContext ) ; // Children xml . appendTag ( "ui:content" ) ; int size = fieldSet . getChildCount ( ) ; for ( int i = 0 ; i < size ; i ++ ) { WComponent child = fieldSet . getChildAt ( i ) ; // Skip label, as it has already been painted if ( child != label ) { child . paint ( renderContext ) ; } } xml . appendEndTag ( "ui:content" ) ; DiagnosticRenderUtil . renderDiagnostics ( fieldSet , renderContext ) ; xml . appendEndTag ( "ui:fieldset" ) ; } | Paints the given WFieldSet . | 443 | 8 |
19,039 | private WApplication findApplication ( ) { WApplication appl = WApplication . instance ( this ) ; if ( appl == null ) { messages . addMessage ( new Message ( Message . WARNING_MESSAGE , "There is no WApplication available for this example." ) ) ; } return appl ; } | Find the closest WApplication instance . | 63 | 7 |
19,040 | public void addTaggedComponent ( final String tag , final WComponent component ) { if ( Util . empty ( tag ) ) { throw new IllegalArgumentException ( "A tag must be provided." ) ; } if ( component == null ) { throw new IllegalArgumentException ( "A component must be provided." ) ; } TemplateModel model = getOrCreateComponentModel ( ) ; if ( model . taggedComponents == null ) { model . taggedComponents = new HashMap <> ( ) ; } else { if ( model . taggedComponents . containsKey ( tag ) ) { throw new IllegalArgumentException ( "The tag [" + tag + "] has already been added." ) ; } if ( model . taggedComponents . containsValue ( component ) ) { throw new IllegalArgumentException ( "Component has already been added." ) ; } } model . taggedComponents . put ( tag , component ) ; add ( component ) ; } | Add a tagged component to be included in the template . The component will be rendered in place of the corresponding tag in the template . | 200 | 26 |
19,041 | public void removeTaggedComponent ( final WComponent component ) { TemplateModel model = getOrCreateComponentModel ( ) ; if ( model . taggedComponents != null ) { // Find tag String tag = null ; for ( Map . Entry < String , WComponent > entry : model . taggedComponents . entrySet ( ) ) { if ( entry . getValue ( ) . equals ( component ) ) { tag = entry . getKey ( ) ; break ; } } if ( tag != null ) { removeTaggedComponent ( tag ) ; } } } | Remove a tagged component via the component instance . | 115 | 9 |
19,042 | public void removeTaggedComponent ( final String tag ) { TemplateModel model = getOrCreateComponentModel ( ) ; if ( model . taggedComponents != null ) { WComponent component = model . taggedComponents . remove ( tag ) ; if ( model . taggedComponents . isEmpty ( ) ) { model . taggedComponents = null ; } if ( component != null ) { remove ( component ) ; } } } | Remove a tagged component by its tag . | 88 | 8 |
19,043 | public void addParameter ( final String tag , final Object value ) { if ( Util . empty ( tag ) ) { throw new IllegalArgumentException ( "A tag must be provided" ) ; } TemplateModel model = getOrCreateComponentModel ( ) ; if ( model . parameters == null ) { model . parameters = new HashMap <> ( ) ; } model . parameters . put ( tag , value ) ; } | Add a template parameter . | 88 | 5 |
19,044 | public void setEngineName ( final TemplateRendererFactory . TemplateEngine templateEngine ) { setEngineName ( templateEngine == null ? null : templateEngine . getEngineName ( ) ) ; } | Set a predefined template engine . If null then the default engine is used . | 41 | 16 |
19,045 | public void removeEngineOption ( final String key ) { TemplateModel model = getOrCreateComponentModel ( ) ; if ( model . engineOptions != null ) { model . engineOptions . remove ( key ) ; } } | Remove a template engine option . | 45 | 6 |
19,046 | public static Date createDate ( final int day , final int month , final int year ) { Calendar cal = Calendar . getInstance ( ) ; cal . clear ( ) ; cal . set ( Calendar . DAY_OF_MONTH , day ) ; cal . set ( Calendar . MONTH , month - 1 ) ; cal . set ( Calendar . YEAR , year ) ; return cal . getTime ( ) ; } | Creates a date from the given components . | 85 | 9 |
19,047 | @ Override public void preparePaint ( final Request request ) { // Headers // The WHeaders comes from the root WComponent and is a // mechanism for WComponents to add their own headers // (eg more JavaScript references). Headers headers = this . getUI ( ) . getHeaders ( ) ; headers . reset ( ) ; super . preparePaint ( request ) ; } | Override preparePaint in order to perform processing specific to this interceptor . Any old headers are cleared out before preparePaint is called on the main UI . | 82 | 32 |
19,048 | @ Override public void paint ( final RenderContext renderContext ) { if ( renderContext instanceof WebXmlRenderContext ) { PageContentHelper . addAllHeadlines ( ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) , getUI ( ) . getHeaders ( ) ) ; } getBackingComponent ( ) . paint ( renderContext ) ; } | Override paint in order to perform processing specific to this interceptor . This implementation is responsible for rendering the headlines for the UI . | 80 | 25 |
19,049 | @ Override public void handleRequest ( final Request request ) { super . handleRequest ( request ) ; WComponent visibleDialog = getVisible ( ) ; if ( visibleDialog != null ) { visibleDialog . serviceRequest ( request ) ; } } | Since none of the children are visible to standard processing handleRequest has been overridden so that the visible card is processed . | 51 | 24 |
19,050 | @ Override protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; WComponent visibleDialog = getVisible ( ) ; if ( visibleDialog != null ) { visibleDialog . preparePaint ( request ) ; } } | Since none of the children are visible to standard processing preparePaintComponent has been overridden so that the visible card is prepared . | 56 | 26 |
19,051 | @ Override protected void paintComponent ( final RenderContext renderContext ) { super . paintComponent ( renderContext ) ; WComponent visibleDialog = getVisible ( ) ; if ( visibleDialog != null ) { visibleDialog . paint ( renderContext ) ; } } | Since none of the children are visible to standard processing paintComponent has been overridden so that the visible card is painted . | 54 | 24 |
19,052 | @ Override protected void validateComponent ( final List < Diagnostic > diags ) { super . validateComponent ( diags ) ; WComponent visibleDialog = getVisible ( ) ; if ( visibleDialog != null ) { visibleDialog . validate ( diags ) ; } } | Since none of the children are visible to standard processing validateComponent has been overridden so that the visible card is processed . | 57 | 24 |
19,053 | @ Override public void showErrorIndicators ( final List < Diagnostic > diags ) { WComponent visibleComponent = getVisible ( ) ; visibleComponent . showErrorIndicators ( diags ) ; } | Override method to show Error indicators on the visible card . | 44 | 11 |
19,054 | @ Override public void showWarningIndicators ( final List < Diagnostic > diags ) { WComponent visibleComponent = getVisible ( ) ; visibleComponent . showWarningIndicators ( diags ) ; } | Override method to show Warning indicators on the visible card . | 44 | 11 |
19,055 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WList list = ( WList ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; WList . Type type = list . getType ( ) ; WList . Separator separator = list . getSeparator ( ) ; Size gap = list . getSpace ( ) ; String gapString = gap == null ? null : gap . toString ( ) ; xml . appendTagOpen ( "ui:panel" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "type" , list . isRenderBorder ( ) , "box" ) ; xml . appendClose ( ) ; // Render margin MarginRendererUtil . renderMargin ( list , renderContext ) ; xml . appendTagOpen ( "ui:listlayout" ) ; xml . appendOptionalAttribute ( "gap" , gapString ) ; if ( type != null ) { switch ( type ) { case FLAT : xml . appendAttribute ( "type" , "flat" ) ; break ; case STACKED : xml . appendAttribute ( "type" , "stacked" ) ; break ; case STRIPED : xml . appendAttribute ( "type" , "striped" ) ; break ; default : throw new SystemException ( "Unknown list type: " + type ) ; } } if ( separator != null ) { switch ( separator ) { case BAR : xml . appendAttribute ( "separator" , "bar" ) ; break ; case DOT : xml . appendAttribute ( "separator" , "dot" ) ; break ; case NONE : break ; default : throw new SystemException ( "Unknown list type: " + type ) ; } } xml . appendClose ( ) ; paintRows ( list , renderContext ) ; xml . appendEndTag ( "ui:listlayout" ) ; xml . appendEndTag ( "ui:panel" ) ; } | Paints the given WList . | 476 | 7 |
19,056 | private void addInteractiveExamples ( ) { add ( new WHeading ( HeadingLevel . H2 , "Simple WCheckBoxSelect examples" ) ) ; addExampleUsingLookupTable ( ) ; addExampleUsingArrayList ( ) ; addExampleUsingStringArray ( ) ; addInsideAFieldLayoutExamples ( ) ; add ( new WHeading ( HeadingLevel . H2 , "Examples showing LAYOUT properties" ) ) ; addFlatSelectExample ( ) ; addColumnSelectExample ( ) ; addSingleColumnSelectExample ( ) ; add ( new WHeading ( HeadingLevel . H2 , "WCheckBoxSelect showing the frameless state" ) ) ; add ( new WHeading ( HeadingLevel . H3 , "Normal (with frame)" ) ) ; WCheckBoxSelect select = new WCheckBoxSelect ( "australian_state" ) ; add ( select ) ; select . setToolTip ( "Make a selection" ) ; add ( new WHeading ( HeadingLevel . H3 , "Without frame" ) ) ; select = new WCheckBoxSelect ( "australian_state" ) ; add ( select ) ; select . setFrameless ( true ) ; select . setToolTip ( "Make a selection (no frame)" ) ; } | Simple interactive - state WCheckBoxSelect examples . | 277 | 10 |
19,057 | private void addExampleUsingStringArray ( ) { add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect created using a String array" ) ) ; String [ ] options = new String [ ] { "Dog" , "Cat" , "Bird" , "Turtle" } ; final WCheckBoxSelect select = new WCheckBoxSelect ( options ) ; select . setToolTip ( "Animals" ) ; select . setMandatory ( true ) ; final WTextField text = new WTextField ( ) ; text . setReadOnly ( true ) ; text . setText ( NO_SELECTION ) ; WButton update = new WButton ( "Select Animals" ) ; update . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { String output = select . getSelected ( ) . isEmpty ( ) ? NO_SELECTION : "The selected animals are: " + select . getSelected ( ) ; text . setText ( output ) ; } } ) ; select . setDefaultSubmitButton ( update ) ; WLabel animalLabel = new WLabel ( "A selection is required" , select ) ; animalLabel . setHint ( "mandatory" ) ; add ( animalLabel ) ; add ( select ) ; add ( update ) ; add ( text ) ; add ( new WAjaxControl ( update , text ) ) ; } | This example creates the WCheckBoxSelect from an array of Strings . | 300 | 15 |
19,058 | private void addExampleUsingArrayList ( ) { add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect created using an array list of options" ) ) ; List < CarOption > options = new ArrayList <> ( ) ; options . add ( new CarOption ( "1" , "Ferrari" , "F-360" ) ) ; options . add ( new CarOption ( "2" , "Mercedez Benz" , "amg" ) ) ; options . add ( new CarOption ( "3" , "Nissan" , "Skyline" ) ) ; options . add ( new CarOption ( "5" , "Toyota" , "Prius" ) ) ; final WCheckBoxSelect select = new WCheckBoxSelect ( options ) ; select . setToolTip ( "Cars" ) ; final WTextField text = new WTextField ( ) ; text . setReadOnly ( true ) ; text . setText ( NO_SELECTION ) ; WButton update = new WButton ( "Select Cars" ) ; update . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { String output = select . getSelected ( ) . isEmpty ( ) ? NO_SELECTION : "The selected cars are: " + select . getSelected ( ) ; text . setText ( output ) ; } } ) ; select . setDefaultSubmitButton ( update ) ; add ( select ) ; add ( update ) ; add ( text ) ; add ( new WAjaxControl ( update , text ) ) ; } | This example creates the WCheckBoxSelect from a List of CarOptions . | 342 | 15 |
19,059 | private void addInsideAFieldLayoutExamples ( ) { add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect inside a WFieldLayout" ) ) ; add ( new ExplanatoryText ( "When a WCheckBoxSelect is inside a WField its label is exposed in a way which appears and behaves like a regular " + "HTML label. This allows WCheckBoxSelects to be used in a layout with simple form controls (such as WTextField) and produce a " + "consistent and predicatable interface. The third example in this set uses a null label and a toolTip to hide the labelling " + "element. This can lead to user confusion and is not recommended." ) ) ; WFieldLayout layout = new WFieldLayout ( ) ; layout . setLabelWidth ( 25 ) ; add ( layout ) ; String [ ] options = new String [ ] { "Dog" , "Cat" , "Bird" , "Turtle" } ; WCheckBoxSelect select = new WCheckBoxSelect ( options ) ; layout . addField ( "Select some animals" , select ) ; String [ ] options2 = new String [ ] { "Parrot" , "Galah" , "Cockatoo" , "Lyre" } ; select = new WCheckBoxSelect ( options2 ) ; layout . addField ( "Select some birds" , select ) ; select . setFrameless ( true ) ; // a tooltip can be used as a label stand-in even in a WField String [ ] options3 = new String [ ] { "Carrot" , "Beet" , "Brocolli" , "Bacon - the perfect vegetable" } ; select = new WCheckBoxSelect ( options3 ) ; layout . addField ( ( WLabel ) null , select ) ; select . setToolTip ( "Veggies" ) ; select = new WCheckBoxSelect ( "australian_state" ) ; layout . addField ( "Select a state" , select ) . getLabel ( ) . setHint ( "This is an ajax trigger" ) ; add ( new WAjaxControl ( select , layout ) ) ; } | When a WCheckBoxSelect is added to a WFieldLayout the legend is moved . The first CheckBoxSelect has a frame the second doesn t | 465 | 30 |
19,060 | private void addColumnSelectExample ( ) { add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect laid out in columns" ) ) ; add ( new ExplanatoryText ( "Setting the layout to COLUMN will make the check boxes be rendered in 'n' columns. The number of columns is" + " determined by the layoutColumnCount property." ) ) ; final WCheckBoxSelect select = new WCheckBoxSelect ( "australian_state" ) ; select . setToolTip ( "Make a selection" ) ; select . setButtonLayout ( WCheckBoxSelect . LAYOUT_COLUMNS ) ; select . setButtonColumns ( 2 ) ; add ( select ) ; add ( new WHeading ( HeadingLevel . H3 , "Options equal to columns" ) ) ; String [ ] options = new String [ ] { "Dog" , "Cat" , "Bird" } ; final WCheckBoxSelect select2 = new WCheckBoxSelect ( options ) ; select2 . setToolTip ( "Animals" ) ; select2 . setButtonColumns ( 3 ) ; final WTextField text = new WTextField ( ) ; text . setReadOnly ( true ) ; text . setText ( NO_SELECTION ) ; WButton update = new WButton ( "Select Animals" ) ; update . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { String output = select2 . getSelected ( ) . isEmpty ( ) ? NO_SELECTION : "The selected animals are: " + select2 . getSelected ( ) ; text . setText ( output ) ; } } ) ; select2 . setDefaultSubmitButton ( update ) ; add ( select2 ) ; add ( update ) ; add ( text ) ; add ( new WAjaxControl ( update , text ) ) ; } | adds a WCheckBoxSelect with LAYOUT_COLUMN in 2 columns . | 404 | 19 |
19,061 | private void addAntiPatternExamples ( ) { add ( new WHeading ( HeadingLevel . H2 , "WCheckBoxSelect anti-pattern examples" ) ) ; add ( new WMessageBox ( WMessageBox . WARN , "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them." ) ) ; add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect with submitOnChange" ) ) ; WFieldLayout layout = new WFieldLayout ( WFieldLayout . LAYOUT_STACKED ) ; add ( layout ) ; WCheckBoxSelect select = new WCheckBoxSelect ( "australian_state" ) ; select . setSubmitOnChange ( true ) ; layout . addField ( "Select a state or territory with auto save" , select ) ; select = new WCheckBoxSelect ( "australian_state" ) ; select . setSubmitOnChange ( true ) ; layout . addField ( "Select a state or territory with auto save and hint" , select ) . getLabel ( ) . setHint ( "This is a hint" ) ; // Even compound controls need a label add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect with no labelling component" ) ) ; add ( new ExplanatoryText ( "All input controls, even those which are complex and do not output labellable HTML elements, must be associated with" + " a WLabel or have a toolTip." ) ) ; add ( new WCheckBoxSelect ( "australian_state" ) ) ; // Too many options anti-pattern add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect with too many options" ) ) ; add ( new ExplanatoryText ( "Don't use a WCheckBoxSelect if you have more than a handful of options. A good rule of thumb is fewer than 10." ) ) ; select = new WCheckBoxSelect ( new String [ ] { "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" , "l" , "m" , "n" , "o" , "p" , "q" , "r" , "s" , "t" , "u" , "v" , "w" , "x" , "y" , "z" } ) ; select . setButtonLayout ( WCheckBoxSelect . LAYOUT_COLUMNS ) ; select . setButtonColumns ( 6 ) ; select . setFrameless ( true ) ; add ( new WLabel ( "Select your country of birth" , select ) ) ; add ( select ) ; add ( new WHeading ( HeadingLevel . H3 , "WCheckBoxSelect with no options." ) ) ; add ( new ExplanatoryText ( "An interactive WCheckBoxSelect with no options is rather pointless." ) ) ; select = new WCheckBoxSelect ( ) ; add ( new WLabel ( "WCheckBoxSelect with no options" , select ) ) ; add ( select ) ; } | Examples of what not to do when using WCheckBoxSelect . | 693 | 13 |
19,062 | private void paintAjaxTrigger ( final WLink link , final XmlStringBuilder xml ) { AjaxTarget [ ] actionTargets = link . getActionTargets ( ) ; // Start tag xml . appendTagOpen ( "ui:ajaxtrigger" ) ; xml . appendAttribute ( "triggerId" , link . getId ( ) ) ; xml . appendClose ( ) ; if ( actionTargets != null && actionTargets . length > 0 ) { // Targets for ( AjaxTarget target : actionTargets ) { xml . appendTagOpen ( "ui:ajaxtargetid" ) ; xml . appendAttribute ( "targetId" , target . getId ( ) ) ; xml . appendEnd ( ) ; } } else { // Target itself xml . appendTagOpen ( "ui:ajaxtargetid" ) ; xml . appendAttribute ( "targetId" , link . getId ( ) ) ; xml . appendEnd ( ) ; } // End tag xml . appendEndTag ( "ui:ajaxtrigger" ) ; } | Paint the AJAX trigger if the link has an action . | 228 | 13 |
19,063 | @ Override public void paint ( final RenderContext renderContext ) { if ( ! ( renderContext instanceof WebXmlRenderContext ) ) { throw new SystemException ( "Unable to render to " + renderContext ) ; } PrintWriter writer = ( ( WebXmlRenderContext ) renderContext ) . getWriter ( ) ; Template template = null ; try { template = VelocityEngineFactory . getVelocityEngine ( ) . getTemplate ( templateUrl ) ; } catch ( Exception ex ) { String message = "Could not open velocity template \"" + templateUrl + "\" for \"" + this . getClass ( ) . getName ( ) + "\"" ; LOG . error ( message , ex ) ; writer . println ( message ) ; return ; } try { VelocityContext context = new VelocityContext ( ) ; fillContext ( context ) ; template . merge ( context , writer ) ; } catch ( ResourceNotFoundException rnfe ) { LOG . error ( "Could not find template " + templateUrl , rnfe ) ; } catch ( ParseErrorException pee ) { // syntax error : problem parsing the template LOG . error ( "Parse problems" , pee ) ; } catch ( MethodInvocationException mie ) { // something invoked in the template // threw an exception 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 ) ; } } | Renders the component using the velocity template which has been provided . | 343 | 13 |
19,064 | private static String [ ] getRegions ( final String state ) { if ( "ACT" . equals ( state ) ) { return ACT_REGIONS ; } else if ( "VIC" . equals ( state ) ) { return VIC_REGIONS ; } else { return null ; } } | Retrieves the regions in a state . | 62 | 9 |
19,065 | private static String [ ] getSuburbs ( final String region ) { if ( "Tuggeranong" . equals ( region ) ) { return TUGGERANONG_SUBURBS ; } else if ( "Woden" . equals ( region ) ) { return WODEN_SUBURBS ; } else if ( "Melbourne" . equals ( region ) ) { return MELBOURNE_SUBURBS ; } else if ( "Mornington Peninsula" . equals ( region ) ) { return MORNINGTON_SUBURBS ; } else { return null ; } } | Retrieves the suburbs in a region . | 130 | 9 |
19,066 | private void applySettings ( ) { // reset the container. container . reset ( ) ; // create the new collapsible. WText component1 = new WText ( "Here is some text that is collapsible via ajax." ) ; WCollapsible collapsible1 = new WCollapsible ( component1 , "Collapsible" , ( CollapsibleMode ) rbCollapsibleSelect . getSelected ( ) ) ; collapsible1 . setCollapsed ( cbCollapsed . isSelected ( ) ) ; collapsible1 . setVisible ( cbVisible . isSelected ( ) ) ; if ( collapsible1 . getMode ( ) == CollapsibleMode . DYNAMIC ) { component1 . setText ( component1 . getText ( ) + "\u00a0Generated on " + new Date ( ) ) ; } if ( drpHeadingLevels . getSelected ( ) != null ) { collapsible1 . setHeadingLevel ( ( HeadingLevel ) drpHeadingLevels . getSelected ( ) ) ; } // add the new collapsible to the container. container . add ( collapsible1 ) ; } | applySettings creates the WCollapsible and loads it into the container . | 253 | 15 |
19,067 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMenuItemGroup group = ( WMenuItemGroup ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:menugroup" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendClose ( ) ; paintChildren ( group , renderContext ) ; xml . appendEndTag ( "ui:menugroup" ) ; } | Paints the given WMenuItemGroup . | 158 | 9 |
19,068 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WMultiDropdown dropdown = ( WMultiDropdown ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; String dataKey = dropdown . getListCacheKey ( ) ; boolean readOnly = dropdown . isReadOnly ( ) ; xml . appendTagOpen ( "ui:multidropdown" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , dropdown . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendOptionalAttribute ( "data" , dataKey != null && ! readOnly , dataKey ) ; xml . appendOptionalAttribute ( "disabled" , dropdown . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , dropdown . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "submitOnChange" , dropdown . isSubmitOnChange ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , component . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , component . getAccessibleText ( ) ) ; int min = dropdown . getMinSelect ( ) ; int max = dropdown . getMaxSelect ( ) ; xml . appendOptionalAttribute ( "min" , min > 0 , min ) ; xml . appendOptionalAttribute ( "max" , max > 0 , max ) ; xml . appendOptionalAttribute ( "title" , I18nUtilities . format ( null , InternalMessages . DEFAULT_MULTIDROPDOWN_TIP ) ) ; } xml . appendClose ( ) ; // Options List < ? > options = dropdown . getOptions ( ) ; boolean renderSelectionsOnly = dropdown . isReadOnly ( ) || dataKey != null ; if ( options != null ) { int optionIndex = 0 ; List < ? > selections = dropdown . getSelected ( ) ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { xml . appendTagOpen ( "ui:optgroup" ) ; xml . appendAttribute ( "label" , ( ( OptionGroup ) option ) . getDesc ( ) ) ; xml . appendClose ( ) ; for ( Object nestedOption : ( ( OptionGroup ) option ) . getOptions ( ) ) { renderOption ( dropdown , nestedOption , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } xml . appendEndTag ( "ui:optgroup" ) ; } else { renderOption ( dropdown , option , optionIndex ++ , xml , selections , renderSelectionsOnly ) ; } } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( dropdown , renderContext ) ; } // End tag xml . appendEndTag ( "ui:multidropdown" ) ; } | Paints the given WMultiDropdown . | 703 | 9 |
19,069 | public void setData ( final List data ) { // Bean properties to render String [ ] properties = new String [ ] { "colour" , "shape" , "animal" } ; simpleTable . setDataModel ( new SimpleBeanListTableDataModel ( properties , data ) ) ; } | Sets the table data . | 61 | 6 |
19,070 | public void setMandatory ( final boolean mandatory , final String message ) { setFlag ( ComponentModel . MANDATORY_FLAG , mandatory ) ; getOrCreateComponentModel ( ) . errorMessage = message ; } | Set whether or not this field set is mandatory and customise the error message that will be displayed . | 45 | 20 |
19,071 | private boolean hasInputWithValue ( ) { // Visit all children of the fieldset of type Input AbstractVisitorWithResult < Boolean > visitor = new AbstractVisitorWithResult < Boolean > ( ) { @ Override public WComponentTreeVisitor . VisitorResult visit ( final WComponent comp ) { // Check if the component is an Input and has a value if ( comp instanceof Input && ! ( ( Input ) comp ) . isEmpty ( ) ) { setResult ( true ) ; return VisitorResult . ABORT ; } return VisitorResult . CONTINUE ; } } ; visitor . setResult ( false ) ; TreeUtil . traverseVisible ( this , visitor ) ; return visitor . getResult ( ) ; } | Checks at least one input component has a value . | 152 | 11 |
19,072 | private static void processJsonToTree ( final TreeItemIdNode parentNode , final JsonObject json ) { String id = json . getAsJsonPrimitive ( "id" ) . getAsString ( ) ; JsonPrimitive expandableJson = json . getAsJsonPrimitive ( "expandable" ) ; TreeItemIdNode node = new TreeItemIdNode ( id ) ; if ( expandableJson != null && expandableJson . getAsBoolean ( ) ) { node . setHasChildren ( true ) ; } parentNode . addChild ( node ) ; JsonArray children = json . getAsJsonArray ( "items" ) ; if ( children != null ) { for ( int i = 0 ; i < children . size ( ) ; i ++ ) { JsonObject child = children . get ( i ) . getAsJsonObject ( ) ; processJsonToTree ( node , child ) ; } } } | Iterate over the JSON objects to create the tree structure . | 206 | 12 |
19,073 | public R fetchQuery ( String path , String properties ) { query . fetchQuery ( path , properties ) ; return root ; } | Specify a path and properties to load using a query join . | 26 | 13 |
19,074 | private R pushExprList ( ExpressionList < T > list ) { if ( textMode ) { textStack . push ( list ) ; } else { whereStack . push ( list ) ; } return root ; } | Push the expression list onto the appropriate stack . | 45 | 9 |
19,075 | protected ExpressionList < T > peekExprList ( ) { if ( textMode ) { // return the current text expression list return _peekText ( ) ; } if ( whereStack == null ) { whereStack = new ArrayStack <> ( ) ; whereStack . push ( query . where ( ) ) ; } // return the current expression list return whereStack . peek ( ) ; } | Return the current expression list that expressions should be added to . | 82 | 12 |
19,076 | public ExpressionBuilder notEquals ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . NOT_EQUAL , trigger , compare ) ; appendExpression ( exp ) ; return this ; } | Appends a not equals test to the condition . | 53 | 10 |
19,077 | public ExpressionBuilder lessThan ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . LESS_THAN , trigger , compare ) ; appendExpression ( exp ) ; return this ; } | Appends a less than test to the condition . | 53 | 10 |
19,078 | public ExpressionBuilder lessThanOrEquals ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . LESS_THAN_OR_EQUAL , trigger , compare ) ; appendExpression ( exp ) ; return this ; } | Appends a less than or equals test to the condition . | 62 | 12 |
19,079 | public ExpressionBuilder greaterThan ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . GREATER_THAN , trigger , compare ) ; appendExpression ( exp ) ; return this ; } | Appends a greater than test to the condition . | 53 | 10 |
19,080 | public ExpressionBuilder greaterThanOrEquals ( final SubordinateTrigger trigger , final Object compare ) { BooleanExpression exp = new CompareExpression ( CompareType . GREATER_THAN_OR_EQUAL , trigger , compare ) ; appendExpression ( exp ) ; return this ; } | Appends a greater than or equals test to the condition . | 62 | 12 |
19,081 | public ExpressionBuilder matches ( final SubordinateTrigger trigger , final String compare ) { BooleanExpression exp = new CompareExpression ( CompareType . MATCH , trigger , compare ) ; appendExpression ( exp ) ; return this ; } | Appends a matches test to the condition . | 48 | 9 |
19,082 | public ExpressionBuilder or ( ) { GroupExpression lastGroupExpression = stack . isEmpty ( ) ? null : stack . peek ( ) ; if ( lhsExpression == null ) { throw new SyntaxException ( "Syntax exception: OR missing LHS operand" ) ; } else if ( lastGroupExpression == null ) { GroupExpression or = new GroupExpression ( GroupExpression . Type . OR ) ; or . add ( lhsExpression ) ; stack . push ( or ) ; expression . setExpression ( or ) ; lhsExpression = null ; } else if ( lastGroupExpression . getType ( ) . equals ( GroupExpression . Type . OR ) ) { // Keep using the existing OR lhsExpression = null ; return this ; } else if ( lastGroupExpression . getType ( ) . equals ( GroupExpression . Type . AND ) ) { // AND takes precedence over OR, so we wrap the AND // by removing it from any parent expressions and inserting the OR in its place GroupExpression and = stack . pop ( ) ; GroupExpression or = new GroupExpression ( GroupExpression . Type . OR ) ; if ( stack . isEmpty ( ) ) { expression . setExpression ( or ) ; or . add ( and ) ; } else { // need to get at the parent GroupExpression parent = stack . pop ( ) ; parent . remove ( and ) ; parent . add ( or ) ; or . add ( and ) ; } stack . push ( and ) ; stack . push ( or ) ; lhsExpression = null ; } return this ; } | Appends an OR expression to the RHS of the expression . The current RHS of the expression must be an Operand . | 344 | 26 |
19,083 | public ExpressionBuilder and ( ) { GroupExpression lastGroupExpression = stack . isEmpty ( ) ? null : stack . peek ( ) ; if ( lhsExpression == null ) { throw new SyntaxException ( "Syntax exception: AND missing LHS operand" ) ; } else if ( lastGroupExpression == null ) { GroupExpression and = new GroupExpression ( GroupExpression . Type . AND ) ; and . add ( lhsExpression ) ; stack . push ( and ) ; expression . setExpression ( and ) ; lhsExpression = null ; } else if ( lastGroupExpression . getType ( ) . equals ( GroupExpression . Type . AND ) ) { // Keep using the existing AND lhsExpression = null ; return this ; } else if ( lastGroupExpression . getType ( ) . equals ( GroupExpression . Type . OR ) ) { // AND takes precedence over OR, so we steal the OR's RHS GroupExpression or = lastGroupExpression ; GroupExpression and = new GroupExpression ( GroupExpression . Type . AND ) ; or . remove ( lhsExpression ) ; and . add ( lhsExpression ) ; or . add ( and ) ; stack . push ( and ) ; lhsExpression = null ; } return this ; } | Appends an AND expression to the RHS of the expression . The current RHS of the expression must be an Operand . | 282 | 26 |
19,084 | public ExpressionBuilder not ( final ExpressionBuilder exp ) { // Note - NOT Expressions are not added to the stack (like the other group expressions AND and OR) and are // treated the same as a "compare" expression. // It is expected a NOT Expression is used by itself or with an AND or NOT. GroupExpression not = new GroupExpression ( Type . NOT ) ; not . add ( exp . expression . getExpression ( ) ) ; appendExpression ( not ) ; return this ; } | Appends a NOT expression to this expression . | 106 | 9 |
19,085 | private void appendExpression ( final BooleanExpression newExpression ) { if ( lhsExpression != null ) { throw new SyntaxException ( "Syntax exception: use AND or OR to join expressions" ) ; } lhsExpression = newExpression ; GroupExpression currentExpression = stack . isEmpty ( ) ? null : stack . peek ( ) ; if ( currentExpression == null ) { this . expression . setExpression ( newExpression ) ; } else { currentExpression . add ( newExpression ) ; } } | Appends the given expression to this expression . | 116 | 9 |
19,086 | public boolean validate ( ) { try { BooleanExpression built = expression . getExpression ( ) ; if ( built == null ) { // nothing to evaluate. return false ; } // First check the nesting (an expression must not contain itself) checkNesting ( built , new ArrayList < BooleanExpression > ( ) ) ; // If the expression evaluates correctly, the syntax is correct. built . evaluate ( ) ; } catch ( Exception e ) { LogFactory . getLog ( getClass ( ) ) . warn ( "Invalid expression: " + e . getMessage ( ) ) ; return false ; } return true ; } | Determines whether the current expression is syntactically correct . | 129 | 13 |
19,087 | private static void checkNesting ( final BooleanExpression expression , final List < BooleanExpression > visitedExpressions ) { if ( visitedExpressions . contains ( expression ) ) { // Unfortunately, we can't give much more information - even calling toString() will overflow the stack. throw new SyntaxException ( "An expression can not contain itself." ) ; } visitedExpressions . add ( expression ) ; if ( expression instanceof GroupExpression ) { GroupExpression group = ( GroupExpression ) expression ; for ( BooleanExpression operand : group . getOperands ( ) ) { checkNesting ( operand , visitedExpressions ) ; } } } | Checks nesting of expressions to ensure we don t end up in an infinite recursive loop during evaluation . | 138 | 20 |
19,088 | private WFieldSet getDropDownControls ( ) { WFieldSet fieldSet = new WFieldSet ( "Drop down configuration" ) ; WFieldLayout layout = new WFieldLayout ( ) ; layout . setLabelWidth ( 25 ) ; fieldSet . add ( layout ) ; rbsDDType . setButtonLayout ( WRadioButtonSelect . LAYOUT_FLAT ) ; rbsDDType . setSelected ( WDropdown . DropdownType . NATIVE ) ; rbsDDType . setFrameless ( true ) ; layout . addField ( "Dropdown Type" , rbsDDType ) ; nfWidth . setMinValue ( 0 ) ; nfWidth . setDecimalPlaces ( 0 ) ; layout . addField ( "Width" , nfWidth ) ; layout . addField ( "ToolTip" , tfToolTip ) ; layout . addField ( "Include null option" , cbNullOption ) ; rgDefaultOption . setButtonLayout ( WRadioButtonSelect . LAYOUT_COLUMNS ) ; rgDefaultOption . setButtonColumns ( 2 ) ; rgDefaultOption . setSelected ( NONE ) ; rgDefaultOption . setFrameless ( true ) ; layout . addField ( "Default Option" , rgDefaultOption ) ; layout . addField ( "Action on change" , cbActionOnChange ) ; layout . addField ( "Ajax" , cbAjax ) ; WField subField = layout . addField ( "Subordinate" , cbSubordinate ) ; //.getLabel().setHint("Does not work with Dropdown Type COMBO"); layout . addField ( "Submit on change" , cbSubmitOnChange ) ; layout . addField ( "Visible" , cbVisible ) ; layout . addField ( "Disabled" , cbDisabled ) ; // Apply Button WButton apply = new WButton ( "Apply" ) ; fieldSet . add ( apply ) ; WSubordinateControl subSubControl = new WSubordinateControl ( ) ; Rule rule = new Rule ( ) ; subSubControl . addRule ( rule ) ; rule . setCondition ( new Equal ( rbsDDType , WDropdown . DropdownType . COMBO ) ) ; rule . addActionOnTrue ( new Disable ( subField ) ) ; rule . addActionOnFalse ( new Enable ( subField ) ) ; fieldSet . add ( subSubControl ) ; apply . setAction ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { applySettings ( ) ; } } ) ; return fieldSet ; } | build the drop down controls . | 563 | 6 |
19,089 | private void applySettings ( ) { container . reset ( ) ; infoPanel . reset ( ) ; // create the list of options. List < String > options = new ArrayList <> ( Arrays . asList ( OPTIONS_ARRAY ) ) ; if ( cbNullOption . isSelected ( ) ) { options . add ( 0 , "" ) ; } // create the dropdown. final WDropdown dropdown = new WDropdown ( options ) ; // set the dropdown type. dropdown . setType ( ( DropdownType ) rbsDDType . getSelected ( ) ) ; // set the selected option if applicable. String selected = ( String ) rgDefaultOption . getSelected ( ) ; if ( selected != null && ! NONE . equals ( selected ) ) { dropdown . setSelected ( selected ) ; } // set the width. if ( nfWidth . getValue ( ) != null ) { dropdown . setOptionWidth ( nfWidth . getValue ( ) . intValue ( ) ) ; } // set the tool tip. if ( tfToolTip . getText ( ) != null && tfToolTip . getText ( ) . length ( ) > 0 ) { dropdown . setToolTip ( tfToolTip . getText ( ) ) ; } // set misc options. dropdown . setVisible ( cbVisible . isSelected ( ) ) ; dropdown . setDisabled ( cbDisabled . isSelected ( ) ) ; // add the action for action on change, ajax and subordinate. if ( cbActionOnChange . isSelected ( ) || cbAjax . isSelected ( ) || cbSubmitOnChange . isSelected ( ) ) { final WStyledText info = new WStyledText ( ) ; info . setWhitespaceMode ( WhitespaceMode . PRESERVE ) ; infoPanel . add ( info ) ; dropdown . setActionOnChange ( new Action ( ) { @ Override public void execute ( final ActionEvent event ) { String selectedOption = ( String ) dropdown . getSelected ( ) ; info . setText ( selectedOption ) ; } } ) ; } // this has to be below the set action on change so it is // not over written. dropdown . setSubmitOnChange ( cbSubmitOnChange . isSelected ( ) ) ; // add the ajax target. if ( cbAjax . isSelected ( ) ) { WAjaxControl update = new WAjaxControl ( dropdown ) ; update . addTarget ( infoPanel ) ; container . add ( update ) ; } // add the subordinate stuff. if ( rbsDDType . getValue ( ) == WDropdown . DropdownType . COMBO ) { //This is to work around a WComponent Subordinate logic flaw. cbSubordinate . setSelected ( false ) ; } if ( cbSubordinate . isSelected ( ) ) { WComponentGroup < SubordinateTarget > group = new WComponentGroup <> ( ) ; container . add ( group ) ; WSubordinateControl control = new WSubordinateControl ( ) ; container . add ( control ) ; for ( String option : OPTIONS_ARRAY ) { buildSubordinatePanel ( dropdown , option , group , control ) ; } // add a rule for none selected. Rule rule = new Rule ( ) ; control . addRule ( rule ) ; rule . setCondition ( new Equal ( dropdown , "" ) ) ; rule . addActionOnTrue ( new Hide ( group ) ) ; } WFieldLayout flay = new WFieldLayout ( ) ; flay . setLabelWidth ( 25 ) ; container . add ( flay ) ; flay . addField ( "Configured dropdown" , dropdown ) ; flay . addField ( ( WLabel ) null , new WButton ( "Submit" ) ) ; } | Apply the settings from the control table to the drop down . | 834 | 12 |
19,090 | private void buildSubordinatePanel ( final WDropdown dropdown , final String value , final WComponentGroup < SubordinateTarget > group , final WSubordinateControl control ) { // create the panel. WPanel panel = new WPanel ( ) ; WStyledText subordinateInfo = new WStyledText ( ) ; subordinateInfo . setWhitespaceMode ( WhitespaceMode . PRESERVE ) ; subordinateInfo . setText ( value + " - Subordinate" ) ; panel . add ( subordinateInfo ) ; // add the panel to the screen and group. infoPanel . add ( panel ) ; group . addToGroup ( panel ) ; // create the rule Rule rule = new Rule ( ) ; control . addRule ( rule ) ; rule . setCondition ( new Equal ( dropdown , value ) ) ; rule . addActionOnTrue ( new ShowInGroup ( panel , group ) ) ; } | Builds a panel for the subordinate control including the rule for that particular option . | 189 | 16 |
19,091 | @ Override public void setDateHeader ( final String name , final long value ) { headers . put ( name , String . valueOf ( value ) ) ; } | Sets a date header . | 34 | 6 |
19,092 | @ Override public void setIntHeader ( final String name , final int value ) { headers . put ( name , String . valueOf ( value ) ) ; } | Sets an integer header . | 34 | 6 |
19,093 | @ Override public void execute ( ) { if ( target instanceof WComponentGroup < ? > ) { for ( WComponent component : ( ( WComponentGroup < WComponent > ) target ) . getComponents ( ) ) { if ( component instanceof SubordinateTarget ) { applyAction ( ( SubordinateTarget ) component , value ) ; } } } else { // Leaf. applyAction ( target , value ) ; } } | Execute the action . | 89 | 5 |
19,094 | @ Override public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WStyledText text = ( WStyledText ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; String textString = text . getText ( ) ; if ( textString != null && textString . length ( ) > 0 ) { xml . appendTagOpen ( "ui:text" ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; switch ( text . getType ( ) ) { case EMPHASISED : xml . appendAttribute ( "type" , "emphasised" ) ; break ; case HIGH_PRIORITY : xml . appendAttribute ( "type" , "highPriority" ) ; break ; case LOW_PRIORITY : xml . appendAttribute ( "type" , "lowPriority" ) ; break ; case MEDIUM_PRIORITY : xml . appendAttribute ( "type" , "mediumPriority" ) ; break ; case ACTIVE_INDICATOR : xml . appendAttribute ( "type" , "activeIndicator" ) ; break ; case MATCH_INDICATOR : xml . appendAttribute ( "type" , "matchIndicator" ) ; break ; case INSERT : xml . appendAttribute ( "type" , "insert" ) ; break ; case DELETE : xml . appendAttribute ( "type" , "delete" ) ; break ; case MANDATORY_INDICATOR : xml . appendAttribute ( "type" , "mandatoryIndicator" ) ; break ; case PLAIN : default : xml . appendAttribute ( "type" , "plain" ) ; break ; } switch ( text . getWhitespaceMode ( ) ) { case PARAGRAPHS : xml . appendAttribute ( "space" , "paragraphs" ) ; break ; case PRESERVE : xml . appendAttribute ( "space" , "preserve" ) ; break ; case DEFAULT : break ; default : throw new IllegalArgumentException ( "Unknown white space mode: " + text . getWhitespaceMode ( ) ) ; } xml . appendClose ( ) ; if ( WStyledText . WhitespaceMode . PARAGRAPHS . equals ( text . getWhitespaceMode ( ) ) ) { textString = text . isEncodeText ( ) ? WebUtilities . encode ( textString ) : HtmlToXMLUtil . unescapeToXML ( textString ) ; writeParagraphs ( textString , xml ) ; } else { xml . append ( textString , text . isEncodeText ( ) ) ; } xml . appendEndTag ( "ui:text" ) ; } } | Paints the given WStyledText . | 587 | 9 |
19,095 | private static void writeParagraphs ( final String text , final XmlStringBuilder xml ) { if ( ! Util . empty ( text ) ) { int start = 0 ; int end = text . length ( ) - 1 ; // Set the start index to the first non-linebreak, so we don't emit leading ui:nl tags for ( ; start < end ; start ++ ) { char c = text . charAt ( start ) ; if ( c != ' ' && c != ' ' ) { break ; } } // Set the end index to the last non-linebreak, so we don't emit trailing ui:nl tags for ( ; start < end ; end -- ) { char c = text . charAt ( end ) ; if ( c != ' ' && c != ' ' ) { break ; } } char lastChar = 0 ; for ( int i = start ; i <= end ; i ++ ) { char c = text . charAt ( i ) ; if ( c == ' ' || c == ' ' ) { if ( lastChar != 0 ) { xml . write ( "<ui:nl/>" ) ; } lastChar = 0 ; } else { xml . write ( c ) ; lastChar = c ; } } } } | Writes out paragraph delimited content . | 264 | 8 |
19,096 | public static void write ( final PrintWriter writer , final UicStats stats ) { writer . println ( "<dl>" ) ; writer . print ( "<dt>Total root wcomponents found in UIC</dt>" ) ; writer . println ( "<dd>" + stats . getRootWCs ( ) . size ( ) + "</dd>" ) ; writer . print ( "<dt>Size of UIC (by serialization)</dt>" ) ; writer . println ( "<dd>" + stats . getOverallSerializedSize ( ) + "</dd>" ) ; writer . print ( "<dt>UI</dt>" ) ; writer . println ( "<dd>" + stats . getUI ( ) . getClass ( ) . getName ( ) + "</dd>" ) ; writer . println ( "</dl>" ) ; for ( Iterator < WComponent > it = stats . getWCsAnalysed ( ) ; it . hasNext ( ) ; ) { WComponent comp = it . next ( ) ; Map < WComponent , UicStats . Stat > treeStats = stats . getWCTreeStats ( comp ) ; writer . println ( "<br /><strong>Analysed component:</strong> " + comp ) ; writer . println ( "<br /><strong>Number of components in tree:</strong> " + treeStats . size ( ) ) ; writeHeader ( writer ) ; writeProfileForTree ( writer , treeStats ) ; writeFooter ( writer ) ; } } | Writes out the given statistics in HTML format . | 313 | 10 |
19,097 | private static void writeProfileForTree ( final PrintWriter writer , final Map < WComponent , UicStats . Stat > treeStats ) { // Copy all the stats into a list so we can sort and cull. List < UicStats . Stat > statList = new ArrayList <> ( treeStats . values ( ) ) ; Comparator < UicStats . Stat > comparator = new Comparator < UicStats . Stat > ( ) { @ Override public int compare ( final UicStats . Stat stat1 , final UicStats . Stat stat2 ) { if ( stat1 . getModelState ( ) > stat2 . getModelState ( ) ) { return - 1 ; } else if ( stat1 . getModelState ( ) < stat2 . getModelState ( ) ) { return 1 ; } else { int diff = stat1 . getClassName ( ) . compareTo ( stat2 . getClassName ( ) ) ; if ( diff == 0 ) { diff = stat1 . getName ( ) . compareTo ( stat2 . getName ( ) ) ; } return diff ; } } } ; Collections . sort ( statList , comparator ) ; for ( int i = 0 ; i < statList . size ( ) ; i ++ ) { UicStats . Stat stat = statList . get ( i ) ; writeRow ( writer , stat ) ; } } | Writes the stats for a single component . | 292 | 9 |
19,098 | private static void writeHeader ( final PrintWriter writer ) { writer . println ( "<table>" ) ; writer . println ( "<thead>" ) ; writer . print ( "<tr>" ) ; writer . print ( "<th>Class</th>" ) ; writer . print ( "<th>Model</th>" ) ; writer . print ( "<th>Size</th>" ) ; writer . print ( "<th>Ref.</th>" ) ; writer . print ( "<th>Name</th>" ) ; writer . print ( "<th>Comment</th>" ) ; writer . println ( "</tr>" ) ; writer . println ( "</thead>" ) ; } | Writes the stats header HTML . | 140 | 7 |
19,099 | private static void writeRow ( final PrintWriter writer , final UicStats . Stat stat ) { writer . print ( "<tr>" ) ; writer . print ( "<td>" + stat . getClassName ( ) + "</td>" ) ; writer . print ( "<td>" + stat . getModelStateAsString ( ) + "</td>" ) ; if ( stat . getSerializedSize ( ) > 0 ) { writer . print ( "<td>" + stat . getSerializedSize ( ) + "</td>" ) ; } else { writer . print ( "<td> </td>" ) ; } writer . print ( "<td>" + stat . getRef ( ) + "</td>" ) ; writer . print ( "<td>" + stat . getName ( ) + "</td>" ) ; if ( stat . getComment ( ) == null ) { writer . print ( "<td> </td>" ) ; } else { writer . print ( "<td>" + stat . getComment ( ) + "</td>" ) ; } writer . println ( "</tr>" ) ; } | Writes a row containing a single stat . | 238 | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.