Window Plugin

(part of package 'Servoy Default Services')

You can access it in code via: plugins.window

Properties

API

cancelFormPopup()

Close/cancels the current form popup panel without assigning a value to the configured data provider.

Example:

// Show a form as popup panel, where the closeFormPopup can pass return a value to a dataprovider in the specified scope.
plugins.window.showFormPopup(null,forms.orderPicker,foundset.getSelectedRecord(),"order_id");
// plugins.window.showFormPopup(null,forms.orderPicker,foundset.getSelectedRecord(),"order_id",-1,-1,100,100,true, false, onClose);
//
// function onClose(event) {application.output("Popup closed");}

closeFormPopup(retval)

Close the current form popup panel and assign the value to the configured data provider.

Example:

// Show a form as popup panel, where the closeFormPopup can pass return a value to a dataprovider in the specified scope.
plugins.window.showFormPopup(null,forms.orderPicker,foundset.getSelectedRecord(),"order_id");
// plugins.window.showFormPopup(null,forms.orderPicker,foundset.getSelectedRecord(),"order_id",-1,-1,100,100,true, false, onClose);
//
// function onClose(event) {application.output("Popup closed");}

Parameters:

  • {object} retval Return value for data provider


createFormPopup(form)

Create a form popup that can be filled with data and shown.

Example:

plugins.window.createFormPopup(forms.orderPicker).show();

Parameters:

  • {form} form The form to show

Returns: FormPopup


createPopupMenu(menu,callback)

Creates a new popup menu, either empty, or initialized from an existing JSMenu.

Example:

// create a popup menu
// var menu = plugins.window.createPopupMenu(menus.getMenu('contextMenu'), feedback);
var menu = plugins.window.createPopupMenu();

// add a menu item
menu.addMenuItem("an entry", callback);
  
if (event.getSource()) {
 // display the popup over the component which is the source of the event
 menu.show(event.getSource());
 // display the popup over the components, at specified coordinates relative to the component
 //menu.show(event.getSource(), 10, 10);
 // display the popup at specified coordinates relative to the main window
 //menu.show(100, 100);
}

Parameters:

  • {JSMenu} [menu] The JSMenu whose structure will be used to initialize the popup menu.

  • {function} [callback] The menu item click handler that will be set on all popup menu items. The callback signature is: function(itemIndex:number, parentIndex: number, isSelected: boolean, parentMenu: String, menu: String)

Returns: Popup


createShortcut(shortcut,callback,contextFilter,arguments,consumeEvent)

Create a shortcut.

Example:

// this plugin uses the java keystroke parser
// see http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/KeyStroke.html#getKeyStroke(java.lang.String)
// global handler
plugins.window.createShortcut('control shift I', scopes.globals.handleOrdersShortcut);
// global handler with a form context filter
plugins.window.createShortcut('control shift I', scopes.globals.handleOrdersShortcut, 'frm_contacts');
// form method called when shortcut is used
plugins.window.createShortcut('control RIGHT', forms.frm_contacts.handleMyShortcut);
// form method called when shortcut is used and arguments are passed to the method
plugins.window.createShortcut('control RIGHT', forms.frm_contacts.handleMyShortcut, new Array(argument1, argument2));
// Passing the method argument as a string prevents unnecessary form loading
//plugins.window.createShortcut('control RIGHT', 'frm_contacts.handleMyShortcut', new Array(argument1, argument2));
// Passing the method as a name and the contextFilter set so that this shortcut only trigger on the form 'frm_contacts'.
plugins.window.createShortcut('control RIGHT', 'frm_contacts.handleMyShortcut', 'frm_contacts', new Array(argument1, argument2));
// Num Lock and Substract shortcuts
plugins.window.createShortcut("NUMPAD8", handleMyShortcut);
plugins.window.createShortcut("SUBTRACT", handleMyShortcut);
// remove global shortcut and form-level shortcut
plugins.window.removeShortcut('menu 1');
plugins.window.removeShortcut('control RIGHT', 'frm_contacts');
// consuming they keystroke so that a default browser event will not happen
plugins.window.createShortcut('F4', scopes.globals.handleOrdersShortcut, 'frm_contacts', null, true);
// shortcut handlers are called with an JSEvent argument
///*
// * Handle keyboard shortcut.
// *
// * @param {JSEvent} event the event that triggered the action
// */
//function handleShortcut(event)
//{
//  application.output(event.getType()) // returns 'menu 1'
//  application.output(event.getFormName()) // returns 'frm_contacts'
//  application.output(event.getElementName()) // returns 'contact_name_field' or null when no element is selected
//}
// NOTES:
// 1) shortcuts will not override existing operating system or browser shortcuts,
// choose your shortcuts carefully to make sure they work in all clients.
// 2) always use lower-case letters for modifiers (shift, control, etc.), otherwise createShortcut will fail.

