* Added mandatory field indicator.

This commit is contained in:
Heng Sin Low 2008-07-21 09:50:59 +00:00
parent 50aa38f16f
commit ec4a6734e1
25 changed files with 360 additions and 252 deletions

View File

@ -31,4 +31,9 @@ public class Bandbox extends org.zkoss.zul.Bandbox
{ {
this.setDisabled(!enabled); this.setDisabled(!enabled);
} }
public boolean isEnabled()
{
return !isDisabled();
}
} }

View File

@ -31,4 +31,9 @@ public class Checkbox extends org.zkoss.zul.Checkbox
{ {
this.setDisabled(!enabled); this.setDisabled(!enabled);
} }
public boolean isEnabled()
{
return !this.isDisabled();
}
} }

View File

@ -31,4 +31,9 @@ public class Datebox extends org.zkoss.zul.Datebox
{ {
this.setReadonly(!enabled); this.setReadonly(!enabled);
} }
public boolean isEnabled()
{
return !isReadonly();
}
} }

View File

@ -74,6 +74,11 @@ public class FilenameBox extends Hbox
button.setEnabled(enabled); button.setEnabled(enabled);
} }
public boolean isEnabled()
{
return !textbox.isReadonly();
}
public void setButtonEnabled(boolean enabled) public void setButtonEnabled(boolean enabled)
{ {
button.setEnabled(enabled); button.setEnabled(enabled);

View File

@ -17,6 +17,8 @@
package org.adempiere.webui.component; package org.adempiere.webui.component;
import org.zkoss.zk.ui.Component;
/** /**
* *
* @author <a href="mailto:agramdass@gmail.com">Ashley G Ramdass</a> * @author <a href="mailto:agramdass@gmail.com">Ashley G Ramdass</a>
@ -26,6 +28,10 @@ package org.adempiere.webui.component;
public class Label extends org.zkoss.zul.Label public class Label extends org.zkoss.zul.Label
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Component decorator;
private boolean mandatory;
public Label() public Label()
{ {
@ -36,4 +42,44 @@ public class Label extends org.zkoss.zul.Label
{ {
super(value); super(value);
} }
public boolean isMandatory() {
return mandatory;
}
public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
setupMandatoryDecorator();
}
public Component getDecorator() {
return decorator;
}
@Override
public void setValue(String value) {
super.setValue(value);
setupMandatoryDecorator();
}
@Override
public boolean setVisible(boolean visible) {
if (decorator != null) {
if (visible)
decorator.setVisible(getValue() != null && getValue().trim().length() > 0 && mandatory);
else
decorator.setVisible(false);
}
return super.setVisible(visible);
}
private void setupMandatoryDecorator() {
String value = getValue();
if (value != null && (value.trim().length() > 0) && mandatory) {
if (decorator == null)
decorator = new Label("*");
((Label)decorator).setStyle("text-decoration: none; font-size: xx-small; vertical-align: top;");
} else if (decorator != null)
decorator.setVisible(false);
}
} }

View File

@ -97,14 +97,4 @@ public class Searchbox extends Hbox
{ {
m_propertyChangeListeners.addPropertyChangeListener(l); m_propertyChangeListeners.addPropertyChangeListener(l);
} }
/**
* Set whether the SearchBox represents a mandatory field.
*
* @param mandatory whether the search box must be filled
*/
public void setMandatory(boolean mandatory)
{
txt.setMandatory(mandatory);
}
} }

View File

@ -18,6 +18,8 @@
package org.adempiere.webui.component; package org.adempiere.webui.component;
import org.zkoss.zk.ui.WrongValueException; import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zul.Constraint;
import org.zkoss.zul.SimpleConstraint;
/** /**
* *
@ -44,19 +46,4 @@ public class Textbox extends org.zkoss.zul.Textbox
{ {
this.setDisabled(!enabled); this.setDisabled(!enabled);
} }
/**
* Set whether the textbox represents a mandatory field.
*
* @param mandatory whether the texbox must be filled
*/
public void setMandatory(boolean mandatory)
{
/* if (mandatory)
{
ZkCssHelper.setStyleBackgroundColor(this, AdempierePLAF.getFieldBackground_Mandatory());
}
*/
this.setStyle("background-color:#e1d6d6");
}
} }

View File

