List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder toSafeHtml
public SafeHtml toSafeHtml()
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.list.wrapper.LemmaVersionCellWrapper.java
License:Apache License
@Override public SafeHtml getUserDetails() { LightUserInfo userInfo = lemma.getUserInfo(); SafeHtmlBuilder builder = new SafeHtmlBuilder(); if (userInfo != null && userInfo.getRole() != Role.GUEST_1) { String firstName = userInfo.getFirstName(); String lastName = userInfo.getLastName(); if (firstName != null && lastName != null) { builder.append(templates.userName(firstName, lastName)); } else {/*w w w . ja v a 2 s . co m*/ builder.append(templates.login(userInfo.getLogin())); } if (lemma.getIP() != null) { builder.append(templates.ipSmall(lemma.getIP())); } else { builder.append(templates.ipSmall(constants.unknownIp())); } } else { if (lemma.getIP() != null) { builder.append(templates.ipDefault(lemma.getIP())); } else { builder.append(templates.ipDefault(constants.unknownIp())); } } return builder.toSafeHtml(); }
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.list.wrapper.LemmaVersionCellWrapper.java
License:Apache License
@Override public SafeHtml getLemma() { SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.appendHtmlConstant(lemmaDescription.toString(lemma, UseCase.RESULT_LIST, true)); builder.appendHtmlConstant(" "); builder.appendHtmlConstant(lemmaDescription.toString(lemma, UseCase.RESULT_LIST, false)); return builder.toSafeHtml(); }
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.list.wrapper.LemmaVersionCellWrapper.java
License:Apache License
@Override public SafeHtml getShortLemma() { SafeHtmlBuilder builder = new SafeHtmlBuilder(); String first = lemmaDescription.toString(lemma, UseCase.RESULT_LIST, true).trim(); if (first.length() > 85) { first = escaper.escape(first.substring(0, 40) + "..." + first.substring(first.length() - 40)); }/*from ww w.j a v a 2 s . c om*/ String second = lemmaDescription.toString(lemma, UseCase.RESULT_LIST, false).trim(); if (second.length() > 85) { second = escaper.escape(second.substring(0, 40) + "..." + first.substring(first.length() - 40)); } builder.appendHtmlConstant(first); builder.appendHtmlConstant(" "); builder.appendHtmlConstant(second); return builder.toSafeHtml(); }
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.editor.client.entry.order.OrderWidget.java
License:Apache License
private void initialize() { selectionModel = new SingleSelectionModel<LemmaVersion>(new ProvidesKey<LemmaVersion>() { @Override//from w w w . j a va 2s .co m public Object getKey(LemmaVersion item) { return item; } }); provider = new ListDataProvider<LemmaVersion>(); initWidget(uiBinder.createAndBindUi(OrderWidget.this)); // header.setText("Modify Order"); list.setPageSize(100); list.setSelectionModel(selectionModel); list.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); Column<LemmaVersion, SafeHtml> column = new Column<LemmaVersion, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(LemmaVersion object) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); LemmaDescription description = AsyncLemmaDescriptionLoader.getDescription(); String toDisplay = description.toString(object, UseCase.RESULT_LIST, true) + " " + description.toString(object, UseCase.RESULT_LIST, false); sb.appendHtmlConstant(toDisplay); return sb.toSafeHtml(); } }; RowStyles<LemmaVersion> wrapper = new RowStyles<LemmaVersion>() { @Override public String getStyleNames(LemmaVersion row, int rowIndex) { return "user-row"; } }; list.setRowStyles(wrapper); list.addColumn(column); provider.addDataDisplay(list); up.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { LemmaVersion obj = selectionModel.getSelectedObject(); if (obj == null) return; int index = provider.getList().indexOf(obj); if (index == -1) return; if (index == 0) return; LemmaVersion other = provider.getList().get(index - 1); provider.getList().set(index - 1, obj); provider.getList().set(index, other); provider.refresh(); } }); down.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { LemmaVersion obj = selectionModel.getSelectedObject(); if (obj == null) return; int index = provider.getList().indexOf(obj); if (index == -1) return; if (index == provider.getList().size() - 1) return; LemmaVersion other = provider.getList().get(index + 1); provider.getList().set(index, other); provider.getList().set(index + 1, obj); provider.refresh(); } }); }
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.user.client.entry.OverlayPopup.java
License:Apache License
private static void createOverlay(Overlay overlay, LemmaVersion lemmaVersion, String closeButton) { String form = overlay.getForm(); HashSet<String> values = new HashSet<String>(); RegExp regExp = RegExp.compile("(\\$\\{(.*)\\})", "g"); for (MatchResult matcher = regExp.exec(form); matcher != null; matcher = regExp.exec(form)) { values.add(matcher.getGroup(2)); }/*ww w . jav a 2 s .co m*/ for (String key : values) { String value = lemmaVersion.getEntryValue(key); if (value == null || value.trim().length() == 0) { form = form.replaceAll("\\$\\{" + key + "\\}", ""); } else { SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.appendEscaped(value); form = form.replaceAll("\\$\\{" + key + "\\}", builder.toSafeHtml().asString()); } } SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.appendHtmlConstant(form); final Modal popup = new Modal(true); popup.add(new HTML(builder.toSafeHtml())); popup.setBackdrop(BackdropType.NORMAL); popup.setCloseVisible(true); popup.setWidth(1000); final Button close = new Button(closeButton); close.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { popup.hide(); } }); ModalFooter footer = new ModalFooter(close); popup.add(footer); popup.show(); }
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.user.client.search.celltable.ResultCellTable.java
License:Apache License
private void addOverlayColumn(final String overlayField, final TranslationMap translationMap) { final SafeHtmlCell overlayCell = new SafeHtmlCell() { final String closeButton = translationMap.get("maalr.verbOverlayPopup.closeButton"); @Override/*from w w w.j av a 2 s . c o m*/ public Set<String> getConsumedEvents() { Set<String> consumed = new HashSet<String>(); consumed.add(BrowserEvents.CLICK); return consumed; } @Override public void onBrowserEvent(com.google.gwt.cell.client.Cell.Context context, Element parent, SafeHtml value, NativeEvent event, ValueUpdater<SafeHtml> valueUpdater) { super.onBrowserEvent(context, parent, value, event, valueUpdater); super.onBrowserEvent(context, parent, value, event, valueUpdater); if (event.getType().equals(BrowserEvents.CLICK)) { LemmaVersion selected = dataProvider.getList().get(hoveredRow); onButtonClicked(selected); } } private void onButtonClicked(LemmaVersion selected) { // Window.alert("Selected: " + selected.getEntryValues()); OverlayPopup.show(selected, overlayField, closeButton); // final LemmaVersion lemma = new LemmaVersion(); // lemma.setEntryValues(selected.getEntryValues()); // lemma.setMaalrValues(selected.getMaalrValues()); // openModifyEditor(lemma); } }; popupColumn = new Column<LemmaVersion, SafeHtml>(overlayCell) { private final SafeHtml nothing = new SafeHtmlBuilder().toSafeHtml(); @Override public SafeHtml getValue(LemmaVersion object) { String overlay = object.getEntryValue(overlayField); if (overlay != null) { SafeHtmlBuilder builder = new SafeHtmlBuilder(); builder.appendHtmlConstant( "<span class=\"maalr_overlay maalr_overlay_" + overlay + "\">" + overlay + "</span>"); return builder.toSafeHtml(); } else { return nothing; } } }; cellTable.addColumn(popupColumn); }
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.user.client.search.celltable.ResultCellTable.java
License:Apache License
private void addColumnA(String langA, final boolean b) { final SafeHtmlCell leftCell = new SafeHtmlCell(); columnA = new Column<LemmaVersion, SafeHtml>(leftCell) { @Override/* www . j a v a2 s.co m*/ public SafeHtml getValue(LemmaVersion object) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); String toDisplay = description.toString(object, UseCase.RESULT_LIST, b); String redirect = b ? object.getEntryValue("redirect_a") : object.getEntryValue("redirect_b"); if (maalrQuery.isHighlight() && redirect == null) { toDisplay = Highlighter.highlight(toDisplay, maalrQuery.getValue("searchPhrase")); } if (redirect != null) { MaalrQuery mq = new MaalrQuery(); String[] redir = redirect.split("="); mq.setQueryValue(redir[0], redir[1]); String text = redir[1]; if (maalrQuery.isHighlight()) { text = Highlighter.highlight(text, maalrQuery.getValue("searchPhrase")); } String url = "<a href=\"" + Window.Location.getPath() + "#" + mq.toURL() + "\">" + text + "</a>"; toDisplay = toDisplay.replace(redir[1], url); } if (!object.isApproved()) { toDisplay = "<span class=\"unverified\">" + toDisplay + "</span>"; } sb.appendHtmlConstant(toDisplay); return sb.toSafeHtml(); } }; cellTable.addColumn(columnA, new SafeHtmlBuilder() .appendHtmlConstant("<span class=\"maalr_result_title\">" + langA + "</span>").toSafeHtml()); }
From source file:de.uni_koeln.spinfo.maalr.webapp.ui.user.client.search.celltable.ResultCellTable.java
License:Apache License
private void addColumnB(String langB, final boolean b) { columnB = new Column<LemmaVersion, SafeHtml>(new SafeHtmlCell()) { @Override//from w w w . j av a2 s . c o m public SafeHtml getValue(LemmaVersion object) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); String toDisplay = description.toString(object, UseCase.RESULT_LIST, b); String redirect = b ? object.getEntryValue("redirect_a") : object.getEntryValue("redirect_b"); if (maalrQuery.isHighlight() && redirect == null) { toDisplay = Highlighter.highlight(toDisplay, maalrQuery.getValue("searchPhrase")); } if (redirect != null) { MaalrQuery mq = new MaalrQuery(); String[] redir = redirect.split("="); mq.setQueryValue(redir[0], redir[1]); String text = redir[1]; if (maalrQuery.isHighlight()) { text = Highlighter.highlight(text, maalrQuery.getValue("searchPhrase")); } String url = "<a href=\"" + Window.Location.getPath() + "#" + mq.toURL() + "\">" + text + "</a>"; toDisplay = toDisplay.replace(redir[1], url); // toDisplay = "<a href=\"" + mq.toURL() + "\">" + redir[1] // + "</a>"; } if (!object.isApproved()) { toDisplay = "<span class=\"unverified\">" + toDisplay + "</span>"; } // if (!b) // sb.appendHtmlConstant(refereTo(toDisplay)); // else sb.appendHtmlConstant(toDisplay); return sb.toSafeHtml(); } }; cellTable.addColumn(columnB, new SafeHtmlBuilder() .appendHtmlConstant("<span class=\"maalr_result_title\">" + langB + "</span>").toSafeHtml()); }
From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.button.Css3ButtonCellAppearance.java
License:sencha.com license
@Override public void render(ButtonCell<M> cell, Context context, M value, SafeHtmlBuilder sb) { String constantHtml = cell.getHTML(); boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0; boolean isBoolean = value != null && value instanceof Boolean; // is a boolean always a toggle button? String text = hasConstantHtml ? cell.getText() : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : ""; ImageResource icon = cell.getIcon(); IconAlign iconAlign = cell.getIconAlign(); String arrowClass = ""; String scaleClass = ""; String iconClass = ""; int width = cell.getWidth(); int height = cell.getHeight(); boolean hasIcon = cell.getIcon() != null; boolean isSplitButton = cell instanceof SplitButtonCell; boolean hasMenu = cell.getMenu() != null; boolean hasWidth = width != -1; if (cell.getMenu() != null) { if (cell instanceof SplitButtonCell) { switch (cell.getArrowAlign()) { case RIGHT: arrowClass = style.split(); break; case BOTTOM: arrowClass = style.splitBottom(); break; }/*from w ww . j a va 2 s. c om*/ } else { switch (cell.getArrowAlign()) { case RIGHT: arrowClass = style.arrow(); break; case BOTTOM: arrowClass = style.arrowBottom(); break; } } } ButtonScale scale = cell.getScale(); switch (scale) { case SMALL: scaleClass = style.small(); break; case MEDIUM: scaleClass = style.medium(); break; case LARGE: scaleClass = style.large(); break; } if (icon != null) { switch (iconAlign) { case TOP: iconClass = style.iconTop(); break; case BOTTOM: iconClass = style.iconBottom(); break; case LEFT: iconClass = style.iconLeft(); break; case RIGHT: iconClass = style.iconRight(); break; } } String buttonClass = style.button(); boolean hasText = text != null && !text.equals(""); if (!hasText) { buttonClass += " " + style.noText(); } // toggle button if (value == Boolean.TRUE) { buttonClass += " " + style.pressed(); } String innerClass = style.buttonInner() + " " + iconClass; innerClass += " " + arrowClass; innerClass += " " + scaleClass; SafeHtmlBuilder builder = new SafeHtmlBuilder(); SafeStylesBuilder ss = new SafeStylesBuilder(); if (height != -1) { ButtonDetails bd = resources.theme().button(); EdgeDetails padding = bd.padding(); EdgeDetails paddingInner = bd.radiusMinusBorderWidth(); int ah = height; ah -= padding.top(); ah -= padding.bottom(); ah -= paddingInner.top(); ah -= paddingInner.bottom(); ss.appendTrustedString("line-height: " + ah + "px;"); } builder.appendHtmlConstant("<div class='" + buttonClass + "'>"); // get iconbuilder ready SafeHtmlBuilder iconBuilder = new SafeHtmlBuilder(); if (icon != null) { int iconWidth = icon != null ? icon.getWidth() : 0; int iconHeight = icon != null ? icon.getHeight() : 0; String styles = "width: " + iconWidth + "px; height: " + iconHeight + "px;"; iconBuilder.appendHtmlConstant("<div class='" + iconClass + "' style='" + styles + "'>"); iconBuilder.append(AbstractImagePrototype.create(icon).getSafeHtml()); iconBuilder.appendHtmlConstant("</div>"); } // for left / right aligned icons with a fixed button width we render the icon outside of the inner div if (hasWidth && hasIcon && iconAlign == IconAlign.LEFT) { builder.append(iconBuilder.toSafeHtml()); } if (hasWidth && hasIcon && (iconAlign == IconAlign.LEFT)) { int tw = width - (resources.theme().button().borderRadius() * 2); if (isSplitButton && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) { tw -= resources.split().getWidth() + 10; } if (!isSplitButton && iconAlign == IconAlign.LEFT && hasMenu && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) { tw -= resources.arrow().getWidth() + 10; } if (hasIcon && iconAlign == IconAlign.LEFT) { tw -= icon.getWidth(); } ss.appendTrustedString("width: " + tw + "px;"); } builder.appendHtmlConstant("<div class='" + innerClass + "' style='" + ss.toSafeStyles().asString() + "'>"); if (icon != null) { if ((!hasWidth && iconAlign == IconAlign.LEFT) || iconAlign == IconAlign.TOP) { builder.append(iconBuilder.toSafeHtml()); } builder.appendHtmlConstant(text); if (iconAlign == IconAlign.RIGHT || iconAlign == IconAlign.BOTTOM) { builder.append(iconBuilder.toSafeHtml()); } } else { builder.appendHtmlConstant(text); } builder.appendHtmlConstant("</div></div>"); sb.append(builder.toSafeHtml()); }
From source file:edu.arizona.biosemantics.gxt.theme.green.client.sliced.button.SlicedButtonCellAppearance.java
License:sencha.com license
@Override public void render(final ButtonCell<C> cell, Context context, C value, SafeHtmlBuilder sb) { String constantHtml = cell.getHTML(); boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0; boolean isBoolean = value != null && value instanceof Boolean; // is a boolean always a toggle button? String text = hasConstantHtml ? cell.getText() : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : ""; ImageResource icon = cell.getIcon(); IconAlign iconAlign = cell.getIconAlign(); String cls = style.button();//w w w . j a va 2s . c o m String arrowCls = ""; if (cell.getMenu() != null) { if (cell instanceof SplitButtonCell) { switch (cell.getArrowAlign()) { case RIGHT: arrowCls = style.split(); break; case BOTTOM: arrowCls = style.splitBottom(); break; default: // empty } } else { switch (cell.getArrowAlign()) { case RIGHT: arrowCls = style.arrow(); break; case BOTTOM: arrowCls = style.arrowBottom(); break; } } } ButtonScale scale = cell.getScale(); switch (scale) { case SMALL: cls += " " + style.small(); break; case MEDIUM: cls += " " + style.medium(); break; case LARGE: cls += " " + style.large(); break; default: // empty } SafeStylesBuilder stylesBuilder = new SafeStylesBuilder(); int width = -1; if (cell.getWidth() != -1) { int w = cell.getWidth(); if (w < cell.getMinWidth()) { w = cell.getMinWidth(); } stylesBuilder.appendTrustedString("width:" + w + "px;"); cls += " " + style.hasWidth() + " x-has-width"; width = w; } else { if (cell.getMinWidth() != -1) { TextMetrics.get().bind(style.text()); int length = TextMetrics.get().getWidth(text); length += 6; // frames if (icon != null) { switch (iconAlign) { case LEFT: case RIGHT: length += icon.getWidth(); break; default: // empty } } } } final int height = cell.getHeight(); if (height != -1) { stylesBuilder.appendTrustedString("height:" + height + "px;"); } if (icon != null) { switch (iconAlign) { case TOP: arrowCls += " " + style.iconTop(); break; case BOTTOM: arrowCls += " " + style.iconBottom(); break; case LEFT: arrowCls += " " + style.iconLeft(); break; case RIGHT: arrowCls += " " + style.iconRight(); break; } } else { arrowCls += " " + style.noIcon(); } // toggle button if (value == Boolean.TRUE) { cls += " " + frame.pressedClass(); } sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles())); SafeHtmlBuilder inside = new SafeHtmlBuilder(); String innerWrap = arrowCls; if (GXT.isIE6() || GXT.isIE7()) { arrowCls += " " + CommonStyles.get().inlineBlock(); } inside.appendHtmlConstant("<div class='" + innerWrap + "'>"); inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>"); boolean hasText = text != null && !text.equals(""); if (icon != null) { switch (iconAlign) { case LEFT: inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); if (hasText) { int w = width - (icon != null ? icon.getWidth() : 0) - 4; writeText(inside, text, w, height); } inside.appendHtmlConstant("</tr>"); break; case RIGHT: inside.appendHtmlConstant("<tr>"); if (hasText) { int w = width - (icon != null ? icon.getWidth() : 0) - 4; writeText(inside, text, w, height); } writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); break; case TOP: inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); if (hasText) { inside.appendHtmlConstant("<tr>"); writeText(inside, text, width, height); inside.appendHtmlConstant("</tr>"); } break; case BOTTOM: if (hasText) { inside.appendHtmlConstant("<tr>"); writeText(inside, text, width, height); inside.appendHtmlConstant("</tr>"); } inside.appendHtmlConstant("<tr>"); writeIcon(inside, icon, height); inside.appendHtmlConstant("</tr>"); break; } } else { inside.appendHtmlConstant("<tr>"); if (text != null) { writeText(inside, text, width, height); } inside.appendHtmlConstant("</tr>"); } inside.appendHtmlConstant("</table>"); inside.appendHtmlConstant("</div>"); frame.render(sb, new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()), inside.toSafeHtml()); sb.appendHtmlConstant("</div>"); }