Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant.

Prototype

public SafeHtmlBuilder appendHtmlConstant(String html) 

Source Link

Document

Appends a compile-time-constant string, which will not be escaped.

Usage

From source file:accelerator.client.ui.cell.IconButtonCell.java

License:Open Source License

@Override
public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) {
    sb.appendHtmlConstant("<span");

    // /*from w w  w. j a va  2s . c om*/
    sb.appendHtmlConstant(" class=\"");
    sb.appendEscaped(JQueryUI.UI_ICON);
    sb.appendHtmlConstant(" ");
    sb.appendEscaped(icon);
    sb.appendHtmlConstant("\"");

    // ?
    if (data != null) {
        sb.appendHtmlConstant(" title=\"");
        sb.append(data);
        sb.appendHtmlConstant("\"");
    }

    sb.appendHtmlConstant(">");
    sb.appendHtmlConstant("</span>");
}

From source file:accelerator.client.ui.cell.StyleCompositeCell.java

License:Open Source License

/**
 * {@inheritDoc}/*from  ww w . j  ava2s .  com*/
 */
@Override
public void render(Context context, C value, SafeHtmlBuilder sb) {
    String divTag = "<div class=\"" + styleName + "\">";
    sb.appendHtmlConstant(divTag);
    for (HasCell<C, ?> hasCell : hasCells) {
        render(context, value, sb, hasCell);
    }
    sb.appendHtmlConstant("</div>");
}

From source file:accelerator.client.ui.cell.StyleCompositeCell.java

License:Open Source License

/**
 * {@inheritDoc}//from w  w w .  jav a  2 s. c  o  m
 */
@Override
protected <X> void render(Context context, C value, SafeHtmlBuilder sb, HasCell<C, X> hasCell) {
    Cell<X> cell = hasCell.getCell();
    sb.appendHtmlConstant("<span>");
    cell.render(context, hasCell.getValue(value), sb);
    sb.appendHtmlConstant("</span>");
}

From source file:accelerator.client.view.desktop.DesktopTaskListView.java

License:Open Source License

/**
 * CompositCell ? HasCell ?????//www.  jav a 2s .  co  m
 * 
 * @param handler
 *            ????????
 * @return HasCell ?
 */
private List<HasCell<Task, ?>> createHasCellList() {
    List<HasCell<Task, ?>> hasCellList = CollectionUtil.createArrayList();
    // ??
    hasCellList.add(new HasCell<Task, Boolean>() {
        private final CheckboxCell cell = new CheckboxCell();

        public Cell<Boolean> getCell() {
            return cell;
        }

        public FieldUpdater<Task, Boolean> getFieldUpdater() {
            return new FieldUpdater<Task, Boolean>() {
                public void update(int index, Task object, Boolean value) {
                    object.setCompleted(value);
                    DesktopTaskListView.this.presenter.updateTask(object);
                }
            };
        }

        public Boolean getValue(Task object) {
            return object.getCompleted();
        }

    });
    // ?
    hasCellList.add(new HasCell<Task, SafeHtml>() {
        private final SafeHtmlCell cell = new SafeHtmlCell();

        public Cell<SafeHtml> getCell() {
            return cell;
        }

        public FieldUpdater<Task, SafeHtml> getFieldUpdater() {
            return null;
        }

        public SafeHtml getValue(Task object) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();

            // ????????????
            if (presenter instanceof InboxPresenter) {
                return sb.toSafeHtml();
            } else if (presenter instanceof ProjectPresenter) {
                return sb.toSafeHtml();
            }

            Key projectKey = object.getProject();
            if ((projectKey != null) && projectList.containsKey(projectKey)) {
                Project p = projectList.get(projectKey);
                sb.appendHtmlConstant("<span class=\"project\">");
                sb.appendEscaped(p.getName());
                sb.appendEscaped(":");
                sb.appendHtmlConstant("</span>");
            }
            return sb.toSafeHtml();
        }
    });
    // ???
    hasCellList.add(new HasCell<Task, SafeHtml>() {
        private final SafeHtmlCell cell = new SafeHtmlCell();

        public Cell<SafeHtml> getCell() {
            return cell;
        }

        public FieldUpdater<Task, SafeHtml> getFieldUpdater() {
            return null;
        }

        public SafeHtml getValue(Task object) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            if (object.getCompleted()) {
                sb.appendHtmlConstant("<s>");
                sb.appendEscaped(object.getName());
                sb.appendHtmlConstant("</s>");
            } else {
                sb.appendEscaped(object.getName());
            }
            return sb.toSafeHtml();
        }

    });
    // ?
    hasCellList.add(new HasCell<Task, String>() {
        private final IconButtonCell cell = new IconButtonCell();

        public Cell<String> getCell() {
            cell.setIcon(JQueryUI.UI_ICON_CLOSE);
            return cell;
        }

        public FieldUpdater<Task, String> getFieldUpdater() {
            return new FieldUpdater<Task, String>() {
                public void update(int index, Task object, String value) {
                    List<Task> tasks = CollectionUtil.createArrayList();
                    tasks.add(object);
                    DesktopTaskListView.this.presenter.deleteTask(tasks);
                }
            };
        }

        public String getValue(Task object) {
            return "?";
        }
    });
    // ?
    hasCellList.add(new HasCell<Task, String>() {
        private final IconButtonCell cell = new IconButtonCell();

        public Cell<String> getCell() {
            cell.setIcon(JQueryUI.UI_ICON_PENCIL);
            return cell;
        }

        public FieldUpdater<Task, String> getFieldUpdater() {
            return new FieldUpdater<Task, String>() {
                public void update(int index, Task object, String value) {
                    DesktopTaskListView.this.editTask(object);
                }
            };
        }

        public String getValue(Task object) {
            return "?";
        }
    });
    // ??
    hasCellList.add(new HasCell<Task, SafeHtml>() {
        private final SafeHtmlCell cell = new SafeHtmlCell();
        private final DateTimeFormat format = DateTimeFormat.getFormat("yyyyMMdd");

        public Cell<SafeHtml> getCell() {
            return cell;
        }

        public FieldUpdater<Task, SafeHtml> getFieldUpdater() {
            return null;
        }

        public SafeHtml getValue(Task object) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            Date d = object.getDueDate();
            if (d != null) {
                sb.appendHtmlConstant("<span class=\"duedate\">");
                sb.appendEscaped(format.format(d));
                sb.appendHtmlConstant("</span>");
            }
            return sb.toSafeHtml();
        }
    });
    // ??
    hasCellList.add(new HasCell<Task, SafeHtml>() {
        private final SafeHtmlCell cell = new SafeHtmlCell();

        public Cell<SafeHtml> getCell() {
            return cell;
        }

        public FieldUpdater<Task, SafeHtml> getFieldUpdater() {
            return null;
        }

        public SafeHtml getValue(Task object) {
            SafeHtmlBuilder sb = new SafeHtmlBuilder();
            if (DesktopTaskListView.this.tagMap != null) {
                List<Key> tagKeys = object.getTags();
                for (Key tagKey : tagKeys) {
                    if (DesktopTaskListView.this.tagMap.containsKey(tagKey)) {
                        Tag tag = DesktopTaskListView.this.tagMap.get(tagKey);
                        sb.appendHtmlConstant("<span class=\"tag\">");
                        sb.appendEscaped(tag.getName());
                        sb.appendHtmlConstant("</span>");
                    }
                }
            }
            return sb.toSafeHtml();
        }
    });
    return hasCellList;
}

From source file:cc.alcina.framework.gwt.client.cell.EditTextCell.java

License:Apache License

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    Object key = context.getKey();
    ViewData viewData = getViewData(key);
    if (viewData != null && !viewData.isEditing() && value != null && value.equals(viewData.getText())) {
        clearViewData(key);//from w w  w . j a v  a2 s .c o  m
        viewData = null;
    }
    String toRender = value;
    if (viewData != null) {
        String text = viewData.getText();
        if (viewData.isEditing()) {
            /*
             * Do not use the renderer in edit mode because the value of a
             * text input element is always treated as text. SafeHtml isn't
             * valid in the context of the value attribute.
             */
            sb.append(template.input(text));
            return;
        } else {
            // The user pressed enter, but view data still exists.
            toRender = text;
        }
    }
    if (toRender != null && toRender.trim().length() > 0) {
        sb.append(renderer.render(toRender));
    } else {
        /*
         * Render a blank space to force the rendered element to have a
         * height. Otherwise it is not clickable.
         */
        sb.appendHtmlConstant("\u00A0");
    }
}

From source file:cc.alcina.framework.gwt.client.cell.PropertyTextCell.java

License:Apache License

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    Object key = context.getKey();
    ViewData viewData = getViewData(key);
    if (viewData != null && !viewData.isEditing() && value != null && value.equals(viewData.getText())) {
        clearViewData(key);//  w w  w  . j a  v a 2  s . c  o  m
        viewData = null;
    }
    String toRender = value;
    if (viewData != null) {
        String text = viewData.getText();
        if (text == null) {
            text = "";
        }
        if (viewData.isEditing()) {
            /*
             * Do not use the renderer in edit mode because the value of a
             * text input element is always treated as text. SafeHtml isn't
             * valid in the context of the value attribute.
             */
            sb.append(template.input(text));
            return;
        } else {
            // The user pressed enter, but view data still exists.
            toRender = text;
        }
    }
    sb.appendHtmlConstant("<span class='property-text-cell'>");
    if (toRender != null && toRender.trim().length() > 0) {
        sb.append(renderer.render(toRender));
    } else {
        /*
         * Render a blank space to force the rendered element to have a
         * height. Otherwise it is not clickable.
         */
        sb.appendHtmlConstant("\u00A0");
    }
    sb.appendHtmlConstant("</span>");
}

From source file:ch.cern.atlas.apvs.client.widget.EditTextCell.java

License:Apache License

@Override
public void render(Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    Object key = context.getKey();
    ViewData viewData = getViewData(key);
    if (viewData != null && !viewData.isEditing() && value != null && value.equals(viewData.getText())) {
        clearViewData(key);/*from www.  j  a v  a 2 s  .  co  m*/
        viewData = null;
    }

    String toRender = value;
    if (viewData != null) {
        String text = viewData.getText();
        if (viewData.isEditing()) {
            /*
             * Do not use the renderer in edit mode because the value of a text
             * input element is always treated as text. SafeHtml isn't valid in the
             * context of the value attribute.
             */
            sb.append(template.input(text));
            return;
        } else {
            // The user pressed enter, but view data still exists.
            toRender = text;
        }
    }

    if (toRender != null && toRender.trim().length() > 0) {
        sb.append(renderer.render(toRender));
    } else {
        /*
         * Render a blank space to force the rendered element to have a height.
         * Otherwise it is not clickable.
         */
        sb.appendHtmlConstant("\u00A0");
    }
}

From source file:cimav.client.view.common.EmpleadoListCell.java

