package ch.difty.scipamato.web.panel.pastemodal;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.StringResourceModel;

import de.agilecoders.wicket.core.markup.html.bootstrap.button.BootstrapAjaxButton;
import de.agilecoders.wicket.core.markup.html.bootstrap.button.Buttons;

public class XmlPasteModalPanel extends Panel {
    private static final long serialVersionUID = 1L;

    private String pastedContent;

    public XmlPasteModalPanel(String id) {
        super(id);
    }

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

        Form<Void> form = new Form<>("form");
        queue(form);
        queue(new TextArea<>("content", new PropertyModel<String>(this, "pastedContent")));

        queue(new BootstrapAjaxButton("submit", new StringResourceModel("submit.label", this, null), form, Buttons.Type.Primary) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onAfterSubmit(AjaxRequestTarget target, Form<?> form) {
                super.onAfterSubmit(target, form);
                ModalWindow.closeCurrent(target);
            }
        });
    }

    public String getPastedContent() {
        return pastedContent;
    }

}
@@ -707,16 +707,46 @@
 ntent;%0A%0A
+    private Form%3CVoid%3E form;%0A%0A
     publ
@@ -895,26 +895,179 @@
         
-Form%3CVoid%3E
+queue(newForm(%22form%22));%0A        queue(newTextArea(%22pastedContent%22));%0A        queue(newButton(%22submit%22));%0A    %7D%0A%0A    private Form%3CVoid%3E newForm(String id) %7B%0A       
  form = 
@@ -1077,22 +1077,18 @@
  Form%3C%3E(
-%22form%22
+id
 );%0A     
@@ -1094,113 +1094,222 @@
     
-queue(
+return 
 form
-)
 ;%0A    
+%7D%0A%0A
     
-queue(new TextArea%3C%3E(%22content%22, new PropertyModel%3CString%3E(this, %22pastedContent%22)));%0A
+private TextArea%3CString%3E newTextArea(String id) %7B%0A        return new TextArea%3C%3E(%22content%22, new PropertyModel%3CString%3E(this, id));%0A    %7D%0A%0A    private BootstrapAjaxButton newButton(String id) %7B
 %0A   
@@ -1313,22 +1313,23 @@
         
-queue(
+return 
 new Boot
@@ -1344,24 +1344,18 @@
 xButton(
-%22submit%22
+id
 , new St
@@ -1372,23 +1372,22 @@
 ceModel(
-%22submit
+id + %22
 .label%22,
@@ -1721,17 +1721,16 @@
        %7D
-)
 ;%0A    %7D%0A

Refactor XmlPasteModalPanel