List of usage examples for com.google.gwt.user.cellview.client Column setHorizontalAlignment
@Override public void setHorizontalAlignment(HorizontalAlignmentConstant align)
The new horizontal alignment will apply the next time the table is rendered.
From source file:cimav.client.view.catalogos.tabulador.NivelesUi.java
/** * Add the columns to the table.//from w ww . ja v a2 s . c o m */ private void initTableColumns(ColumnSortEvent.ListHandler<Tabulador> sortHandler) { // ID Column<Tabulador, String> idCol = new Column<Tabulador, String>(new TextCell()) { @Override public String getValue(Tabulador object) { return object.getId().toString(); } }; dataGrid.addColumn(idCol, "ID"); dataGrid.setColumnWidth(idCol, 40, Style.Unit.PX); // Code Column<Tabulador, String> codigoCol = new Column<Tabulador, String>((new TextCell())) { @Override public String getValue(Tabulador object) { return object.getCode(); } }; codigoCol.setSortable(true); sortHandler.setComparator(codigoCol, new Comparator<Tabulador>() { @Override public int compare(Tabulador o1, Tabulador o2) { return o1.getCode().compareTo(o2.getCode()); } }); dataGrid.addColumn(codigoCol, "Cdigo"); dataGrid.setColumnWidth(codigoCol, 70, Style.Unit.PX); // Sueldo Column<Tabulador, String> sueldoCol = new Column<Tabulador, String>(new TextCell()) { @Override public String getValue(Tabulador object) { NumberFormat fmt = NumberFormat.getCurrencyFormat(); String output = object.getSueldo().toString(); Double value = Double.parseDouble(output); String formatted = fmt.format(value); return formatted; } }; sueldoCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); sueldoCol.setSortable(true); sortHandler.setComparator(sueldoCol, new Comparator<Tabulador>() { @Override public int compare(Tabulador o1, Tabulador o2) { return o1.getSueldo().compareTo(o2.getSueldo()); } }); dataGrid.addColumn(sueldoCol, "Sueldo"); dataGrid.setColumnWidth(sueldoCol, 60, Style.Unit.PX); // matDidacticos Column<Tabulador, String> matDidacticosCol = new Column<Tabulador, String>(new TextCell()) { @Override public String getValue(Tabulador object) { return object.getMatDidacticos().toString(); } }; dataGrid.addColumn(matDidacticosCol, "Mat. Didacticos"); dataGrid.setColumnWidth(matDidacticosCol, 60, Style.Unit.PX); // honorarios Column<Tabulador, String> honorariosCol = new Column<Tabulador, String>(new TextCell()) { @Override public String getValue(Tabulador object) { return object.getHonorarios().toString(); } }; dataGrid.addColumn(honorariosCol, "Honorarios"); dataGrid.setColumnWidth(honorariosCol, 60, Style.Unit.PX); // compGarantizadaCol Column<Tabulador, String> compGarantizadaCol = new Column<Tabulador, String>(new TextCell()) { @Override public String getValue(Tabulador object) { return object.getCompGarantizada().toString(); } }; dataGrid.addColumn(compGarantizadaCol, "Comp. Garantizada"); dataGrid.setColumnWidth(compGarantizadaCol, 60, Style.Unit.PX); // cargaAdmin Column<Tabulador, String> cargaAdminCol = new Column<Tabulador, String>(new TextCell()) { @Override public String getValue(Tabulador object) { return object.getCargaAdmin().toString(); } }; dataGrid.addColumn(cargaAdminCol, "Carga Admin."); dataGrid.setColumnWidth(cargaAdminCol, 60, Style.Unit.PX); }
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 v a2s. c om 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.NominaFaltasUI.java
private void initTableColumns() { // id + icon remove Column<Incidencia, String> iconCol = new Column<Incidencia, String>( new NomIconInputCell(NomIconInputCell.FALTA)) { @Override/* w w w. j a va 2s. co m*/ public String getValue(Incidencia object) { return "" + object.getId(); } }; dataGrid.addColumn(iconCol, ""); dataGrid.setColumnWidth(iconCol, 16, Style.Unit.PX); // Id+Tipo Column<Incidencia, SafeHtml> tipoCol = new Column<Incidencia, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Incidencia object) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant( "<div style='outline-style:none; white-space: nowrap;'><strong style='font-size: 12px; padding-right: 3px;'>" + object.getCode() + "</strong> " + "<span>" + object.getTipo().getDescripcion() + "</span></div>"); return sb.toSafeHtml(); } }; dataGrid.addColumn(tipoCol, "Tipo"); dataGrid.setColumnWidth(tipoCol, 60, Style.Unit.PCT); // Fecha Column<Incidencia, Date> fechaCol = new Column<Incidencia, Date>(fechaInicioCell) { @Override public Date getValue(Incidencia object) { return object.getFechaInicial(); } }; fechaCol.setFieldUpdater(new FieldUpdater<Incidencia, Date>() { @Override public void update(int index, Incidencia object, Date value) { try { object.setFechaInicial(value); object.ajustar(); getIncidenciasREST().update(object); } catch (Exception ex) { } fechaInicioCell.clearViewData(object); int absRowIndex = index; dataGrid.redrawRow(absRowIndex); } }); dataGrid.addColumn(fechaCol, "Fecha"); dataGrid.setColumnWidth(fechaCol, 120, Style.Unit.PX); // Dias Column<Incidencia, String> diasCol = new Column<Incidencia, String>(diasCell) { @Override public String getValue(Incidencia object) { Integer result = object == null || object.getDias() == null ? 0 : object.getDias(); return Integer.toString(result); } }; diasCol.setFieldUpdater(new FieldUpdater<Incidencia, String>() { @Override public void update(int index, Incidencia object, String value) { try { Integer dias = Integer.parseInt(value); object.setDias(dias); object.ajustar(); getIncidenciasREST().update(object); } catch (Exception ex) { } diasCell.clearViewData(object); int absRowIndex = index; dataGrid.redrawRow(absRowIndex); } }); diasCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); dataGrid.addColumn(diasCol, "Das"); dataGrid.setColumnWidth(diasCol, 88, Style.Unit.PX); // Dias Habiles Column<Incidencia, SafeHtml> diasHabilesCols = new Column<Incidencia, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Incidencia object) { Integer result = object == null || object.getDiasHabiles() == null ? 0 : object.getDiasHabiles(); SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant( "<div style='outline-style:none; white-space: nowrap;'><strong style='font-size: 12px; padding-right: 6px;'>" + Integer.toString(result) + "</strong></div>"); return sb.toSafeHtml(); } }; diasHabilesCols.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); dataGrid.addColumn(diasHabilesCols, new SafeHtmlHeader(SafeHtmlUtils.fromString("Hbiles"))); dataGrid.setColumnWidth(diasHabilesCols, 68, Style.Unit.PX); // Dias Inhabiles Column<Incidencia, SafeHtml> diasInhabiles = new Column<Incidencia, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Incidencia object) { Integer result = object == null || object.getDiasInhabiles() == null ? 0 : object.getDiasInhabiles(); SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant( "<div style='outline-style:none; white-space: nowrap;'><strong style='font-size: 12px; padding-right: 6px;'>" + Integer.toString(result) + "</strong></div>"); return sb.toSafeHtml(); } }; diasInhabiles.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); dataGrid.addColumn(diasInhabiles, new SafeHtmlHeader(SafeHtmlUtils.fromString("Inhbiles"))); dataGrid.setColumnWidth(diasInhabiles, 68, Style.Unit.PX); // Dias Restantes Column<Incidencia, SafeHtml> diasRestantesCol = new Column<Incidencia, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Incidencia object) { Integer result = object == null || object.getDiasRestantes() == null ? 0 : object.getDiasRestantes(); SafeHtmlBuilder sb = new SafeHtmlBuilder(); sb.appendHtmlConstant( "<div style='outline-style:none; white-space: nowrap;'><strong style='font-size: 12px; padding-right: 6px;'>" + Integer.toString(result) + "</strong></div>"); return sb.toSafeHtml(); } }; diasRestantesCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); dataGrid.addColumn(diasRestantesCol, new SafeHtmlHeader(SafeHtmlUtils.fromString("Restantes"))); dataGrid.setColumnWidth(diasRestantesCol, 68, Style.Unit.PX); // Folio Column<Incidencia, String> folioCol = new Column<Incidencia, String>(folioCell) { @Override public String getValue(Incidencia object) { return object.getFolio(); } }; folioCol.setFieldUpdater(new FieldUpdater<Incidencia, String>() { @Override public void update(int index, Incidencia object, String value) { try { object.setFolio(value); getIncidenciasREST().update(object); } catch (Exception ex) { } folioCell.clearViewData(object); int absRowIndex = index; dataGrid.redrawRow(absRowIndex); } }); Header<String> forzarFooter = new Header<String>(new TextCell()) { @Override public String getValue() { return " "; } }; dataGrid.addColumn(folioCol, new SafeHtmlHeader(SafeHtmlUtils.fromString("Folio")), forzarFooter); dataGrid.setColumnWidth(folioCol, 40, Style.Unit.PCT); }
From source file:cimav.client.view.nomina.NominaMovimientosUI.java
private void initTableColumns() { // Concepto//from w w w. j a v a 2 s. co m Column<Movimiento, SafeHtml> conceptoCol = new Column<Movimiento, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Movimiento object) { SafeHtmlBuilder a = new SafeHtmlBuilder(); 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(conceptoCol, "Concepto"); dataGrid.setColumnWidth(conceptoCol, 80, Style.Unit.PCT); // Cantidad Column<Movimiento, SafeHtml> cantidadCol = new Column<Movimiento, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Movimiento object) { String result = Utils.formatCantidad(object.getCantidad()); SafeHtmlBuilder a = new SafeHtmlBuilder(); if (object.getConcepto().getSuma()) { a.appendHtmlConstant("<span style='padding-right: 5px;'>" + result + "</span>"); } else { a.appendHtmlConstant("<span style='padding-right: 5px; color: grey; font-style: italic;'>" + result + "</span>"); } return a.toSafeHtml(); } }; cantidadCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); SafeHtmlHeader headerCantidad = new SafeHtmlHeader(new SafeHtml() { @Override public String asString() { return "<p style='text-align:center; margin-bottom: 0px;'>Cantidad</p>"; } }); if (ETipoConcepto.PERCEPCION.equals(this.tipoConcepto) || ETipoConcepto.DEDUCCION.equals(this.tipoConcepto)) { SafeHtmlHeader footerCantidad = new SafeHtmlHeader(new SafeHtml() { @Override public String asString() { String result = "0.00"; List<Movimiento> items = dataGrid.getVisibleItems(); if (!items.isEmpty()) { // create MathContext object with 2 precision BigDecimal totalPercepciones = BigDecimal.ZERO; for (Movimiento nomQuin : items) { if (nomQuin.getConcepto().getSuma()) { // si el concepto suma (ej. Despensa no suma) totalPercepciones = totalPercepciones.add(nomQuin.getCantidad()); } } result = Utils.formatCurrency(totalPercepciones); } return "<p style=\"text-align:right;\">" + result.trim() + "</p>"; } }); dataGrid.addColumn(cantidadCol, headerCantidad, footerCantidad); } else { dataGrid.addColumn(cantidadCol, headerCantidad); } dataGrid.setColumnWidth(cantidadCol, 20, Style.Unit.PCT); }
From source file:cimav.client.view.nomina.NominaRepercucionesUI.java
private void initTableColumns() { // Concepto/*from w ww . ja va 2 s. c o m*/ Column<Movimiento, SafeHtml> conceptoCol = new Column<Movimiento, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Movimiento object) { SafeHtmlBuilder a = new SafeHtmlBuilder(); 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(conceptoCol, "Concepto"); dataGrid.setColumnWidth(conceptoCol, 80, Style.Unit.PCT); // Cantidad Column<Movimiento, SafeHtml> cantidadCol = new Column<Movimiento, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Movimiento object) { String result = Utils.formatCantidad(object.getCantidad()); SafeHtmlBuilder a = new SafeHtmlBuilder(); if (object.getConcepto().getSuma()) { a.appendHtmlConstant("<span style='padding-right: 5px;'>" + result + "</span>"); } else { a.appendHtmlConstant("<span style='padding-right: 5px; color: grey; font-style: italic;'>" + result + "</span>"); } return a.toSafeHtml(); } }; cantidadCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); SafeHtmlHeader headerCantidad = new SafeHtmlHeader(new SafeHtml() { @Override public String asString() { return "<p style='text-align:center; margin-bottom: 0px;'>Empleado</p>"; } }); dataGrid.addColumn(cantidadCol, headerCantidad); dataGrid.setColumnWidth(cantidadCol, 20, Style.Unit.PCT); // Cantidad_empresa Column<Movimiento, SafeHtml> cantidadEmpresaCol = new Column<Movimiento, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Movimiento object) { String result = Utils.formatCantidad(object.getCantidadEmpresa()); SafeHtmlBuilder a = new SafeHtmlBuilder(); a.appendHtmlConstant("<span style='padding-right: 5px;'>" + result + "</span>"); return a.toSafeHtml(); } }; cantidadEmpresaCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); SafeHtmlHeader headerCantidadEmpresa = new SafeHtmlHeader(new SafeHtml() { @Override public String asString() { return "<p style='text-align:center; margin-bottom: 0px;'>Empresa</p>"; } }); dataGrid.addColumn(cantidadEmpresaCol, headerCantidadEmpresa); dataGrid.setColumnWidth(cantidadEmpresaCol, 20, Style.Unit.PCT); }
From source file:cimav.client.view.nomina.NominaSaldoUI.java
/** * Add the columns to the table./*from w w w . j av a 2s. c o m*/ */ private void initTableColumns() { // id + icon remove Column<Movimiento, String> iconCol = new Column<Movimiento, String>( new NomIconInputCell(NomIconInputCell.SALDO)) { @Override public String getValue(Movimiento object) { return "" + object.getId(); } }; Header<String> forzarFooter = new Header<String>(new TextCell()) { @Override public String getValue() { return " "; } }; dataGrid.addColumn(iconCol, new SafeHtmlHeader(SafeHtmlUtils.fromString("")), forzarFooter); dataGrid.setColumnWidth(iconCol, 16, Style.Unit.PX); // Concepto Column<Movimiento, String> conceptoCol = new Column<Movimiento, String>((new TextCell())) { @Override public String getValue(Movimiento object) { Concepto concepto = object.getConcepto(); return concepto.getName(); } }; dataGrid.addColumn(conceptoCol, "Concepto"); dataGrid.setColumnWidth(conceptoCol, 100, Style.Unit.PCT); // Permanente Column<Movimiento, Boolean> permanenteCol = new Column<Movimiento, Boolean>(permanenteCell) { @Override public Boolean getValue(Movimiento object) { Boolean result = object.getPermanente(); return result; } }; permanenteCol.setFieldUpdater(new FieldUpdater<Movimiento, Boolean>() { @Override public void update(int index, Movimiento object, Boolean value) { try { object.setPermanente(value); getNominaQuincenalsREST().update(object); } catch (Exception e) { } saldoCell.clearViewData(object); int absRowIndex = index; dataGrid.redrawRow(absRowIndex); } }); permanenteCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); TextHeader permanenteHeader = new TextHeader(""); permanenteHeader.setHeaderStyleNames("permanenteHeader"); dataGrid.addColumn(permanenteCol, permanenteHeader); dataGrid.setColumnWidth(permanenteCol, 20, Style.Unit.PX); // Pago Column<Movimiento, SafeHtml> pagoCol = new Column<Movimiento, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(Movimiento object) { BigDecimal pago = object == null || object.getPago() == null ? BigDecimal.ZERO : object.getPago(); Utils.formatCantidad(pago); SafeHtmlBuilder a = new SafeHtmlBuilder(); if (object.getPermanente()) { a.appendHtmlConstant( "<span style='padding-right:3px; '>" + Utils.formatCantidad(pago) + "</span>"); } else { a.appendHtmlConstant("<span style='padding-right:3px; color: grey; font-style: italic;'>" + Utils.formatCantidad(pago) + "</span>"); } return a.toSafeHtml(); } }; pagoCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); dataGrid.addColumn(pagoCol, "Pago"); dataGrid.setColumnWidth(pagoCol, 90, Style.Unit.PCT); // Saldo Column<Movimiento, String> saldoCol = new Column<Movimiento, String>(saldoCell) { @Override public String getValue(Movimiento object) { BigDecimal result = object == null || object.getSaldo() == null ? BigDecimal.ZERO : object.getSaldo(); return Utils.formatCantidad(result); } }; saldoCol.setFieldUpdater(new FieldUpdater<Movimiento, String>() { @Override public void update(int index, Movimiento object, String value) { BigDecimal nuevoSaldo; try { nuevoSaldo = new BigDecimal(value.trim()); object.setSaldo(nuevoSaldo); getNominaQuincenalsREST().update(object); } catch (Exception e) { } saldoCell.clearViewData(object); int absRowIndex = index; dataGrid.redrawRow(absRowIndex); } }); saldoCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); dataGrid.addColumn(saldoCol, "Saldo"); dataGrid.setColumnWidth(saldoCol, 110, Style.Unit.PX); // Quincenas Column<Movimiento, String> quincenasCol = new Column<Movimiento, String>(quincenasCell) { @Override public String getValue(Movimiento object) { Integer result = object == null || object.getNumQuincenas() == null ? 0 : object.getNumQuincenas(); return Integer.toString(result); } }; quincenasCol.setFieldUpdater(new FieldUpdater<Movimiento, String>() { @Override public void update(int index, Movimiento object, String value) { // Push the changes into the MyDTO. At this point, you could send an // asynchronous request to the server to update the database. // value es el valor capturado // si es valido, pasar al object y a la DB // NOTA requiere de un Ajax con icono chiquito // Tiene su propio loading el DataGrid // Intenta convertir el value a Integer // si falla lo deja como estaba // si no falla lo actualiza Integer numQuin = 0; try { numQuin = Integer.parseInt(value.trim()); object.setNumQuincenas(numQuin); getNominaQuincenalsREST().update(object); } catch (NumberFormatException | NullPointerException e) { } quincenasCell.clearViewData(object); int absRowIndex = index; dataGrid.redrawRow(absRowIndex); } }); quincenasCol.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); dataGrid.addColumn(quincenasCol, "Veces"); dataGrid.setColumnWidth(quincenasCol, 68, Style.Unit.PX); }
From source file:com.Administration.client.Administration.java
License:Apache License
/** * ? ? /*from w ww .ja v a2 s . c o m*/ */ private void initTable() { // ? Column<LinkData, String> codeColumn = new Column<LinkData, String>(new TextCell()) { // C ? - ? ? @Override public String getValue(LinkData object) { // ? ? ? ? return object.getCode(); } }; codeColumn.setSortable(true); // ? sortHandler.setComparator(codeColumn, new Comparator<LinkData>() { // ? // , ? @Override public int compare(LinkData o1, LinkData o2) { // ? ?? if (o1 == o2) { return 0; } if (o1 != null) { return (o2 != null) ? o1.getCode().compareTo(o2.getCode()) : 1; } return -1; } }); cellTable.addColumn(codeColumn, "Short Link"); // ? // ? ?? Column<LinkData, String> originalLinkColumn = new Column<LinkData, String>(new EditTextCell()) { @Override public String getValue(LinkData object) { return object.getLink(); } }; originalLinkColumn.setSortable(true); sortHandler.setComparator(originalLinkColumn, new Comparator<LinkData>() { @Override public int compare(LinkData o1, LinkData o2) { if (o1 == o2) { return 0; } if (o1 != null) { return (o2 != null) ? o1.getLink().compareTo(o2.getLink()) : 1; } return -1; } }); cellTable.addColumn(originalLinkColumn, "Original Link"); originalLinkColumn.setFieldUpdater(new FieldUpdater<LinkData, String>() { // ? ? @Override public void update(int index, final LinkData object, final String value) { // ?? ? // ? ? AdministrationServiceInterface.App.getInstance().setOriginalLink(object.getId(), value, new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { // ? ? ??? label.setHTML("<h4>Connection error!<br>Can't update data!<h4>"); // ? } @Override public void onSuccess(Boolean result) { // ? ? if (!result) { // ? ? ? ? label.setHTML("<h4>Server error!<h4>"); // } else { // ? ? object.setLink(value); dataProvider.refresh(); } } }); } }); DateTimeFormat dateFormat = DateTimeFormat.getFormat("dd MMM yyyy"); // // ? ?? Column<LinkData, Date> createDateColumn = new Column<LinkData, Date>(new DateCell(dateFormat)) { @Override public Date getValue(LinkData object) { return object.getCreateDate(); } }; createDateColumn.setSortable(true); sortHandler.setComparator(createDateColumn, new Comparator<LinkData>() { @Override public int compare(LinkData o1, LinkData o2) { if (o1 == o2) { return 0; } if (o1 != null) { return (o2 != null) ? o1.getCreateDate().compareTo(o2.getCreateDate()) : 1; } return -1; } }); cellTable.addColumn(createDateColumn, "Create date"); DatePickerCell cell = new DatePickerCell(dateFormat); // ?? ? // ? Column<LinkData, Date> expiredDateColumn = new Column<LinkData, Date>(cell) { @Override public Date getValue(LinkData object) { return object.getExpiredDate(); } }; expiredDateColumn.setSortable(true); sortHandler.setComparator(expiredDateColumn, new Comparator<LinkData>() { @Override public int compare(LinkData o1, LinkData o2) { if (o1 == o2) { return 0; } if (o1 != null) { return (o2 != null) ? o1.getExpiredDate().compareTo(o2.getExpiredDate()) : 1; } return -1; } }); cellTable.addColumn(expiredDateColumn, "Expired Date"); expiredDateColumn.setFieldUpdater(new FieldUpdater<LinkData, Date>() { @Override public void update(int index, final LinkData object, final Date value) { AdministrationServiceInterface.App.getInstance().setExpiredDate(object.getId(), value, new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { label.setHTML("<h4>Connection error!<br>Can't update data!<h4>"); } @Override public void onSuccess(Boolean result) { if (!result) { label.setHTML("<h4>Server error!<h4>"); } else { object.setExpiredDate(value); dataProvider.refresh(); } } }); } }); // - Column<LinkData, Number> currentCountColumn = new Column<LinkData, Number>(new NumberCell()) { @Override public Number getValue(LinkData object) { return object.getCurrentCount(); } }; currentCountColumn.setSortable(true); sortHandler.setComparator(currentCountColumn, new Comparator<LinkData>() { @Override public int compare(LinkData o1, LinkData o2) { if (o1 == o2) { return 0; } if (o1 != null) { return (o2 != null) ? o1.getCurrentCount().compareTo(o2.getCurrentCount()) : 1; } return -1; } }); currentCountColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); cellTable.addColumn(currentCountColumn, "Current visits"); // ?, GWT EditNumberCell. . // ? ? ?. ? ?? ?. // ? - Column<LinkData, String> maxCountColumn = new Column<LinkData, String>(new EditTextCell()) { @Override public String getValue(LinkData object) { Integer t = object.getMaxCount(); if (t == 0) { return "Infinity"; } else { return t.toString(); // GWT!!! } } }; maxCountColumn.setSortable(true); sortHandler.setComparator(maxCountColumn, new Comparator<LinkData>() { @Override public int compare(LinkData o1, LinkData o2) { if (o1 == o2) { return 0; } if (o1 != null) { return (o2 != null) ? o1.getMaxCount().compareTo(o2.getMaxCount()) : 1; } return -1; } }); maxCountColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT); cellTable.addColumn(maxCountColumn, "Max Visits"); maxCountColumn.setFieldUpdater(new FieldUpdater<LinkData, String>() { @Override public void update(int index, final LinkData object, final String value) { final Integer t; if (value.equals("Infinity")) { t = 0; } else { t = Integer.parseInt(value); } if (t < 0) { label.setHTML("Wrong maximum count!"); } AdministrationServiceInterface.App.getInstance().setMaxCount(object.getId(), t, new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { label.setHTML("<h4>Connection error!<br>Can't update data!<h4>"); } @Override public void onSuccess(Boolean result) { if (!result) { label.setHTML("Server error!"); } else { object.setMaxCount(t); dataProvider.refresh(); } } }); } }); // Column<LinkData, String> passwordColumn = new Column<LinkData, String>(new EditTextCell()) { @Override public String getValue(LinkData object) { if (object.getPassword().equals("")) { return ""; } else { // ? , ? return "*********"; } } }; cellTable.addColumn(passwordColumn, "Password"); passwordColumn.setFieldUpdater(new FieldUpdater<LinkData, String>() { @Override public void update(int index, final LinkData object, final String value) { final String pass; if (value.isEmpty() || value.contains(" ")) { // ? ? ? ?? ? ? pass = null; } else { pass = value; } AdministrationServiceInterface.App.getInstance().setPassword(object.getId(), getMD5(pass), new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { label.setHTML("<h4>Connection error!<br>Can't update data!<h4>"); } @Override public void onSuccess(Boolean result) { if (!result) { label.setHTML("<h4>Server error!<h4>"); } else { object.setPassword(getMD5(pass)); dataProvider.refresh(); } } }); } }); // ?? Column<LinkData, String> deleteColumn = new Column<LinkData, String>(new ButtonCell()) { @Override public String getValue(LinkData object) { return "Delete link"; // + object.getCode(); // + "' link"; } }; cellTable.addColumn(deleteColumn, ""); deleteColumn.setFieldUpdater(new FieldUpdater<LinkData, String>() { @Override public void update(int index, final LinkData object, String value) { if (Window.confirm("Shortlink " + object.getCode() + " will be delete!")) { AdministrationServiceInterface.App.getInstance().deleteLink(object.getId(), new AsyncCallback<Boolean>() { @Override public void onFailure(Throwable caught) { label.setHTML("<h4>Connection error!<br>Can't delete data!<h4>"); } @Override public void onSuccess(Boolean result) { if (!result) { label.setHTML("<h4>Server error!<h4>"); } else { // ? ?? dataProvider.getList().remove(object); dataProvider.refresh(); } } }); } } }); }
From source file:com.google.gwt.sample.showcase.client.content.cell.CwCellSampler.java
License:Apache License
/** * Initialize this example.// ww w . ja va 2 s .c om */ @ShowcaseSource @Override public Widget onInitialize() { Images images = GWT.create(Images.class); // Create the table. editableCells = new ArrayList<AbstractEditableCell<?, ?>>(); contactList = new DataGrid<ContactInfo>(25, ContactInfo.KEY_PROVIDER); contactList.setMinimumTableWidth(140, Unit.EM); ContactDatabase.get().addDataDisplay(contactList); // CheckboxCell. final Category[] categories = ContactDatabase.get().queryCategories(); addColumn(new CheckboxCell(), "Checkbox", new GetValue<Boolean>() { @Override public Boolean getValue(ContactInfo contact) { // Checkbox indicates that the contact is a relative. // Index 0 = Family. return contact.getCategory() == categories[0]; } }, new FieldUpdater<ContactInfo, Boolean>() { @Override public void update(int index, ContactInfo object, Boolean value) { if (value) { // If a relative, use the Family Category. pendingChanges.add(new CategoryChange(object, categories[0])); } else { // If not a relative, use the Contacts Category. pendingChanges.add(new CategoryChange(object, categories[categories.length - 1])); } } }); // TextCell. addColumn(new TextCell(), "Text", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getFullName(); } }, null); // EditTextCell. Column<ContactInfo, String> editTextColumn = addColumn(new EditTextCell(), "EditText", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getFirstName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { pendingChanges.add(new FirstNameChange(object, value)); } }); contactList.setColumnWidth(editTextColumn, 16.0, Unit.EM); // TextInputCell. Column<ContactInfo, String> textInputColumn = addColumn(new TextInputCell(), "TextInput", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getLastName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { pendingChanges.add(new LastNameChange(object, value)); } }); contactList.setColumnWidth(textInputColumn, 16.0, Unit.EM); // ClickableTextCell. addColumn(new ClickableTextCell(), "ClickableText", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return "Click " + contact.getFirstName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { Window.alert("You clicked " + object.getFullName()); } }); // ActionCell. addColumn(new ActionCell<ContactInfo>("Click Me", new ActionCell.Delegate<ContactInfo>() { @Override public void execute(ContactInfo contact) { Window.alert("You clicked " + contact.getFullName()); } }), "Action", new GetValue<ContactInfo>() { @Override public ContactInfo getValue(ContactInfo contact) { return contact; } }, null); // ButtonCell. addColumn(new ButtonCell(), "Button", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return "Click " + contact.getFirstName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { Window.alert("You clicked " + object.getFullName()); } }); // DateCell. DateTimeFormat dateFormat = DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM); addColumn(new DateCell(dateFormat), "Date", new GetValue<Date>() { @Override public Date getValue(ContactInfo contact) { return contact.getBirthday(); } }, null); // DatePickerCell. addColumn(new DatePickerCell(dateFormat), "DatePicker", new GetValue<Date>() { @Override public Date getValue(ContactInfo contact) { return contact.getBirthday(); } }, new FieldUpdater<ContactInfo, Date>() { @Override public void update(int index, ContactInfo object, Date value) { pendingChanges.add(new BirthdayChange(object, value)); } }); // NumberCell. Column<ContactInfo, Number> numberColumn = addColumn(new NumberCell(), "Number", new GetValue<Number>() { @Override public Number getValue(ContactInfo contact) { return contact.getAge(); } }, null); numberColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LOCALE_END); // IconCellDecorator. addColumn(new IconCellDecorator<String>(images.contactsGroup(), new TextCell()), "Icon", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getCategory().getDisplayName(); } }, null); // ImageCell. addColumn(new ImageCell(), "Image", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return "contact.jpg"; } }, null); // SelectionCell. List<String> options = new ArrayList<String>(); for (Category category : categories) { options.add(category.getDisplayName()); } addColumn(new SelectionCell(options), "Selection", new GetValue<String>() { @Override public String getValue(ContactInfo contact) { return contact.getCategory().getDisplayName(); } }, new FieldUpdater<ContactInfo, String>() { @Override public void update(int index, ContactInfo object, String value) { for (Category category : categories) { if (category.getDisplayName().equals(value)) { pendingChanges.add(new CategoryChange(object, category)); break; } } } }); // Create the UiBinder. Binder uiBinder = GWT.create(Binder.class); Widget widget = uiBinder.createAndBindUi(this); // Add handlers to redraw or refresh the table. redrawButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { contactList.redraw(); } }); commitButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // Commit the changes. for (PendingChange<?> pendingChange : pendingChanges) { pendingChange.commit(); } pendingChanges.clear(); // Push the changes to the views. ContactDatabase.get().refreshDisplays(); } }); return widget; }
From source file:com.gsr.myschool.back.client.web.application.affectation.AffectationView.java
License:Apache License
private void initDataGrid() { TextColumn<DossierProxy> refColumn = new TextColumn<DossierProxy>() { @Override// w w w . ja v a2 s . c om public String getValue(DossierProxy object) { return object.getGeneratedNumDossier(); } }; refColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(refColumn, "N Dossier"); preInscriptionsTable.setColumnWidth(refColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> nomColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getCandidat() == null) return ""; return object.getCandidat().getLastname() + " " + object.getCandidat().getFirstname(); } }; nomColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(nomColumn, "Nom prnom"); preInscriptionsTable.setColumnWidth(nomColumn, 15, Style.Unit.PCT); TextColumn<DossierProxy> dateColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getCandidat().getBirthDate() == null) return ""; return dateFormat.format(object.getCandidat().getBirthDate()); } }; dateColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(dateColumn, "Date de naissance"); preInscriptionsTable.setColumnWidth(dateColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> cFiliereColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getFiliere() == null) { return ""; } else { return object.getFiliere().getNom(); } } }; cFiliereColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(cFiliereColumn, "Formation"); preInscriptionsTable.setColumnWidth(cFiliereColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> cLevelColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getNiveauEtude() == null) { return ""; } else { return object.getNiveauEtude().getNom(); } } }; cLevelColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(cLevelColumn, "Niveau demand"); preInscriptionsTable.setColumnWidth(cLevelColumn, 15, Style.Unit.PCT); TextColumn<DossierProxy> statusColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getStatus() == null) return ""; return object.getStatus().toString(); } }; statusColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(statusColumn, "Statut"); preInscriptionsTable.setColumnWidth(statusColumn, 10, Style.Unit.PCT); Delegate<DossierProxy> viewDetailsAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy dossier) { getUiHandlers().viewDetails(dossier); } }; Delegate<DossierProxy> affectAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().affecter(inscription); } }; Delegate<DossierProxy> desaffectAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().desaffecter(inscription); } }; Delegate<DossierProxy> imprimer = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().imprimer(inscription); } }; AffectationActionCell actionsCell = actionCellFactory.create(viewDetailsAction, affectAction, desaffectAction, imprimer); Column<DossierProxy, DossierProxy> actionsColumn = new Column<DossierProxy, DossierProxy>(actionsCell) { @Override public DossierProxy getValue(DossierProxy object) { return object; } }; actionsColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(actionsColumn, "Action"); preInscriptionsTable.setColumnWidth(actionsColumn, 10, Style.Unit.PCT); }
From source file:com.gsr.myschool.back.client.web.application.preinscription.PreInscriptionView.java
License:Apache License
private void initDataGrid() { TextColumn<DossierProxy> nomColumn = new TextColumn<DossierProxy>() { @Override/*from w w w . j av a 2s .c o m*/ public String getValue(DossierProxy object) { if (object.getCandidat() == null) return ""; return object.getCandidat().getLastname() + " " + object.getCandidat().getFirstname(); } }; nomColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(nomColumn, "Nom prnom"); preInscriptionsTable.setColumnWidth(nomColumn, 15, Style.Unit.PCT); TextColumn<DossierProxy> dateColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getCandidat().getBirthDate() == null) return ""; return dateFormat.format(object.getCandidat().getBirthDate()); } }; dateColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(dateColumn, "Date de naissance"); preInscriptionsTable.setColumnWidth(dateColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> refColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { return object.getGeneratedNumDossier(); } }; refColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(refColumn, "N Dossier"); preInscriptionsTable.setColumnWidth(refColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> statusColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getStatus() == null) return ""; return object.getStatus().toString(); } }; statusColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(statusColumn, "Statut"); preInscriptionsTable.setColumnWidth(statusColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> anneeScolaireColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getAnneeScolaire() == null) return ""; return object.getAnneeScolaire().getLabel(); } }; statusColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(anneeScolaireColumn, "Anne scolaire"); preInscriptionsTable.setColumnWidth(anneeScolaireColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> createdColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getCreateDate() == null) return ""; return dateFormat.format(object.getCreateDate()); } }; createdColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(createdColumn, "Date de cration"); preInscriptionsTable.setColumnWidth(createdColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> cFiliereColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getFiliere() == null) { return ""; } else { return object.getFiliere().getNom(); } } }; cFiliereColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(cFiliereColumn, "Formation"); preInscriptionsTable.setColumnWidth(cFiliereColumn, 10, Style.Unit.PCT); TextColumn<DossierProxy> cLevelColumn = new TextColumn<DossierProxy>() { @Override public String getValue(DossierProxy object) { if (object.getNiveauEtude() == null) { return ""; } else { return object.getNiveauEtude().getNom(); } } }; cLevelColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); preInscriptionsTable.addColumn(cLevelColumn, "Niveau demand"); preInscriptionsTable.setColumnWidth(cLevelColumn, 15, Style.Unit.PCT); Delegate<DossierProxy> viewDetailsAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy dossier) { getUiHandlers().viewDetails(dossier); } }; printAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().printInscription(inscription); } }; Delegate<DossierProxy> deleteAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().delete(inscription); } }; Delegate<DossierProxy> printConvocationAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().printConvocationAction(inscription); } }; Delegate<DossierProxy> sendConvocationAction = new Delegate<DossierProxy>() { @Override public void execute(DossierProxy inscription) { getUiHandlers().sendConvocationAction(inscription); } }; PreInscriptionActionCell actionsCell = actionCellFactory.create(viewDetailsAction, printAction, deleteAction, printConvocationAction, sendConvocationAction); Column<DossierProxy, DossierProxy> actionsColumn = new Column<DossierProxy, DossierProxy>(actionsCell) { @Override public DossierProxy getValue(DossierProxy object) { return object; } }; actionsColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); preInscriptionsTable.addColumn(actionsColumn, "Dtails"); preInscriptionsTable.setColumnWidth(actionsColumn, 10, Style.Unit.PCT); }