Enhance image field editor.
Added reset button to image editor dialog, handle user cancellation of dialog correctly.
This commit is contained in:
parent
fb02b1955a
commit
3a82aaec93
|
@ -37,10 +37,10 @@ import org.compiere.model.MLookupFactory;
|
||||||
import org.compiere.util.DisplayType;
|
import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.NamePair;
|
import org.compiere.util.NamePair;
|
||||||
import org.zkoss.zk.ui.HtmlBasedComponent;
|
|
||||||
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.EventListener;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
|
import org.zkoss.zul.Image;
|
||||||
import org.zkoss.zul.Listbox;
|
import org.zkoss.zul.Listbox;
|
||||||
import org.zkoss.zul.Listcell;
|
import org.zkoss.zul.Listcell;
|
||||||
import org.zkoss.zul.Listitem;
|
import org.zkoss.zul.Listitem;
|
||||||
|
@ -138,7 +138,7 @@ public class GridTabListItemRenderer implements ListitemRenderer, ListitemRender
|
||||||
editor.addValueChangeListener(dataBinder);
|
editor.addValueChangeListener(dataBinder);
|
||||||
}
|
}
|
||||||
cell.appendChild(editor.getComponent());
|
cell.appendChild(editor.getComponent());
|
||||||
if (editor.getComponent() instanceof Checkbox) {
|
if (editor.getComponent() instanceof Checkbox || editor.getComponent() instanceof Image) {
|
||||||
cell.setStyle("text-align:center");
|
cell.setStyle("text-align:center");
|
||||||
}
|
}
|
||||||
else if (DisplayType.isNumeric(gridField.getDisplayType())) {
|
else if (DisplayType.isNumeric(gridField.getDisplayType())) {
|
||||||
|
@ -155,22 +155,7 @@ public class GridTabListItemRenderer implements ListitemRenderer, ListitemRender
|
||||||
}
|
}
|
||||||
|
|
||||||
//streach component to fill grid cell
|
//streach component to fill grid cell
|
||||||
if (editor.getComponent() instanceof HtmlBasedComponent) {
|
editor.fillHorizontal();
|
||||||
//can't stretch bandbox & datebox
|
|
||||||
if (!(editor.getComponent() instanceof Bandbox) &&
|
|
||||||
!(editor.getComponent() instanceof Datebox)) {
|
|
||||||
String width = "100%";
|
|
||||||
if (editor.getComponent() instanceof Button) {
|
|
||||||
Button btn = (Button) editor.getComponent();
|
|
||||||
String zclass = btn.getZclass();
|
|
||||||
if (!zclass.contains("form-button ")) {
|
|
||||||
btn.setZclass("form-button " + zclass);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
((HtmlBasedComponent)editor.getComponent()).setWidth(width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cell;
|
return cell;
|
||||||
|
|
|
@ -30,9 +30,11 @@ import org.adempiere.webui.event.ValueChangeEvent;
|
||||||
import org.adempiere.webui.event.ValueChangeListener;
|
import org.adempiere.webui.event.ValueChangeListener;
|
||||||
import org.compiere.model.GridField;
|
import org.compiere.model.GridField;
|
||||||
import org.compiere.model.GridTab;
|
import org.compiere.model.GridTab;
|
||||||
|
import org.compiere.util.DisplayType;
|
||||||
import org.zkoss.zk.ui.Component;
|
import org.zkoss.zk.ui.Component;
|
||||||
import org.zkoss.zk.ui.HtmlBasedComponent;
|
import org.zkoss.zk.ui.HtmlBasedComponent;
|
||||||
import org.zkoss.zk.ui.event.EventListener;
|
import org.zkoss.zk.ui.event.EventListener;
|
||||||
|
import org.zkoss.zul.Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -438,9 +440,17 @@ public abstract class WEditor implements EventListener, PropertyChangeListener
|
||||||
if (getComponent() instanceof Button) {
|
if (getComponent() instanceof Button) {
|
||||||
Button btn = (Button) getComponent();
|
Button btn = (Button) getComponent();
|
||||||
String zclass = btn.getZclass();
|
String zclass = btn.getZclass();
|
||||||
if (!zclass.contains("form-button ")) {
|
if (gridField.getDisplayType() == DisplayType.Image) {
|
||||||
|
if (!zclass.contains("image-button-field ")) {
|
||||||
|
btn.setZclass("image-button-field " + zclass);
|
||||||
|
}
|
||||||
|
} else if (!zclass.contains("form-button ")) {
|
||||||
btn.setZclass("form-button " + zclass);
|
btn.setZclass("form-button " + zclass);
|
||||||
}
|
}
|
||||||
|
} else if (getComponent() instanceof Image) {
|
||||||
|
Image image = (Image) getComponent();
|
||||||
|
image.setWidth("48px");
|
||||||
|
image.setHeight("48px");
|
||||||
} else {
|
} else {
|
||||||
((HtmlBasedComponent)getComponent()).setWidth(width);
|
((HtmlBasedComponent)getComponent()).setWidth(width);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,15 +14,18 @@
|
||||||
package org.adempiere.webui.editor;
|
package org.adempiere.webui.editor;
|
||||||
|
|
||||||
|
|
||||||
import org.adempiere.webui.component.Button;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.adempiere.webui.event.ValueChangeEvent;
|
import org.adempiere.webui.event.ValueChangeEvent;
|
||||||
import org.adempiere.webui.window.WImageDialog;
|
import org.adempiere.webui.window.WImageDialog;
|
||||||
import org.compiere.model.GridField;
|
import org.compiere.model.GridField;
|
||||||
import org.compiere.model.MImage;
|
import org.compiere.model.MImage;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
import org.zkoss.image.AImage;
|
||||||
import org.zkoss.zk.ui.event.Event;
|
import org.zkoss.zk.ui.event.Event;
|
||||||
import org.zkoss.zk.ui.event.Events;
|
import org.zkoss.zk.ui.event.Events;
|
||||||
|
import org.zkoss.zul.Image;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is based on org.compiere.grid.ed.VImage written by Jorg Janke.
|
* This class is based on org.compiere.grid.ed.VImage written by Jorg Janke.
|
||||||
|
@ -35,7 +38,8 @@ public class WImageEditor extends WEditor
|
||||||
{
|
{
|
||||||
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
|
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK};
|
||||||
|
|
||||||
private static final CLogger logger;
|
@SuppressWarnings("unused")
|
||||||
|
private static final CLogger logger;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
|
@ -48,24 +52,29 @@ public class WImageEditor extends WEditor
|
||||||
private String m_columnName = "AD_Image_ID";
|
private String m_columnName = "AD_Image_ID";
|
||||||
|
|
||||||
private boolean m_mandatory;
|
private boolean m_mandatory;
|
||||||
|
|
||||||
|
private Object readWrite;
|
||||||
|
|
||||||
|
private boolean readwrite;
|
||||||
|
|
||||||
/** Logger */
|
/** Logger */
|
||||||
private static CLogger log = CLogger.getCLogger(WImageEditor.class);
|
private static CLogger log = CLogger.getCLogger(WImageEditor.class);
|
||||||
|
|
||||||
public WImageEditor(GridField gridField)
|
public WImageEditor(GridField gridField)
|
||||||
{
|
{
|
||||||
super(new Button(), gridField);
|
super(new Image(), gridField);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Button getComponent() {
|
public Image getComponent() {
|
||||||
return (Button) component;
|
return (Image) component;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
getComponent().setLabel("-");
|
AImage img = null;
|
||||||
|
getComponent().setContent(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,12 +106,16 @@ public class WImageEditor extends WEditor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isReadWrite() {
|
public boolean isReadWrite() {
|
||||||
return getComponent().isEnabled();
|
return readwrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReadWrite(boolean readWrite) {
|
public void setReadWrite(boolean readWrite) {
|
||||||
getComponent().setEnabled(readWrite);
|
this.readwrite = readWrite;
|
||||||
|
if (readWrite)
|
||||||
|
getComponent().setStyle("cursor: pointer; border: 1px solid;");
|
||||||
|
else
|
||||||
|
getComponent().setStyle("cursor: default; border: none;");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -114,7 +127,8 @@ public class WImageEditor extends WEditor
|
||||||
if (newValue == 0)
|
if (newValue == 0)
|
||||||
{
|
{
|
||||||
m_mImage = null;
|
m_mImage = null;
|
||||||
getComponent().setLabel("-");
|
AImage img = null;
|
||||||
|
getComponent().setContent(img);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Get/Create Image
|
// Get/Create Image
|
||||||
|
@ -122,9 +136,15 @@ public class WImageEditor extends WEditor
|
||||||
m_mImage = MImage.get (Env.getCtx(), newValue);
|
m_mImage = MImage.get (Env.getCtx(), newValue);
|
||||||
//
|
//
|
||||||
log.fine(m_mImage.toString());
|
log.fine(m_mImage.toString());
|
||||||
getComponent().setLabel(m_mImage.getName());
|
AImage img = null;
|
||||||
if (m_mImage.getDescription() != null)
|
byte[] data = m_mImage.getData();
|
||||||
getComponent().setTooltiptext(m_mImage.getDescription());
|
if (data != null && data.length > 0) {
|
||||||
|
try {
|
||||||
|
img = new AImage(null, data);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(Level.WARNING, e.getLocalizedMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -135,20 +155,22 @@ public class WImageEditor extends WEditor
|
||||||
|
|
||||||
public void onEvent(Event event) throws Exception
|
public void onEvent(Event event) throws Exception
|
||||||
{
|
{
|
||||||
if (Events.ON_CLICK.equals(event.getName()))
|
if (Events.ON_CLICK.equals(event.getName()) && readwrite)
|
||||||
{
|
{
|
||||||
WImageDialog vid = new WImageDialog(m_mImage);
|
WImageDialog vid = new WImageDialog(m_mImage);
|
||||||
int AD_Image_ID = vid.getAD_Image_ID();
|
if (!vid.isCancel()) {
|
||||||
Object oldValue = getValue();
|
int AD_Image_ID = vid.getAD_Image_ID();
|
||||||
Integer newValue = null;
|
Object oldValue = getValue();
|
||||||
if (AD_Image_ID != 0)
|
Integer newValue = null;
|
||||||
newValue = new Integer (AD_Image_ID);
|
if (AD_Image_ID != 0)
|
||||||
//
|
newValue = new Integer (AD_Image_ID);
|
||||||
m_mImage = null; // force reload
|
//
|
||||||
setValue(newValue); // set explicitly
|
m_mImage = null; // force reload
|
||||||
//
|
setValue(newValue); // set explicitly
|
||||||
ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), oldValue, newValue);
|
//
|
||||||
fireValueChange(vce);
|
ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), oldValue, newValue);
|
||||||
|
fireValueChange(vce);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,8 @@ public class WImageDialog extends Window implements EventListener
|
||||||
private Label fileLabel = new Label();
|
private Label fileLabel = new Label();
|
||||||
private Button fileButton = new Button();
|
private Button fileButton = new Button();
|
||||||
private Image image = new Image();
|
private Image image = new Image();
|
||||||
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
|
private ConfirmPanel confirmPanel = new ConfirmPanel(true,false,true,false,false,false);
|
||||||
|
private boolean cancel = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static Init
|
* Static Init
|
||||||
|
@ -147,18 +148,31 @@ public class WImageDialog extends Window implements EventListener
|
||||||
if (e.getTarget() == fileButton)
|
if (e.getTarget() == fileButton)
|
||||||
cmd_file();
|
cmd_file();
|
||||||
|
|
||||||
else if (e.getTarget().getId().equals("Ok"))
|
else if (e.getTarget().getId().equals(ConfirmPanel.A_OK))
|
||||||
{
|
{
|
||||||
if (m_mImage.save())
|
if (m_mImage.save())
|
||||||
detach();
|
detach();
|
||||||
else
|
else
|
||||||
FDialog.error(-1, "Failed to save image");
|
FDialog.error(-1, "Failed to save image");
|
||||||
}
|
}
|
||||||
else if (e.getTarget().getId().equals("Cancel"))
|
else if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
|
||||||
{
|
{
|
||||||
m_mImage = null; // reset
|
cancel = true;
|
||||||
detach();
|
detach();
|
||||||
}
|
}
|
||||||
|
else if (e.getTarget().getId().equals(ConfirmPanel.A_RESET))
|
||||||
|
{
|
||||||
|
m_mImage = null;
|
||||||
|
AImage img = null;
|
||||||
|
image.setContent(img);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if dialog cancel by user
|
||||||
|
*/
|
||||||
|
public boolean isCancel() {
|
||||||
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue