public void injectUniqueCSS ( String cssContent , String wrapperClass ) { if ( alreadyAddedCSS == null ) { alreadyAddedCSS = new TreeSet < String > ( ) ; } if ( wrapperClass != null ) { cssContent = wrapCSS ( cssContent , wrapperClass ) ; } String hashForCssContent = Hashing . md5 ( ) . hashString ( cssContent , Charsets . UTF_8 ) . toString ( ) ; if ( ! alreadyAddedCSS . contains ( hashForCssContent ) ) { // CSSInject cssInject = new CSSInject(UI.getCurrent()); // cssInject.setStyles(cssContent); Page . getCurrent ( ) . getStyles ( ) . add ( cssContent ) ; alreadyAddedCSS . add ( hashForCssContent ) ; } }
Inject CSS into the UI . This function will not add multiple style - elements if the exact CSS string was already added .