Parameters:

  • {string} shortcut Shortcut

  • {function} callback Scopes.scopename.methodname or formname.methodname String to target the method to execute

  • {string} [contextFilter] ContextFilter form or element name ( ng only - specified by formName.elementName); only triggers the shortcut when on this form/element

  • {object []} [arguments] ** arguments

  • {boolean} [consumeEvent] ConsumeEvent if true then the shotcut will consume the event and the default browser behavior will not be executed (default false)

Returns: boolean


getFormPopup(form)

It will return a FormPopup with the form passed as an argument or null.

Example:

plugins.window.getFormPopup(forms.orderPicker)

Parameters:

Returns: FormPopup


removeShortcut(shortcut,contextFilter)

@clonedesc js_removeShortcut(String) Example:

as js_removeShortcut(String)

Parameters:

  • {string} shortcut Shortcut

  • {string} [contextFilter] ContextFilter form or element name ( ng only - specified by formName.elementName); only triggers the shortcut when on this form/element

Returns: boolean


showFormPopup(component,form,scope,dataProviderID,width,height,x,y,showBackdrop,doNotCloseOnClickOutside,onClose)

Show a form as popup panel, where the closeFormPopup can pass return a value to a dataprovider in the specified scope. Can show relative to a component or at specified coordinates. Show on specified location and backdrop is only supported in NGClient.

Example:

// Show a form as popup panel, where the closeFormPopup can pass return a value to a dataprovider in the specified scope.
plugins.window.showFormPopup(null,forms.orderPicker,foundset.getSelectedRecord(),"order_id");
// plugins.window.showFormPopup(null,forms.orderPicker,foundset.getSelectedRecord(),"order_id",-1,-1,100,100,true, false, onClose);
//
// function onClose(event) {application.output("Popup closed");}

Parameters:

  • {runtimecomponent} component ElementToShowRelatedTo element to show related to or null to center in screen

  • {form} form The form to show

  • {object} scope The scope to put retval into

  • {string} dataProviderID DataproviderID the dataprovider of scope to fill

  • {int} [width] Popup width

  • {int} [height] Popup height

  • {int} [x] Popup x location

  • {int} [y] Popup y location

  • {boolean} [showBackdrop] ShowBackdrop whatever to show a dimmed backdrop under the popup

  • {boolean} [doNotCloseOnClickOutside] DoNotCloseOnClickOutside whether to close on not close the popup on clicking outside

  • {function} [onClose] OnClose a callback function that is being triggered once the formpopup window is being closed


Types

CheckBox

scripting type: CustomType<window.CheckBox> extends: MenuItem

FormPopup

scripting type: CustomType<window.FormPopup>

cancel()

Close/Cancel the current form and his children if applicable.

Example:

plugins.window.getFormPopup(forms.orderPicker).cancel();

component()

Returns the component.

Example:

plugins.window.createFormPopup(forms.orderPicker).component();

Returns: runtimecomponent FormPopup itself if it's used as a setter or the component if no argument is given


component(component)

Set component form popup will be shown relative to. If null, will use coordinates or show at screen center.

Example:

plugins.window.createFormPopup(forms.orderPicker).component(elements.myelement).show();

Parameters:

Returns: FormPopup FormPopup itself if it's used as a setter or the component if no argument is given


createFormPopup(form)

