Skip to content

Instantly share code, notes, and snippets.

@kevzlou7979
Created March 27, 2018 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevzlou7979/4667f68416bdc9032f679c2ae28c0ac2 to your computer and use it in GitHub Desktop.
Save kevzlou7979/4667f68416bdc9032f679c2ae28c0ac2 to your computer and use it in GitHub Desktop.
package com.patient.portal.client.base;
import com.google.gwt.core.client.Scheduler;
import com.google.inject.Inject;
import com.google.web.bindery.event.shared.EventBus;
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.ViewImpl;
import com.gwtplatform.mvp.client.presenter.slots.NestedSlot;
import com.gwtplatform.mvp.client.proxy.Proxy;
import com.patient.portal.client.events.PageShownEvent;
import java.util.List;
public abstract class AbstractTablePresenter<X, V extends AbstractTablePresenter.MyView, P extends Proxy<?>> extends Presenter<V, P> {
public interface MyView<X> extends View {
void buildTable();
void loadData(List<X> data);
AppTable<X> getDataTable();
}
@Inject
public AbstractTablePresenter(
EventBus eventBus,
V view,
P proxy, NestedSlot slotMain) {
super(eventBus, view, proxy, slotMain);
}
@Override
protected void onBind() {
super.onBind();
Scheduler.get().scheduleDeferred(() -> loadData());
}
protected abstract void loadData();
@Override
protected void onReveal() {
super.onReveal();
if (getView() instanceof ViewImpl) {
PageShownEvent.fire(getTitle(), getDescription(), (ViewImpl) getView(), this);
}
}
protected abstract String getTitle();
protected abstract String getDescription();
}
package com.patient.portal.client.base;
import com.gwtplatform.mvp.client.ViewImpl;
import com.patient.portal.client.HasDataTable;
import com.patient.portal.client.application.mixins.SearchMixin;
import gwt.material.design.client.ui.MaterialPanel;
import java.util.List;
public abstract class AbstractTableViewImpl<X> extends ViewImpl implements HasDataTable<X> {
protected AppTable<X> table;
protected SearchMixin<X, AppTable> searchMixin;
public void buildTable() {
table = new AppTable<>();
addColumns();
getTableContainer().add(table);
}
protected abstract void addColumns();
@Override
public void loadData(List<X> data) {
getSearchMixin().loadData(data);
}
@Override
public List<X> getAllData() {
return getSearchMixin().getAllData();
}
@Override
public void reset() {
getSearchMixin().reset();
}
public SearchMixin<X, AppTable> getSearchMixin() {
if (searchMixin == null) {
searchMixin = new SearchMixin<>(table);
}
return searchMixin;
}
public AppTable<X> getDataTable() {
return table;
}
public abstract MaterialPanel getTableContainer();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment