Search in sources :

Example 6 with FileUploadField

use of org.apache.wicket.markup.html.form.upload.FileUploadField in project projectforge by micromata.

the class EmployeeBillingImportForm 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));
    fsMonthYear.add(dropDownMonth);
    dropDownYear = new DropDownChoicePanel<>(fsMonthYear.newChildId(), new DropDownChoice<>(DropDownChoicePanel.WICKET_ID, new PropertyModel<>(this, "selectedYear"), eedHelper.getDropDownYears()));
    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 EmployeeBillingImportStoragePanel(panel.newChildId(), parentPage, importFilter);
    final Date dateToSelectAttrRow = new GregorianCalendar(selectedYear, selectedMonth - 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 7 with FileUploadField

use of org.apache.wicket.markup.html.form.upload.FileUploadField in project projectforge by micromata.

the class AddressImportForm method onInitialize.

/**
 * @see org.apache.wicket.Component#onInitialize()
 */
@Override
protected void onInitialize() {
    super.onInitialize();
    gridBuilder.newSplitPanel(GridSize.COL50);
    final FieldsetPanel newFieldset = gridBuilder.newFieldset(getString("address.book.vCardImport.fileUploadPanel"));
    final FileUploadField uploadField = new FileUploadField(FileUploadPanel.WICKET_ID, new PropertyModel<List<FileUpload>>(this, "uploads"));
    newFieldset.add(new FileUploadPanel(newFieldset.newChildId(), uploadField));
}
Also used : FieldsetPanel(org.projectforge.web.wicket.flowlayout.FieldsetPanel) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) FileUploadPanel(org.projectforge.web.wicket.flowlayout.FileUploadPanel) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 8 with FileUploadField

use of org.apache.wicket.markup.html.form.upload.FileUploadField in project projectforge by micromata.

the class DatevImportForm method init.

@SuppressWarnings("serial")
@Override
protected void init() {
    super.init();
    this.setOutputMarkupId(true);
    Bytes maxSize = Bytes.valueOf(configurationService.getMaxFileSizeDatev());
    this.setMaxSize(maxSize);
    gridBuilder.newGridPanel();
    String hint = I18nHelper.getLocalizedMessage("finance.datev.upload.hint", NumberHelper.formatBytes(maxSize.bytes()));
    final FieldsetPanel fs = gridBuilder.newFieldset(getString("file"), hint);
    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>("uploadAccounts")) {

        @Override
        public final void onSubmit() {
            parentPage.importAccountList();
        }
    }, getString("finance.datev.uploadAccountList"), SingleButtonPanel.NORMAL).setTooltip(getString("common.import.upload.tooltip")));
    fs.add(new SingleButtonPanel(fs.newChildId(), new Button(SingleButtonPanel.WICKET_ID, new Model<String>("uploadRecords")) {

        @Override
        public final void onSubmit() {
            parentPage.importAccountRecords();
        }
    }, getString("finance.datev.uploadAccountingRecords"), SingleButtonPanel.NORMAL).setTooltip(getString("common.import.upload.tooltip")));
    addClearButton(fs);
    addImportFilterRadio(gridBuilder);
    // Statistics
    new BusinessAssessment4Fieldset(gridBuilder) {

        /**
         * @see org.projectforge.web.fibu.BusinessAssessment4Fieldset#getBusinessAssessment()
         */
        @Override
        protected BusinessAssessment getBusinessAssessment() {
            return storagePanel.businessAssessment;
        }

        @Override
        public boolean isVisible() {
            return storagePanel.businessAssessment != null;
        }
    };
    gridBuilder.newGridPanel();
    final DivPanel panel = gridBuilder.getPanel();
    storagePanel = new DatevImportStoragePanel(panel.newChildId(), parentPage, importFilter);
    panel.add(storagePanel);
    this.fileUploadField.add(new FileFieldSizeCheckBehavior() {

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final FileList fileList) {
            // return form to remove errors
            target.add(DatevImportForm.this.feedbackPanel);
        }

        @Override
        protected void addErrorMsg(AjaxRequestTarget target, FileList fileList) {
            DatevImportForm.this.addError("common.uploadpanel.filetolarge", NumberHelper.formatBytes(maxSize.bytes()));
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final FileList fileList) {
            // clear input field to avoid uploading the image
            DatevImportForm.this.fileUploadField.clearInput();
            // return form
            target.add(DatevImportForm.this);
        }
    });
}
Also used : FileList(org.wicketstuff.html5.fileapi.FileList) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) Bytes(org.apache.wicket.util.lang.Bytes) Button(org.apache.wicket.markup.html.form.Button) FileFieldSizeCheckBehavior(org.wicketstuff.html5.fileapi.FileFieldSizeCheckBehavior) Model(org.apache.wicket.model.Model) 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 9 with FileUploadField

