MessageDialog MessageDialogPage

public abstract class MessageDialog extends AbstractDialog<String>
{
    private static final long serialVersionUID = 1L;

    private Label label;
    private DialogButtons buttons;

    /**
     * Constructor.
     * @param id the markupId, an html div suffice to host a dialog.
     * @param title the title of the dialog
     * @param message the message to be displayed
     * @param buttons button set to display
     */
    public MessageDialog(String id, String title, String message, DialogButtons buttons)
    {
        this(id, title, message, buttons, DialogIcon.NONE);
    }

    /**
     * Constructor.
     * @param id the markupId, an html div suffice to host a dialog.
     * @param title the title of the dialog
     * @param message the message to be displayed
     * @param buttons button set to display
     */
    public MessageDialog(String id, IModel<String> title, IModel<String> message, DialogButtons buttons)
    {
        this(id, title, message, buttons, DialogIcon.NONE);
    }

    /**
     * Constructor.
     * @param id the markupId, an html div suffice to host a dialog.
     * @param title the title of the dialog
     * @param message the message to be displayed
     * @param buttons button set to display
     * @param icon the predefined icon to display
     */
    public MessageDialog(String id, String title, String message, DialogButtons buttons, DialogIcon icon)
    {
        this(id, Model.of(title), Model.of(message), buttons, icon);
    }

    /**
     * Constructor.
     * @param id the markupId, an html div suffice to host a dialog.
     * @param title the title of the dialog
     * @param message the message to be displayed
     * @param buttons button set to display
     * @param icon the predefined icon to display
     */
    public MessageDialog(String id, IModel<String> title, IModel<String> message, DialogButtons buttons, DialogIcon icon)
    {
        super(id, title, message, true);
        this.buttons = buttons;

        WebMarkupContainer container = new WebMarkupContainer("container");
        this.add(container);

        container.add(AttributeModifier.append("class", icon.getStyle()));
        container.add(new EmptyPanel("icon").add(AttributeModifier.replace("class", icon)));

        this.label = new Label("message", this.getModel());
        container.add(this.label.setOutputMarkupId(true));
    }

    @Override
    protected final List<DialogButton> getButtons()
    {
        if (this.buttons != null)
        {
            return this.buttons.toList();
        }

        return super.getButtons(); //cannot happen
    }

    @Override
    protected void onOpen(AjaxRequestTarget target)
    {
        target.add(this.label);
    }
}

<html xmlns:wicket="http://wicket.apache.org">
    <head>
    </head>
    <body>
        <wicket:panel>
            <div wicket:id="container" style="padding: 4px;">
                <span wicket:id="icon" style="display: inline-block; margin-right: 0.1em; vertical-align: middle;"></span>
                <span wicket:id="message" style="vertical-align: middle;"></span>
            </div>
        </wicket:panel>
    </body>
</html>

public class MessageDialogPage extends AbstractDialogPage
{
    private static final long serialVersionUID = 1L;

    public MessageDialogPage()
    {
        this.init();
    }

    private void init()
    {
        final Form<Void> form = new Form<Void>("form");
        this.add(form);

        // FeedbackPanel //
        final FeedbackPanel feedback = new JQueryFeedbackPanel("feedback");
        form.add(feedback.setOutputMarkupId(true));

        // Dialog //
        final MessageDialog informDialog = new MessageDialog("infoDialog", "Information", "This is a information message", DialogButtons.OK_CANCEL, DialogIcon.INFO) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClose(AjaxRequestTarget target, DialogButton button)
            {
            }
        };

        this.add(informDialog);

        final MessageDialog warningDialog = new MessageDialog("warningDialog", "Warning", "Are you sure you want to do something?", DialogButtons.YES_NO, DialogIcon.WARN) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClose(AjaxRequestTarget target, DialogButton button)
            {
            }
        };

        this.add(warningDialog);

        final MessageDialog errorDialog = new MessageDialog("errorDialog", new StringResourceModel("dialog.error.title", this, null), new StringResourceModel("dialog.error.message", this, null), DialogButtons.OK, DialogIcon.ERROR) {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClose(AjaxRequestTarget target, DialogButton button)
            {
            }
        };

        this.add(errorDialog);


        // Buttons //
        form.add(new AjaxButton("info") {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form)
            {
                informDialog.open(target);
            }
        });

        form.add(new AjaxButton("warning") {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form)
            {
                warningDialog.open(target);
            }
        });

        form.add(new AjaxButton("error") {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form)
            {
                errorDialog.open(target);
            }
        });
    }
}
AbstractDialogPage
abstract class AbstractDialogPage extends SamplePage
{
    private static final long serialVersionUID = 1L;
    
    public AbstractDialogPage()
    {
        
    }
    
    @Override
    protected List<DemoLink> getDemoLinks()
    {
        return Arrays.asList(
                new DemoLink(MessageDialogPage.class, "Message Dialogs"),
                new DemoLink(CustomDialogPage.class, "Custom Dialog"),
                new DemoLink(FragmentDialogPage.class, "Fragment Dialog"),

                new DemoLink(InputDialogPage.class, "Input Dialog"),
                new DemoLink(FormDialogPage.class, "Form Dialog (Slider sample)"),
                new DemoLink(UserDialogPage.class, "<b>Demo:</b> User Accounts")
            );
    }
}
SamplePage
public abstract class SamplePage extends TemplatePage
{
    private static final long serialVersionUID = 1L;
    private enum Source { HTML, JAVA, TEXT }

    private static String getSource(Source source, Class<? extends SamplePage> scope)
    {
        PackageTextTemplate stream = new PackageTextTemplate(scope, String.format("%s.%s", scope.getSimpleName(), source.toString().toLowerCase()));
        String string = ResourceUtil.readString(stream);

        try
        {
            stream.close();
        }
        catch (IOException e) { /* not handled */ }

        return string;
    }


    public SamplePage()
    {
        super();

        this.add(new Label("title", this.getResourceString("title")));
        this.add(new Label("source-desc", this.getSource(Source.TEXT)).setEscapeModelStrings(false));
        this.add(new Label("source-java", this.getSource(Source.JAVA)));
        this.add(new Label("source-html", this.getSource(Source.HTML)));
        this.add(new JQueryBehavior("#wrapper-panel-source", "tabs"));

        this.add(new ListView<DemoLink>("demo-list", this.getDemoLinks()) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(ListItem<DemoLink> item)
            {
                DemoLink object = item.getModelObject();
                Link<SamplePage> link = new BookmarkablePageLink<SamplePage>("link", object.getPage());
                link.add(new Label("label", object.getLabel()).setEscapeModelStrings(false)); //new StringResourceModel("title", ), getString("title", type)

                item.add(link);
            }

            @Override
            public boolean isVisible()
            {
                return this.getModelObject().size() > 0; //model object cannot be null
            }

        });
    }

    private String getResourceString(String string)
    {
        return this.getString(String.format("%s.%s", this.getClass().getSimpleName(), string));
    }

    private String getSource(Source source)
    {
        return SamplePage.getSource(source, this.getClass());
    }

    protected List<DemoLink> getDemoLinks()
    {
        return Collections.emptyList();
    }

    protected class DemoLink implements IClusterable
    {
        private static final long serialVersionUID = 1L;

        private final Class<? extends SamplePage> page;
        private final String label;

        public DemoLink(Class<? extends SamplePage> page, String label)
        {
            this.page = page;
            this.label = label;
        }

        public Class<? extends SamplePage> getPage()
        {
            return this.page;
        }

        public String getLabel()
        {
            return this.label;
        }
    }
}

public abstract class TemplatePage extends WebPage
{
    private static final long serialVersionUID = 1L;

    public TemplatePage()
    {
        super();

        this.add(new Label("version", getApplication().getFrameworkSettings().getVersion()));
    }

    @Override
    protected void onInitialize()
    {
        super.onInitialize();

        this.add(new GoogleAnalyticsBehavior(this));
    }
}

class GoogleAnalyticsBehavior extends Behavior
{
    private static final long serialVersionUID = 1L;

    private final String url;

    public GoogleAnalyticsBehavior(final WebPage page)
    {
        this.url = GoogleAnalyticsBehavior.getUrl(page);
    }

    private IModel<Map<String, Object>> newResourceModel()
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("url", this.url);

        return Model.ofMap(map);
    }

    private ResourceReference newResourceReference()
    {
        return new TextTemplateResourceReference(GoogleAnalyticsBehavior.class, "gaq.js", this.newResourceModel());
    }

    @Override
    public void renderHead(Component component, IHeaderResponse response)
    {
        super.renderHead(component, response);

        response.render(JavaScriptHeaderItem.forReference(this.newResourceReference(), "gaq"));
    }

    private static String getUrl(WebPage page)
    {
        Url pageUrl = Url.parse(page.urlFor(page.getClass(), null).toString());
        Url baseUrl = new Url(page.getRequestCycle().getUrlRenderer().getBaseUrl());

        baseUrl.resolveRelative(pageUrl);

        return String.format("%s/%s", page.getRequest().getContextPath(), baseUrl);
    }
}

<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<wicket:head>
    <title>Wicket - jQuery UI: message dialog box</title>
</wicket:head>
</head>
<body>
<wicket:extend>
    <div id="wrapper-panel-frame" class="ui-corner-all">
        <form wicket:id="form">
            <button wicket:id="info">Open info</button>
            <button wicket:id="warning">Open warning</button>
            <button wicket:id="error">Open error</button>
            <br/><br/>
            <div wicket:id="feedback" style="width: 360px;"></div>
        </form>
    </div>
    <div wicket:id="infoDialog">[info]</div>
    <div wicket:id="warningDialog">[warning]</div>
    <div wicket:id="errorDialog">[error]</div>
</wicket:extend>
</body>
</html>


转载于:https://my.oschina.net/u/1047983/blog/146597

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值