Search in sources :

Example 1 with ScriptMenuItem

use of com.servoy.j2db.smart.scripting.ScriptMenuItem 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);
}
Also used : FormController(com.servoy.j2db.FormController) BasicFormController(com.servoy.j2db.BasicFormController) ScriptMenuItem(com.servoy.j2db.smart.scripting.ScriptMenuItem) Form(com.servoy.j2db.persistence.Form) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSeparator(javax.swing.JSeparator) FunctionDefinition(com.servoy.j2db.scripting.FunctionDefinition) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) JMenu(javax.swing.JMenu)

Aggregations

BasicFormController (com.servoy.j2db.BasicFormController)1 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 FormController (com.servoy.j2db.FormController)1 Form (com.servoy.j2db.persistence.Form)1 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)1 FunctionDefinition (com.servoy.j2db.scripting.FunctionDefinition)1 ScriptMenuItem (com.servoy.j2db.smart.scripting.ScriptMenuItem)1 ArrayList (java.util.ArrayList)1 JMenu (javax.swing.JMenu)1 JSeparator (javax.swing.JSeparator)1