Skip to content

Instantly share code, notes, and snippets.

@slugmandrew
Created August 21, 2013 14:13
Show Gist options
  • Save slugmandrew/6294986 to your computer and use it in GitHub Desktop.
Save slugmandrew/6294986 to your computer and use it in GitHub Desktop.
AdminModule and Presenter/View/UiBinder triplet
public class AdminModule extends AbstractPresenterModule
{
@Override
protected void configure()
{
bindPresenter(AdminPresenter.class, AdminPresenter.MyView.class, AdminView.class, AdminPresenter.MyProxy.class);
}
}
public class AdminPresenter extends Presenter<AdminPresenter.MyView, AdminPresenter.MyProxy>
{
public interface MyView extends View
{
HasClickHandlers getFillDatastoreButton();
HasClickHandlers getParseMtcGuidesButton();
HasClickHandlers getParseTariffBooksButton();
}
/**
* The logged in Gatekeeper prevents folks that are not logged in from seeing this presenter.
*/
@Title("Admin Panel")
@ProxyStandard
@NameToken(NameTokens.admin)
@UseGatekeeper(AdminGatekeeper.class)
public interface MyProxy extends ProxyPlace<AdminPresenter>
{
}
private DispatchAsync dispatchAsync;
@Inject
public AdminPresenter(EventBus eventBus, MyView view, MyProxy proxy, DispatchAsync dispatchAsync, CurrentUserDto currentUser)
{
super(eventBus, view, proxy, ApplicationPresenter.TYPE_MainContent);
this.dispatchAsync = dispatchAsync;
}
@Override
protected void onReveal()
{
super.onReveal();
}
@Override
protected void onBind()
{
super.onBind();
// using registerHandler() so that GWTP removes the handler for me later
registerHandler(getView().getFillDatastoreButton().addClickHandler(new ClickHandler()
{
@Override
public void onClick(ClickEvent event)
{
// the action we want to do
FillDatastore action = new FillDatastore();
// execute it, passing a callback for the result
dispatchAsync.execute(action, new AsyncCallbackImpl<FillDatastoreResult>()
{
@Override
public void onSuccess(FillDatastoreResult result)
{
Window.alert("Success filling datastore!");
History.fireCurrentHistoryState();
}
});
}
}));
}
}
public class AdminView extends ViewImpl implements AdminPresenter.MyView
{
@UiField
Button fillDatastoreButton, parseMtcGuidesButton, parseTariffBooksButton;
public interface Binder extends UiBinder<Widget, AdminView>
{
}
@Inject
public AdminView(Binder uiBinder)
{
initWidget(uiBinder.createAndBindUi(this));
}
@Override
public HasClickHandlers getFillDatastoreButton()
{
return fillDatastoreButton;
}
@Override
public HasClickHandlers getParseMtcGuidesButton()
{
return parseMtcGuidesButton;
}
@Override
public HasClickHandlers getParseTariffBooksButton()
{
return parseTariffBooksButton;
}
}
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:g='urn:import:com.google.gwt.user.client.ui' xmlns:b='urn:import:com.github.gwtbootstrap.client.ui'>
<ui:style src="../../resources/GlobalStyles.css" field="global" />
<g:HTMLPanel>
<b:FluidContainer>
<b:FluidRow>
<b:Column size="12">
<b:Heading size="2" subtext="Add data to the system for testing">Add customer and pricing data</b:Heading>
</b:Column>
</b:FluidRow>
<b:FluidRow>
<b:Column size="12">
<b:Paragraph>&nbsp;</b:Paragraph>
</b:Column>
</b:FluidRow>
<b:FluidRow>
<b:Column size="4" addStyleNames="{global.center}">
<b:Well>
<b:Heading size="3">Step 1)</b:Heading>
<b:Paragraph>
If the Accounts page seems to contain no data, press this button to generate 30 accounts with related Site, Supply and Contact
info.
</b:Paragraph>
<b:Button size="LARGE" type="DANGER" ui:field="fillDatastoreButton">Fill Datastore</b:Button>
</b:Well>
</b:Column>
<b:Column size="4" addStyleNames="{global.center}">
<b:Well>
<b:Heading size="3">Step 2)</b:Heading>
<b:Paragraph>
For quote creation, groups of are extracted from MTC Guides using this button. They are used to look up tariffs for any particular
meter.
</b:Paragraph>
<b:Button size="LARGE" type="WARNING" ui:field="parseMtcGuidesButton">Parse MTC Guides</b:Button>
</b:Well>
</b:Column>
<b:Column size="4" addStyleNames="{global.center}">
<b:Well>
<b:Heading size="3">Step 3)</b:Heading>
<b:Paragraph>
Once the MTC Guides have been parsed and saved in the datastore, tariffs can be associated with the right MTC group.
</b:Paragraph>
<b:Button size="LARGE" type="SUCCESS" ui:field="parseTariffBooksButton">Parse Tariff Books</b:Button>
</b:Well>
</b:Column>
</b:FluidRow>
</b:FluidContainer>
</g:HTMLPanel>
</ui:UiBinder>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment