Search in sources :

Example 56 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.

the class JSDataSourceNode method removeCalculation.

/**
 * Removes the calculation specified by name.
 *
 * @sample
 * var calc1 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation1() { return 123; }", JSVariable.INTEGER);
 * var calc2 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation2() { return '20'; }");
 *
 * var c = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myCalculation1");
 * application.output("Name: " + c.getName() + ", Stored: " + c.isStored());
 *
 * solutionModel.getDataSourceNode("db:/example_data/customers").removeCalculation("myCalculation1");
 * c = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myCalculation1");
 * if (c != null) {
 * 	application.output("myCalculation could not be removed.");
 * }
 *
 * var allCalcs = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculations();
 * for (var i = 0; i < allCalcs.length; i++) {
 * 	application.output(allCalcs[i]);
 * }
 *
 * @param name the name of the calculation to be removed
 *
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeCalculation(String name) {
    try {
        FlattenedSolution fs = application.getFlattenedSolution();
        TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
        ScriptCalculation sc = tablenode.getScriptCalculation(name);
        if (sc != null) {
            tablenode.removeChild(sc);
            return true;
        }
        // it is a design time calculation, therefore we "hide" it
        sc = fs.getScriptCalculation(name, dataSource);
        if (sc != null) {
            fs.addToRemovedPersists(sc);
            return true;
        }
        // not found
        return false;
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) TableNode(com.servoy.j2db.persistence.TableNode) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 57 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.

the class PersistHelper method getOrderedStyleSheets.

public static List<String> getOrderedStyleSheets(FlattenedSolution fs) {
    List<String> styleSheets = new ArrayList<String>();
    List<Solution> orderedModules = new ArrayList<Solution>();
    orderedModules.add(fs.getSolution());
    if (fs.getModules() != null) {
        buildOrderedModulesList(fs.getSolution(), orderedModules, new ArrayList<Solution>(Arrays.asList(fs.getModules())));
    }
    for (Solution solution : orderedModules) {
        if (solution.getStyleSheetID() > 0) {
            Media media = fs.getMedia(solution.getStyleSheetID());
            if (media != null) {
                if (!styleSheets.contains(media.getName())) {
                    styleSheets.add(media.getName());
                }
            } else {
                // $NON-NLS-1$ //$NON-NLS-2$
                Debug.warn("Stylesheet set for solution '" + solution.getName() + "' cannot be found");
            }
        }
    }
    return styleSheets;
}
Also used : ArrayList(java.util.ArrayList) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 58 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution 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)

Example 59 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.

the class CSSPositionPropertyType method toJSON.

public JSONWriter toJSON(JSONWriter writer, String key, CSSPosition object, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
    FormElement fe = null;
    if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof WebFormComponent) {
        fe = ((WebFormComponent) dataConverterContext.getWebObject()).getFormElement();
    }
    FlattenedSolution fs = null;
    Form form = null;
    if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof IContextProvider) {
        fs = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution();
        if (((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getForm() != null) {
            form = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getForm().getForm();
        }
    }
    return toJSON(writer, key, object, pd, clientConversion, fe, fs, form);
}
Also used : IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) FlattenedSolution(com.servoy.j2db.FlattenedSolution) FormElement(com.servoy.j2db.server.ngclient.FormElement) INGFormElement(com.servoy.j2db.server.ngclient.INGFormElement) IDesignToFormElement(com.servoy.j2db.server.ngclient.property.types.NGConversions.IDesignToFormElement)

Example 60 with FlattenedSolution

use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.

the class FormComponentPropertyType method toRhinoValue.

@Override
public Object toRhinoValue(Object webComponentValue, PropertyDescription pd, IWebObjectContext componentOrService, Scriptable startScriptable) {
    Scriptable newObject = DefaultScope.newObject(startScriptable);
    WebFormComponent webFormComponent = (WebFormComponent) componentOrService;
    FlattenedSolution fs = webFormComponent.getDataConverterContext().getSolution();
    FormComponentCache cache = null;
    if (webComponentValue instanceof FormComponentSabloValue) {
        cache = ((FormComponentSabloValue) webComponentValue).getCache();
    } else {
        Form form = getForm(webComponentValue, fs);
        if (form == null)
            return null;
        // TODO return here a NativeScriptable object that understand the full hiearchy?
        cache = FormElementHelper.INSTANCE.getFormComponentCache(webFormComponent.getFormElement(), pd, (JSONObject) webComponentValue, form, fs);
    }
    IWebFormUI formUI = webFormComponent.findParent(IWebFormUI.class);
    String prefix = FormElementHelper.getStartElementName(webFormComponent.getFormElement(), pd);
    for (FormElement fe : cache.getFormComponentElements()) {
        String name = fe.getName();
        if (name != null && !name.startsWith(FormElement.SVY_NAME_PREFIX)) {
            RuntimeWebComponent webComponent = formUI.getRuntimeWebComponent(fe.getRawName());
            if (webComponent != null) {
                newObject.put(name.substring(prefix.length()), newObject, webComponent);
            }
        }
    }
    return newObject;
}
Also used : IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) FormComponentCache(com.servoy.j2db.server.ngclient.FormElementHelper.FormComponentCache) JSONObject(org.json.JSONObject) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Scriptable(org.mozilla.javascript.Scriptable) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) FormElement(com.servoy.j2db.server.ngclient.FormElement) INGFormElement(com.servoy.j2db.server.ngclient.INGFormElement) IFormElement(com.servoy.j2db.persistence.IFormElement)

Aggregations

FlattenedSolution (com.servoy.j2db.FlattenedSolution)79 JSFunction (org.mozilla.javascript.annotations.JSFunction)27 Form (com.servoy.j2db.persistence.Form)20 RepositoryException (com.servoy.j2db.persistence.RepositoryException)17 ArrayList (java.util.ArrayList)17 Relation (com.servoy.j2db.persistence.Relation)15 Media (com.servoy.j2db.persistence.Media)10 Solution (com.servoy.j2db.persistence.Solution)10 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)9 IBaseSMForm (com.servoy.base.solutionmodel.IBaseSMForm)7 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)7 ISMForm (com.servoy.j2db.solutionmodel.ISMForm)7 FormController (com.servoy.j2db.FormController)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ValueList (com.servoy.j2db.persistence.ValueList)6 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)6 IApplicationServer (com.servoy.j2db.server.shared.IApplicationServer)6 ITable (com.servoy.j2db.persistence.ITable)5 QueryTable (com.servoy.j2db.query.QueryTable)5 SafeArrayList (com.servoy.j2db.util.SafeArrayList)5