Package io.jmix.ui.component.impl
Class AbstractSingleFileUploadField<R>
java.lang.Object
io.jmix.ui.component.impl.AbstractComponent<T>
io.jmix.ui.component.impl.AbstractValueComponent<T,P,V>
io.jmix.ui.component.impl.AbstractField<JmixFileUploadField,String,R>
io.jmix.ui.component.impl.AbstractSingleFileUploadField<R>
- All Implemented Interfaces:
AttachNotifier
,Buffered
,Component
,Component.BelongToFrame
,Component.Editable
,Component.Focusable
,Component.HasCaption
,Component.HasDescription
,Component.HasIcon
,Component.HasXmlDescriptor
,Component.Wrapper
,HasValueSource<R>
,Field<R>
,HasContextHelp
,HasDebugId
,HasHtmlCaption
,HasHtmlDescription
,HasHtmlSanitizer
,HasValidator<R>
,HasValue<R>
,Requirable
,SingleFileUploadField
,UploadField
,Validatable
,org.springframework.beans.factory.InitializingBean
- Direct Known Subclasses:
AbstractFileStorageUploadField
,FileUploadFieldImpl
public abstract class AbstractSingleFileUploadField<R>
extends AbstractField<JmixFileUploadField,String,R>
implements SingleFileUploadField, org.springframework.beans.factory.InitializingBean
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
Nested classes/interfaces inherited from interface io.jmix.ui.component.Component
Component.Alignment, Component.BelongToFrame, Component.Disposable, Component.Editable, Component.Focusable, Component.HasCaption, Component.HasDescription, Component.HasIcon, Component.HasXmlDescriptor, Component.Wrapper
Nested classes/interfaces inherited from interface io.jmix.ui.component.HasContextHelp
HasContextHelp.ContextHelpIconClickEvent
Nested classes/interfaces inherited from interface io.jmix.ui.component.HasValue
HasValue.ValueChangeEvent<V>
Nested classes/interfaces inherited from interface io.jmix.ui.component.SingleFileUploadField
SingleFileUploadField.AfterValueClearEvent, SingleFileUploadField.BeforeValueClearEvent, SingleFileUploadField.FileUploadSucceedEvent
Nested classes/interfaces inherited from interface io.jmix.ui.component.UploadField
UploadField.DropZone, UploadField.FileUploadErrorEvent, UploadField.FileUploadEvent, UploadField.FileUploadFinishEvent, UploadField.FileUploadStartEvent
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
protected static final int
protected UiComponentProperties
protected Supplier<InputStream>
protected Downloader
protected UploadField.DropZone
protected String
protected String
protected long
protected Messages
protected Notifications
protected ComponentContainer
Fields inherited from class io.jmix.ui.component.impl.AbstractField
editable, parentEditableChangeListener, validators, VALIDATORS_LIST_INITIAL_CAPACITY
Fields inherited from class io.jmix.ui.component.impl.AbstractValueComponent
internalValue, uiTestIdsSupport, valueBinding
Fields inherited from class io.jmix.ui.component.impl.AbstractComponent
alignment, applicationContext, component, contextHelpIconClickHandler, contextHelpIconClickListener, descriptionAsHtml, element, frame, htmlSanitizerEnabled, icon, ICON_STYLE, id, parent
Fields inherited from interface io.jmix.ui.component.Component
AUTO_SIZE, AUTO_SIZE_PX, FULL_SIZE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds a callback interface which is invoked by theSingleFileUploadField
after value has been cleared using clear button.Sets a callback interface which is invoked by theSingleFileUploadField
before value clearing when user use clear button.Adds file upload error listener.Adds file upload finish listener.Adds file upload start listener.Adds file upload succeed listener.void
protected void
clearButtonClicked
(com.vaadin.ui.Button.ClickEvent clickEvent) void
commit()
Updates all changes since the previous commit to the data source.protected JmixFileUploadField
void
discard()
Discards all changes since last commit.protected void
fireFileUploadError
(String fileName, long contentLength, Exception cause) protected void
fireFileUploadFinish
(String fileName, long contentLength) protected void
fireFileUploadStart
(String fileName, long contentLength) protected void
fireFileUploadSucceed
(String fileName, long contentLength) void
focus()
Sets focus to this componentReturns comma separated types of files.protected long
long
Returns maximum allowed file size in bytes.protected String
Returns white list of file extensions.int
Gets the tabulator index of theHasTabIndex
component.protected void
protected void
internalValueChanged
(Object newValue) boolean
boolean
Tests if the value stored in the object has been modified since it was last updated from the data source.boolean
boolean
protected void
protected abstract void
onFileNameClick
(com.vaadin.ui.Button.ClickEvent e) protected void
protected void
protected void
protected void
protected void
protected abstract OutputStream
receiveUpload
(String fileName, String MIMEType) void
Sets the mask for files to filter them in the file selection dialog.void
setBuffered
(boolean buffered) Sets the buffered mode.void
setClearButtonCaption
(String caption) Setup clear button caption.void
setClearButtonDescription
(String description) Setup clear button description.void
setClearButtonIcon
(String icon) Setup clear button icon.void
setComponentProperties
(UiComponentProperties componentProperties) void
setContentProvider
(Supplier<InputStream> contentProvider) Set content provider which contains file data.void
setDownloader
(Downloader downloader) void
setDropZone
(UploadField.DropZone dropZone) Sets drop zone reference to this upload component.void
setDropZonePrompt
(String dropZonePrompt) Sets drop zone prompt that will be shown on drag over window with file.void
setFileSizeLimit
(long fileSizeLimit) Sets maximum allowed file size in bytes.void
setMessages
(Messages messages) void
setNotifications
(Notifications notifications) void
setPasteZone
(ComponentContainer pasteZone) Sets paste zone reference to this upload component.void
setPermittedExtensions
(Set<String> permittedExtensions) Sets white list of file extensions.void
setShowClearButton
(boolean showClearButton) Enable or disable displaying name of clear button.void
setShowFileName
(boolean showFileName) Enable or disable displaying name of uploaded file next to upload button.void
setTabIndex
(int tabIndex) Sets the tabulator index of theFocusable
component.void
setUploadButtonCaption
(String caption) Setup caption of upload button.void
setUploadButtonDescription
(String description) Setup upload button description.void
setUploadButtonIcon
(String icon) Setup upload button icon.Methods inherited from class io.jmix.ui.component.impl.AbstractField
addValidator, attachValueChangeListener, getDatatypeConversionErrorMsg, getDefaultRequiredMessage, getErrorMessage, getRequiredMessage, getValidators, isEditable, isRequired, isValid, removeValidator, setEditable, setEditableToComponent, setParent, setRequired, setRequiredMessage, setupComponentErrorProvider, triggerValidators, validate
Methods inherited from class io.jmix.ui.component.impl.AbstractValueComponent
addValueChangeListener, componentValueChanged, convertToModel, convertToPresentation, fieldValueEquals, getValue, getValueSource, setUiTestId, setUiTestIdsSupport, setValue, setValueSource, setValueToPresentation, valueBindingActivated, valueBindingConnected
Methods inherited from class io.jmix.ui.component.impl.AbstractComponent
addAttachListener, addDetachListener, addStyleName, assignDebugId, attached, detached, getAlignment, getCaption, getComponent, getComposition, getContextHelpIconClickHandler, getContextHelpText, getDebugId, getDescription, getEventHub, getFrame, getHeight, getHeightSizeUnit, getHtmlSanitizer, getIcon, getIconName, getIconResource, getId, getParent, getStyleName, getUiComponentProperties, getUiProperties, getWidth, getWidthSizeUnit, getXmlDescriptor, hasSubscriptions, hasValidationError, isAttached, isCaptionAsHtml, isContextHelpTextHtmlEnabled, isDescriptionAsHtml, isEnabled, isEnabledRecursive, isHtmlSanitizerEnabled, isResponsive, isVisible, isVisibleRecursive, onContextHelpIconClick, publish, removeStyleName, sanitize, setAlignment, setApplicationContext, setCaption, setCaptionAsHtml, setContextHelpIconClickHandler, setContextHelpText, setContextHelpTextHtmlEnabled, setDebugId, setDescription, setDescriptionAsHtml, setEnabled, setFrame, setHeight, setHtmlSanitizerEnabled, setIcon, setIconFromSet, setId, setResponsive, setStyleName, setValidationError, setVisible, setWidth, setXmlDescriptor, unsubscribe, unwrap, unwrapComposition, unwrapCompositionOrNull, unwrapOrNull, withUnwrapped, withUnwrappedComposition
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.jmix.ui.component.Component
addStyleName, getAlignment, getHeight, getHeightSizeUnit, getId, getParent, getStyleName, getWidth, getWidthSizeUnit, isEnabled, isEnabledRecursive, isResponsive, isVisible, isVisibleRecursive, removeStyleName, setAlignment, setEnabled, setHeight, setHeightAuto, setHeightFull, setId, setParent, setResponsive, setSizeAuto, setSizeFull, setStyleName, setVisible, setWidth, setWidthAuto, setWidthFull, unwrap, unwrapComposition, unwrapCompositionOrNull, unwrapOrNull, withUnwrapped, withUnwrappedComposition
Methods inherited from interface io.jmix.ui.component.Component.BelongToFrame
getFrame, setFrame
Methods inherited from interface io.jmix.ui.component.Component.Editable
isEditableWithParent
Methods inherited from interface io.jmix.ui.component.Component.Focusable
isFocusable, setFocusable
Methods inherited from interface io.jmix.ui.component.Component.HasCaption
getCaption, setCaption
Methods inherited from interface io.jmix.ui.component.Component.HasDescription
getDescription, setDescription
Methods inherited from interface io.jmix.ui.component.Component.HasIcon
getIcon, setIcon, setIconFromSet
Methods inherited from interface io.jmix.ui.component.HasContextHelp
getContextHelpIconClickHandler, getContextHelpText, isContextHelpTextHtmlEnabled, setContextHelpIconClickHandler, setContextHelpText, setContextHelpTextHtmlEnabled
Methods inherited from interface io.jmix.ui.component.HasHtmlCaption
isCaptionAsHtml, setCaptionAsHtml
Methods inherited from interface io.jmix.ui.component.HasHtmlDescription
isDescriptionAsHtml, setDescriptionAsHtml
Methods inherited from interface io.jmix.ui.component.HasHtmlSanitizer
isHtmlSanitizerEnabled, setHtmlSanitizerEnabled
Methods inherited from interface io.jmix.ui.component.HasValidator
addValidators
Methods inherited from interface io.jmix.ui.component.HasValue
addValueChangeListener, clear, getEmptyValue, getValue, isEmpty, setValue
Methods inherited from interface io.jmix.ui.component.data.HasValueSource
getValueSource, setValueSource
Methods inherited from interface io.jmix.ui.component.SingleFileUploadField
getFileContent
Methods inherited from interface io.jmix.ui.component.Validatable
isValidateOnCommit
-
Field Details
-
BYTES_IN_MEGABYTE
protected static final int BYTES_IN_MEGABYTE- See Also:
-
downloader
-
messages
-
notifications
-
contentProvider
-
componentProperties
-
fileSizeLimit
protected long fileSizeLimit -
permittedExtensions
-
accept
-
fileName
-
dropZone
-
pasteZone
-
dropZonePrompt
-
-
Constructor Details
-
AbstractSingleFileUploadField
public AbstractSingleFileUploadField()
-
-
Method Details
-
createComponent
-
setDownloader
-
setMessages
-
setNotifications
-
setComponentProperties
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
initComponent
protected void initComponent() -
receiveUpload
-
onUploadStarted
-
onUploadFinished
-
onUploadSucceeded
-
onUploadFailed
-
onFileSizeLimitExceeded
-
onFileExtensionNotAllowed
-
onFileNameClick
protected abstract void onFileNameClick(com.vaadin.ui.Button.ClickEvent e) -
getFileName
-
addFileUploadSucceedListener
public Subscription addFileUploadSucceedListener(Consumer<SingleFileUploadField.FileUploadSucceedEvent> listener) Description copied from interface:SingleFileUploadField
Adds file upload succeed listener. It is invoked when the uploads are successfully finished.- Specified by:
addFileUploadSucceedListener
in interfaceSingleFileUploadField
- Parameters:
listener
- a listener to add- Returns:
- a registration object for removing an event listener
-
getAccept
Description copied from interface:UploadField
Returns comma separated types of files.- Specified by:
getAccept
in interfaceUploadField
- Returns:
- comma separated types of files
-
setAccept
Description copied from interface:UploadField
Sets the mask for files to filter them in the file selection dialog.
uploadField.setAccept(".png,.jpeg");
- Specified by:
setAccept
in interfaceUploadField
- Parameters:
accept
- comma separated types of files
-
setDropZone
Description copied from interface:UploadField
Sets drop zone reference to this upload component. Files can be dropped to component of the drop zone to be uploaded by this upload component.- Specified by:
setDropZone
in interfaceUploadField
- Parameters:
dropZone
- drop zone descriptor
-
setPasteZone
Description copied from interface:UploadField
Sets paste zone reference to this upload component. PasteZone handles paste shortcut when a text input field in the container is focused.
It is supported by Chromium-based browsers.- Specified by:
setPasteZone
in interfaceUploadField
- Parameters:
pasteZone
- paste zone container
-
setDropZonePrompt
Description copied from interface:UploadField
Sets drop zone prompt that will be shown on drag over window with file.- Specified by:
setDropZonePrompt
in interfaceUploadField
- Parameters:
dropZonePrompt
- drop zone prompt
-
getFileSizeLimit
public long getFileSizeLimit()Description copied from interface:UploadField
Returns maximum allowed file size in bytes.- Specified by:
getFileSizeLimit
in interfaceUploadField
-
getActualFileSizeLimit
protected long getActualFileSizeLimit() -
getPermittedExtensions
Description copied from interface:UploadField
Returns white list of file extensions.- Specified by:
getPermittedExtensions
in interfaceUploadField
- Returns:
- set of file extensions.
-
getFileSizeLimitString
-
internalValueChanged
-
getDropZone
- Specified by:
getDropZone
in interfaceUploadField
- Returns:
- current drop zone
-
getPasteZone
- Specified by:
getPasteZone
in interfaceUploadField
- Returns:
- current paste zone container
-
getDropZonePrompt
- Specified by:
getDropZonePrompt
in interfaceUploadField
- Returns:
- current drop zone prompt
-
clearButtonClicked
protected void clearButtonClicked(com.vaadin.ui.Button.ClickEvent clickEvent) -
fireFileUploadStart
-
fireFileUploadFinish
-
fireFileUploadError
-
fireFileUploadSucceed
-
setContentProvider
Description copied from interface:SingleFileUploadField
Set content provider which contains file data.Passed content provider will be used for downloading by clicking the link with file name or as source for
SingleFileUploadField.getFileContent()
method.- Specified by:
setContentProvider
in interfaceSingleFileUploadField
- Parameters:
contentProvider
- content provider
-
getContentProvider
- Specified by:
getContentProvider
in interfaceSingleFileUploadField
- Returns:
- FileContentProvider which can be used to read data from field
-
addFileUploadStartListener
Description copied from interface:UploadField
Adds file upload start listener. It is invoked when start uploading the file.- Specified by:
addFileUploadStartListener
in interfaceUploadField
- Parameters:
listener
- a listener to add- Returns:
- a registration object for removing an event listener
-
addFileUploadFinishListener
public Subscription addFileUploadFinishListener(Consumer<UploadField.FileUploadFinishEvent> listener) Description copied from interface:UploadField
Adds file upload finish listener. It is invoked when file is uploaded.- Specified by:
addFileUploadFinishListener
in interfaceUploadField
- Parameters:
listener
- a listener to add- Returns:
- a registration object for removing an event listener
-
addFileUploadErrorListener
Description copied from interface:UploadField
Adds file upload error listener. It is invoked when the uploads are finished, but unsuccessful.- Specified by:
addFileUploadErrorListener
in interfaceUploadField
- Parameters:
listener
- a listener to add- Returns:
- a registration object for removing an event listener
-
setFileSizeLimit
public void setFileSizeLimit(long fileSizeLimit) Description copied from interface:UploadField
Sets maximum allowed file size in bytes. Default value is 0. In this case component uses system value.- Specified by:
setFileSizeLimit
in interfaceUploadField
-
isShowFileName
public boolean isShowFileName()- Specified by:
isShowFileName
in interfaceSingleFileUploadField
- Returns:
- true if name of uploaded file is shown.
-
setShowFileName
public void setShowFileName(boolean showFileName) Description copied from interface:SingleFileUploadField
Enable or disable displaying name of uploaded file next to upload button.- Specified by:
setShowFileName
in interfaceSingleFileUploadField
-
setPermittedExtensions
Description copied from interface:UploadField
Sets white list of file extensions. Each extension should start with dot symbol, e.g. ".png".uploadField.setPermittedExtensions(Sets.newHashSet(".png", ".jpg"));
- Specified by:
setPermittedExtensions
in interfaceUploadField
- Parameters:
permittedExtensions
- permitted extensions.
-
setShowClearButton
public void setShowClearButton(boolean showClearButton) Description copied from interface:SingleFileUploadField
Enable or disable displaying name of clear button.- Specified by:
setShowClearButton
in interfaceSingleFileUploadField
-
isShowClearButton
public boolean isShowClearButton()- Specified by:
isShowClearButton
in interfaceSingleFileUploadField
- Returns:
- true if clear button is shown.
-
setClearButtonCaption
Description copied from interface:SingleFileUploadField
Setup clear button caption.- Specified by:
setClearButtonCaption
in interfaceSingleFileUploadField
-
getClearButtonCaption
- Specified by:
getClearButtonCaption
in interfaceSingleFileUploadField
- Returns:
- clear button caption.
-
setClearButtonIcon
Description copied from interface:SingleFileUploadField
Setup clear button icon.- Specified by:
setClearButtonIcon
in interfaceSingleFileUploadField
-
getClearButtonIcon
- Specified by:
getClearButtonIcon
in interfaceSingleFileUploadField
- Returns:
- clear button icon.
-
setClearButtonDescription
Description copied from interface:SingleFileUploadField
Setup clear button description.- Specified by:
setClearButtonDescription
in interfaceSingleFileUploadField
-
getClearButtonDescription
- Specified by:
getClearButtonDescription
in interfaceSingleFileUploadField
- Returns:
- clear button description.
-
addBeforeValueClearListener
public Subscription addBeforeValueClearListener(Consumer<SingleFileUploadField.BeforeValueClearEvent> listener) Description copied from interface:SingleFileUploadField
Sets a callback interface which is invoked by theSingleFileUploadField
before value clearing when user use clear button.Listener can prevent value clearing using
SingleFileUploadField.BeforeValueClearEvent.preventClearAction()
.- Specified by:
addBeforeValueClearListener
in interfaceSingleFileUploadField
- Parameters:
listener
- a listener to add- Returns:
- a registration object for removing an event listener
- See Also:
-
addAfterValueClearListener
public Subscription addAfterValueClearListener(Consumer<SingleFileUploadField.AfterValueClearEvent> listener) Description copied from interface:SingleFileUploadField
Adds a callback interface which is invoked by theSingleFileUploadField
after value has been cleared using clear button.- Specified by:
addAfterValueClearListener
in interfaceSingleFileUploadField
- Parameters:
listener
- a listener to add- Returns:
- a registration object for removing an event listener
- See Also:
-
setUploadButtonCaption
Description copied from interface:SingleFileUploadField
Setup caption of upload button.- Specified by:
setUploadButtonCaption
in interfaceSingleFileUploadField
-
getUploadButtonCaption
- Specified by:
getUploadButtonCaption
in interfaceSingleFileUploadField
- Returns:
- upload button caption.
-
setUploadButtonIcon
Description copied from interface:SingleFileUploadField
Setup upload button icon.- Specified by:
setUploadButtonIcon
in interfaceSingleFileUploadField
-
getUploadButtonIcon
- Specified by:
getUploadButtonIcon
in interfaceSingleFileUploadField
- Returns:
- upload button icon.
-
setUploadButtonDescription
Description copied from interface:SingleFileUploadField
Setup upload button description.- Specified by:
setUploadButtonDescription
in interfaceSingleFileUploadField
-
getUploadButtonDescription
- Specified by:
getUploadButtonDescription
in interfaceSingleFileUploadField
- Returns:
- upload button description.
-
focus
public void focus()Description copied from interface:Component.Focusable
Sets focus to this component- Specified by:
focus
in interfaceComponent.Focusable
-
getTabIndex
public int getTabIndex()Description copied from interface:Component.Focusable
Gets the tabulator index of theHasTabIndex
component.- Specified by:
getTabIndex
in interfaceComponent.Focusable
- Returns:
- tab index set for the
HasTabIndex
component
-
setTabIndex
public void setTabIndex(int tabIndex) Description copied from interface:Component.Focusable
Sets the tabulator index of theFocusable
component. The tab index property is used to specify the order in which the fields are focused when the user presses the Tab key. Components with a defined tab index are focused sequentially first, and then the components with no tab index.- Specified by:
setTabIndex
in interfaceComponent.Focusable
- Parameters:
tabIndex
- tab index
-
commit
public void commit()Description copied from interface:Buffered
Updates all changes since the previous commit to the data source.- Specified by:
commit
in interfaceBuffered
- Overrides:
commit
in classAbstractValueComponent<JmixFileUploadField,
String, R>
-
discard
public void discard()Description copied from interface:Buffered
Discards all changes since last commit. The object updates its value from the data source.- Specified by:
discard
in interfaceBuffered
- Overrides:
discard
in classAbstractValueComponent<JmixFileUploadField,
String, R>
-
isBuffered
public boolean isBuffered()- Specified by:
isBuffered
in interfaceBuffered
- Overrides:
isBuffered
in classAbstractValueComponent<JmixFileUploadField,
String, R> - Returns:
true
if buffered mode is on,false
otherwise
-
setBuffered
public void setBuffered(boolean buffered) Description copied from interface:Buffered
Sets the buffered mode.When in buffered mode, an internal buffer will be used to store changes until
Buffered.commit()
is called. CallingBuffered.discard()
will revert the internal buffer to the value of the data source.When in non-buffered mode both read and write operations will be done directly on the data source. In this mode the
Buffered.commit()
andBuffered.discard()
methods serve no purpose.- Specified by:
setBuffered
in interfaceBuffered
- Overrides:
setBuffered
in classAbstractValueComponent<JmixFileUploadField,
String, R> - Parameters:
buffered
-true
if buffered mode should be turned on,false
otherwise
-
isModified
public boolean isModified()Description copied from interface:Buffered
Tests if the value stored in the object has been modified since it was last updated from the data source.- Specified by:
isModified
in interfaceBuffered
- Overrides:
isModified
in classAbstractValueComponent<JmixFileUploadField,
String, R> - Returns:
true
if the value in the object has been modified since the last data source update,false
if not.
-