mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
PL-7224 Wrong rows count after changing entity count
This commit is contained in:
parent
387c3e33d6
commit
ad356126c7
@ -41,9 +41,11 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
protected CollectionDatasource datasource;
|
||||
protected boolean refreshing;
|
||||
protected State state;
|
||||
protected State lastState;
|
||||
protected int start;
|
||||
protected int size;
|
||||
protected ListComponent owner;
|
||||
protected boolean samePage;
|
||||
|
||||
public DesktopRowsCount() {
|
||||
impl = new RowsCountComponent();
|
||||
@ -59,7 +61,10 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
this.datasource = datasource;
|
||||
if (datasource != null) {
|
||||
//noinspection unchecked
|
||||
this.datasource.addCollectionChangeListener(e -> onCollectionChanged());
|
||||
this.datasource.addCollectionChangeListener(e -> {
|
||||
samePage = !CollectionDatasource.Operation.REFRESH.equals(e.getOperation());
|
||||
onCollectionChanged();
|
||||
});
|
||||
|
||||
impl.getCountButton().addActionListener(e -> onLinkClick());
|
||||
|
||||
@ -94,21 +99,30 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
|
||||
if (datasource instanceof CollectionDatasource.SupportsPaging) {
|
||||
CollectionDatasource.SupportsPaging ds = (CollectionDatasource.SupportsPaging) datasource;
|
||||
if ((size == 0 || size < ds.getMaxResults()) && ds.getFirstResult() == 0) {
|
||||
if (samePage) {
|
||||
state = lastState;
|
||||
start = ds.getFirstResult();
|
||||
} else if ((size == 0 || size < ds.getMaxResults()) && ds.getFirstResult() == 0) {
|
||||
state = State.FIRST_COMPLETE;
|
||||
lastState = state;
|
||||
} else if (size == ds.getMaxResults() && ds.getFirstResult() == 0) {
|
||||
state = State.FIRST_INCOMPLETE;
|
||||
lastState = state;
|
||||
} else if (size == ds.getMaxResults() && ds.getFirstResult() > 0) {
|
||||
state = State.MIDDLE;
|
||||
start = ds.getFirstResult();
|
||||
lastState = state;
|
||||
} else if (size < ds.getMaxResults() && ds.getFirstResult() > 0) {
|
||||
state = State.LAST;
|
||||
start = ds.getFirstResult();
|
||||
lastState = state;
|
||||
} else {
|
||||
state = State.FIRST_COMPLETE;
|
||||
lastState = state;
|
||||
}
|
||||
} else {
|
||||
state = State.FIRST_COMPLETE;
|
||||
lastState = state;
|
||||
}
|
||||
|
||||
String countValue;
|
||||
@ -144,7 +158,7 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
impl.getFirstButton().setVisible(false);
|
||||
impl.getLastButton().setVisible(true);
|
||||
msgKey = "table.rowsCount.msg1";
|
||||
countValue = "1-" + size;
|
||||
countValue = countValue(start, size);
|
||||
break;
|
||||
case MIDDLE:
|
||||
impl.getCountButton().setVisible(true);
|
||||
@ -153,7 +167,7 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
impl.getFirstButton().setVisible(true);
|
||||
impl.getLastButton().setVisible(true);
|
||||
msgKey = "table.rowsCount.msg1";
|
||||
countValue = (start + 1) + "-" + (start + size);
|
||||
countValue = countValue(start, size);
|
||||
break;
|
||||
case LAST:
|
||||
impl.getCountButton().setVisible(false);
|
||||
@ -162,7 +176,7 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
impl.getFirstButton().setVisible(true);
|
||||
impl.getLastButton().setVisible(false);
|
||||
msgKey = "table.rowsCount.msg2Plural2";
|
||||
countValue = (start + 1) + "-" + (start + size);
|
||||
countValue = countValue(start, size);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
@ -179,6 +193,14 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
impl.revalidate();
|
||||
}
|
||||
|
||||
protected String countValue(int start, int size) {
|
||||
if (size == 0) {
|
||||
return String.valueOf(size);
|
||||
} else {
|
||||
return (start + 1) + "-" + (start + size);
|
||||
}
|
||||
}
|
||||
|
||||
private void onLinkClick() {
|
||||
if (datasource == null || !(datasource instanceof CollectionDatasource.SupportsPaging)) {
|
||||
return;
|
||||
|
@ -21,6 +21,7 @@ import com.haulmont.cuba.core.global.Messages;
|
||||
import com.haulmont.cuba.gui.components.ListComponent;
|
||||
import com.haulmont.cuba.gui.components.RowsCount;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource;
|
||||
import com.haulmont.cuba.gui.data.CollectionDatasource.Operation;
|
||||
import com.haulmont.cuba.gui.data.Datasource;
|
||||
import com.haulmont.cuba.web.toolkit.ui.CubaRowsCount;
|
||||
|
||||
@ -31,9 +32,11 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
protected CollectionDatasource datasource;
|
||||
protected boolean refreshing;
|
||||
protected State state;
|
||||
protected State lastState;
|
||||
protected int start;
|
||||
protected int size;
|
||||
protected ListComponent owner;
|
||||
protected boolean samePage;
|
||||
|
||||
public WebRowsCount() {
|
||||
component = new CubaRowsCount();
|
||||
@ -50,7 +53,10 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
this.datasource = datasource;
|
||||
if (datasource != null) {
|
||||
//noinspection unchecked
|
||||
this.datasource.addCollectionChangeListener(e -> onCollectionChanged());
|
||||
this.datasource.addCollectionChangeListener(e -> {
|
||||
samePage = !Operation.REFRESH.equals(e.getOperation());
|
||||
onCollectionChanged();
|
||||
});
|
||||
|
||||
component.getCountButton().addClickListener(event -> onLinkClick());
|
||||
component.getPrevButton().addClickListener(event -> onPrevClick());
|
||||
@ -175,21 +181,30 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
|
||||
if (datasource instanceof CollectionDatasource.SupportsPaging) {
|
||||
CollectionDatasource.SupportsPaging ds = (CollectionDatasource.SupportsPaging) datasource;
|
||||
if ((size == 0 || size < ds.getMaxResults()) && ds.getFirstResult() == 0) {
|
||||
if (samePage) {
|
||||
state = lastState;
|
||||
start = ds.getFirstResult();
|
||||
} else if ((size == 0 || size < ds.getMaxResults()) && ds.getFirstResult() == 0) {
|
||||
state = State.FIRST_COMPLETE;
|
||||
lastState = state;
|
||||
} else if (size == ds.getMaxResults() && ds.getFirstResult() == 0) {
|
||||
state = State.FIRST_INCOMPLETE;
|
||||
lastState = state;
|
||||
} else if (size == ds.getMaxResults() && ds.getFirstResult() > 0) {
|
||||
state = State.MIDDLE;
|
||||
start = ds.getFirstResult();
|
||||
lastState = state;
|
||||
} else if (size < ds.getMaxResults() && ds.getFirstResult() > 0) {
|
||||
state = State.LAST;
|
||||
start = ds.getFirstResult();
|
||||
lastState = state;
|
||||
} else {
|
||||
state = State.FIRST_COMPLETE;
|
||||
lastState = state;
|
||||
}
|
||||
} else {
|
||||
state = State.FIRST_COMPLETE;
|
||||
lastState = state;
|
||||
}
|
||||
|
||||
String countValue;
|
||||
@ -225,7 +240,7 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getFirstButton().setVisible(false);
|
||||
component.getLastButton().setVisible(true);
|
||||
msgKey = "table.rowsCount.msg1";
|
||||
countValue = "1-" + size;
|
||||
countValue = countValue(start, size);
|
||||
break;
|
||||
case MIDDLE:
|
||||
component.getCountButton().setVisible(true);
|
||||
@ -234,7 +249,7 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getFirstButton().setVisible(true);
|
||||
component.getLastButton().setVisible(true);
|
||||
msgKey = "table.rowsCount.msg1";
|
||||
countValue = (start + 1) + "-" + (start + size);
|
||||
countValue = countValue(start, size);
|
||||
break;
|
||||
case LAST:
|
||||
component.getCountButton().setVisible(false);
|
||||
@ -243,7 +258,7 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getFirstButton().setVisible(true);
|
||||
component.getLastButton().setVisible(false);
|
||||
msgKey = "table.rowsCount.msg2Plural2";
|
||||
countValue = (start + 1) + "-" + (start + size);
|
||||
countValue = countValue(start, size);
|
||||
break;
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
@ -257,4 +272,12 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getCountButton().removeStyleName("cuba-paging-count-number");
|
||||
}
|
||||
}
|
||||
|
||||
protected String countValue(int start, int size) {
|
||||
if (size == 0) {
|
||||
return String.valueOf(size);
|
||||
} else {
|
||||
return (start + 1) + "-" + (start + size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user