mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-05 04:38:10 +08:00
PL-7065 Ability to focus concrete cell of editable table
This commit is contained in:
parent
c56be2877c
commit
3740f70509
@ -2315,6 +2315,11 @@ public abstract class DesktopAbstractTable<C extends JXTable, E extends Entity>
|
||||
return showSelection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFocus(E itemId, String columnId) {
|
||||
// unsupported for desktop
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses delegate renderer to create cell component.
|
||||
* Then applies desktop styles to cell component.
|
||||
|
@ -19,9 +19,9 @@ package com.haulmont.cuba.gui.components;
|
||||
import com.haulmont.cuba.core.entity.Entity;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import org.dom4j.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
@ -140,6 +140,14 @@ public interface Table<E extends Entity>
|
||||
void setColumnSortable(Column column, boolean sortable);
|
||||
boolean getColumnSortable(Column column);
|
||||
|
||||
/**
|
||||
* Set focus on inner field of editable/generated column.
|
||||
*
|
||||
* @param entity entity
|
||||
* @param columnId column id
|
||||
*/
|
||||
void requestFocus(E entity, String columnId);
|
||||
|
||||
/**
|
||||
* Sort the table by a column.
|
||||
* For example:
|
||||
|
@ -62,6 +62,11 @@ public class CubaScrollTableConnector extends TableConnector {
|
||||
public void showCustomPopup() {
|
||||
getWidget().showCustomPopup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFocus(String itemKey, String columnKey) {
|
||||
getWidget().requestFocus(itemKey, columnKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.haulmont.cuba.web.toolkit.ui.client.table;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.Scheduler;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.NativeEvent;
|
||||
import com.google.gwt.dom.client.Style;
|
||||
@ -39,6 +40,8 @@ import com.vaadin.client.*;
|
||||
import com.vaadin.client.Focusable;
|
||||
import com.vaadin.client.ui.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.haulmont.cuba.web.toolkit.ui.client.Tools.isAnyModifierKeyPressed;
|
||||
@ -560,6 +563,10 @@ public class CubaScrollTableWidget extends VScrollTable implements ShortcutActio
|
||||
super(uidl, aligns);
|
||||
}
|
||||
|
||||
public ArrayList<Widget> getChildWidgets() {
|
||||
return childWidgets;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initCellWithWidget(final Widget w, char align,
|
||||
String style, boolean sorted, TableCellElement td) {
|
||||
@ -850,6 +857,48 @@ public class CubaScrollTableWidget extends VScrollTable implements ShortcutActio
|
||||
}
|
||||
}
|
||||
|
||||
public void requestFocus(final String itemKey, final String columnKey) {
|
||||
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
setFocus(itemKey, columnKey);
|
||||
} catch (Exception e) {
|
||||
VConsole.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void setFocus(String itemKey, String columnKey) {
|
||||
CubaScrollTableBody.CubaScrollTableRow row =
|
||||
(CubaScrollTableBody.CubaScrollTableRow) getRenderedRowByKey(itemKey);
|
||||
for (Widget childWidget : row.getChildWidgets()) {
|
||||
|
||||
int columnIndex = Arrays.asList(visibleColOrder).indexOf(columnKey);
|
||||
if (row.getElement().getChild(columnIndex).getFirstChild() == childWidget.getElement().getParentNode()) {
|
||||
focusWidget(childWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean focusWidget(Widget widget) {
|
||||
if (widget instanceof Focusable) {
|
||||
((Focusable) widget).focus();
|
||||
return true;
|
||||
} else if (widget instanceof com.google.gwt.user.client.ui.Focusable) {
|
||||
((com.google.gwt.user.client.ui.Focusable) widget).setFocus(true);
|
||||
return true;
|
||||
} else if (widget instanceof HasWidgets) {
|
||||
for (Widget childWidget : (HasWidgets) widget) {
|
||||
if (focusWidget(childWidget)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void showContextMenuPopup(int left, int top) {
|
||||
if (customContextMenu instanceof HasWidgets) {
|
||||
if (!((HasWidgets) customContextMenu).iterator().hasNext()) {
|
||||
|
@ -68,6 +68,11 @@ public class CubaTreeTableConnector extends TreeTableConnector {
|
||||
public void showCustomPopup() {
|
||||
getWidget().showCustomPopup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFocus(String itemKey, String columnKey) {
|
||||
getWidget().requestFocus(itemKey, columnKey);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
package com.haulmont.cuba.web.toolkit.ui.client.treetable;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.core.client.Scheduler;
|
||||
import com.google.gwt.dom.client.Element;
|
||||
import com.google.gwt.dom.client.NativeEvent;
|
||||
import com.google.gwt.dom.client.Style;
|
||||
@ -33,12 +34,15 @@ import com.haulmont.cuba.web.toolkit.ui.client.Tools;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.aggregation.AggregatableTable;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.aggregation.TableAggregationRow;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.profiler.ScreenClientProfiler;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.table.TableCellClickListener;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.tablesort.EnhancedCubaTableWidget;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.tablesort.TableCustomSortDelegate;
|
||||
import com.haulmont.cuba.web.toolkit.ui.client.table.TableCellClickListener;
|
||||
import com.vaadin.client.*;
|
||||
import com.vaadin.client.Focusable;
|
||||
import com.vaadin.client.ui.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.haulmont.cuba.web.toolkit.ui.client.Tools.isAnyModifierKeyPressed;
|
||||
@ -550,6 +554,10 @@ public class CubaTreeTableWidget extends VTreeTable implements ShortcutActionHan
|
||||
super(uidl, aligns);
|
||||
}
|
||||
|
||||
public ArrayList<Widget> getChildWidgets() {
|
||||
return childWidgets;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initCellWithWidget(Widget w, char align,
|
||||
String style, boolean sorted, TableCellElement td) {
|
||||
@ -839,6 +847,48 @@ public class CubaTreeTableWidget extends VTreeTable implements ShortcutActionHan
|
||||
Tools.showPopup(customContextMenuPopup, left, top);
|
||||
}
|
||||
|
||||
public void requestFocus(final String itemKey, final String columnKey) {
|
||||
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
setFocus(itemKey, columnKey);
|
||||
} catch (Exception e) {
|
||||
VConsole.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void setFocus(String itemKey, String columnKey) {
|
||||
CubaTreeTableBody.CubaTreeTableRow row =
|
||||
(CubaTreeTableBody.CubaTreeTableRow) getRenderedRowByKey(itemKey);
|
||||
|
||||
for (Widget childWidget : row.getChildWidgets()) {
|
||||
int columnIndex = Arrays.asList(visibleColOrder).indexOf(columnKey);
|
||||
if (row.getElement().getChild(columnIndex).getFirstChild() == childWidget.getElement().getParentNode()) {
|
||||
focusWidget(childWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean focusWidget(Widget widget) {
|
||||
if (widget instanceof Focusable) {
|
||||
((Focusable) widget).focus();
|
||||
return true;
|
||||
} else if (widget instanceof com.google.gwt.user.client.ui.Focusable) {
|
||||
((com.google.gwt.user.client.ui.Focusable) widget).setFocus(true);
|
||||
return true;
|
||||
} else if (widget instanceof HasWidgets) {
|
||||
for (Widget childWidget : (HasWidgets) widget) {
|
||||
if (focusWidget(childWidget)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showCustomPopup() {
|
||||
if (customPopupWidget != null) {
|
||||
if (customPopupWidget instanceof HasWidgets) {
|
||||
|
@ -2593,4 +2593,12 @@ public abstract class WebAbstractTable<T extends com.vaadin.ui.Table & CubaEnhan
|
||||
component.setHeight(100, Unit.PERCENTAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFocus(E item, String columnId) {
|
||||
Preconditions.checkNotNullArgument(item);
|
||||
Preconditions.checkNotNullArgument(columnId);
|
||||
|
||||
component.requestFocus(item.getId(), getColumn(columnId).getId());
|
||||
}
|
||||
}
|
@ -25,7 +25,10 @@ import com.haulmont.cuba.core.global.MetadataTools;
|
||||
import com.haulmont.cuba.core.global.View;
|
||||
import com.haulmont.cuba.gui.components.GroupTable;
|
||||
import com.haulmont.cuba.gui.components.Table;
|
||||
import com.haulmont.cuba.gui.data.*;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.gui.data.GroupDatasource;
|
||||
import com.haulmont.cuba.gui.data.GroupInfo;
|
||||
import com.haulmont.cuba.web.gui.data.CollectionDsWrapper;
|
||||
import com.haulmont.cuba.web.gui.data.ItemWrapper;
|
||||
import com.haulmont.cuba.web.gui.data.PropertyWrapper;
|
||||
|
@ -89,6 +89,8 @@ public interface CubaEnhancedTable extends AggregationContainer {
|
||||
boolean getColumnSortable(Object columnId);
|
||||
void setColumnSortable(Object columnId, boolean sortable);
|
||||
|
||||
void requestFocus(Object itemId, Object columnId);
|
||||
|
||||
interface CellClickListener {
|
||||
void onClick(Object itemId, Object columnId);
|
||||
}
|
||||
|
@ -69,6 +69,8 @@ public class CubaTable extends com.vaadin.ui.Table implements TableContainer, Cu
|
||||
protected Map<Object, String> columnDescriptions; // lazily initialized map
|
||||
|
||||
protected Table.AggregationStyle aggregationStyle = Table.AggregationStyle.TOP;
|
||||
protected Object focusColumn;
|
||||
protected Object focusItem;
|
||||
|
||||
public CubaTable() {
|
||||
registerRpc(new CubaTableServerRpc() {
|
||||
@ -603,6 +605,22 @@ public class CubaTable extends com.vaadin.ui.Table implements TableContainer, Cu
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFocus(Object itemId, Object columnId) {
|
||||
if (!getItemIds().contains(itemId)) {
|
||||
throw new IllegalArgumentException("Item doesn't exists");
|
||||
}
|
||||
|
||||
if (!visibleColumns.contains(columnId)) {
|
||||
throw new IllegalArgumentException("Column doesn't exists or not visible");
|
||||
}
|
||||
|
||||
focusColumn = columnId;
|
||||
focusItem = itemId;
|
||||
setPageLength(-1);
|
||||
markAsDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> getSortableContainerPropertyIds() {
|
||||
Collection<?> ids = new ArrayList<>(super.getSortableContainerPropertyIds());
|
||||
@ -624,6 +642,14 @@ public class CubaTable extends com.vaadin.ui.Table implements TableContainer, Cu
|
||||
updateFooterAggregation();
|
||||
}
|
||||
}
|
||||
|
||||
if (focusColumn != null) {
|
||||
setCurrentPageFirstItemId(focusItem);
|
||||
getRpcProxy(CubaTableClientRpc.class).requestFocus(itemIdMapper.key(focusItem), columnIdMap.key(focusColumn));
|
||||
|
||||
focusColumn = null;
|
||||
focusItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateFooterAggregation() {
|
||||
|
@ -73,6 +73,8 @@ public class CubaTreeTable extends com.vaadin.ui.TreeTable implements TreeTableC
|
||||
protected Map<Object, String> columnDescriptions; // lazily initialized map
|
||||
|
||||
protected Table.AggregationStyle aggregationStyle = Table.AggregationStyle.TOP;
|
||||
protected Object focusColumn;
|
||||
protected Object focusItem;
|
||||
|
||||
public CubaTreeTable() {
|
||||
registerRpc(new CubaTableServerRpc() {
|
||||
@ -688,6 +690,22 @@ public class CubaTreeTable extends com.vaadin.ui.TreeTable implements TreeTableC
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFocus(Object itemId, Object columnId) {
|
||||
if (!getItemIds().contains(itemId)) {
|
||||
throw new IllegalArgumentException("Item doesn't exists");
|
||||
}
|
||||
|
||||
if (!visibleColumns.contains(columnId)) {
|
||||
throw new IllegalArgumentException("Column doesn't exists or not visible");
|
||||
}
|
||||
|
||||
focusColumn = columnId;
|
||||
focusItem = itemId;
|
||||
setPageLength(-1);
|
||||
markAsDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<?> getSortableContainerPropertyIds() {
|
||||
Collection<?> ids = new ArrayList<>(super.getSortableContainerPropertyIds());
|
||||
@ -707,6 +725,14 @@ public class CubaTreeTable extends com.vaadin.ui.TreeTable implements TreeTableC
|
||||
if (Table.AggregationStyle.BOTTOM.equals(getAggregationStyle())) {
|
||||
updateFooterAggregation();
|
||||
}
|
||||
|
||||
if (focusColumn != null) {
|
||||
setCurrentPageFirstItemId(focusItem);
|
||||
getRpcProxy(CubaTableClientRpc.class).requestFocus(itemIdMapper.key(focusItem), columnIdMap.key(focusColumn));
|
||||
|
||||
focusColumn = null;
|
||||
focusItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateFooterAggregation() {
|
||||
|
@ -29,4 +29,6 @@ public interface CubaTableClientRpc extends ClientRpc {
|
||||
void hideContextMenuPopup();
|
||||
|
||||
void showCustomPopup();
|
||||
|
||||
void requestFocus(String itemKey, String columnKey);
|
||||
}
|
Loading…
Reference in New Issue
Block a user