List of usage examples for com.google.gwt.user.cellview.client Column isSortable
boolean isSortable
To view the source code for com.google.gwt.user.cellview.client Column isSortable.
Click Source Link
From source file:com.bearsoft.gwt.ui.widgets.grid.builders.ThemedHeaderOrFooterBuilder.java
protected void buildNodes(List<HeaderNode<T>> aHeaders, Map<Column<T, ?>, ColumnSortList.ColumnSortInfo> sortedColumns) { // AbstractCellTable<T> table = getTable(); List<HeaderNode<T>> children = new ArrayList<>(); boolean isFooter = isBuildingFooter(); // Get the common style names. String className = isBuildingFooter() ? ThemedGridResources.instance.cellTableStyle().cellTableFooter() : ThemedGridResources.instance.cellTableStyle().cellTableHeader(); String sortableStyle = ThemedGridResources.instance.cellTableStyle().cellTableSortableHeader(); String sortedAscStyle = ThemedGridResources.instance.cellTableStyle().cellTableSortedHeaderAscending(); String sortedDescStyle = ThemedGridResources.instance.cellTableStyle().cellTableSortedHeaderDescending(); TableRowBuilder tr = startRow();//from w ww. ja v a2 s. com // Loop through all column header nodes. for (int i = 0; i < aHeaders.size(); i++) { HeaderNode<T> headerNode = aHeaders.get(i); children.addAll(headerNode.getChildren()); Header<?> headerOrFooter = headerNode.getHeader(); Column<T, ?> column = null; if (headerOrFooter instanceof HasColumn<?>) column = ((HasColumn<T>) headerOrFooter).getColumn(); boolean isSortable = !isFooter && column != null && column.isSortable(); ColumnSortList.ColumnSortInfo sortedInfo = sortedColumns.get(column); boolean isSorted = sortedInfo != null; StringBuilder classesBuilder = new StringBuilder(className); boolean isSortAscending = isSortable && sortedInfo != null ? sortedInfo.isAscending() : false; if (isSortable) { if (classesBuilder.length() > 0) { classesBuilder.append(" "); } classesBuilder.append(sortableStyle); if (isSorted) { if (classesBuilder.length() > 0) { classesBuilder.append(" "); } classesBuilder.append(isSortAscending ? sortedAscStyle : sortedDescStyle); } } // Render the header or footer. TableCellBuilder th = tr.startTH(); if (headerNode.getDepthRemainder() > 0) th.rowSpan(headerNode.getDepthRemainder() + 1); if (headerNode.getLeavesCount() > 1) th.colSpan(headerNode.getLeavesCount()); th.className(classesBuilder.toString()); StylesBuilder thStyles = th.style(); if (headerNode.getBackground() != null) { thStyles.trustedBackgroundColor(headerNode.getBackground().toStyled()); } if (headerNode.getForeground() != null) { thStyles.trustedColor(headerNode.getForeground().toStyled()); } if (headerNode.getFont() != null) { thStyles.trustedProperty("font-family", headerNode.getFont().getFamily()); thStyles.fontSize(headerNode.getFont().getSize(), Style.Unit.PX); thStyles.fontStyle(headerNode.getFont().isItalic() ? FontStyle.ITALIC : FontStyle.NORMAL); thStyles.fontWeight(headerNode.getFont().isBold() ? FontWeight.BOLD : FontWeight.NORMAL); } if (headerOrFooter != null) { appendExtraStyles(headerOrFooter, classesBuilder); if (column != null) { enableColumnHandlers(th, column); } // Build the header. Cell.Context context = new Cell.Context(0, i, headerOrFooter.getKey()); // Add div element with aria button role if (isSortable) { // TODO: Figure out aria-label and translation // of label text th.attribute("role", "button"); th.tabIndex(-1); } renderSortableHeader(th, context, headerOrFooter, isSorted, isSortAscending); } th.endTH(); } // End the row. tr.endTR(); if (!children.isEmpty()) { buildNodes(children, sortedColumns); } }
From source file:com.novartis.pcs.ontology.webapp.client.view.ApproveRejectComposite.java
License:Apache License
@SuppressWarnings("unchecked") protected void setupTable() { table.setWidth("100%"); table.addStyleName("gwt-CellTable"); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); /* getValue gets called during update. Need to combine objects * and include a flag that is set when update starts. Using default * functionality with Shit key is better anyway and have include * note to user so they are aware of it. See addWidgets below. Header<Boolean> checkHeader = new Header<Boolean>(new CheckboxCell()) { @Override/*www . ja v a 2 s. c o m*/ public Boolean getValue() { return false; //selection.getSelectedSet().containsAll(table.getVisibleItems()); } }; checkHeader.setUpdater(new ValueUpdater<Boolean>() { @Override public void update(Boolean value) { List<T> displayedItems = table.getVisibleItems(); for (T pending : displayedItems) { selection.setSelected(pending, value); } } }); */ if (curator != null && curator.isAuthorised(entity)) { Column<T, Boolean> checkColumn = new Column<T, Boolean>(new DisableableCheckboxCell(true, false)) { @Override public Boolean getValue(T object) { return !object.getCreatedBy().equals(curator) ? selection.isSelected(object) : null; } }; table.addColumn(checkColumn); table.setColumnWidth(checkColumn, 16, Unit.PX); table.setSelectionModel(selection, DefaultSelectionEventManager.<T>createCheckboxManager(0)); } else { table.setSelectionModel(new NoSelectionModel<T>(keyProvider)); } addTableColumns(table); table.addColumn(new CreatedDateColumn(), "Created"); table.addColumn(new CreatedByColumn(), "Created By"); if (curator != null) { IconActionCell.Delegate<T> delegate = new IconActionCell.Delegate<T>() { @Override public void execute(T entity) { editView.setEntity(entity); editView.show(); } }; Column<T, T> editColumn = new Column<T, T>( new IconActionCell<T>(ImageResources.INSTANCE.editIcon(), delegate)) { @Override public T getValue(T entity) { return entity; } }; editColumn.setCellStyleNames("icon-action"); table.addColumn(editColumn, SafeHtmlUtils.fromSafeConstant(" ")); } if (curator != null) { IconActionCell.Delegate<T> delegate = new IconActionCell.Delegate<T>() { @Override public void execute(final T entity) { if (entity != null && curator.equals(entity.getCreatedBy())) { if (errorLabel.isVisible()) { errorLabel.setVisible(false); } if (selection != null) { selection.setSelected(entity, false); } processing.add(entity); busyIndicator.busy(); service.delete(entity, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { GWT.log("Failed to delete pending item", caught); processing.remove(entity); busyIndicator.idle(); if (caught instanceof InvalidEntityException) { InvalidEntityException e = (InvalidEntityException) caught; errorLabel.setText(e.getMessage() + ": " + e.getEntity()); errorLabel.setVisible(true); } else { ErrorView.instance().onUncaughtException(caught); } } @Override public void onSuccess(Void nothing) { processing.remove(entity); dataProvider.getList().remove(entity); busyIndicator.idle(); fireDeleteEvent(entity); } }); } } }; Column<T, T> deleteColumn = new Column<T, T>( new IconActionCell<T>(ImageResources.INSTANCE.deleteIcon(), delegate)) { @Override public T getValue(T entity) { return curator.equals(entity.getCreatedBy()) ? entity : null; } }; deleteColumn.setCellStyleNames("icon-action"); table.addColumn(deleteColumn, SafeHtmlUtils.fromSafeConstant(" ")); } ListHandler<T> sortHandler = new ListHandler<T>(dataProvider.getList()); for (int i = 0; i < table.getColumnCount(); i++) { Column<T, ?> column = table.getColumn(i); if (column.isSortable() && column instanceof Comparator<?>) { sortHandler.setComparator(column, (Comparator<T>) column); } } table.addColumnSortHandler(sortHandler); table.getColumnSortList().push(table.getColumn(curator != null && curator.isAuthorised(entity) ? 2 : 1)); }
From source file:com.novartis.pcs.ontology.webapp.client.view.ControlledVocabularyTermLinksView.java
License:Apache License
@SuppressWarnings("unchecked") private void addTableColumns() { table.setWidth("100%"); table.setPageSize(10);// w w w . j ava2 s . c o m table.addStyleName("gwt-CellTable"); table.addStyleName("spaced-vert"); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); table.setSelectionModel(new NoSelectionModel<ControlledVocabularyTermLink>(keyProvider)); table.addColumn(new NameColumn(), "Linked Term"); table.addColumn(new DomainColumn(), "Domain"); table.addColumn(new ContextColumn(), "Context"); table.addColumn(new SourceColumn(), "Source"); table.addColumn(new UsageColumn(), "Usage"); ListHandler<ControlledVocabularyTermLink> sortHandler = new ListHandler<ControlledVocabularyTermLink>( dataProvider.getList()); for (int i = 1; i < table.getColumnCount(); i++) { Column<ControlledVocabularyTermLink, ?> column = table.getColumn(i); if (column.isSortable() && column instanceof Comparator<?>) { sortHandler.setComparator(column, (Comparator<ControlledVocabularyTermLink>) column); } } table.addColumnSortHandler(sortHandler); table.getColumnSortList().push(table.getColumn(table.getColumnCount() - 1)); // Second time to reverse sort order table.getColumnSortList().push(table.getColumn(table.getColumnCount() - 1)); }
From source file:com.novartis.pcs.ontology.webapp.client.view.CrossRefPopup.java
License:Apache License
@SuppressWarnings("unchecked") private void addTableColumns() { /*/*w ww . ja v a2s .c o m*/ List<String> typeNames = new ArrayList<String>(); for(Synonym.Type type : Synonym.Type.values()) { typeNames.add(type.name()); } Column<ControlledVocabularyTerm, String> typeColumn = new Column<ControlledVocabularyTerm, String>(new SelectionCell(typeNames)) { @Override public String getValue(ControlledVocabularyTerm term) { Synonym.Type type = term.getSynonymType(); if(type == null) { type = Synonym.Type.RELATED; } return type.name(); } }; typeColumn.setFieldUpdater(new FieldUpdater<ControlledVocabularyTerm, String>() { @Override public void update(int index, ControlledVocabularyTerm term, String typeName) { Synonym.Type type = Synonym.Type.valueOf(typeName); term.setSynonymType(type); } }); */ IconActionCell.Delegate<ControlledVocabularyTerm> delegate = new IconActionCell.Delegate<ControlledVocabularyTerm>() { @Override public void execute(ControlledVocabularyTerm term) { eventBus.fireEvent(new SearchEvent(term.getName())); if (selection != null) { selection.clear(); selection.setSelected(term, true); } } }; Column<ControlledVocabularyTerm, ControlledVocabularyTerm> searchColumn = new Column<ControlledVocabularyTerm, ControlledVocabularyTerm>( new IconActionCell<ControlledVocabularyTerm>(ImageResources.INSTANCE.searchIcon(), delegate)) { @Override public ControlledVocabularyTerm getValue(ControlledVocabularyTerm term) { return term; } }; searchColumn.setCellStyleNames("icon-action"); /* Column<ControlledVocabularyTerm, ControlledVocabularyTerm> addColumn = new Column<ControlledVocabularyTerm, ControlledVocabularyTerm>(new IconActionCell<ControlledVocabularyTerm>(ImageResources.INSTANCE.addIcon(), this)) { @Override public ControlledVocabularyTerm getValue(ControlledVocabularyTerm term) { return term; } }; addColumn.setCellStyleNames("icon-action"); // colspans the table header if we use the same Header object Header<String> actionHeader = new Header<String>(new TextCell()) { @Override public String getValue() { return "Action"; } }; */ table.setWidth("100%"); table.setPageSize(10); table.addStyleName("gwt-CellTable"); table.addStyleName("spaced-vert"); //table.setKeyboardPagingPolicy(KeyboardPagingPolicy.CHANGE_PAGE); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); if (curator != null) { Column<ControlledVocabularyTerm, Boolean> checkColumn = new Column<ControlledVocabularyTerm, Boolean>( new CheckboxCell(true, false)) { @Override public Boolean getValue(ControlledVocabularyTerm term) { return selection.isSelected(term); } }; table.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant(" ")); table.setColumnWidth(checkColumn, 16, Unit.PX); table.setSelectionModel(selection, DefaultSelectionEventManager.<ControlledVocabularyTerm>createCheckboxManager(0)); } else { table.setSelectionModel(new NoSelectionModel<ControlledVocabularyTerm>(keyProvider)); } NameColumn nameColumn = new NameColumn(); nameColumn.setFieldUpdater(new FieldUpdater<ControlledVocabularyTerm, String>() { @Override public void update(int index, ControlledVocabularyTerm term, String value) { linkedTermsView.show(term); } }); nameColumn.setCellStyleNames("clickable-text"); table.addColumn(searchColumn, SafeHtmlUtils.fromSafeConstant(" ")); table.addColumn(nameColumn, "Unmapped Term"); table.addColumn(new ContextColumn(), "Context"); table.addColumn(new SourceColumn(), "Source"); table.addColumn(new UsageColumn(), "Usage"); // table.addColumn(typeColumn, "Type"); ListHandler<ControlledVocabularyTerm> sortHandler = new ListHandler<ControlledVocabularyTerm>( dataProvider.getList()); for (int i = 1; i < table.getColumnCount(); i++) { Column<ControlledVocabularyTerm, ?> column = table.getColumn(i); if (column.isSortable() && column instanceof Comparator<?>) { sortHandler.setComparator(column, (Comparator<ControlledVocabularyTerm>) column); } } table.addColumnSortHandler(sortHandler); table.getColumnSortList().push(table.getColumn(table.getColumnCount() - 1)); // Second time to reverse sort order table.getColumnSortList().push(table.getColumn(table.getColumnCount() - 1)); }
From source file:com.novartis.pcs.ontology.webapp.client.view.HistoryPopup.java
License:Apache License
@SuppressWarnings("unchecked") protected void setupTable() { table.setWidth("100%"); table.addStyleName("gwt-CellTable"); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED); table.setSelectionModel(new NoSelectionModel<CuratorAction>(keyProvider)); table.addColumn(new ActionDateColumn(), "Date"); table.addColumn(new CuratorColumn(), "Curator"); table.addColumn(new ActionColumn(), "Action"); table.addColumn(new EntityColumn(), "Entity"); table.addColumn(new OntologyColumn(), "Ontology/Codelist"); table.addColumn(new TermColumn(), "Term"); table.addColumn(new EntityValueColumn(), "Relationship/Synonym"); table.addColumn(new CommentsColumn(), "Comments"); ListHandler<CuratorAction> sortHandler = new ListHandler<CuratorAction>(dataProvider.getList()); for (int i = 0; i < table.getColumnCount(); i++) { Column<CuratorAction, ?> column = table.getColumn(i); if (column.isSortable() && column instanceof Comparator<?>) { sortHandler.setComparator(column, (Comparator<CuratorAction>) column); }/* w ww. j ava2 s . c o m*/ } table.addColumnSortHandler(sortHandler); table.getColumnSortList().push(table.getColumn(0)); }
From source file:org.overlord.sramp.ui.client.widgets.DataTableWithPager.java
License:Apache License
/** * Called to update thet able's column sort info. * @param currentPlace/*from ww w. j ava 2 s.c o m*/ */ private void updateColumnSort(AbstractPagedPlace currentPlace) { String orderBy = currentPlace.getOrderBy(); Boolean asc = currentPlace.isAscending(); if (orderBy == null) orderBy = getDefaultOrderBy(); if (orderBy == null) return; if (asc == null) asc = true; for (int idx = 0; idx < this.table.getColumnCount(); idx++) { Column<T, ?> column = this.table.getColumn(idx); if (column.isSortable() && orderBy.equals(column.getDataStoreName())) { ColumnSortInfo sortInfo = new ColumnSortInfo(column, asc); this.table.getColumnSortList().push(sortInfo); } } }
From source file:org.roda.wui.common.client.widgets.wcag.AccessibleHeaderOrFooterBuilder.java
@Override protected boolean buildHeaderOrFooterImpl() { AbstractCellTable<T> table = getTable(); boolean isFooter = isBuildingFooter(); // Early exit if there aren't any columns to render. int columnCount = table.getColumnCount(); if (columnCount == 0) { // Nothing to render return false; }/*from w ww . ja va 2 s . c o m*/ // Early exit if there aren't any headers in the columns to render. boolean hasHeader = false; for (int i = 0; i < columnCount; i++) { if (getHeader(i) != null) { hasHeader = true; break; } } if (!hasHeader) { return false; } // Get information about the sorted column. ColumnSortList sortList = table.getColumnSortList(); ColumnSortInfo sortedInfo = (sortList.size() == 0) ? null : sortList.get(0); Column<?, ?> sortedColumn = (sortedInfo == null) ? null : sortedInfo.getColumn(); boolean isSortAscending = (sortedInfo == null) ? false : sortedInfo.isAscending(); // Get the common style names. Style style = getTable().getResources().style(); String className = isBuildingFooter() ? style.footer() : style.header(); String sortableStyle = " " + style.sortableHeader(); String sortedStyle = " " + (isSortAscending ? style.sortedHeaderAscending() : style.sortedHeaderDescending()); // Setup the first column. Header<?> prevHeader = getHeader(0); Column<T, ?> column = getTable().getColumn(0); int prevColspan = 1; boolean isSortable = false; boolean isSorted = false; StringBuilder classesBuilder = new StringBuilder(className); classesBuilder.append(" " + (isFooter ? style.firstColumnFooter() : style.firstColumnHeader())); if (!isFooter && column.isSortable()) { isSortable = true; isSorted = (column == sortedColumn); } // Loop through all column headers. TableRowBuilder tr = startRow(); int curColumn; for (curColumn = 1; curColumn < columnCount; curColumn++) { Header<?> header = getHeader(curColumn); if (header != prevHeader) { // The header has changed, so append the previous one. if (isSortable) { classesBuilder.append(sortableStyle); } if (isSorted) { classesBuilder.append(sortedStyle); } appendExtraStyles(prevHeader, classesBuilder); // Render the header. TableCellBuilder th = tr.startTH().colSpan(prevColspan).className(classesBuilder.toString()); enableColumnHandlers(th, column); if (prevHeader != null) { // Build the header. Context context = new Context(0, curColumn - prevColspan, prevHeader.getKey()); // Add div element with aria button role if (isSortable) { // TODO: Figure out aria-label and translation of label text th.attribute("role", "button"); th.tabIndex(-1); } updatedRenderSortableHeader(th, context, prevHeader, isSorted, isSortAscending); } th.endTH(); // Reset the previous header. prevHeader = header; prevColspan = 1; classesBuilder = new StringBuilder(className); isSortable = false; isSorted = false; } else { // Increment the colspan if the headers == each other. prevColspan++; } // Update the sorted state. column = table.getColumn(curColumn); if (!isFooter && column.isSortable()) { isSortable = true; isSorted = (column == sortedColumn); } } // Append the last header. if (isSortable) { classesBuilder.append(sortableStyle); } if (isSorted) { classesBuilder.append(sortedStyle); } // The first and last columns could be the same column. classesBuilder.append(" ").append(isFooter ? style.lastColumnFooter() : style.lastColumnHeader()); appendExtraStyles(prevHeader, classesBuilder); // Render the last header. TableCellBuilder th = tr.startTH().colSpan(prevColspan).className(classesBuilder.toString()); enableColumnHandlers(th, column); if (prevHeader != null) { Context context = new Context(0, curColumn - prevColspan, prevHeader.getKey()); updatedRenderSortableHeader(th, context, prevHeader, isSorted, isSortAscending); } th.endTH(); // End the row. tr.endTR(); return true; }