mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-02 19:27:57 +08:00
New rows count component with 'First' and 'Last' buttons #PL-5035
This commit is contained in:
parent
c56f50a10c
commit
a7d0be6148
@ -55,6 +55,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
|
||||
impl.getPrevButton().addActionListener(e -> onPrevClick());
|
||||
impl.getNextButton().addActionListener(e -> onNextClick());
|
||||
impl.getFirstButton().addActionListener(e -> onFirstClick());
|
||||
impl.getLastButton().addActionListener(e -> onLastClick());
|
||||
if (datasource.getState() == Datasource.State.VALID) {
|
||||
onCollectionChanged();
|
||||
}
|
||||
@ -105,6 +107,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
impl.getCountButton().setVisible(false);
|
||||
impl.getPrevButton().setVisible(false);
|
||||
impl.getNextButton().setVisible(false);
|
||||
impl.getFirstButton().setVisible(false);
|
||||
impl.getLastButton().setVisible(false);
|
||||
if (size % 100 > 10 && size % 100 < 20) {
|
||||
msgKey = "table.rowsCount.msg2Plural1";
|
||||
} else {
|
||||
@ -127,6 +131,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
impl.getCountButton().setVisible(true);
|
||||
impl.getPrevButton().setVisible(false);
|
||||
impl.getNextButton().setVisible(true);
|
||||
impl.getFirstButton().setVisible(false);
|
||||
impl.getLastButton().setVisible(true);
|
||||
msgKey = "table.rowsCount.msg1";
|
||||
countValue = "1-" + size;
|
||||
break;
|
||||
@ -134,6 +140,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
impl.getCountButton().setVisible(true);
|
||||
impl.getPrevButton().setVisible(true);
|
||||
impl.getNextButton().setVisible(true);
|
||||
impl.getFirstButton().setVisible(true);
|
||||
impl.getLastButton().setVisible(true);
|
||||
msgKey = "table.rowsCount.msg1";
|
||||
countValue = (start + 1) + "-" + (start + size);
|
||||
break;
|
||||
@ -141,6 +149,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
impl.getCountButton().setVisible(false);
|
||||
impl.getPrevButton().setVisible(true);
|
||||
impl.getNextButton().setVisible(false);
|
||||
impl.getFirstButton().setVisible(true);
|
||||
impl.getLastButton().setVisible(false);
|
||||
msgKey = "table.rowsCount.msg2Plural2";
|
||||
countValue = (start + 1) + "-" + (start + size);
|
||||
break;
|
||||
@ -206,6 +216,40 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
}
|
||||
}
|
||||
|
||||
protected void onFirstClick() {
|
||||
if (!(datasource instanceof CollectionDatasource.SupportsPaging)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CollectionDatasource.SupportsPaging ds = (CollectionDatasource.SupportsPaging) datasource;
|
||||
ds.setFirstResult(0);
|
||||
refreshDatasource(ds);
|
||||
if (owner instanceof DesktopAbstractTable) {
|
||||
JXTable table = (JXTable) ((DesktopAbstractTable) owner).getComponent();
|
||||
table.scrollRowToVisible(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onLastClick() {
|
||||
if (!(datasource instanceof CollectionDatasource.SupportsPaging)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CollectionDatasource.SupportsPaging ds = (CollectionDatasource.SupportsPaging) datasource;
|
||||
int count = ((CollectionDatasource.SupportsPaging) datasource).getCount();
|
||||
int itemsToDisplay = count % ds.getMaxResults();
|
||||
if (itemsToDisplay == 0) itemsToDisplay = ds.getMaxResults();
|
||||
|
||||
ds.setFirstResult(count - itemsToDisplay);
|
||||
refreshDatasource(ds);
|
||||
|
||||
if (owner instanceof DesktopAbstractTable) {
|
||||
JXTable table = (JXTable) ((DesktopAbstractTable) owner).getComponent();
|
||||
table.scrollRowToVisible(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void refreshDatasource(CollectionDatasource.SupportsPaging ds) {
|
||||
refreshing = true;
|
||||
try {
|
||||
@ -219,11 +263,13 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
|
||||
private JButton prevButton;
|
||||
private JButton nextButton;
|
||||
private JButton firstButton;
|
||||
private JButton lastButton;
|
||||
private JLabel label;
|
||||
private JButton countButton;
|
||||
private MigLayout layout;
|
||||
|
||||
private final Dimension size = new Dimension(35, 25);
|
||||
private final Dimension size = new Dimension(38, 25);
|
||||
|
||||
public RowsCountComponent() {
|
||||
LC lc = new LC();
|
||||
@ -235,6 +281,11 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
}
|
||||
setLayout(layout);
|
||||
|
||||
firstButton = new JButton("<<");
|
||||
add(firstButton);
|
||||
firstButton.setPreferredSize(size);
|
||||
firstButton.setMinimumSize(size);
|
||||
|
||||
prevButton = new JButton("<");
|
||||
add(prevButton);
|
||||
prevButton.setPreferredSize(size);
|
||||
@ -251,6 +302,11 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
add(nextButton);
|
||||
nextButton.setPreferredSize(size);
|
||||
nextButton.setMinimumSize(size);
|
||||
|
||||
lastButton = new JButton(">>");
|
||||
add(lastButton);
|
||||
lastButton.setPreferredSize(size);
|
||||
lastButton.setMinimumSize(size);
|
||||
}
|
||||
|
||||
public JLabel getLabel() {
|
||||
@ -268,5 +324,13 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
|
||||
public JButton getNextButton() {
|
||||
return nextButton;
|
||||
}
|
||||
|
||||
public JButton getFirstButton() {
|
||||
return firstButton;
|
||||
}
|
||||
|
||||
public JButton getLastButton() {
|
||||
return lastButton;
|
||||
}
|
||||
}
|
||||
}
|
@ -155,4 +155,6 @@ actions.dialog.Ok.icon=icons/ok.png
|
||||
actions.dialog.Cancel.icon=icons/cancel.png
|
||||
actions.dialog.Yes.icon=icons/ok.png
|
||||
actions.dialog.No.icon=icons/cancel.png
|
||||
actions.dialog.Close.icon=
|
||||
actions.dialog.Close.icon=
|
||||
|
||||
cuba.gui.rowsCount.arrowButton.width=20px
|
@ -45,6 +45,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getCountButton().addClickListener(event -> onLinkClick());
|
||||
component.getPrevButton().addClickListener(event -> onPrevClick());
|
||||
component.getNextButton().addClickListener(event -> onNextClick());
|
||||
component.getFirstButton().addClickListener(event -> onFirstClick());
|
||||
component.getLastButton().addClickListener(event -> onLastClick());
|
||||
|
||||
if (datasource.getState() == Datasource.State.VALID) {
|
||||
onCollectionChanged();
|
||||
@ -100,6 +102,39 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
}
|
||||
}
|
||||
|
||||
protected void onFirstClick() {
|
||||
if (!(datasource instanceof CollectionDatasource.SupportsPaging)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CollectionDatasource.SupportsPaging ds = (CollectionDatasource.SupportsPaging) datasource;
|
||||
ds.setFirstResult(0);
|
||||
refreshDatasource(ds);
|
||||
if (owner instanceof WebAbstractTable) {
|
||||
com.vaadin.ui.Table vTable = (com.vaadin.ui.Table) ((WebAbstractTable) owner).getComponent();
|
||||
vTable.setCurrentPageFirstItemIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onLastClick() {
|
||||
if (!(datasource instanceof CollectionDatasource.SupportsPaging)) {
|
||||
return;
|
||||
}
|
||||
|
||||
CollectionDatasource.SupportsPaging ds = (CollectionDatasource.SupportsPaging) datasource;
|
||||
int count = ((CollectionDatasource.SupportsPaging) datasource).getCount();
|
||||
int itemsToDisplay = count % ds.getMaxResults();
|
||||
if (itemsToDisplay == 0) itemsToDisplay = ds.getMaxResults();
|
||||
|
||||
ds.setFirstResult(count - itemsToDisplay);
|
||||
refreshDatasource(ds);
|
||||
|
||||
if (owner instanceof WebAbstractTable) {
|
||||
com.vaadin.ui.Table vTable = (com.vaadin.ui.Table) ((WebAbstractTable) owner).getComponent();
|
||||
vTable.setCurrentPageFirstItemIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected void refreshDatasource(CollectionDatasource.SupportsPaging ds) {
|
||||
refreshing = true;
|
||||
try {
|
||||
@ -153,6 +188,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getCountButton().setVisible(false);
|
||||
component.getPrevButton().setVisible(false);
|
||||
component.getNextButton().setVisible(false);
|
||||
component.getFirstButton().setVisible(false);
|
||||
component.getLastButton().setVisible(false);
|
||||
if (size % 100 > 10 && size % 100 < 20) {
|
||||
msgKey = "table.rowsCount.msg2Plural1";
|
||||
} else {
|
||||
@ -175,6 +212,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getCountButton().setVisible(true);
|
||||
component.getPrevButton().setVisible(false);
|
||||
component.getNextButton().setVisible(true);
|
||||
component.getFirstButton().setVisible(false);
|
||||
component.getLastButton().setVisible(true);
|
||||
msgKey = "table.rowsCount.msg1";
|
||||
countValue = "1-" + size;
|
||||
break;
|
||||
@ -182,6 +221,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getCountButton().setVisible(true);
|
||||
component.getPrevButton().setVisible(true);
|
||||
component.getNextButton().setVisible(true);
|
||||
component.getFirstButton().setVisible(true);
|
||||
component.getLastButton().setVisible(true);
|
||||
msgKey = "table.rowsCount.msg1";
|
||||
countValue = (start + 1) + "-" + (start + size);
|
||||
break;
|
||||
@ -189,6 +230,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
|
||||
component.getCountButton().setVisible(false);
|
||||
component.getPrevButton().setVisible(true);
|
||||
component.getNextButton().setVisible(false);
|
||||
component.getFirstButton().setVisible(true);
|
||||
component.getLastButton().setVisible(false);
|
||||
msgKey = "table.rowsCount.msg2Plural2";
|
||||
countValue = (start + 1) + "-" + (start + size);
|
||||
break;
|
||||
|
@ -4,6 +4,10 @@
|
||||
*/
|
||||
package com.haulmont.cuba.web.toolkit.ui;
|
||||
|
||||
import com.haulmont.cuba.core.global.AppBeans;
|
||||
import com.haulmont.cuba.gui.theme.ThemeConstants;
|
||||
import com.haulmont.cuba.gui.theme.ThemeConstantsManager;
|
||||
import com.haulmont.cuba.web.gui.components.WebComponentsHelper;
|
||||
import com.vaadin.shared.ui.MarginInfo;
|
||||
import com.vaadin.ui.*;
|
||||
import com.vaadin.ui.themes.BaseTheme;
|
||||
@ -16,6 +20,8 @@ public class CubaRowsCount extends CustomComponent {
|
||||
|
||||
protected Button prevButton;
|
||||
protected Button nextButton;
|
||||
protected Button firstButton;
|
||||
protected Button lastButton;
|
||||
protected Label label;
|
||||
protected Button countButton;
|
||||
|
||||
@ -44,8 +50,20 @@ public class CubaRowsCount extends CustomComponent {
|
||||
contentLayout.setSpacing(true);
|
||||
contentLayout.setHeight("-1px");
|
||||
|
||||
prevButton = new CubaButton("<");
|
||||
prevButton.setWidth("-1px");
|
||||
ThemeConstants themeConstants = AppBeans.get(ThemeConstantsManager.class).getConstants();
|
||||
String buttonWidth = themeConstants.get("cuba.gui.rowsCount.arrowButton.width");
|
||||
firstButton = new CubaButton();
|
||||
firstButton.setIcon(WebComponentsHelper.getIcon("icons/rows-count-first.png"));
|
||||
firstButton.setWidth(buttonWidth);
|
||||
firstButton.setStyleName("cuba-paging-change-page");
|
||||
firstButton.addStyleName("cuba-paging-first");
|
||||
contentLayout.addComponent(firstButton);
|
||||
|
||||
contentLayout.setComponentAlignment(firstButton, Alignment.MIDDLE_CENTER);
|
||||
|
||||
prevButton = new CubaButton();
|
||||
prevButton.setIcon(WebComponentsHelper.getIcon("icons/rows-count-prev.png"));
|
||||
prevButton.setWidth(buttonWidth);
|
||||
prevButton.setStyleName("cuba-paging-change-page");
|
||||
prevButton.addStyleName("cuba-paging-prev");
|
||||
contentLayout.addComponent(prevButton);
|
||||
@ -64,13 +82,22 @@ public class CubaRowsCount extends CustomComponent {
|
||||
contentLayout.addComponent(countButton);
|
||||
contentLayout.setComponentAlignment(countButton, Alignment.MIDDLE_CENTER);
|
||||
|
||||
nextButton = new CubaButton(">");
|
||||
nextButton.setWidth("-1px");
|
||||
nextButton = new CubaButton();
|
||||
nextButton.setIcon(WebComponentsHelper.getIcon("icons/rows-count-next.png"));
|
||||
nextButton.setWidth(buttonWidth);
|
||||
nextButton.setStyleName("cuba-paging-change-page");
|
||||
nextButton.addStyleName("cuba-paging-next");
|
||||
contentLayout.addComponent(nextButton);
|
||||
contentLayout.setComponentAlignment(nextButton, Alignment.MIDDLE_CENTER);
|
||||
|
||||
lastButton = new CubaButton();
|
||||
lastButton.setIcon(WebComponentsHelper.getIcon("icons/rows-count-last.png"));
|
||||
lastButton.setWidth(buttonWidth);
|
||||
lastButton.setStyleName("cuba-paging-change-page");
|
||||
lastButton.addStyleName("cuba-paging-last");
|
||||
contentLayout.addComponent(lastButton);
|
||||
contentLayout.setComponentAlignment(lastButton, Alignment.MIDDLE_CENTER);
|
||||
|
||||
return contentLayout;
|
||||
}
|
||||
|
||||
@ -89,4 +116,12 @@ public class CubaRowsCount extends CustomComponent {
|
||||
public Button getNextButton() {
|
||||
return nextButton;
|
||||
}
|
||||
|
||||
public Button getFirstButton() {
|
||||
return firstButton;
|
||||
}
|
||||
|
||||
public Button getLastButton() {
|
||||
return lastButton;
|
||||
}
|
||||
}
|
@ -158,6 +158,10 @@ cuba.web.icons.plus.png = PLUS_SQUARE_O
|
||||
cuba.web.icons.plus-btn.png = PLUS
|
||||
cuba.web.icons.refresh.png = REFRESH
|
||||
cuba.web.icons.remove.png = TIMES
|
||||
cuba.web.icons.rows-count-next.png = ANGLE_RIGHT
|
||||
cuba.web.icons.rows-count-last.png = ANGLE_DOUBLE_RIGHT
|
||||
cuba.web.icons.rows-count-prev.png = ANGLE_LEFT
|
||||
cuba.web.icons.rows-count-first.png = ANGLE_DOUBLE_LEFT
|
||||
cuba.web.icons.report-wizard-down-property.png = CARET_DOWN
|
||||
cuba.web.icons.report-wizard-next.png = ARROW_RIGHT
|
||||
cuba.web.icons.report-wizard-previous.png = ARROW_LEFT
|
||||
|
BIN
modules/web/themes/havana/icons/rows-count-first.png
Normal file
BIN
modules/web/themes/havana/icons/rows-count-first.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 361 B |
BIN
modules/web/themes/havana/icons/rows-count-last.png
Normal file
BIN
modules/web/themes/havana/icons/rows-count-last.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 372 B |
BIN
modules/web/themes/havana/icons/rows-count-next.png
Normal file
BIN
modules/web/themes/havana/icons/rows-count-next.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 297 B |
BIN
modules/web/themes/havana/icons/rows-count-prev.png
Normal file
BIN
modules/web/themes/havana/icons/rows-count-prev.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 290 B |
Loading…
Reference in New Issue
Block a user