IDEMPIERE-618 Zk: Binary editor not working.

This commit is contained in:
Heng Sin Low 2013-02-08 11:11:25 +08:00
parent c0870adfa9
commit c621ead859
2 changed files with 48 additions and 46 deletions

View File

@ -14,12 +14,18 @@
package org.adempiere.webui.editor; package org.adempiere.webui.editor;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.adwindow.ADWindow;
import org.adempiere.webui.adwindow.ADWindowContent;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Button;
import org.adempiere.webui.event.DialogEvents;
import org.adempiere.webui.event.ValueChangeEvent; import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.window.WMediaDialog; import org.adempiere.webui.window.WMediaDialog;
import org.compiere.model.GridField; import org.compiere.model.GridField;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
/** /**
@ -34,6 +40,8 @@ public class WBinaryEditor extends WEditor
private boolean m_mandatory; private boolean m_mandatory;
private Object m_data; private Object m_data;
private ADWindow adwindow;
public WBinaryEditor(GridField gridField) public WBinaryEditor(GridField gridField)
{ {
@ -124,20 +132,40 @@ public class WBinaryEditor extends WEditor
{ {
if (Events.ON_CLICK.equals(event.getName())) if (Events.ON_CLICK.equals(event.getName()))
{ {
WMediaDialog dialog = new WMediaDialog(gridField.getHeader(), m_data); final WMediaDialog dialog = new WMediaDialog(gridField.getHeader(), m_data);
if (!dialog.isCancel() && dialog.isChange()) dialog.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener<Event>() {
{
Object oldValue = m_data; @Override
Object newValue = dialog.getData(); public void onEvent(Event event) throws Exception {
if (oldValue != null && newValue != null && oldValue.equals(newValue)) { if (adwindow != null)
return; {
} adwindow.getADWindowContent().hideBusyMask();
if (oldValue == null && newValue == null) { adwindow = null;
return; }
} if (!dialog.isCancel() && dialog.isChange())
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); {
super.fireValueChange(changeEvent); Object oldValue = m_data;
setValue(newValue); Object newValue = dialog.getData();
if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
return;
}
if (oldValue == null && newValue == null) {
return;
}
ValueChangeEvent changeEvent = new ValueChangeEvent(WBinaryEditor.this, getColumnName(), oldValue, newValue);
fireValueChange(changeEvent);
setValue(newValue);
}
}
});
adwindow = ADWindow.findADWindow(getComponent());
if (adwindow != null) {
ADWindowContent content = adwindow.getADWindowContent();
content.showBusyMask();
content.getComponent().getParent().appendChild(dialog);
LayoutUtils.openOverlappedWindow(content.getComponent().getParent(), dialog, "middle_center");
} else {
AEnv.showWindow(dialog);
} }
} }
} }

View File

@ -21,11 +21,10 @@ import java.sql.Clob;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.webui.AdempiereWebUI;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Button; import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.Panel;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.adempiere.webui.component.ZkCssHelper;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
@ -40,7 +39,6 @@ import org.zkoss.zul.Center;
import org.zkoss.zul.North; import org.zkoss.zul.North;
import org.zkoss.zul.South; import org.zkoss.zul.South;
import org.zkoss.zul.Filedownload; import org.zkoss.zul.Filedownload;
import org.zkoss.zul.Fileupload;
import org.zkoss.zul.Hbox; import org.zkoss.zul.Hbox;
import org.zkoss.zul.Iframe; import org.zkoss.zul.Iframe;
@ -102,14 +100,6 @@ public class WMediaDialog extends Window implements EventListener<Event>
catch (Exception ex) catch (Exception ex)
{ {
log.log(Level.SEVERE, "", ex); log.log(Level.SEVERE, "", ex);
}
try
{
AEnv.showWindow(this);
}
catch (Exception e)
{
} }
} // WAttachment } // WAttachment
@ -132,7 +122,7 @@ public class WMediaDialog extends Window implements EventListener<Event>
void staticInit() throws Exception void staticInit() throws Exception
{ {
this.setWidth("500px"); this.setWidth("500px");
this.setHeight("600px"); this.setHeight("500px");
this.setClosable(true); this.setClosable(true);
this.setBorder("normal"); this.setBorder("normal");
this.appendChild(mainPanel); this.appendChild(mainPanel);
@ -159,13 +149,15 @@ public class WMediaDialog extends Window implements EventListener<Event>
bLoad.setImage("/images/Import24.png"); bLoad.setImage("/images/Import24.png");
bLoad.setTooltiptext(Msg.getMsg(Env.getCtx(), "Load")); bLoad.setTooltiptext(Msg.getMsg(Env.getCtx(), "Load"));
bLoad.addEventListener(Events.ON_CLICK, this); bLoad.addEventListener(Events.ON_UPLOAD, this);
bLoad.setUpload("true");
bDelete.setImage("/images/Delete24.png"); bDelete.setImage("/images/Delete24.png");
bDelete.setTooltiptext(Msg.getMsg(Env.getCtx(), "Delete")); bDelete.setTooltiptext(Msg.getMsg(Env.getCtx(), "Delete"));
bDelete.addEventListener(Events.ON_CLICK, this); bDelete.addEventListener(Events.ON_CLICK, this);
previewPanel.appendChild(preview); previewPanel.appendChild(preview);
ZkCssHelper.appendStyle(previewPanel, "margin-top: 10px; margin-bottom: 10px;");
preview.setHeight("100%"); preview.setHeight("100%");
preview.setWidth("100%"); preview.setWidth("100%");
@ -188,9 +180,7 @@ public class WMediaDialog extends Window implements EventListener<Event>
bCancel.addEventListener(Events.ON_CLICK, this); bCancel.addEventListener(Events.ON_CLICK, this);
confirmPanel.appendChild(bOk); confirmPanel.appendChild(bOk);
confirmPanel.appendChild(bCancel); confirmPanel.appendChild(bCancel);
addEventListener(Events.ON_UPLOAD, this);
} }
/** /**
@ -301,11 +291,6 @@ public class WMediaDialog extends Window implements EventListener<Event>
displayData(); displayData();
} }
// Load Attachment
else if (e.getTarget() == bLoad)
loadFile();
// Open Attachment // Open Attachment
else if (e.getTarget() == bSave) else if (e.getTarget() == bSave)
@ -319,17 +304,6 @@ public class WMediaDialog extends Window implements EventListener<Event>
} }
} // onEvent } // onEvent
/**************************************************************************
* Load file
*/
private void loadFile()
{
Media media = Fileupload.get();
if (AdempiereWebUI.isEventThreadEnabled())
processUploadMedia(media);
} // getFileName
private void processUploadMedia(Media media) { private void processUploadMedia(Media media) {
if (media == null) if (media == null)
return; return;