« [Article] Working with record objects | Main | [Article] Alternatives to Using Global Dataproviders »
August 23, 2007
[Tip] Popping UP the popupmenu plugin
by David Workman
Data Mosaic
The popupmenu plugin only displays a menu below the button object you assign it to. If your button is at the bottom of the screen or a list, popping the window up instead of down is much more desirable.
You can get this effect by adding a second invisible button directly behind your triggering button. In the trigger method move this invisible button up the vertical axis an amount equal to the button size plus number of menu items. Then drop the popupmenu window down from this invisible button. At the end of the trigger method, return the invisible button to its original position.
You can use this method to pop up the menu window at any position on a form from the triggered button. This is somewhat of a hack but it's easy and it works great!
Method: F_DROP_filter
/*****
pop the menu UP instead of the default down
uses a secondary invisible object on the layout which is behind the clicked button
move secondary object up far enough to drop down a popup that hits the top edge
of clicked btn
when menu item is selected, return secondary object to original location
*****/
//get menu list from a value list
var dataset = application.getValueListItems("REF_indent")
var valueList = dataset.getColumnAsArray(1)
valueList.unshift("<html><b>All","---")
//build menu
var menu = new Array
for ( var i = 0 ; i < valueList.length ; i++ ) {
menu[i] = plugins.popupmenu.createCheckboxMenuItem(valueList[i] + "", F_DROP_filter_control)
}
//move invisible button up to correct location
var lineHeight = 16 //adjust for font size
var topShift = 18 //adjust for graphic trigger size
var btnInvisible = application.getMethodTriggerElementName() + "_up"
var currentLocationX = elements[btnInvisible].getLocationX()
var currentLocationY = elements[btnInvisible].getLocationY()
elements[btnInvisible].setLocation(currentLocationX, currentLocationY - (topShift + (menu.length * lineHeight)))
//set menu method arguments and check mark
var x = 0
while (menu[x])
{
//pass arguments
menu[x].setMethodArguments(menu[x].text)
//set check mark
if (globals.REF_D_check_mark == menu[x].text) {
menu[x].setSelected(true)
}
else {
menu[x].setSelected(false)
}
x++
}
//trigger popup to invisible button, not clicked button
var elem = elements[btnInvisible]
if (elem != null)
{
plugins.popupmenu.showPopupMenu(elem, menu);
}
//set invisible btn back to original location
elements[btnInvisible].setLocation(currentLocationX, currentLocationY)
Method: F_DROP_filter_control
//filter list by passed variable
globals.REF_D_check_mark = arguments[0]
if (arguments[0] != "<html><b>All") {
controller.find()
indentation = arguments[0]
controller.search()
}
else {
controller.loadAllRecords()
}
| Posted by David Workman on August 23, 2007 at 11:07 PM in Tips | Permalink
Comments
Hi David,
you can set the position of the popup by passing the x,y coordinates to the showPopupMenu function,
avoiding to use a hidden control (unfortunatly this is not documented in the plugin - it will be in the next versions)
plugins.popupmenu.showPopupMenu(x, y, menu);
in the next version of the popupmenu plugin we will fix this
issue with correct positioning, so you won't need to do extra coding.
at the end, if you find issues or want to propose new features for Servoy, don't hesitate to post them here : http://crm.servoy.com/servoy-webclient/solutions/solution/servoy_support
Best regards!
Posted by: Gabi Boros | Aug 28, 2007 10:46:52 AM
Nice! No complaints about having this technique discarded so fast.
Posted by: David Workman | Aug 28, 2007 11:02:59 PM
Nice workaround, even better that this will be solved soon!
BTW the IT2Be Menubar plug-in popup does not have this issue :)
Posted by: IT2Be | Sep 23, 2007 1:49:48 PM
The x,y coordinate setting is still bugged in v3.5.1 so we're still using this tip for now. Glad to hear your plugin has this figured out Marcel!
Posted by: David Workman | Sep 25, 2007 10:03:50 AM