@Override
public void render(Cell.Context context, EmpleadoBase value, SafeHtmlBuilder sb) {
    if (value == null) {
        return;//from w w w . j a  va 2s  .  c o  m
    }

    boolean isSelected = this.selectionModel != null && this.selectionModel.getSelectedObject() != null
            && this.selectionModel.getSelectedObject().equals(value);

    String es_null = "---";
    String grupoStr = value.getGrupo() != null ? value.getGrupo().getCode() : es_null;
    boolean tieneEstimulos = EGrupo.CYT.equals(value.getGrupo());
    if (tieneEstimulos) {
        String estimulos = value.getEstimulosProductividad() != null ? "" + value.getEstimulosProductividad()
                : es_null;
        grupoStr = grupoStr + "(" + estimulos + ")";
    }
    String estimulosCyt = value.getEstimulosProductividad() != null ? "" + value.getEstimulosProductividad()
            : es_null;
    String deptoCodeStr = value.getDepartamento() != null ? value.getDepartamento().getCode() : es_null;
    String deptoNameStr = value.getDepartamento() != null ? value.getDepartamento().getName() : es_null;
    String nivelStr = value.getNivel() != null ? value.getNivel().getCode() : es_null;
    String nivelNombreStr = value.getNivel() != null ? value.getNivel().getName() : es_null;
    String sedeStr = value.getSede() != null ? value.getSede().getAbrev() : es_null;
    DateTimeFormat dtf = DateTimeFormat.getFormat("dd/MMM/yyyy");
    String fechaAntStr = dtf.format(value.getFechaAntiguedad());
    String diasMesesAniosStr = "Nulo";
    if (value.getPantYears() != null) {
        diasMesesAniosStr = value.getPantYears() + " aos(s), " + value.getPantMonths() + " mese(s), "
                + value.getPantDayOdd() + " das(s)";
    }

    String td_selec_id = "td_selec_" + value.getId();

    String html = "<table width='100%' cellspacing='0' cellpadding='0' style='cursor: pointer; text-align: left; vertical-align: middle; border-bottom:1px solid lightgray;'>\n"
            + " <tbody> \n" + "  <tr >\n" + "    <td rowspan='6' id='" + td_selec_id
            + "_left' class'td_selection' style='height:auto; width: 5px; SELECTED_COLOR_REEMPLAZO'></td>\n"
            + "    <td colspan='3' style='height:10px;'></td>\n" + "    <td rowspan='6' id='" + td_selec_id
            + "_right' class'td_selection' style='height:auto; width: 5px; SELECTED_COLOR_REEMPLAZO'></td>\n"
            + "  </tr>\n" + "  <tr>\n" + "    <td width='78px' rowspan='3' style='text-align: center;'>"
            + "         <img data-toggle='tooltip' data-placement='left' title='TOOL_TIP_ID_REEMPLAZO' src='URL_FOTO_REEMPLAZO' style='border:1px solid lightgray; margin-top: 3px; border-radius:50%; padding:2px;'/>"
            + "    </td>\n" + "  </tr>\n" + "  <tr>\n"
            + "    <td colspan='2' style='vertical-align: top;'><h5 style='margin-top: 0px; margin-bottom: 0px;'>NOMBRE_REEMPLAZO</h5></td>\n"
            + "  </tr>\n" + "  <tr >\n" + "    <td  colspan='1' style='line-height: 1.8;'> "
            + "         <code class='label-cyt-grp-niv'><span >CODE_REEMPLAZO</span></code> "
            + "         <code class='label-cyt-grp-niv'><span >GRUPO_REEMPLAZO</span></code> "
            + "         <code class='label-cyt-grp-niv' data-toggle='tooltip' data-placement='left' title='TOOL_TIP_NIVEL_REEMPLAZO'><span >NIVEL_REEMPLAZO</span></code> "
            + "         <code class='label-cyt-grp-niv'><span >SEDE_REEMPLAZO</span></code> "
            + "         <code class='label-cyt-grp-niv' data-toggle='tooltip' data-placement='left' title='DATO_ANTIGUEDAD_REEMPLAZO'><span >FECHA_ANTIGUEDAD_REEMPLAZO</span></code> "
            + "    </td>\n" + "  </tr>\n" + "  <tr style='border-bottom:1px solid lightgray;'>\n"
            + "    <td style='text-align:center;' ></td>\n" + "    <td colspan='3' style='height:10px;'></td>\n"
            + "  </tr>\n" + " </tbody> " + "</table>";

    if (isSelected) {
        html = html.replace("SELECTED_COLOR_REEMPLAZO", "background-color: " + colorSelected + ";"); // 628cd5;");
    } else if (value.isDirty() != null && value.isDirty()) {
        html = html.replace("SELECTED_COLOR_REEMPLAZO", "background-color: lightgray;");
    } else {
        html = html.replace("SELECTED_COLOR_REEMPLAZO", "background-color: #F8F8F8;");
    }

    try {

        String idReem = "---";
        if (value.getId() != null) {
            idReem = value.getId().toString();
        }
        html = html.replace("TOOL_TIP_ID_REEMPLAZO", idReem);
        html = html.replace("CODE_REEMPLAZO", chkStrNull(value.getCode()));
        html = html.replace("URL_FOTO_REEMPLAZO", chkStrNull(value.getUrlPhoto()));
        html = html.replace("NOMBRE_REEMPLAZO", chkStrNull(value.getName()));
        html = html.replace("GRUPO_REEMPLAZO", chkStrNull(grupoStr));
        html = html.replace("TOOL_TIP_NIVEL_REEMPLAZO", chkStrNull(nivelNombreStr));
        html = html.replace("NIVEL_REEMPLAZO", chkStrNull(nivelStr));
        html = html.replace("DEPTO_CODIGO_REEMPLAZO", chkStrNull(deptoCodeStr));
        html = html.replace("TOOL_TIP_DEPTO_REEMPLAZO", chkStrNull(deptoNameStr));
        html = html.replace("SEDE_REEMPLAZO", chkStrNull(sedeStr));
        html = html.replace("FECHA_ANTIGUEDAD_REEMPLAZO", chkStrNull(fechaAntStr));
        html = html.replace("DATO_ANTIGUEDAD_REEMPLAZO", chkStrNull(diasMesesAniosStr));
        if (value.getId() != null) {
            html = html.replace("ID_REEMPLAZO", value.getId().toString());
        } else {
            html = html.replace("ID_REEMPLAZO", "---");
        }

        sb.appendHtmlConstant(html);
    } catch (Exception e) {
        Window.alert("Catch it! " + html);
    }
}