use of org.apache.wicket.markup.html.form.upload.FileUploadField in project invesdwin-nowicket by invesdwin.

the class Components method updateValidModelsOnValidationError.

/**
 * Synchronize valid model values so that validator utilities have something to work with. This is useful in onError
 * calls in submit behaviors
 */
public static boolean updateValidModelsOnValidationError(final Component component) {
    final Component root = Components.findRoot(component);
    final Form<?> form = Components.findForm(root);
    final AtomicBoolean invalidFound = new AtomicBoolean(false);
    FormComponent.visitFormComponentsPostOrder(form, new IVisitor<FormComponent<?>, Void>() {

        @Override
        public void component(final FormComponent<?> object, final IVisit<Void> visit) {
            if (object.isEnabledInHierarchy() && object.isVisibleInHierarchy() && // fileUploadField chokes on FileNotFound if synchronized twice in a call!
            !(object instanceof FileUploadField)) {
                try {
                    /*
                         * fill in values regardless of valid state, since complex validation rules might require all
                         * inputs
                         * 
                         * we need to call convertInput here because otherwise wicket will leave the value null at that
                         * point, which would use null in updateModel()
                         */
                    object.convertInput();
                    object.updateModel();
                } catch (final Throwable t) {
                // ignore
                }
                object.validate();
                if (!object.isValid()) {
                    invalidFound.set(true);
                }
            }
        }
    });
    return invalidFound.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FormComponent(org.apache.wicket.markup.html.form.FormComponent) FormComponent(org.apache.wicket.markup.html.form.FormComponent) Component(org.apache.wicket.Component) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 10 with FileUploadField

use of org.apache.wicket.markup.html.form.upload.FileUploadField in project midpoint by Evolveum.

the class PageNewReport method initLayout.

private void initLayout() {
    Form mainForm = new Form(ID_MAIN_FORM);
    add(mainForm);
    final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT);
    input.setOutputMarkupId(true);
    mainForm.add(input);
    final WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR);
    buttonBar.setOutputMarkupId(true);
    mainForm.add(buttonBar);
    final IModel<Integer> groupModel = new Model<Integer>(INPUT_FILE);
    RadioGroup importRadioGroup = new RadioGroup(ID_IMPORT_RADIO_GROUP, groupModel);
    importRadioGroup.add(new AjaxFormChoiceComponentUpdatingBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(input);
            target.add(buttonBar);
        }
    });
    mainForm.add(importRadioGroup);
    Radio fileRadio = new Radio(ID_FILE_RADIO, new Model(INPUT_FILE), importRadioGroup);
    importRadioGroup.add(fileRadio);
    Radio xmlRadio = new Radio(ID_XML_RADIO, new Model(INPUT_XML), importRadioGroup);
    importRadioGroup.add(xmlRadio);
    WebMarkupContainer inputAce = new WebMarkupContainer(ID_INPUT_ACE);
    addVisibileForInputType(inputAce, INPUT_XML, groupModel);
    input.add(inputAce);
    AceEditor aceEditor = new AceEditor(ID_ACE_EDITOR, xmlEditorModel);
    aceEditor.setOutputMarkupId(true);
    inputAce.add(aceEditor);
    WebMarkupContainer inputFileLabel = new WebMarkupContainer(ID_INPUT_FILE_LABEL);
    addVisibileForInputType(inputFileLabel, INPUT_FILE, groupModel);
    input.add(inputFileLabel);
    WebMarkupContainer inputFile = new WebMarkupContainer(ID_INPUT_FILE);
    addVisibileForInputType(inputFile, INPUT_FILE, groupModel);
    input.add(inputFile);
    FileUploadField fileInput = new FileUploadField(ID_FILE_INPUT);
    inputFile.add(fileInput);
    initButtons(buttonBar, groupModel);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) RadioGroup(org.apache.wicket.markup.html.form.RadioGroup) Form(org.apache.wicket.markup.html.form.Form) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) Radio(org.apache.wicket.markup.html.form.Radio) AceEditor(com.evolveum.midpoint.web.component.AceEditor) AjaxFormChoiceComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

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