IDEMPIERE-1066 Toolbar Access problems.

This commit is contained in:
Heng Sin Low 2013-06-19 16:32:36 +08:00
parent 2578545807
commit f0c1b2db34
6 changed files with 155 additions and 40 deletions

View File

@ -49,10 +49,10 @@ public class MToolBarButton extends X_AD_ToolBarButton {
super(ctx, rs, trxName);
}
public static MToolBarButton[] getOfTab(int AD_Tab_ID, String trxName) {
public static MToolBarButton[] getProcessButtonOfTab(int AD_Tab_ID, String trxName) {
MToolBarButton[] buttons = new MToolBarButton[0];
Query query = new Query(Env.getCtx(), MTable.get(Env.getCtx(), Table_ID), "AD_Tab_ID=? AND Action=?", trxName);
Query query = new Query(Env.getCtx(), MTable.get(Env.getCtx(), Table_ID), "AD_Tab_ID=? AND Action=? AND AD_Process_ID IS NOT NULL", trxName);
List<MToolBarButton> list = query.setParameters(AD_Tab_ID, "W").setOnlyActiveRecords(true)
.setOrderBy("SeqNo").list();
if (list != null && !list.isEmpty()) {

View File

@ -35,6 +35,7 @@ public class MToolBarButtonRestrict extends X_AD_ToolBarButtonRestrict
+ " AND AD_Client_ID IN (0, ?)"
+ " AND (AD_Role_ID IS NULL OR AD_Role_ID = ?)"
+ " AND (AD_Window_ID IS NULL OR (Action='W' AND AD_Window_ID=?))"
+ " AND AD_Tab_ID IS NULL"
+ " AND AD_ToolBarButton_ID IN"
+ " (SELECT AD_ToolBarButton_ID FROM AD_ToolBarButton WHERE AD_Tab_ID IS NULL AND IsActive='Y' AND Action=?)";
@ -45,7 +46,7 @@ public class MToolBarButtonRestrict extends X_AD_ToolBarButtonRestrict
+ " AND AD_ToolBarButton_ID IN"
+ " (SELECT AD_ToolBarButton_ID FROM AD_ToolBarButton WHERE AD_Tab_ID IS NULL AND IsActive='Y' AND Action=?)";
private static final String GET_OF_TAB_SQL = "SELECT AD_ToolBarButton_ID FROM AD_ToolBarButtonRestrict WHERE IsActive = 'Y'"
private static final String GET_PROCESS_BUTTON_OF_TAB_SQL = "SELECT AD_ToolBarButton_ID FROM AD_ToolBarButtonRestrict WHERE IsActive = 'Y'"
+ " AND AD_Client_ID IN (0, ?)"
+ " AND (AD_Role_ID IS NULL OR AD_Role_ID = ?)"
+ " AND Action='W'"
@ -53,6 +54,13 @@ public class MToolBarButtonRestrict extends X_AD_ToolBarButtonRestrict
+ " (SELECT AD_ToolBarButton_ID FROM AD_ToolBarButton WHERE AD_Tab_ID=?"
+ " AND AD_Process_ID IS NOT NULL AND IsActive='Y' AND Action='W')";
private static final String GET_OF_TAB_SQL = "SELECT AD_ToolBarButton_ID FROM AD_ToolBarButtonRestrict WHERE IsActive = 'Y'"
+ " AND AD_Client_ID IN (0, ?)"
+ " AND (AD_Role_ID IS NULL OR AD_Role_ID = ?)"
+ " AND AD_Window_ID=?"
+ " AND AD_Tab_ID=?"
+ " AND AD_ToolBarButton_ID IN"
+ " (SELECT AD_ToolBarButton_ID FROM AD_ToolBarButton WHERE AD_Process_ID IS NULL AND IsActive='Y')";
/**
*
*/
@ -100,10 +108,27 @@ public class MToolBarButtonRestrict extends X_AD_ToolBarButtonRestrict
} // getOfWindow
/**
* Returns a list of restrictions to be applied according to the role, the window of the form ...
* Returns a list of restrictions to be applied according to the role, the tab of the window ...
* @param ctx
* @param AD_Role_ID
* @param AD_Window_ID
* @param AD_Tab_ID
* @param trxName
**/
public static int[] getOfTab(Properties ctx, int AD_Role_ID, int AD_Window_ID, int AD_Tab_ID, String trxName)
{
if (s_log.isLoggable(Level.INFO)) s_log.info("sql="+GET_OF_TAB_SQL);
int[] ids = DB.getIDsEx(trxName, GET_OF_TAB_SQL, Env.getAD_Client_ID(ctx), AD_Role_ID, AD_Window_ID, AD_Tab_ID);
return ids;
} // getOfWindow
/**
* Returns a list of restrictions to be applied according to the role, the report/process ...
* @param ctx
* @param AD_Role_ID
* @param AD_Process_ID
* @param trxName
**/
public static int[] getOfReport(Properties ctx, int AD_Role_ID, int AD_Process_ID, String trxName)
@ -115,12 +140,18 @@ public class MToolBarButtonRestrict extends X_AD_ToolBarButtonRestrict
return ids;
} // getOf
/** Returns a list of restrictions to be applied according to the role for ad_tab toolbar buttons **/
public static int[] getOfTab(Properties ctx, int AD_Role_ID, int AD_Tab_ID, String trxName)
/**
* Returns a list of restrictions to be applied according to the role for tab process toolbar buttons
* @param ctx
* @param AD_Role_ID
* @param AD_Tab_ID
* @param trxName
**/
public static int[] getProcessButtonOfTab(Properties ctx, int AD_Role_ID, int AD_Tab_ID, String trxName)
{
if (s_log.isLoggable(Level.INFO)) s_log.info("sql="+GET_OF_TAB_SQL);
if (s_log.isLoggable(Level.INFO)) s_log.info("sql="+GET_PROCESS_BUTTON_OF_TAB_SQL);
int[] ids = DB.getIDsEx(trxName, GET_OF_TAB_SQL, Env.getAD_Client_ID(ctx), AD_Role_ID, AD_Tab_ID);
int[] ids = DB.getIDsEx(trxName, GET_PROCESS_BUTTON_OF_TAB_SQL, Env.getAD_Client_ID(ctx), AD_Role_ID, AD_Tab_ID);
return ids;
} // getOfTab

View File

@ -622,14 +622,14 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer
private void loadToolbarButtons() {
//get extra toolbar process buttons
MToolBarButton[] mToolbarButtons = MToolBarButton.getOfTab(gridTab.getAD_Tab_ID(), null);
MToolBarButton[] mToolbarButtons = MToolBarButton.getProcessButtonOfTab(gridTab.getAD_Tab_ID(), null);
for(MToolBarButton mToolbarButton : mToolbarButtons) {
ToolbarProcessButton toolbarProcessButton = new ToolbarProcessButton(mToolbarButton, this, windowPanel, windowNo);
toolbarProcessButtons.add(toolbarProcessButton);
}
if (toolbarProcessButtons.size() > 0) {
int ids[] = MToolBarButtonRestrict.getOfTab(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()), gridTab.getAD_Tab_ID(), null);
int ids[] = MToolBarButtonRestrict.getProcessButtonOfTab(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()), gridTab.getAD_Tab_ID(), null);
if (ids != null && ids.length > 0) {
for(int id : ids) {
X_AD_ToolBarButton tbt = new X_AD_ToolBarButton(Env.getCtx(), id, null);

View File

@ -18,6 +18,10 @@
package org.adempiere.webui.adwindow;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.adempiere.webui.desktop.IDesktop;
@ -25,7 +29,11 @@ import org.adempiere.webui.part.AbstractUIPart;
import org.adempiere.webui.session.SessionManager;
import org.compiere.model.MImage;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MToolBarButtonRestrict;
import org.compiere.model.X_AD_ToolBarButton;
import org.compiere.util.CCache;
import org.compiere.util.Env;
import org.zkoss.image.AImage;
import org.zkoss.zk.ui.Component;
@ -51,6 +59,10 @@ public class ADWindow extends AbstractUIPart
private static final CCache<Integer, AImage> imageCache = new CCache<Integer, AImage>(null, "WindowImageCache", 5, false);
private Map<Integer, List<String>> tabToolbarRestricMap = new HashMap<Integer, List<String>>();
private List<String> windowToolbarRestrictList = null;
/**
*
* @param ctx
@ -149,6 +161,44 @@ public class ADWindow extends AbstractUIPart
return windowContent;
}
public List<String> getTabToolbarRestrictList(int AD_Tab_ID) {
List<String> tabRestrictList = tabToolbarRestricMap.get(AD_Tab_ID);
if (tabRestrictList == null) {
tabRestrictList = new ArrayList<String>();
tabToolbarRestricMap.put(AD_Tab_ID, tabRestrictList);
int[] restrictionList = MToolBarButtonRestrict.getOfTab(Env.getCtx(), MRole.getDefault().getAD_Role_ID(),
adWindowId, AD_Tab_ID, null);
for (int i = 0; i < restrictionList.length; i++)
{
int ToolBarButton_ID= restrictionList[i];
X_AD_ToolBarButton tbt = new X_AD_ToolBarButton(Env.getCtx(), ToolBarButton_ID, null);
String restrictName = ADWindowToolbar.BTNPREFIX + tbt.getComponentName();
tabRestrictList.add(restrictName);
}
}
return tabRestrictList;
}
public List<String> getWindowToolbarRestrictList() {
if (windowToolbarRestrictList == null) {
//load window restriction
windowToolbarRestrictList = new ArrayList<String>();
int[] restrictionList = MToolBarButtonRestrict.getOfWindow(Env.getCtx(), MRole.getDefault().getAD_Role_ID(), adWindowId, false, null);
for (int i = 0; i < restrictionList.length; i++)
{
int ToolBarButton_ID= restrictionList[i];
X_AD_ToolBarButton tbt = new X_AD_ToolBarButton(Env.getCtx(), ToolBarButton_ID, null);
String restrictName = ADWindowToolbar.BTNPREFIX + tbt.getComponentName();
windowToolbarRestrictList.add(restrictName);
} // All restrictions
}
return windowToolbarRestrictList;
}
/**
*
* @param windowNo

View File

@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.base.IServiceHolder;
@ -36,10 +35,9 @@ import org.adempiere.webui.event.ToolbarListener;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager;
import org.adempiere.webui.window.FDialog;
import org.compiere.model.GridTab;
import org.compiere.model.MRole;
import org.compiere.model.MToolBarButton;
import org.compiere.model.MToolBarButtonRestrict;
import org.compiere.model.X_AD_ToolBarButton;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Msg;
@ -73,7 +71,7 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
*/
private static final long serialVersionUID = 3390505814516682801L;
private static final String BTNPREFIX = "Btn";
public static final String BTNPREFIX = "Btn";
private static CLogger log = CLogger.getCLogger(ADWindowToolbar.class);
@ -577,22 +575,12 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
if (ToolBarMenuRestictionLoaded)
return;
Properties m_ctx = Env.getCtx();
ADWindow adwindow = ADWindow.findADWindow(this);
List<String> restrictionList = adwindow.getWindowToolbarRestrictList();
int ToolBarButton_ID = 0;
int[] restrictionList = MToolBarButtonRestrict.getOfWindow(m_ctx, MRole.getDefault().getAD_Role_ID(), AD_Window_ID, false, null);
if (log.isLoggable(Level.INFO))
log.info("restrictionList="+restrictionList.toString());
for (int i = 0; i < restrictionList.length; i++)
for (String restrictName : restrictionList)
{
ToolBarButton_ID= restrictionList[i];
X_AD_ToolBarButton tbt = new X_AD_ToolBarButton(m_ctx, ToolBarButton_ID, null);
String restrictName = BTNPREFIX + tbt.getComponentName();
if (log.isLoggable(Level.CONFIG)) log.config("tbt="+tbt.getAD_ToolBarButton_ID() + " / " + restrictName);
for (Component p = this.getFirstChild(); p != null; p = p.getNextSibling()) {
if (p instanceof ToolBarButton) {
if ( restrictName.equals(((ToolBarButton)p).getName()) ) {
@ -656,6 +644,33 @@ public class ADWindowToolbar extends FToolbar implements EventListener<Event>
for(ToolbarCustomButton toolbarCustomBtn : toolbarCustomButtons) {
toolbarCustomBtn.dynamicDisplay();
}
ADWindow adwindow = ADWindow.findADWindow(this);
GridTab gridTab = adwindow.getADWindowContent().getActiveGridTab();
if (gridTab != null) {
int AD_Tab_ID = gridTab.getAD_Tab_ID();
List<String> restrictionList = adwindow.getTabToolbarRestrictList(AD_Tab_ID);
for (Component p = this.getFirstChild(); p != null; p = p.getNextSibling()) {
if (p instanceof ToolBarButton) {
if (!p.isVisible())
p.setVisible(true);
}
}
for (String restrictName : restrictionList)
{
for (Component p = this.getFirstChild(); p != null; p = p.getNextSibling()) {
if (p instanceof ToolBarButton) {
if ( restrictName.equals(((ToolBarButton)p).getName()) ) {
p.setVisible(false);
break;
}
}
}
}
}
}
@Override

View File

@ -4,6 +4,7 @@
package org.adempiere.webui.adwindow;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.adempiere.webui.LayoutUtils;
@ -45,6 +46,14 @@ import org.zkoss.zul.Toolbar;
*/
public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
private static final String BTN_PROCESS_ID = "BtnProcess";
private static final String BTN_DELETE_ID = "BtnDelete";
private static final String BTN_EDIT_ID = "BtnEdit";
private static final String BTN_NEW_ID = "BtnNew";
private static final String TABBOX_ONSELECT_ATTRIBUTE = "detailpane.tabbox.onselect";
public static final String ON_POST_SELECT_TAB_EVENT = "onPostSelectTab";
@ -82,7 +91,7 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
public static final String ON_NEW_EVENT = "onNew";
public static final String ON_EDIT_EVENT = "onEdit";
public DetailPane() {
tabbox = new Tabbox();
tabbox.setParent(this);
@ -105,6 +114,7 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
addEventListener(LayoutUtils.ON_REDRAW_EVENT, this);
setId("detailPane");
}
/**
@ -245,7 +255,7 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
button = new ToolBarButton();
button.setImage(ThemeManager.getThemeResource(NEW_IMAGE));
button.setId("BtnNew");
button.setId(BTN_NEW_ID);
toolbar.appendChild(button);
button.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override
@ -257,7 +267,7 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
button = new ToolBarButton();
button.setImage(ThemeManager.getThemeResource(EDIT_IMAGE));
button.setId("BtnEdit");
button.setId(BTN_EDIT_ID);
toolbar.appendChild(button);
button.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override
@ -269,7 +279,7 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
button = new ToolBarButton();
button.setImage(ThemeManager.getThemeResource(DELETE_IMAGE));
button.setId("BtnDelete");
button.setId(BTN_DELETE_ID);
toolbar.appendChild(button);
button.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override
@ -283,7 +293,7 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
if (!tabPanel.getGridTab().isSortTab()) {
button = new ToolBarButton();
button.setImage(ThemeManager.getThemeResource(PROCESS_IMAGE));
button.setId("BtnProcess");
button.setId(BTN_PROCESS_ID);
toolbar.appendChild(button);
button.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
@Override
@ -542,21 +552,30 @@ public class DetailPane extends Panel implements EventListener<Event>, IdSpace {
}
boolean enableNew = !changed && insertRecord && !adtab.getGridTab().isSortTab();
boolean enableDelete = !changed && !readOnly && !adtab.getGridTab().isSortTab();
String newImage = ThemeManager.getThemeResource(NEW_IMAGE);
String deleteImage = ThemeManager.getThemeResource(DELETE_IMAGE);
String editImage = ThemeManager.getThemeResource(EDIT_IMAGE);
ADWindow adwindow = ADWindow.findADWindow(this);
List<String> tabRestrictList = adwindow.getTabToolbarRestrictList(adtab.getGridTab().getAD_Tab_ID());
List<String> windowRestrictList = adwindow.getWindowToolbarRestrictList();
for(Component c : toolbar.getChildren()) {
if (c instanceof ToolBarButton) {
ToolBarButton btn = (ToolBarButton) c;
if (newImage.equals(btn.getImage())) {
if (BTN_NEW_ID.equals(btn.getId())) {
btn.setDisabled(!enableNew);
} else if (deleteImage.equals(btn.getImage())) {
} else if (BTN_DELETE_ID.equals(btn.getId())) {
btn.setDisabled(!enableDelete);
} else if (editImage.equals(btn.getImage())) {
} else if (BTN_EDIT_ID.equals(btn.getId())) {
btn.setDisabled(false);
}
if (windowRestrictList.contains(btn.getId())) {
btn.setVisible(false);
} else if (tabRestrictList.contains(btn.getId())) {
btn.setVisible(false);
} else {
btn.setVisible(true);
}
}
}
}
}
private void updateProcessToolbar() {