Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBPM-6892 - Remove spacing between table results and controls #202

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package org.uberfire.ext.widgets.common.client.tables;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Style;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HasWidgets;
Expand All @@ -39,8 +41,9 @@ public class PagedTable<T>
extends SimpleTable<T> {

public static final int DEFAULT_PAGE_SIZE = 10;
public static final int ROW_HEIGHT_PX = 33;
public static final int HEIGHT_OFFSET_PX = 56;
public static final int ROW_HEIGHT_PX = 30;
public static final int FIXED_HEIGHT_OFFSET_PX = 56;
public static final int HEIGHT_OFFSET_PX = 30;
private static Binder uiBinder = GWT.create(Binder.class);

@UiField
Expand All @@ -55,6 +58,7 @@ public class PagedTable<T>
protected boolean showPageSizesSelector = false;
private int pageSize;
private AbstractDataProvider<T> dataProvider;
private boolean useFixedHeight = true;

public PagedTable() {
this(DEFAULT_PAGE_SIZE);
Expand Down Expand Up @@ -100,8 +104,25 @@ public PagedTable(final int pageSize,
final boolean showPageSizesSelector,
final boolean showFFButton,
final boolean showLButton) {
this(pageSize,
providesKey,
gridGlobalPreferences,
showPageSizesSelector,
showFFButton,
showLButton,
true);
}

public PagedTable(final int pageSize,
final ProvidesKey<T> providesKey,
final GridGlobalPreferences gridGlobalPreferences,
final boolean showPageSizesSelector,
final boolean showFFButton,
final boolean showLButton,
final boolean useFixedHeight) {
super(providesKey,
gridGlobalPreferences);
this.useFixedHeight = useFixedHeight;
this.showPageSizesSelector = showPageSizesSelector;
this.pageSize = pageSize;
this.dataGrid.setPageStart(0);
Expand All @@ -115,6 +136,13 @@ public PagedTable(final int pageSize,
createPageSizesListBox(5,
20,
5);

if (useFixedHeight == false) {
dataGrid.addRangeChangeHandler(e -> Scheduler.get().scheduleDeferred(() -> setTableHeight()));
dataGrid.addRowCountChangeHandler(e -> Scheduler.get().scheduleDeferred(() -> setTableHeight()));
dataGrid.getElement().getStyle().setMarginBottom(10,
Style.Unit.PX);
}
}

@Override
Expand Down Expand Up @@ -144,7 +172,12 @@ public final void loadPageSizePreferences() {
this.dataGrid.setPageStart(0);
this.dataGrid.setPageSize(pageSize);
this.pager.setPageSize(pageSize);
int height = ((pageSize <= 0 ? 1 : pageSize) * ROW_HEIGHT_PX) + HEIGHT_OFFSET_PX;
setTableHeight();
}

protected void setTableHeight() {
int base = useFixedHeight ? pageSize : dataGrid.getRowCount() - dataGrid.getVisibleRange().getStart();
int height = ((base <= 0 ? 1 : base) * ROW_HEIGHT_PX) + (useFixedHeight ? FIXED_HEIGHT_OFFSET_PX : HEIGHT_OFFSET_PX);
this.dataGrid.setHeight(height + "px");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
xmlns:g="urn:import:com.google.gwt.user.client.ui"
xmlns:b="urn:import:org.gwtbootstrap3.client.ui"
xmlns:bg="urn:import:org.gwtbootstrap3.client.ui.gwt"
xmlns:bh="urn:import:org.gwtbootstrap3.client.ui.html"
xmlns:uf="urn:import:org.uberfire.ext.widgets.table.client">

<ui:style>
Expand All @@ -33,7 +34,7 @@
}

.rightToolBar {
float: right;
display: inline;
text-align: right;
}

Expand All @@ -50,31 +51,33 @@
<b:Row>
<b:Column size="MD_12" ui:field="topToolbar"/>
</b:Row>
<g:HorizontalPanel ui:field="toolbarContainer" width="100%">
<g:cell width="33%">
<b:Row ui:field="toolbarContainer">
<b:Column size="MD_4">
<g:FlowPanel width="100%" ui:field="leftToolbar" addStyleNames="{style.leftToolBar}"></g:FlowPanel>
</g:cell>
<g:cell width="33%">
</b:Column>
<b:Column size="MD_4">
<g:FlowPanel width="100%" ui:field="centerToolbar" addStyleNames="{style.centerToolBar}"></g:FlowPanel>
</g:cell>
<g:cell width="33%" horizontalAlignment="right">
<g:HorizontalPanel ui:field="rightToolbar">
</b:Column>
<b:Column size="MD_4">
<bh:Div ui:field="rightToolbar" pull="RIGHT">
<g:FlowPanel width="100%" ui:field="rightActionsToolbar" addStyleNames="{style.rightToolBar}"/>
<b:Button ui:field="columnPickerButton" dataToggle="BUTTON" icon="COLUMNS"/>
</g:HorizontalPanel>
</g:cell>
</g:HorizontalPanel>
<g:SimplePanel>
<bg:DataGrid ui:field="dataGrid" />
</g:SimplePanel>
<g:HorizontalPanel width="100%">
<g:cell width="50%" horizontalAlignment="left" verticalAlignment="middle">
</bh:Div>
</b:Column>
</b:Row>
<b:Row>
<b:Column size="MD_12">
<bg:DataGrid ui:field="dataGrid"/>
</b:Column>
</b:Row>
<b:Row>
<b:Column size="MD_6">
<b:ListBox ui:field="pageSizesSelector" width="100px"/>
</g:cell>
<g:cell width="50%" horizontalAlignment="right" verticalAlignment="top">
</b:Column>
<b:Column size="MD_6">
<uf:UberfireSimplePager ui:field="pager" addStyleNames="pagination pagination-right pull-right {style.pager}"/>
</g:cell>
</g:HorizontalPanel>
</b:Column>
</b:Row>
</g:FlowPanel>

</ui:UiBinder>
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,40 @@ public class PagedTableTest {

@Test
public void testSetDataProvider() throws Exception {
PagedTable pagedTable = new PagedTable(5);
PagedTable pagedTable = new PagedTable(5);

pagedTable.setDataProvider(dataProvider);
verify(dataProvider).addDataDisplay(pagedTable);
}


@Test
public void testDataGridFixedHeight() throws Exception {
final int PAGE_SIZE = 10;
final int EXPECTED_HEIGHT_PX = (PAGE_SIZE * PagedTable.ROW_HEIGHT_PX) + PagedTable.FIXED_HEIGHT_OFFSET_PX;
PagedTable pagedTable = new PagedTable(PAGE_SIZE);
pagedTable.dataGrid = spy(pagedTable.dataGrid);

verify(pagedTable.dataGrid,
times(0)).setHeight(anyString());
pagedTable.loadPageSizePreferences();
verify(pagedTable.dataGrid,
times(1)).setHeight(eq(EXPECTED_HEIGHT_PX + "px"));
}

@Test
public void testDataGridHeight() throws Exception {
final int PAGE_SIZE = 10;
final int EXPECTED_HEIGHT_PX = (PAGE_SIZE * PagedTable.ROW_HEIGHT_PX) + PagedTable.HEIGHT_OFFSET_PX;
PagedTable pagedTable = new PagedTable(PAGE_SIZE);
pagedTable.dataGrid = spy(pagedTable.dataGrid);

verify(pagedTable.dataGrid, times(0)).setHeight(anyString());
final int PAGE_SIZE = 10;
final int ROWS = 2;
final int EXPECTED_HEIGHT_PX = (ROWS * PagedTable.ROW_HEIGHT_PX) + PagedTable.HEIGHT_OFFSET_PX;
PagedTable pagedTable = new PagedTable(PAGE_SIZE, null, null, false, false, false, false);
pagedTable.dataGrid = spy(pagedTable.dataGrid);
when(pagedTable.dataGrid.getRowCount()).thenReturn(ROWS);

verify(pagedTable.dataGrid,
times(0)).setHeight(anyString());
pagedTable.loadPageSizePreferences();
verify(pagedTable.dataGrid, times(1)).setHeight(eq(EXPECTED_HEIGHT_PX + "px"));
verify(pagedTable.dataGrid,
times(1)).setHeight(eq(EXPECTED_HEIGHT_PX + "px"));
}

@Test
Expand All @@ -62,11 +80,11 @@ public void testLoadPageSizePreferencesResetsPageStart() throws Exception {
PagedTable pagedTable = new PagedTable(PAGE_SIZE);
pagedTable.dataGrid = spy(pagedTable.dataGrid);

verify(pagedTable.dataGrid, times(0)).setPageStart(0);
verify(pagedTable.dataGrid,
times(0)).setPageStart(0);

pagedTable.loadPageSizePreferences();
verify(pagedTable.dataGrid, times(1)).setPageStart(0);
verify(pagedTable.dataGrid,
times(1)).setPageStart(0);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.annotation.PostConstruct;

import org.jboss.errai.ioc.client.api.EntryPoint;
import org.uberfire.client.views.pfly.sys.PatternFlyBootstrapper;
import org.uberfire.ext.widgets.table.client.resources.UFTableResources;

@EntryPoint
Expand All @@ -26,5 +27,6 @@ public class TableEntryPoint {
@PostConstruct
public void startApp() {
UFTableResources.INSTANCE.CSS().ensureInjected();
PatternFlyBootstrapper.ensurejQueryIsAvailable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import com.google.gwt.user.cellview.client.ColumnSortEvent;
import com.google.gwt.user.cellview.client.ColumnSortList;
import com.google.gwt.user.cellview.client.RowStyles;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.CellPreviewEvent;
import com.google.gwt.view.client.HasData;
Expand All @@ -42,7 +42,6 @@
import com.google.gwt.view.client.SelectionModel;
import org.gwtbootstrap3.client.ui.Button;
import org.gwtbootstrap3.client.ui.Label;
import org.uberfire.client.views.pfly.sys.PatternFlyBootstrapper;
import org.uberfire.ext.widgets.table.client.resources.UFTableResources;

/**
Expand All @@ -59,9 +58,9 @@ public class UberfireSimpleTable<T>
@UiField(provided = true)
public DataGrid<T> dataGrid;
@UiField
public HorizontalPanel toolbarContainer;
public ComplexPanel toolbarContainer;
@UiField
public HorizontalPanel rightToolbar;
public ComplexPanel rightToolbar;
@UiField
public FlowPanel rightActionsToolbar;
@UiField
Expand Down Expand Up @@ -125,8 +124,6 @@ public void setEmptyTableCaption(final String emptyTableCaption) {
}

protected void setupDataGrid() {
PatternFlyBootstrapper.ensurejQueryIsAvailable();

dataGrid.setSkipRowHoverCheck(false);
dataGrid.setSkipRowHoverStyleUpdate(false);
dataGrid.addStyleName(UFTableResources.INSTANCE.CSS().dataGridMain());
Expand Down