From 15a7173e648a09c07c7918471c73ea83b5fc28b9 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 13 May 2015 18:47:50 -0500 Subject: [PATCH] IDEMPIERE-2596 Lost changes when attachment window is closed / avoid NPE and duplicated process of changes --- .../adempiere/webui/panel/WAttachment.java | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java index d61c8f0998..e9eb19e3db 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/WAttachment.java @@ -478,28 +478,31 @@ public class WAttachment extends Window implements EventListener UploadEvent ue = (UploadEvent) e; processUploadMedia(ue.getMedia()); } else if (e.getTarget() == bOk || DialogEvents.ON_WINDOW_CLOSE.equals(e.getName())) { - String newText = text.getText(); - if (newText == null) - newText = ""; - String oldText = m_attachment.getTextMsg(); - if (oldText == null) - oldText = ""; + if (m_attachment != null) { + String newText = text.getText(); + if (newText == null) + newText = ""; + String oldText = m_attachment.getTextMsg(); + if (oldText == null) + oldText = ""; - if (!m_change) - m_change = !newText.equals(oldText); + if (!m_change) + m_change = !newText.equals(oldText); - if (newText.length() > 0 || m_attachment.getEntryCount() > 0) { - if (m_change) { - m_attachment.setBinaryData(new byte[0]); // ATTENTION! HEAVY HACK HERE... Else it will not save :( - m_attachment.setTextMsg(text.getText()); - m_attachment.saveEx(); + if (newText.length() > 0 || m_attachment.getEntryCount() > 0) { + if (m_change) { + m_attachment.setBinaryData(new byte[0]); // ATTENTION! HEAVY HACK HERE... Else it will not save :( + m_attachment.setTextMsg(text.getText()); + m_attachment.saveEx(); + m_change = false; + } + } else { + m_attachment.delete(true); + m_attachment = null; } - } else { - m_attachment.delete(true); - m_attachment = null; - } - dispose(); + dispose(); + } } else if (e.getTarget() == bCancel) { // Cancel dispose();