added null check for attachment entry and move button state management to the auto preview method.

This commit is contained in:
Heng Sin Low 2011-01-19 13:11:01 +08:00
parent 4aef583e4f
commit 8675e83423
1 changed files with 125 additions and 118 deletions

View File

@ -314,6 +314,8 @@ public class WAttachment extends Window implements EventListener
private boolean autoPreview(int index, boolean immediate)
{
MAttachmentEntry entry = m_attachment.getEntry(index);
if (entry != null)
{
String mimeType = entry.getContentType();
byte[] data = entry.getData();
String unit = " KB";
@ -326,6 +328,10 @@ public class WAttachment extends Window implements EventListener
}
size = size.setScale(2, BigDecimal.ROUND_HALF_EVEN);
sizeLabel.setText(size.toPlainString() + unit);
bSave.setEnabled(true);
bDelete.setEnabled(true);
if (autoPreviewList.contains(mimeType))
{
displayData(index, immediate);
@ -336,6 +342,13 @@ public class WAttachment extends Window implements EventListener
return false;
}
}
else
{
bSave.setEnabled(false);
bDelete.setEnabled(false);
return false;
}
}
/**
* Display gif or jpg in gifPanel
@ -347,9 +360,6 @@ public class WAttachment extends Window implements EventListener
// Reset UI
preview.setSrc(null);
bDelete.setEnabled(false);
bSave.setEnabled(false);
displayIndex = index;
if (immediate)
@ -372,9 +382,6 @@ public class WAttachment extends Window implements EventListener
log.config("Index=" + displayIndex + " - " + entry);
if (entry != null && entry.getData() != null)
{
bSave.setEnabled(true);
bDelete.setEnabled(true);
log.config(entry.toStringX());
try