AD_UserPreference context values not available for Window Logic

84 views
Skip to first unread message

Andy Conn

unread,
Feb 16, 2017, 12:39:21 PM2/16/17
to iDempiere
I have created a AD_UserPreference column "ShowAdvancedFields" which would allow users to view advanced Window fields that would otherwise be hidden.

"ShowAdvancedFields == Y" is inserted into the context. However, Window field DisplayLogic cannot access this (e.g. @ShowAdvancedFields@='Y') because the context variable does not start with "$" or "#" (see Env.GetContext ).

Can this be fixed (e.g. put the insert the user preferences prefixed with #) or can anybody recommend an improved approach? I would like an easy way for users to toggle Easy/Advanced versions of windows.

Thanks,

Andy

Carlos Antonio Ruiz Gomez

unread,
Feb 16, 2017, 12:56:40 PM2/16/17
to idem...@googlegroups.com
Are you planning to use the AD_Field.IsAdvancedField flag? If that's
the case is not recommended, that's a flag intended for fields that
compromise security, so just Advanced (this is entrusted IT) users can
use those fields.


El 16/02/17 a las 18:39, Andy Conn escribió:

Andy Conn

unread,
Feb 16, 2017, 1:51:31 PM2/16/17
to idem...@googlegroups.com
No Carlos. I was hoping to simply use  @ShowAdvancedFields@='Y' in DisplayLogic. For normal use the user would see simplified windows but could view advanced fields if desired.

I did notice a @ShowAdvanced@ variable. Maybe a better name for my preferences field would be @ShowSimplifiedWindow@

Regardless, what's there best approach or can user preference variables be changed for access by Window  logic?
 
--
You received this message because you are subscribed to a topic in the Google Groups "iDempiere" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/idempiere/r_wDJe5HGos/unsubscribe.
To unsubscribe from this group and all its topics, send an email to idempiere+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/idempiere/dcf64400-3842-e90a-c19f-c238f9f847e7%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Andy Conn

unread,
Feb 16, 2017, 4:51:28 PM2/16/17
to iDempiere
I have written the following event handler plugin to load the user preferences as #UserPreference_{field} into the context. This allows them to be referenced in Window logic.

Can someone please comment whether there are any dangers/concerns with this approach? Thanks!

public class EventHandler extends AbstractEventHandler {

private static CLogger log = CLogger.getCLogger(EventHandler.class);

public EventHandler() {
// TODO Auto-generated constructor stub
}

@Override
protected void initialize() {
registerEvent(IEventTopics.AFTER_LOGIN);
registerTableEvent(IEventTopics.PO_AFTER_CHANGE, I_AD_UserPreference.Table_Name);
}
protected void doHandleEvent(Event event) {
if (event.getTopic().equals(IEventTopics.AFTER_LOGIN)){
setupUserPreferences();
} else if (event.getTopic().equals(IEventTopics.PO_AFTER_CHANGE)){
setupUserPreferences();
//PO po = getPO(event);
//log.info(" topics="+event.getTopic()+" po="+po);
}
};

void setupUserPreferences(){
// Add AD_UserPreferences to the context:
Map<String,Object> newEntries = new HashMap<String, Object>();
for (Entry<Object,Object> entry : Env.getCtx().entrySet()){
String key = (String)entry.getKey();
if (key.startsWith("P|")){
String splitter[] = key.split("[|]");
newEntries.put("#UserPreference_"+splitter[1], entry.getValue());
}
}
for (Entry<String,Object> entry : newEntries.entrySet()){
if (entry.getValue() instanceof String){
Env.setContext(Env.getCtx(), entry.getKey(), (String)entry.getValue());
} else if (entry.getValue() instanceof Integer) {
Env.setContext(Env.getCtx(), entry.getKey(), (Integer)entry.getValue());
} else if (entry.getValue() instanceof Boolean) {
Env.setContext(Env.getCtx(), entry.getKey(), (Boolean)entry.getValue());
} else if (entry.getValue() instanceof Timestamp) {
Env.setContext(Env.getCtx(), entry.getKey(), (Timestamp)entry.getValue());
}
}
}
}

To unsubscribe from this group and all its topics, send an email to idempiere+unsubscribe@googlegroups.com.

Carlos Antonio Ruiz Gomez

unread,
Feb 17, 2017, 1:08:14 AM2/17/17
to idem...@googlegroups.com
Andy, I don't understand what you're doing.

After implementation of IDEMPIERE-2556 you don't need to add code to manage a user preference, please check:
http://wiki.idempiere.org/en/NF3.0_User_Preference

I think the user preference can be accessed in context using P| prefix, like @P|ToggleOnDoubleClick@

Regards,

Carlos Ruiz


El 16/02/17 a las 22:51, Andy Conn escribió:

Andy Conn

unread,
Feb 17, 2017, 9:36:02 AM2/17/17
to iDempiere
Indeed you cannot use @P|ToggleOnDoubleClick@ in Window logic because it gets tokenized by "|" in Evaluator.evaluateLogic(source,logic) because it assumes it is a logic operator:

StringTokenizer st = new StringTokenizer(logic.trim(), "&|", true);


Evaluator.evaluateLogic(source,logic) would have to be adjusted to account for "P|" prefix and also Env.getContext (ctx,WindowNo,context,onlyWindow) because it assumes any non "#" or "$" prefixed variable is a window variable. I think it would be an ugly fix.  

Ideally it would be must cleaner for the UserPreferences to be inserted into context prefixed by # (withtout P|) in the first place.

Carlos Antonio Ruiz Gómez

unread,
Feb 17, 2017, 2:04:22 PM2/17/17
to iDempiere
Andy, I find this idea very interesting.

Opened a ticket IDEMPIERE-3302 and attached a patch there - in my tests it worked fine, just he user needs to push the refresh button to read the new context value from preference.

So, your idea is to add a new column like IsSimpleField on AD_Column, AD_Field and AD_UserDef_Field ?
I think this can be very interesting for core.

Regards,

Carlos Ruiz

Andy Conn

unread,
Feb 17, 2017, 3:47:12 PM2/17/17
to iDempiere
UserPreference and Display Logic will work for my purposes but if you wanted this kind of functionality in the core I think your suggestion of a Yes/No field would be more elegant. Since most fields probably are "Simple" I'm not sure I'd use "IsSimpleModeHidden". Maybe "IsSimpleModeHidden"; that way you'd only have to set Yes on the advanced fields.

If you are considering something like this for the core, you might also consider expanding the idea to hide fields based on user Role and maybe by an Industry setting on the Client.

Thanks Carlos!

Carlos Antonio Ruiz Gomez

unread,
Feb 17, 2017, 3:55:57 PM2/17/17
to idem...@googlegroups.com
Andy,

> you might also consider expanding the idea to hide fields based on user Role

This can be done actually configuring Window Customization


> and maybe by an Industry setting on the Client.

This can be done configuring ASP Levels

Regards,

Carlos Ruiz


El 17/02/17 a las 21:47, Andy Conn escribió:

Andy Conn

unread,
Feb 17, 2017, 3:57:19 PM2/17/17
to idem...@googlegroups.com
Ah ha very good! I am still learning the system :) Awesome job on the OSGI plugin system BTW

--
You received this message because you are subscribed to a topic in the Google Groups "iDempiere" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/idempiere/r_wDJe5HGos/unsubscribe.
To unsubscribe from this group and all its topics, send an email to idempiere+unsubscribe@googlegroups.com.

Andy Conn

unread,
Feb 20, 2017, 9:47:42 AM2/20/17
to iDempiere
Carlos, while on the subject, I think it would also be super cool if the concept could also apply to menu items.

Andy Conn

unread,
Feb 20, 2017, 10:04:10 AM2/20/17
to idem...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages