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