package com.im.lac.portal.webapp;

import com.im.lac.wicket.semantic.SemanticModalPanel;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.markup.html.form.Form;

import java.io.IOException;
import java.io.InputStream;

public class UploadFilePanel extends SemanticModalPanel {

    public UploadFilePanel(String id, String modalElementWicketId) {
        super(id, modalElementWicketId);
        addForm();
    }

    private void addForm() {
        Form form = new Form("form");
        form.setOutputMarkupId(true);
        getModalRootComponent().add(form);

        final AjaxSubmitLink submit = new AjaxSubmitLink("save") {

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            }
        };
        submit.setOutputMarkupId(true);
        form.add(submit);

        AjaxLink cancelAction = new AjaxLink("cancel") {

            @Override
            public void onClick(AjaxRequestTarget ajaxRequestTarget) {
                hideModal();
            }
        };
        form.add(cancelAction);

        FileUploadPanel fileUploadPanel = new FileUploadPanel("upload", true);
        fileUploadPanel.setCallbackHandler(new FileUploadPanel.CallbackHandler() {

            @Override
            public void onUpload(String clientFileName, InputStream inputStream, AjaxRequestTarget target) throws IOException {
                // create dataset here
            }

            @Override
            public String beforeSubmit() {
                return "document.getElementById('" + submit.getMarkupId() + "').disabled = true;";
            }

            @Override
            public String afterSubmit() {
                return "document.getElementById('" + submit.getMarkupId() + "').disabled = false;";
            }
        });
        form.add(fileUploadPanel);
    }

}

@@ -28,16 +28,130 @@
 ebapp;%0A%0A
+import com.im.lac.portal.service.DatasetInputStreamFormat;%0Aimport com.im.lac.portal.service.PrototypeServiceMock;%0A
 import c
@@ -409,16 +409,44 @@
 .Form;%0A%0A
+import javax.inject.Inject;%0A
 import j
@@ -492,16 +492,64 @@
 tStream;
+%0Aimport java.util.HashMap;%0Aimport java.util.Map;
 %0A%0Apublic
@@ -597,24 +597,92 @@
 dalPanel %7B%0A%0A
+    @Inject%0A    private PrototypeServiceMock prototypeServiceMock;%0A%0A
     public U
@@ -1785,30 +1785,230 @@
     
-// create dataset here
+Map%3CString, Class%3E properties = new HashMap%3CString, Class%3E();%0A                properties.put(%22set%22, Integer.class);%0A                prototypeServiceMock.createDataset(DatasetInputStreamFormat.SDF, inputStream, properties);
 %0A   

Call to create data set.