* always render button for grid view.

This commit is contained in:
Heng Sin Low 2010-07-19 14:07:36 +08:00
parent eff346092a
commit de964d5180
4 changed files with 330 additions and 16 deletions

View File

@ -0,0 +1,235 @@
/**
*
*/
package org.adempiere.util;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.GridTable;
import org.compiere.util.Env;
import org.compiere.util.Evaluatee;
import org.compiere.util.KeyNamePair;
import org.compiere.util.ValueNamePair;
/**
* Context (Properties) wrapper to be able to evaluate grid row context
* @author Teo Sarca, teo.sarca@gmail.com
*/
public class GridRowCtx extends Properties
implements Evaluatee
{
/**
*
*/
private static final long serialVersionUID = 8163657930039348267L;
private final Properties ctx;
private final GridTab gridTab;
private final GridTable gridTable;
private final int windowNo;
private final int row;
public GridRowCtx(Properties ctx, GridTab tab, int row)
{
super();
this.ctx = ctx;
this.gridTab = tab;
this.gridTable = tab.getTableModel();
this.windowNo = tab.getWindowNo();
this.row = row;
}
public GridRowCtx(Properties ctx, GridTable table, int windowNo, int row)
{
super();
this.ctx = ctx;
this.gridTab = null;
this.gridTable = table;
this.windowNo = windowNo;
this.row = row;
}
private String getColumnName(Object key)
{
if (! (key instanceof String) )
return null;
String windowStr = windowNo+"|";
String keyStr = (String)key;
if (!keyStr.startsWith(windowStr))
{
return null;
}
String columnName = keyStr.substring(windowStr.length()).trim();
return columnName;
}
@Override
public synchronized Object get(Object key)
{
String columnName = getColumnName(key);
if (columnName == null)
{
return ctx.get(key);
}
int col = gridTable.findColumn(columnName);
if (col == -1)
{
return ctx.get(key);
}
Object value = gridTable.getValueAt(row, col);
if (value == null)
{
value = "";
}
else if (value instanceof KeyNamePair)
{
value = ((KeyNamePair)value).getKey();
}
else if (value instanceof ValueNamePair)
{
value = ((ValueNamePair)value).getID();
}
else if (value instanceof Boolean)
{
value = ((Boolean)value).booleanValue() ? "Y" : "N";
}
return value.toString();
}
@Override
public synchronized void clear() {
ctx.clear();
}
@Override
public synchronized Object clone() {
final GridRowCtx grc;
if (this.gridTab != null)
grc = new GridRowCtx((Properties)this.ctx.clone(), this.gridTab, this.row);
else
grc = new GridRowCtx((Properties)this.ctx.clone(), this.gridTable, this.windowNo, this.row);
return grc;
}
@Override
public synchronized boolean contains(Object value) {
// TODO: check if that value exists in one of our GridFields
return this.ctx.contains(value);
}
@Override
public synchronized boolean containsKey(Object key)
{
String columnName = getColumnName(key);
if (columnName != null && gridTable.findColumn(columnName) != -1)
return true;
return ctx.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
// TODO: check if that value exists in one of our GridFields
return ctx.containsValue(value);
}
@Override
public synchronized Enumeration<Object> elements() {
// TODO: implement for GridField values too
return ctx.elements();
}
@Override
public Set<java.util.Map.Entry<Object, Object>> entrySet() {
// TODO: implement for GridField values too
return ctx.entrySet();
}
@Override
public synchronized boolean isEmpty() {
return false;
}
@Override
public synchronized Enumeration<Object> keys() {
// TODO: implement for GridField values too
return ctx.keys();
}
@Override
public Set<Object> keySet() {
// TODO: implement for GridField values too
return ctx.keySet();
}
@Override
public synchronized Object put(Object key, Object value)
{
if (gridTab == null)
throw new IllegalStateException("Method not supported (gridTab is null)");
if (gridTab.getCurrentRow() != row)
{
return ctx.put(key, value);
}
String columnName = getColumnName(key);
if (columnName == null)
{
return ctx.put(key, value);
}
GridField field = gridTab.getField(columnName);
if (field == null)
{
return ctx.put(key, value);
}
Object valueOld = field.getValue();
field.setValue(value, false);
return valueOld;
}
@Override
public synchronized void putAll(Map<? extends Object, ? extends Object> t) {
for (Map.Entry<? extends Object, ? extends Object> e : t.entrySet())
put(e.getKey(), e.getValue());
}
@Override
public synchronized Object remove(Object key) {
// TODO: implement for GridField values too
return ctx.remove(key);
}
@Override
public synchronized int size() {
// TODO: implement for GridField values too
return ctx.size();
}
@Override
public synchronized String toString() {
// TODO: implement for GridField values too
return ctx.toString();
}
@Override
public Collection<Object> values() {
return ctx.values();
}
@Override
public String getProperty(String key) {
// I need to override this method, because Properties.getProperty method is calling super.get() instead of get()
Object oval = get(key);
return oval == null ? null : oval.toString();
}
public String get_ValueAsString(String variableName)
{
return Env.getContext (this, windowNo, variableName, true);
}
}

View File

@ -358,13 +358,22 @@ public class GridField
return isDisplayed (checkContext);
}
/**
* Is it Editable - checks IsActive, IsUpdateable, and isDisplayed
* @param checkContext if true checks Context for Active, IsProcessed, LinkColumn
* @return true, if editable
*/
public boolean isEditable (boolean checkContext)
{
return isEditable(m_vo.ctx, checkContext);
}
/**
* Is it Editable - checks IsActive, IsUpdateable, and isDisplayed
* @param checkContext if true checks Context for Active, IsProcessed, LinkColumn
* @return true, if editable
*/
public boolean isEditable (Properties ctx, boolean checkContext)
{
if (isVirtualColumn())
return false;
@ -392,7 +401,7 @@ public class GridField
}
// Field is the Link Column of the tab
if (m_vo.ColumnName.equals(Env.getContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, GridTab.CTX_LinkColumnName)))
if (m_vo.ColumnName.equals(Env.getContext(ctx, m_vo.WindowNo, m_vo.TabNo, GridTab.CTX_LinkColumnName)))
{
log.finest(m_vo.ColumnName + " NO - LinkColumn");
return false;
@ -401,19 +410,19 @@ public class GridField
// Role Access & Column Access
if (checkContext)
{
int AD_Client_ID = Env.getContextAsInt(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, "AD_Client_ID");
int AD_Org_ID = Env.getContextAsInt(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, "AD_Org_ID");
String keyColumn = Env.getContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, GridTab.CTX_KeyColumnName);
int AD_Client_ID = Env.getContextAsInt(ctx, m_vo.WindowNo, m_vo.TabNo, "AD_Client_ID");
int AD_Org_ID = Env.getContextAsInt(ctx, m_vo.WindowNo, m_vo.TabNo, "AD_Org_ID");
String keyColumn = Env.getContext(ctx, m_vo.WindowNo, m_vo.TabNo, GridTab.CTX_KeyColumnName);
if ("EntityType".equals(keyColumn))
keyColumn = "AD_EntityType_ID";
if (!keyColumn.endsWith("_ID"))
keyColumn += "_ID"; // AD_Language_ID
int Record_ID = Env.getContextAsInt(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, keyColumn);
int Record_ID = Env.getContextAsInt(ctx, m_vo.WindowNo, m_vo.TabNo, keyColumn);
int AD_Table_ID = m_vo.AD_Table_ID;
if (!MRole.getDefault(m_vo.ctx, false).canUpdate(
if (!MRole.getDefault(ctx, false).canUpdate(
AD_Client_ID, AD_Org_ID, AD_Table_ID, Record_ID, false))
return false;
if (!MRole.getDefault(m_vo.ctx, false).isColumnAccess(AD_Table_ID, m_vo.AD_Column_ID, false))
if (!MRole.getDefault(ctx, false).isColumnAccess(AD_Table_ID, m_vo.AD_Column_ID, false))
return false;
}
@ -428,7 +437,7 @@ public class GridField
//BF [ 2910368 ]
// Always editable if Active
if (checkContext && "Y".equals(Env.getContext(m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, "IsActive"))
if (checkContext && "Y".equals(Env.getContext(ctx, m_vo.WindowNo, m_vo.TabNo, "IsActive"))
&& ( m_vo.ColumnName.equals("Processing")
|| m_vo.ColumnName.equals("PaymentRule")
|| m_vo.ColumnName.equals("DocAction")
@ -445,11 +454,11 @@ public class GridField
return true;
// BF [ 2910368 ]
// Record is not Active
if (checkContext && !Env.getContext(m_vo.ctx, m_vo.WindowNo,m_vo.TabNo, "IsActive").equals("Y"))
if (checkContext && !Env.getContext(ctx, m_vo.WindowNo,m_vo.TabNo, "IsActive").equals("Y"))
return false;
// ultimately visibility decides
return isDisplayed (checkContext);
return isDisplayed (ctx, checkContext);
} // isEditable
/**
@ -772,6 +781,16 @@ public class GridField
* @return true, if visible
*/
public boolean isDisplayed (boolean checkContext)
{
return isDisplayed(m_vo.ctx, checkContext);
}
/**************************************************************************
* Is the Column Visible ?
* @param checkContext - check environment (requires correct row position)
* @return true, if visible
*/
public boolean isDisplayed (final Properties ctx, boolean checkContext)
{
// ** static content **
// not displayed
@ -784,7 +803,12 @@ public class GridField
// ** dynamic content **
if (checkContext)
{
boolean retValue = Evaluator.evaluateLogic(this, m_vo.DisplayLogic);
Evaluatee evaluatee = new Evaluatee() {
public String get_ValueAsString(String variableName) {
return GridField.this.get_ValueAsString(ctx, variableName);
}
};
boolean retValue = Evaluator.evaluateLogic(evaluatee, m_vo.DisplayLogic);
log.finest(m_vo.ColumnName
+ " (" + m_vo.DisplayLogic + ") => " + retValue);
return retValue;
@ -798,11 +822,21 @@ public class GridField
* @return value
*/
public String get_ValueAsString (String variableName)
{
return get_ValueAsString(m_vo.ctx, variableName);
}
/**
* Get Variable Value (Evaluatee)
* @param variableName name
* @return value
*/
public String get_ValueAsString (Properties ctx, String variableName)
{
if( m_vo.TabNo == 0)
return Env.getContext (m_vo.ctx, m_vo.WindowNo, variableName, true);
return Env.getContext (ctx, m_vo.WindowNo, variableName, true);
else
return Env.getContext (m_vo.ctx, m_vo.WindowNo, m_vo.TabNo, variableName, false, true);
return Env.getContext (ctx, m_vo.WindowNo, m_vo.TabNo, variableName, false, true);
} // get_ValueAsString

View File

@ -1374,6 +1374,27 @@ public class GridTab implements DataStatusListener, Evaluatee, Serializable
* Get Tree ID of this tab
* @return ID
*/
private int getTreeID()
{
log.fine(m_vo.TableName);
String SQL = "SELECT * FROM AD_ClientInfo WHERE AD_Client="
+ Env.getContext(m_vo.ctx, m_vo.WindowNo, "AD_Client_ID")
+ " ORDER BY AD_Org DESC";
//
if (m_vo.TableName.equals("AD_Menu"))
return 10; // MM
else if (m_vo.TableName.equals("C_ElementValue"))
return 20; // EV
else if (m_vo.TableName.equals("M_Product"))
return 30; // PR
else if (m_vo.TableName.equals("C_BPartner"))
return 40; // BP
else if (m_vo.TableName.equals("AD_Org"))
return 50; // OO
else if (m_vo.TableName.equals("C_Project"))
return 60; // PJ
return 0;
} // getTreeID
/**
* Returns true if this is a detail record

View File

@ -21,11 +21,14 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.adempiere.util.GridRowCtx;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.editor.WButtonEditor;
import org.adempiere.webui.editor.WEditor;
import org.adempiere.webui.editor.WEditorPopupMenu;
import org.adempiere.webui.editor.WebEditorFactory;
import org.adempiere.webui.event.ActionEvent;
import org.adempiere.webui.event.ActionListener;
import org.adempiere.webui.event.ContextMenuListener;
import org.adempiere.webui.panel.AbstractADWindowPanel;
import org.adempiere.webui.session.SessionManager;
@ -219,10 +222,27 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt, Renderer
return value.toString();
}
private Component getDisplayComponent(Object value, GridField gridField) {
private Component getDisplayComponent(int rowIndex, Object value, GridField gridField) {
Component component;
if (gridField.getDisplayType() == DisplayType.YesNo) {
component = createReadonlyCheckbox(value);
} else if (gridField.getDisplayType() == DisplayType.Button) {
GridRowCtx gridRowCtx = new GridRowCtx(Env.getCtx(), gridTab, rowIndex);
WButtonEditor editor = new WButtonEditor(gridField);
editor.setValue(gridTab.getValue(rowIndex, gridField.getColumnName()));
editor.setReadWrite(gridField.isEditable(gridRowCtx, true));
editor.getComponent().setAttribute("grid.row.index", rowIndex);
editor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
WButtonEditor editor = (WButtonEditor) event.getSource();
int rowIndex = (Integer) editor.getComponent().getAttribute("grid.row.index");
int newRowIndex = gridTab.navigate(rowIndex);
if (newRowIndex == rowIndex) {
m_windowPanel.actionPerformed(event);
}
}
});
component = editor.getComponent();
} else {
String text = getDisplayText(value, gridField);
@ -363,7 +383,7 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt, Renderer
org.zkoss.zul.Column column = (org.zkoss.zul.Column) columns.getChildren().get(colIndex);
if (column.isVisible()) {
compCount++;
Component component = getDisplayComponent(currentValues[i], gridField[i]);
Component component = getDisplayComponent(rowIndex, currentValues[i], gridField[i]);
div.appendChild(component);
// if (compCount == 1) {
//add hidden input component to help focusing to row
@ -553,12 +573,16 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt, Renderer
Component c = toFocus.getComponent();
if (c instanceof EditorBox) {
c = ((EditorBox)c).getTextbox();
} else if (c instanceof NumberBox) {
c = ((NumberBox)c).getDecimalbox();
}
Clients.response(new AuFocus(c));
} else if (firstEditor != null) {
Component c = firstEditor.getComponent();
if (c instanceof EditorBox) {
c = ((EditorBox)c).getTextbox();
} else if (c instanceof NumberBox) {
c = ((NumberBox)c).getDecimalbox();
}
Clients.response(new AuFocus(c));
}