Create a form popup that can be filled with data and shown.

Example:

plugins.window.createFormPopup(forms.orderPicker).show();

Parameters:

  • form form The form to show

Returns: FormPopup ** FormPopup


dataprovider()

Returns the datprovider value

Example:

plugins.window.createFormPopup(forms.orderPicker).dataprovider('myid').scope(foundset.getSelectedRecord()).show();

Returns: string FormPopup itself if it's used as a setter or the dataprovider value if no argument is given


dataprovider(dataprovider)

Set form popup dataprovider that will be set. If this is set, also scope needs to be specified.

Example:

plugins.window.createFormPopup(forms.orderPicker).dataprovider('myid').scope(foundset.getSelectedRecord()).show();

Parameters:

  • string dataprovider Form popup dataprovider

Returns: FormPopup FormPopup itself if it's used as a setter or the dataprovider value if no argument is given


height()

Returns the height.

Example:

plugins.window.createFormPopup(forms.orderPicker).height(100).show();

Returns: int FormPopup itself if it's used as a setter or the height if no argument is given


height(height)

Set form popup height. If not set, form design height will be used.

Example:

plugins.window.createFormPopup(forms.orderPicker).height(100).show();

Parameters:

  • int height Form popup height

Returns: FormPopup FormPopup itself if it's used as a setter or the height if no argument is given


onClose()

Returns the onClose function value

Example:

plugins.window.createFormPopup(forms.orderPicker).dataprovider('myid').onClose(closePopupFunction).show();

Returns: function FormPopup itself if it's used as a setter or the dataprovider value if no argument is given


onClose(onClose)

Set the onclose function that is called when the closeFormPopup is called. This onClose will get a JSEvent as the first argument, and the return value that is given to the closeFormPopup(retvalue) call.

Example:

plugins.window.createFormPopup(forms.orderPicker).dataprovider('myid').onClose(closePopupFunction).show();

Parameters:

  • function onClose Function that needs to be called when closed

Returns: FormPopup The dataprovider value if no argument is given


scope()

Returns the scope object

Example:

plugins.window.createFormPopup(forms.orderPicker).dataprovider('myid').scope(foundset.getSelectedRecord()).show();

Returns: object FormPopup itself if it's used as a setter or the dataprovider value if no argument is given


scope(scope)

Set form popup scope that will be modified. If this is set, also dataprovider needs to be specified.

Example:

plugins.window.createFormPopup(forms.orderPicker).dataprovider('myid').scope(foundset.getSelectedRecord()).show();

Parameters:

  • object scope Form popup scope to modify

Returns: FormPopup FormPopup itself if it's used as a setter or the dataprovider value if no argument is given


show()

Show form popup using parameters that were set

Example:

plugins.window.createFormPopup(forms.orderPicker).x(100).y(100).width(100).height(100).showBackdrop(true).show();

showBackdrop()

Returns the backdrop value

Example:

plugins.window.createFormPopup(forms.orderPicker).showBackdrop(true).show();

Returns: boolean FormPopup itself if it's used as a setter or the showBackdrop value if no argument is given


showBackdrop(showBackdrop)

Set whether backdrop will be shown. Default value is false.

Example:

plugins.window.createFormPopup(forms.orderPicker).showBackdrop(true).show();

Parameters:

  • boolean showBackdrop Form popup showBackdrop

Returns: FormPopup FormPopup itself if it's used as a setter or the showBackdrop value if no argument is given


width()

Returns the width.

Example:

plugins.window.createFormPopup(forms.orderPicker).width(100).show();

Returns: int FormPopup itself if it's used as a setter or the width if no argument is given


width(width)

Set form popup width. If not set, form design width will be used.

Example:

plugins.window.createFormPopup(forms.orderPicker).width(100).show();

Parameters:

  • int width Form popup width

Returns: FormPopup FormPopup itself if it's used as a setter or the width if no argument is given


x()

Returns the x.

Example:

plugins.window.createFormPopup(forms.orderPicker).x(100).show();

Returns: int FormPopup itself if it's used as a setter or the x if no argument is given


