Skip to content

Commit

Permalink
Merge branch 'release_2.5.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	pom.xml
#	src/main/java/gwt/material/design/client/data/Categories.java
#	src/main/java/gwt/material/design/client/data/component/CategoryComponent.java
#	src/main/java/gwt/material/design/client/ui/table/AbstractDataTable.java
#	src/main/java/gwt/material/design/client/ui/table/AbstractTableScaffolding.java
#	src/main/java/gwt/material/design/client/ui/table/TableScaffolding.java
#	src/main/resources/gwt/material/design/client/resources/css/style.min.css
  • Loading branch information
kevzlou7979 committed Sep 6, 2021
2 parents 6f834d6 + 3739b40 commit d9b13b4
Show file tree
Hide file tree
Showing 55 changed files with 1,465 additions and 148 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Current Version 2.5.0-rc1
<dependency>
<groupId>com.github.gwtmaterialdesign</groupId>
<artifactId>gwt-material-table</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>gwt-material-parent</artifactId>
<groupId>com.github.gwtmaterialdesign</groupId>
<version>2.5.0-rc1</version>
<version>2.5.0</version>
</parent>

<artifactId>gwt-material-table</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.gwt.dom.client.StyleInjector;
import gwt.material.design.client.resources.MaterialTableBundle;
import gwt.material.design.client.resources.MaterialTableDebugBundle;
import gwt.material.design.client.ui.pager.MaterialDataPagerClientBundle;

/**
Expand All @@ -34,6 +35,7 @@ public void load() {
// Scripts
injectJs(MaterialTableBundle.INSTANCE.jQueryExt());
injectJs(MaterialTableBundle.INSTANCE.stickyth());
injectJs(MaterialTableBundle.INSTANCE.stickytfoot());
injectJs(MaterialTableBundle.INSTANCE.tableSubHeaders());
injectJs(MaterialTableBundle.INSTANCE.greedyScroll());
injectJs(MaterialTableBundle.INSTANCE.mutateEvents());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*/

import com.google.gwt.dom.client.StyleInjector;
import gwt.material.design.client.resources.MaterialTableBundle;
import gwt.material.design.client.resources.MaterialTableDebugBundle;
import gwt.material.design.client.ui.pager.MaterialDataPagerClientBundle;

