IDEMPIERE-809 Zk URL Field Editor: Open url in new browser tab instead of in iFrame or new window.

This commit is contained in:
Heng Sin Low 2013-03-29 00:20:44 +08:00
parent 96dbdd2cf0
commit 069a5f9e11
2 changed files with 120 additions and 30 deletions

View File

@ -12,20 +12,34 @@
*****************************************************************************/ *****************************************************************************/
package org.adempiere.webui.component; 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 * URL Box
* @author Low Heng Sin * @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() public Urlbox()
{ {
super(); initComponents();
} }
/** /**
@ -33,12 +47,110 @@ public class Urlbox extends EditorBox
*/ */
public Urlbox(String url) public Urlbox(String url)
{ {
super(); initComponents();
setText(url); 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) { public void setEnabled(boolean enabled) {
txt.setReadonly(!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;
}
} }

View File

@ -23,17 +23,14 @@ import org.adempiere.webui.event.ContextMenuEvent;
import org.adempiere.webui.event.ContextMenuListener; import org.adempiere.webui.event.ContextMenuListener;
import org.adempiere.webui.event.ValueChangeEvent; import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.window.FDialog;
import org.adempiere.webui.window.WFieldRecordInfo; import org.adempiere.webui.window.WFieldRecordInfo;
import org.compiere.model.GridField; 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.Event;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.Clients;
public class WUrlEditor extends WEditor implements ContextMenuListener 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; private String oldValue;
public WUrlEditor(GridField gridField) public WUrlEditor(GridField gridField)
@ -107,25 +104,6 @@ public class WUrlEditor extends WEditor implements ContextMenuListener
fireValueChange(changeEvent); fireValueChange(changeEvent);
oldValue = newValue; 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() public String[] getEvents()