Search in sources :

Example 11 with FileUploadField

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());
}
Also used : InputStreamReader(java.io.InputStreamReader) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ReportDto(com.evolveum.midpoint.web.page.admin.reports.dto.ReportDto) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) FileInputStream(java.io.FileInputStream) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) ReaderInputStream(org.apache.commons.io.input.ReaderInputStream) WebApplicationConfiguration(com.evolveum.midpoint.web.security.WebApplicationConfiguration) File(org.apache.wicket.util.file.File) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 12 with FileUploadField

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);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) AjaxButton(com.evolveum.midpoint.web.component.AjaxButton) FeedbackAlerts(com.evolveum.midpoint.web.component.message.FeedbackAlerts) TextPanel(com.evolveum.midpoint.web.component.input.TextPanel) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) TextAreaPanel(com.evolveum.midpoint.web.component.input.TextAreaPanel) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 13 with FileUploadField

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));
}
Also used : IFormValidator(org.apache.wicket.markup.html.form.validation.IFormValidator) PropertyModel(org.apache.wicket.model.PropertyModel) Date(java.util.Date) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) DivTextPanel(org.projectforge.web.wicket.flowlayout.DivTextPanel) Button(org.apache.wicket.markup.html.form.Button) DatePanel(org.projectforge.web.wicket.components.DatePanel) Model(org.apache.wicket.model.Model) PropertyModel(org.apache.wicket.model.PropertyModel) FieldsetPanel(org.projectforge.web.wicket.flowlayout.FieldsetPanel) FileUploadPanel(org.projectforge.web.wicket.flowlayout.FileUploadPanel) DivPanel(org.projectforge.web.wicket.flowlayout.DivPanel) SingleButtonPanel(org.projectforge.web.wicket.components.SingleButtonPanel)

Example 14 with FileUploadField

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);
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) Button(org.apache.wicket.markup.html.form.Button) FieldsetPanel(org.projectforge.web.wicket.flowlayout.FieldsetPanel) FileUploadPanel(org.projectforge.web.wicket.flowlayout.FileUploadPanel) DivPanel(org.projectforge.web.wicket.flowlayout.DivPanel) SingleButtonPanel(org.projectforge.web.wicket.components.SingleButtonPanel)

Example 15 with FileUploadField

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);
}
Also used : PropertyModel(org.apache.wicket.model.PropertyModel) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) DropDownChoice(org.apache.wicket.markup.html.form.DropDownChoice) Button(org.apache.wicket.markup.html.form.Button) LabelValueChoiceRenderer(org.projectforge.web.wicket.components.LabelValueChoiceRenderer) TeamCalDO(org.projectforge.business.teamcal.admin.model.TeamCalDO) FieldsetPanel(org.projectforge.web.wicket.flowlayout.FieldsetPanel) List(java.util.List) FileUploadPanel(org.projectforge.web.wicket.flowlayout.FileUploadPanel) DivPanel(org.projectforge.web.wicket.flowlayout.DivPanel) SingleButtonPanel(org.projectforge.web.wicket.components.SingleButtonPanel)

Aggregations

FileUploadField (org.apache.wicket.markup.html.form.upload.FileUploadField)16 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)8 FieldsetPanel (org.projectforge.web.wicket.flowlayout.FieldsetPanel)7 FileUploadPanel (org.projectforge.web.wicket.flowlayout.FileUploadPanel)7 Button (org.apache.wicket.markup.html.form.Button)6 SingleButtonPanel (org.projectforge.web.wicket.components.SingleButtonPanel)6 Model (org.apache.wicket.model.Model)5 DivPanel (org.projectforge.web.wicket.flowlayout.DivPanel)5 List (java.util.List)4 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)3 InputStream (java.io.InputStream)3 Date (java.util.Date)3 AjaxFormSubmitBehavior (org.apache.wicket.ajax.form.AjaxFormSubmitBehavior)3 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)3 Form (org.apache.wicket.markup.html.form.Form)3 AjaxDownloadBehaviorFromStream (com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream)2 MidpointForm (com.evolveum.midpoint.web.component.form.MidpointForm)2 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2