x(x)

Set form popup x location. The priority sequence for location is: related element, set location, center of screen.

Example:

plugins.window.createFormPopup(forms.orderPicker).x(100).show();

Parameters:

  • int x Form popup x location

Returns: FormPopup FormPopup itself if it's used as a setter or the x if no argument is given


y()

Returns the y value

Example:

plugins.window.createFormPopup(forms.orderPicker).y(100).show();

Returns: int ** The FormPopup itself if it's used as a setter or the y value if no argument is given


y(y)

Set form popup y location. The priority sequence for location is: related element, set location, center of screen.

Example:

plugins.window.createFormPopup(forms.orderPicker).y(100).show();

Parameters:

  • int y Form popup y location

Returns: FormPopup FormPopup itself if it's used as a setter or the y value if no argument is given


scripting type: CustomType<window.Menu> extends: BaseMenu

doClick()

Script the selection (emulate a mouse click) of the menu.

Example:

// simulate a click on the popup menu
menu.doClick();

setEnabled(enabled)

Set the the selected menu enabled or disabled.

Example:

var popup = plugins.window.createPopupMenu();
var menu = popup.addMenu();
// set the menu's text
menu.text = "New Menu";
// disable the menu
menu.setEnabled(false);
// set a mnemonic
menu.setMnemonic("u");
// add an icon to the menu
menu.setIcon("media:///yourimage.gif");

Parameters:


setIcon(icon)

Set the icon of the menu.

Example:

var popup = plugins.window.createPopupMenu();
var menu = popup.addMenu();
// set the menu's text
menu.text = "New Menu";
// disable the menu
menu.setEnabled(false);
// set a mnemonic
menu.setMnemonic("u");
// add an icon to the menu
menu.setIcon("media:///yourimage.gif");

Parameters:


setMnemonic(mnemonic)

Set the mnemonic of the selected menu.

Example:

var popup = plugins.window.createPopupMenu();
var menu = popup.addMenu();
// set the menu's text
menu.text = "New Menu";
// disable the menu
menu.setEnabled(false);
// set a mnemonic
menu.setMnemonic("u");
// add an icon to the menu
menu.setIcon("media:///yourimage.gif");

Parameters:


scripting type: CustomType<window.MenuItem>

doClick()

Script the selection (emulate a mouse click) of the item.

Example:

// create a popup menu
var menu = plugins.window.createPopupMenu();

// add a menu item
var entry = menu.addMenuItem("menu entry", feedback);
// alternatively add a checkbox
//var entry = menu.addCheckBox("menu entry", feedback);
// or alternatively add a radiobutton
//var entry = menu.addRadioButton("menu entry", feedback);

// simulate a click on the entry
entry.doClick();

getClientProperty(key)

Gets the specified client property for the menu item/checkbox/radiobutton based on a key.

Example:

// add a new menu to the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
menu.text = "New Menu";
// alternatively create a popup menu
//var menu = plugins.window.createPopupMenu();

// add a menu item
var entry = menu.addMenuItem("menu entry", feedback);
// alternatively add a checkbox
//var entry = menu.addCheckBox("menu entry", feedback);
// or alternatively add a radiobutton
//var entry = menu.addRadioButton("menu entry", feedback);

// NOTE: Depending on the operating system, a user interface property name may be available.
// set the tooltip of the menu item/checkbox/radiobutton via client properties
// keep the original tooltip in a form or global variable
originalTooltip = entry.getClientProperty("ToolTipText");
entry.putClientProperty("ToolTipText", "changed tooltip");

// later restore the original tooltip from the variable
//var menubar = plugins.window.getMenuBar();
//var menuIndex = menubar.getMenuIndexByText("New Menu");
//var menu = menubar.getMenu(menuIndex);
//var entry = menu.getItem(0);
//entry.putClientProperty("ToolTipText", originalTooltip);

Parameters:


putClientProperty(key,value)

Sets the value for the specified client property key of the menu item/checkbox/radiobutton.

Example:

// add a new menu to the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
menu.text = "New Menu";
// alternatively create a popup menu
//var menu = plugins.window.createPopupMenu();

