/** * Initializes HTMl elements (DIV and Canvas).<br> * It sets also some default behaviors (width in percentage) for resizing */ public AbstractChart() { // creates DIV div = Document.get().createDivElement(); div.setId(id); // sets relative position div.getStyle().setPosition(Position.RELATIVE); // sets default width values div.getStyle().setWidth(DEFAULT_PCT_WIDTH, Unit.PCT); div.getStyle().setHeight(100, Unit.PCT); // checks if canvas is supported if (isCanvasSupported) { // creates a canvas and add to DIV canvas = Document.get().createCanvasElement(); div.appendChild(canvas); } else { // creates a header element HeadingElement h = Document.get().createHElement(3); // to show the error message // because canvas is not supported h.setInnerText(CANVAS_NOT_SUPPORTED_MESSAGE); div.appendChild(h); // resets canvas canvas = null; } // sets DIV as element of the widget setElement(div); // injects Chart.js java script source Injector.ensureInjected(); // creates plugins container plugins = new Plugins(this); // creates global options options = new GlobalOptions(createGlobalOptions(getType().name())); }
public static HeadingElement createHeading(int n, String value) { HeadingElement h = Document.get().createHElement(n); h.setInnerHTML(value); return h; }
private void updatePreview () { pnlPreview.getElement().removeAllChildren(); Document d = Document.get(); HeadingElement title = d.createHElement(1); title.setInnerHTML(PostHelper.makeHeading(txtTitle.getValue())); pnlPreview.getElement().appendChild(title); User user = SessionController.get().user(); DivElement elDate = d.createDivElement(); if (post != null) { if (post.published == null) { elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE .notPublished(DateTimeHelper.ago(post.created))); } else { elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE .publishedDate(DateTimeHelper.ago(post.published))); } } else { elDate.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE .notPublished(DateTimeHelper.ago(new Date()))); } pnlPreview.getElement().appendChild(elDate); DivElement elAuthor = d.createDivElement(); if (PropertyController.get() .booleanProperty(PropertyHelper.POST_SHOW_AUTHOR, false)) { elAuthor.setInnerSafeHtml(PostSummaryCell.Templates.INSTANCE.author( UriUtils.fromString( (post != null ? post.author.avatar : user.avatar) + "?s=" + UserHelper.AVATAR_HEADER_SIZE + "&default=retro"), UserHelper.handle((post != null ? post.author : user)))); } pnlPreview.getElement().appendChild(elAuthor); tagList.getList().clear(); List<String> tags = TagHelper.convertToTagList(txtTags.getValue()); if (tags != null) { for (String tag : tags) { tagList.getList().add(new Tag().name(tag)); } } DivElement summary = d.createDivElement(); summary.setInnerHTML(markup(txtSummary)); pnlPreview.getElement().appendChild(summary); DivElement content = d.createDivElement(); content.setInnerHTML(markup(txtContent)); pnlPreview.getElement().appendChild(content); }