info.magnolia.ui.form.field.upload
Class AbstractUploadField<D extends FileItemWrapper>

java.lang.Object
  extended by com.vaadin.server.AbstractClientConnector
      extended by com.vaadin.ui.AbstractComponent
          extended by com.vaadin.ui.AbstractField<T>
              extended by com.vaadin.ui.CustomField<Byte[]>
                  extended by info.magnolia.ui.form.field.upload.AbstractUploadField<D>
Type Parameters:
D - FileItemWrapper implemented class.
All Implemented Interfaces:
com.vaadin.data.Buffered, com.vaadin.data.BufferedValidatable, com.vaadin.data.Property<Byte[]>, com.vaadin.data.Property.Editor, com.vaadin.data.Property.ReadOnlyStatusChangeListener, com.vaadin.data.Property.ReadOnlyStatusChangeNotifier, com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer, com.vaadin.data.Validatable, com.vaadin.event.Action.ShortcutNotifier, com.vaadin.event.dd.DropHandler, com.vaadin.event.MethodEventSource, com.vaadin.server.ClientConnector, com.vaadin.server.Sizeable, com.vaadin.shared.Connector, com.vaadin.ui.Component, com.vaadin.ui.Component.Focusable, com.vaadin.ui.Field<Byte[]>, com.vaadin.ui.HasComponents, com.vaadin.ui.Upload.FailedListener, com.vaadin.ui.Upload.FinishedListener, com.vaadin.ui.Upload.ProgressListener, com.vaadin.ui.Upload.StartedListener, UploadField, Serializable, Iterable<com.vaadin.ui.Component>
Direct Known Subclasses:
BasicUploadField

public abstract class AbstractUploadField<D extends FileItemWrapper>
extends com.vaadin.ui.CustomField<Byte[]>
implements com.vaadin.ui.Upload.StartedListener, com.vaadin.ui.Upload.FinishedListener, com.vaadin.ui.Upload.ProgressListener, com.vaadin.ui.Upload.FailedListener, com.vaadin.event.dd.DropHandler, UploadField

Main implementation of the UploadFile field. This implementation used some features of UploadField and associated classes.

This class handles Upload events and expose functions that allows to customize the 3 main upload states (link to a view Component):

Important exposed method
Upload getUpload() : Return the Vaadin Upload Component responsible for the Uploading a File based on a folder.
createDropZone(Component c) : Give the Drop ability to the passed Component.

See Also:
Serialized Form

Nested Class Summary
protected static class AbstractUploadField.InterruptionReason
          Simple Enumeration listing all available Interruption reason.
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractField
com.vaadin.ui.AbstractField.FocusShortcut, com.vaadin.ui.AbstractField.ReadOnlyStatusChangeEvent
 
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
com.vaadin.ui.HasComponents.ComponentAttachDetachNotifier, com.vaadin.ui.HasComponents.ComponentAttachEvent, com.vaadin.ui.HasComponents.ComponentAttachListener, com.vaadin.ui.HasComponents.ComponentDetachEvent, com.vaadin.ui.HasComponents.ComponentDetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
com.vaadin.ui.Component.ErrorEvent, com.vaadin.ui.Component.Event, com.vaadin.ui.Component.Focusable, com.vaadin.ui.Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
com.vaadin.server.ClientConnector.AttachEvent, com.vaadin.server.ClientConnector.AttachListener, com.vaadin.server.ClientConnector.ConnectorErrorEvent, com.vaadin.server.ClientConnector.DetachEvent, com.vaadin.server.ClientConnector.DetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
com.vaadin.server.Sizeable.Unit
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Field
com.vaadin.ui.Field.ValueChangeEvent
 
Nested classes/interfaces inherited from interface com.vaadin.data.Buffered
com.vaadin.data.Buffered.SourceException
 
Nested classes/interfaces inherited from interface com.vaadin.data.Property
com.vaadin.data.Property.Editor, com.vaadin.data.Property.ReadOnlyException, com.vaadin.data.Property.ReadOnlyStatusChangeListener, com.vaadin.data.Property.ReadOnlyStatusChangeNotifier, com.vaadin.data.Property.Transactional<T>, com.vaadin.data.Property.ValueChangeListener, com.vaadin.data.Property.ValueChangeNotifier, com.vaadin.data.Property.Viewer
 
Field Summary
 
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
AbstractUploadField(D fileWrapper, File tmpUploadDirectory, info.magnolia.i18nsystem.SimpleTranslator i18n)
           
 
Method Summary
protected abstract  void buildCompletedLayout()
          Build the Completed Layout.
