List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder appendHtmlConstant
public SafeHtmlBuilder appendHtmlConstant(String html)
From source file:taxonomy.webui.client.widget.ModelGridFactory.java
License:Open Source License
public static ModelGridPanel<VNaturalObject> createNObject() { if (objects == null) { ObjectProperties properties = GWT.create(ObjectProperties.class); List<ColumnConfig<VNaturalObject, ?>> cf = new ArrayList<ColumnConfig<VNaturalObject, ?>>(); IdentityValueProvider<VNaturalObject> identity = new IdentityValueProvider<VNaturalObject>(); final RowExpander<VNaturalObject> desc = new RowExpander<VNaturalObject>(identity, new AbstractCell<VNaturalObject>() { @Override/*from w w w.j a v a2 s .c om*/ public void render(com.google.gwt.cell.client.Cell.Context context, VNaturalObject value, SafeHtmlBuilder sb) { sb.appendHtmlConstant( "<div style='float:left; margin: 5px 5px 10px;'><img style='height:100px' src='" + (value.getAvatar() != null ? value.getAvatar() : "images/photos/all_kids.jpg") + "'/></div>"); sb.appendHtmlConstant("<p style='margin: 5px 5px 10px'><span><b>Reference:</b> " + value.getReferences() + "<span><br/><b>Description:</b> " + value.getDesc() + "</p>"); } }); cf.add(desc); cf.add(new ColumnConfig<VNaturalObject, Integer>(properties.id(), 20, "ID")); cf.add(new ColumnConfig<VNaturalObject, VKingdom>(properties.kingdom(), 50, "Kingdom")); cf.add(new SetColumnConfig<VNaturalObject, VFamily>(properties.families(), "Family")); cf.add(new ColumnConfig<VNaturalObject, VGenus>(properties.genus(), 50, "Genus")); cf.add(new ColumnConfig<VNaturalObject, VSpecies>(properties.species(), 50, "Species")); cf.add(new SetColumnConfig<VNaturalObject, String>(properties.vnNameSet(), 80, "Vietnamese Name")); cf.add(new SetColumnConfig<VNaturalObject, String>(properties.enNameSet(), 80, "English Name")); cf.add(new SetColumnConfig<VNaturalObject, VIndex>(properties.indecies(), "Indecies")); cf.add(new SetColumnConfig<VNaturalObject, VTag>(properties.tags(), "Tags")); ColumnConfig<VNaturalObject, Date> createDate = new ColumnConfig<VNaturalObject, Date>( new ValueProvider<VNaturalObject, Date>() { @Override public Date getValue(VNaturalObject object) { return object.getCreateDate() != null ? DateTimeFormat .getFormat(PredefinedFormat.DATE_TIME_MEDIUM).parse(object.getCreateDate()) : null; } @Override public void setValue(VNaturalObject object, Date value) { try { object.setCreateDate(value); } catch (Exception e) { object.setCreateDate(new Date()); } } @Override public String getPath() { return "createDate"; } }, 50, "Created Date"); createDate.setCell(new DateCell(DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_SHORT))); cf.add(createDate); ColumnConfig<VNaturalObject, Date> modifyDate = new ColumnConfig<VNaturalObject, Date>( new ValueProvider<VNaturalObject, Date>() { @Override public Date getValue(VNaturalObject object) { return object.getModifyDate() != null ? DateTimeFormat .getFormat(PredefinedFormat.DATE_TIME_MEDIUM).parse(object.getModifyDate()) : null; } @Override public void setValue(VNaturalObject object, Date value) { try { object.setCreateDate(value); } catch (Exception e) { object.setCreateDate(new Date()); } } @Override public String getPath() { return "modifyDate"; } }, 50, "Modify Date"); modifyDate.setCell(new DateCell(DateTimeFormat.getFormat(PredefinedFormat.DATE_TIME_SHORT))); cf.add(modifyDate); objects = new ModelGridPanel<VNaturalObject>(Tables.OBJECT.getName(), cf); foo(desc, objects); } return objects; }
From source file:taxonomy.webui.client.widget.ModelGridFactory.java
License:Open Source License
public static ModelGridPanel<VLocale> createLocale() { if (locales == null) { List<ColumnConfig<VLocale, ?>> cf = new ArrayList<ColumnConfig<VLocale, ?>>(); LocalesProperties properties = GWT.create(LocalesProperties.class); cf.add(new ColumnConfig<VLocale, Integer>(properties.id(), 20, "ID")); ColumnConfig<VLocale, String> name = new ColumnConfig<VLocale, String>(properties.name(), 50, "Name"); name.setCell(new AbstractCell<String>() { @Override//from w w w . j a v a 2 s . c o m public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) { sb.appendHtmlConstant( "<img src='images/flags/" + (value.equals("en") ? "gb.png" : "vn.png") + "' />"); } }); cf.add(name); cf.add(new ColumnConfig<VLocale, String>(properties.value(), 100, "Value")); locales = new ModelGridPanel<VLocale>(Tables.LOCALES.getName(), cf); } return locales; }
From source file:taxonomy.webui.client.widget.ModelGridFactory.java
License:Open Source License
public static ModelGridPanel<VGlossary> createGlossary() { if (glossary == null) { List<ColumnConfig<VGlossary, ?>> cf = new ArrayList<ColumnConfig<VGlossary, ?>>(); GlossaryProperties properties = GWT.create(GlossaryProperties.class); IdentityValueProvider<VGlossary> identity = new IdentityValueProvider<VGlossary>(); final RowExpander<VGlossary> desc = new RowExpander<VGlossary>(identity, new AbstractCell<VGlossary>() { @Override//from w w w .j a v a 2s. c o m public void render(com.google.gwt.cell.client.Cell.Context context, VGlossary value, SafeHtmlBuilder sb) { sb.appendHtmlConstant("<p style='margin: 5px 5px 10px'><b>Explaintion:</b> " + value.getExplaintion() + "</p>"); } }); cf.add(desc); cf.add(new ColumnConfig<VGlossary, Integer>(properties.id(), 20, "Id")); cf.add(new ColumnConfig<VGlossary, String>(properties.name(), 50, "Name")); cf.add(new ColumnConfig<VGlossary, String>(properties.example(), 50, "Example")); cf.add(new LocalesColumnConfig<VGlossary>(properties.locales())); glossary = new ModelGridPanel<VGlossary>(Tables.GLOSSARY.getName(), cf); desc.initPlugin(glossary.getGrid()); glossary.getGrid().addRowClickHandler(new RowClickEvent.RowClickHandler() { @Override public void onRowClick(RowClickEvent event) { ModelGridFactory.collapseAll(desc); desc.expandRow(event.getRowIndex()); } }); PagingToolBar toolbar = glossary.getPagingToolbar(); toolbar.add(new SeparatorToolItem()); TextButton btnExpand = new TextButton("Expand All", ExampleImages.INSTANCE.add()); btnExpand.addSelectHandler(new SelectEvent.SelectHandler() { @Override public void onSelect(SelectEvent event) { expandAll(desc); } }); toolbar.add(btnExpand); toolbar.add(new SeparatorToolItem()); TextButton btnCollapse = new TextButton("Collapse All", ExampleImages.INSTANCE.connect()); btnCollapse.addSelectHandler(new SelectEvent.SelectHandler() { @Override public void onSelect(SelectEvent event) { collapseAll(desc); } }); toolbar.add(btnCollapse); toolbar.add(new SeparatorToolItem()); } return glossary; }
From source file:taxonomy.webui.client.widget.SetColumnConfig.java
License:Open Source License
public SetColumnConfig(ValueProvider<M, Set<N>> valueProvider, int width, String columnName) { super(valueProvider, width, columnName); setCell(new AbstractCell<Set<N>>() { @Override/* www .j a v a 2 s . c o m*/ public void render(com.google.gwt.cell.client.Cell.Context context, Set<N> value, SafeHtmlBuilder sb) { if (value == null) return; int index = 0; for (Iterator<?> i = value.iterator(); i.hasNext();) { sb.appendHtmlConstant("<span style='color:" + ((index % 2 == 0) ? "green" : "blue") + "'>" + i.next() + "</span>"); if (i.hasNext()) { sb.appendHtmlConstant("<span> | </span>"); } index++; } } }); }
From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.experiment.design.ProtocolsViewImpl.java
License:Apache License
private void addAssignmentColumn() { Column<ProtocolRow, String> column = new Column<ProtocolRow, String>(new ButtonCell() { @Override//from ww w. ja v a 2 s .com public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { sb.appendHtmlConstant("<button type=\"button\" tabindex=\"-1\">"); sb.append(data); sb.appendHtmlConstant("</button>"); } }) { @Override public String getValue(ProtocolRow row) { return "Assign..."; } }; column.setFieldUpdater(new FieldUpdater<ProtocolRow, String>() { @Override public void update(int index, ProtocolRow row, String value) { final boolean isRowAssignable = row.isAssignable(); final String protocolType = row.getProtocolType().getLabel(); presenter.getAssignmentProfileAsync(row.getId(), new ReportingAsyncCallback<ProtocolAssignmentProfile>( FailureMessage.UNABLE_TO_LOAD_PROTOCOL_ASSIGNMENTS) { @Override public void onSuccess(ProtocolAssignmentProfile result) { if (!isRowAssignable) { NotificationPopupPanel .warning("Protocol '" + protocolType + "' is always assigned to all " + result.getProtocolSubjectType() + "s.", true, false); return; } else if (result.getNames().isEmpty()) { NotificationPopupPanel.warning("You do not have any " + result.getProtocolSubjectType() + "s to assign protocols to.", true, false); return; } new ProtocolAssignmentDialog(result, new DialogCallback<ProtocolAssignmentProfileUpdates>() { @Override public boolean onOk(ProtocolAssignmentProfileUpdates profileUpdates) { updateProtocolAssignments(profileUpdates); return true; } }).show(); } }); } }); gridView.addPermanentColumn("Assign protocols to materials/data files", column, null, 300, Style.Unit.PX); }
From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.widget.AsyncSelectionCell.java
License:Apache License
@Override public void render(Context context, String value, SafeHtmlBuilder sb) { Object key = context.getKey(); String viewData = getViewData(key); if (viewData != null && viewData.equals(value)) { clearViewData(key);//from w ww. j a v a 2s. c o m viewData = null; } int selectedIndex = getSelectedIndex(viewData == null ? value : viewData); sb.appendHtmlConstant("<select tabindex=\"-1\">"); int index = 0; for (String option : options) { if (index++ == selectedIndex) { sb.append(template.selected(option)); } else { sb.append(template.deselected(option)); } } sb.appendHtmlConstant("</select>"); }
From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.widget.DynSelectionCell.java
License:Apache License
@Override public void render(Context context, C value, SafeHtmlBuilder sb) { // Get the view data. Object key = context.getKey(); C viewData = getViewData(key);//from w w w . j a v a 2s.co m if (viewData != null && viewData.equals(value)) { clearViewData(key); viewData = null; } int selectedIndex = getSelectedIndex(viewData == null ? value : viewData); sb.appendHtmlConstant("<select tabindex=\"-1\">"); int index = 0; for (Option<C> option : options) { if (index++ == selectedIndex) { sb.append(template.selected(option.getText())); } else { sb.append(template.deselected(option.getText())); } } sb.appendHtmlConstant("</select>"); }
From source file:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.widget.EditSelectionCell.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 ww . j av a2 s . c om viewData = null; } String toRender = value; if (viewData != null) { String text = viewData.getText(); if (viewData.isEditing()) { int selectedIndex = getSelectedIndex(viewData.getText()); sb.append(template.selectStart("-1")); boolean hasGroupOpened = false; for (int index = 0; index < options.size(); index++) { String option = options.get(index); if (!option.startsWith("---")) { if (index == selectedIndex) { sb.append(template.selectedOption(option, String.valueOf(index))); } else { sb.append(template.option(option, String.valueOf(index))); } } else { if (hasGroupOpened) { sb.append(template.groupEnd()); hasGroupOpened = false; } sb.append(template.groupStart(option.replaceFirst("^---\\s*", ""))); hasGroupOpened = true; } } if (hasGroupOpened) { sb.append(template.groupEnd()); } sb.append(template.selectEnd()); 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:uk.ac.ebi.fg.annotare2.web.gwt.editor.client.view.widget.SingleSelectionCell.java
License:Apache License
@Override public void render(Context context, V value, SafeHtmlBuilder sb) { Object key = context.getKey(); V viewData = getViewData(key);//from www . j a v a 2 s . c o m if (viewData != null && viewData.equals(value)) { clearViewData(key); viewData = null; } String toRender = null; if (viewData != null) { toRender = getText(viewData); } else if (value != null) { toRender = getText(value); } 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:us.softoption.proofs.TProofDisplayCellTable.java
License:Open Source License
public void synchronizeViewToData() { /*//from w w w . j a v a 2 s. com A proof looks like 1 | F^G Ass 2 || H Ass 3 || F 1 ^E now, a line (row) on its own is fine, we can use one column for the line number, then one each for the vertical lines, the formula, and the justification. Conceptually, the line numbers are col 1, the vertical lines are subcolumns of col 2, the formula is col 3, and the justification col 4. But, if we wanted to combine several lines into a table we have the problem that the different rows might have a different number of columns. But we know If this method is called with a (max) numberOfColumns, then we can insert a colspan if needed. The colspan needs to go with the formula (ie with F^G in line 1), we are looking for left justification. Now, some proofs start with a headlevel of -1, others with a headlevel of 0 (that information is on the line itself). Then the parameter tells us the maximum nesting. So the number of columns in the table as a whole is 4 + maxSubProofLevel. So, any particular line has to look at the difference between its level and the headlevel. It that is maxSubProoflevel no colspan is needed. If it is one less than maxSubProoflevel a colspan of 2 is needed ie colspan = maxSubProoflevel - difference +1 (and colspan has to be greater than 1 to matter) */ if (fProofListModel != null) { //updating display from the model //empty old int presentCols = this.getColumnCount(); for (int i = 0; i < presentCols; i++) this.removeColumn(presentCols - i - 1); //prep new int rows = fProofListModel.getRowCount(); int cols = fProofListModel.getColumnCount(); List<TProofline> rowList = fProofListModel.proofAsProoflines(); //this.setVisibleRangeAndClearData(new Range(0,0),true); this.setRowCount(0, true); //belt and braces //this.se // Create a value updater that will be called when the value in a cell // changes. // ValueUpdater<String> valueUpdater = new ValueUpdater<String>() { // public void update(String newValue) { // Window.alert("You typed: " + newValue); // } // }; // Add the value updater to the cellList. // this.setUpdater(valueUpdater); this.setRowCount(rows, true); // Add a text column to show the line number /* TextColumn<TProofline> nameColumn = new TextColumn<TProofline>() { @Override public String getValue(TProofline object) { return (object.firstColumnGWT()); } }; this.addColumn(nameColumn, "LineNo"); */ // Column<TProofline,String> aColumn=new Column<TProofline,String>(); /* Column<TProofline, String> editableColumn = new Column<TProofline, String>( new ClickableTextCell() /* (Cell)(new TProofCustomCell())*/ /*) { @Override public String getValue(TProofline parameter) { return parameter.firstColumnGWT(); } }; this.addColumn(editableColumn /*,"LineNo"); */ /****** experiment Jan 18 2013 *****/ /* final int maxSubProofLevel = fProofListModel.maxSubProofLevel(); final SafeHtmlCell lineNoCell = new SafeHtmlCell(); final SafeHtmlCell vertLinesCell = new SafeHtmlCell(); final SafeHtmlCell formulaCell = new SafeHtmlCell(); final SafeHtmlCell justificationCell = new SafeHtmlCell(); Column<TProofline, SafeHtml> safeColumn1 = new Column<TProofline, SafeHtml>( lineNoCell) { @Override public SafeHtml getValue(TProofline parameter) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant(parameter.firstColumnGWT()); return sb.toSafeHtml() ; } }; this.addColumn(safeColumn1); Column<TProofline, SafeHtml> safeColumn2 = new Column<TProofline, SafeHtml>( vertLinesCell) { @Override public SafeHtml getValue(TProofline parameter) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant(parameter.secondColumnGWT()); return sb.toSafeHtml() ; } }; this.addColumn(safeColumn2); Column<TProofline, SafeHtml> safeColumn3 = new Column<TProofline, SafeHtml>( formulaCell) { @Override public SafeHtml getValue(TProofline parameter) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant(parameter.thirdColumnGWT(maxSubProofLevel)); return sb.toSafeHtml() ; } }; this.addColumn(safeColumn3); Column<TProofline, SafeHtml> safeColumn4 = new Column<TProofline, SafeHtml>( justificationCell) { @Override public SafeHtml getValue(TProofline parameter) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant(parameter.fourthColumnGWT()); return sb.toSafeHtml() ; } }; this.addColumn(safeColumn4); this.setRowData(rowList); //now we want to set column widths this.setWidth("100%", true); //fixed layout this.setColumnWidth(safeColumn1, 36.0, Unit.PX); this.setColumnWidth(safeColumn2, 10.0, Unit.PCT); this.setColumnWidth(safeColumn3, 70.0, Unit.PCT); this.setColumnWidth(safeColumn4, 20.0, Unit.PCT); */ /******************/ /****** experiment Feb 2013 *****/ /*we really want three columns, the line number, the vert lines and formula in one, and the justification*/ final int maxSubProofLevel = fProofListModel.maxSubProofLevel(); final SafeHtmlCell lineNoCell = new SafeHtmlCell(); final SafeHtmlCell vertLinesAndFormulaCell = new SafeHtmlCell(); // final SafeHtmlCell formulaCell = new SafeHtmlCell(); final SafeHtmlCell justificationCell = new SafeHtmlCell(); Column<TProofline, SafeHtml> safeColumn1 = new Column<TProofline, SafeHtml>(lineNoCell) { @Override public SafeHtml getValue(TProofline parameter) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant(parameter.firstColumnGWT()); return sb.toSafeHtml(); } }; this.addColumn(safeColumn1 /*,"Line No"*/); Column<TProofline, SafeHtml> safeColumn2 = new Column<TProofline, SafeHtml>(vertLinesAndFormulaCell) { @Override public SafeHtml getValue(TProofline parameter) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant(parameter.secondAndThirdColumnGWT(maxSubProofLevel)); return sb.toSafeHtml(); } }; this.addColumn(safeColumn2 /*,"Vert Lines" and formula*/); Column<TProofline, SafeHtml> safeColumn3 = new Column<TProofline, SafeHtml>(justificationCell) { @Override public SafeHtml getValue(TProofline parameter) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant(parameter.fourthColumnGWT()); return sb.toSafeHtml(); } }; this.addColumn(safeColumn3 /*,"Justification"*/); this.setRowData(rowList); //now we want to set column widths this.setWidth("100%", true); //fixed layout this.setColumnWidth(safeColumn1, 36.0, Unit.PX); //line no this.setColumnWidth(safeColumn2, 100.0, Unit.PCT); // vert lines and formula this.setColumnWidth(safeColumn3, 100.0, Unit.PX); // justification /******************/ } }