IDEMPIERE-2148:Cant add fields over Grid Sequence fields in window column customisation

This commit is contained in:
hieplq 2015-01-08 02:14:33 +07:00
parent afcfc0b1a6
commit f93bc28a0d
6 changed files with 107 additions and 53 deletions

View File

@ -511,9 +511,7 @@ public class GridField
if (checkContext && getGridTab() != null && !Env.getContext(ctx, m_vo.WindowNo,m_vo.TabNo, "IsActive").equals("Y")) if (checkContext && getGridTab() != null && !Env.getContext(ctx, m_vo.WindowNo,m_vo.TabNo, "IsActive").equals("Y"))
return false; return false;
// ultimately visibility decides
if(isGrid)
return isDisplayedGrid();
return isDisplayed (ctx, checkContext); return isDisplayed (ctx, checkContext);
} // isEditable } // isEditable

View File

@ -3101,6 +3101,8 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
} }
/** /**
* show dialog to customize fields (hidden, display, order of field) in grid mode
* @see CustomizeGridViewDialog
* @see ToolbarListener#onCustomize() * @see ToolbarListener#onCustomize()
*/ */
public void onCustomize() { public void onCustomize() {
@ -3111,6 +3113,9 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements
Map<Integer, String> columnsWidth = new HashMap<Integer, String>(); Map<Integer, String> columnsWidth = new HashMap<Integer, String>();
ArrayList<Integer> gridFieldIds = new ArrayList<Integer>(); ArrayList<Integer> gridFieldIds = new ArrayList<Integer>();
for (int i = 0; i < fields.length; i++) { for (int i = 0; i < fields.length; i++) {
// 2 is offset of num of column in grid view and actual data fields.
// in grid view, add two function column, indicator column and selection (checkbox) column
// @see GridView#setupColumns
Column column = (Column) columnList.get(i+2); Column column = (Column) columnList.get(i+2);
String width = column.getWidth(); String width = column.getWidth();
columnsWidth.put(fields[i].getAD_Field_ID(), width); columnsWidth.put(fields[i].getAD_Field_ID(), width);

View File

@ -94,7 +94,11 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
private int currentRowIndex = -1; private int currentRowIndex = -1;
private AbstractADWindowContent m_windowPanel; private AbstractADWindowContent m_windowPanel;
private ActionListener buttonListener; private ActionListener buttonListener;
/**
* Flag detect this view has customized column or not
* value is set at {@link #render(Row, Object[], int)}
*/
private boolean isGridViewCustomized = false;
/** DefaultFocusField */ /** DefaultFocusField */
private WEditor defaultFocusField = null; private WEditor defaultFocusField = null;
@ -164,14 +168,33 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
return checkBox; return checkBox;
} }
private String getDisplayText(Object value, GridField gridField, int rowIndex) /**
* call {@link #getDisplayText(Object, GridField, int, boolean)} with isForceGetValue = false
* @param value
* @param gridField
* @param rowIndex
* @return
*/
private String getDisplayText(Object value, GridField gridField, int rowIndex){
return getDisplayText(value, gridField, rowIndex, false);
}
/**
* Get display text of a field. when field have isDisplay = false always return empty string, except isForceGetValue = true
* @param value
* @param gridField
* @param rowIndex
* @param isForceGetValue
* @return
*/
private String getDisplayText(Object value, GridField gridField, int rowIndex, boolean isForceGetValue)
{ {
if (value == null) if (value == null)
return ""; return "";
if (rowIndex >= 0) { if (rowIndex >= 0) {
GridRowCtx gridRowCtx = new GridRowCtx(Env.getCtx(), gridTab, rowIndex); GridRowCtx gridRowCtx = new GridRowCtx(Env.getCtx(), gridTab, rowIndex);
if (!gridField.isDisplayed(gridRowCtx, true)) { if (!isForceGetValue && !gridField.isDisplayed(gridRowCtx, true)) {
return ""; return "";
} }
} }
@ -189,7 +212,17 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
return value.toString(); return value.toString();
} }
private Component getDisplayComponent(int rowIndex, Object value, GridField gridField) { /**
* get component to display value of a field.
* when display is boolean or button, return correspond component
* other return a label with text get from {@link #getDisplayText(Object, GridField, int, boolean)}
* @param rowIndex
* @param value
* @param gridField
* @param isForceGetValue
* @return
*/
private Component getDisplayComponent(int rowIndex, Object value, GridField gridField, boolean isForceGetValue) {
Component component; Component component;
if (gridField.getDisplayType() == DisplayType.YesNo) { if (gridField.getDisplayType() == DisplayType.YesNo) {
component = createReadonlyCheckbox(value); component = createReadonlyCheckbox(value);
@ -202,7 +235,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
editor.addActionListener(buttonListener); editor.addActionListener(buttonListener);
component = editor.getComponent(); component = editor.getComponent();
} else { } else {
String text = getDisplayText(value, gridField, rowIndex); String text = getDisplayText(value, gridField, rowIndex, isForceGetValue);
Label label = new Label(); Label label = new Label();
setLabelText(text, label); setLabelText(text, label);
@ -315,7 +348,6 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
int columnCount = 0; int columnCount = 0;
GridField[] gridPanelFields = null; GridField[] gridPanelFields = null;
GridField[] gridTabFields = null; GridField[] gridTabFields = null;
boolean isGridViewCustomized = false;
if (gridPanel != null) { if (gridPanel != null) {
if (!gridPanel.isVisible()) { if (!gridPanel.isVisible()) {
@ -426,7 +458,8 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
} }
} }
if (!gridPanelFields[i].isDisplayedGrid() || gridPanelFields[i].isToolbarButton()) { // IDEMPIERE-2148: when has tab customize, ignore check properties isDisplayedGrid
if ((!isGridViewCustomized && gridPanelFields[i].isDisplayedGrid()) || gridPanelFields[i].isToolbarButton()) {
continue; continue;
} }
colIndex ++; colIndex ++;
@ -435,7 +468,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
String divStyle = CELL_DIV_STYLE; String divStyle = CELL_DIV_STYLE;
org.zkoss.zul.Column column = (org.zkoss.zul.Column) columns.getChildren().get(colIndex); org.zkoss.zul.Column column = (org.zkoss.zul.Column) columns.getChildren().get(colIndex);
if (column.isVisible()) { if (column.isVisible()) {
Component component = getDisplayComponent(rowIndex, currentValues[i], gridPanelFields[i]); Component component = getDisplayComponent(rowIndex, currentValues[i], gridPanelFields[i], isGridViewCustomized);
div.appendChild(component); div.appendChild(component);
div.setAttribute("display.component", component); div.setAttribute("display.component", component);
@ -445,8 +478,12 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
else if (DisplayType.isNumeric(gridPanelFields[i].getDisplayType())) { else if (DisplayType.isNumeric(gridPanelFields[i].getDisplayType())) {
divStyle = CELL_DIV_STYLE_ALIGN_RIGHT; divStyle = CELL_DIV_STYLE_ALIGN_RIGHT;
} }
GridRowCtx ctx = new GridRowCtx(Env.getCtx(), gridTab, rowIndex); GridRowCtx ctx = new GridRowCtx(Env.getCtx(), gridTab, rowIndex);
component.setVisible(gridPanelFields[i].isDisplayed(ctx, true)); if (!gridPanelFields[i].isDisplayed(ctx, true)){
// IDEMPIERE-2253
div.removeChild(component);
}
} }
div.setStyle(divStyle); div.setStyle(divStyle);
div.setWidth("100%"); div.setWidth("100%");
@ -553,7 +590,7 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
//skip selection and indicator column //skip selection and indicator column
int colIndex = 1; int colIndex = 1;
for (int i = 0; i < columnCount; i++) { for (int i = 0; i < columnCount; i++) {
if (!gridPanelFields[i].isDisplayedGrid() || gridPanelFields[i].isToolbarButton()) { if ((!isGridViewCustomized && !gridPanelFields[i].isDisplayedGrid()) || gridPanelFields[i].isToolbarButton()) {
continue; continue;
} }
colIndex ++; colIndex ++;
@ -584,11 +621,11 @@ public class GridTabRowRenderer implements RowRenderer<Object[]>, RowRendererExt
Properties ctx = isDetailPane() ? new GridRowCtx(Env.getCtx(), gridTab, gridTab.getCurrentRow()) Properties ctx = isDetailPane() ? new GridRowCtx(Env.getCtx(), gridTab, gridTab.getCurrentRow())
: gridPanelFields[i].getVO().ctx; : gridPanelFields[i].getVO().ctx;
//check context //check context
if (!gridPanelFields[i].isDisplayedGrid() || if (!gridPanelFields[i].isDisplayed(ctx, true)){
!gridPanelFields[i].isDisplayed(ctx, true)) // IDEMPIERE-2253
{ div.removeChild(editor.getComponent());
editor.setVisible(false);
} }
editor.setReadWrite(gridPanelFields[i].isEditableGrid(true)); editor.setReadWrite(gridPanelFields[i].isEditableGrid(true));
} }
} }

View File

@ -97,6 +97,10 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
private int pageSize = DEFAULT_PAGE_SIZE; private int pageSize = DEFAULT_PAGE_SIZE;
/**
* list field display in grid mode, in case user customize grid
* this list container only customize list.
*/
private GridField[] gridField; private GridField[] gridField;
private AbstractTableModel tableModel; private AbstractTableModel tableModel;
@ -130,6 +134,8 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
protected Checkbox selectAll; protected Checkbox selectAll;
boolean isHasCustomizeData = false;
public GridView() public GridView()
{ {
this(0); this(0);
@ -254,8 +260,9 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
columnWidthMap = new HashMap<Integer, String>(); columnWidthMap = new HashMap<Integer, String>();
GridField[] tmpFields = ((GridTable)tableModel).getFields(); GridField[] tmpFields = ((GridTable)tableModel).getFields();
MTabCustomization tabCustomization = MTabCustomization.get(Env.getCtx(), Env.getAD_User_ID(Env.getCtx()), gridTab.getAD_Tab_ID(), null); MTabCustomization tabCustomization = MTabCustomization.get(Env.getCtx(), Env.getAD_User_ID(Env.getCtx()), gridTab.getAD_Tab_ID(), null);
if (tabCustomization != null && tabCustomization.getAD_Tab_Customization_ID() > 0 isHasCustomizeData = tabCustomization != null && tabCustomization.getAD_Tab_Customization_ID() > 0
&& tabCustomization.getCustom() != null && tabCustomization.getCustom().trim().length() > 0) { && tabCustomization.getCustom() != null && tabCustomization.getCustom().trim().length() > 0;
if (isHasCustomizeData) {
String custom = tabCustomization.getCustom().trim(); String custom = tabCustomization.getCustom().trim();
String[] customComponent = custom.split(";"); String[] customComponent = custom.split(";");
String[] fieldIds = customComponent[0].split("[,]"); String[] fieldIds = customComponent[0].split("[,]");
@ -266,7 +273,8 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
int AD_Field_ID = Integer.parseInt(fieldIdStr); int AD_Field_ID = Integer.parseInt(fieldIdStr);
for(GridField gridField : tmpFields) { for(GridField gridField : tmpFields) {
if (gridField.getAD_Field_ID() == AD_Field_ID) { if (gridField.getAD_Field_ID() == AD_Field_ID) {
if(gridField.isDisplayedGrid() && !gridField.isToolbarButton()) // IDEMPIERE-2204 add field in tabCustomization list to display list event this field have showInGrid = false
if((gridField.isDisplayedGrid() || gridField.isDisplayed()) && !gridField.isToolbarButton())
fieldList.add(gridField); fieldList.add(gridField);
break; break;
@ -477,9 +485,11 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
Map<Integer, String> colnames = new HashMap<Integer, String>(); Map<Integer, String> colnames = new HashMap<Integer, String>();
int index = 0; int index = 0;
for (int i = 0; i < numColumns; i++) for (int i = 0; i < numColumns; i++)
{ {
if (gridField[i].isDisplayedGrid() && !gridField[i].isToolbarButton()) // IDEMPIERE-2148: when has tab customize, ignore check properties isDisplayedGrid
if ((isHasCustomizeData || gridField[i].isDisplayedGrid()) && !gridField[i].isToolbarButton())
{ {
colnames.put(index, gridField[i].getHeader()); colnames.put(index, gridField[i].getHeader());
index++; index++;
@ -959,7 +969,7 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
Properties ctx = isDetailPane() ? new GridRowCtx(Env.getCtx(), gridTab, gridTab.getCurrentRow()) Properties ctx = isDetailPane() ? new GridRowCtx(Env.getCtx(), gridTab, gridTab.getCurrentRow())
: mField.getVO().ctx; : mField.getVO().ctx;
comp.setVisible(mField.isDisplayedGrid() && mField.isDisplayed(ctx, true)); comp.setVisible((isHasCustomizeData || mField.isDisplayedGrid()) && mField.isDisplayed(ctx, true));
} }
} }
} }
@ -1044,6 +1054,10 @@ public class GridView extends Vbox implements EventListener<Event>, IdSpace, IFi
updateModel(); updateModel();
} }
/**
* list field display in grid mode, in case user customize grid
* this list container only customize list.
*/
public GridField[] getFields() { public GridField[] getFields() {
return gridField; return gridField;
} }

View File

@ -16,9 +16,6 @@
*****************************************************************************/ *****************************************************************************/
package org.adempiere.webui.panel; package org.adempiere.webui.panel;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -27,6 +24,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import org.adempiere.exceptions.DBException;
import org.adempiere.model.MTabCustomization; import org.adempiere.model.MTabCustomization;
import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.adwindow.GridView; import org.adempiere.webui.adwindow.GridView;
@ -43,9 +41,12 @@ import org.adempiere.webui.component.SimpleListModel;
import org.adempiere.webui.factory.ButtonFactory; import org.adempiere.webui.factory.ButtonFactory;
import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.window.FDialog; import org.adempiere.webui.window.FDialog;
import org.compiere.model.MField;
import org.compiere.model.MRefList; import org.compiere.model.MRefList;
import org.compiere.model.MRole;
import org.compiere.model.MTab;
import org.compiere.model.Query;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
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.compiere.util.NamePair; import org.compiere.util.NamePair;
@ -295,27 +296,31 @@ public class CustomizeGridViewPanel extends Panel
yesModel.removeAllElements(); yesModel.removeAllElements();
noModel.removeAllElements(); noModel.removeAllElements();
boolean baseLanguage = Env.isBaseLanguage(Env.getCtx(), "AD_Field"); boolean baseLanguage = Env.isBaseLanguage(Env.getCtx(), "AD_Field");
String sql; Query query = null;
if (baseLanguage)
sql = "SELECT f.AD_Field_ID,f.Name FROM AD_Field f WHERE f.AD_Tab_ID=? AND (f.IsDisplayed='Y' OR f.IsDisplayedGrid='Y') AND f.IsActive='Y' ORDER BY f.SeqNoGrid,f.Name,f.SeqNo"; query = new Query(Env.getCtx(), MField.Table_Name, "AD_Tab_ID=? AND (IsDisplayed='Y' OR IsDisplayedGrid='Y') AND IsActive='Y'", null);
else query.setOrderBy("SeqNoGrid, Name, SeqNo");
sql = "SELECT f.AD_Field_ID,trl.Name FROM AD_Field f JOIN AD_Field_Trl trl ON (f.AD_Field_ID = trl.AD_Field_ID)" query.setParameters(new Object [] {m_AD_Tab_ID});
+ " WHERE f.AD_Tab_ID=? AND (f.IsDisplayed='Y' OR f.IsDisplayedGrid='Y') AND f.IsActive='Y' AND trl.AD_Language=? ORDER BY f.SeqNoGrid,f.Name,f.SeqNo"; query.setApplyAccessFilter(true);
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, null); List<MField> lsFieldsOfGrid = query.list();
pstmt.setInt(1, m_AD_Tab_ID);
if (!baseLanguage)
pstmt.setString(2, Env.getAD_Language(Env.getCtx()));
rs = pstmt.executeQuery();
HashMap<Integer, ListElement> curTabSel = new HashMap<Integer, CustomizeGridViewPanel.ListElement>(); HashMap<Integer, ListElement> curTabSel = new HashMap<Integer, CustomizeGridViewPanel.ListElement>();
while (rs.next()) MTab tab = new MTab(Env.getCtx(), m_AD_Tab_ID, null);
for (MField field : lsFieldsOfGrid)
{ {
int key = rs.getInt(1); if (!MRole.getDefault(Env.getCtx(), false).isColumnAccess(tab.getAD_Table_ID(), field.getAD_Column_ID(), true))
String name = rs.getString(2); continue;
int key = field.get_ID();
String name = null;
if (baseLanguage)
name = field.getName();
else
name = field.get_Translation(MField.COLUMNNAME_Name);
ListElement pp = new ListElement(key, name); ListElement pp = new ListElement(key, name);
if (tableSeqs != null && tableSeqs.size() > 0 ) { if (tableSeqs != null && tableSeqs.size() > 0 ) {
if (tableSeqs.contains(key)) { if (tableSeqs.contains(key)) {
@ -335,16 +340,10 @@ public class CustomizeGridViewPanel extends Panel
} }
} }
} }
catch (SQLException e) catch (DBException e)
{ {
log.log(Level.SEVERE, sql.toString(), e); log.log(Level.SEVERE, e.getMessage(), e);
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
bAdd.setEnabled(true); bAdd.setEnabled(true);
bRemove.setEnabled(true); bRemove.setEnabled(true);

View File

@ -61,6 +61,7 @@ public class CustomizeGridViewDialog extends Window {
* @param WindowNo window no * @param WindowNo window no
* @param AD_Tab_ID * @param AD_Tab_ID
* @param columnsWidth * @param columnsWidth
* @param gridFieldIds list fieldId current display in gridview
*/ */
public static boolean showCustomize (int WindowNo, int AD_Tab_ID, Map<Integer, String> columnsWidth,ArrayList<Integer> gridFieldIds,GridView gridPanel) public static boolean showCustomize (int WindowNo, int AD_Tab_ID, Map<Integer, String> columnsWidth,ArrayList<Integer> gridFieldIds,GridView gridPanel)
{ {