// add a menu item
var entry = menu.addMenuItem("menu entry", feedback);
// alternatively add a checkbox
//var entry = menu.addCheckBox("menu entry", feedback);
// or alternatively add a radiobutton
//var entry = menu.addRadioButton("menu entry", feedback);

// NOTE: Depending on the operating system, a user interface property name may be available.
// set the tooltip of the menu item/checkbox/radiobutton via client properties
// keep the original tooltip in a form or global variable
originalTooltip = entry.getClientProperty("ToolTipText");
entry.putClientProperty("ToolTipText", "changed tooltip");

// later restore the original tooltip from the variable
//var menubar = plugins.window.getMenuBar();
//var menuIndex = menubar.getMenuIndexByText("New Menu");
//var menu = menubar.getMenu(menuIndex);
//var entry = menu.getItem(0);
//entry.putClientProperty("ToolTipText", originalTooltip);

Parameters:


setAccelerator(accelerator)

Set the accelerator key of the menu item/checkbox/radiobutton.

Example:

// add a new menu to the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
menu.text = "New Menu";
// alternatively create a popup menu
//var menu = plugins.window.createPopupMenu();

// add a menu item
var entry = menu.addMenuItem("menu entry", feedback);
// alternatively add a checkbox
//var entry = menu.addCheckBox("menu entry", feedback);
// or alternatively add a radiobutton
//var entry = menu.addRadioButton("menu entry", feedback);

// define an accelerator for the menu entry
entry.setAccelerator("ctrl alt Y");
// also define a mnemonic
entry.setMnemonic("y");
// set a custom background color
entry.setBackgroundColor("#111111");
// set a custom foreground color
entry.setForegroundColor("#EE5555");
// set an icon
entry.setIcon("media:///yourimage.gif");

Parameters:

  • string accelerator Accelerator


setBackgroundColor(bgColor)

Set the background color of the menu item/checkbox/radiobutton.

Parameters:


setForegroundColor(fgColor)

Set the foreground color of the menu item/checkbox/radiobutton.

Parameters:


setIcon(icon)

Set the icon of the menu item/checkbox/radiobutton.

Example:

// add a new menu to the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
menu.text = "New Menu";
// alternatively create a popup menu
//var menu = plugins.window.createPopupMenu();

// add a menu item
var entry = menu.addMenuItem("menu entry", feedback);
// alternatively add a checkbox
//var entry = menu.addCheckBox("menu entry", feedback);
// or alternatively add a radiobutton
//var entry = menu.addRadioButton("menu entry", feedback);

// define an accelerator for the menu entry
entry.setAccelerator("ctrl alt Y");
// also define a mnemonic
entry.setMnemonic("y");
// set a custom background color
entry.setBackgroundColor("#111111");
// set a custom foreground color
entry.setForegroundColor("#EE5555");
// set an icon
entry.setIcon("media:///yourimage.gif");

Parameters:


setMethod(method,arguments)

Set the method for the menu item/checkbox/radiobutton.

Example:

// add a new menu to the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
menu.text = "New Menu";
// alternatively create a popup menu
//var menu = plugins.window.createPopupMenu();

// add a menu item at the first position in the menu
var entry = menu.addMenuItem(0);
// alternatively add a checkbox at the first position
//var entry = menu.addCheckBox(0);
// or alternatively add a radiobutton at the first position
//var entry = menu.addRadioButton(0);

// disable the newly added entry
entry.enabled = false;
// give a name to the entry (the name is not visible anywhere)
entry.name = "my_name";
// make the entry selected (affects checkboxes and radiobuttons)
entry.selected = true;
// set the text of the entry
entry.text = "menu entry";
// set the callback method
entry.setMethod(feedback);
// set the arguments to be sent to the callback method
// (an array of elements which will be passed as arguments 5, 6 and so on to the callback method)
// the first 5 arguments are fixed: 
//   [0] item index
//   [1] parent item index
//   [2] isSelected boolean
//   [3] parent menu text
//   [4] menu text
entry.methodArguments = [17, "data"];