@ -74,6 +74,11 @@ public class Urlbox extends Hbox
btnUrl.setEnabled(enabled); btnUrl.setEnabled(enabled);
} }
public boolean isEnabled()
{
return !txtUrl.isReadonly();
}
public void setButtonEnabled(boolean enabled) public void setButtonEnabled(boolean enabled)
{ {
btnUrl.setEnabled(enabled); btnUrl.setEnabled(enabled);

View File

@ -1,5 +1,22 @@
/******************************************************************************
* Copyright (C) 2008 Low Heng Sin All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
*****************************************************************************/
package org.adempiere.webui.editor; package org.adempiere.webui.editor;
/**
*
* @author Low Heng Sin
*
*/
public interface IZoomableEditor { public interface IZoomableEditor {
public void actionZoom(); public void actionZoom();

View File

@ -9,9 +9,6 @@
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* Posterita Ltd., 3, Draper Avenue, Quatre Bornes, Mauritius *
* or via info@posterita.org or http://www.posterita.org/ *
*****************************************************************************/ *****************************************************************************/
package org.adempiere.webui.editor; package org.adempiere.webui.editor;
@ -83,6 +80,16 @@ public class WBinaryEditor extends WEditor
} }
@Override @Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
@Override
public void setValue(Object value) public void setValue(Object value)
{ {
log.config("=" + value); log.config("=" + value);

View File

@ -57,8 +57,6 @@ public class WButtonEditor extends WEditor
logger = CLogger.getCLogger(WButtonEditor.class); logger = CLogger.getCLogger(WButtonEditor.class);
} }
private Button button;
private String m_text; private String m_text;
private boolean m_mandatory; private boolean m_mandatory;
private Object m_value; private Object m_value;
@ -77,7 +75,6 @@ public class WButtonEditor extends WEditor
public WButtonEditor(GridField gridField) public WButtonEditor(GridField gridField)
{ {
super(new Button(), gridField); super(new Button(), gridField);
button = (Button)super.component;
m_text = gridField.getHeader(); m_text = gridField.getHeader();
AD_Process_ID = gridField.getAD_Process_ID(); AD_Process_ID = gridField.getAD_Process_ID();
gridfield = gridField; gridfield = gridField;
@ -101,37 +98,37 @@ public class WButtonEditor extends WEditor
private void init() private void init()
{ {
label.setValue(" "); label.setValue(" ");
button.setLabel(gridField.getHeader()); getComponent().setLabel(gridField.getHeader());
button.setTooltiptext(gridField.getDescription()); getComponent().setTooltiptext(gridField.getDescription());
button.addEventListener(Events.ON_CLICK, this); getComponent().addEventListener(Events.ON_CLICK, this);
String columnName = super.getColumnName(); String columnName = super.getColumnName();
if (columnName.equals("PaymentRule")) if (columnName.equals("PaymentRule"))
{ {
readReference(195); readReference(195);
// this.setForeground(Color.blue); // this.setForeground(Color.blue);
button.setImage("/images/Payment16.gif"); // 29*14 getComponent().setImage("/images/Payment16.gif"); // 29*14
} }
else if (columnName.equals("DocAction")) else if (columnName.equals("DocAction"))
{ {
readReference(135); readReference(135);
// this.setForeground(Color.blue); // this.setForeground(Color.blue);
button.setImage("/images/Process16.gif"); // 16*16 getComponent().setImage("/images/Process16.gif"); // 16*16
} }
else if (columnName.equals("CreateFrom")) else if (columnName.equals("CreateFrom"))
{ {
button.setImage("/images/Copy16.gif"); // 16*16 getComponent().setImage("/images/Copy16.gif"); // 16*16
} }
else if (columnName.equals("Record_ID")) else if (columnName.equals("Record_ID"))
{ {
button.setImage("/images/Zoom16.gif"); // 16*16 getComponent().setImage("/images/Zoom16.gif"); // 16*16
button.setLabel(Msg.getMsg(Env.getCtx(), "ZoomDocument")); getComponent().setLabel(Msg.getMsg(Env.getCtx(), "ZoomDocument"));
} }
else if (columnName.equals("Posted")) else if (columnName.equals("Posted"))
{ {
readReference(234); readReference(234);
// this.setForeground(Color.magenta); // this.setForeground(Color.magenta);
button.setImage("/images/InfoAccount16.gif"); // 16*16 getComponent().setImage("/images/InfoAccount16.gif"); // 16*16
} }
if (gridField.getColumnName().endsWith("_ID") && !gridField.getColumnName().equals("Record_ID")) if (gridField.getColumnName().endsWith("_ID") && !gridField.getColumnName().equals("Record_ID"))
@ -193,10 +190,25 @@ public class WButtonEditor extends WEditor
if (pp != null) if (pp != null)
text = pp.getName(); text = pp.getName();
} }
button.setLabel(text != null ? text : ""); getComponent().setLabel(text != null ? text : "");
} }
public HashMap getValues() @Override
public Button getComponent() {
return (Button) component;
}
@Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
public HashMap getValues()
{ {
return m_values; return m_values;
} // getValues } // getValues

View File

@ -46,12 +46,9 @@ public class WDateEditor extends WEditor
private Timestamp oldValue = new Timestamp(0); private Timestamp oldValue = new Timestamp(0);
private Datebox datebox;
public WDateEditor(GridField gridField) public WDateEditor(GridField gridField)
{ {
super(new Datebox(), gridField); super(new Datebox(), gridField);
datebox = (Datebox)super.component;
} }
@ -73,7 +70,6 @@ public class WDateEditor extends WEditor
{ {
super(new Datebox(), label, description, mandatory, readonly, updateable); super(new Datebox(), label, description, mandatory, readonly, updateable);
this.datebox = (Datebox)super.component;
setColumnName("Date"); setColumnName("Date");
} }
@ -84,7 +80,7 @@ public class WDateEditor extends WEditor
public void onEvent(Event event) public void onEvent(Event event)
{ {
Date date = datebox.getValue(); Date date = getComponent().getValue();
Timestamp newValue = null; Timestamp newValue = null;
if (date != null) if (date != null)
@ -129,7 +125,7 @@ public class WDateEditor extends WEditor
} }
else if (value instanceof Timestamp) else if (value instanceof Timestamp)
{ {
datebox.setValue((Timestamp)value); getComponent().setValue((Timestamp)value);
oldValue = (Timestamp)value; oldValue = (Timestamp)value;
} }
else else
@ -137,7 +133,23 @@ public class WDateEditor extends WEditor
logger.log(Level.SEVERE, "New field value is not of type timestamp"); logger.log(Level.SEVERE, "New field value is not of type timestamp");
} }
} }
@Override
public Datebox getComponent() {
return (Datebox) component;
}
@Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
public String[] getEvents() public String[] getEvents()
{ {
return LISTENER_EVENTS; return LISTENER_EVENTS;

View File

@ -22,15 +22,7 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.ArrayList; import java.util.ArrayList;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.Datebox;
import org.adempiere.webui.component.EditorBox;
import org.adempiere.webui.component.Label; import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.Locationbox;
import org.adempiere.webui.component.Searchbox;
import org.adempiere.webui.component.Urlbox;
import org.adempiere.webui.event.ValueChangeEvent; 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;
@ -38,7 +30,6 @@ import org.compiere.model.GridTab;
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.impl.InputElement;
/** /**
* *
@ -257,77 +248,9 @@ public abstract class WEditor implements EventListener, PropertyChangeListener
return label; return label;
} }
public void setReadWrite(boolean readWrite) public abstract void setReadWrite(boolean readWrite);
{
if (component instanceof Checkbox)
{
((Checkbox)component).setEnabled(readWrite);
}
else if (component instanceof Button)
{
((Button)component).setEnabled(readWrite);
}
else if (component instanceof Listbox)
{
((Listbox)component).setEnabled(readWrite);
}
else if (component instanceof Datebox)
{
((Datebox)component).setEnabled(readWrite);
}
else if (component instanceof Urlbox)
{
((Urlbox)component).setEnabled(readWrite);
}
else if (component instanceof Searchbox)
{
((Searchbox)component).setEnabled(readWrite);
}
else if (component instanceof Locationbox)
{
((Locationbox)component).setEnabled(readWrite);
}
else if (component instanceof EditorBox)
{
((EditorBox)component).setEnabled(readWrite);
}
else
{
((InputElement)component).setReadonly(!readWrite);
}
}
public boolean isReadWrite() public abstract boolean isReadWrite();
{
if (component instanceof Checkbox)
{
return ((Checkbox)component).isDisabled();
}
else if (component instanceof Button)
{
return ((Button)component).isEnabled();
}
else if (component instanceof Listbox)
{
return ((Listbox)component).isEnabled();
}
else if (component instanceof Searchbox)
{
return ((Searchbox)component).isEnabled();
}
else if (component instanceof Locationbox)
{
return ((Locationbox)component).isEnabled();
}
else if (component instanceof EditorBox)
{
return ((EditorBox)component).isEnabled();
}
else
{
return ((InputElement)component).isReadonly();
}
}
public void setVisible(boolean visible) public void setVisible(boolean visible)
{ {
@ -378,6 +301,8 @@ public abstract class WEditor implements EventListener, PropertyChangeListener
public void setMandatory (boolean mandatory) public void setMandatory (boolean mandatory)
{ {
this.mandatory = mandatory; this.mandatory = mandatory;
if (label != null)
label.setMandatory(mandatory);
} }
public boolean isMandatory() public boolean isMandatory()

View File

@ -9,9 +9,6 @@
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* Posterita Ltd., 3, Draper Avenue, Quatre Bornes, Mauritius *
* or via info@posterita.org or http://www.posterita.org/ *
*****************************************************************************/ *****************************************************************************/
package org.adempiere.webui.editor; package org.adempiere.webui.editor;
@ -80,6 +77,16 @@ public class WFilenameEditor extends WEditor
return getComponent().getText(); return getComponent().getText();
} }
@Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
public void onEvent(Event event) public void onEvent(Event event)
{ {
if (Events.ON_CHANGE.equals(event.getName())) if (Events.ON_CHANGE.equals(event.getName()))

View File

@ -9,9 +9,6 @@
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* Posterita Ltd., 3, Draper Avenue, Quatre Bornes, Mauritius *
* or via info@posterita.org or http://www.posterita.org/ *
*****************************************************************************/ *****************************************************************************/
package org.adempiere.webui.editor; package org.adempiere.webui.editor;
@ -98,8 +95,18 @@ public class WImageEditor extends WEditor
{ {
m_mandatory = mandatory; m_mandatory = mandatory;
} }
@Override @Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
@Override
public void setValue(Object value) public void setValue(Object value)
{ {
int newValue = 0; int newValue = 0;

View File

@ -44,7 +44,6 @@ public class WLocationEditor extends WEditor implements EventListener, PropertyC
private static CLogger log = CLogger.getCLogger(WLocationEditor.class); private static CLogger log = CLogger.getCLogger(WLocationEditor.class);
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Locationbox locationbox;
private String m_columnName; private String m_columnName;
private MLocationLookup m_Location; private MLocationLookup m_Location;
private MLocation m_value; private MLocation m_value;
@ -64,14 +63,13 @@ public class WLocationEditor extends WEditor implements EventListener, PropertyC
m_columnName = columnName; m_columnName = columnName;
m_Location = mLocation; m_Location = mLocation;
locationbox = (Locationbox)super.component; getComponent().setButtonImage("/images/Location10.gif");
locationbox.setButtonImage("/images/Location10.gif");
} }
@Override @Override
public String getDisplay() public String getDisplay()
{ {
return locationbox.getText(); return getComponent().getText();
} }
@Override @Override
@ -88,19 +86,34 @@ public class WLocationEditor extends WEditor implements EventListener, PropertyC
if (value == null) if (value == null)
{ {
m_value = null; m_value = null;
locationbox.setText(null); getComponent().setText(null);
} }
else else
{ {
m_value = m_Location.getLocation(value, null); m_value = m_Location.getLocation(value, null);
if (m_value == null) if (m_value == null)
locationbox.setText("<" + value + ">"); getComponent().setText("<" + value + ">");
else else
locationbox.setText(m_value.toString()); getComponent().setText(m_value.toString());
} }
} }
@Override
public Locationbox getComponent() {
return (Locationbox) component;
}
/** @Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
/**
* Return Editor value * Return Editor value
* @return value * @return value
*/ */

