Search in sources :

Example 46 with FlattenedSolution

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

the class JSSolutionModel method removeGlobalMethod.

/**
 * Removes the specified global method.
 *
 * @sample
 * var m1 = solutionModel.newGlobalMethod('globals', 'function myglobalmethod1(){application.output("Global Method 1");}');
 * var m2 = solutionModel.newGlobalMethod('globals', 'function myglobalmethod2(){application.output("Global Method 2");}');
 *
 * var success = solutionModel.removeGlobalMethod('globals', 'myglobalmethod1');
 * if (success == false) application.output('!!! myglobalmethod1 could not be removed !!!');
 *
 * var list = solutionModel.getGlobalMethods('globals');
 * for (var i = 0; i < list.length; i++) {
 * 	application.output(list[i].code);
 * }
 *
 * @param scopeName the scope in which the method is declared
 * @param name the name of the global method to be removed
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeGlobalMethod(String scopeName, String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    ScriptMethod sm = fs.getScriptMethod(scopeName, name);
    if (sm != null) {
        fs.deletePersistCopy(sm, false);
        if (application.getFormManager() instanceof FormManager)
            ((FormManager) application.getFormManager()).fillScriptMenu();
        return true;
    }
    return false;
}
Also used : FormManager(com.servoy.j2db.FormManager) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 47 with FlattenedSolution

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

the class JSSolutionModel method removeRelation.

/**
 * Removes the relation specified by name. You cannot remove the relation if it is touched within the application.
 * So even if you remove all the ui elements using it, like tabs, it still can't be removed, because of underlying created and cached data.
 *
 * @sample
 * var success = solutionModel.removeRelation('myRelation');
 * if (success) { application.output("Relation has been removed");}
 * else {application.output("Relation could not be removed");}
 *
 * @param name the name of the relation to be removed
 *
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeRelation(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Relation rel = fs.getRelation(name);
    if (rel != null) {
        try {
            if (((FoundSetManager) application.getFoundSetManager()).getSQLGenerator().getCachedTableSQLSheet(rel.getForeignDataSource()).getRelatedSQLDescription(name) != null) {
                return false;
            }
            fs.deletePersistCopy(rel, false);
        } catch (ServoyException e) {
            Debug.error(e);
            return false;
        }
        return true;
    }
    return false;
}
Also used : ISMRelation(com.servoy.j2db.solutionmodel.ISMRelation) Relation(com.servoy.j2db.persistence.Relation) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ServoyException(com.servoy.j2db.util.ServoyException) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 48 with FlattenedSolution

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

the class JSSolutionModel method revertForm.

/**
 * Reverts the specified form to the original (blueprint) version of the form; will result in an exception error if the form is not an original form.
 *
 * NOTE: Make sure you call history.remove first in your Servoy method (script) or call form.controller.recreateUI() before the script ends.
 *
 * @sample
 * // revert the form to the original solution form, removing any changes done to it through the solution model.
 * var revertedForm = solutionModel.revertForm('myForm')
 * // add a label on a random place.
 * revertedForm.newLabel("MyLabel",Math.random()*100,Math.random()*100,80,20);
 * // make sure that the ui is up to date.
 * forms.myForm.controller.recreateUI();
 *
 * @param name the specified name of the form to revert
 *
 * @return a JSForm object
 */
@JSFunction
public JSForm revertForm(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Form form = fs.revertForm(name);
    if (form != null) {
        application.getFormManager().addForm(form, false);
        return instantiateForm(form, false);
    } else {
        form = application.getFormManager().getPossibleForm(name);
        if (form != null) {
            application.getFormManager().removeForm(form);
        }
    }
    return null;
}
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 49 with FlattenedSolution

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

the class JSSolutionModel method getAllRelations.

/**
 * Gets an array of all relations.
 *
 * @sample
 * var relations = solutionModel.getAllRelations();
 * if (relations.length != 0)
 * 	for (var i in relations)
 * 		application.output(relations[i].name);
 *
 * @return an array of all relations (all elements in the array are of type JSRelation)
 */
@JSFunction
public JSRelation[] getAllRelations() {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        List<JSRelation> relations = new ArrayList<JSRelation>();
        Iterator<Relation> iterator = fs.getRelations(true);
        while (iterator.hasNext()) {
            relations.add(new JSRelation(iterator.next(), application, false));
        }
        return relations.toArray(new JSRelation[relations.size()]);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ISMRelation(com.servoy.j2db.solutionmodel.ISMRelation) Relation(com.servoy.j2db.persistence.Relation) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 50 with FlattenedSolution

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

the class JSSolutionModel method getGlobalMethod.

/**
 * Gets an existing global method by the specified name.
 *
 * @sample
 * var method = solutionModel.getGlobalMethod('globals', 'nameOfGlobalMethod');
 * if (method != null) application.output(method.code);
 *
 * @param scopeName the scope in which the method is searched
 * @param name the name of the specified global method
 *
 * @return a JSMethod
 */
@JSFunction
public JSMethod getGlobalMethod(String scopeName, String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    ScriptMethod sm = fs.getScriptMethod(scopeName, name);
    if (sm != null) {
        return new JSMethod(sm, application, false);
    }
    return null;
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) 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