Parameters:


setMnemonic(mnemonic)

Set the icon of the menu item/checkbox/radiobutton.

Example:

// add a new menu to the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
menu.text = "New Menu";
// alternatively create a popup menu
//var menu = plugins.window.createPopupMenu();

// add a menu item
var entry = menu.addMenuItem("menu entry", feedback);
// alternatively add a checkbox
//var entry = menu.addCheckBox("menu entry", feedback);
// or alternatively add a radiobutton
//var entry = menu.addRadioButton("menu entry", feedback);

// define an accelerator for the menu entry
entry.setAccelerator("ctrl alt Y");
// also define a mnemonic
entry.setMnemonic("y");
// set a custom background color
entry.setBackgroundColor("#111111");
// set a custom foreground color
entry.setForegroundColor("#EE5555");
// set an icon
entry.setIcon("media:///yourimage.gif");

Parameters:


setVisible(visible)

Set the item visible.

Example:

// add a new menu to the menubar
var menubar = plugins.window.getMenuBar();
var menu = menubar.addMenu();
menu.text = "New Menu";
// alternatively create a popup menu
//var menu = plugins.window.createPopupMenu();

// add a menu item
var entry_one = menu.addMenuItem("an entry", feedback);
// add a checkbox
var entry_two = menu.addCheckBox("another entry", feedback);
// add a radiobutton
var entry_three = menu.addRadioButton("yet another entry", feedback);

// hide the menu item
entry_one.setVisible(false);
// make sure the checkbox is visible
entry_two.setVisible(true);
// hide the radiobutton
entry_three.setVisible(false);

Parameters:


scripting type: CustomType<window.Popup> extends: BaseMenu

show(component,positionTop)

Show the popup menu relative to the specified component. If there is not enough space above or under the component, the behavior is undefined (the browser will decide how menu is displayed)

Example:

// create a popup menu
var menu = plugins.window.createPopupMenu();
// add a menu item
menu.addMenuItem("an entry", feedback);

if (event.getSource()) {
 // display the popup over the component which is the source of the event
 menu.show(event.getSource(), true);
}

Parameters:

  • runtimecomponent component The component where this popup is linked in

  • boolean [positionTop] The positionTop where to show the popup (default false)


show(component,x,y,positionTop)

Show the popup menu at the specified location. If positionTop is true, and there is enough room available, then popup menu's bottom - left corner is ending at the specified coordinates; x, y values are relative to top-left corner of the component. By default, positionTop is false. If there is not enough space above or under the component, the behavior is undefined (the browser will decide how menu is displayed)

Example:

// create a popup menu
var menu = plugins.window.createPopupMenu();
// add a menu item
menu.addMenuItem("an entry", feedback);

if (event.getSource()) {
 // display the popup over the component which is the source of the event
 // display the popup over the components, at specified coordinates relative to the component
 //menu.show(event.getSource(), 10, 10, true);
}

Parameters:

  • runtimecomponent component The component where this popup is linked in

  • int x The x of the popup

  • int y The y coordinate of the popup

  • boolean [positionTop] The positionTop where to show the popup (default false)


show(event)

Show the popup menu relative to the event's source

Example:

// create a popup menu
var menu = plugins.window.createPopupMenu();
// add a menu item
menu.addMenuItem("an entry", feedback);

if (event.getSource()) {
 // display the popup over the component which is the source of the event
 // display the popup over the components, at specified coordinates relative to the component
 //menu.show(event.getSource());
}

Parameters:

  • JSEvent event Event related to Popup


show(x,y)

Show the popup menu at the specified location

Example:

// create a popup menu
var menu = plugins.window.createPopupMenu();
// add a menu item
menu.addMenuItem("an entry", feedback);

if (event.getSource()) {
 // display the popup over the component which is the source of the event
 // display the popup over the components, at specified coordinates relative to the component
 //menu.show(event.getSource(), 10, 10, true);
}

Parameters:

  • int x The x of the popup

  • int y The y coordinate of the popup


RadioButton

scripting type: CustomType<window.RadioButton> extends: MenuItem


Last updated