List of usage examples for com.google.gwt.view.client ProvidesKey getKey
Object getKey(T item);
From source file:com.bearsoft.gwt.ui.widgets.grid.GridSection.java
public <C> void redrawAllRowsInColumn(int aIndex, ListDataProvider<T> aDataProvider) { if (aIndex >= 0 && aIndex < getColumnCount()) { int start = getVisibleRange().getStart(); Column<T, C> column = (Column<T, C>) getColumn(aIndex); Cell<C> cell = column.getCell(); List<T> data = aDataProvider.getList(); ProvidesKey<T> keys = getKeyProvider(); NodeList<TableRowElement> rows = getTableBodyElement().getRows(); for (int i = 0; i < rows.getLength(); i++) { TableRowElement row = rows.getItem(i); NodeList<TableCellElement> cells = row.getCells(); if (aIndex >= 0 && aIndex < cells.getLength()) { TableCellElement toRerender = cells.getItem(aIndex); if (toRerender != null) { SafeHtmlBuilder sb = new SafeHtmlBuilder(); int dataIdx = start + i; if (dataIdx >= 0 && dataIdx < data.size()) { T object = data.get(dataIdx); Cell.Context cx = new Cell.Context(start + i, aIndex, keys.getKey(object)); cell.render(cx, column.getValue(object), sb); // Take into account, that cell builder supports // some // maps // to cells' divs // and generates them. So we have to work with first // <div> // in <td>. toRerender.getFirstChildElement().setInnerSafeHtml(sb.toSafeHtml()); }//from w ww . ja v a 2 s.co m } } } } }
From source file:com.google.gwt.sample.expenses.client.PhaseAnimation.java
License:Apache License
/** * Construct a new {@link CellTablePhaseAnimation}. * //w ww. j a v a 2s. c o m * @param value the value to phase in * @param keyProvider the {@link ProvidesKey} */ public PhaseAnimation(T value, ProvidesKey<T> keyProvider) { this.key = keyProvider.getKey(value); this.keyProvider = keyProvider; }
From source file:gwt.material.design.client.data.AbstractDataView.java
License:Apache License
/** * Get the key for the specified value. If a keyProvider is not specified or the value is null, * the value is returned. If the key provider is specified, it is used to get the key from * the value.//w ww . jav a 2 s .c o m * * @param value the value * @return the key */ public Object getValueKey(T value) { ProvidesKey<T> keyProvider = getKeyProvider(); return (keyProvider == null || value == null) ? value : keyProvider.getKey(value); }
From source file:n3phele.client.view.CommandDetailView.java
License:Open Source License
public CellTable<CloudProfile> createAccountTable(/*final SingleSelectionModel<ExtendedCloudProfile> selectionModel*/) { final SensitiveCheckBoxCell checkbox = new SensitiveCheckBoxCell(true, true); final ProvidesKey<CloudProfile> KEY_PROVIDER = new ProvidesKey<CloudProfile>() { public Object getKey(CloudProfile item) { return item.id(); }/*from w w w . j ava 2 s . co m*/ }; final CellTable<CloudProfile> table = new CellTable<CloudProfile>(KEY_PROVIDER); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); Column<CloudProfile, Boolean> checkColumn = new Column<CloudProfile, Boolean>(checkbox) { @Override public Boolean getValue(CloudProfile profile) { return (profile.getId().equals(CommandDetailView.this.selectedProfile)) && (profile.getAccountUri().equals(CommandDetailView.this.selectedAccountURI)); } }; checkColumn.setFieldUpdater(new FieldUpdater<CloudProfile, Boolean>() { @Override public void update(int index, CloudProfile profile, Boolean value) { if (profile != null) { if (value) { CommandDetailView.this.selectedProfile = profile.getId(); CommandDetailView.this.selectedAccountURI = profile.getAccountUri(); } else { if (profile.getId().equals(CommandDetailView.this.selectedProfile)) { CommandDetailView.this.selectedProfile = null; CommandDetailView.this.selectedAccountURI = null; } } table.redraw(); String visible = value ? "-" : "+"; CommandDetailView.this.gotExecutionSelection.setValue( visible + CommandDetailView.this.gotExecutionSelection.getValue().substring(1)); updateRunButton(true); } else { checkbox.clearViewData(KEY_PROVIDER.getKey(profile)); table.redraw(); updateRunButton(false); CommandDetailView.this.gotExecutionSelection .setValue("+" + CommandDetailView.this.gotExecutionSelection.getValue().substring(1)); } } }); table.addColumn(checkColumn); TextColumn<CloudProfile> accountColumn = new TextColumn<CloudProfile>() { @Override public String getValue(CloudProfile profile) { String result = ""; if (profile != null) return profile.getAccountName(); return result; } }; table.addColumn(accountColumn); TextColumn<CloudProfile> nameColumn = new TextColumn<CloudProfile>() { @Override public String getValue(CloudProfile profile) { String result = ""; if (profile != null) { return profile.getCloudName(); } return result; } }; table.addColumn(nameColumn); TextColumn<CloudProfile> descriptionColumn = new TextColumn<CloudProfile>() { @Override public String getValue(CloudProfile profile) { if (profile != null) return profile.getDescription(); else return null; } }; table.addColumn(descriptionColumn); return table; }
From source file:n3phele.client.view.CreateServiceView.java
License:Open Source License
public CellTable<CommandCloudAccount> createAccountTable() { final SensitiveCheckBoxCell checkbox = new SensitiveCheckBoxCell(true, true); final ProvidesKey<CommandCloudAccount> KEY_PROVIDER = new ProvidesKey<CommandCloudAccount>() { public Object getKey(CommandCloudAccount item) { return item.getAccountUri(); }// w w w . j a v a2 s. c o m }; final CellTable<CommandCloudAccount> table = new CellTable<CommandCloudAccount>(KEY_PROVIDER); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); Column<CommandCloudAccount, Boolean> checkColumn = new Column<CommandCloudAccount, Boolean>(checkbox) { @Override public Boolean getValue(CommandCloudAccount profile) { return (profile.getAccountUri().equals(CreateServiceView.this.selectedAccountURI)); } }; checkColumn.setFieldUpdater(new FieldUpdater<CommandCloudAccount, Boolean>() { @Override public void update(int index, CommandCloudAccount profile, Boolean value) { if (profile != null) { if (value) { CreateServiceView.this.selectedImplementation = profile.getImplementation(); CreateServiceView.this.selectedAccountURI = profile.getAccountUri().toString(); } else { if (profile.getImplementation().equals(CreateServiceView.this.selectedImplementation)) { CreateServiceView.this.selectedImplementation = null; CreateServiceView.this.selectedAccountURI = null; } } table.redraw(); String visible = value ? "-" : "+"; CreateServiceView.this.gotExecutionSelection.setValue( visible + CreateServiceView.this.gotExecutionSelection.getValue().substring(1)); updateRunButton(true); validateAccount(true); } else { checkbox.clearViewData(KEY_PROVIDER.getKey(profile)); table.redraw(); updateRunButton(false); validateAccount(false); GWT.log("update account"); CreateServiceView.this.gotExecutionSelection .setValue("+" + CreateServiceView.this.gotExecutionSelection.getValue().substring(1)); } } }); table.addColumn(checkColumn); table.setColumnWidth(checkColumn, "40px"); TextColumn<CommandCloudAccount> accountColumn = new TextColumn<CommandCloudAccount>() { @Override public String getValue(CommandCloudAccount profile) { String result = ""; if (profile != null) return profile.getAccountName(); return result; } }; table.addColumn(accountColumn); TextColumn<CommandCloudAccount> nameColumn = new TextColumn<CommandCloudAccount>() { @Override public String getValue(CommandCloudAccount profile) { String result = ""; if (profile != null) { return profile.getImplementation(); } return result; } }; table.addColumn(nameColumn); table.setWidth("400px"); table.addStyleName(N3phele.n3pheleResource.css().lineBreakStyle()); table.setTableLayoutFixed(true); return table; }
From source file:org.jboss.ballroom.client.widgets.tables.DefaultCellTable.java
License:Open Source License
/** * In order for the default selection to work, you need to implement * {@link com.google.gwt.view.client.ProvidesKey} on the cell table. */// w ww . java 2 s .c om public void selectDefaultEntity() { flush(); if (null == getSelectionModel()) return; ProvidesKey keyProvider = getKeyProvider(); boolean didMatch = false; if (keyProvider != null && getPreviousSelectedEntity() != null) { Object prevKey = keyProvider.getKey(getPreviousSelectedEntity()); for (Object entity : getVisibleItems()) { Object currKey = keyProvider.getKey(entity); if (prevKey.equals(currKey)) { getSelectionModel().setSelected(entity, true); didMatch = true; break; } } } if (!didMatch && getVisibleItemCount() > 0) { lastSelection = null; getSelectionModel().setSelected(getVisibleItem(0), true); } }