Class FileUpload
- java.lang.Object
-
- org.eclipse.swt.widgets.Widget
-
- org.eclipse.swt.widgets.Control
-
- org.eclipse.swt.widgets.Scrollable
-
- org.eclipse.swt.widgets.Composite
-
- org.eclipse.swt.widgets.Canvas
-
- org.eclipse.rap.rwt.widgets.FileUpload
-
public class FileUpload extends Canvas
A button-like widget allowing to select a file from the client's file system and to upload this file to a given URL using HTTP POST. Multiple files may be selected if MULTI style is given, but not all clients may support it.Note that although this class is a subclass of
Composite, it does not make sense to set a layout on it.- Styles:
- MULTI
- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description FileUpload(Composite parent, int style)Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSelectionListener(SelectionListener listener)Adds the listener to the collection of listeners who will be notified when the user changes the receiver's selection, by sending it one of the messages defined in theSelectionListenerinterface.PointcomputeSize(int wHint, int hHint, boolean changed)Returns the preferred size of the receiver.<T> TgetAdapter(java.lang.Class<T> adapter)Implementation of theAdaptableinterface.Control[]getChildren()Returns a (possibly empty) array containing the receiver's children.java.lang.StringgetFileName()Returns the selected file name, without the path.java.lang.String[]getFileNames()Returns a (possibly empty) array with the names of all files that were selected.java.lang.String[]getFilterExtensions()Returns the file extensions which the widget will use to filter the files it shows.ImagegetImage()Returns the receiver's image if it has one, or null if it does not.java.lang.StringgetText()Returns the receiver's text, which will be an empty string if it has never been set.voidremoveSelectionListener(SelectionListener listener)Removes the listener from the collection of listeners who will be notified when the user changes the receiver's selection.voidsetFilterExtensions(java.lang.String[] extensions)Set the file extensions which the widget will use to filter the files it shows to the argument, which may not be null.voidsetImage(Image image)Sets the receiver's image to the argument, which may benullindicating that no image should be displayed.voidsetLayout(Layout layout)Sets the layout which is associated with the receiver to be the argument which may be null.voidsetText(java.lang.String text)Sets the receiver's text.voidsubmit(java.lang.String url)Starts to upload the selected file to the given URL using HTTP POST.-
Methods inherited from class org.eclipse.swt.widgets.Canvas
addPaintListener, removePaintListener
-
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, getBackgroundMode, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayoutDeferred, setTabList
-
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
-
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addTouchListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getShell, getSize, getToolTipText, getTouchEnabled, getVisible, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCursor, setData, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setSize, setSize, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, update
-
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, toString
-
-
-
-
Constructor Detail
-
FileUpload
public FileUpload(Composite parent, int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.The style value is either one of the style constants defined in class
SWTwhich is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint"|" operator) two or more of thoseSWTstyle constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent- a composite control which will be the parent of the new instance (cannot be null)style- the style of control to construct- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
-
-
Method Detail
-
setText
public void setText(java.lang.String text)
Sets the receiver's text.- Parameters:
text- the new text- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the text is null
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getText
public java.lang.String getText()
Returns the receiver's text, which will be an empty string if it has never been set.- Returns:
- the receiver's text
- Throws:
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setImage
public void setImage(Image image)
Sets the receiver's image to the argument, which may benullindicating that no image should be displayed.- Parameters:
image- the image to display on the receiver (may benull)- Throws:
java.lang.IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the image has been disposed
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getImage
public Image getImage()
Returns the receiver's image if it has one, or null if it does not.- Returns:
- the receiver's image
- Throws:
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getFileName
public java.lang.String getFileName()
Returns the selected file name, without the path. If no file name has been selected,nullis returned. If multiple files have been selected, the first is returned.- Returns:
- the selected file name
- Throws:
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getFileNames
public java.lang.String[] getFileNames()
Returns a (possibly empty) array with the names of all files that were selected.- Returns:
- the names of the selected files
- Throws:
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 2.2
-
setFilterExtensions
public void setFilterExtensions(java.lang.String[] extensions)
Set the file extensions which the widget will use to filter the files it shows to the argument, which may not be null.An extension filter string must be of the form ".extension".
- Parameters:
extensions- the file extension filter- Throws:
java.lang.IllegalArgumentException-- ERROR_INVALID_ARGUMENT - if the extensions is null
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 3.2
-
getFilterExtensions
public java.lang.String[] getFilterExtensions()
Returns the file extensions which the widget will use to filter the files it shows.- Returns:
- the file extensions filter
- Since:
- 3.2
-
submit
public void submit(java.lang.String url)
Starts to upload the selected file to the given URL using HTTP POST. If no file has been selected, nothing happens.Note: Calling this method while a file is still uploading might interrupt the ongoing upload. Due to restrictions of the client, there is no feedback for success or failure of the upload. This information can only be obtained from the server that accepts the upload.
- Parameters:
url- the URL to upload to, must not benull- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the url is null
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
addSelectionListener
public void addSelectionListener(SelectionListener listener)
Adds the listener to the collection of listeners who will be notified when the user changes the receiver's selection, by sending it one of the messages defined in theSelectionListenerinterface.widgetSelectedis called when the selected file changes.widgetDefaultSelectedis not called.- Parameters:
listener- the listener which should be notified when the user changes the receiver's selection- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
SelectionListener,SelectionEvent,removeSelectionListener(org.eclipse.swt.events.SelectionListener)
-
removeSelectionListener
public void removeSelectionListener(SelectionListener listener)
Removes the listener from the collection of listeners who will be notified when the user changes the receiver's selection.- Parameters:
listener- the listener which should no longer be notified- Throws:
java.lang.IllegalArgumentException-- ERROR_NULL_ARGUMENT - if the listener is null
SWTException-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- See Also:
SelectionListener,SelectionEvent,addSelectionListener(org.eclipse.swt.events.SelectionListener)
-
computeSize
public Point computeSize(int wHint, int hHint, boolean changed)
Description copied from class:ControlReturns the preferred size of the receiver.The preferred size of a control is the size that it would best be displayed at. The width hint and height hint arguments allow the caller to ask a control questions such as "Given a particular width, how high does the control need to be to show all of the contents?" To indicate that the caller does not wish to constrain a particular dimension, the constant
SWT.DEFAULTis passed for the hint.If the changed flag is
true, it indicates that the receiver's contents have changed, therefore any caches that a layout manager containing the control may have been keeping need to be flushed. When the control is resized, the changed flag will befalse, so layout manager caches can be retained.- Overrides:
computeSizein classComposite- Parameters:
wHint- the width hint (can beSWT.DEFAULT)hHint- the height hint (can beSWT.DEFAULT)changed-trueif the control's contents have changed, andfalseotherwise- Returns:
- the preferred size of the control.
- See Also:
Layout,Control.getBorderWidth(),Control.getBounds(),Control.getSize(),Control.pack(boolean), "computeTrim, getClientArea for controls that implement them"
-
setLayout
public void setLayout(Layout layout)
Description copied from class:CompositeSets the layout which is associated with the receiver to be the argument which may be null.
-
getChildren
public Control[] getChildren()
Description copied from class:CompositeReturns a (possibly empty) array containing the receiver's children. Children are returned in the order that they are drawn. The topmost control appears at the beginning of the array. Subsequent controls draw beneath this control and appear later in the array.Note: This is not the actual structure used by the receiver to maintain its list of children, so modifying the array will not affect the receiver.
- Overrides:
getChildrenin classComposite- Returns:
- an array of children
- See Also:
Control.moveAbove(org.eclipse.swt.widgets.Control),Control.moveBelow(org.eclipse.swt.widgets.Control)
-
getAdapter
public <T> T getAdapter(java.lang.Class<T> adapter)
Description copied from class:WidgetImplementation of theAdaptableinterface.IMPORTANT: This method is not part of the RWT public API. It is marked public only so that it can be shared within the packages provided by RWT. It should never be accessed from application code.
- Specified by:
getAdapterin interfaceAdaptable- Overrides:
getAdapterin classCanvas- Parameters:
adapter- the lookup class- Returns:
- an object that can be cast to the given class or
nullif there is no adapter associated with the given class.
-
-