Search in sources :

Example 26 with FlattenedSolution

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

the class JSSolutionModel method getRelation.

/**
 * Gets an existing relation by the specified name and returns a JSRelation Object.
 *
 * @sample
 * var relation = solutionModel.getRelation('name');
 * application.output("The primary server name is " + relation.primaryServerName);
 * application.output("The primary table name is " + relation.primaryTableName);
 * application.output("The foreign table name is " + relation.foreignTableName);
 * application.output("The relation items are " + relation.getRelationItems());
 *
 * @param name the specified name of the relation
 *
 * @return a JSRelation
 */
@JSFunction
public JSRelation getRelation(String name) {
    if (name == null)
        return null;
    FlattenedSolution fs = application.getFlattenedSolution();
    Relation relation = fs.getRelation(name);
    if (relation != null) {
        return new JSRelation(relation, application, false);
    }
    return null;
}
Also used : ISMRelation(com.servoy.j2db.solutionmodel.ISMRelation) Relation(com.servoy.j2db.persistence.Relation) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 27 with FlattenedSolution

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

the class JSSolutionModel method cloneForm.

/**
 * Makes an exact copy of the given form and gives it the new name.
 *
 * @sample
 * // get an existing form
 * var form = solutionModel.getForm("existingForm")
 * // make a clone/copy from it
 * var clone = solutionModel.cloneForm("clonedForm", form)
 * // add a new label to the clone
 * clone.newLabel("added label",50,50,80,20);
 * // show it
 * forms["clonedForm"].controller.show();
 *
 * @param newName the new name for the form clone
 *
 * @param jsForm the form to be cloned
 *
 * @return a JSForm
 */
@JSFunction
public JSForm cloneForm(String newName, IBaseSMForm jsForm) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Form clone = fs.clonePersist(((JSForm) jsForm).getSupportChild(), IdentDocumentValidator.checkName(newName), fs.getSolutionCopy());
    application.getFormManager().addForm(clone, false);
    return instantiateForm(clone, true);
}
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) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 28 with FlattenedSolution

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

the class JSSolutionModel method newGlobalVariable.

/**
 * Creates a new global variable with the specified name and number type.
 *
 * NOTE: The global variable number type is based on the value assigned from the SolutionModel-JSVariable node; for example: JSVariable.INTEGER.
 *
 * @sample
 * var myGlobalVariable = solutionModel.newGlobalVariable('globals', 'newGlobalVariable', JSVariable.INTEGER);
 * myGlobalVariable.defaultValue = 12;
 * //myGlobalVariable.defaultValue = "{a:'First letter',b:'Second letter'}" // an js object, type must be media.
 * //myGlobalVariable.defaultValue = '"some text"'; // Use two pairs of quotes if you want to assign a String as default value.
 * @param scopeName the scope in which the variable is created
 * @param name the specified name for the global variable
 *
 * @param type the specified number type for the global variable
 *
 * @return a JSVariable object
 */
@JSFunction
public JSVariable newGlobalVariable(String scopeName, String name, int type) {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        String scope = scopeName == null ? ScriptVariable.GLOBAL_SCOPE : scopeName;
        ScriptVariable variable = fs.getSolutionCopy().createNewScriptVariable(new ScriptNameValidator(application.getFlattenedSolution()), scope, name, type);
        application.getScriptEngine().getScopesScope().getGlobalScope(scope).put(variable);
        return new JSVariable(application, variable, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 29 with FlattenedSolution

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

the class JSSolutionModel method cloneComponent.

/**
 * Makes an exact copy of the given component (JSComponent/JSField/JSLabel), gives it a new name and moves it to a new parent form, specified as a parameter.
 *
 * @sample
 * // get an existing field to clone.
 * var field = solutionModel.getForm("formWithField").getField("fieldName");
 * // get the target form for the copied/cloned field
 * var form = solutionModel.getForm("targetForm");
 * // make a clone/copy of the field and re parent it to the target form.
 * var clone = solutionModel.cloneComponent("clonedField",field,form);
 * // show it
 * forms["targetForm"].controller.show();
 *
 * @param newName the new name of the cloned component
 *
 * @param component the component to clone
 *
 * @param newParentForm the new parent form
 *
 * @return the exact copy of the given component
 */
@JSFunction
public JSComponent<?> cloneComponent(String newName, IBaseSMComponent component, IBaseSMForm newParentForm) {
    if (component == null || !(((JSBase) component).getBaseComponent(false).getParent() instanceof Form)) {
        throw new RuntimeException("only components of a form can be cloned");
    }
    JSForm parent = (JSForm) newParentForm;
    if (parent == null) {
        parent = (JSForm) ((JSBase) component).getJSParent();
    }
    parent.checkModification();
    Form form = parent.getSupportChild();
    FlattenedSolution fs = application.getFlattenedSolution();
    fs.clonePersist(((JSBase) component).getBaseComponent(false), IdentDocumentValidator.checkName(newName), form);
    return parent.getComponent(newName);
}
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) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 30 with FlattenedSolution

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

the class JSSolutionModel method removeForm.

/**
 * Removes the specified form during the persistent connected client session.
 *
 * NOTE: Make sure you call history.remove first in your Servoy method (script).
 *
 * @sample
 * //first remove it from the current history, to destroy any active form instance
 * var success = history.removeForm('myForm')
 * //removes the named form from this session, please make sure you called history.remove() first
 * if(success)
 * {
 * 	solutionModel.removeForm('myForm')
 * }
 *
 * @param name the specified name of the form to remove
 *
 * @return true is form has been removed, false if form could not be removed
 */
@JSFunction
public boolean removeForm(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Form form = fs.getForm(name);
    if (form != null) {
        if (application.getFormManager().removeForm(form)) {
            fs.deletePersistCopy(form, false);
            return true;
        }
    }
    return false;
}
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) 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