List of usage examples for com.google.gwt.user.cellview.client Column setFieldUpdater
public void setFieldUpdater(FieldUpdater<T, C> fieldUpdater)
From source file:br.org.olimpiabarbacena.client.Pesquisar.java
License:Apache License
public void listarAcervo() { // remove todas as colunas for (int i = cellTable.getColumnCount() - 1; i >= 0; i--) { cellTable.removeColumn(i);/* w w w .j av a 2s . c o m*/ } // Adiciona coluna imagem para exibir o tipo. Column<Object, ImageResource> colunaTipo = new Column<Object, ImageResource>(new ImageResourceCell()) { @Override public ImageResource getValue(Object object) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Midia")) { if (((Midia) object).getTipo() == Tipo.LIVRO) { return Icons.INSTANCE.livro(); } else if (((Midia) object).getTipo() == Tipo.CD) { return Icons.INSTANCE.cd(); } else if (((Midia) object).getTipo() == Tipo.DVD) { return Icons.INSTANCE.dvd(); } else if (((Midia) object).getTipo() == Tipo.REVISTA) { return Icons.INSTANCE.revista(); } else if (((Midia) object).getTipo() == Tipo.JORNAL) { return Icons.INSTANCE.jornal(); } else { return Icons.INSTANCE.desconhecido(); } } return Icons.INSTANCE.desconhecido(); } }; cellTable.addColumn(colunaTipo, "Tipo"); cellTable.setColumnWidth(colunaTipo, "16px"); // Adiciona coluna texto para exibir o ttulo. TextColumn<Object> colunaNome = new TextColumn<Object>() { @Override public String getValue(Object object) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Midia")) { return ((Midia) object).getTitulo(); } return new String(); } }; colunaNome.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); cellTable.addColumn(colunaNome, "Ttulo"); // Adiciona coluna com o boto editar. ButtonCell buttonCellEditar = new ButtonCell() { @Override public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { if (data != null) { ImageResource icon = Icons.INSTANCE.editar(); String iconDisplay = AbstractImagePrototype.create(icon).getHTML(); iconDisplay = iconDisplay.replaceFirst(">", " title=\"Editar\">"); SafeHtml html = SafeHtmlUtils.fromTrustedString(iconDisplay); sb.append(html); } } }; Column<Object, String> colunaEditar = new Column<Object, String>(buttonCellEditar) { @Override public String getValue(Object object) { return "Editar"; } }; colunaEditar.setFieldUpdater(new FieldUpdater<Object, String>() { @Override public void update(int index, Object object, String value) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Midia")) { if (((Midia) object).getTipo() == Tipo.LIVRO) { principal.getControle().setDialogo(new DialogBox(false)); principal.getControle().getDialogo().setWidth("464px"); principal.getControle().getDialogo().setHeight("417px"); principal.getControle().setLivro(new br.org.olimpiabarbacena.client.formulario.midia.Livro( principal, principal.getControle().getDialogo())); principal.getControle().getLivro().get(((Midia) object).getId()); principal.getControle().getDialogo().setWidget(principal.getControle().getLivro()); principal.getControle().getDialogo().center(); } else if (((Midia) object).getTipo() == Tipo.CD) { principal.getControle().setDialogo(new DialogBox(false)); principal.getControle().getDialogo().setWidth("462px"); principal.getControle().getDialogo().setHeight("261px"); principal.getControle().setCD(new br.org.olimpiabarbacena.client.formulario.midia.CD( principal, principal.getControle().getDialogo(), Tipo.CD)); principal.getControle().getCD().get(((Midia) object).getId()); principal.getControle().getDialogo().setWidget(principal.getControle().getCD()); principal.getControle().getDialogo().center(); } else if (((Midia) object).getTipo() == Tipo.DVD) { principal.getControle().setDialogo(new DialogBox(false)); principal.getControle().getDialogo().setWidth("462px"); principal.getControle().getDialogo().setHeight("261px"); principal.getControle().setCD(new br.org.olimpiabarbacena.client.formulario.midia.CD( principal, principal.getControle().getDialogo(), Tipo.DVD)); principal.getControle().getCD().get(((Midia) object).getId()); principal.getControle().getDialogo().setWidget(principal.getControle().getCD()); principal.getControle().getDialogo().center(); } else if (((Midia) object).getTipo() == Tipo.JORNAL) { principal.getControle().setDialogo(new DialogBox(false)); principal.getControle().getDialogo().setWidth("460px"); principal.getControle().getDialogo().setHeight("359px"); principal.getControle() .setJornal(new br.org.olimpiabarbacena.client.formulario.midia.Jornal(principal, principal.getControle().getDialogo(), Tipo.JORNAL)); principal.getControle().getJornal().get(((Midia) object).getId()); principal.getControle().getDialogo().setWidget(principal.getControle().getJornal()); principal.getControle().getDialogo().center(); } else if (((Midia) object).getTipo() == Tipo.REVISTA) { principal.getControle().setDialogo(new DialogBox(false)); principal.getControle().getDialogo().setWidth("460px"); principal.getControle().getDialogo().setHeight("359px"); principal.getControle() .setJornal(new br.org.olimpiabarbacena.client.formulario.midia.Jornal(principal, principal.getControle().getDialogo(), Tipo.REVISTA)); principal.getControle().getJornal().get(((Midia) object).getId()); principal.getControle().getDialogo().setWidget(principal.getControle().getJornal()); principal.getControle().getDialogo().center(); } } } }); colunaEditar.setCellStyleNames("gwt-cell-pointer"); cellTable.addColumn(colunaEditar, new String()); cellTable.setColumnWidth(colunaEditar, "16px"); // Adiciona coluna com o boto remover. ButtonCell buttonCellRemover = new ButtonCell() { @Override public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { if (data != null) { ImageResource icon = Icons.INSTANCE.remover(); String iconDisplay = AbstractImagePrototype.create(icon).getHTML(); iconDisplay = iconDisplay.replaceFirst(">", " title=\"Remover\">"); SafeHtml html = SafeHtmlUtils.fromTrustedString(iconDisplay); sb.append(html); } } }; Column<Object, String> colunaRemover = new Column<Object, String>(buttonCellRemover) { @Override public String getValue(Object object) { return "Remover"; } }; colunaRemover.setFieldUpdater(new FieldUpdater<Object, String>() { @Override public void update(int index, Object object, String value) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Midia")) { if (Window.confirm( "Deseja remover \"" + ((Midia) object).getTitulo() + "\" e suas dependncias?")) { midiaService.remover(((Midia) object).getId(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { }; @Override public void onSuccess(Void result) { limpar(); listarAcervo(); }; }); } } } }); colunaRemover.setCellStyleNames("gwt-cell-pointer"); cellTable.addColumn(colunaRemover, new String()); cellTable.setColumnWidth(colunaRemover, "16px"); dataProvider = new AsyncDataProvider<Object>() { @Override protected void onRangeChanged(HasData<Object> display) { final Range range = display.getVisibleRange(); final int start = range.getStart(); final int end = start + range.getLength(); midiaService.listar(textboxPesquisar.getText(), new AsyncCallback<List<Midia>>() { @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); } @Override public void onSuccess(List<Midia> result) { // convert old list type to new list type List<Object> list = new ArrayList<Object>(result.size()); for (Midia midia : result) { list.add(midia); } updateRowData(start, list.subList(start, (result.size() < end) ? result.size() : end)); updateRowCount(result.size(), true); } }); } }; dataProvider.addDataDisplay(cellTable); }
From source file:br.org.olimpiabarbacena.client.Pesquisar.java
License:Apache License
public void listarMembro() { // remove todas as colunas for (int i = cellTable.getColumnCount() - 1; i >= 0; i--) { cellTable.removeColumn(i);//from w w w.j a v a 2 s .c om } // Adiciona coluna texto para exibir o nome. TextColumn<Object> colunaNome = new TextColumn<Object>() { @Override public String getValue(Object object) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Membro")) { return ((Membro) object).getNome(); } return new String(); } }; colunaNome.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); cellTable.addColumn(colunaNome, "Nome"); // Adiciona coluna com o boto editar. ButtonCell buttonCellEditar = new ButtonCell() { @Override public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { if (data != null) { ImageResource icon = Icons.INSTANCE.editar(); String iconDisplay = AbstractImagePrototype.create(icon).getHTML(); iconDisplay = iconDisplay.replaceFirst(">", " title=\"Editar\">"); SafeHtml html = SafeHtmlUtils.fromTrustedString(iconDisplay); sb.append(html); } } }; Column<Object, String> colunaEditar = new Column<Object, String>(buttonCellEditar) { @Override public String getValue(Object object) { return "Editar"; } }; colunaEditar.setFieldUpdater(new FieldUpdater<Object, String>() { @Override public void update(int index, Object object, String value) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Membro")) { principal.getControle().setDialogo(new DialogBox(false)); principal.getControle().getDialogo().setWidth("466px"); principal.getControle().getDialogo().setHeight("319px"); br.org.olimpiabarbacena.client.formulario.Membro membro = new br.org.olimpiabarbacena.client.formulario.Membro( principal, principal.getControle().getDialogo()); membro.buttonHistorico.setVisible(false); membro.buttonFechar.setText("Cancelar"); membro.get(((Membro) object).getId()); principal.getControle().getDialogo().setWidget(membro); principal.getControle().getDialogo().center(); } } }); colunaEditar.setCellStyleNames("gwt-cell-pointer"); cellTable.addColumn(colunaEditar, new String()); cellTable.setColumnWidth(colunaEditar, "16px"); // Adiciona coluna com o boto remover. ButtonCell buttonCellRemover = new ButtonCell() { @Override public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { if (data != null) { ImageResource icon = Icons.INSTANCE.remover(); String iconDisplay = AbstractImagePrototype.create(icon).getHTML(); iconDisplay = iconDisplay.replaceFirst(">", " title=\"Remover\">"); SafeHtml html = SafeHtmlUtils.fromTrustedString(iconDisplay); sb.append(html); } } }; Column<Object, String> colunaRemover = new Column<Object, String>(buttonCellRemover) { @Override public String getValue(Object object) { return "Remover"; } }; colunaRemover.setFieldUpdater(new FieldUpdater<Object, String>() { @Override public void update(int index, Object object, String value) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Membro")) { if (Window.confirm( "Deseja remover \"" + ((Membro) object).getNome() + "\" e suas dependncias?")) { membroService.remover(((Membro) object).getId(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { }; @Override public void onSuccess(Void result) { limpar(); listarMembro(); }; }); } } } }); colunaRemover.setCellStyleNames("gwt-cell-pointer"); cellTable.addColumn(colunaRemover, new String()); cellTable.setColumnWidth(colunaRemover, "16px"); dataProvider = new AsyncDataProvider<Object>() { @Override protected void onRangeChanged(HasData<Object> display) { final Range range = display.getVisibleRange(); final int start = range.getStart(); final int end = start + range.getLength(); membroService.listar(textboxPesquisar.getText(), new AsyncCallback<List<Membro>>() { @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); } @Override public void onSuccess(List<Membro> result) { // convert old list type to new list type List<Object> list = new ArrayList<Object>(result.size()); for (Membro membro : result) { list.add(membro); } updateRowData(start, list.subList(start, (result.size() < end) ? result.size() : end)); updateRowCount(result.size(), true); } }); } }; dataProvider.addDataDisplay(cellTable); }
From source file:br.org.olimpiabarbacena.client.Pesquisar.java
License:Apache License
public void listarEmprestimo() { // remove todas as colunas for (int i = cellTable.getColumnCount() - 1; i >= 0; i--) { cellTable.removeColumn(i);//w w w .j av a 2s . co m } // Adiciona coluna imagem para exibir a situao. Column<Object, ImageResource> colunaSituacao = new Column<Object, ImageResource>(new ImageResourceCell()) { @Override public ImageResource getValue(Object object) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Emprestimo")) { if (((Emprestimo) object).getEntrega() == null) { return Icons.INSTANCE.emprestado(); } else { return Icons.INSTANCE.baixado(); } } else { return Icons.INSTANCE.desconhecido(); } } }; cellTable.addColumn(colunaSituacao, new String()); cellTable.setColumnWidth(colunaSituacao, "16px"); // Adiciona coluna texto para exibir o ttulo. TextColumn<Object> colunaNome = new TextColumn<Object>() { @Override public String getValue(Object object) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Emprestimo")) { return ((Emprestimo) object).getMidiaObject().getTitulo(); } return new String(); } }; colunaNome.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); cellTable.addColumn(colunaNome, "Ttulo"); // Adiciona coluna com o boto reservar. ButtonCell buttonCellReservar = new ButtonCell() { @Override public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { if (data != null) { ImageResource icon = Icons.INSTANCE.reservar(); String iconDisplay = AbstractImagePrototype.create(icon).getHTML(); iconDisplay = iconDisplay.replaceFirst(">", " title=\"Reservar\">"); SafeHtml html = SafeHtmlUtils.fromTrustedString(iconDisplay); sb.append(html); } } }; Column<Object, String> colunaReservar = new Column<Object, String>(buttonCellReservar) { @Override public String getValue(Object object) { return "Reservar"; } }; colunaReservar.setFieldUpdater(new FieldUpdater<Object, String>() { @Override public void update(int index, Object object, String value) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Emprestimo")) { principal.getControle().setDialogo(new DialogBox(false)); principal.getControle().getDialogo().setWidth("450px"); principal.getControle().getDialogo().setHeight("91px"); Reserva reserva = new Reserva(((Emprestimo) object), principal.getControle().getDialogo()); principal.getControle().getDialogo().setWidget(reserva); principal.getControle().getDialogo().center(); } } }); colunaReservar.setCellStyleNames("gwt-cell-pointer"); cellTable.addColumn(colunaReservar, new String()); cellTable.setColumnWidth(colunaReservar, "16px"); // Adiciona coluna com o boto reservar. ButtonCell buttonCellBaixar = new ButtonCell() { @Override public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { if (data != null) { ImageResource icon = Icons.INSTANCE.baixar(); String iconDisplay = AbstractImagePrototype.create(icon).getHTML(); iconDisplay = iconDisplay.replaceFirst(">", " title=\"Baixar\">"); SafeHtml html = SafeHtmlUtils.fromTrustedString(iconDisplay); sb.append(html); } } }; Column<Object, String> colunaBaixar = new Column<Object, String>(buttonCellBaixar) { @Override public String getValue(Object object) { return "Baixar"; } }; colunaBaixar.setFieldUpdater(new FieldUpdater<Object, String>() { @Override public void update(int index, Object object, String value) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Emprestimo")) { if (((Emprestimo) object).getEntrega() == null) { if (Window.confirm("Deseja baixar \"" + ((Emprestimo) object).getMidiaObject().getTitulo() + "\" emprestado para \"" + ((Emprestimo) object).getMembroObject().getNome() + "\"?")) { emprestimoService.baixar(((Emprestimo) object).getId(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { }; @Override public void onSuccess(Void result) { limpar(); listarEmprestimo(); }; }); } } else { Window.alert("Esta mdia j foi devolvida."); } } } }); colunaBaixar.setCellStyleNames("gwt-cell-pointer"); cellTable.addColumn(colunaBaixar, new String()); cellTable.setColumnWidth(colunaBaixar, "16px"); // Adiciona coluna com o boto visualizar. ButtonCell buttonCellVisualizar = new ButtonCell() { @Override public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { if (data != null) { ImageResource icon = Icons.INSTANCE.visualizar(); String iconDisplay = AbstractImagePrototype.create(icon).getHTML(); iconDisplay = iconDisplay.replaceFirst(">", " title=\"Visualizar\">"); SafeHtml html = SafeHtmlUtils.fromTrustedString(iconDisplay); sb.append(html); } } }; Column<Object, String> colunaVisualizar = new Column<Object, String>(buttonCellVisualizar) { @Override public String getValue(Object object) { return "Visualizar"; } }; colunaVisualizar.setFieldUpdater(new FieldUpdater<Object, String>() { @Override public void update(int index, Object object, String value) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Emprestimo")) { principal.getControle().setDialogo(new DialogBox(false)); principal.getControle().getDialogo().setWidth("451px"); principal.getControle().getDialogo().setHeight("124px"); principal.getControle().getDialogo().setWidget( new br.org.olimpiabarbacena.client.formulario.midia.Emprestimo(((Emprestimo) object), principal.getControle().getDialogo())); principal.getControle().getDialogo().center(); } } }); colunaVisualizar.setCellStyleNames("gwt-cell-pointer"); cellTable.addColumn(colunaVisualizar, new String()); cellTable.setColumnWidth(colunaVisualizar, "16px"); // Adiciona coluna com o boto remover. ButtonCell buttonCellRemover = new ButtonCell() { @Override public void render(Context context, SafeHtml data, SafeHtmlBuilder sb) { if (data != null) { ImageResource icon = Icons.INSTANCE.remover(); String iconDisplay = AbstractImagePrototype.create(icon).getHTML(); iconDisplay = iconDisplay.replaceFirst(">", " title=\"Remover\">"); SafeHtml html = SafeHtmlUtils.fromTrustedString(iconDisplay); sb.append(html); } } }; Column<Object, String> colunaRemover = new Column<Object, String>(buttonCellRemover) { @Override public String getValue(Object object) { return "Remover"; } }; colunaRemover.setFieldUpdater(new FieldUpdater<Object, String>() { @Override public void update(int index, Object object, String value) { if (object.getClass().getName().equals("br.org.olimpiabarbacena.shared.dados.Emprestimo")) { if (Window.confirm("Deseja remover \"" + ((Emprestimo) object).getMidiaObject().getTitulo() + "\" emprestado para \"" + ((Emprestimo) object).getMembroObject().getNome() + "\"?")) { emprestimoService.remover(((Emprestimo) object).getId(), new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { }; @Override public void onSuccess(Void result) { limpar(); listarEmprestimo(); }; }); } } } }); colunaRemover.setCellStyleNames("gwt-cell-pointer"); cellTable.addColumn(colunaRemover, new String()); cellTable.setColumnWidth(colunaRemover, "16px"); dataProvider = new AsyncDataProvider<Object>() { @Override protected void onRangeChanged(HasData<Object> display) { final Range range = display.getVisibleRange(); final int start = range.getStart(); final int end = start + range.getLength(); emprestimoService.listar(textboxPesquisar.getText(), new AsyncCallback<List<Emprestimo>>() { @Override public void onFailure(Throwable caught) { Window.alert(caught.getMessage()); } @Override public void onSuccess(List<Emprestimo> result) { // convert old list type to new list type List<Object> list = new ArrayList<Object>(result.size()); for (Emprestimo emprestimo : result) { list.add(emprestimo); } updateRowData(start, list.subList(start, (result.size() < end) ? result.size() : end)); updateRowCount(result.size(), true); } }); } }; dataProvider.addDataDisplay(cellTable); }
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/*w w w.j a v a2 s. 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.NominaFaltasUI.java
private void initTableColumns() { // id + icon remove Column<Incidencia, String> iconCol = new Column<Incidencia, String>( new NomIconInputCell(NomIconInputCell.FALTA)) { @Override/*from w ww.j av a 2 s. c o 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.NominaSaldoUI.java
/** * Add the columns to the table./*from w ww.j a v a 2 s .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 www . java 2s . 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.agnie.useradmin.contextmgr.client.presenter.shared.ui.CTXUsersCellTable.java
License:Open Source License
public CTXUsersCellTable() { initWidget(uiBinder.createAndBindUi(this)); multiSelectionModel = new MultiSelectionModel<UserApplicationCtxRegistrationPx>(keyProvider); table.setPageSize(ApplicationConfig.getInstance().getPageSize()); Column<UserApplicationCtxRegistrationPx, Boolean> select = new Column<UserApplicationCtxRegistrationPx, Boolean>( new CheckboxCell(true, false)) { @Override/*from w w w .j a v a 2 s.c o m*/ public Boolean getValue(UserApplicationCtxRegistrationPx object) { return multiSelectionModel.isSelected(object); } }; table.addColumn(select, messages.select()); Column<UserApplicationCtxRegistrationPx, String> fname = new TextColumn<UserApplicationCtxRegistrationPx>() { @Override public String getValue(UserApplicationCtxRegistrationPx object) { return object.getUser().getFirstName(); } }; fname.setSortable(true); fname.setDataStoreName("user.firstName"); table.addColumn(fname, messages.fName()); Column<UserApplicationCtxRegistrationPx, String> lName = new TextColumn<UserApplicationCtxRegistrationPx>() { @Override public String getValue(UserApplicationCtxRegistrationPx object) { return object.getUser().getLastName(); } }; lName.setSortable(true); lName.setDataStoreName("user.lastName"); table.addColumn(lName, messages.lName()); Column<UserApplicationCtxRegistrationPx, String> userName = new TextColumn<UserApplicationCtxRegistrationPx>() { @Override public String getValue(UserApplicationCtxRegistrationPx object) { return object.getUser().getUserName(); } }; userName.setSortable(true); userName.setDataStoreName("user.userName"); table.addColumn(userName, messages.uName()); Column<UserApplicationCtxRegistrationPx, String> status = new TextColumn<UserApplicationCtxRegistrationPx>() { @Override public String getValue(UserApplicationCtxRegistrationPx object) { return (object.getStatus() != null ? object.getStatus().getLocalized() : RequestStatus.DISABLED.getLocalized()); } }; status.setSortable(true); status.setDataStoreName("status"); table.addColumn(status, messages.status()); Column<UserApplicationCtxRegistrationPx, String> roles = new Column<UserApplicationCtxRegistrationPx, String>( new ButtonCell()) { @Override public String getValue(UserApplicationCtxRegistrationPx object) { return messages.view_edit(); } }; roles.setFieldUpdater(new FieldUpdater<UserApplicationCtxRegistrationPx, String>() { @Override public void update(int index, UserApplicationCtxRegistrationPx object, String value) { if (presenter.checkPermission(Permissions.CONTEXT_USER_ROLE_MANAGER)) { getViewFactory().getCTXUsersView().getUserCTXRoles(object); } } }); table.addColumn(roles, messages.roles()); Column<UserApplicationCtxRegistrationPx, String> adminRoles = new Column<UserApplicationCtxRegistrationPx, String>( new ButtonCell()) { @Override public String getValue(UserApplicationCtxRegistrationPx object) { return messages.view_edit(); } }; adminRoles.setFieldUpdater(new FieldUpdater<UserApplicationCtxRegistrationPx, String>() { @Override public void update(int index, UserApplicationCtxRegistrationPx object, String value) { if (presenter.checkPermission(Permissions.CONTEXT_USER_ADMIN_ROLE_MANAGER)) { getViewFactory().getCTXUsersView().getUserCTXAdminRoles(object); } } }); table.addColumn(adminRoles, messages.adminRoles()); VerticalPanel panel = new VerticalPanel(); Label label = new Label(messages.no_data()); panel.add(label); panel.setCellHorizontalAlignment(label, HasHorizontalAlignment.ALIGN_CENTER); table.setEmptyTableWidget(label); table.setSelectionModel(multiSelectionModel, DefaultSelectionEventManager.<UserApplicationCtxRegistrationPx>createCustomManager( new MultiSelectEventTranslator<UserApplicationCtxRegistrationPx>())); pager.setRangeLimited(true); pager.setDisplay(table); AsyncHandler columnSortHandler = new AsyncHandler(table); table.addColumnSortHandler(columnSortHandler); }
From source file:com.agnie.useradmin.main.client.presenter.sahered.ui.AppUsersCellTable.java
License:Open Source License
public AppUsersCellTable() { initWidget(uiBinder.createAndBindUi(this)); multiSelectionModel = new MultiSelectionModel<UserApplicationRegistrationPx>(keyProvider); table.setPageSize(ApplicationConfig.getInstance().getPageSize()); Column<UserApplicationRegistrationPx, Boolean> select = new Column<UserApplicationRegistrationPx, Boolean>( new CheckboxCell(true, false)) { @Override/* w w w.j a v a 2 s . c o m*/ public Boolean getValue(UserApplicationRegistrationPx object) { return multiSelectionModel.isSelected(object); } }; table.addColumn(select, messages.select()); Column<UserApplicationRegistrationPx, String> fName = new TextColumn<UserApplicationRegistrationPx>() { @Override public String getValue(UserApplicationRegistrationPx object) { return object.getUser().getFirstName(); } }; fName.setSortable(true); fName.setDataStoreName("user.firstName"); table.addColumn(fName, messages.fName()); Column<UserApplicationRegistrationPx, String> lName = new TextColumn<UserApplicationRegistrationPx>() { @Override public String getValue(UserApplicationRegistrationPx object) { return object.getUser().getLastName(); } }; lName.setSortable(true); lName.setDataStoreName("user.lastName"); table.addColumn(lName, messages.lName()); Column<UserApplicationRegistrationPx, String> userName = new TextColumn<UserApplicationRegistrationPx>() { @Override public String getValue(UserApplicationRegistrationPx object) { return object.getUser().getUserName(); } }; userName.setSortable(true); userName.setDataStoreName("user.userName"); table.addColumn(userName, messages.uName()); Column<UserApplicationRegistrationPx, String> status = new TextColumn<UserApplicationRegistrationPx>() { @Override public String getValue(UserApplicationRegistrationPx object) { return (object.getStatus() != null ? object.getStatus().getLocalized() : RequestStatus.DISABLED.getLocalized()); } }; status.setSortable(true); status.setDataStoreName("status"); table.addColumn(status, messages.status()); Column<UserApplicationRegistrationPx, String> roles = new Column<UserApplicationRegistrationPx, String>( new ButtonCell()) { @Override public String getValue(UserApplicationRegistrationPx object) { return messages.view_edit(); } }; roles.setFieldUpdater(new FieldUpdater<UserApplicationRegistrationPx, String>() { @Override public void update(int index, UserApplicationRegistrationPx object, String value) { if (presenter.checkPermission(Permissions.APPLICATION_USER_ROLE_MANAGER)) { getViewFactory().getAppUsersView().getUserAppRoles(object); } } }); table.addColumn(roles, messages.roles()); Column<UserApplicationRegistrationPx, String> adminRoles = new Column<UserApplicationRegistrationPx, String>( new ButtonCell()) { @Override public String getValue(UserApplicationRegistrationPx object) { return messages.view_edit(); } }; adminRoles.setFieldUpdater(new FieldUpdater<UserApplicationRegistrationPx, String>() { @Override public void update(int index, UserApplicationRegistrationPx object, String value) { if (presenter.checkPermission(Permissions.APPLICATION_USER_ADMIN_ROLE_MANAGER)) { getViewFactory().getAppUsersView().getUserAppAdminRoles(object); } } }); table.addColumn(adminRoles, messages.adminRoles()); VerticalPanel panel = new VerticalPanel(); Label label = new Label(messages.no_data()); panel.add(label); panel.setCellHorizontalAlignment(label, HasHorizontalAlignment.ALIGN_CENTER); table.setEmptyTableWidget(label); table.setSelectionModel(multiSelectionModel, DefaultSelectionEventManager.<UserApplicationRegistrationPx>createCustomManager( new MultiSelectEventTranslator<UserApplicationRegistrationPx>())); pager.setRangeLimited(true); pager.setDisplay(table); AsyncHandler columnSortHandler = new AsyncHandler(table); table.addColumnSortHandler(columnSortHandler); }
From source file:com.anritsu.mcrepositorymanager.client.FilterDBForm.java
public void buildPackageListTable(final CellTable table) { table.setPageSize(200);//from www . ja v a 2 s . co m // Attach column sort handler ListHandler<McPackage> sortHandler = new ListHandler<McPackage>(dataProvider.getList()); table.addColumnSortHandler(sortHandler); Column<McPackage, String> packageNameColumn = new Column<McPackage, String>( new ButtonCell(ButtonType.LINK)) { @Override public String getValue(McPackage object) { return object.getName(); } }; packageNameColumn.setFieldUpdater(new FieldUpdater<McPackage, String>() { @Override public void update(int index, McPackage object, String value) { Set<String> dependencies = new HashSet(); for (McPackage p : object.getDependencies()) { dependencies.add(p.getName() + "-" + p.getPackageVersion()); } Set<String> dependencyFor = new HashSet<>(); for (McPackage p : object.getDependencyFor()) { dependencyFor.add(p.getName() + "-" + p.getPackageVersion()); } Notify.notify("Dependencies: " + Arrays.toString(dependencies.toArray()) + "\nDependency for: " + Arrays.toString(dependencyFor.toArray())); } }); packageNameColumn.setSortable(true); packageNameColumn.setDefaultSortAscending(true); sortHandler.setComparator(packageNameColumn, new Comparator<McPackage>() { @Override public int compare(McPackage t1, McPackage t2) { return t1.getName().compareTo(t2.getName()); } }); Column<McPackage, String> packageVersionColumn = new Column<McPackage, String>( new ButtonCell(ButtonType.LINK)) { @Override public String getValue(McPackage object) { return object.getPackageVersion(); } }; packageVersionColumn.setFieldUpdater(new FieldUpdater<McPackage, String>() { @Override public void update(int index, McPackage object, String value) { HTML html = new HTML(); SafeHtmlBuilder sHtmlBuilder = new SafeHtmlBuilder(); for (String stringLink : object.getDownloadLinks()) { sHtmlBuilder.appendHtmlConstant("<a href='" + stringLink + "'>"); sHtmlBuilder.appendEscaped(stringLink); sHtmlBuilder.appendHtmlConstant("</a><br />"); } html.setHTML(sHtmlBuilder.toSafeHtml()); downloadLinkModalBody.clear(); downloadLinkModalBody.add(html); downloadLinkModal.show(); } }); Column<McPackage, String> packageQ7admOutputVersionColumn = new Column<McPackage, String>( new ButtonCell(ButtonType.LINK)) { @Override public String getValue(McPackage object) { return object.getQ7admOutputVersion(); } }; TextColumn<McPackage> packageAvailabilityColumn = new TextColumn<McPackage>() { @Override public String getValue(McPackage pack) { return pack.getAvailability(); } }; TextColumn<McPackage> packageReleaseDateColumn = new TextColumn<McPackage>() { @Override public String getValue(McPackage pack) { StringBuilder dateFormated = new StringBuilder(); if (pack.getReleaseDate() != null) { String[] releaseDateArray = pack.getReleaseDate().toString().split(" "); dateFormated .append(releaseDateArray[2] + "-" + releaseDateArray[1] + "-" + releaseDateArray[5]); return dateFormated.toString(); } return ""; } }; Column<McPackage, String> selectedForDownloadColumn = new Column<McPackage, String>(new ButtonCell()) { @Override public String getValue(McPackage object) { ((ButtonCell) this.getCell()).setEnabled(false); if (object.getDownloadLinks().isEmpty()) { return "Missing from DB"; } if (object.isMatchFilter()) { ((ButtonCell) this.getCell()).setEnabled(true); } if (object.isDependency()) { ((ButtonCell) this.getCell()).setEnabled(false); } return (object.isAddToRepository()) ? "remove from repository" : "add to repository"; } }; selectedForDownloadColumn.setFieldUpdater(new FieldUpdater<McPackage, String>() { @Override public void update(int index, McPackage object, String value) { downloadRepositoryArchive.setVisible(false); downloadRepositoryArchive.setActive(false); repositoryDownloadLink.setVisible(false); repositoryDownloadLink.setActive(false); object.setAddToRepository(!object.isAddToRepository()); // Dealing with dependencies HashSet<McPackage> pList = new HashSet<>(); for (McPackage p : dataProvider.getList()) { if (p.isAddToRepository() && p.isMatchFilter()) { p.setDependencySolved(false); pList.add(p); } } getService().solveDependencies(pList, solveDependenciesCallback); Notify.notify("Package " + object.getName() + " " + value + " : " + object.isAddToRepository()); } }); table.addColumn(packageNameColumn, "Package Name"); table.addColumn(packageQ7admOutputVersionColumn, "Installed version"); table.addColumn(packageVersionColumn, "Package Version"); table.addColumn(packageAvailabilityColumn, "Availability"); table.addColumn(packageReleaseDateColumn, "Release Date"); table.addColumn(selectedForDownloadColumn, "Add to repository"); }