use of com.servoy.j2db.scripting.FunctionDefinition in project servoy-client by Servoy.
the class SwingFormManager method fillScriptMenu.
// fill the scripts menu
@Override
public void fillScriptMenu() {
JMenu menu = getScriptMenu();
// Remove old script methods.
menu.removeAll();
FlattenedSolution sol = getApplication().getFlattenedSolution();
if (sol.getSolution() == null)
return;
List<ScriptMenuItem> globalMenus = new ArrayList<ScriptMenuItem>();
int menuCount = 1;
Iterator<ScriptMethod> globalMethods = sol.getScriptMethods(true);
while (globalMethods.hasNext()) {
ScriptMethod sm = globalMethods.next();
ScriptMenuItem item = getScriptMenuItem(sm, new FunctionDefinition(ScriptVariable.SCOPES_DOT_PREFIX + sm.getScopeName(), sm.getName()), menuCount);
if (item != null) {
globalMenus.add(item);
if (menuCount > 0 && menuCount < 9) {
menuCount++;
} else {
menuCount = -1;
}
// just break after 50, doesn't make sense to have more in the menu..
if (globalMenus.size() > 50)
break;
}
}
JMenu globalMenu = menu;
if (// if big create sub menu for global methods
globalMenus.size() > 20) {
globalMenu = new JMenu(Messages.getString("servoy.formManager.menuGlobalMethods"));
menu.add(globalMenu);
}
Iterator<ScriptMenuItem> it = globalMenus.iterator();
while (it.hasNext()) {
ScriptMenuItem item = it.next();
globalMenu.add(item);
}
boolean insertSeparator = menu.getMenuComponentCount() > 0;
FormController fp = getCurrentMainShowingFormController();
if (fp != null) {
int nformmethods = 0;
Form form = fp.getForm();
Iterator<ScriptMethod> formMethods = form.getScriptMethods(true);
while (formMethods.hasNext()) {
ScriptMethod sm = formMethods.next();
ScriptMenuItem item = getScriptMenuItem(sm, new FunctionDefinition(form.getName(), sm.getName()), -1);
if (item != null) {
if (insertSeparator) {
menu.add(new JSeparator());
insertSeparator = false;
}
nformmethods++;
menu.add(item);
}
}
if (form.getDataSource() != null) {
insertSeparator |= nformmethods > 0;
Iterator<ScriptMethod> foundsetMethods = fp.getApplication().getFlattenedSolution().getFoundsetMethods(fp.getDataSource(), true);
while (foundsetMethods.hasNext()) {
ScriptMethod sm = foundsetMethods.next();
ScriptMenuItem item = getScriptMenuItem(sm, new FunctionDefinition(form.getName(), sm.getName()), -1);
if (item != null) {
if (insertSeparator) {
menu.add(new JSeparator());
insertSeparator = false;
}
menu.add(item);
}
}
}
}
menu.setEnabled(menu.getMenuComponentCount() > 0);
}
Aggregations