New rows count component with 'First' and 'Last' buttons #PL-5035

This commit is contained in:
Maxim Gorbunkov 2015-10-02 08:31:22 +00:00
parent c56f50a10c
commit a7d0be6148
9 changed files with 154 additions and 6 deletions

View File

@ -55,6 +55,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
impl.getPrevButton().addActionListener(e -> onPrevClick()); impl.getPrevButton().addActionListener(e -> onPrevClick());
impl.getNextButton().addActionListener(e -> onNextClick()); impl.getNextButton().addActionListener(e -> onNextClick());
impl.getFirstButton().addActionListener(e -> onFirstClick());
impl.getLastButton().addActionListener(e -> onLastClick());
if (datasource.getState() == Datasource.State.VALID) { if (datasource.getState() == Datasource.State.VALID) {
onCollectionChanged(); onCollectionChanged();
} }
@ -105,6 +107,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
impl.getCountButton().setVisible(false); impl.getCountButton().setVisible(false);
impl.getPrevButton().setVisible(false); impl.getPrevButton().setVisible(false);
impl.getNextButton().setVisible(false); impl.getNextButton().setVisible(false);
impl.getFirstButton().setVisible(false);
impl.getLastButton().setVisible(false);
if (size % 100 > 10 && size % 100 < 20) { if (size % 100 > 10 && size % 100 < 20) {
msgKey = "table.rowsCount.msg2Plural1"; msgKey = "table.rowsCount.msg2Plural1";
} else { } else {
@ -127,6 +131,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
impl.getCountButton().setVisible(true); impl.getCountButton().setVisible(true);
impl.getPrevButton().setVisible(false); impl.getPrevButton().setVisible(false);
impl.getNextButton().setVisible(true); impl.getNextButton().setVisible(true);
impl.getFirstButton().setVisible(false);
impl.getLastButton().setVisible(true);
msgKey = "table.rowsCount.msg1"; msgKey = "table.rowsCount.msg1";
countValue = "1-" + size; countValue = "1-" + size;
break; break;
@ -134,6 +140,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
impl.getCountButton().setVisible(true); impl.getCountButton().setVisible(true);
impl.getPrevButton().setVisible(true); impl.getPrevButton().setVisible(true);
impl.getNextButton().setVisible(true); impl.getNextButton().setVisible(true);
impl.getFirstButton().setVisible(true);
impl.getLastButton().setVisible(true);
msgKey = "table.rowsCount.msg1"; msgKey = "table.rowsCount.msg1";
countValue = (start + 1) + "-" + (start + size); countValue = (start + 1) + "-" + (start + size);
break; break;
@ -141,6 +149,8 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
impl.getCountButton().setVisible(false); impl.getCountButton().setVisible(false);
impl.getPrevButton().setVisible(true); impl.getPrevButton().setVisible(true);
impl.getNextButton().setVisible(false); impl.getNextButton().setVisible(false);
impl.getFirstButton().setVisible(true);
impl.getLastButton().setVisible(false);
msgKey = "table.rowsCount.msg2Plural2"; msgKey = "table.rowsCount.msg2Plural2";
countValue = (start + 1) + "-" + (start + size); countValue = (start + 1) + "-" + (start + size);
break; 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) { private void refreshDatasource(CollectionDatasource.SupportsPaging ds) {
refreshing = true; refreshing = true;
try { try {
@ -219,11 +263,13 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
private JButton prevButton; private JButton prevButton;
private JButton nextButton; private JButton nextButton;
private JButton firstButton;
private JButton lastButton;
private JLabel label; private JLabel label;
private JButton countButton; private JButton countButton;
private MigLayout layout; private MigLayout layout;
private final Dimension size = new Dimension(35, 25); private final Dimension size = new Dimension(38, 25);
public RowsCountComponent() { public RowsCountComponent() {
LC lc = new LC(); LC lc = new LC();
@ -235,6 +281,11 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
} }
setLayout(layout); setLayout(layout);
firstButton = new JButton("<<");
add(firstButton);
firstButton.setPreferredSize(size);
firstButton.setMinimumSize(size);
prevButton = new JButton("<"); prevButton = new JButton("<");
add(prevButton); add(prevButton);
prevButton.setPreferredSize(size); prevButton.setPreferredSize(size);
@ -251,6 +302,11 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
add(nextButton); add(nextButton);
nextButton.setPreferredSize(size); nextButton.setPreferredSize(size);
nextButton.setMinimumSize(size); nextButton.setMinimumSize(size);
lastButton = new JButton(">>");
add(lastButton);
lastButton.setPreferredSize(size);
lastButton.setMinimumSize(size);
} }
public JLabel getLabel() { public JLabel getLabel() {
@ -268,5 +324,13 @@ public class DesktopRowsCount extends DesktopAbstractComponent<DesktopRowsCount.
public JButton getNextButton() { public JButton getNextButton() {
return nextButton; return nextButton;
} }
public JButton getFirstButton() {
return firstButton;
}
public JButton getLastButton() {
return lastButton;
}
} }
} }

View File

@ -156,3 +156,5 @@ actions.dialog.Cancel.icon=icons/cancel.png
actions.dialog.Yes.icon=icons/ok.png actions.dialog.Yes.icon=icons/ok.png
actions.dialog.No.icon=icons/cancel.png actions.dialog.No.icon=icons/cancel.png
actions.dialog.Close.icon= actions.dialog.Close.icon=
cuba.gui.rowsCount.arrowButton.width=20px

View File

@ -45,6 +45,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
component.getCountButton().addClickListener(event -> onLinkClick()); component.getCountButton().addClickListener(event -> onLinkClick());
component.getPrevButton().addClickListener(event -> onPrevClick()); component.getPrevButton().addClickListener(event -> onPrevClick());
component.getNextButton().addClickListener(event -> onNextClick()); component.getNextButton().addClickListener(event -> onNextClick());
component.getFirstButton().addClickListener(event -> onFirstClick());
component.getLastButton().addClickListener(event -> onLastClick());
if (datasource.getState() == Datasource.State.VALID) { if (datasource.getState() == Datasource.State.VALID) {
onCollectionChanged(); 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) { protected void refreshDatasource(CollectionDatasource.SupportsPaging ds) {
refreshing = true; refreshing = true;
try { try {
@ -153,6 +188,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
component.getCountButton().setVisible(false); component.getCountButton().setVisible(false);
component.getPrevButton().setVisible(false); component.getPrevButton().setVisible(false);
component.getNextButton().setVisible(false); component.getNextButton().setVisible(false);
component.getFirstButton().setVisible(false);
component.getLastButton().setVisible(false);
if (size % 100 > 10 && size % 100 < 20) { if (size % 100 > 10 && size % 100 < 20) {
msgKey = "table.rowsCount.msg2Plural1"; msgKey = "table.rowsCount.msg2Plural1";
} else { } else {
@ -175,6 +212,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
component.getCountButton().setVisible(true); component.getCountButton().setVisible(true);
component.getPrevButton().setVisible(false); component.getPrevButton().setVisible(false);
component.getNextButton().setVisible(true); component.getNextButton().setVisible(true);
component.getFirstButton().setVisible(false);
component.getLastButton().setVisible(true);
msgKey = "table.rowsCount.msg1"; msgKey = "table.rowsCount.msg1";
countValue = "1-" + size; countValue = "1-" + size;
break; break;
@ -182,6 +221,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
component.getCountButton().setVisible(true); component.getCountButton().setVisible(true);
component.getPrevButton().setVisible(true); component.getPrevButton().setVisible(true);
component.getNextButton().setVisible(true); component.getNextButton().setVisible(true);
component.getFirstButton().setVisible(true);
component.getLastButton().setVisible(true);
msgKey = "table.rowsCount.msg1"; msgKey = "table.rowsCount.msg1";
countValue = (start + 1) + "-" + (start + size); countValue = (start + 1) + "-" + (start + size);
break; break;
@ -189,6 +230,8 @@ public class WebRowsCount extends WebAbstractComponent<CubaRowsCount> implements
component.getCountButton().setVisible(false); component.getCountButton().setVisible(false);
component.getPrevButton().setVisible(true); component.getPrevButton().setVisible(true);
component.getNextButton().setVisible(false); component.getNextButton().setVisible(false);
component.getFirstButton().setVisible(true);
component.getLastButton().setVisible(false);
msgKey = "table.rowsCount.msg2Plural2"; msgKey = "table.rowsCount.msg2Plural2";
countValue = (start + 1) + "-" + (start + size); countValue = (start + 1) + "-" + (start + size);
break; break;

View File

@ -4,6 +4,10 @@
*/ */
package com.haulmont.cuba.web.toolkit.ui; 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.shared.ui.MarginInfo;
import com.vaadin.ui.*; import com.vaadin.ui.*;
import com.vaadin.ui.themes.BaseTheme; import com.vaadin.ui.themes.BaseTheme;
@ -16,6 +20,8 @@ public class CubaRowsCount extends CustomComponent {
protected Button prevButton; protected Button prevButton;
protected Button nextButton; protected Button nextButton;
protected Button firstButton;
protected Button lastButton;
protected Label label; protected Label label;
protected Button countButton; protected Button countButton;
@ -44,8 +50,20 @@ public class CubaRowsCount extends CustomComponent {
contentLayout.setSpacing(true); contentLayout.setSpacing(true);
contentLayout.setHeight("-1px"); contentLayout.setHeight("-1px");
prevButton = new CubaButton("<"); ThemeConstants themeConstants = AppBeans.get(ThemeConstantsManager.class).getConstants();
prevButton.setWidth("-1px"); 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.setStyleName("cuba-paging-change-page");
prevButton.addStyleName("cuba-paging-prev"); prevButton.addStyleName("cuba-paging-prev");
contentLayout.addComponent(prevButton); contentLayout.addComponent(prevButton);
@ -64,13 +82,22 @@ public class CubaRowsCount extends CustomComponent {
contentLayout.addComponent(countButton); contentLayout.addComponent(countButton);
contentLayout.setComponentAlignment(countButton, Alignment.MIDDLE_CENTER); contentLayout.setComponentAlignment(countButton, Alignment.MIDDLE_CENTER);
nextButton = new CubaButton(">"); nextButton = new CubaButton();
nextButton.setWidth("-1px"); nextButton.setIcon(WebComponentsHelper.getIcon("icons/rows-count-next.png"));
nextButton.setWidth(buttonWidth);
nextButton.setStyleName("cuba-paging-change-page"); nextButton.setStyleName("cuba-paging-change-page");
nextButton.addStyleName("cuba-paging-next"); nextButton.addStyleName("cuba-paging-next");
contentLayout.addComponent(nextButton); contentLayout.addComponent(nextButton);
contentLayout.setComponentAlignment(nextButton, Alignment.MIDDLE_CENTER); 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; return contentLayout;
} }
@ -89,4 +116,12 @@ public class CubaRowsCount extends CustomComponent {
public Button getNextButton() { public Button getNextButton() {
return nextButton; return nextButton;
} }
public Button getFirstButton() {
return firstButton;
}
public Button getLastButton() {
return lastButton;
}
} }

View File

@ -158,6 +158,10 @@ cuba.web.icons.plus.png = PLUS_SQUARE_O
cuba.web.icons.plus-btn.png = PLUS cuba.web.icons.plus-btn.png = PLUS
cuba.web.icons.refresh.png = REFRESH cuba.web.icons.refresh.png = REFRESH
cuba.web.icons.remove.png = TIMES 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-down-property.png = CARET_DOWN
cuba.web.icons.report-wizard-next.png = ARROW_RIGHT cuba.web.icons.report-wizard-next.png = ARROW_RIGHT
cuba.web.icons.report-wizard-previous.png = ARROW_LEFT cuba.web.icons.report-wizard-previous.png = ARROW_LEFT

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 297 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 290 B