/**
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.bricket.plugin.picture.web;
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.model.Model;
import org.apache.wicket.util.lang.Bytes;
import org.bricket.web.BricketPanel;
/**
* @author Ingo Renner
* @author Henning Teek
*
*/
public abstract class UploadPanel extends BricketPanel {
private int maxMbSize;
public UploadPanel(String id) {
this(id, 10);
}
public UploadPanel(String id, int maxMbSize) {
super(id);
this.maxMbSize = maxMbSize;
}
@Override
protected void initGui() {
final FileUploadField uploadField = new FileUploadField("file", new Model<FileUpload>());
@SuppressWarnings("rawtypes")
Form form = new Form("uploadForm") {
@Override
protected void onSubmit() {
FileUpload upload = uploadField.getFileUpload();
String filename = upload.getClientFileName();
handleUpload(upload, filename);
}
};
uploadField.setRequired(true);
form.add(uploadField);
// Wegen Bug in wicket 1.4.14 deaktiviert
// form.add(new UploadProgressBar("progress", form));
// html Zeile 15 <div wicket:id="progress"></div>
// Max size of uploaded file.
form.setMaxSize(Bytes.megabytes(maxMbSize));
add(form);
}
protected abstract void handleUpload(FileUpload upload, String filename);
}