From source file:cimav.client.view.nomina.HorasExtrasUI.java

private void initTableColumns() {

    // id + icon remove
    Column<HoraExtra, String> iconCol = new Column<HoraExtra, String>(
            new NomIconInputCell(NomIconInputCell.HORA_EXTRA)) {
        @Override//from ww  w.j a  va 2s .c o m
        public String getValue(HoraExtra object) {
            return "" + object.getId();
        }
    };
    dataGrid.addColumn(iconCol, "");
    dataGrid.setColumnWidth(iconCol, 16, Style.Unit.PX);

    // Semana
    Column<HoraExtra, SafeHtml> semanaCol = new Column<HoraExtra, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(HoraExtra object) {
            SafeHtmlBuilder a = new SafeHtmlBuilder();
            a.appendHtmlConstant("<span>" + object.getWeekOfYear() + "</span>");
            //                if (object.getConcepto().getSuma()) {
            //                    a.appendHtmlConstant("<span>" + object.getConcepto().getName() + "</span>");
            //                } else {
            //                    a.appendHtmlConstant("<span style='color: grey; font-style: italic;'>" + object.getConcepto().getName() + "</span>");
            //                }
            return a.toSafeHtml();
        }
    };
    dataGrid.addColumn(semanaCol, "Semana");
    dataGrid.setColumnWidth(semanaCol, 120, Style.Unit.PCT);

    // Fecha
    Column<HoraExtra, Date> diaCol = new Column<HoraExtra, Date>(diaCell) {
        @Override
        public Date getValue(HoraExtra object) {
            return object.getDia();
        }
    };
    diaCol.setFieldUpdater(new FieldUpdater<HoraExtra, Date>() {
        @Override
        public void update(int index, HoraExtra object, Date value) {
            try {
                object.setDia(value);

                //object.ajustar();

                getHorasExtrasREST().update(object);
            } catch (Exception ex) {

            }
            diaCell.clearViewData(object);
            int absRowIndex = index;
            dataGrid.redrawRow(absRowIndex);
        }
    });
    dataGrid.addColumn(diaCol, "Da (fecha)");
    dataGrid.setColumnWidth(diaCol, 120, Style.Unit.PX);

    // Horas
    Column<HoraExtra, String> horasCol = new Column<HoraExtra, String>(horasCell) {
        @Override
        public String getValue(HoraExtra object) {
            Double result = object == null || object.getHoras() == null ? 0 : object.getHoras();
            return Double.toString(result);
        }
    };
    horasCol.setFieldUpdater(new FieldUpdater<HoraExtra, String>() {
        @Override
        public void update(int index, HoraExtra object, String value) {
            try {
                Double horas = Double.parseDouble(value);
                object.setHoras(horas);

                //object.ajustar();

                getHorasExtrasREST().update(object);
            } catch (Exception ex) {

            }
            horasCell.clearViewData(object);
            int absRowIndex = index;
            dataGrid.redrawRow(absRowIndex);
        }
    });
    horasCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    Header<String> forzarFooter = new Header<String>(new TextCell()) {
        @Override
        public String getValue() {
            return "  ";
        }
    };
    dataGrid.addColumn(horasCol, new SafeHtmlHeader(SafeHtmlUtils.fromString("Horas")), forzarFooter);
    dataGrid.setColumnWidth(horasCol, 68, Style.Unit.PX);

}

From source file:cimav.client.view.nomina.NomCantidadInputCell.java

@Override
public void render(Cell.Context context, String value, SafeHtmlBuilder sb) {
    // Get the view data.
    Object key = context.getKey();
    TextInputCell.ViewData viewData = this.getViewData(key);
    if (viewData != null && viewData.getCurrentValue().equals(value)) {
        clearViewData(key);//from   w  ww  .j  av a2s  . c om
        viewData = null;
    }

    // boolean isEditing = this.isEditing(context, null, value);
    String s = (viewData != null) ? viewData.getCurrentValue() : value;
    if (s == null) // || isEditing)
    {
        sb.appendHtmlConstant("<input type=\"text\" tabindex=\"-1\"></input>");
    } else {
        // this is where we set value, size, style
        sb.append(template.input(s,
                "width: 100%; text-align: inherit; margin: 0px; height: 22px !important; font-size:11px;"));
    }
}