Use the fileWrapper to display file information and Status.
protected abstract  void buildEmptyLayout()
          Build the Empty Layout.
Use the fileWrapper to display file information and Status.
protected abstract  void buildInProgressLayout(String uploadedFileMimeType)
          Build the in Progress Layout.
Generally display a progress bar UploadProgressIndicator and some file information.
Refresh of the action bar is handled by refreshInProgressLayout(...)
Use the fileWrapper to display file information and Status.
protected  DragAndDropWrapper createDropZone(com.vaadin.ui.Component c)
          The dropZone is a wrapper around a Component.
 void detach()
           
protected abstract  void displayUploadFailedNote(String fileName)
           
protected abstract  void displayUploadFinishedNote(String fileName)
           
protected abstract  void displayUploadInterruptNote(AbstractUploadField.InterruptionReason reason)
           
 void drop(com.vaadin.event.dd.DragAndDropEvent event)
          Drop zone Handler.
 com.vaadin.event.dd.acceptcriteria.AcceptCriterion getAcceptCriterion()
          Handled by isValidFile().
protected  DragAndDropWrapper getDropZone()
           
protected  D getFileWrapper()
          Used to access the current File Wrapper in order to access the current File Informations.
protected  com.vaadin.ui.HasComponents getRootLayout()
           
 Class<? extends Byte[]> getType()
           
protected  com.vaadin.ui.Upload getUpload()
           
protected  void interruptUpload(AbstractUploadField.InterruptionReason reason)
          Interrupt upload based on a user Action.
protected  boolean isValidFile(com.vaadin.ui.Upload.StartedEvent event)
          Define the acceptance Upload Image criteria.
protected abstract  void refreshInProgressLayout(long readBytes, long contentLength, String fileName)
          Update the in Progress Layout.
 void setAllowedMimeTypePattern(String allowedMimeTypePattern)
          Set the AllowedMimeType.
 void setMaxUploadSize(long maxUploadSize)
          Define the Maximum Upload File size in bytes.
protected  void setRootLayout(com.vaadin.ui.HasComponents root)
           
protected  void updateDisplay()
          Call the correct layout.
 void updateProgress(long readBytes, long contentLength)
          Update the Progress Component.
 void uploadFailed(com.vaadin.ui.Upload.FailedEvent event)
           
 void uploadFinished(com.vaadin.ui.Upload.FinishedEvent event)
          Handle the Upload.FinishedEvent.
 void uploadStarted(com.vaadin.ui.Upload.StartedEvent event)
          Start Upload if the file is supported.
 
Methods inherited from class com.vaadin.ui.CustomField
attach, getContent, initContent, iterator, setHeight, setWidth
 
Methods inherited from class com.vaadin.ui.AbstractField
addListener, addListener, addReadOnlyStatusChangeListener, addValidator, addValueChangeListener, beforeClientResponse, commit, discard, fireReadOnlyStatusChange, fireValueChange, focus, getConversionError, getConversionError, getConvertedValue, getConverter, getCurrentBufferedSourceException, getErrorMessage, getInternalValue, getModelType, getPropertyDataSource, getRequiredError, getState, getState, getTabIndex, getValidators, getValue, isBuffered, isEmpty, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isRequired, isValid, isValidationVisible, readOnlyStatusChange, removeAllValidators, removeListener, removeListener, removeReadOnlyStatusChangeListener, removeValidator, removeValueChangeListener, setBuffered, setConversionError, setConvertedValue, setConverter, setConverter, setCurrentBufferedSourceException, setInternalValue, setInvalidAllowed, setInvalidCommitted, setLocale, setPropertyDataSource, setReadOnly, setRequired, setRequiredError, setTabIndex, setValidationVisible, setValue, setValue, shouldHideErrors, toString, validate, validate, valueChange
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addShortcutListener, addStyleName, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isConnectorEnabled, isEnabled, isImmediate, isVisible, removeListener, removeShortcutListener, removeStyleName, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setIcon, setId, setImmediate, setParent, setPrimaryStyleName, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth
 
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hasListeners, isAttached, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
 
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
 
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setSizeFull, setSizeUndefined, setWidth
 
Methods inherited from interface com.vaadin.event.Action.ShortcutNotifier
addShortcutListener, removeShortcutListener
 

Constructor Detail

AbstractUploadField

public AbstractUploadField(D fileWrapper,
                           File tmpUploadDirectory,
                           info.magnolia.i18nsystem.SimpleTranslator i18n)
Method Detail

buildEmptyLayout

protected abstract void buildEmptyLayout()
Build the Empty Layout.
Use the fileWrapper to display file information and Status.


