diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Urlbox.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Urlbox.java index 25e59bd32b..50180e16ea 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Urlbox.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Urlbox.java @@ -12,20 +12,34 @@ *****************************************************************************/ package org.adempiere.webui.component; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; + +import org.adempiere.webui.LayoutUtils; +import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; +import org.zkoss.zul.A; +import org.zkoss.zul.Div; +import org.zkoss.zul.Hlayout; + /** * URL Box * @author Low Heng Sin */ -public class Urlbox extends EditorBox +public class Urlbox extends Div { - /** + /** * */ - private static final long serialVersionUID = -3846071364733430994L; - + private static final long serialVersionUID = -5493978668402134644L; + + protected PropertyChangeSupport m_propertyChangeListeners = new PropertyChangeSupport(this); + protected Textbox txt; + protected A btn; + public Urlbox() { - super(); + initComponents(); } /** @@ -33,12 +47,110 @@ public class Urlbox extends EditorBox */ public Urlbox(String url) { - super(); + initComponents(); setText(url); } - @Override + private void initComponents() { + Hlayout hlayout = new Hlayout(); + this.appendChild(hlayout); + hlayout.setHflex("1"); + txt = new Textbox(); + hlayout.appendChild(txt); + txt.setHflex("1"); + + btn = new A(); + btn.setTarget("_blank"); + btn.setTabindex(-1); + btn.setSclass("editor-button"); + btn.setZclass("z-button-os"); + btn.setHflex("0"); + hlayout.appendChild(btn); + + LayoutUtils.addSclass("editor-box", this); + } + + /** + * @param imageSrc + */ + public void setButtonImage(String imageSrc) { + btn.setImage(imageSrc); + } + + /** + * @return textbox component + */ + public Textbox getTextbox() { + return txt; + } + + /** + * @param value + */ + public void setText(String value) { + txt.setText(value); + String url = null; + if (value == null) { + url = "about:blank"; + } else { + url = value.trim(); + if (url.length() == 0) { + url = "about:blank"; + } else if (url.indexOf("://") < 0) { + url = "http://"+url; + } + } + btn.setHref(url); + } + + /** + * @return text + */ + public String getText() { + return txt.getText(); + } + public void setEnabled(boolean enabled) { txt.setReadonly(!enabled); } + + /** + * @return boolean + */ + public boolean isEnabled() { + return !txt.isReadonly(); + } + + /** + * @param evtnm + * @param listener + */ + public boolean addEventListener(String evtnm, EventListener listener) { + if (Events.ON_CLICK.equals(evtnm)) { + return btn.addEventListener(evtnm, listener); + } else { + return txt.addEventListener(evtnm, listener); + } + } + + /** + * @param l + */ + public synchronized void addPropertyChangeListener(PropertyChangeListener l) { + m_propertyChangeListeners.addPropertyChangeListener(l); + } + + /** + * @param tooltiptext + */ + public void setToolTipText(String tooltiptext) { + txt.setTooltiptext(tooltiptext); + } + + /** + * @return A + */ + public A getButton() { + return btn; + } } \ No newline at end of file diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WUrlEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WUrlEditor.java index 1e38807607..4f8e8999d9 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WUrlEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WUrlEditor.java @@ -23,17 +23,14 @@ import org.adempiere.webui.event.ContextMenuEvent; import org.adempiere.webui.event.ContextMenuListener; import org.adempiere.webui.event.ValueChangeEvent; import org.adempiere.webui.theme.ThemeManager; -import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.WFieldRecordInfo; import org.compiere.model.GridField; -import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; -import org.zkoss.zk.ui.util.Clients; public class WUrlEditor extends WEditor implements ContextMenuListener { - private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE, Events.ON_OK}; + private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE, Events.ON_OK}; private String oldValue; public WUrlEditor(GridField gridField) @@ -107,25 +104,6 @@ public class WUrlEditor extends WEditor implements ContextMenuListener fireValueChange(changeEvent); oldValue = newValue; } - else if (Events.ON_CLICK.equals(event.getName())) - { - String urlString =getComponent().getText(); - String message = null; - if (urlString != null && urlString.length() > 0) - { - try - { - Clients.response(new AuScript("window.open('"+urlString+"');")); - return; - } - catch(Exception e) - { - message = e.getMessage(); - } - } - FDialog.warn(0, this.getComponent(), "URLnotValid", message); - - } } public String[] getEvents()