Expand All @@ -33,6 +34,7 @@ public class MaterialTableDebugBase extends MaterialDesignBase {
public void load() {
injectDebugJs(MaterialTableDebugBundle.INSTANCE.jQueryExt());
injectDebugJs(MaterialTableDebugBundle.INSTANCE.stickyth());
injectDebugJs(MaterialTableDebugBundle.INSTANCE.stickytfoot());
injectDebugJs(MaterialTableDebugBundle.INSTANCE.tableSubHeaders());
injectDebugJs(MaterialTableDebugBundle.INSTANCE.greedyScroll());
injectDebugJs(MaterialTableDebugBundle.INSTANCE.mutateEvents());
Expand Down
120 changes: 96 additions & 24 deletions src/main/java/gwt/material/design/client/data/AbstractDataView.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.gwt.event.logical.shared.AttachEvent;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.Range;
Expand Down Expand Up @@ -88,7 +87,7 @@ public abstract class AbstractDataView<T> implements DataView<T> {
protected ProvidesKey<T> keyProvider;
//protected List<ComponentFactory<?, T>> componentFactories;
protected JsTableSubHeaders subheaderLib;
protected Panel xScrollPanel;
protected XScrollPanel xScrollPanel;
protected String height;
protected int categoryHeight = 0;
protected int frozenMarginLeft;
Expand All @@ -104,6 +103,7 @@ public abstract class AbstractDataView<T> implements DataView<T> {
protected Table table;
protected MaterialWidget thead;
protected MaterialWidget tbody;
protected TableFooter<T> footer;
protected MaterialProgress progressWidget;
protected TableRow headerRow;
protected JQueryElement container;
Expand All @@ -128,6 +128,7 @@ public abstract class AbstractDataView<T> implements DataView<T> {
private boolean shiftDown;
private boolean useRowExpansion;
private boolean useStickyHeader;
private boolean useStickyFooter;
private boolean useLoadOverlay;
private boolean useCategories;
private SelectionType selectionType = SelectionType.NONE;
Expand Down Expand Up @@ -276,6 +277,8 @@ public void render(Components<Component<?>> components) {

ComponentsRenderedEvent.fire(this);

buildCategoryColumns();

if (pendingRenderEvent) {
RenderedEvent.fire(this);
pendingRenderEvent = false;
Expand All @@ -287,6 +290,7 @@ public void render(Components<Component<?>> components) {
attachHandler = componentWidget.addAttachHandler(handler);
}
} else {
RowEmptyEvent.fire(this);
rendering = false;
}

Expand All @@ -304,6 +308,10 @@ public void render(Components<Component<?>> components) {
return ++maxTries[0] < 125;
}
}, 40);

if (isUseStickyFooter()) {
Scheduler.get().scheduleDeferred(this::setupStickyFooter);
}
}

/**
Expand Down Expand Up @@ -516,7 +524,6 @@ protected void renderColumns() {

public void renderColumn(Column<T, ?> column) {
int index = column.getIndex() + getColumnOffset();
column.setDataView(this);
TableHeader th = renderer.drawColumnHeader(getContainer(), column, column.name(), index);
if (th != null) {
if (column.sortable()) {
Expand All @@ -529,14 +536,14 @@ public void renderColumn(Column<T, ?> column) {
}

addHeader(index, th);
th.setVisible(!column.isHidden());
}

for (RowComponent<T> row : rows) {
Context context = new Context(row.getIndex(), index, getValueKey(row.getData()));
renderer.drawColumn(row.getWidget(), context, row.getData(), column, index, true);
}

refreshStickyHeaders();
refreshStickyComponents();
}

@Override
Expand Down Expand Up @@ -596,6 +603,7 @@ public void setup(TableScaffolding scaffolding) throws Exception {
xScrollPanel = scaffolding.getXScrollPanel();
tbody = table.getBody();
thead = table.getHead();
footer = table.getFooter();
$table = table.getJsElement();

// apply the table-layout style property
Expand Down Expand Up @@ -670,10 +678,12 @@ public void setup(TableScaffolding scaffolding) throws Exception {
$xScrollPanel.on("scroll." + id, e -> {
int scrollLeft = $xScrollPanel.scrollLeft();
innerScroll.prop("scrollLeft", scrollLeft);
if (scrollLeft < 1) {
innerScroll.removeClass("inner-shadow");
} else {
innerScroll.addClass("inner-shadow");
if (hasFrozenColumns()) {
if (scrollLeft < 1) {
innerScroll.removeClass("inner-shadow");
} else {
innerScroll.addClass("inner-shadow");
}
}
return true;
});
Expand Down Expand Up @@ -709,6 +719,11 @@ protected void onSetup(TableScaffolding scaffolding) {

setSelectionType(selectionType);

// Setup Footer
if (footer != null) {
footer.load();
}

renderColumns();

for (CategoryComponent<T> category : categories) {
Expand Down Expand Up @@ -958,6 +973,14 @@ protected void setupStickyHeader() {
}
}

public void setupStickyFooter() {
if ($table != null && display != null && footer != null) {
int marginTop = tableBody.outerHeight() - $(footer).outerHeight();
$table.stickyTableFooter(StickyTableOptions.create($(".table-body", getContainer()), marginTop));
$table.stickyTableFooter("toggleHeadersAutoLoad");
}
}

protected void setupSubHeaders() {
if ($table != null && display != null) {
subheaderLib = JsTableSubHeaders.newInstance(
Expand Down Expand Up @@ -1048,7 +1071,7 @@ public boolean isHeaderVisible(int colIndex) {

@Override
public <X extends Column<T, ?>> X addColumn(X column) {
return addColumn("", column);
return addColumn(column.name(), column);
}

@Override
Expand Down Expand Up @@ -1083,6 +1106,7 @@ public boolean isHeaderVisible(int colIndex) {
renderColumn(column);
}

column.setDataView(this);
InsertColumnEvent.fire(this, beforeIndex, column, header);

return column;
Expand Down Expand Up @@ -1271,7 +1295,7 @@ public void removeColumn(int colIndex, boolean hardRemove) {
}

reindexHeadersAndRows();
refreshStickyHeaders();
refreshStickyComponents();

if (hardRemove) {
columns.remove(colIndex);
Expand Down Expand Up @@ -1353,11 +1377,19 @@ public void setSelectionType(SelectionType selectionType) {
row.getWidget().insert(selectionCell, 0);
}
reindexHeadersAndRows();

// Refresh Sticky Components
refreshStickyComponents();
} else if (selectionType.equals(SelectionType.NONE) && hadSelection) {
removeHeader(0);
$("td#col0", getContainer()).remove();
reindexHeadersAndRows();
}

// Update Footer Column
if (footer != null && footer.isAttached()) {
footer.updateSelectionType(selectionType);
}
}
}

Expand All @@ -1382,6 +1414,10 @@ protected void setupHeaderSelectionBox() {
return false;
});
}
th.setWidth("32px");
th.setMinWidth("32px");
th.setMaxWidth("32px");

addHeader(0, th);
}

Expand Down Expand Up @@ -1420,6 +1456,8 @@ protected void reindexHeadersAndRows() {
td.setId("col" + i);
}
}


}

protected void reindexColumns(int fromIndex) {
Expand All @@ -1445,7 +1483,6 @@ public void setUseStickyHeader(boolean stickyHeader) {
// Destroy existing sticky header function
$table.stickyTableHeaders("destroy");
} else if (stickyHeader) {
// Initialize sticky header
setupStickyHeader();
}
this.useStickyHeader = stickyHeader;
Expand All @@ -1456,21 +1493,46 @@ public boolean isUseStickyHeader() {
return useStickyHeader;
}

@Override
public void setUseStickyFooter(boolean stickyFooter) {
if (this.useStickyFooter && !stickyFooter) {
$table.stickyTableFooter("destroy");
} else if (stickyFooter) {
setupStickyFooter();
}
this.useStickyFooter = stickyFooter;
}

@Override
public boolean isUseStickyFooter() {
return useStickyFooter;
}

/**
* TODO: This method can be optimized.
*/
private void refreshStickyHeaders() {
private void refreshStickyComponents() {
if ($table != null) {
// Destroy existing sticky header function
$table.stickyTableHeaders("destroy");

if (isUseStickyHeader()) {
// Initialize sticky header
setupStickyHeader();
}
}
}

protected void refreshStickyFooter() {
if ($table != null) {
// Destroy existing sticky footer function
$table.stickyTableFooter("destroy");

if (isUseStickyFooter()) {
setupStickyFooter();
}
}
}

@Override
public void selectAllRows(boolean select) {
selectAllRows(select, true);
Expand Down Expand Up @@ -1893,15 +1955,15 @@ public void enableCategory(String categoryName) {
}

@Override
public Categories getCategories() {
return new Categories(categories);
public Categories<T> getCategories() {
return new Categories<>(categories);
}

@Override
public Categories getOpenCategories() {
Categories openCategories = null;
public Categories<T> getOpenCategories() {
Categories<T> openCategories = null;
if (isUseCategories()) {
openCategories = new Categories();
openCategories = new Categories<>();
for (CategoryComponent<T> category : categories) {
TableSubHeader element = category.getWidget();
if (element != null && element.isOpen()) {
Expand Down Expand Up @@ -2390,6 +2452,11 @@ public List<TableHeader> getHeaders() {
return headers;
}

@Override
public TableFooter<T> getFooter() {
return footer;
}

protected void addHeader(int index, TableHeader header) {
if (headers.size() < 1) {
headers.add(header);
Expand All @@ -2404,7 +2471,7 @@ protected void removeHeader(int index) {
headers.remove(index);
headerRow.remove(index);
}
refreshStickyHeaders();
refreshStickyComponents();
}

protected int getCategoryRowCount(String category) {
Expand Down Expand Up @@ -2495,13 +2562,18 @@ public void calculateFrozenColumns() {
}
}

if (isUseStickyHeader() && (leftFrozenColumns > 0 || rightFrozenColumns > 0)) {
logger.warning("Sticky header is not supported with frozen columns, this will be disabled automatically.");
if ((isUseStickyHeader() || isUseStickyFooter()) && (leftFrozenColumns > 0 || rightFrozenColumns > 0)) {
logger.warning("Sticky header or footer is not supported with frozen columns, this will be disabled automatically.");
setUseStickyHeader(false);
setUseStickyFooter(false);
}
}
}

protected void buildCategoryColumns() {
if (isUseCategories()) getCategories().buildColumns(getColumns());
}

protected void calculateComputedColumns() {
List<RowComponent<T>> rows = getRows();
for (RowComponent<T> row : rows) {
Expand Down Expand Up @@ -2571,7 +2643,7 @@ public void setDefaultFormatProvider(ColumnFormatProvider defaultFormatProvider)
}

@Override
public ColumnFormatProvider getDefaultFormatProvider() {
public ColumnFormatProvider getFormatProvider() {
if (defaultFormatProvider == null) {
defaultFormatProvider = new ColumnFormatProvider();
}
Expand All @@ -2584,7 +2656,7 @@ public void setDefaultBlankPlaceholder(String defaultBlankPlaceholder) {
}

@Override
public String getDefaultBlankPlaceholder() {
public String getBlankPlaceholder() {
return defaultBlankPlaceholder;
}

Expand Down
Loading

0 comments on commit d9b13b4

Please sign in to comment.