buildInProgressLayout

protected abstract void buildInProgressLayout(String uploadedFileMimeType)
Build the in Progress Layout.
Generally display a progress bar UploadProgressIndicator and some file information.
Refresh of the action bar is handled by refreshInProgressLayout(...)
Use the fileWrapper to display file information and Status.


refreshInProgressLayout

protected abstract void refreshInProgressLayout(long readBytes,
                                                long contentLength,
                                                String fileName)
Update the in Progress Layout.


buildCompletedLayout

protected abstract void buildCompletedLayout()
Build the Completed Layout.
Use the fileWrapper to display file information and Status.


displayUploadInterruptNote

protected abstract void displayUploadInterruptNote(AbstractUploadField.InterruptionReason reason)

displayUploadFinishedNote

protected abstract void displayUploadFinishedNote(String fileName)

displayUploadFailedNote

protected abstract void displayUploadFailedNote(String fileName)

updateDisplay

protected void updateDisplay()
Call the correct layout.


interruptUpload

protected void interruptUpload(AbstractUploadField.InterruptionReason reason)
Interrupt upload based on a user Action. An com.vaadin.server.communication.FileUploadHandler.UploadInterruptedException will be thrown by the underlying Vaadin classes.


isValidFile

protected boolean isValidFile(com.vaadin.ui.Upload.StartedEvent event)
Define the acceptance Upload Image criteria. The current implementation only check if the MimeType match the desired regExp.


getUpload

protected com.vaadin.ui.Upload getUpload()
Returns:
the initialized Upload component.

getDropZone

protected DragAndDropWrapper getDropZone()
Returns:
the initialized DragAndDropWrapper.

getFileWrapper

protected D getFileWrapper()
Used to access the current File Wrapper in order to access the current File Informations.


createDropZone

protected DragAndDropWrapper createDropZone(com.vaadin.ui.Component c)
The dropZone is a wrapper around a Component.


drop

public void drop(com.vaadin.event.dd.DragAndDropEvent event)
Drop zone Handler.

Specified by:
drop in interface com.vaadin.event.dd.DropHandler

getAcceptCriterion

public com.vaadin.event.dd.acceptcriteria.AcceptCriterion getAcceptCriterion()
Handled by isValidFile().

Specified by:
getAcceptCriterion in interface com.vaadin.event.dd.DropHandler

uploadStarted

public void uploadStarted(com.vaadin.ui.Upload.StartedEvent event)
Start Upload if the file is supported.
In case of not a supported file, interrupt the Upload.

Specified by:
uploadStarted in interface com.vaadin.ui.Upload.StartedListener

updateProgress

public void updateProgress(long readBytes,
                           long contentLength)
Update the Progress Component. At the same time, check if the uploaded File is not bigger as expected. Interrupt the Upload in this case.

Specified by:
updateProgress in interface com.vaadin.ui.Upload.ProgressListener

uploadFinished

public void uploadFinished(com.vaadin.ui.Upload.FinishedEvent event)
Handle the Upload.FinishedEvent. In case of success:
- Populate the Uploaded Information to the fileWrapper.
- Build the Completed Layout.
In case of Upload.FailedEvent (this event is send on a Cancel upload)
- Do not populate data and call uploadFailed().

Specified by:
uploadFinished in interface com.vaadin.ui.Upload.FinishedListener

uploadFailed

public void uploadFailed(com.vaadin.ui.Upload.FailedEvent event)
Specified by:
uploadFailed in interface com.vaadin.ui.Upload.FailedListener

getType

public Class<? extends Byte[]> getType()
Specified by:
getType in interface com.vaadin.data.Property<Byte[]>
Specified by:
getType in class com.vaadin.ui.AbstractField<Byte[]>

getRootLayout

protected com.vaadin.ui.HasComponents getRootLayout()

setRootLayout

protected void setRootLayout(com.vaadin.ui.HasComponents root)

setAllowedMimeTypePattern

public void setAllowedMimeTypePattern(String allowedMimeTypePattern)
Description copied from interface: UploadField
Set the AllowedMimeType.

Specified by:
setAllowedMimeTypePattern in interface UploadField

setMaxUploadSize

public void setMaxUploadSize(long maxUploadSize)
Description copied from interface: UploadField
Define the Maximum Upload File size in bytes.

Specified by:
setMaxUploadSize in interface UploadField

detach

public void detach()
Specified by:
detach in interface com.vaadin.server.ClientConnector
Overrides:
detach in class com.vaadin.ui.AbstractField<Byte[]>


Copyright © 2013 Magnolia International Ltd.. All Rights Reserved.