View File

@ -53,7 +53,6 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh
private String m_columnName; private String m_columnName;
private MLocatorLookup m_mLocator; private MLocatorLookup m_mLocator;
private EditorBox editorbox;
private MLocator m_value; private MLocator m_value;
private int m_WindowNo; private int m_WindowNo;
@ -85,8 +84,7 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh
m_columnName = columnName; m_columnName = columnName;
m_mLocator = mLocator; m_mLocator = mLocator;
editorbox = (EditorBox)super.component; getComponent().setButtonImage("/images/Locator10.gif");
editorbox.setButtonImage("/images/Locator10.gif");
setDefault_Locator_ID(); // set default locator, teo_sarca [ 1661546 ] setDefault_Locator_ID(); // set default locator, teo_sarca [ 1661546 ]
} }
@ -114,7 +112,7 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh
} }
m_value = m_mLocator.getMLocator(value, null); m_value = m_mLocator.getMLocator(value, null);
editorbox.setText(m_mLocator.getDisplay(value)); // loads value getComponent().setText(m_mLocator.getDisplay(value)); // loads value
// Data Binding // Data Binding
if (fire) { if (fire) {
@ -137,6 +135,21 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh
return m_value; return m_value;
} // getValue } // getValue
@Override
public EditorBox getComponent() {
return (EditorBox) component;
}
@Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
/** /**
* Get M_Locator_ID * Get M_Locator_ID
* @return id * @return id
@ -157,7 +170,7 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh
public String getDisplay() public String getDisplay()
{ {
return editorbox.getText(); return getComponent().getText();
} // getDisplay } // getDisplay
public void onEvent(Event event) throws Exception public void onEvent(Event event) throws Exception
@ -171,7 +184,7 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh
// Text Entry ok // Text Entry ok
if (event.getTarget() == editorbox && actionText(only_Warehouse_ID, only_Product_ID)) if (event.getTarget() == getComponent() && actionText(only_Warehouse_ID, only_Product_ID))
return; return;
// Button - Start Dialog // Button - Start Dialog
@ -210,7 +223,7 @@ public class WLocatorEditor extends WEditor implements EventListener, PropertyCh
private boolean actionText(int only_Warehouse_ID, int only_Product_ID) private boolean actionText(int only_Warehouse_ID, int only_Product_ID)
{ {
String text = editorbox.getText(); String text = getComponent().getText();
log.fine(text); log.fine(text);
// Null // Null

View File

@ -39,8 +39,6 @@ public class WNumberEditor extends WEditor
public static final int MAX_DISPLAY_LENGTH = 20; public static final int MAX_DISPLAY_LENGTH = 20;
private NumberBox comp;
private String oldValue; private String oldValue;
private boolean mandatory = false; private boolean mandatory = false;
@ -49,42 +47,55 @@ public class WNumberEditor extends WEditor
{ {
super(new NumberBox(gridField.getDisplayType() == DisplayType.Integer), super(new NumberBox(gridField.getDisplayType() == DisplayType.Integer),
gridField); gridField);
comp = (NumberBox)super.component;
init(); init();
} }
public WNumberEditor(GridField gridField, boolean integral) public WNumberEditor(GridField gridField, boolean integral)
{ {
super(new NumberBox(integral), gridField); super(new NumberBox(integral), gridField);
comp = (NumberBox)super.component;
init(); init();
} }
private void init() private void init()
{ {
comp.setMaxlength(gridField.getFieldLength()); getComponent().setMaxlength(gridField.getFieldLength());
comp.setCols(MAX_DISPLAY_LENGTH); getComponent().setCols(MAX_DISPLAY_LENGTH);
comp.setTooltiptext(gridField.getDescription()); getComponent().setTooltiptext(gridField.getDescription());
} }
public void onEvent(Event event) public void onEvent(Event event)
{ {
String newValue = comp.getValue(); String newValue = getComponent().getValue();
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue); ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue);
super.fireValueChange(changeEvent); super.fireValueChange(changeEvent);
oldValue = newValue; oldValue = newValue;
} }
@Override @Override
public NumberBox getComponent() {
return (NumberBox) component;
}
@Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
@Override
public String getDisplay() public String getDisplay()
{ {
return comp.getValue(); return getComponent().getValue();
} }
@Override @Override
public Object getValue() public Object getValue()
{ {
return comp.getValue(); return getComponent().getValue();
} }
@Override @Override
@ -104,11 +115,11 @@ public class WNumberEditor extends WEditor
{ {
if (value != null) if (value != null)
{ {
comp.setValue(value.toString()); getComponent().setValue(value.toString());
} }
else else
{ {
comp.setValue("0"); getComponent().setValue("0");
} }
} }

View File

@ -9,9 +9,6 @@
* You should have received a copy of the GNU General Public License along * * You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., * * with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* Posterita Ltd., 3, Draper Avenue, Quatre Bornes, Mauritius *
* or via info@posterita.org or http://www.posterita.org/ *
*****************************************************************************/ *****************************************************************************/
package org.adempiere.webui.editor; package org.adempiere.webui.editor;

View File

@ -42,7 +42,6 @@ import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.zkoss.zk.ui.Component;
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;
@ -56,7 +55,6 @@ import org.zkoss.zk.ui.event.Events;
public class WSearchEditor extends WEditor implements ContextMenuListener, ValueChangeListener, IZoomableEditor public class WSearchEditor extends WEditor implements ContextMenuListener, ValueChangeListener, IZoomableEditor
{ {
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE}; private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
private Searchbox searchbox;
private Lookup lookup; private Lookup lookup;
private String m_tableName = null; private String m_tableName = null;
private String m_keyColumnName = null; private String m_keyColumnName = null;
@ -78,23 +76,23 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
init(); init();
} }
/**
* Set the underlying component. @Override
* public Searchbox getComponent() {
* @param comp the component to use return (Searchbox) super.getComponent();
*/ }
protected void setComponent(Component comp)
{ @Override
// TODO remove this duplication of components. public boolean isReadWrite() {
// Only need component from WEditor (superclass) return getComponent().isEnabled();
// and can then override get component and cast it to Searchbox }
if (!(comp instanceof Searchbox))
{
throw new IllegalArgumentException("A search editor must contain a Searchbox"); @Override
} public void setReadWrite(boolean readWrite) {
super.setComponent(comp); getComponent().setEnabled(readWrite);
this.searchbox = (Searchbox)super.component; }
}
/** /**
* Constructor for use if a grid field is unavailable * Constructor for use if a grid field is unavailable
@ -131,19 +129,19 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
columnName = this.getColumnName(); columnName = this.getColumnName();
popupMenu = new WEditorPopupMenu(true, true, true, true); popupMenu = new WEditorPopupMenu(true, true, true, true);
(searchbox.getTextBox()).setContext(popupMenu.getId()); (getComponent().getTextBox()).setContext(popupMenu.getId());
if (columnName.equals("C_BPartner_ID")) if (columnName.equals("C_BPartner_ID"))
{ {
searchbox.setButtonImage("/images/BPartner10.gif"); getComponent().setButtonImage("/images/BPartner10.gif");
} }
else if (columnName.equals("M_Product_ID")) else if (columnName.equals("M_Product_ID"))
{ {
searchbox.setButtonImage("/images/Product10.gif"); getComponent().setButtonImage("/images/Product10.gif");
} }
else else
{ {
searchbox.setButtonImage("/images/PickOpen10.gif"); getComponent().setButtonImage("/images/PickOpen10.gif");
} }
return; return;
@ -167,25 +165,14 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
text = text.substring(1); text = text.substring(1);
} }
searchbox.setText(text); getComponent().setText(text);
} }
else else
{ {
searchbox.setText(""); getComponent().setText("");
} }
} }
/**
* Set whether the editor represents a mandatory field.
*
* @param mandatory whether the editor must be filled
*/
public void setMandatory(boolean mandatory)
{
searchbox.setMandatory(mandatory);
super.setMandatory(mandatory);
}
@Override @Override
public Object getValue() public Object getValue()
{ {
@ -195,14 +182,14 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
@Override @Override
public String getDisplay() public String getDisplay()
{ {
return searchbox.getText(); return getComponent().getText();
} }
public void onEvent(Event e) public void onEvent(Event e)
{ {
if ("onChange".equals(e.getName())) if ("onChange".equals(e.getName()))
{ {
actionText(searchbox.getText()); actionText(getComponent().getText());
} }
else if ("onClick".equals(e.getName())) else if ("onClick".equals(e.getName()))
@ -345,7 +332,7 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
log.fine(getColumnName() + " - Not Unique - " + finalSQL); log.fine(getColumnName() + " - Not Unique - " + finalSQL);
//m_value = null; // force re-display //m_value = null; // force re-display
actionButton(searchbox.getText()); actionButton(getComponent().getText());
return; return;
} }
log.fine(getColumnName() + " - Unique ID=" + id); log.fine(getColumnName() + " - Unique ID=" + id);
@ -454,8 +441,8 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
Env.setContext(Env.getCtx(), lookup.getWindowNo(), Env.TAB_INFO, "M_Lookup_ID", "0"); Env.setContext(Env.getCtx(), lookup.getWindowNo(), Env.TAB_INFO, "M_Lookup_ID", "0");
// Replace Value with name if no value exists // Replace Value with name if no value exists
if (queryValue.length() == 0 && searchbox.getText().length() > 0) if (queryValue.length() == 0 && getComponent().getText().length() > 0)
queryValue = "@" + searchbox.getText() + "@"; // Name indicator - otherwise Value queryValue = "@" + getComponent().getText() + "@"; // Name indicator - otherwise Value
int M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), lookup.getWindowNo(), "M_Warehouse_ID"); int M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), lookup.getWindowNo(), "M_Warehouse_ID");
int M_PriceList_ID = Env.getContextAsInt(Env.getCtx(), lookup.getWindowNo(), "M_PriceList_ID"); int M_PriceList_ID = Env.getContextAsInt(Env.getCtx(), lookup.getWindowNo(), "M_PriceList_ID");
@ -475,8 +462,8 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
else if (col.equals("C_BPartner_ID")) else if (col.equals("C_BPartner_ID"))
{ {
// Replace Value with name if no value exists // Replace Value with name if no value exists
if (queryValue.length() == 0 && searchbox.getText().length() > 0) if (queryValue.length() == 0 && getComponent().getText().length() > 0)
queryValue = searchbox.getText(); queryValue = getComponent().getText();
boolean isSOTrx = true; // default boolean isSOTrx = true; // default
@ -503,8 +490,8 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Value
if (m_tableName == null) // sets table name & key column if (m_tableName == null) // sets table name & key column
getDirectAccessSQL("*"); getDirectAccessSQL("*");
if (queryValue.length() == 0 && searchbox.getText().length() > 0) if (queryValue.length() == 0 && getComponent().getText().length() > 0)
queryValue = searchbox.getText(); queryValue = getComponent().getText();
boolean isSOTrx = true; // default boolean isSOTrx = true; // default

View File

@ -54,8 +54,18 @@ public class WStringEditor extends WEditor implements ContextMenuListener
public Textbox getComponent() { public Textbox getComponent() {
return (Textbox) component; return (Textbox) component;
} }
private void init() @Override
public boolean isReadWrite() {
return !getComponent().isReadonly();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setReadonly(!readWrite);
}
private void init()
{ {
getComponent().setMaxlength(gridField.getFieldLength()); getComponent().setMaxlength(gridField.getFieldLength());
int displayLength = gridField.getDisplayLength(); int displayLength = gridField.getDisplayLength();

View File

@ -59,14 +59,12 @@ ContextMenuListener, IZoomableEditor
} }
private Lookup lookup; private Lookup lookup;
private Listbox listbox;
private Object oldValue; private Object oldValue;
private WEditorPopupMenu popupMenu; private WEditorPopupMenu popupMenu;
public WTableDirEditor(GridField gridField) public WTableDirEditor(GridField gridField)
{ {
super(new Listbox(), gridField); super(new Listbox(), gridField);
listbox = (Listbox)super.component;
lookup = gridField.getLookup(); lookup = gridField.getLookup();
init(); init();
} }
@ -90,7 +88,6 @@ ContextMenuListener, IZoomableEditor
throw new IllegalArgumentException("Lookup cannot be null"); throw new IllegalArgumentException("Lookup cannot be null");
} }
this.listbox = (Listbox)super.component;
this.lookup = lookup; this.lookup = lookup;
super.setColumnName(lookup.getColumnName()); super.setColumnName(lookup.getColumnName());
init(); init();
@ -98,11 +95,11 @@ ContextMenuListener, IZoomableEditor
private void init() private void init()
{ {
listbox.setRows(0); getComponent().setRows(0);
listbox.setMultiple(false); getComponent().setMultiple(false);
listbox.setMold("select"); getComponent().setMold("select");
listbox.setWidth("200px"); getComponent().setWidth("200px");
listbox.addPropertyChangeListener(this); getComponent().addPropertyChangeListener(this);
boolean zoom= false; boolean zoom= false;
if (lookup != null) if (lookup != null)
@ -119,7 +116,7 @@ ContextMenuListener, IZoomableEditor
} }
popupMenu = new WEditorPopupMenu(zoom, true, true); popupMenu = new WEditorPopupMenu(zoom, true, true);
listbox.setContext(popupMenu.getId()); getComponent().setContext(popupMenu.getId());
} }
@Override @Override
@ -127,7 +124,7 @@ ContextMenuListener, IZoomableEditor
{ {
String display = null; String display = null;
ListItem selItem = listbox.getSelectedItem(); ListItem selItem = getComponent().getSelectedItem();
if (selItem != null) if (selItem != null)
{ {
display = selItem.getLabel(); display = selItem.getLabel();
@ -139,7 +136,7 @@ ContextMenuListener, IZoomableEditor
public Object getValue() public Object getValue()
{ {
Object retVal = null; Object retVal = null;
ListItem selItem = listbox.getSelectedItem(); ListItem selItem = getComponent().getSelectedItem();
if (selItem != null) if (selItem != null)
{ {
retVal = selItem.getValue(); retVal = selItem.getValue();
@ -151,9 +148,9 @@ ContextMenuListener, IZoomableEditor
{ {
if (value != null && (value instanceof Integer || value instanceof String)) if (value != null && (value instanceof Integer || value instanceof String))
{ {
listbox.setValue(value); getComponent().setValue(value);
if (listbox.getSelectedIndex() == -1 && lookup != null) if (getComponent().getSelectedIndex() == -1 && lookup != null)
{ {
lookup.refresh(); lookup.refresh();
oldValue = value; oldValue = value;
@ -162,16 +159,31 @@ ContextMenuListener, IZoomableEditor
} }
else else
{ {
listbox.setValue(null); getComponent().setValue(null);
} }
oldValue = value; oldValue = value;
} }
private void refreshList() @Override
public Listbox getComponent() {
return (Listbox) component;
}
@Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
private void refreshList()
{ {
if (listbox.getItemCount() > 0) if (getComponent().getItemCount() > 0)
listbox.getItems().clear(); getComponent().getItems().clear();
if (lookup != null) if (lookup != null)
{ {
@ -183,17 +195,17 @@ ContextMenuListener, IZoomableEditor
if (obj instanceof KeyNamePair) if (obj instanceof KeyNamePair)
{ {
KeyNamePair lookupKNPair = (KeyNamePair) obj; KeyNamePair lookupKNPair = (KeyNamePair) obj;
listbox.appendItem(lookupKNPair.getName(), lookupKNPair.getKey()); getComponent().appendItem(lookupKNPair.getName(), lookupKNPair.getKey());
} }
else if (obj instanceof ValueNamePair) else if (obj instanceof ValueNamePair)
{ {
ValueNamePair lookupKNPair = (ValueNamePair) obj; ValueNamePair lookupKNPair = (ValueNamePair) obj;
listbox.appendItem(lookupKNPair.getName(), lookupKNPair.getValue()); getComponent().appendItem(lookupKNPair.getName(), lookupKNPair.getValue());
} }
} }
} }
listbox.setValue(oldValue); getComponent().setValue(oldValue);
} }
public void onEvent(Event event) public void onEvent(Event event)

View File

@ -31,13 +31,10 @@ public class WUrlEditor extends WEditor
{ {
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE}; private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
private Urlbox urlbox;
public WUrlEditor(GridField gridField) public WUrlEditor(GridField gridField)
{ {
super(new Urlbox(), gridField); super(new Urlbox(), gridField);
this.urlbox = (Urlbox)super.component; getComponent().setButtonImage("/images/Online16.gif");
urlbox.setButtonImage("/images/Online16.gif");
} }
@ -46,36 +43,54 @@ public class WUrlEditor extends WEditor
{ {
if (value == null) if (value == null)
{ {
urlbox.setText(""); getComponent().setText("");
} }
else else
{ {
urlbox.setText(String.valueOf(value)); getComponent().setText(String.valueOf(value));
} }
} }
@Override @Override
public Object getValue() public Object getValue()
{ {
return urlbox.getText(); return getComponent().getText();
} }
@Override @Override
public String getDisplay() public String getDisplay()
{ {
return urlbox.getText(); return getComponent().getText();
} }
@Override
public Urlbox getComponent() {
return (Urlbox) component;
}
@Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
public void onEvent(Event event) public void onEvent(Event event)
{ {
if (Events.ON_CHANGE.equals(event.getName())) if (Events.ON_CHANGE.equals(event.getName()))
{ {
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), urlbox.getText(), urlbox.getText()); ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), getComponent().getText(), getComponent().getText());
fireValueChange(changeEvent); fireValueChange(changeEvent);
} }
else if (Events.ON_CLICK.equals(event.getName())) else if (Events.ON_CLICK.equals(event.getName()))
{ {
String urlString =urlbox.getText(); String urlString =getComponent().getText();
String message = null; String message = null;
if (urlString != null && urlString.length() > 0) if (urlString != null && urlString.length() > 0)
{ {

View File

@ -45,13 +45,11 @@ public class WYesNoEditor extends WEditor
logger = CLogger.getCLogger(WYesNoEditor.class); logger = CLogger.getCLogger(WYesNoEditor.class);
} }
private Checkbox checkbox;
private boolean oldValue = false; private boolean oldValue = false;
public WYesNoEditor(GridField gridField) public WYesNoEditor(GridField gridField)
{ {
super(new Checkbox(), gridField); super(new Checkbox(), gridField);
checkbox = (Checkbox)super.component;
init(); init();
} }
@ -59,7 +57,7 @@ public class WYesNoEditor extends WEditor
{ {
super.label.setValue(""); super.label.setValue("");
super.label.setTooltiptext(""); super.label.setTooltiptext("");
checkbox.setLabel(gridField.getHeader()); getComponent().setLabel(gridField.getHeader());
} }
public void onEvent(Event event) public void onEvent(Event event)
@ -81,14 +79,14 @@ public class WYesNoEditor extends WEditor
@Override @Override
public String getDisplay() public String getDisplay()
{ {
String display = checkbox.isChecked() ? "Y" : "N"; String display = getComponent().isChecked() ? "Y" : "N";
return Msg.translate(Env.getCtx(), display); return Msg.translate(Env.getCtx(), display);
} }
@Override @Override
public Object getValue() public Object getValue()
{ {
return new Boolean(checkbox.isChecked()); return new Boolean(getComponent().isChecked());
} }
@Override @Override
@ -98,13 +96,13 @@ public class WYesNoEditor extends WEditor
{ {
Boolean val = ((value == null) ? false Boolean val = ((value == null) ? false
: (Boolean) value); : (Boolean) value);
checkbox.setChecked(val); getComponent().setChecked(val);
oldValue = val; oldValue = val;
} }
else if (value instanceof String) else if (value instanceof String)
{ {
Boolean val = value.equals("Y"); Boolean val = value.equals("Y");
checkbox.setChecked(val); getComponent().setChecked(val);
oldValue = val; oldValue = val;
} }
else else
@ -113,11 +111,26 @@ public class WYesNoEditor extends WEditor
"New field value of unknown type, Type: " "New field value of unknown type, Type: "
+ value.getClass() + value.getClass()
+ ", Value: " + value); + ", Value: " + value);
checkbox.setChecked(false); getComponent().setChecked(false);
} }
} }
public String[] getEvents() @Override
public Checkbox getComponent() {
return (Checkbox) component;
}
@Override
public boolean isReadWrite() {
return getComponent().isEnabled();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
public String[] getEvents()
{ {
return LISTENER_EVENTS; return LISTENER_EVENTS;
} }

View File

@ -332,6 +332,8 @@ DataStatusListener, ValueChangeListener, IADTabpanel
div.setAlign("right"); div.setAlign("right");
Label label = editor.getLabel(); Label label = editor.getLabel();
div.appendChild(label); div.appendChild(label);
if (label.getDecorator() != null)
div.appendChild(label.getDecorator());
row.appendChild(div); row.appendChild(div);
row.appendChild(editor.getComponent()); row.appendChild(editor.getComponent());
if (field.isLongField()) { if (field.isLongField()) {