private void sort(boolean userOriginated) { // Set sort orders // In-memory comparator getDataCommunicator().setInMemorySorting(createSortingComparator()); // Back-end sort properties List<QuerySortOrder> sortProperties = new ArrayList<>(); sortOrder.stream().map( order -> order.getSorted().getSortOrder(order.getDirection())) .forEach(s -> s.forEach(sortProperties::add)); getDataCommunicator().setBackEndSorting(sortProperties); // Close grid editor if it's open. if (getEditor().isOpen()) { getEditor().cancel(); } fireEvent(new SortEvent<>(this, new ArrayList<>(sortOrder), userOriginated)); }
/** * Sets a component and setter to use for editing values of this column * in the editor row. This is a shorthand for use in simple cases where * no validator or converter is needed. Use * {@link #setEditorBinding(Binding)} to support more complex cases. * <p> * <strong>Note:</strong> The same component cannot be used for multiple * columns. * * @param editorComponent * the editor component * @param setter * a setter that stores the component value in the row item * @return this column * * @see #setEditorBinding(Binding) * @see Grid#getEditor() * @see Binder#bind(HasValue, ValueProvider, Setter) */ public <C extends HasValue<V> & Component> Column<T, V> setEditorComponent( C editorComponent, Setter<T, V> setter) { Objects.requireNonNull(editorComponent, "Editor component cannot be null"); Objects.requireNonNull(setter, "Setter cannot be null"); Binding<T, V> binding = getGrid().getEditor().getBinder() .bind(editorComponent, valueProvider::apply, setter); return setEditorBinding(binding); }
Binding<T, F> binding = getGrid().getEditor().getBinder() .bind(editorComponent, propertyName);
@Override public void setEditorCancelCaption(String cancelCaption) { component.getEditor().setCancelCaption(cancelCaption); }
/** * Set whether the item editor is enabled. * @param enabled whether the item editor is enabled */ public void setEditorEnabled(boolean enabled) { getGrid().getEditor().setEnabled(enabled); }
/** * Set the item editor <em>cancel</em> button caption * @param caption the caption to set */ public void setEditorCancelCaption(String caption) { getGrid().getEditor().setCancelCaption(caption); }
/** * Register an item editor save listener. * @param listener The listener to add * @return the listener registration */ public Registration addEditorSaveListener(EditorSaveListener<T> listener) { return getGrid().getEditor().addSaveListener(listener); }
/** * Register an item editor open listener. * @param listener The listener to add * @return the listener registration */ public Registration addEditorOpenListener(EditorOpenListener<T> listener) { return getGrid().getEditor().addOpenListener(listener); }
/** * Set the item editor <em>save</em> button caption * @param caption the caption to set */ public void setEditorSaveCaption(String caption) { getGrid().getEditor().setSaveCaption(caption); }
/** * Register an item editor cancel listener. * @param listener The listener to add * @return the listener registration */ public Registration addEditorCancelListener(EditorCancelListener<T> listener) { return getGrid().getEditor().addCancelListener(listener); }
/** * Set whether the item editor is in buffered mode. * @param buffered whether the item editor is in buffered mode */ public void setEditorBuffered(boolean buffered) { getGrid().getEditor().setBuffered(buffered); }
/** * Set the editor error generator. * @param editorErrorGenerator the editor error generator to set */ public void setEditorErrorGenerator(EditorErrorGenerator<T> editorErrorGenerator) { getGrid().getEditor().setErrorGenerator(editorErrorGenerator); }
@Override public void editRow(int rowNumber) { if (!isEditable()) { throw new IllegalStateException("The listing is not editable"); } getGrid().getEditor().editRow(rowNumber); }
@Override public void cancelEditing() { if (!isEditable()) { throw new IllegalStateException("The listing is not editable"); } getGrid().getEditor().cancel(); }
@Override public Subscription addEditorOpenListener(Consumer<EditorOpenEvent> listener) { if (editorOpenListener == null) { editorOpenListener = component.getEditor().addOpenListener(this::onEditorOpen); } return getEventHub().subscribe(EditorOpenEvent.class, listener); }
@Override public Subscription addEditorPostCommitListener(Consumer<EditorPostCommitEvent> listener) { if (editorSaveListener == null) { editorSaveListener = component.getEditor().addSaveListener(this::onEditorSave); } return getEventHub().subscribe(EditorPostCommitEvent.class, listener); }
@Override public Subscription addEditorPreCommitListener(Consumer<EditorPreCommitEvent> listener) { if (editorBeforeSaveListener == null) { //noinspection unchecked CubaEditorImpl<E> editor = (CubaEditorImpl) component.getEditor(); editorBeforeSaveListener = editor.addBeforeSaveListener(this::onEditorBeforeSave); } return getEventHub().subscribe(EditorPreCommitEvent.class, listener); }
@Override public Subscription addEditorCloseListener(Consumer<EditorCloseEvent> listener) { if (editorCancelListener == null) { editorCancelListener = component.getEditor().addCancelListener(this::onEditorCancel); } return getEventHub().subscribe(EditorCloseEvent.class, listener); }
/** * Add an item-level validator. * @param validator The validator to add (not null) */ public void addValidator(Validator<T> validator) { ObjectUtils.argumentNotNull(validator, "Validator must be not null"); getGrid().getEditor().getBinder().withValidator(validator); }