use of org.apache.wicket.markup.html.form.upload.FileUploadField in project midpoint by Evolveum.
the class PageNewReport method importReportFromFilePerformed.
private void importReportFromFilePerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(OPERATION_IMPORT_REPORT);
FileUploadField file = (FileUploadField) get(createComponentPath(ID_MAIN_FORM, ID_INPUT, ID_INPUT_FILE, ID_FILE_INPUT));
final FileUpload uploadedFile = file.getFileUpload();
if (uploadedFile == null) {
error(getString("PageNewReport.message.nullFile"));
target.add(getFeedbackPanel());
return;
}
InputStream stream = null;
File newFile = null;
try {
// Create new file
MidPointApplication application = getMidpointApplication();
WebApplicationConfiguration config = application.getWebApplicationConfiguration();
File folder = new File(config.getImportFolder());
if (!folder.exists() || !folder.isDirectory()) {
folder.mkdir();
}
newFile = new File(folder, uploadedFile.getClientFileName());
// Check new file, delete if it already exists
if (newFile.exists()) {
newFile.delete();
}
// Save file
// Task task = createSimpleTask(OPERATION_IMPORT_FILE);
newFile.createNewFile();
uploadedFile.writeTo(newFile);
InputStreamReader reader = new InputStreamReader(new FileInputStream(newFile), "utf-8");
// reader.
stream = new ReaderInputStream(reader, reader.getEncoding());
byte[] reportIn = IOUtils.toByteArray(stream);
setResponsePage(new PageReport(new ReportDto(Base64.encodeBase64(reportIn))));
} catch (Exception ex) {
result.recordFatalError("Couldn't import file.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file", ex);
} finally {
if (stream != null) {
IOUtils.closeQuietly(stream);
}
if (newFile != null) {
FileUtils.deleteQuietly(newFile);
}
}
showResult(result);
target.add(getFeedbackPanel());
}
use of org.apache.wicket.markup.html.form.upload.FileUploadField in project midpoint by Evolveum.
the class ImportReportPopupPanel method initLayout.
protected void initLayout() {
Form<?> mainForm = new MidpointForm<>(ID_MAIN_FORM);
add(mainForm);
FeedbackAlerts feedback = new FeedbackAlerts(ID_POPUP_FEEDBACK);
feedback.setOutputMarkupId(true);
mainForm.add(feedback);
Model<String> nameModel = Model.of("");
TextPanel nameField = new TextPanel(ID_NAME_FOR_DATA, nameModel);
nameField.setOutputMarkupId(true);
mainForm.add(nameField);
Model<String> fileStringModel = Model.of("");
TextAreaPanel fileStringField = new TextAreaPanel(ID_FILE_AS_NAME, fileStringModel, 5);
fileStringField.setOutputMarkupId(true);
mainForm.add(fileStringField);
AjaxSubmitButton importButton = new AjaxSubmitButton(ID_IMPORT_BUTTON, createStringResource("PageReports.button.import")) {
@Override
protected void onSubmit(AjaxRequestTarget target) {
importConfirmPerformed(target, nameModel, fileStringModel);
}
@Override
protected void onError(AjaxRequestTarget target) {
FeedbackAlerts feedback = (FeedbackAlerts) getForm().get(ID_POPUP_FEEDBACK);
target.add(feedback);
}
};
mainForm.add(importButton);
AjaxButton cancelButton = new AjaxButton(ID_CANCEL_BUTTON, createStringResource("userBrowserDialog.button.cancelButton")) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
ImportReportPopupPanel.this.getPageBase().hideMainPopup(target);
}
};
cancelButton.setOutputMarkupId(true);
mainForm.add(cancelButton);
FileUploadField choseFile = new FileUploadField(ID_CHOSE_FILE);
mainForm.add(choseFile);
}
use of org.apache.wicket.markup.html.form.upload.FileUploadField in project projectforge by micromata.
the class ReportObjectivesForm method init.
@SuppressWarnings("serial")
@Override
protected void init() {
super.init();
add(new IFormValidator() {
@Override
public FormComponent<?>[] getDependentFormComponents() {
return dependentFormComponents;
}
@Override
public void validate(final Form<?> form) {
final Date fromDate = fromDatePanel.getConvertedInput();
final Date toDate = toDatePanel.getConvertedInput();
if (toDate != null && fromDate != null && fromDate.after(toDate)) {
toDatePanel.getDateField().error(getString("fibu.buchungssatz.error.invalidTimeperiod"));
}
}
});
filter = getFilter();
gridBuilder.newGridPanel();
{
final FieldsetPanel fs = new FieldsetPanel(gridBuilder.getPanel(), getString("file"), "*.xml") {
@Override
public boolean isVisible() {
return parentPage.getReportStorage() == null;
}
};
fileUploadField = new FileUploadField(FileUploadPanel.WICKET_ID);
fs.add(new FileUploadPanel(fs.newChildId(), fileUploadField));
fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID, new Model<>("import")) {
@Override
public final void onSubmit() {
parentPage.importReportObjectivs();
}
}, getString("import"), SingleButtonPanel.NORMAL));
}
{
final FieldsetPanel fs = new FieldsetPanel(gridBuilder.getPanel(), getString("timePeriod")) {
@Override
public boolean isVisible() {
return reportObjectivesPanel.isVisible();
}
};
fs.add(fromDatePanel = new DatePanel(fs.newChildId(), new PropertyModel<>(filter, "fromDate"), DatePanelSettings.get().withRequired(true)));
dependentFormComponents[0] = fromDatePanel;
fs.add(new DivTextPanel(fs.newChildId(), " - "));
fs.add(toDatePanel = new DatePanel(fs.newChildId(), new PropertyModel<>(filter, "toDate"), DatePanelSettings.get()));
dependentFormComponents[1] = toDatePanel;
final Button createReportButton = new Button(SingleButtonPanel.WICKET_ID, new Model<>("createReport")) {
@Override
public final void onSubmit() {
parentPage.createReport();
}
};
setDefaultButton(createReportButton);
fs.add(new SingleButtonPanel(fs.newChildId(), createReportButton, getString("fibu.kost.reporting.createReport"), SingleButtonPanel.DEFAULT_SUBMIT));
fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID, new Model<>("clear")) {
@Override
public final void onSubmit() {
parentPage.clear();
}
}, getString("fibu.kost.reporting.clearStorage"), SingleButtonPanel.RESET));
}
final DivPanel panel = gridBuilder.getPanel();
panel.add(reportObjectivesPanel = new ReportObjectivesPanel(panel.newChildId(), parentPage));
}
use of org.apache.wicket.markup.html.form.upload.FileUploadField in project projectforge by micromata.
the class EmployeeSalaryImportForm method init.
@SuppressWarnings("serial")
@Override
protected void init() {
super.init();
gridBuilder.newGridPanel();
// Date DropDowns
final FieldsetPanel fsMonthYear = gridBuilder.newFieldset(I18nHelper.getLocalizedMessage("plugins.eed.listcare.yearmonth"));
dropDownMonth = new DropDownChoicePanel<>(fsMonthYear.newChildId(), new DropDownChoice<>(DropDownChoicePanel.WICKET_ID, new PropertyModel<>(this, "selectedMonth"), EEDHelper.MONTH_INTEGERS));
dropDownMonth.setRequired(true);
fsMonthYear.add(dropDownMonth);
dropDownYear = new DropDownChoicePanel<>(fsMonthYear.newChildId(), new DropDownChoice<>(DropDownChoicePanel.WICKET_ID, new PropertyModel<>(this, "selectedYear"), eedHelper.getDropDownYears()));
dropDownYear.setRequired(true);
fsMonthYear.add(dropDownYear);
// upload buttons
{
final FieldsetPanel fs = gridBuilder.newFieldset(getString("file"), "*.xls");
fileUploadField = new FileUploadField(FileUploadPanel.WICKET_ID);
fs.add(new FileUploadPanel(fs.newChildId(), fileUploadField));
fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID) {
@Override
public final void onSubmit() {
final Date dateToSelectAttrRow = new GregorianCalendar(selectedYear, selectedMonth - 1, 1, 0, 0).getTime();
storagePanel.setDateToSelectAttrRow(dateToSelectAttrRow);
final boolean success = parentPage.doImport(dateToSelectAttrRow);
if (success) {
setDateDropDownsEnabled(false);
}
}
}, getString("upload"), SingleButtonPanel.NORMAL).setTooltip(getString("common.import.upload.tooltip")));
addClearButton(fs);
}
addImportFilterRadio(gridBuilder);
// preview of the imported data
gridBuilder.newGridPanel();
final DivPanel panel = gridBuilder.getPanel();
storagePanel = new EmployeeSalaryImportStoragePanel(panel.newChildId(), parentPage, importFilter);
final Date dateToSelectAttrRow = new GregorianCalendar(selectedYear, (selectedMonth != null ? selectedMonth : PFDateTime.now().getMonthValue()) - 1, 1, 0, 0).getTime();
storagePanel.setDateToSelectAttrRow(dateToSelectAttrRow);
panel.add(storagePanel);
}
use of org.apache.wicket.markup.html.form.upload.FileUploadField in project projectforge by micromata.
the class TeamCalImportForm method init.
@SuppressWarnings("serial")
@Override
protected void init() {
super.init();
// createModalDialog(parentPage);
gridBuilder.newGridPanel();
{
final FieldsetPanel fs = gridBuilder.newFieldset(getString("plugins.teamcal.event.teamCal"));
final List<TeamCalDO> list = teamCalDao.getAllCalendarsWithFullAccess();
final LabelValueChoiceRenderer<TeamCalDO> calChoiceRenderer = new LabelValueChoiceRenderer<TeamCalDO>();
for (final TeamCalDO cal : list) {
calChoiceRenderer.addValue(cal, cal.getTitle());
}
final DropDownChoice<TeamCalDO> calDropDownChoice = new DropDownChoice<TeamCalDO>(fs.getDropDownChoiceId(), new PropertyModel<TeamCalDO>(this, "calendar"), calChoiceRenderer.getValues(), calChoiceRenderer) {
/**
* @see org.apache.wicket.markup.html.form.DropDownChoice#wantOnSelectionChangedNotifications()
*/
@Override
protected boolean wantOnSelectionChangedNotifications() {
return true;
}
/**
* @see org.apache.wicket.markup.html.form.DropDownChoice#onSelectionChanged(java.lang.Object)
*/
@Override
protected void onSelectionChanged(final TeamCalDO newSelection) {
parentPage.reconcile();
}
};
calDropDownChoice.setNullValid(false);
calDropDownChoice.setRequired(true);
// calDropDownChoice.add(new AjaxEventBehavior("change")
// {
// @Override
// protected void onEvent(AjaxRequestTarget target)
// {
// modalDialog.open(target);
// }
// });
fs.add(calDropDownChoice);
}
{
final FieldsetPanel fs = gridBuilder.newFieldset(getString("file"), "*.ics");
fileUploadField = new FileUploadField(FileUploadPanel.WICKET_ID);
fs.add(new FileUploadPanel(fs.newChildId(), fileUploadField));
fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID, new Model<String>("importEvents")) {
@Override
public final void onSubmit() {
parentPage.importEvents();
}
}, getString("upload"), SingleButtonPanel.NORMAL).setTooltip(getString("common.import.upload.tooltip")));
addClearButton(fs);
}
{
addImportFilterRadio(gridBuilder);
}
gridBuilder.newGridPanel();
final DivPanel panel = gridBuilder.getPanel();
storagePanel = new TeamCalImportStoragePanel(panel.newChildId(), parentPage, importFilter);
panel.add(storagePanel);
}
Aggregations