use of com.vaadin.data.sort.SortOrder in project VaadinUtils by rlsutton1.
the class ReportParameterTable method init.
protected void init(final String caption, final Class<T> tableClass, final SingularAttribute<T, String> displayField) {
JpaBaseDao.getGenericDao(tableClass).flushCache();
container = createContainer(tableClass, displayField);
UI ui = UI.getCurrent();
if (ui != null) {
Runnable runner = new Runnable() {
@Override
public void run() {
try (AutoCloseable closer = EntityManagerProvider.setThreadLocalEntityManagerTryWithResources()) {
ReportParameterTable.this.displayField = displayField;
layout.setSizeFull();
ReportParameterTable.this.caption = caption;
TextField searchText = new TextField();
searchText.setInputPrompt("Search");
searchText.setWidth("100%");
searchText.setImmediate(true);
searchText.setHeight("20");
searchText.addTextChangeListener(new TextChangeListener() {
private static final long serialVersionUID = 1315710313315289836L;
@Override
public void textChange(TextChangeEvent event) {
String value = event.getText();
removeAllContainerFilters();
if (value.length() > 0) {
container.addContainerFilter(new SimpleStringFilter(displayField.getName(), value, true, false));
}
}
});
grid = new Grid();
grid.setImmediate(true);
grid.setSizeFull();
// table.setHeight("150");
grid.setContainerDataSource(container);
new GridHeadingPropertySet.Builder<T>().createColumn(caption, displayField.getName()).setLockedState(true).build().applyToGrid(grid);
List<SortOrder> orders = new LinkedList<>();
orders.add(new SortOrder(displayField.getName(), SortDirection.ASCENDING));
grid.setSortOrder(orders);
final Label selectionCount = new Label("0 selected");
// removed for concertina
// layout.addComponent(new Label(caption));
layout.addComponent(searchText);
layout.addComponent(grid);
HorizontalLayout selectionLayout = new HorizontalLayout();
selectionLayout.setHeight("30");
selectionLayout.setWidth("100%");
selectionLayout.addComponent(selectionCount);
selectionLayout.setComponentAlignment(selectionCount, Alignment.MIDDLE_RIGHT);
layout.addComponent(selectionLayout);
grid.addSelectionListener(new SelectionListener() {
/**
*/
private static final long serialVersionUID = 1L;
@Override
public void select(SelectionEvent event) {
validate();
selectionCount.setValue("" + event.getSelected().size() + " selected");
}
});
layout.setExpandRatio(grid, 1);
// layout.setComponentAlignment(selectAll,
// Alignment.BOTTOM_RIGHT);
} catch (Exception e) {
ErrorWindow.showErrorWindow(e);
}
}
};
UI.getCurrent().accessSynchronously(runner);
} else {
logger.warn("No vaadin session available, not setting up UI");
}
}
use of com.vaadin.data.sort.SortOrder in project VaadinUtils by rlsutton1.
the class BasePortal method setupGridSorting.
public void setupGridSorting(final Grid grid, final String keySorting) {
if (sortListeners.get(grid) != null) {
grid.removeSortListener(sortListeners.get(grid));
} else {
SortListener sortListener = new SortListener() {
private static final long serialVersionUID = 1L;
@Override
public void sort(SortEvent event) {
String sorts = "";
for (SortOrder sort : event.getSortOrder()) {
sorts += sort.getPropertyId() + "=" + sort.getDirection() + ",";
}
getConfigDelegate().setValue(getPortal(), keySorting, sorts);
}
};
sortListeners.put(grid, sortListener);
}
String sorts = getConfigDelegate().getValueString(getPortal(), keySorting);
if (StringUtils.isNotEmpty(sorts)) {
try {
List<SortOrder> sortList = new LinkedList<>();
String[] sortArray = sorts.split(",");
for (String sort : sortArray) {
String[] parts = sort.split("=");
sortList.add(new SortOrder(parts[0], SortDirection.valueOf(parts[1])));
}
grid.setSortOrder(sortList);
} catch (Exception e) {
logger.error(e);
}
}
grid.addSortListener(sortListeners.get(grid));
}
Aggregations