Skip to content

Instantly share code, notes, and snippets.

@bugabinga
Created November 21, 2013 12:18
Show Gist options
  • Save bugabinga/7580650 to your computer and use it in GitHub Desktop.
Save bugabinga/7580650 to your computer and use it in GitHub Desktop.
An example showcasing how to create a simple pop in dialog in MGWT.
package com.bugabinga.net.client.widget.dialog;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHTML;
import com.google.gwt.user.client.ui.HasText;
import com.googlecode.mgwt.dom.client.event.tap.HasTapHandlers;
import com.googlecode.mgwt.dom.client.event.tap.TapEvent;
import com.googlecode.mgwt.dom.client.event.tap.TapHandler;
import com.googlecode.mgwt.ui.client.dialog.Dialog;
import com.googlecode.mgwt.ui.client.dialog.DialogPanel;
import com.googlecode.mgwt.ui.client.dialog.HasTitleText;
import com.googlecode.mgwt.ui.client.dialog.PopinDialog;
import com.googlecode.mgwt.ui.client.theme.base.DialogCss;
/**
* This is generic example dialog for showing arbitrary HTML content.
*
* @author flasheater
*
*/
public class ExampleDialog implements HasTitleText, HasTapHandlers, Dialog, HasHTML
{
private final PopinDialog popinDialog;
private final DialogPanel containerPanel;
private final DialogCss css;
private final HTML html;
/**
* Constructs an example dialog.
*
* @param closeButtonLabel close button label text
* @param dialogTitle title text of the dialog
* @param html html content
*/
public ExampleDialog( final String dialogTitle, final String html,
final String closeButtonLabel )
{
css = MGWTStyle.getTheme().getMGWTClientBundle().getDialogCss();
css.ensureInjected();
popinDialog = new PopinDialog( css );
containerPanel = new DialogPanel();
this.html = new HTML( html );
layout( closeButtonLabel, dialogTitle );
}
private void layout( final String closeButtonLabel, final String dialogTitle )
{
setTitleText( dialogTitle );
containerPanel.showCancelButton( false );
containerPanel.showOkButton( true );
containerPanel.setOkButtonText( closeButtonLabel );
//FIXME(flasheater): refactor this into css resource
html.getElement().getStyle().setProperty( "display", "-webkit-box" );
html.getElement().getStyle().setProperty( "WebkitBoxOrient", "vertical" );
html.getElement().getStyle().setProperty( "WebkitBoxAlign", "center" );
html.getElement().getStyle().setProperty( "WebkitBoxPack", "center" );
html.getElement().getStyle().setProperty( "paddingTop", "2em" );
containerPanel.getContent().add( html );
popinDialog.add( containerPanel );
}
@Override
public String getHTML()
{
return html.getHTML();
}
@Override
public void setHTML( final String html )
{
html.setHTML( html );
}
@Override
public void show()
{
popinDialog.center();
}
@Override
public void hide()
{
popinDialog.hide();
}
@Override
public HandlerRegistration addTapHandler( final TapHandler handler )
{
return containerPanel.getOkButton().addTapHandler( handler );
}
@Override
public void setTitleText( final String title )
{
containerPanel.getDialogTitle().setText( title );
}
@Override
public String getTitleText()
{
return containerPanel.getDialogTitle().getText();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment