idx int64 0 165k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
18,400 | @ SuppressWarnings ( "unchecked" ) private void loadServlets ( Map < String , ServletConfiguration > servlets , Environment environment ) throws ClassNotFoundException { if ( servlets != null ) { for ( Map . Entry < String , ServletConfiguration > servletEntry : servlets . entrySet ( ) ) { ServletConfiguration servlet = servletEntry . getValue ( ) ; ServletHolder servletHolder = new ServletHolder ( ( Class < ? extends Servlet > ) Class . forName ( servlet . getClazz ( ) ) ) ; servletHolder . setName ( servletEntry . getKey ( ) ) ; if ( servlet . getParam ( ) != null ) { for ( Map . Entry < String , String > entry : servlet . getParam ( ) . entrySet ( ) ) { servletHolder . setInitParameter ( entry . getKey ( ) , entry . getValue ( ) ) ; } } environment . getApplicationContext ( ) . addServlet ( servletHolder , servlet . getUrl ( ) ) ; } } } | Load all servlets . |
18,401 | private String getPart ( int pos ) { String value = this . getValue ( ) ; if ( value == null ) { return null ; } String [ ] parts = value . split ( "/" ) ; return parts . length >= pos + 1 ? parts [ pos ] : null ; } | Extracts the given part from the unique identifier . |
18,402 | public NeedleRule withOuter ( final MethodRule rule ) { if ( rule instanceof InjectionProvider ) { addInjectionProvider ( ( InjectionProvider < ? > ) rule ) ; } methodRuleChain . add ( 0 , rule ) ; return this ; } | Encloses the added rule . |
18,403 | private List < String > buildCommand ( ) { List < String > command = new ArrayList < String > ( ) ; command . add ( cmd ) ; command . add ( "thin" ) ; command . add ( "--sourceAppPath=" + getSourceAppPath ( ) ) ; command . add ( "--targetLibCachePath=" + getTargetLibCachePath ( ) ) ; command . add ( "--targetThinAppPath=" + getTargetThinAppPath ( ) ) ; if ( getParentLibCachePath ( ) != null ) { command . add ( "--parentLibCachePath=" + getParentLibCachePath ( ) ) ; } return command ; } | Build up a command string to launch in new process |
18,404 | @ SuppressWarnings ( "unchecked" ) public < X > X resetToNice ( final Object mock ) { EasyMock . resetToNice ( mock ) ; return ( X ) mock ; } | Resets the given mock object and turns them to a mock with nice behavior . For details see the EasyMock documentation . |
18,405 | @ SuppressWarnings ( "unchecked" ) public < X > X resetToStrict ( final Object mock ) { EasyMock . resetToStrict ( mock ) ; return ( X ) mock ; } | Resets the given mock object and turns them to a mock with strict behavior . For details see the EasyMock documentation . |
18,406 | @ SuppressWarnings ( "unchecked" ) public < X > X resetToDefault ( final Object mock ) { EasyMock . resetToDefault ( mock ) ; return ( X ) mock ; } | Resets the given mock object and turns them to a mock with default behavior . For details see the EasyMock documentation . |
18,407 | protected void deleteContent ( final List < String > tables , final Statement statement ) throws SQLException { final ArrayList < String > tempTables = new ArrayList < String > ( tables ) ; while ( ! tempTables . isEmpty ( ) ) { final int sizeBefore = tempTables . size ( ) ; for ( final ListIterator < String > iterator = tempTables . listIterator ( ) ; iterator . hasNext ( ) ; ) { final String table = iterator . next ( ) ; try { statement . executeUpdate ( "DELETE FROM " + table ) ; iterator . remove ( ) ; } catch ( final SQLException exc ) { LOG . warn ( "Ignored exception: " + exc . getMessage ( ) + ". WILL RETRY." ) ; } } if ( tempTables . size ( ) == sizeBefore ) { throw new AssertionError ( "unable to clean tables " + tempTables ) ; } } } | Deletes all contents from the given tables . |
18,408 | private List < String > initCommand ( ) { List < String > command = new ArrayList < String > ( ) ; command . add ( cmd ) ; command . add ( "install" ) ; if ( acceptLicense ) { command . add ( "--acceptLicense" ) ; } else { command . add ( "--viewLicenseAgreement" ) ; } if ( to != null ) { command . add ( "--to=" + to ) ; } if ( from != null ) { command . add ( "--from=" + from ) ; } return command ; } | Generate a String list containing all the parameter for the command . |
18,409 | private < T extends XSString > T createXSString ( Class < T > clazz , String value ) { if ( value == null ) { return null ; } QName elementName = null ; String localName = null ; try { elementName = ( QName ) clazz . getDeclaredField ( "DEFAULT_ELEMENT_NAME" ) . get ( null ) ; localName = ( String ) clazz . getDeclaredField ( "DEFAULT_ELEMENT_LOCAL_NAME" ) . get ( null ) ; } catch ( NoSuchFieldException | IllegalArgumentException | IllegalAccessException | SecurityException e ) { throw new RuntimeException ( e ) ; } XMLObjectBuilder < ? extends XMLObject > builder = XMLObjectProviderRegistrySupport . getBuilderFactory ( ) . getBuilder ( elementName ) ; Object object = builder . buildObject ( new QName ( this . getElementQName ( ) . getNamespaceURI ( ) , localName , this . getElementQName ( ) . getPrefix ( ) ) ) ; T xsstring = clazz . cast ( object ) ; xsstring . setValue ( value ) ; return xsstring ; } | Utility method for creating an OpenSAML object given its type and assigns the value . |
18,410 | public Annotation [ ] getAnnotations ( ) { final Annotation [ ] accessibleObjectAnnotations = accessibleObject . getAnnotations ( ) ; final Annotation [ ] annotations = new Annotation [ accessibleObjectAnnotations . length + parameterAnnotations . length ] ; System . arraycopy ( accessibleObjectAnnotations , 0 , annotations , 0 , accessibleObjectAnnotations . length ) ; System . arraycopy ( parameterAnnotations , 0 , annotations , accessibleObjectAnnotations . length , parameterAnnotations . length ) ; return annotations ; } | Returns an array of all annotations present on the injection target . |
18,411 | public static final MetadataServiceListVersion valueOf ( final int majorVersion , final int minorVersion ) { if ( majorVersion == 1 && minorVersion == 0 ) { return MetadataServiceListVersion . VERSION_10 ; } return new MetadataServiceListVersion ( majorVersion , minorVersion ) ; } | Gets the version given the major and minor version number . |
18,412 | public static final MetadataServiceListVersion valueOf ( String version ) { String [ ] components = version . split ( "\\." ) ; return valueOf ( Integer . valueOf ( components [ 0 ] ) , Integer . valueOf ( components [ 1 ] ) ) ; } | Gets the version for a given version string such as 1 . 0 . |
18,413 | public static < T > InjectionProvider < T > providerForQualifiedInstance ( final Class < ? extends Annotation > qualifier , final T instance ) { return new QualifiedInstanceInjectionProvider < T > ( qualifier , instance ) ; } | InjectionProvider that provides a singleton instance of type T for every injection point that is annotated with the given qualifier . |
18,414 | private static Set < InjectionProvider < ? > > newProviderSet ( final InjectionProvider < ? > ... providers ) { final Set < InjectionProvider < ? > > result = new LinkedHashSet < InjectionProvider < ? > > ( ) ; if ( providers != null && providers . length > 0 ) { for ( final InjectionProvider < ? > provider : providers ) { result . add ( provider ) ; } } return result ; } | Creates a new Set . |
18,415 | private static InjectionProviderInstancesSupplier mergeSuppliers ( final InjectionProviderInstancesSupplier ... suppliers ) { final Set < InjectionProvider < ? > > result = new LinkedHashSet < InjectionProvider < ? > > ( ) ; if ( suppliers != null && suppliers . length > 0 ) { for ( final InjectionProviderInstancesSupplier supplier : suppliers ) { result . addAll ( supplier . get ( ) ) ; } } return new InjectionProviderInstancesSupplier ( ) { public Set < InjectionProvider < ? > > get ( ) { return result ; } } ; } | Creates new supplier containing all providers in a new set . |
18,416 | public static InjectionProvider < ? > [ ] providersForInstancesSuppliers ( final InjectionProviderInstancesSupplier ... suppliers ) { final InjectionProviderInstancesSupplier supplier = mergeSuppliers ( suppliers ) ; return supplier . get ( ) . toArray ( new InjectionProvider < ? > [ supplier . get ( ) . size ( ) ] ) ; } | Create array of providers from given suppliers . |
18,417 | public static InjectionProvider < ? > [ ] providersToArray ( final Collection < InjectionProvider < ? > > providers ) { return providers == null ? new InjectionProvider < ? > [ 0 ] : providers . toArray ( new InjectionProvider < ? > [ providers . size ( ) ] ) ; } | Create array of InjectionProviders for given collection . |
18,418 | public final < T > T saveObject ( final T obj ) throws Exception { return executeInTransaction ( new Runnable < T > ( ) { public T run ( final EntityManager entityManager ) { return persist ( obj , entityManager ) ; } } ) ; } | Saves the given object in the database . |
18,419 | public final < T > T loadObject ( final Class < T > clazz , final Object id ) throws Exception { return executeInTransaction ( new Runnable < T > ( ) { public T run ( final EntityManager entityManager ) { return loadObject ( entityManager , clazz , id ) ; } } ) ; } | Finds and returns the object of the given id in the persistence context . |
18,420 | public final < T > List < T > loadAllObjects ( final Class < T > clazz ) throws Exception { final Entity entityAnnotation = clazz . getAnnotation ( Entity . class ) ; if ( entityAnnotation == null ) { throw new IllegalArgumentException ( "Unknown entity: " + clazz . getName ( ) ) ; } return executeInTransaction ( new Runnable < List < T > > ( ) { @ SuppressWarnings ( "unchecked" ) public List < T > run ( final EntityManager entityManager ) { final String fromEntity = entityAnnotation . name ( ) . isEmpty ( ) ? clazz . getSimpleName ( ) : entityAnnotation . name ( ) ; final String alias = fromEntity . toLowerCase ( ) ; return entityManager . createQuery ( "SELECT " + alias + " FROM " + fromEntity + " " + alias ) . getResultList ( ) ; } } ) ; } | Returns all objects of the given class in persistence context . |
18,421 | public XMLObject unmarshall ( Element domElement ) throws UnmarshallingException { Document newDocument = null ; Node childNode = domElement . getFirstChild ( ) ; while ( childNode != null ) { if ( childNode . getNodeType ( ) != Node . TEXT_NODE ) { log . info ( "Ignoring node {} - it is not a text node" , childNode . getNodeName ( ) ) ; } else { newDocument = parseContents ( ( Text ) childNode , domElement ) ; if ( newDocument != null ) { break ; } } childNode = childNode . getNextSibling ( ) ; } return super . unmarshall ( newDocument != null ? newDocument . getDocumentElement ( ) : domElement ) ; } | Special handling of the Base64 encoded value that represents the address elements . |
18,422 | private static Map < String , String > getNamespaceBindings ( Element element ) { Map < String , String > namespaceMap = new HashMap < String , String > ( ) ; getNamespaceBindings ( element , namespaceMap ) ; return namespaceMap ; } | Returns a map holding all registered namespace bindings where the key is the qualified name of the namespace and the value part is the URI . |
18,423 | public String waitForStringInLog ( String regexp , long timeout , File outputFile ) { int waited = 0 ; final int waitIncrement = 500 ; log ( MessageFormat . format ( messages . getString ( "info.search.string" ) , regexp , outputFile . getAbsolutePath ( ) , timeout / 1000 ) ) ; try { while ( waited <= timeout ) { String string = findStringInFile ( regexp , outputFile ) ; if ( string == null ) { try { Thread . sleep ( waitIncrement ) ; } catch ( InterruptedException e ) { } waited += waitIncrement ; } else { return string ; } } log ( MessageFormat . format ( messages . getString ( "error.serch.string.timeout" ) , regexp , outputFile . getAbsolutePath ( ) ) ) ; } catch ( Exception e ) { throw new BuildException ( e ) ; } return null ; } | Check for a number of strings in a potentially remote file |
18,424 | public void bootstrap ( ) throws ConfigurationException { XMLConfigurator configurator = new XMLConfigurator ( ) ; for ( String config : configs ) { log . debug ( "Loading XMLTooling configuration " + config ) ; configurator . load ( Configuration . class . getResourceAsStream ( config ) ) ; } } | Bootstrap method for this library . |
18,425 | public static InputStream loadResource ( final String resource ) throws FileNotFoundException { final boolean hasLeadingSlash = resource . startsWith ( "/" ) ; final String stripped = hasLeadingSlash ? resource . substring ( 1 ) : resource ; InputStream stream = null ; final ClassLoader classLoader = Thread . currentThread ( ) . getContextClassLoader ( ) ; if ( classLoader != null ) { stream = classLoader . getResourceAsStream ( resource ) ; if ( stream == null && hasLeadingSlash ) { stream = classLoader . getResourceAsStream ( stripped ) ; } } if ( stream == null ) { throw new FileNotFoundException ( "resource " + resource + " not found" ) ; } return stream ; } | Returns an input stream for reading the specified resource . |
18,426 | public OperationResult operate ( TestStep testStep ) { String testStepName = testStep . getLocator ( ) . getValue ( ) ; LogRecord log = LogRecord . info ( LOG , testStep , "script.execute" , testStepName ) ; current . backup ( ) ; TestScript testScript = dao . load ( new File ( pm . getPageScriptDir ( ) , testStepName ) , sheetName , false ) ; current . setTestScript ( testScript ) ; current . reset ( ) ; current . setCurrentIndex ( current . getCurrentIndex ( ) - 1 ) ; String caseNo = testStep . getValue ( ) ; if ( testScript . containsCaseNo ( caseNo ) ) { current . setCaseNo ( caseNo ) ; } else { String msg = MessageManager . getMessage ( "case.number.error" , caseNo ) + testScript . getCaseNoMap ( ) . keySet ( ) ; throw new TestException ( msg ) ; } current . setTestContextListener ( this ) ; return new OperationResult ( log ) ; } | OperationLog opelog ; |
18,427 | public OperationResult operate ( TestStep testStep ) { String value = testStep . getValue ( ) ; LogRecord record = LogRecord . info ( log , testStep , "test.step.execute" , value ) ; TestScript testScript = current . getTestScript ( ) ; int nextIndex = testScript . getIndexByScriptNo ( value ) - 1 ; current . setCurrentIndex ( nextIndex ) ; return new OperationResult ( record ) ; } | protected OperationLog opelog ; |
18,428 | private WMenu buildTreeMenu ( final WText selectedMenuText ) { WMenu menu = new WMenu ( WMenu . MenuType . TREE ) ; menu . setSelectMode ( SelectMode . SINGLE ) ; mapTreeHierarchy ( menu , createExampleHierarchy ( ) , selectedMenuText ) ; return menu ; } | Builds up a tree menu for inclusion in the example . |
18,429 | private void mapTreeHierarchy ( final WComponent currentComponent , final StringTreeNode currentNode , final WText selectedMenuText ) { if ( currentNode . isLeaf ( ) ) { WMenuItem menuItem = new WMenuItem ( currentNode . getData ( ) , new ExampleMenuAction ( selectedMenuText ) ) ; menuItem . setActionObject ( currentNode . getData ( ) ) ; if ( currentComponent instanceof WMenu ) { ( ( WMenu ) currentComponent ) . add ( menuItem ) ; } else { ( ( WSubMenu ) currentComponent ) . add ( menuItem ) ; } } else { WSubMenu subMenu = new WSubMenu ( currentNode . getData ( ) ) ; subMenu . setSelectMode ( SelectMode . SINGLE ) ; if ( currentComponent instanceof WMenu ) { ( ( WMenu ) currentComponent ) . add ( subMenu ) ; } else { ( ( WSubMenu ) currentComponent ) . add ( subMenu ) ; } if ( currentNode . getLevel ( ) < 2 ) { subMenu . setOpen ( true ) ; } for ( Iterator < TreeNode > i = currentNode . children ( ) ; i . hasNext ( ) ; ) { mapTreeHierarchy ( subMenu , ( StringTreeNode ) i . next ( ) , selectedMenuText ) ; } } } | Recursively maps a tree hierarchy to a hierarchical menu . |
18,430 | private static StringTreeNode createExampleHierarchy ( ) { StringTreeNode root = new StringTreeNode ( Object . class . getName ( ) ) ; Map < String , StringTreeNode > nodeMap = new HashMap < > ( ) ; nodeMap . put ( root . getData ( ) , root ) ; Class < ? > [ ] classes = new Class [ ] { WMenu . class , WMenuItem . class , WSubMenu . class , WMenuItemGroup . class , WText . class , WText . class } ; for ( Class < ? > clazz : classes ) { StringTreeNode childNode = new StringTreeNode ( clazz . getName ( ) ) ; nodeMap . put ( childNode . getData ( ) , childNode ) ; for ( Class < ? > parentClass = clazz . getSuperclass ( ) ; parentClass != null ; parentClass = parentClass . getSuperclass ( ) ) { StringTreeNode parentNode = nodeMap . get ( parentClass . getName ( ) ) ; if ( parentNode == null ) { parentNode = new StringTreeNode ( parentClass . getName ( ) ) ; nodeMap . put ( parentNode . getData ( ) , parentNode ) ; parentNode . add ( childNode ) ; childNode = parentNode ; } else { parentNode . add ( childNode ) ; break ; } } } return root ; } | Creates an example hierarchy showing the WMenu API . |
18,431 | public void addTerm ( final String term , final WComponent ... data ) { for ( WComponent component : data ) { if ( component != null ) { content . add ( component , term ) ; } } if ( getComponentsForTerm ( term ) . isEmpty ( ) ) { content . add ( new DefaultWComponent ( ) , term ) ; } } | Adds a term to this definition list . If there is an existing term the component is added to the list of data for the term . |
18,432 | public List < Duplet < String , ArrayList < WComponent > > > getTerms ( ) { Map < String , Duplet < String , ArrayList < WComponent > > > componentsByTerm = new HashMap < > ( ) ; List < Duplet < String , ArrayList < WComponent > > > result = new ArrayList < > ( ) ; List < WComponent > childList = content . getComponentModel ( ) . getChildren ( ) ; if ( childList != null ) { for ( int i = 0 ; i < childList . size ( ) ; i ++ ) { WComponent child = childList . get ( i ) ; String term = child . getTag ( ) ; Duplet < String , ArrayList < WComponent > > termComponents = componentsByTerm . get ( term ) ; if ( termComponents == null ) { termComponents = new Duplet < > ( term , new ArrayList < WComponent > ( ) ) ; componentsByTerm . put ( term , termComponents ) ; result . add ( termComponents ) ; } termComponents . getSecond ( ) . add ( child ) ; } } return result ; } | Groups a definition list s child components by their term for rendering . |
18,433 | private List < WComponent > getComponentsForTerm ( final String term ) { List < WComponent > childList = content . getComponentModel ( ) . getChildren ( ) ; List < WComponent > result = new ArrayList < > ( ) ; if ( childList != null ) { for ( int i = 0 ; i < childList . size ( ) ; i ++ ) { WComponent child = childList . get ( i ) ; if ( term . equals ( child . getTag ( ) ) ) { result . add ( child ) ; } } } return result ; } | Retrieves the components for the given term . |
18,434 | public void setArgs ( final Serializable ... args ) { this . args = args == null || args . length == 0 ? null : args ; } | Sets the message format arguments . |
18,435 | public int addSpaceContact ( int spaceId , ContactCreate create , boolean silent ) { return getResourceFactory ( ) . getApiResource ( "/contact/space/" + spaceId + "/" ) . queryParam ( "silent" , silent ? "1" : "0" ) . entity ( create , MediaType . APPLICATION_JSON_TYPE ) . post ( ContactCreateResponse . class ) . getId ( ) ; } | Adds a new contact to the given space . |
18,436 | public void updateSpaceContact ( int profileId , ContactUpdate update , boolean silent , boolean hook ) { getResourceFactory ( ) . getApiResource ( "/contact/" + profileId ) . queryParam ( "silent" , silent ? "1" : "0" ) . queryParam ( "hook" , hook ? "1" : "0" ) . entity ( update , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Updates the entire space contact . Only fields which have values specified will be updated . To delete the contents of a field pass an empty array for the value . |
18,437 | public < T , F , R > List < T > getContacts ( ProfileField < F , R > key , F value , Integer limit , Integer offset , ProfileType < T > type , ContactOrder order , ContactType contactType ) { WebResource resource = getResourceFactory ( ) . getApiResource ( "/contact/" ) ; return getContactsCommon ( resource , key , value , limit , offset , type , order , contactType ) ; } | Used to get a list of contacts for the user . |
18,438 | public void handleRequest ( final Request request ) { super . handleRequest ( request ) ; String targ = request . getParameter ( Environment . TARGET_ID ) ; boolean contentReqested = ( targ != null && targ . equals ( getTargetId ( ) ) ) ; if ( contentReqested ) { ContentEscape escape = new ContentEscape ( getImage ( ) ) ; escape . setCacheable ( ! Util . empty ( getCacheKey ( ) ) ) ; throw escape ; } } | When an img element is included in the html output of a page the browser will make a second request to get the image contents . The handleRequest method has been overridden to detect whether the request is the image content fetch request by looking for the parameter that we encode in the image url . |
18,439 | public void setImage ( final Image image ) { ImageModel model = getOrCreateComponentModel ( ) ; model . image = image ; model . imageUrl = null ; } | Sets the image . |
18,440 | public void setImageUrl ( final String imageUrl ) { ImageModel model = getOrCreateComponentModel ( ) ; model . imageUrl = imageUrl ; model . image = null ; } | Sets the image to an external URL . |
18,441 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WRadioButtonSelect rbSelect = ( WRadioButtonSelect ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; int cols = rbSelect . getButtonColumns ( ) ; boolean readOnly = rbSelect . isReadOnly ( ) ; xml . appendTagOpen ( "ui:radiobuttonselect" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , rbSelect . isHidden ( ) , "true" ) ; if ( readOnly ) { xml . appendAttribute ( "readOnly" , "true" ) ; } else { xml . appendOptionalAttribute ( "disabled" , rbSelect . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "required" , rbSelect . isMandatory ( ) , "true" ) ; xml . appendOptionalAttribute ( "submitOnChange" , rbSelect . isSubmitOnChange ( ) , "true" ) ; xml . appendOptionalAttribute ( "toolTip" , component . getToolTip ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , component . getAccessibleText ( ) ) ; } xml . appendOptionalAttribute ( "frameless" , rbSelect . isFrameless ( ) , "true" ) ; switch ( rbSelect . getButtonLayout ( ) ) { case COLUMNS : xml . appendAttribute ( "layout" , "column" ) ; xml . appendOptionalAttribute ( "layoutColumnCount" , cols > 0 , String . valueOf ( cols ) ) ; break ; case FLAT : xml . appendAttribute ( "layout" , "flat" ) ; break ; case STACKED : xml . appendAttribute ( "layout" , "stacked" ) ; break ; default : throw new SystemException ( "Unknown radio button layout: " + rbSelect . getButtonLayout ( ) ) ; } xml . appendClose ( ) ; List < ? > options = rbSelect . getOptions ( ) ; boolean renderSelectionsOnly = readOnly ; if ( options != null ) { int optionIndex = 0 ; Object selectedOption = rbSelect . getSelected ( ) ; for ( Object option : options ) { if ( option instanceof OptionGroup ) { throw new SystemException ( "Option groups not supported in WRadioButtonSelect." ) ; } else { renderOption ( rbSelect , option , optionIndex ++ , xml , selectedOption , renderSelectionsOnly ) ; } } } if ( ! readOnly ) { DiagnosticRenderUtil . renderDiagnostics ( rbSelect , renderContext ) ; } xml . appendEndTag ( "ui:radiobuttonselect" ) ; if ( rbSelect . isAjax ( ) ) { paintAjax ( rbSelect , xml ) ; } } | Paints the given WRadioButtonSelect . |
18,442 | private void paintAjax ( final WRadioButtonSelect rbSelect , final XmlStringBuilder xml ) { xml . appendTagOpen ( "ui:ajaxtrigger" ) ; xml . appendAttribute ( "triggerId" , rbSelect . getId ( ) ) ; xml . appendClose ( ) ; xml . appendTagOpen ( "ui:ajaxtargetid" ) ; xml . appendAttribute ( "targetId" , rbSelect . getAjaxTarget ( ) . getId ( ) ) ; xml . appendEnd ( ) ; xml . appendEndTag ( "ui:ajaxtrigger" ) ; } | Paints the AJAX information for the given WRadioButtonSelect . |
18,443 | public void setBean ( final Object bean ) { BeanAndProviderBoundComponentModel model = getOrCreateComponentModel ( ) ; model . setBean ( bean ) ; if ( getBeanProperty ( ) == null ) { setBeanProperty ( "." ) ; } removeBeanFromScratchMap ( ) ; } | Sets the bean associated with this WBeanComponent . This method of bean association is discouraged as the bean will be stored in the user s session . A better alternative is to provide a BeanProvider and a Bean Id . |
18,444 | public void setBeanId ( final Object beanId ) { BeanAndProviderBoundComponentModel model = getOrCreateComponentModel ( ) ; model . setBeanId ( beanId ) ; removeBeanFromScratchMap ( ) ; } | Sets the bean id associated with this WBeanComponent . |
18,445 | public void setBeanProperty ( final String propertyName ) { String currBeanProperty = getBeanProperty ( ) ; if ( ! Objects . equals ( propertyName , currBeanProperty ) ) { getOrCreateComponentModel ( ) . setBeanProperty ( propertyName ) ; } } | Sets the bean property that this component is interested in . The bean property is expressed in Jakarta PropertyUtils bean notation with an extension of . to indicate that the bean itself should be used . |
18,446 | protected void doUpdateBeanValue ( final Object value ) { String beanProperty = getBeanProperty ( ) ; if ( beanProperty != null && beanProperty . length ( ) > 0 && ! "." . equals ( beanProperty ) ) { Object bean = getBean ( ) ; if ( bean != null ) { try { Object beanValue = getBeanValue ( ) ; if ( ! Util . equals ( beanValue , value ) ) { PropertyUtils . setProperty ( bean , beanProperty , value ) ; } } catch ( Exception e ) { LOG . error ( "Failed to set bean property " + beanProperty + " on " + bean ) ; } } } } | Updates the bean value with the new value . |
18,447 | protected void removeBeanFromScratchMap ( ) { Map < Object , Object > scratchMap = getBeanScratchMap ( ) ; if ( scratchMap == null ) { return ; } scratchMap . remove ( SCRATCHMAP_BEAN_ID_KEY ) ; scratchMap . remove ( SCRATCHMAP_BEAN_OBJECT_KEY ) ; } | Remove the bean from the scratch maps . |
18,448 | public boolean isChanged ( ) { Object currentValue = getData ( ) ; Object sharedValue = ( ( BeanAndProviderBoundComponentModel ) getDefaultModel ( ) ) . getData ( ) ; if ( getBeanProperty ( ) != null ) { sharedValue = getBeanValue ( ) ; } return ! Util . equals ( currentValue , sharedValue ) ; } | Indicates whether this component s data has changed from the default value . |
18,449 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WTabSet tabSet = ( WTabSet ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:tabset" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendAttribute ( "type" , getTypeAsString ( tabSet . getType ( ) ) ) ; xml . appendOptionalAttribute ( "disabled" , tabSet . isDisabled ( ) , "true" ) ; xml . appendOptionalAttribute ( "hidden" , tabSet . isHidden ( ) , "true" ) ; xml . appendOptionalAttribute ( "contentHeight" , tabSet . getContentHeight ( ) ) ; xml . appendOptionalAttribute ( "showHeadOnly" , tabSet . isShowHeadOnly ( ) , "true" ) ; xml . appendOptionalAttribute ( "single" , TabSetType . ACCORDION . equals ( tabSet . getType ( ) ) && tabSet . isSingle ( ) , "true" ) ; if ( WTabSet . TabSetType . ACCORDION . equals ( tabSet . getType ( ) ) ) { xml . appendOptionalAttribute ( "groupName" , tabSet . getGroupName ( ) ) ; } xml . appendClose ( ) ; MarginRendererUtil . renderMargin ( tabSet , renderContext ) ; paintChildren ( tabSet , renderContext ) ; xml . appendEndTag ( "ui:tabset" ) ; } | Paints the given WTabSet . |
18,450 | private void createUI ( ) { add ( new WHeading ( HeadingLevel . H2 , "Contacts" ) ) ; add ( repeater ) ; createButtonBar ( ) ; createAddContactSubForm ( ) ; createPrintContactsSubForm ( ) ; } | Creates the example UI . |
18,451 | private void createButtonBar ( ) { WPanel buttonPanel = new WPanel ( WPanel . Type . FEATURE ) ; buttonPanel . setMargin ( new Margin ( Size . MEDIUM , null , Size . LARGE , null ) ) ; buttonPanel . setLayout ( new BorderLayout ( ) ) ; WButton updateButton = new WButton ( "Update" ) ; updateButton . setImage ( "/image/document-save-5.png" ) ; updateButton . setImagePosition ( WButton . ImagePosition . EAST ) ; buttonPanel . add ( updateButton , BorderLayout . EAST ) ; WButton resetButton = new WButton ( "Reset" ) ; resetButton . setImage ( "/image/edit-undo-8.png" ) ; resetButton . setImagePosition ( WButton . ImagePosition . WEST ) ; resetButton . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { repeater . setData ( fetchDataList ( ) ) ; } } ) ; buttonPanel . add ( resetButton , BorderLayout . WEST ) ; add ( buttonPanel ) ; add ( new WAjaxControl ( updateButton , repeater ) ) ; add ( new WAjaxControl ( resetButton , repeater ) ) ; } | Create the UI artefacts for the update and reset buttons . |
18,452 | private void createAddContactSubForm ( ) { add ( new WHeading ( HeadingLevel . H3 , "Add a new contact" ) ) ; WButton addBtn = new WButton ( "Add" ) ; addBtn . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { addNewContact ( ) ; } } ) ; addBtn . setImage ( "/image/address-book-new.png" ) ; newNameField . setDefaultSubmitButton ( addBtn ) ; WContainer container = new WContainer ( ) ; container . add ( newNameField ) ; container . add ( addBtn ) ; WFieldLayout layout = new WFieldLayout ( ) ; add ( layout ) ; layout . addField ( "New contact name" , container ) ; add ( new WAjaxControl ( addBtn , new AjaxTarget [ ] { repeater , newNameField } ) ) ; } | Create the UI artefacts for the Add contact sub form . |
18,453 | private void createPrintContactsSubForm ( ) { add ( new WHeading ( HeadingLevel . H3 , "Print to CSV" ) ) ; WButton printBtn = new WButton ( "Print" ) ; printBtn . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { printDetails ( ) ; } } ) ; printBtn . setImage ( "/image/document-print.png" ) ; printBtn . setImagePosition ( WButton . ImagePosition . EAST ) ; WFieldLayout layout = new WFieldLayout ( ) ; add ( layout ) ; layout . setMargin ( new Margin ( Size . LARGE , null , null , null ) ) ; layout . addField ( "Print output" , printOutput ) ; layout . addField ( ( WLabel ) null , printBtn ) ; add ( new WAjaxControl ( printBtn , printOutput ) ) ; } | Create the UI artefacts for the Print contacts sub form . |
18,454 | private void printDetails ( ) { StringBuilder builder = new StringBuilder ( "\"Name\",\"Phone\",\"Roles\",\"Identifier\"\n" ) ; for ( Object contact : repeater . getBeanList ( ) ) { builder . append ( contact ) . append ( '\n' ) ; } printOutput . setText ( builder . toString ( ) ) ; } | Write the list of contacts into the WTextArea printOutput . |
18,455 | private static List < ContactDetails > fetchDataList ( ) { List < ContactDetails > list = new ArrayList < > ( ) ; list . add ( new ContactDetails ( "David" , "1234" , new String [ ] { "a" , "b" } ) ) ; list . add ( new ContactDetails ( "Jun" , "1111" , new String [ ] { "c" } ) ) ; list . add ( new ContactDetails ( "Martin" , null , new String [ ] { "b" } ) ) ; return list ; } | Retrieves dummy data used by this example . |
18,456 | private WFieldSet addFieldSet ( final String title , final WFieldSet . FrameType type ) { final WFieldSet fieldset = new WFieldSet ( title ) ; fieldset . setFrameType ( type ) ; fieldset . setMargin ( new Margin ( null , null , Size . LARGE , null ) ) ; final WFieldLayout layout = new WFieldLayout ( ) ; fieldset . add ( layout ) ; layout . setLabelWidth ( 25 ) ; layout . addField ( "Street address" , new WTextField ( ) ) ; final WField add2Field = layout . addField ( "Street address line 2" , new WTextField ( ) ) ; add2Field . getLabel ( ) . setHidden ( true ) ; layout . addField ( "Suburb" , new WTextField ( ) ) ; layout . addField ( "State/Territory" , new WDropdown ( new String [ ] { "" , "ACT" , "NSW" , "NT" , "QLD" , "SA" , "TAS" , "VIC" , "WA" } ) ) ; final WTextField postcode = new WTextField ( ) ; postcode . setMaxLength ( 4 ) ; postcode . setColumns ( 4 ) ; postcode . setMinLength ( 3 ) ; layout . addField ( "Postcode" , postcode ) ; add ( fieldset ) ; return fieldset ; } | Creates a WFieldSet with content and a given FrameType . |
18,457 | private void makeSimpleExample ( ) { add ( new WHeading ( HeadingLevel . H3 , "Simple WRadioButtonSelect" ) ) ; WPanel examplePanel = new WPanel ( ) ; examplePanel . setLayout ( new FlowLayout ( FlowLayout . VERTICAL , Size . MEDIUM ) ) ; add ( examplePanel ) ; final WRadioButtonSelect rbSelect = new WRadioButtonSelect ( "australian_state" ) ; final WTextField text = new WTextField ( ) ; text . setReadOnly ( true ) ; text . setText ( NO_SELECTION ) ; WButton update = new WButton ( "Update" ) ; update . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { text . setText ( "The selected item is: " + rbSelect . getSelected ( ) ) ; } } ) ; examplePanel . setDefaultSubmitButton ( update ) ; examplePanel . add ( new WLabel ( "Select a state or territory" , rbSelect ) ) ; examplePanel . add ( rbSelect ) ; examplePanel . add ( text ) ; examplePanel . add ( update ) ; add ( new WAjaxControl ( update , text ) ) ; } | Make a simple editable example . The label for this example is used to get the example for use in the unit tests . |
18,458 | private void makeFramelessExample ( ) { add ( new WHeading ( HeadingLevel . H3 , "WRadioButtonSelect without its frame" ) ) ; add ( new ExplanatoryText ( "When a WRadioButtonSelect is frameless it loses some of its coherence, especially when its WLabel is hidden or " + "replaced by a toolTip. Using a frameless WRadioButtonSelect is useful within an existing WFieldLayout as it can provide a more " + "consistent user interface but only if it has a relatively small number of options." ) ) ; final WRadioButtonSelect select = new SelectWithSelection ( "australian_state" ) ; select . setFrameless ( true ) ; add ( new WLabel ( "Frameless with default selection" , select ) ) ; add ( select ) ; } | Make a simple editable example without a frame . |
18,459 | private void addInsideAFieldLayoutExample ( ) { add ( new WHeading ( HeadingLevel . H3 , "WRadioButtonSelect inside a WFieldLayout" ) ) ; add ( new ExplanatoryText ( "When a WRadioButtonSelect is inside a WField its label is exposed in a way which appears and behaves like a regular HTML label." + " This allows WRadioButtonSelects to be used in a layout with simple form controls (such as WTextField) and produce a consistent" + " and predicatable interface.\n" + "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." ) ) ; final WPanel wrapper = new WPanel ( ) ; add ( wrapper ) ; final WMessages messages = new WMessages ( ) ; wrapper . add ( messages ) ; WFieldLayout layout = new WFieldLayout ( ) ; layout . setLabelWidth ( 25 ) ; wrapper . add ( layout ) ; WButton resetThisBit = new WButton ( "Reset this bit" ) ; resetThisBit . setCancel ( true ) ; resetThisBit . setAjaxTarget ( wrapper ) ; resetThisBit . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { wrapper . reset ( ) ; } } ) ; layout . addField ( resetThisBit ) ; String [ ] options = new String [ ] { "Dog" , "Cat" , "Bird" , "Turtle" } ; WRadioButtonSelect select = new WRadioButtonSelect ( options ) ; layout . addField ( "Select an animal" , select ) ; String [ ] options2 = new String [ ] { "Parrot" , "Galah" , "Cockatoo" , "Lyre" } ; select = new WRadioButtonSelect ( options2 ) ; select . setMandatory ( true ) ; layout . addField ( "You must select a bird" , select ) ; select . setFrameless ( true ) ; String [ ] options3 = new String [ ] { "Carrot" , "Beet" , "Brocolli" , "Bacon - the perfect vegetable" } ; select = new WRadioButtonSelect ( options3 ) ; layout . addField ( ( WLabel ) null , select ) ; select . setToolTip ( "Veggies" ) ; WButton btnValidate = new WButton ( "validate" ) ; btnValidate . setAction ( new ValidatingAction ( messages . getValidationErrors ( ) , layout ) { public void executeOnValid ( final ActionEvent event ) { } } ) ; layout . addField ( btnValidate ) ; wrapper . add ( new WAjaxControl ( btnValidate , wrapper ) ) ; } | When a WRadioButtonSelect is added to a WFieldLayout the legend is moved . The first CheckBoxSelect has a frame the second doesn t |
18,460 | private void addFlatSelectExample ( ) { add ( new WHeading ( HeadingLevel . H3 , "WRadioButtonSelect with flat layout" ) ) ; add ( new ExplanatoryText ( "Setting the layout to FLAT will make the radio buttons be rendered in a horizontal line. They will wrap when they" + " reach the edge of the parent container." ) ) ; final WRadioButtonSelect select = new WRadioButtonSelect ( "australian_state" ) ; select . setButtonLayout ( WRadioButtonSelect . LAYOUT_FLAT ) ; add ( new WLabel ( "Flat selection" , select ) ) ; add ( select ) ; } | adds a WRadioButtonSelect with LAYOUT_FLAT . |
18,461 | private void addReadOnlyExamples ( ) { add ( new WHeading ( HeadingLevel . H3 , "Read-only WRadioButtonSelect examples" ) ) ; add ( new ExplanatoryText ( "These examples all use the same list of options: the states and territories list from the editable examples above. " + "When the readOnly state is specified only that option which is selected is output.\n" + "Since no more than one option is able to be selected the layout and frame settings are ignored in the read only state." ) ) ; WFieldLayout layout = new WFieldLayout ( ) ; add ( layout ) ; WRadioButtonSelect select = new WRadioButtonSelect ( "australian_state" ) ; select . setReadOnly ( true ) ; layout . addField ( "Read only with no selection" , select ) ; select = new SelectWithSelection ( "australian_state" ) ; select . setReadOnly ( true ) ; layout . addField ( "Read only with selection" , select ) ; } | Examples of readonly states . When in a read only state only the selected option is output . Since a WRadioButtonSeelct can only have 0 or 1 selected option the LAYOUT and FRAME are ignored . |
18,462 | private void addContentRow ( final String contentDesc , final ContentAccess contentAccess , final MutableContainer target ) { WButton button = new WButton ( contentDesc ) ; final WContent buttonContent = new WContent ( ) ; button . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { buttonContent . setContentAccess ( contentAccess ) ; buttonContent . display ( ) ; } } ) ; WContainer buttonCell = new WContainer ( ) ; buttonCell . add ( buttonContent ) ; buttonCell . add ( button ) ; target . add ( buttonCell ) ; WButton ajaxButton = new WButton ( contentDesc ) ; final WContent ajaxContent = new WContent ( ) ; ajaxButton . setAction ( new Action ( ) { public void execute ( final ActionEvent event ) { ajaxContent . setContentAccess ( contentAccess ) ; ajaxContent . display ( ) ; } } ) ; WContainer ajaxCell = new WContainer ( ) ; WPanel ajaxContentPanel = new WPanel ( ) ; ajaxContentPanel . add ( ajaxContent ) ; ajaxCell . add ( ajaxButton ) ; ajaxCell . add ( ajaxContentPanel ) ; ajaxButton . setAjaxTarget ( ajaxContentPanel ) ; target . add ( ajaxCell ) ; WContentLink contentLinkNewWindow = new WContentLink ( contentDesc ) { protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; setContentAccess ( contentAccess ) ; } } ; target . add ( contentLinkNewWindow ) ; WContentLink contentLinkPromptToSave = new WContentLink ( contentDesc ) { protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; setContentAccess ( contentAccess ) ; } } ; contentLinkPromptToSave . setDisplayMode ( DisplayMode . PROMPT_TO_SAVE ) ; target . add ( contentLinkPromptToSave ) ; WContentLink contentLinkInline = new WContentLink ( contentDesc ) { protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; setContentAccess ( contentAccess ) ; } } ; contentLinkInline . setDisplayMode ( DisplayMode . DISPLAY_INLINE ) ; target . add ( contentLinkInline ) ; WMenu menu = new WMenu ( WMenu . MenuType . FLYOUT ) ; final WContent menuContent = new WContent ( ) ; menuContent . setDisplayMode ( DisplayMode . PROMPT_TO_SAVE ) ; WMenuItem menuItem = new WMenuItem ( contentDesc ) { protected void preparePaintComponent ( final Request request ) { super . preparePaintComponent ( request ) ; menuContent . setContentAccess ( contentAccess ) ; setUrl ( menuContent . getUrl ( ) ) ; } } ; menu . add ( menuItem ) ; WContainer menuCell = new WContainer ( ) ; menuCell . add ( menuContent ) ; menuCell . add ( menu ) ; target . add ( menuCell ) ; } | Adds components to the given container which demonstrate various ways of acessing the given content . |
18,463 | private void applySettings ( ) { linkContainer . reset ( ) ; WLink exampleLink = new WLink ( ) ; exampleLink . setText ( tfLinkLabel . getText ( ) ) ; final String url = tfUrlField . getValue ( ) ; if ( "" . equals ( url ) || ! isValidUrl ( url ) ) { tfUrlField . setText ( URL ) ; exampleLink . setUrl ( URL ) ; } else { exampleLink . setUrl ( url ) ; } exampleLink . setRenderAsButton ( cbRenderAsButton . isSelected ( ) ) ; exampleLink . setText ( tfLinkLabel . getText ( ) ) ; if ( cbSetImage . isSelected ( ) ) { WImage linkImage = new WImage ( "/image/attachment.png" , "Add attachment" ) ; exampleLink . setImage ( linkImage . getImage ( ) ) ; exampleLink . setImagePosition ( ( ImagePosition ) ddImagePosition . getSelected ( ) ) ; } exampleLink . setDisabled ( cbDisabled . isSelected ( ) ) ; if ( tfAccesskey . getText ( ) != null && tfAccesskey . getText ( ) . length ( ) > 0 ) { exampleLink . setAccessKey ( tfAccesskey . getText ( ) . toCharArray ( ) [ 0 ] ) ; } if ( cbOpenNew . isSelected ( ) ) { exampleLink . setOpenNewWindow ( true ) ; exampleLink . setTargetWindowName ( "_blank" ) ; } else { exampleLink . setOpenNewWindow ( false ) ; } linkContainer . add ( exampleLink ) ; } | this is were the majority of the work is done for building the link . Note that it is in a container that is reset effectively creating a new link . this is only done to enable to dynamically change the link to a button and back . |
18,464 | public void showDetails ( final ActionEvent event ) { MyData data = ( MyData ) event . getActionObject ( ) ; displayDialog . setData ( data ) ; dialog . display ( ) ; } | Handle show details . |
18,465 | private WMessages getWMessageInstance ( ) { MessageContainer container = getMessageContainer ( component ) ; WMessages result = null ; if ( container == null ) { LOG . warn ( "No MessageContainer as ancestor of " + component + ". Messages will not be added" ) ; } else { result = container . getMessages ( ) ; if ( result == null ) { LOG . warn ( "No messages in container of " + component + ". Messages will not be added" ) ; } } return result ; } | Utility method that searches for the WMessages instance for the given component . If not found a warning will be logged and null returned . |
18,466 | public void error ( final String code ) { WMessages instance = getWMessageInstance ( ) ; if ( instance != null ) { instance . error ( code ) ; } } | Adds an error message . |
18,467 | public void setBeanList ( final List beanList ) { RepeaterModel model = getOrCreateComponentModel ( ) ; model . setData ( beanList ) ; HashSet rowIds = new HashSet ( beanList . size ( ) ) ; for ( Object bean : beanList ) { rowIds . add ( getRowId ( bean ) ) ; } cleanupStaleContexts ( rowIds ) ; UIContext uic = UIContextHolder . getCurrent ( ) ; if ( uic != null && getRepeatRoot ( ) != null ) { clearScratchMaps ( this ) ; } } | Remember the list of beans that hold the data object for each row . |
18,468 | protected void clearScratchMaps ( final WComponent node ) { UIContext uic = UIContextHolder . getCurrent ( ) ; uic . clearRequestScratchMap ( node ) ; uic . clearScratchMap ( node ) ; if ( node instanceof WRepeater ) { WRepeater repeater = ( WRepeater ) node ; List < UIContext > rowContextList = repeater . getRowContexts ( ) ; WComponent repeatedComponent = repeater . getRepeatedComponent ( ) ; for ( UIContext rowContext : rowContextList ) { UIContextHolder . pushContext ( rowContext ) ; try { clearScratchMaps ( repeatedComponent ) ; } finally { UIContextHolder . popContext ( ) ; } } uic . clearRequestScratchMap ( node ) ; uic . clearScratchMap ( node ) ; } else if ( node instanceof Container ) { Container container = ( Container ) node ; for ( int i = 0 ; i < container . getChildCount ( ) ; i ++ ) { clearScratchMaps ( container . getChildAt ( i ) ) ; } } } | Recursively clears cached component scratch maps . This is called when the bean list changes as the beans may have changed . |
18,469 | public List getBeanList ( ) { List beanList = ( List ) getData ( ) ; if ( beanList == null ) { return Collections . emptyList ( ) ; } return Collections . unmodifiableList ( beanList ) ; } | Retrieves the list of dataBeans that holds the data object for each row . The list returned will be the same instance as the one supplied via the setBeanList method . Will never return null but it can return an empty list . |
18,470 | public void validate ( final List < Diagnostic > diags ) { List beanList = this . getBeanList ( ) ; WComponent row = getRepeatedComponent ( ) ; for ( int i = 0 ; i < beanList . size ( ) ; i ++ ) { Object rowData = beanList . get ( i ) ; UIContext rowContext = getRowContext ( rowData , i ) ; UIContextHolder . pushContext ( rowContext ) ; try { row . validate ( diags ) ; } finally { UIContextHolder . popContext ( ) ; } } } | Validates each row . |
18,471 | public void handleRequest ( final Request request ) { assertConfigured ( ) ; List beanList = getBeanList ( ) ; HashSet rowIds = new HashSet ( beanList . size ( ) ) ; WComponent row = getRepeatedComponent ( ) ; for ( int i = 0 ; i < beanList . size ( ) ; i ++ ) { Object rowData = beanList . get ( i ) ; rowIds . add ( getRowId ( rowData ) ) ; UIContext rowContext = getRowContext ( rowData , i ) ; try { UIContextHolder . pushContext ( rowContext ) ; row . serviceRequest ( request ) ; } finally { UIContextHolder . popContext ( ) ; } } cleanupStaleContexts ( rowIds ) ; } | Override handleRequest to process the request for each row . |
18,472 | protected void cleanupStaleContexts ( final Set < ? > rowIds ) { RepeaterModel model = getOrCreateComponentModel ( ) ; if ( model . rowContextMap != null ) { for ( Iterator < Map . Entry < Object , SubUIContext > > i = model . rowContextMap . entrySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Map . Entry < Object , SubUIContext > entry = i . next ( ) ; Object rowId = entry . getKey ( ) ; if ( ! rowIds . contains ( rowId ) ) { i . remove ( ) ; } } if ( model . rowContextMap . isEmpty ( ) ) { model . rowContextMap = null ; } } } | Removes any stale contexts from the row context map . |
18,473 | protected void preparePaintComponent ( final Request request ) { assertConfigured ( ) ; List beanList = getBeanList ( ) ; List < Integer > used = new ArrayList < > ( ) ; for ( int i = 0 ; i < beanList . size ( ) ; i ++ ) { Object rowData = beanList . get ( i ) ; UIContext rowContext = getRowContext ( rowData , i ) ; Integer subId = ( ( SubUIContext ) rowContext ) . getContextId ( ) ; if ( used . contains ( subId ) ) { Object rowId = ( ( SubUIContext ) rowContext ) . getRowId ( ) ; String msg = "The row context for row id [" + rowId + "] has already been used for another row. " + "Either the row ID is not unique or the row bean has not implemented equals/hashcode " + "or no rowIdBeanProperty set on the repeater that uniquely identifies the row." ; throw new SystemException ( msg ) ; } used . add ( subId ) ; UIContextHolder . pushContext ( rowContext ) ; try { prepareRow ( request , i ) ; } finally { UIContextHolder . popContext ( ) ; } } } | Override preparePaintComponent to prepare each row for painting . |
18,474 | protected void prepareRow ( final Request request , final int rowIndex ) { WComponent row = getRepeatedComponent ( ) ; row . preparePaint ( request ) ; } | Prepares a single row for painting . |
18,475 | public UIContext getRowContext ( final Object rowBean , final int rowIndex ) { RepeaterModel model = getOrCreateComponentModel ( ) ; Object rowId = getRowId ( rowBean ) ; if ( model . rowContextMap == null ) { model . rowContextMap = new HashMap < > ( ) ; } SubUIContext rowContext = model . rowContextMap . get ( rowId ) ; if ( rowContext == null ) { int seq = model . rowContextIdSequence ++ ; if ( seq == 0 ) { try { if ( rowId . getClass ( ) != rowId . getClass ( ) . getMethod ( "equals" , Object . class ) . getDeclaringClass ( ) || rowId . getClass ( ) != rowId . getClass ( ) . getMethod ( "hashCode" ) . getDeclaringClass ( ) ) { LOG . warn ( "Row id class [" + rowId . getClass ( ) . getName ( ) + "] has not implemented equals or hashcode. This can cause errors when matching a row context. " + "Implement equals/hashcode on the row bean or refer to setRowIdBeanProperty method on WRepeater." ) ; } } catch ( Exception e ) { LOG . info ( "Error checking equals and hashcode implementation on the row id. " + e . getMessage ( ) , e ) ; } } String renderId = getRowIdName ( rowBean , rowId ) ; if ( renderId == null ) { rowContext = new SubUIContext ( this , seq ) ; } else { Matcher matcher = ROW_ID_CONTEXT_NAME_PATTERN . matcher ( renderId ) ; if ( ! matcher . matches ( ) ) { throw new IllegalArgumentException ( "Row idName [" + renderId + "] must start with a letter and followed by letters, digits and or underscores." ) ; } rowContext = new SubUIContext ( this , seq , renderId ) ; } rowContext . setRowId ( rowId ) ; model . rowContextMap . put ( rowId , rowContext ) ; } rowContext . setRowIndex ( rowIndex ) ; return rowContext ; } | Retrieves the UIContext for a row . |
18,476 | public Object getRowBeanForSubcontext ( final SubUIContext subContext ) { if ( subContext . repeatRoot != getRepeatRoot ( ) ) { throw new IllegalArgumentException ( "SubUIContext is not for this WRepeater instance." ) ; } UIContextHolder . pushContext ( subContext . getParentContext ( ) ) ; try { return getRowData ( subContext . getRowId ( ) ) ; } finally { UIContextHolder . popContext ( ) ; } } | Returns the row data for the given row context . |
18,477 | private Object getRowData ( final Object rowId ) { Map dataByRowId = ( Map ) getScratchMap ( ) . get ( SCRATCHMAP_DATA_BY_ROW_ID_KEY ) ; if ( dataByRowId == null ) { dataByRowId = createRowIdCache ( ) ; } Object data = dataByRowId . get ( rowId ) ; if ( data == null && ! dataByRowId . containsKey ( rowId ) ) { dataByRowId = createRowIdCache ( ) ; data = dataByRowId . get ( rowId ) ; } return data ; } | Returns the row data corresponding to the given id . |
18,478 | protected Object getRowId ( final Object rowBean ) { String rowIdProperty = getComponentModel ( ) . rowIdProperty ; if ( rowIdProperty == null || rowBean == null ) { return rowBean ; } try { return PropertyUtils . getProperty ( rowBean , rowIdProperty ) ; } catch ( Exception e ) { LOG . error ( "Failed to read row property \"" + rowIdProperty + "\" on " + rowBean , e ) ; return rowBean ; } } | Retrieves the row id for the given row . |
18,479 | public List < UIContext > getRowContexts ( ) { List < ? > beanList = this . getBeanList ( ) ; List < UIContext > contexts = new ArrayList < > ( beanList . size ( ) ) ; for ( int i = 0 ; i < beanList . size ( ) ; i ++ ) { Object rowData = beanList . get ( i ) ; contexts . add ( this . getRowContext ( rowData , i ) ) ; } return Collections . unmodifiableList ( contexts ) ; } | Retrieves the row contexts for all rows . |
18,480 | public void assignTask ( int taskId , int responsible ) { getResourceFactory ( ) . getApiResource ( "/task/" + taskId + "/assign" ) . entity ( new AssignValue ( responsible ) , MediaType . APPLICATION_JSON_TYPE ) . post ( ) ; } | Assigns the task to another user . This makes the user responsible for the task and its completion . |
18,481 | public void completeTask ( int taskId ) { getResourceFactory ( ) . getApiResource ( "/task/" + taskId + "/complete" ) . entity ( new Empty ( ) , MediaType . APPLICATION_JSON_TYPE ) . post ( ) ; } | Mark the given task as completed . |
18,482 | public void updateDueDate ( int taskId , LocalDate dueDate ) { getResourceFactory ( ) . getApiResource ( "/task/" + taskId + "/due_date" ) . entity ( new TaskDueDate ( dueDate ) , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Updates the due date of the task to the given value |
18,483 | public void updatePrivate ( int taskId , boolean priv ) { getResourceFactory ( ) . getApiResource ( "/task/" + taskId + "/private" ) . entity ( new TaskPrivate ( priv ) , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Update the private flag on the given task . |
18,484 | public void updateText ( int taskId , String text ) { getResourceFactory ( ) . getApiResource ( "/task/" + taskId + "/text" ) . entity ( new TaskText ( text ) , MediaType . APPLICATION_JSON_TYPE ) . put ( ) ; } | Updates the text of the task . |
18,485 | public int createTask ( TaskCreate task , boolean silent , boolean hook ) { TaskCreateResponse response = getResourceFactory ( ) . getApiResource ( "/task/" ) . queryParam ( "silent" , silent ? "1" : "0" ) . queryParam ( "hook" , hook ? "1" : "0" ) . entity ( task , MediaType . APPLICATION_JSON_TYPE ) . post ( TaskCreateResponse . class ) ; return response . getId ( ) ; } | Creates a new task with no reference to other objects . |
18,486 | public List < Task > getTasksWithReference ( Reference reference ) { return getResourceFactory ( ) . getApiResource ( "/task/" + reference . getType ( ) . name ( ) . toLowerCase ( ) + "/" + reference . getId ( ) + "/" ) . get ( new GenericType < List < Task > > ( ) { } ) ; } | Gets a list of tasks with a reference to the given object . This will return both active and completed tasks . The reference will not be set on the individual tasks . |
18,487 | private Date convertDate ( final Object data ) { if ( data == null ) { return null ; } else if ( data instanceof Date ) { return ( Date ) data ; } else if ( data instanceof Long ) { return new Date ( ( Long ) data ) ; } else if ( data instanceof Calendar ) { return ( ( Calendar ) data ) . getTime ( ) ; } else if ( data instanceof String ) { try { SimpleDateFormat sdf = new SimpleDateFormat ( INTERNAL_DATE_FORMAT ) ; sdf . setLenient ( lenient ) ; return sdf . parse ( ( String ) data ) ; } catch ( ParseException e ) { throw new SystemException ( "Could not convert String data [" + data + "] to a date." ) ; } } throw new SystemException ( "Cannot convert data type " + data . getClass ( ) + " to a date." ) ; } | Attempts to convert the given object to a date . Throws a SystemException on error . |
18,488 | protected void validateComponent ( final List < Diagnostic > diags ) { if ( isParseable ( ) ) { super . validateComponent ( diags ) ; validateDate ( diags ) ; } else { diags . add ( createErrorDiagnostic ( getComponentModel ( ) . errorMessage , this ) ) ; } } | Override WInput s validateComponent to perform further validation on the date . |
18,489 | public void setModel ( final WebComponent component , final WebModel model ) { map . put ( component , model ) ; } | Stores the extrinsic state information for the given component . |
18,490 | public void invokeLater ( final UIContext uic , final Runnable runnable ) { if ( invokeLaterRunnables == null ) { invokeLaterRunnables = new ArrayList < > ( ) ; } invokeLaterRunnables . add ( new UIContextImplRunnable ( uic , runnable ) ) ; } | Adds a runnable to the list of runnables to be invoked later . |
18,491 | public void setFocussed ( final WComponent component , final UIContext uic ) { this . focussed = component ; this . focussedUIC = uic ; } | Sets the component in this UIC which is to be the focus of the client browser cursor . The id of the component is used to find the focussed element in the rendered html . Since id could be different in different contexts the context of the component is also needed . |
18,492 | public Object getFwkAttribute ( final String name ) { if ( attribMap == null ) { return null ; } return attribMap . get ( name ) ; } | Reserved for internal framework use . Retrieves a framework attribute . |
18,493 | public void setFwkAttribute ( final String name , final Object value ) { if ( attribMap == null ) { attribMap = new HashMap < > ( ) ; } attribMap . put ( name , value ) ; } | Reserved for internal framework use . Sets a framework attribute . |
18,494 | public Map < Object , Object > getScratchMap ( final WComponent component ) { if ( scratchMaps == null ) { scratchMaps = new HashMap < > ( ) ; } Map < Object , Object > componentScratchMap = scratchMaps . get ( component ) ; if ( componentScratchMap == null ) { componentScratchMap = new HashMap < > ( 2 ) ; scratchMaps . put ( component , componentScratchMap ) ; } return componentScratchMap ; } | Reserved for internal framework use . Retrieves a scratch area where data can be temporarily stored . WComponents must not rely on data being available in the scratch area after each phase . |
18,495 | private void setupLabel ( ) { WText textBody = new WText ( ) { public boolean isEncodeText ( ) { return WHeading . this . isEncodeText ( ) ; } public String getText ( ) { return WHeading . this . getText ( ) ; } } ; if ( label . getBody ( ) == null ) { label . setBody ( textBody ) ; } else { WComponent oldBody = label . getBody ( ) ; WContainer newBody = new WContainer ( ) ; label . setBody ( newBody ) ; newBody . add ( textBody ) ; newBody . add ( oldBody ) ; } } | Setup the label . |
18,496 | private void addNullLabelExample ( ) { add ( new WHeading ( HeadingLevel . H2 , "How to use accessible null WLabels" ) ) ; add ( new ExplanatoryText ( "These examples shows how sometime a null WLabel is the right thing to do." + "\n This example uses a WFieldSet as the labelled component and it has its own \"label\"." ) ) ; WFieldLayout fieldsFlat = new WFieldLayout ( ) ; fieldsFlat . setMargin ( new Margin ( null , null , Size . XL , null ) ) ; add ( fieldsFlat ) ; WFieldSet fs = new WFieldSet ( "Do you like Bananas?" ) ; fieldsFlat . addField ( ( WLabel ) null , fs ) ; WFieldLayout innerLayout = new WFieldLayout ( WFieldLayout . LAYOUT_STACKED ) ; RadioButtonGroup group1 = new RadioButtonGroup ( ) ; WRadioButton rb1 = group1 . addRadioButton ( 1 ) ; WRadioButton rb2 = group1 . addRadioButton ( 2 ) ; WLabel rb1Label = new WLabel ( "" , rb1 ) ; WImage labelImage = new WImage ( "/image/success.png" , "I still like bananas" ) ; labelImage . setHtmlClass ( "wc-valign-bottom" ) ; rb1Label . add ( labelImage ) ; WLabel rb2Label = new WLabel ( "" , rb2 ) ; labelImage = new WImage ( "/image/error.png" , "I still dislike bananas" ) ; labelImage . setHtmlClass ( "wc-valign-bottom" ) ; rb2Label . add ( labelImage ) ; innerLayout . addField ( rb1Label , rb1 ) ; innerLayout . addField ( rb2Label , rb2 ) ; fs . add ( group1 ) ; fs . add ( innerLayout ) ; } | Example of when and how to use a null WLabel . |
18,497 | public void doRender ( final WComponent component , final WebXmlRenderContext renderContext ) { WHeading heading = ( WHeading ) component ; XmlStringBuilder xml = renderContext . getWriter ( ) ; xml . appendTagOpen ( "ui:heading" ) ; xml . appendAttribute ( "id" , component . getId ( ) ) ; xml . appendOptionalAttribute ( "class" , component . getHtmlClass ( ) ) ; xml . appendOptionalAttribute ( "track" , component . isTracking ( ) , "true" ) ; xml . appendAttribute ( "level" , heading . getHeadingLevel ( ) . getLevel ( ) ) ; xml . appendOptionalAttribute ( "accessibleText" , heading . getAccessibleText ( ) ) ; xml . appendClose ( ) ; MarginRendererUtil . renderMargin ( heading , renderContext ) ; if ( heading . getDecoratedLabel ( ) == null ) { xml . append ( heading . getText ( ) , heading . isEncodeText ( ) ) ; } else { heading . getDecoratedLabel ( ) . paint ( renderContext ) ; } xml . appendEndTag ( "ui:heading" ) ; } | Paints the given WHeading . |
18,498 | protected boolean execute ( ) { if ( ( trigger instanceof Disableable ) && ( ( Disableable ) trigger ) . isDisabled ( ) && ! ( trigger instanceof Input && ( ( Input ) trigger ) . isReadOnly ( ) ) ) { return false ; } final Object triggerValue = getTriggerValue ( null ) ; final Object compareValue = getCompareValue ( ) ; return executeCompare ( triggerValue , compareValue ) ; } | Compare the trigger and compare value . |
18,499 | public boolean isTabVisible ( final int idx ) { WTab tab = getTab ( idx ) ; Container tabParent = tab . getParent ( ) ; if ( tabParent instanceof WTabGroup ) { return tab . isVisible ( ) && tabParent . isVisible ( ) ; } else { return tab . isVisible ( ) ; } } | Indicates whether the tab at the given index is visible . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.