* Support for Account combination editor
This commit is contained in:
parent
1afbdc34d4
commit
08e767da24
|
@ -0,0 +1,98 @@
|
|||
/******************************************************************************
|
||||
* Product: Posterita Ajax UI *
|
||||
* Copyright (C) 2007 Posterita Ltd. 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. *
|
||||
* 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.component;
|
||||
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zul.Hbox;
|
||||
|
||||
/**
|
||||
* URL Box
|
||||
*/
|
||||
public class Combinationbox extends Hbox
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Textbox textbox;
|
||||
|
||||
private Button button;
|
||||
|
||||
public Combinationbox()
|
||||
{
|
||||
initComponents();
|
||||
}
|
||||
|
||||
public Combinationbox(String url)
|
||||
{
|
||||
initComponents();
|
||||
setText(url);
|
||||
}
|
||||
|
||||
public void setButtonImage(String imageSrc)
|
||||
{
|
||||
button.setImage(imageSrc);
|
||||
}
|
||||
|
||||
private void initComponents()
|
||||
{
|
||||
textbox = new Textbox();
|
||||
textbox.setWidth("100%");
|
||||
button = new Button();
|
||||
button.setHeight("98%");
|
||||
appendChild(textbox);
|
||||
appendChild(button);
|
||||
}
|
||||
|
||||
public void setText(String value)
|
||||
{
|
||||
textbox.setText(value);
|
||||
}
|
||||
|
||||
public String getText()
|
||||
{
|
||||
return textbox.getText();
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled)
|
||||
{
|
||||
textbox.setReadonly(!enabled);
|
||||
button.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public boolean isEnabled()
|
||||
{
|
||||
return button.isEnabled();
|
||||
}
|
||||
|
||||
public void setButtonEnabled(boolean enabled)
|
||||
{
|
||||
button.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public boolean addEventListener(String evtnm, EventListener listener)
|
||||
{
|
||||
if ("onClick".equals(evtnm))
|
||||
return button.addEventListener(evtnm, listener);
|
||||
else
|
||||
return textbox.addEventListener(evtnm, listener);
|
||||
}
|
||||
|
||||
public void setToolTipText(String tooltiptext) {
|
||||
textbox.setTooltiptext(tooltiptext);
|
||||
}
|
||||
}
|
|
@ -70,7 +70,7 @@ public class Urlbox extends Hbox
|
|||
|
||||
public void setEnabled(boolean enabled)
|
||||
{
|
||||
txtUrl.setEnabled(enabled);
|
||||
txtUrl.setReadonly(!enabled);
|
||||
btnUrl.setEnabled(enabled);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,196 @@
|
|||
/******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.adempiere.webui.component.Combinationbox;
|
||||
import org.adempiere.webui.event.ValueChangeEvent;
|
||||
import org.adempiere.webui.window.WAccountDialog;
|
||||
import org.compiere.model.GridField;
|
||||
import org.compiere.model.MAccountLookup;
|
||||
import org.compiere.model.MRole;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Low Heng Sin
|
||||
*
|
||||
*/
|
||||
public class WAccountEditor extends WEditor
|
||||
{
|
||||
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
|
||||
|
||||
private MAccountLookup m_mAccount;
|
||||
|
||||
private Object m_value;
|
||||
|
||||
/** Logger */
|
||||
private static CLogger log = CLogger.getCLogger(WAccountEditor.class);
|
||||
|
||||
public WAccountEditor(GridField gridField)
|
||||
{
|
||||
super(new Combinationbox(), gridField);
|
||||
getComponent().setButtonImage("/images/Account16.gif");
|
||||
|
||||
m_mAccount = new MAccountLookup (gridField.getVO().ctx, gridField.getWindowNo());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Combinationbox getComponent() {
|
||||
return (Combinationbox) component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValue(Object value)
|
||||
{
|
||||
m_value = value;
|
||||
getComponent().setText(m_mAccount.getDisplay(value)); // loads value
|
||||
getComponent().setToolTipText(m_mAccount.getDescription());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue()
|
||||
{
|
||||
return new Integer (m_mAccount.C_ValidCombination_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplay()
|
||||
{
|
||||
return getComponent().getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Button - Start Dialog
|
||||
*/
|
||||
public void cmd_button()
|
||||
{
|
||||
int C_AcctSchema_ID = Env.getContextAsInt(Env.getCtx(), gridField.getWindowNo(), "C_AcctSchema_ID");
|
||||
WAccountDialog ad = new WAccountDialog (gridField.getHeader(), m_mAccount, C_AcctSchema_ID);
|
||||
//
|
||||
Integer newValue = ad.getValue();
|
||||
if (newValue == null)
|
||||
return;
|
||||
|
||||
Object oldValue = m_value;
|
||||
|
||||
// set & redisplay
|
||||
setValue(newValue);
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue);
|
||||
fireValueChange(changeEvent);
|
||||
} // cmd_button
|
||||
|
||||
/**
|
||||
* Text - try to find Alias or start Dialog
|
||||
*/
|
||||
public void cmd_text()
|
||||
{
|
||||
String text = getComponent().getText();
|
||||
log.info("Text=" + text);
|
||||
if (text == null || text.length() == 0 || text.equals("%"))
|
||||
{
|
||||
cmd_button();
|
||||
return;
|
||||
}
|
||||
if (!text.endsWith("%"))
|
||||
text += "%";
|
||||
//
|
||||
String sql = "SELECT C_ValidCombination_ID FROM C_ValidCombination "
|
||||
+ "WHERE C_AcctSchema_ID=?"
|
||||
+ " AND (UPPER(Alias) LIKE ? OR UPPER(Combination) LIKE ?)";
|
||||
sql = MRole.getDefault().addAccessSQL(sql,
|
||||
"C_ValidCombination", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
|
||||
int C_AcctSchema_ID = Env.getContextAsInt(Env.getCtx(), gridField.getWindowNo(), "C_AcctSchema_ID");
|
||||
//
|
||||
int C_ValidCombination_ID = 0;
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, null);
|
||||
pstmt.setInt(1, C_AcctSchema_ID);
|
||||
pstmt.setString(2, text.toUpperCase());
|
||||
pstmt.setString(3, text.toUpperCase());
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next())
|
||||
{
|
||||
C_ValidCombination_ID = rs.getInt(1);
|
||||
if (rs.next()) // only one
|
||||
C_ValidCombination_ID = 0;
|
||||
}
|
||||
rs.close();
|
||||
pstmt.close();
|
||||
pstmt = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, sql, e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
|
||||
// We have a Value
|
||||
if (C_ValidCombination_ID > 0)
|
||||
{
|
||||
Integer newValue = new Integer(C_ValidCombination_ID);
|
||||
Object oldValue = m_value;
|
||||
m_value = newValue;
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldValue, newValue);
|
||||
fireValueChange(changeEvent);
|
||||
}
|
||||
else
|
||||
cmd_button();
|
||||
} // actionPerformed
|
||||
|
||||
public void onEvent(Event event)
|
||||
{
|
||||
if (Events.ON_CHANGE.equals(event.getName()))
|
||||
{
|
||||
cmd_text();
|
||||
}
|
||||
else if (Events.ON_CLICK.equals(event.getName()))
|
||||
{
|
||||
cmd_button();
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getEvents()
|
||||
{
|
||||
return LISTENER_EVENTS;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isReadWrite() {
|
||||
return getComponent().isEnabled();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setReadWrite(boolean readWrite) {
|
||||
getComponent().setEnabled(readWrite);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -17,8 +17,6 @@
|
|||
|
||||
package org.adempiere.webui.editor;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
@ -54,7 +52,7 @@ import org.zkoss.zk.ui.event.Events;
|
|||
* @author Ashley G Ramdass
|
||||
*
|
||||
*/
|
||||
public class WSearchEditor extends WEditor implements ContextMenuListener, PropertyChangeListener, ValueChangeListener, IZoomableEditor
|
||||
public class WSearchEditor extends WEditor implements ContextMenuListener, ValueChangeListener, IZoomableEditor
|
||||
{
|
||||
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
|
||||
private Searchbox searchbox;
|
||||
|
@ -212,21 +210,6 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Prope
|
|||
}
|
||||
|
||||
}
|
||||
public void propertyChange(PropertyChangeEvent evt)
|
||||
{
|
||||
if ("FieldValue".equals(evt.getPropertyName()))
|
||||
{
|
||||
if ( evt.getNewValue()== null)
|
||||
{
|
||||
actionRefresh("");
|
||||
}
|
||||
else
|
||||
{
|
||||
actionRefresh(evt.getNewValue());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void actionRefresh(Object value)
|
||||
{
|
||||
|
@ -362,7 +345,7 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Prope
|
|||
ValueChangeEvent evt = new ValueChangeEvent(this, this.getColumnName(), value, value);
|
||||
// -> ADTabpanel - valuechange
|
||||
fireValueChange(evt);
|
||||
/*
|
||||
|
||||
// is the value updated ?
|
||||
boolean updated = false;
|
||||
if (value == null && getValue() == null)
|
||||
|
@ -371,12 +354,8 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Prope
|
|||
updated = true;
|
||||
if (!updated)
|
||||
{
|
||||
// happens if VLookup is used outside of APanel/GridController (no property listener)
|
||||
log.fine(getColumnName() + " - Value explicitly set - new=" + value + ", old=" + getValue());
|
||||
if (getListeners(PropertyChangeListener.class).length <= 0)
|
||||
setValue(value);
|
||||
}
|
||||
*/
|
||||
} // actionCombo
|
||||
|
||||
/**
|
||||
|
@ -435,8 +414,8 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Prope
|
|||
* - Window closed -> ignore => result == null && !cancalled
|
||||
*/
|
||||
|
||||
//Object result = null; // Not Being Used
|
||||
//boolean cancelled = false; // Not Being Used
|
||||
Object result = null; // Not Being Used
|
||||
boolean cancelled = false; // Not Being Used
|
||||
|
||||
String col = lookup.getColumnName(); // fully qualified name
|
||||
|
||||
|
@ -523,34 +502,30 @@ public class WSearchEditor extends WEditor implements ContextMenuListener, Prope
|
|||
ig.addValueChangeListener(this);
|
||||
AEnv.showWindow(ig);
|
||||
|
||||
cancelled = ig.isCancelled();
|
||||
result = ig.getSelectedKey();
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
// Result
|
||||
if (result != null)
|
||||
{
|
||||
log.config(m_columnName + " - Result = " + result.toString() + " (" + result.getClass().getName() + ")");
|
||||
log.config(gridField.getColumnName() + " - Result = " + result.toString() + " (" + result.getClass().getName() + ")");
|
||||
// make sure that value is in cache
|
||||
m_lookup.getDirect(result, false, true);
|
||||
if (resetValue)
|
||||
actionCombo (null);
|
||||
lookup.getDirect(result, false, true);
|
||||
actionCombo (result); // data binding
|
||||
}
|
||||
else if (cancelled)
|
||||
{
|
||||
log.config(m_columnName + " - Result = null (cancelled)");
|
||||
actionCombo(null);
|
||||
log.config(getColumnName() + " - Result = null (cancelled)");
|
||||
// actionCombo(null);
|
||||
}
|
||||
else
|
||||
{
|
||||
log.config(m_columnName + " - Result = null (not cancelled)");
|
||||
setValue(m_value); // to re-display value
|
||||
log.config(getColumnName() + " - Result = null (not cancelled)");
|
||||
// setValue(m_value); // to re-display value
|
||||
}
|
||||
//
|
||||
m_button.setEnabled(true);
|
||||
m_text.requestFocus();
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.compiere.model.MLocationLookup;
|
|||
import org.compiere.model.MLocatorLookup;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -132,6 +131,10 @@ public class WebEditorFactory
|
|||
gridField.isReadOnly(), gridField.isUpdateable(),
|
||||
(MLocatorLookup)gridField.getLookup());
|
||||
}
|
||||
else if (displayType == DisplayType.Account)
|
||||
{
|
||||
editor = new WAccountEditor(gridField);
|
||||
}
|
||||
else
|
||||
{
|
||||
editor = new WUnknownEditor(gridField);
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.adempiere.webui.editor.IZoomableEditor;
|
|||
import org.adempiere.webui.editor.WButtonEditor;
|
||||
import org.adempiere.webui.editor.WEditor;
|
||||
import org.adempiere.webui.editor.WEditorPopupMenu;
|
||||
import org.adempiere.webui.editor.WSearchEditor;
|
||||
import org.adempiere.webui.editor.WebEditorFactory;
|
||||
import org.adempiere.webui.event.ContextMenuListener;
|
||||
import org.adempiere.webui.event.ValueChangeEvent;
|
||||
|
|
|
@ -781,6 +781,7 @@ public abstract class InfoPanel extends Window implements EventListener, WTableM
|
|||
}
|
||||
else if (event.getTarget().equals(confirmPanel.getButton("Cancel")))
|
||||
{
|
||||
m_cancel = true;
|
||||
dispose(false);
|
||||
}
|
||||
else if (event.getTarget().equals(confirmPanel.getButton("Zoom")))
|
||||
|
|
|
@ -62,6 +62,11 @@ public class StatusBarPanel extends Panel
|
|||
this.appendChild(mainBox);
|
||||
}
|
||||
|
||||
public void setStatusDB (String text)
|
||||
{
|
||||
setStatusDB(text, null);
|
||||
}
|
||||
|
||||
public void setStatusDB (String text, DataStatusEvent dse)
|
||||
{
|
||||
if (text == null || text.length() == 0)
|
||||
|
@ -76,6 +81,11 @@ public class StatusBarPanel extends Panel
|
|||
}
|
||||
}
|
||||
|
||||
public void setStatusLine (String text)
|
||||
{
|
||||
setStatusLine(text, false);
|
||||
}
|
||||
|
||||
public void setStatusLine (String text, boolean error)
|
||||
{
|
||||
statusLine.setValue(text);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue