Search in sources :

Example 1 with FileUploadField

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

the class UploadDownloadPanel method initLayout.

private void initLayout(final boolean isReadOnly) {
    final FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE);
    Form form = this.findParent(Form.class);
    fileUpload.add(new AjaxFormSubmitBehavior(form, "change") {

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            super.onSubmit(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            super.onError(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }
    });
    fileUpload.setOutputMarkupId(true);
    add(fileUpload);
    final AjaxDownloadBehaviorFromStream downloadBehavior = new AjaxDownloadBehaviorFromStream() {

        @Override
        protected InputStream initStream() {
            return getStream();
        }
    };
    add(downloadBehavior);
    add(new AjaxSubmitButton(ID_BUTTON_DOWNLOAD) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            downloadPerformed(downloadBehavior, target);
        }
    });
    add(new AjaxSubmitButton(ID_BUTTON_DELETE) {

        @Override
        protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            removeFilePerformed(target);
        }
    });
    add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) Form(org.apache.wicket.markup.html.form.Form) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 2 with FileUploadField

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

the class FormTester method setFile.

/**
 * Sets the <code>File</code> on a {@link FileUploadField}.
 *
 * @param formComponentId
 *            relative path (from <code>Form</code>) to the selectable
 *            <code>FormComponent</code>. The <code>FormComponent</code> must be of a type
 *            <code>FileUploadField</code>.
 * @param file
 *            the <code>File</code> to upload or {@code null} for an empty input
 * @param contentType
 *            the content type of the file. Must be a valid mime type.
 * @return This
 */
public FormTester setFile(final String formComponentId, final File file, final String contentType) {
    checkClosed();
    FormComponent<?> formComponent = (FormComponent<?>) workingForm.get(formComponentId);
    MockHttpServletRequest servletRequest = tester.getRequest();
    if (formComponent instanceof FileUploadField) {
        servletRequest.addFile(formComponent.getInputName(), file, contentType);
    } else if (formComponent instanceof MultiFileUploadField) {
        String inputName = formComponent.getInputName() + MultiFileUploadField.MAGIC_SEPARATOR + multiFileUploadIndex++;
        servletRequest.addFile(inputName, file, contentType);
    } else {
        fail("'" + formComponentId + "' is not " + "a FileUploadField. You can only attach a file to form " + "component of this type.");
    }
    return this;
}
Also used : FormComponent(org.apache.wicket.markup.html.form.FormComponent) MultiFileUploadField(org.apache.wicket.markup.html.form.upload.MultiFileUploadField) MockHttpServletRequest(org.apache.wicket.protocol.http.mock.MockHttpServletRequest) MultiFileUploadField(org.apache.wicket.markup.html.form.upload.MultiFileUploadField) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField)

Example 3 with FileUploadField

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

the class UploadDownloadPanel method initLayout.

private void initLayout() {
    final FileUploadField fileUpload = new FileUploadField(ID_INPUT_FILE) {

        private static final long serialVersionUID = 1L;

        @Override
        public String[] getInputAsArray() {
            List<String> input = new ArrayList<>();
            try {
                input.add(new String(IOUtils.toByteArray(getStream())));
            } catch (IOException e) {
                LOGGER.error("Unable to define file content type: {}", e.getLocalizedMessage());
            }
            return input.toArray(new String[0]);
        }
    };
    Form form = this.findParent(Form.class);
    fileUpload.add(new AjaxFormSubmitBehavior(form, "change") {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            super.onSubmit(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }

        @Override
        protected void onError(AjaxRequestTarget target) {
            super.onError(target);
            UploadDownloadPanel.this.uploadFilePerformed(target);
        }
    });
    fileUpload.add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
    fileUpload.setOutputMarkupId(true);
    add(fileUpload);
    final AjaxDownloadBehaviorFromStream downloadBehavior = new AjaxDownloadBehaviorFromStream() {

        private static final long serialVersionUID = 1L;

        @Override
        protected InputStream initStream() {
            InputStream is = getStream();
            try {
                String newContentType = URLConnection.guessContentTypeFromStream(is);
                if (StringUtils.isNotEmpty(newContentType)) {
                    setContentType(newContentType);
                }
            } catch (IOException ex) {
                LOGGER.error("Unable to define download file content type: {}", ex.getLocalizedMessage());
            }
            return is;
        }
    };
    downloadBehavior.setContentType(getDownloadContentType());
    downloadBehavior.setFileName(getDownloadFileName());
    add(downloadBehavior);
    add(new AjaxSubmitButton(ID_BUTTON_DOWNLOAD) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            downloadPerformed(downloadBehavior, target);
        }
    });
    AjaxSubmitButton deleteButton = new AjaxSubmitButton(ID_BUTTON_DELETE) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onSubmit(AjaxRequestTarget target) {
            removeFilePerformed(target);
        }
    };
    deleteButton.add(new VisibleBehaviour(() -> !isReadOnly));
    add(deleteButton);
    add(new VisibleEnableBehaviour() {

        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isReadOnly;
        }
    });
}
Also used : AjaxSubmitButton(com.evolveum.midpoint.web.component.AjaxSubmitButton) Form(org.apache.wicket.markup.html.form.Form) AjaxDownloadBehaviorFromStream(com.evolveum.midpoint.web.component.AjaxDownloadBehaviorFromStream) VisibleBehaviour(com.evolveum.midpoint.web.component.util.VisibleBehaviour) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)

