package org.orienteer.core.component.command.modal;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
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.upload.FileUpload;
import org.apache.wicket.markup.html.form.upload.FileUploadField;
import org.apache.wicket.markup.html.panel.Panel;
import ru.ydn.wicket.wicketorientdb.model.SimpleNamingModel;

/**
 * For uploading file from modal window
 *
 */

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

	public AbstractUploadFilePanel(String id, final ModalWindow modal) {
		super(id);
		modal.setMinimalHeight(300);
		Form<?> uploadForm = new Form<Object>("uploadForm");
		final FileUploadField inputFile = new FileUploadField("inputFile");
		uploadForm.add(inputFile);
		uploadForm.add(new AjaxButton("loadFile",getLoadButtonTitle(),uploadForm)
		{
			private static final long serialVersionUID = 1L;

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				FileUpload file = inputFile.getFileUpload();
				onLoadFile(file);
//				error(getLocalizer().getString("errors.load.file.error", this));
				modal.close(target);
				onModalClose(target);
			}
			
		});
		add(uploadForm);		
	}
	public abstract SimpleNamingModel<String> getLoadButtonTitle();
	public abstract void onLoadFile(FileUpload file);
	
	public void onModalClose(AjaxRequestTarget target){
		//may be empty
	};
}

@@ -1209,16 +1209,38 @@
 load();%0A
+%09%09%09%09if (file!=null)%7B%0A%09
 %09%09%09%09onLo
@@ -1253,16 +1253,17 @@
 (file);%0A
+%09
 //%09%09%09%09er
@@ -1325,16 +1325,17 @@
 this));%0A
+%09
 %09%09%09%09moda
@@ -1355,16 +1355,17 @@
 t);%0A%09%09%09%09
+%09
 onModalC
@@ -1378,16 +1378,22 @@
 arget);%0A
+%09%09%09%09%7D%0A
 %09%09%09%7D%0A%09%09%09

Fix case if user not select file and click "submit"