Class WFileDropWidget
- java.lang.Object
-
- eu.webtoolkit.jwt.WObject
-
- eu.webtoolkit.jwt.WWidget
-
- eu.webtoolkit.jwt.WWebWidget
-
- eu.webtoolkit.jwt.WInteractWidget
-
- eu.webtoolkit.jwt.WContainerWidget
-
- eu.webtoolkit.jwt.WFileDropWidget
-
public class WFileDropWidget extends WContainerWidget
A widget that allows dropping files and directories for upload.This widget accepts files that are dropped into it. A signal is triggered whenever one or more files or directories are dropped. The filename, type and size of files is immediately available through the
WFileDropWidget.Fileinterface. Similarly, information about directories is available through theWFileDropWidget.Directoryinterface (which is a subclass ofWFileDropWidget.File).The file upload is done sequentially. All files before the
getCurrentIndex()have either finished, failed or have been cancelled.The widget has the default style-class 'Wt-filedropzone'. The style-class 'Wt-dropzone-hover' is added when files are hovered over the widget.
Apart from dropping files, users can also use the browser-specific dialog to select files or directories. Note that the dialog will support either selecting files or directories, but not both at the same time. The dialog can be opened by clicking the widget. The type of dialog that is opened can be configured with
setOnClickFilePicker(). The dialog can also be opened programmatically in response to another event (e.g. a user clicking a button outside this widget) usingopenFilePicker()andopenDirectoryPicker().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWFileDropWidget.DirectoryA nested class ofWFileDropWidgetrepresenting aWFileDropWidget.Directory.static classWFileDropWidget.FileA nested class ofWFileDropWidgetrepresenting a file.-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Field Summary
-
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefault
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Constructor Summary
Constructors Constructor Description WFileDropWidget()Constructor.WFileDropWidget(WContainerWidget parentContainer)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcancelUpload(WFileDropWidget.File file)Cancels the upload of a file.voidcleanDirectoryResources()Cleans up resources ofWFileDropWidget.Directoryobjects.Signal1<java.util.List<WFileDropWidget.File>>drop()The signal triggers if one or more files are dropped.protected voidenableAjax()Progresses to an Ajax-enabled widget.protected WFileDropWidget.FilegetCurrentFile()intgetCurrentIndex()Return the index of the file that is currently being handled.FilePickerTypegetOnClickFilePicker()Returns the type of file picker that is opened when a user clicks the widget.protected WResourcegetUploadResource()Resource to upload data to.java.util.List<WFileDropWidget.File>getUploads()Returns the vector of uploads managed by this widget.booleanisAcceptDirectories()Returns if directories are accepted.booleanisAcceptDirectoriesRecursive()Returns if directory contents is uploaded recursively or not.booleanisDropIndicationEnabled()Returns if the widget is highlighted for drags anywhere on the page.booleanisGlobalDropEnabled()Returns if all drops are forwarded to this widget.Signal1<WFileDropWidget.File>newUpload()The signal triggers when the upload of a file is about to begin.voidopenDirectoryPicker()Programmatically open the directory picker.voidopenFilePicker()Programmatically open the file picker.voidproceedToNextFile()Indicate that the next file can be handled.booleanremove(WFileDropWidget.File file)Removes the file.protected JSignal1<java.lang.Integer>requestSend()voidsetAcceptDirectories(boolean enable)Allow users to drop directories.voidsetAcceptDirectories(boolean enable, boolean recursive)Allow users to drop directories.voidsetAcceptDrops(boolean enable)When set to false, the widget no longer accepts any files.voidsetDropIndicationEnabled(boolean enable)Highlight widget if a file is dragged anywhere on the page.voidsetFilters(java.lang.String acceptAttributes)Sets input accept attributes.voidsetGlobalDropEnabled(boolean enable)Allow dropping the files anywhere on the page.voidsetHoverStyleClass(java.lang.String className)Deprecated.Override the css rule '.Wt-filedropzone.Wt-dropzone-hover' instead.voidsetJavaScriptFilter(java.lang.String filterFn)Supply a function to process file data before it is uploaded to the server.voidsetJavaScriptFilter(java.lang.String filterFn, long chunksize)Supply a function to process file data before it is uploaded to the server.voidsetJavaScriptFilter(java.lang.String filterFn, long chunksize, java.util.List<java.lang.String> imports)Supply a function to process file data before it is uploaded to the server.voidsetOnClickFilePicker(FilePickerType type)Set the type of file picker that is opened when a user clicks the widget.Signal2<WFileDropWidget.File,java.lang.Long>tooLarge()The signal triggers when a file is too large for upload.Signal1<WFileDropWidget.File>uploaded()The signal is triggered if any file finished uploading.Signal1<WFileDropWidget.File>uploadFailed()The signal triggers when an upload failed.-
Methods inherited from class eu.webtoolkit.jwt.WContainerWidget
addWidget, clear, createDomElement, getContentAlignment, getCount, getDomChanges, getIndexOf, getLayout, getPadding, getScrollLeft, getScrollTop, getWidget, insertBefore, insertWidget, isGlobalUnfocussed, isList, isOrderedList, isUnorderedList, iterateChildren, parentResized, remove, removeWidget, scrolled, setContentAlignment, setContentAlignment, setFormData, setGlobalUnfocused, setLayout, setList, setList, setOverflow, setOverflow, setOverflow, setPadding, setPadding, setPadding
-
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, render, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
-
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, hideToolTip, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, propagateSetVisible, refresh, removeScript, removeStyleClass, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
-
-
-
Constructor Detail
-
WFileDropWidget
public WFileDropWidget(WContainerWidget parentContainer)
Constructor.
-
WFileDropWidget
public WFileDropWidget()
Constructor.
-
-
Method Detail
-
getUploads
public java.util.List<WFileDropWidget.File> getUploads()
Returns the vector of uploads managed by this widget.The files in this vector are handled sequentially by the widget. All
WFileDropWidget.Fileobjects in this vector have either finished or failed if they are before thegetCurrentIndex(), depending on the return value ofisUploadFinished(). The other files are still being handled.Remark: Since version 4.7.0, this method returns a copy of the vector because we changed the internal vector to hold values of type std::unique_ptr.
- See Also:
getCurrentIndex()
-
getCurrentIndex
public int getCurrentIndex()
Return the index of the file that is currently being handled.If nothing is to be done, this will return the size of the vector returned by
getUploads().
-
cancelUpload
public void cancelUpload(WFileDropWidget.File file)
Cancels the upload of a file.If you cancel a file that is still waiting to be uploaded, it will stay in the
getUploads()vector, but it will be skipped.
-
remove
public boolean remove(WFileDropWidget.File file)
Removes the file.This can be used to free resources of files that were already uploaded. A file can only be removed if its index in
getUploads()is before the current index. A directory can be removed as soon as thedrop()signal is emitted.Note: This method is only important if you intend to use this widget to upload a lot of files. Otherwise, simply removing the widget will also clean up all resources.
-
cleanDirectoryResources
public void cleanDirectoryResources()
Cleans up resources ofWFileDropWidget.Directoryobjects.This can be used to free resources. The
drop()signal returns raw pointers for objects that are managed by this widget. TheWFileDropWidget.Directoryobjects are no longer needed after thedrop()signal, so whenever you don't need them anymore, it is safe to call this method. Note that noWFileDropWidget.Fileobjects are removed by this method since these objects can only be removed after their upload has completed.Note: This method is only important if you intend to use this widget to upload a lot of files. Otherwise, simply removing the widget will also clean up all resources.
- See Also:
remove(WFileDropWidget.File file)
-
setAcceptDrops
public void setAcceptDrops(boolean enable)
When set to false, the widget no longer accepts any files.
-
setHoverStyleClass
public void setHoverStyleClass(java.lang.String className)
Deprecated.Override the css rule '.Wt-filedropzone.Wt-dropzone-hover' instead.Set the style class that is applied when a file is hovered over the widget.
-
setFilters
public void setFilters(java.lang.String acceptAttributes)
Sets input accept attributes.The accept attribute may be specified to provide user agents with a hint of what file types will be accepted. Use html input accept attributes as input. This only affects the popup that is shown when users click on the widget. A user can still drop any file type.
-
setDropIndicationEnabled
public void setDropIndicationEnabled(boolean enable)
Highlight widget if a file is dragged anywhere on the page.As soon as a drag enters anywhere on the page the styleclass 'Wt-dropzone-indication' is added to this widget. This can be useful to point the user to the correct place to drop the file. Once the user drags a file over the widget itself, the styleclass 'hover-style' is also added. This can be enabled for multiple dropwidgets if only one of them is visible at the same time.
- See Also:
setGlobalDropEnabled(boolean enable)
-
isDropIndicationEnabled
public boolean isDropIndicationEnabled()
Returns if the widget is highlighted for drags anywhere on the page.- See Also:
setDropIndicationEnabled(boolean enable)
-
setGlobalDropEnabled
public void setGlobalDropEnabled(boolean enable)
Allow dropping the files anywhere on the page.If enabled, a drop anywhere on the page will be forwarded to this widget.
- See Also:
setDropIndicationEnabled(boolean enable)
-
isGlobalDropEnabled
public boolean isGlobalDropEnabled()
Returns if all drops are forwarded to this widget.- See Also:
setGlobalDropEnabled(boolean enable)
-
setJavaScriptFilter
public void setJavaScriptFilter(java.lang.String filterFn, long chunksize, java.util.List<java.lang.String> imports)Supply a function to process file data before it is uploaded to the server.
-
setJavaScriptFilter
public final void setJavaScriptFilter(java.lang.String filterFn)
Supply a function to process file data before it is uploaded to the server.
-
setJavaScriptFilter
public final void setJavaScriptFilter(java.lang.String filterFn, long chunksize)Supply a function to process file data before it is uploaded to the server.Calls
setJavaScriptFilter(filterFn, chunksize, new ArrayList())
-
setAcceptDirectories
public void setAcceptDirectories(boolean enable, boolean recursive)Allow users to drop directories.Dropping a directory will emit the
drop()signal with aWFileDropWidget.Directoryobject (which inheritsWFileDropWidget.File). A directory can also be recognized by theisDirectory()method. After downcasting the object, the methodgetContents()can be used to iterate over the contents.Subdirectories are also included in the contents. The contents of subdirectories itself is only included if recursive is true.
Only
WFileDropWidget.Fileobjects for whichisDirectory()is false are uploaded to the server. The contents of a directory is 'flattened' into thegetUploads()vector. The directory structure is still available through thegetPath()method that describes the file's path relative to the dropped directory.- See Also:
openFilePicker(),openDirectoryPicker()
-
setAcceptDirectories
public final void setAcceptDirectories(boolean enable)
Allow users to drop directories.
-
isAcceptDirectories
public boolean isAcceptDirectories()
-
isAcceptDirectoriesRecursive
public boolean isAcceptDirectoriesRecursive()
Returns if directory contents is uploaded recursively or not.
-
setOnClickFilePicker
public void setOnClickFilePicker(FilePickerType type)
Set the type of file picker that is opened when a user clicks the widget.The default is
FilePickerType.FileSelection.When
FilePickerType.Noneis passed, no file picker will be shown. Files or directories can still be dropped in, ifsetAcceptDrops()is set totrue(which by default it is). Also note that in this case, the methodsopenFilePicker()andopenDirectoryPicker()can still be used to open a picker by redirecting clicks from other buttons.
-
getOnClickFilePicker
public FilePickerType getOnClickFilePicker()
Returns the type of file picker that is opened when a user clicks the widget.
-
openFilePicker
public void openFilePicker()
Programmatically open the file picker.Users can click the widget to open a browser-specific dialog to select either files or directories (see
setOnClickFilePicker()). This method allows developers to also open the dialog by other means, e.g. buttons outside the widget to open either the file- or directory picker.- See Also:
openDirectoryPicker()
-
openDirectoryPicker
public void openDirectoryPicker()
Programmatically open the directory picker.Users can click the widget to open a browser-specific dialog to select either files or directories (see
setOnClickFilePicker()). This method allows developers to also open the dialog by other means, e.g. buttons outside the widget to open either the file- or directory picker.Warning: Due to limitations in the directory picker api, empty directories will not be returned when selected through the dialog.
- See Also:
openFilePicker()
-
drop
public Signal1<java.util.List<WFileDropWidget.File>> drop()
The signal triggers if one or more files are dropped.
-
newUpload
public Signal1<WFileDropWidget.File> newUpload()
The signal triggers when the upload of a file is about to begin.After this signal is triggered, the upload automatically starts. The upload can still fail if the file is too large or if there is a network error.
-
uploaded
public Signal1<WFileDropWidget.File> uploaded()
The signal is triggered if any file finished uploading.
-
tooLarge
public Signal2<WFileDropWidget.File,java.lang.Long> tooLarge()
The signal triggers when a file is too large for upload.This signal is triggered when the widget attempts to upload the file.
The second argument is the size of the file in bytes.
-
uploadFailed
public Signal1<WFileDropWidget.File> uploadFailed()
The signal triggers when an upload failed.This signal will trigger when the widget skips over one of the files in the list for an unknown reason (e.g. happens when you drop a folder).
-
proceedToNextFile
public void proceedToNextFile()
Indicate that the next file can be handled.Internally indicate handling of the next file. Any resource handling the upload needs to call this when the file is handled.
-
enableAjax
protected void enableAjax()
Description copied from class:WWidgetProgresses to an Ajax-enabled widget.This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.
You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.
- Overrides:
enableAjaxin classWWebWidget- See Also:
WApplication.enableAjax()
-
getUploadResource
protected WResource getUploadResource()
Resource to upload data to.This returns a resource to upload data to. By default this returns a resource where the file contents can be POSTed. This can be overridden to allow for custom upload mechanisms.
This can be used to implement upload protocols that are different from the normal upload flow. The request may include extra information in their payload, or be located on a public fixed URL and require custom handling of the request.
On the client side, the JS function wtCustomSend(isValid, url, upload, APP) can implement a custom upload mechanism, with:
- isValid: whether a valid file is uploaded
- url: the upload location
- upload: a file object with:
- id: generated upload identifier
- filename: upload file name
- type: file type
- size: file size
To use this function, define the JS boolean
wtUseCustomSend, which isfalseby default. Example:Wt::WApplication::instance().setJavaScriptMember("wtUseCustomSend", "true"); Wt::WApplication::instance().setJavaScriptMember("wtCustomSend", "function(isValid, url, upload) { * ... * };");
-
requestSend
protected JSignal1<java.lang.Integer> requestSend()
-
getCurrentFile
protected WFileDropWidget.File getCurrentFile()
-
-