Example 4 with FileUploadField

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

the class PageImportObject method initLayout.

private void initLayout() {
    Form<?> mainForm = new MidpointForm<>(ID_MAIN_FORM);
    mainForm.setMultiPart(true);
    add(mainForm);
    ImportOptionsPanel importOptions = new ImportOptionsPanel(ID_IMPORT_OPTIONS, optionsModel, fullProcessingModel);
    mainForm.add(importOptions);
    final WebMarkupContainer input = new WebMarkupContainer(ID_INPUT);
    input.setOutputMarkupId(true);
    mainForm.add(input);
    WebMarkupContainer buttonBar = new WebMarkupContainer(ID_BUTTON_BAR);
    buttonBar.setOutputMarkupId(true);
    mainForm.add(buttonBar);
    final IModel<Integer> groupModel = new Model<>(INPUT_FILE);
    RadioGroup<Integer> 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<Integer> fileRadio = new Radio<>(ID_FILE_RADIO, new Model<>(INPUT_FILE), importRadioGroup);
    importRadioGroup.add(fileRadio);
    Radio<Integer> 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);
    dataLanguage = determineDataLanguage();
    DataLanguagePanel<List> languagePanel = new DataLanguagePanel<List>(ID_LANGUAGE_PANEL, dataLanguage, List.class, this) {

        @Override
        protected void onLanguageSwitched(AjaxRequestTarget target, int index, String updatedLanguage, String objectString) {
            dataLanguage = updatedLanguage;
            xmlEditorModel.setObject(objectString);
            addOrReplaceEditor(inputAce);
            target.add(mainForm);
        }

        @Override
        protected String getObjectStringRepresentation() {
            return xmlEditorModel.getObject();
        }
    };
    inputAce.add(languagePanel);
    addOrReplaceEditor(inputAce);
    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 : RadioGroup(org.apache.wicket.markup.html.form.RadioGroup) MidpointForm(com.evolveum.midpoint.web.component.form.MidpointForm) Radio(org.apache.wicket.markup.html.form.Radio) DataLanguagePanel(com.evolveum.midpoint.web.component.input.DataLanguagePanel) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) FileUploadField(org.apache.wicket.markup.html.form.upload.FileUploadField) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ImportOptionsPanel(com.evolveum.midpoint.web.page.admin.configuration.component.ImportOptionsPanel) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) List(java.util.List) AjaxFormChoiceComponentUpdatingBehavior(org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior)

Example 5 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)7 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 AjaxSubmitButton (com.evolveum.midpoint.web.component.AjaxSubmitButton)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 InputStream (java.io.InputStream)2 AjaxFormChoiceComponentUpdatingBehavior (org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior)2 AjaxFormSubmitBehavior (org.apache.wicket.ajax.form.AjaxFormSubmitBehavior)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 Radio (org.apache.wicket.markup.html.form.Radio)2 RadioGroup (org.apache.wicket.markup.html.form.RadioGroup)2 IModel (org.apache.wicket.model.IModel)2 Model (org.apache.wicket.model.Model)2 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 AceEditor (com.evolveum.midpoint.web.component.AceEditor)1 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)1 DataLanguagePanel (com.evolveum.midpoint.web.component.input.DataLanguagePanel)1