package org.jboss.as.console.client.shared.subsys.mail;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import org.jboss.as.console.client.Console;
import org.jboss.as.console.client.domain.model.ProfileRecord;
import org.jboss.as.console.client.domain.model.ServerGroupRecord;
import org.jboss.as.console.client.shared.help.FormHelpPanel;
import org.jboss.ballroom.client.widgets.forms.ComboBoxItem;
import org.jboss.ballroom.client.widgets.forms.Form;
import org.jboss.ballroom.client.widgets.forms.FormValidation;
import org.jboss.ballroom.client.widgets.forms.TextBoxItem;
import org.jboss.ballroom.client.widgets.window.DialogueOptions;
import org.jboss.ballroom.client.widgets.window.WindowContentBuilder;
import org.jboss.dmr.client.ModelNode;

/**
 * @author Heiko Braun
 * @date 11/28/11
 */
public class NewMailSessionWizard {
    private MailPresenter presenter;

    public NewMailSessionWizard(MailPresenter presenter) {
        this.presenter = presenter;
    }

    Widget asWidget() {
        VerticalPanel layout = new VerticalPanel();
        layout.setStyleName("window-content");

        final Form<MailSession> form = new Form(MailSession.class);

        TextBoxItem jndi = new TextBoxItem("jndiName", "JNDI Name");
        TextBoxItem pop = new TextBoxItem("popServer", "Pop3 Server") {
            {
                setRequired(false);
            }
        };
        TextBoxItem imap = new TextBoxItem("imapServer", "IMAP Server") {{
            setRequired(false);
        }};

        TextBoxItem smtp = new TextBoxItem("smtpServer", "SMTP Server");

        form.setFields(jndi, smtp, imap, pop);

        DialogueOptions options = new DialogueOptions(

                // save
                new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        // merge base

                        FormValidation validation = form.validate();
                        if(validation.hasErrors())
                            return;

                        presenter.onCreateSession(form.getUpdatedEntity());

                    }
                },

                // cancel
                new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        presenter.closeDialoge();
                    }
                }

        );

        // ----------------------------------------

        Widget formWidget = form.asWidget();

        final FormHelpPanel helpPanel = new FormHelpPanel(
                new FormHelpPanel.AddressCallback() {
                    @Override
                    public ModelNode getAddress() {
                        ModelNode address = new ModelNode();
                        address.add("server-group", "*");
                        return address;
                    }
                }, form
        );

        layout.add(helpPanel.asWidget());

        layout.add(formWidget);

        return new WindowContentBuilder(layout, options).build();
    }
}

@@ -483,24 +483,85 @@
 mHelpPanel;%0A
+import org.jboss.as.console.client.shared.subsys.Baseadress;%0A
 import org.j
@@ -2956,21 +2956,22 @@
 s = 
-new ModelNode
+Baseadress.get
 ();%0A
@@ -3012,19 +3012,77 @@
 d(%22s
-erver-group
+ubsystem%22, %22mail%22);%0A                        address.add(%22mail-session
 %22, %22

fix mail session wizard help