IDEMPIERE-4713 Allow definition of context variables to inject on menu and window definition (#600)

* IDEMPIERE-4713 Allow definition of context variables to inject on menu and window definition

* * Implement prefix "+" as suggested by @hengsin
* Clear the variable

* * Fix scope of methods and fix interface as suggested by @hengsin

* * Implement changes suggested by @hengsin
* Add control for clicking on new button on Favourites and menu
This commit is contained in:
Carlos Ruiz 2021-02-23 16:24:39 +01:00 committed by GitHub
parent ed68a01c74
commit 47f7180eff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 293 additions and 24 deletions

View File

@ -0,0 +1,55 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-4713 Allow definition of context variables to inject on menu and window definition
-- Feb 19, 2021, 7:13:25 PM CET
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,Help,PrintName,EntityType,AD_Element_UU) VALUES (203475,0,0,'Y',TO_DATE('2021-02-19 19:12:32','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-02-19 19:12:32','YYYY-MM-DD HH24:MI:SS'),100,'PredefinedContextVariables','Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',NULL,'Predefined Context Variables','D','901ebd74-5da3-4686-b327-8e759a72b544')
;
-- Feb 19, 2021, 7:15:30 PM CET
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (214411,0,'Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',116,'PredefinedContextVariables',4000,'N','N','N','N','N',0,'N',10,0,0,'Y',TO_DATE('2021-02-19 19:15:29','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-02-19 19:15:29','YYYY-MM-DD HH24:MI:SS'),100,203475,'Y','N','D','N','N','N','Y','0863f890-c2be-44a8-88cd-9772d1c2e5d2','Y',0,'N','N','N')
;
-- Feb 19, 2021, 7:15:59 PM CET
ALTER TABLE AD_Menu ADD PredefinedContextVariables VARCHAR2(4000 CHAR) DEFAULT NULL
;
-- Feb 19, 2021, 7:16:18 PM CET
INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (206595,'Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',110,214411,'Y',4000,190,'N','N','N','N',0,0,'Y',TO_DATE('2021-02-19 19:16:18','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-02-19 19:16:18','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','b2f36f4b-1058-4f1c-a55c-be9cbd00a363','Y',190,5)
;
-- Feb 19, 2021, 7:16:52 PM CET
UPDATE AD_Field SET AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, NumLines=4, IsToolbarButton=NULL,Updated=TO_DATE('2021-02-19 19:16:52','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206595
;
-- Feb 19, 2021, 7:17:35 PM CET
UPDATE AD_Field SET DisplayLogic='@IsSummary@=N', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2021-02-19 19:17:35','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206595
;
-- Feb 19, 2021, 7:18:18 PM CET
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,FKConstraintType,IsHtml) VALUES (214412,0,'Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',105,'PredefinedContextVariables',4000,'N','N','N','N','N',0,'N',10,0,0,'Y',TO_DATE('2021-02-19 19:18:17','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-02-19 19:18:17','YYYY-MM-DD HH24:MI:SS'),100,203475,'Y','N','D','N','N','N','Y','56b9d393-46d3-468b-bdcd-0c5a6088aed4','Y',0,'N','N','N','N')
;
-- Feb 19, 2021, 7:18:39 PM CET
ALTER TABLE AD_Window ADD PredefinedContextVariables VARCHAR2(4000 CHAR) DEFAULT NULL
;
-- Feb 19, 2021, 7:19:45 PM CET
INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (206596,'Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',105,214412,'Y',4000,180,'N','N','N','N',0,0,'Y',TO_DATE('2021-02-19 19:19:45','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-02-19 19:19:45','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','8d645d35-c38f-4c73-a0ab-dfe85f3777b6','Y',160,5)
;
-- Feb 19, 2021, 7:20:00 PM CET
UPDATE AD_Field SET SeqNo=180, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, NumLines=4, IsToolbarButton=NULL,Updated=TO_DATE('2021-02-19 19:20:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206596
;
-- Feb 19, 2021, 7:20:00 PM CET
UPDATE AD_Field SET SeqNo=0, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2021-02-19 19:20:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202514
;
-- Feb 19, 2021, 8:51:44 PM CET
UPDATE AD_Field SET DisplayLogic='@IsSummary@=N & @Action@!T & @Action@!F', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2021-02-19 20:51:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206595
;
SELECT register_migration_script('202102191922_IDEMPIERE-4713.sql') FROM dual
;

View File

@ -0,0 +1,52 @@
-- IDEMPIERE-4713 Allow definition of context variables to inject on menu and window definition
-- Feb 19, 2021, 7:13:25 PM CET
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,Description,Help,PrintName,EntityType,AD_Element_UU) VALUES (203475,0,0,'Y',TO_TIMESTAMP('2021-02-19 19:12:32','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-02-19 19:12:32','YYYY-MM-DD HH24:MI:SS'),100,'PredefinedContextVariables','Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',NULL,'Predefined Context Variables','D','901ebd74-5da3-4686-b327-8e759a72b544')
;
-- Feb 19, 2021, 7:15:30 PM CET
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (214411,0,'Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',116,'PredefinedContextVariables',4000,'N','N','N','N','N',0,'N',10,0,0,'Y',TO_TIMESTAMP('2021-02-19 19:15:29','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-02-19 19:15:29','YYYY-MM-DD HH24:MI:SS'),100,203475,'Y','N','D','N','N','N','Y','0863f890-c2be-44a8-88cd-9772d1c2e5d2','Y',0,'N','N','N')
;
-- Feb 19, 2021, 7:15:59 PM CET
ALTER TABLE AD_Menu ADD COLUMN PredefinedContextVariables VARCHAR(4000) DEFAULT NULL
;
-- Feb 19, 2021, 7:16:18 PM CET
INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (206595,'Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',110,214411,'Y',4000,190,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2021-02-19 19:16:18','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-02-19 19:16:18','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','b2f36f4b-1058-4f1c-a55c-be9cbd00a363','Y',190,5)
;
-- Feb 19, 2021, 7:16:52 PM CET
UPDATE AD_Field SET AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, NumLines=4, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-19 19:16:52','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206595
;
-- Feb 19, 2021, 7:17:35 PM CET
UPDATE AD_Field SET DisplayLogic='@IsSummary@=N', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-19 19:17:35','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206595
;
-- Feb 19, 2021, 7:18:18 PM CET
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,FKConstraintType,IsHtml) VALUES (214412,0,'Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',105,'PredefinedContextVariables',4000,'N','N','N','N','N',0,'N',10,0,0,'Y',TO_TIMESTAMP('2021-02-19 19:18:17','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-02-19 19:18:17','YYYY-MM-DD HH24:MI:SS'),100,203475,'Y','N','D','N','N','N','Y','56b9d393-46d3-468b-bdcd-0c5a6088aed4','Y',0,'N','N','N','N')
;
-- Feb 19, 2021, 7:18:39 PM CET
ALTER TABLE AD_Window ADD COLUMN PredefinedContextVariables VARCHAR(4000) DEFAULT NULL
;
-- Feb 19, 2021, 7:19:45 PM CET
INSERT INTO AD_Field (AD_Field_ID,Name,Description,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (206596,'Predefined Context Variables','Predefined context variables to inject when opening a menu entry or a window',105,214412,'Y',4000,180,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2021-02-19 19:19:45','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-02-19 19:19:45','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','8d645d35-c38f-4c73-a0ab-dfe85f3777b6','Y',160,5)
;
-- Feb 19, 2021, 7:20:00 PM CET
UPDATE AD_Field SET SeqNo=180, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, NumLines=4, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-19 19:20:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206596
;
-- Feb 19, 2021, 7:20:00 PM CET
UPDATE AD_Field SET SeqNo=0, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-19 19:20:00','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=202514
;
-- Feb 19, 2021, 8:51:44 PM CET
UPDATE AD_Field SET DisplayLogic='@IsSummary@=N & @Action@!T & @Action@!F', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-19 20:51:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206595
;
SELECT register_migration_script('202102191922_IDEMPIERE-4713.sql') FROM dual
;

View File

@ -309,6 +309,19 @@ public interface I_AD_Menu
*/
public String getName();
/** Column name PredefinedContextVariables */
public static final String COLUMNNAME_PredefinedContextVariables = "PredefinedContextVariables";
/** Set Predefined Context Variables.
* Predefined context variables to inject when opening a menu entry or a window
*/
public void setPredefinedContextVariables (String PredefinedContextVariables);
/** Get Predefined Context Variables.
* Predefined context variables to inject when opening a menu entry or a window
*/
public String getPredefinedContextVariables();
/** Column name Updated */
public static final String COLUMNNAME_Updated = "Updated";

View File

@ -236,6 +236,19 @@ public interface I_AD_Window
*/
public String getName();
/** Column name PredefinedContextVariables */
public static final String COLUMNNAME_PredefinedContextVariables = "PredefinedContextVariables";
/** Set Predefined Context Variables.
* Predefined context variables to inject when opening a menu entry or a window
*/
public void setPredefinedContextVariables (String PredefinedContextVariables);
/** Get Predefined Context Variables.
* Predefined context variables to inject when opening a menu entry or a window
*/
public String getPredefinedContextVariables();
/** Column name Processing */
public static final String COLUMNNAME_Processing = "Processing";

View File

@ -30,7 +30,7 @@ public class X_AD_Menu extends PO implements I_AD_Menu, I_Persistent
/**
*
*/
private static final long serialVersionUID = 20201220L;
private static final long serialVersionUID = 20210219L;
/** Standard Constructor */
public X_AD_Menu (Properties ctx, int AD_Menu_ID, String trxName)
@ -478,4 +478,21 @@ public class X_AD_Menu extends PO implements I_AD_Menu, I_Persistent
{
return new KeyNamePair(get_ID(), getName());
}
/** Set Predefined Context Variables.
@param PredefinedContextVariables
Predefined context variables to inject when opening a menu entry or a window
*/
public void setPredefinedContextVariables (String PredefinedContextVariables)
{
set_Value (COLUMNNAME_PredefinedContextVariables, PredefinedContextVariables);
}
/** Get Predefined Context Variables.
@return Predefined context variables to inject when opening a menu entry or a window
*/
public String getPredefinedContextVariables ()
{
return (String)get_Value(COLUMNNAME_PredefinedContextVariables);
}
}

View File

@ -30,7 +30,7 @@ public class X_AD_Window extends PO implements I_AD_Window, I_Persistent
/**
*
*/
private static final long serialVersionUID = 20201220L;
private static final long serialVersionUID = 20210219L;
/** Standard Constructor */
public X_AD_Window (Properties ctx, int AD_Window_ID, String trxName)
@ -323,6 +323,23 @@ public class X_AD_Window extends PO implements I_AD_Window, I_Persistent
return new KeyNamePair(get_ID(), getName());
}
/** Set Predefined Context Variables.
@param PredefinedContextVariables
Predefined context variables to inject when opening a menu entry or a window
*/
public void setPredefinedContextVariables (String PredefinedContextVariables)
{
set_Value (COLUMNNAME_PredefinedContextVariables, PredefinedContextVariables);
}
/** Get Predefined Context Variables.
@return Predefined context variables to inject when opening a menu entry or a window
*/
public String getPredefinedContextVariables ()
{
return (String)get_Value(COLUMNNAME_PredefinedContextVariables);
}
/** Set Process Now.
@param Processing Process Now */
public void setProcessing (boolean Processing)

View File

@ -2090,6 +2090,8 @@ public final class Env
/** New Line */
public static final String NL = System.getProperty("line.separator");
/* Prefix for predefined context variables coming from menu or window definition */
private static final String PREFIX_PREDEFINED_VARIABLE = "+";
/**
@ -2101,4 +2103,37 @@ public final class Env
getCtx().put(LANGUAGE, Language.getBaseAD_Language());
} // static
/**
* Add in context predefined variables with prefix +, coming from menu or window definition
* Predefined variables must come separated by new lines in one of the formats:
* VAR=VALUE
* VAR="VALUE"
* VAR='VALUE'
* The + prefix is not required, is added here to the defined variables
* @param ctx
* @param windowNo
* @param predefinedVariables
*/
public static void setPredefinedVariables(Properties ctx, int windowNo, String predefinedVariables) {
if (predefinedVariables != null) {
String[] lines = predefinedVariables.split("\n");
for (String line : lines) {
int idxEq = line.indexOf("=");
if (idxEq > 0) {
String var = line.substring(0, idxEq).trim();
if (var.length() > 0) {
String value = line.substring(idxEq+1).trim();
if ( (value.startsWith("\"") && value.endsWith("\""))
|| (value.startsWith("'") && value.endsWith("'") )
) {
value = value.substring(1, value.length()-1);
}
Env.setContext(ctx, windowNo, PREFIX_PREDEFINED_VARIABLE + var, value);
}
}
}
}
}
} // Env

View File

@ -87,8 +87,10 @@ public class ADWindow extends AbstractUIPart
this.ctx = ctx;
this.adWindowId = adWindowId;
this.adWindowUUID = MWindow.get(ctx, adWindowId).getAD_Window_UU();
MWindow window = MWindow.get(ctx, adWindowId);
this.adWindowUUID = window.getAD_Window_UU();
windowNo = SessionManager.getAppDesktop().registerWindow(this);
Env.setPredefinedVariables(ctx, windowNo, window.getPredefinedContextVariables());
this.query = query;
try {
init();

View File

@ -118,22 +118,27 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
/**
* Dialog to start a process/report
* @param ctx
* @param parent
* @param title
* @param aProcess
* @param WindowNo
* @param AD_Process_ID
* @param tableId
* @param recordId
* @param autoStart
* @param isSOTrx
*/
public ProcessDialog (int AD_Process_ID, boolean isSOTrx)
{
this(AD_Process_ID, isSOTrx, null);
}
/**
* Dialog to start a process/report
* @param AD_Process_ID
* @param isSOTrx
* @param predefinedContextVariables
*/
public ProcessDialog (int AD_Process_ID, boolean isSOTrx, String predefinedContextVariables)
{
log.info("Process=" + AD_Process_ID );
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
this.setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo);
Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", isSOTrx ? "Y" : "N");
Env.setPredefinedVariables(Env.getCtx(), m_WindowNo, predefinedContextVariables);
try
{
init(Env.getCtx(), m_WindowNo, AD_Process_ID, null, false, false);

View File

@ -19,7 +19,9 @@ import org.adempiere.util.Callback;
import org.adempiere.webui.ClientInfo;
import org.adempiere.webui.adwindow.ADTabpanel;
import org.adempiere.webui.adwindow.ADWindow;
import org.adempiere.webui.desktop.AbstractDesktop;
import org.adempiere.webui.desktop.FavouriteController;
import org.adempiere.webui.desktop.IDesktop;
import org.adempiere.webui.exception.ApplicationException;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager;
@ -315,6 +317,9 @@ public class FavoriteSimpleTreeModel extends SimpleTreeModel implements EventLis
try
{
MMenu menu = (MMenu) MTable.get(Env.getCtx(), MMenu.Table_ID).getPO(menuID, null);
IDesktop desktop = SessionManager.getAppDesktop();
if (desktop instanceof AbstractDesktop)
((AbstractDesktop)desktop).setPredefinedContextVariables(menu.getPredefinedContextVariables());
MQuery query = new MQuery("");
query.addRestriction("1=2");

View File

@ -43,6 +43,8 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
private transient ClientInfo clientInfo;
private String predefinedContextVariables;
@SuppressWarnings("unused")
private static final CLogger logger = CLogger.getCLogger(AbstractDesktop.class);
@ -63,6 +65,10 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
{
MMenu menu = new MMenu(Env.getCtx(), menuId, null);
try
{
setPredefinedContextVariables(menu.getPredefinedContextVariables());
if(menu.getAction().equals(MMenu.ACTION_Window))
{
openWindow(menu.getAD_Window_ID(), null);
@ -92,6 +98,11 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
{
throw new ApplicationException("Menu Action not yet implemented: " + menu.getAction());
}
}
finally
{
setPredefinedContextVariables(null);
}
}
/**
@ -318,4 +329,12 @@ public abstract class AbstractDesktop extends AbstractUIPart implements IDesktop
}
}
public void setPredefinedContextVariables(String predefinedVariables) {
this.predefinedContextVariables = predefinedVariables;
}
protected String getPredefinedContextVariables() {
return this.predefinedContextVariables;
}
}

View File

@ -67,7 +67,8 @@ public abstract class TabbedDesktop extends AbstractDesktop {
* @return ProcessDialog
*/
public ProcessDialog openProcessDialog(int processId, boolean soTrx) {
ProcessDialog pd = new ProcessDialog (processId, soTrx);
ProcessDialog pd = new ProcessDialog (processId, soTrx, getPredefinedContextVariables());
if (pd.isValid()) {
DesktopTabpanel tabPanel = new DesktopTabpanel();
pd.setParent(tabPanel);
@ -86,7 +87,7 @@ public abstract class TabbedDesktop extends AbstractDesktop {
* @return ADWindow
*/
public ADForm openForm(int formId) {
ADForm form = ADForm.openForm(formId);
ADForm form = ADForm.openForm(formId, getPredefinedContextVariables());
if (Window.Mode.EMBEDDED == form.getWindowMode()) {
DesktopTabpanel tabPanel = new DesktopTabpanel();
@ -113,6 +114,7 @@ public abstract class TabbedDesktop extends AbstractDesktop {
InfoPanel infoPanel = InfoManager.create(infoId);
if (infoPanel != null) {
Env.setPredefinedVariables(Env.getCtx(), infoPanel.getWindowNo(), getPredefinedContextVariables());
DesktopTabpanel tabPanel = new DesktopTabpanel();
infoPanel.setParent(tabPanel);
String title = infoPanel.getTitle();
@ -160,11 +162,13 @@ public abstract class TabbedDesktop extends AbstractDesktop {
final DesktopTabpanel tabPanel = new DesktopTabpanel();
String id = AdempiereIdGenerator.escapeId(adWindow.getTitle());
tabPanel.setId(id+"_"+adWindow.getADWindowContent().getWindowNo());
int windowNo = adWindow.getADWindowContent().getWindowNo();
tabPanel.setId(id+"_"+windowNo);
final Tab tab = windowContainer.addWindow(tabPanel, adWindow.getTitle(), true, DecorateInfo.get(adWindow));
tab.setClosable(false);
final OpenWindowRunnable runnable = new OpenWindowRunnable(adWindow, tab, tabPanel, callback);
Env.setPredefinedVariables(Env.getCtx(), windowNo, getPredefinedContextVariables());
preOpenNewTab();
runnable.run();
}

View File

@ -43,9 +43,10 @@ import org.zkoss.zk.ui.event.EventListener;
public abstract class ADForm extends Window implements EventListener<Event>, IHelpContext
{
/**
*
*
*/
private static final long serialVersionUID = -5183711788893823434L;
private static final long serialVersionUID = 1621402409447265196L;
/** The class' logging enabler */
protected static final CLogger logger;
@ -134,30 +135,55 @@ public abstract class ADForm extends Window implements EventListener<Event>, IHe
*/
public static ADForm openForm (int adFormID)
{
return openForm(adFormID, null, null);
return openForm(adFormID, null, null, null);
}
/**
/**
* Open a form based on it's ID with the predefined context variables from menu
*
* @param formId
* @param predefinedContextVariables
* @return The created form
*/
public static ADForm openForm(int formId, String predefinedContextVariables) {
return openForm(formId, null, null, predefinedContextVariables);
}
/**
* Open a form base on it's ID
*
* @param adFormID
* @param gridTab
* @return
* @return The created form
*/
public static ADForm openForm (int adFormID, GridTab gridTab)
{
return openForm(adFormID, gridTab, null);
return openForm(adFormID, gridTab, null, null);
}
/**
* Open a form base on it's ID and a Process Info parameters
*
* @param adFormID
* @param gridTab
* @param pi
* @return The created form
*/
public static ADForm openForm (int adFormID, GridTab gridTab, ProcessInfo pi)
{
return openForm(adFormID, gridTab, pi, null);
}
/**
* Open a form base on it's ID and a Process Info parameters
* Open a form base on it's ID and a Process Info parameters with the predefined context variables from menu
*
* @param adFormID
* @param gridTab
* @param pi
* @return
* @param predefinedContextVariables
* @return The created form
*/
public static ADForm openForm (int adFormID, GridTab gridTab, ProcessInfo pi)
public static ADForm openForm (int adFormID, GridTab gridTab, ProcessInfo pi, String predefinedContextVariables)
{
ADForm form;
MForm mform = new MForm(Env.getCtx(), adFormID, null);
@ -177,6 +203,7 @@ public abstract class ADForm extends Window implements EventListener<Event>, IHe
{
form.gridTab = gridTab;
form.setProcessInfo(pi);
Env.setPredefinedVariables(Env.getCtx(), form.getWindowNo(), predefinedContextVariables);
form.init(adFormID, name);
return form;
}

View File

@ -24,6 +24,8 @@ import org.adempiere.util.Callback;
import org.adempiere.webui.adwindow.ADTabpanel;
import org.adempiere.webui.adwindow.ADWindow;
import org.adempiere.webui.apps.MenuSearchController;
import org.adempiere.webui.desktop.AbstractDesktop;
import org.adempiere.webui.desktop.IDesktop;
import org.adempiere.webui.exception.ApplicationException;
import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager;
@ -313,6 +315,9 @@ public abstract class AbstractMenuPanel extends Panel implements EventListener<E
{
int menuId = Integer.parseInt((String)selectedItem.getValue());
MMenu menu = new MMenu(Env.getCtx(), menuId, null);
IDesktop desktop = SessionManager.getAppDesktop();
if (desktop instanceof AbstractDesktop)
((AbstractDesktop)desktop).setPredefinedContextVariables(menu.getPredefinedContextVariables());
MQuery query = new MQuery("");
query.addRestriction("1=2");