Search in sources :

Example 31 with FlattenedSolution

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

the class JSSolutionModel method newGlobalMethod.

/**
 * Creates a new global method with the specified code in a scope.
 *
 * @sample
 * var method = solutionModel.newGlobalMethod('globals', 'function myglobalmethod(){foundset.newRecord()}')
 *
 * @param scopeName the scope in which the method is created
 * @param code the specified code for the global method
 *
 * @return a JSMethod object
 */
@JSFunction
public JSMethod newGlobalMethod(String scopeName, String code) {
    FlattenedSolution fs = application.getFlattenedSolution();
    String name = JSMethod.parseName(code);
    try {
        String scope = scopeName == null ? ScriptVariable.GLOBAL_SCOPE : scopeName;
        ScriptMethod method = fs.getSolutionCopy().createNewGlobalScriptMethod(new ScriptNameValidator(application.getFlattenedSolution()), scope, name);
        method.setDeclaration(code);
        application.getScriptEngine().getScopesScope().getGlobalScope(scope).put(method, method);
        JSMethod jsMethod = new JSMethod(method, application, true);
        return jsMethod;
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 32 with FlattenedSolution

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

the class JSSolutionModel method newForm.

protected JSForm newForm(String name, String dataSource, String styleName, boolean show_in_menu, int width, int height, boolean isResponsive) {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        Style style = null;
        if (styleName != null) {
            style = fs.getStyle(styleName);
        }
        Form form = createNewForm(style, IdentDocumentValidator.checkName(name), dataSource, show_in_menu, new Dimension(width, height));
        if (!isResponsive) {
            form.createNewPart(Part.BODY, height);
        } else {
            form.setResponsiveLayout(true);
        }
        if (fs.getSolution().getSolutionType() == SolutionMetaData.MOBILE) {
            // mobile solution, make the form mobile
            form.putCustomMobileProperty(IMobileProperties.MOBILE_FORM.propertyName, Boolean.TRUE);
            // set internal style name
            form.setStyleName("_servoy_mobile");
        }
        application.getFormManager().addForm(form, false);
        return instantiateForm(form, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IBaseSMForm(com.servoy.base.solutionmodel.IBaseSMForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Style(com.servoy.j2db.persistence.Style) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Dimension(java.awt.Dimension)

Example 33 with FlattenedSolution

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

the class JSSolutionModel method getMedia.

/**
 * Gets the specified media object; can be assigned to a button/label.
 *
 * @sample
 * var myMedia = solutionModel.getMedia('button01.gif')
 * //now set the imageMedia property of your label or button
 * //myButton.imageMedia = myMedia
 * // OR
 * //myLabel.imageMedia = myMedia
 *
 * @param name the specified name of the media object
 *
 * @return a JSMedia element
 */
@JSFunction
public JSMedia getMedia(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Media media = fs.getMedia(name);
    if (media != null) {
        return new JSMedia(media, application.getFlattenedSolution(), false);
    }
    return null;
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 34 with FlattenedSolution

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

the class JSDataSourceNode method newMethod.

/**
 * Creates a new foundset method with the specified code.
 *
 * @sample
 * var method = solutionModel.getDataSourceNode("db:/example_data/orders").newMethod("function doubleSize() { return 2*getSize(); }");
 *
 * application.output('Doubled orders for this customer: '+customers_to_orders.doubleSize())
 *
 * @param code the specified code for the foundset method
 *
 * @return a JSMethod object
 */
@JSFunction
public JSMethod newMethod(String code) {
    try {
        FlattenedSolution fs = application.getFlattenedSolution();
        TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
        if (tablenode == null)
            throw new RuntimeException("Couldnt create method for datasource: " + dataSource);
        String name = JSMethod.parseName(code);
        ScriptMethod method = tablenode.createNewFoundsetMethod(new ScriptNameValidator(fs), name, null);
        method.setDeclaration(code);
        ((FoundSetManager) application.getFoundSetManager()).reloadFoundsetMethod(dataSource, method);
        return new JSMethod(this, method, application, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) TableNode(com.servoy.j2db.persistence.TableNode) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 35 with FlattenedSolution

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

the class JSDataSourceNode method newCalculation.

/**
 * Creates a new calculation for the given code and the type, if it builds on a column (name is a column name) then type will be ignored.
 *
 * @param code The code of the calculation, this must be a full function declaration.
 * @param type The type of the calculation, one of the JSVariable types.
 *
 * @sample
 * var calc = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation() { return 123; }", JSVariable.INTEGER);
 * var calc2 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myCalculation2() { return '20'; }");
 * var calc3 = solutionModel.getDataSourceNode("db:/example_data/employees").newCalculation("function myCalculation3() { return 'Hello World!'; }",	JSVariable.TEXT);
 *
 * var c = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myCalculation");
 * application.output("Name: " + c.getName() + ", Stored: " + c.isStored());
 *
 * var allCalcs = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculations();
 * for (var i = 0; i < allCalcs.length; i++) {
 * 	application.output(allCalcs[i]);
 * }
 */
@JSFunction
public JSCalculation newCalculation(String code, int type) {
    try {
        FlattenedSolution fs = application.getFlattenedSolution();
        TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
        String name = JSMethod.parseName(code);
        ScriptCalculation scriptCalculation = tablenode.createNewScriptCalculation(new ScriptNameValidator(fs), name, null, fs.getTable(dataSource));
        scriptCalculation.setDeclaration(code);
        scriptCalculation.setTypeAndCheck(type, application);
        TableScope tableScope = (TableScope) application.getScriptEngine().getTableScope(scriptCalculation.getTable());
        if (tableScope != null) {
            tableScope.put(scriptCalculation, scriptCalculation);
            ((FoundSetManager) application.getFoundSetManager()).flushSQLSheet(dataSource);
        }
        return new JSCalculation(this, scriptCalculation, application, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) TableScope(com.servoy.j2db.scripting.TableScope) TableNode(com.servoy.j2db.persistence.TableNode) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

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