diff -Nadur delme/FileBuffer.java easyuploads/FileBuffer.java --- delme/FileBuffer.java Thu Jun 23 18:18:48 2011 +++ easyuploads/FileBuffer.java Tue May 7 09:28:31 2013 @@ -107,6 +107,8 @@ file.delete(); } if (newValue == null) { + // bug #2 delete for most cases just does not work + file=null; return; } // we set the contents of the file diff -Nadur delme/UploadField.java easyuploads/UploadField.java --- delme/UploadField.java Fri Mar 15 15:04:50 2013 +++ easyuploads/UploadField.java Tue May 7 09:28:31 2013 @@ -76,16 +76,16 @@ @SuppressWarnings({ "serial", "unused" }) public class UploadField extends CssLayout implements Field, StartedListener, FinishedListener, ProgressListener { - private static final int MAX_SHOWN_BYTES = 5; + protected static final int MAX_SHOWN_BYTES = 5; - private UploadFieldReceiver receiver; + protected UploadFieldReceiver receiver; - private Upload upload; - private Label display = new Label("", Label.CONTENT_XHTML); + protected Upload upload; + protected Label display = new Label("", Label.CONTENT_XHTML); - private ProgressIndicator progress = new ProgressIndicator(); + protected ProgressIndicator progress = new ProgressIndicator(); - private StorageMode storageMode; + protected StorageMode storageMode; public UploadField() { this(StorageMode.FILE); @@ -100,6 +100,8 @@ upload.addListener((FinishedListener) this); upload.addListener((ProgressListener) this); upload.setButtonCaption("Choose File"); + // bug#1 lastFileName will often show contents of another dialog. + lastFileName=null; progress.setVisible(false); progress.setPollingInterval(500); buildDefaulLayout(); @@ -176,9 +178,9 @@ } } - private FieldType fieldType; + protected FieldType fieldType; - private String lastFileName; + protected String lastFileName; public Class getType() { return fieldType.getRawType(); @@ -229,6 +231,11 @@ } public InputStream getContentAsStream() { + // #bug2 Potential problem NullPointer. + if( outputBuffer == null) + { + return new ByteArrayInputStream( new byte[0] ); + } byte[] byteArray = outputBuffer.toByteArray(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( byteArray); @@ -240,6 +247,9 @@ fileName = null; outputBuffer = new ByteArrayOutputStream(); FieldType fieldType2 = getFieldType(); + // #bug2 Potential problem NullPointer. + if(newValue== null) + return; switch (fieldType2) { case BYTE_ARRAY: byte[] newValueBytes = (byte[]) newValue; @@ -270,6 +280,11 @@ } public long getLastFileSize() { + // #bug2 Potential problem NullPointer. + if( isEmpty()) + { + return 0L; + } return outputBuffer.size(); } @@ -283,9 +298,9 @@ } - private FileFactory fileFactory; + protected FileFactory fileFactory; - private Button deleteButton; + protected Button deleteButton; public void setFileFactory(FileFactory fileFactory) { this.fileFactory = fileFactory; @@ -299,10 +314,16 @@ } public void setValue(Object newValue) { + + // bug#1 lastFileName will often show contents of another dialog. + this.lastFileName=null; receiver.setValue(newValue); if (writeTroughMode) { commit(); } + // bug#1 lastFileName will often show contents of another dialog. + this.updateDisplay(); + this.requestRepaint(); } public Object getValue() { @@ -357,7 +378,9 @@ public void buttonClick(ClickEvent arg0) { setValue(null); getRootLayout().removeComponent(arg0.getButton()); - updateDisplay(); + // bug #2 delete for most cases just does not work. + updateDisplay(); // Display needs to be updated. + fireValueChange(); // Listener needs to know, otherwise commit may not be possible } }); } @@ -372,8 +395,24 @@ getRootLayout().addComponent(b); } - protected String getDeleteCaption() { - return "X"; + protected String deleteCaption = "X"; + + public String getDeleteCaption() { + return deleteCaption; + } + + public void setDeleteCaption(String caption) { + deleteCaption = caption; + } + + protected boolean showFileStart = true; + + public void setShowFileStart(boolean ssfs) { + this.showFileStart = ssfs; + } + + public boolean getShowFileStart() { + return showFileStart; } /** @@ -383,32 +422,48 @@ */ protected String getDisplayDetails() { StringBuilder sb = new StringBuilder(); - sb.append("File: "); - sb.append(lastFileName); - sb.append("
"); + // Bug #3 will display FileName when no present + if( lastFileName != null ) + { + sb.append("Filename:\u00a0"); + sb.append(lastFileName); + sb.append("
"); + } + Object value = getValue(); - if (getFieldType() == FieldType.BYTE_ARRAY) { - byte[] ba = (byte[]) value; - int shownBytes = MAX_SHOWN_BYTES; - if (ba.length < MAX_SHOWN_BYTES) { - shownBytes = ba.length; - } - for (int i = 0; i < shownBytes; i++) { - byte b = ba[i]; - sb.append(Integer.toHexString(b)); - } - if (ba.length > MAX_SHOWN_BYTES) { - sb.append("..."); - sb.append("(" + ba.length + " bytes)"); - } - } else { - String string = value == null ? null : value.toString(); - if (string.length() > 200) { - string = string.substring(0, 199) + "..."; + if (showFileStart == false) { + boolean isByte = getFieldType() == FieldType.BYTE_ARRAY; + sb.append("Length:\u00a0").append( + (isByte + ? ((byte[]) value).length + : value.toString().length())); + } else + { + sb.append(""); + if (getFieldType() == FieldType.BYTE_ARRAY) { + byte[] ba = (byte[]) value; + int shownBytes = MAX_SHOWN_BYTES; + if (ba.length < MAX_SHOWN_BYTES) { + shownBytes = ba.length; + } + for (int i = 0; i < shownBytes; i++) { + byte b = ba[i]; + sb.append(Integer.toHexString(b)); + } + if (ba.length > MAX_SHOWN_BYTES) { + sb.append("..."); + sb.append("(" + ba.length + " bytes)"); + } + } else { + String string = value == null ? null : value.toString(); + if (string.length() > 200) { + string = string.substring(0, 199) + "..."; + } + sb.append(string); } - sb.append(string); + sb.append(""); } - sb.append("
"); + return sb.toString(); } @@ -424,67 +479,67 @@ return fileDeletesAllowed; } - private boolean fileDeletesAllowed = true; + protected boolean fileDeletesAllowed = true; // FIELD RELATED FIELDS /** * Connected data-source. */ - private Property dataSource = null; + protected Property dataSource = null; /** * The list of validators. */ - private LinkedList validators = null; + protected LinkedList validators = null; /** * Auto commit mode. */ - private boolean writeTroughMode = true; + protected boolean writeTroughMode = true; /** * Is the field modified but not committed. */ - private boolean modified = false; + protected boolean modified = false; /** * Current source exception. */ - private Buffered.SourceException currentBufferedSourceException = null; + protected Buffered.SourceException currentBufferedSourceException = null; /** * Are the invalid values allowed in fields ? */ - private boolean invalidAllowed = true; + protected boolean invalidAllowed = true; /** * Are the invalid values committed ? */ - private boolean invalidCommitted = false; + protected boolean invalidCommitted = false; /** * The tab order number of this field. */ - private int tabIndex = 0; + protected int tabIndex = 0; /** * Required field. */ - private boolean required = false; + protected boolean required = false; /** * The error message for the exception that is thrown when the field is * required but empty. */ - private String requiredError = ""; + protected String requiredError = ""; /** * Is automatic validation enabled. */ - private boolean validationVisible = true; + protected boolean validationVisible = true; - private static final Method VALUE_CHANGE_METHOD; + protected static final Method VALUE_CHANGE_METHOD; static { try { @@ -759,6 +814,10 @@ setPropertyDataSource(null); setPropertyDataSource(dataSource2); modified = false; + // bug#4 Discard does not update shown contents + lastFileName=null; + this.updateDisplay(); + this.requestRepaint(); } }