Search in sources :

Example 36 with FlattenedSolution

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

the class JSDataSourceNode method removeMethod.

/**
 * Removes the foundset method specified by name.
 *
 * @sample
 * var method1 = solutionModel.getDataSourceNode("db:/example_data/customers").newMethod("function myFoundsetMethod1() { return 123; }");
 * var method2 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myFoundsetMethod2() { return '20'; }");
 *
 * var m = solutionModel.getDataSourceNode("db:/example_data/customers").getMethod("myFoundsetMethod1");
 * application.output("Name: " + m.getName());
 *
 * solutionModel.getDataSourceNode("db:/example_data/customers").removeMethod("myFoundsetMethod1");
 * m = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myFoundsetMethod1");
 * if (m != null) { application.output("myFoundsetMethod1 could not be removed."); }
 *
 * var allMethods = solutionModel.getDataSourceNode("db:/example_data/customers").getMethod();
 * for (var i = 0; i < allMethods; i++)
 * {
 * 	application.output(allMethods[i]);
 * }
 *
 * @param name the name of the method to be removed
 *
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeMethod(String name) {
    try {
        FlattenedSolution fs = application.getFlattenedSolution();
        TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
        ScriptMethod sc = tablenode.getFoundsetMethod(name);
        if (sc != null) {
            tablenode.removeChild(sc);
            return true;
        }
        // it is a design time method, therefore we "hide" it
        sc = fs.getFoundsetMethod(name, dataSource);
        if (sc != null) {
            fs.addToRemovedPersists(sc);
            if (application.getFormManager() instanceof FormManager)
                ((FormManager) application.getFormManager()).fillScriptMenu();
            return true;
        }
        // not found
        return false;
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : FormManager(com.servoy.j2db.FormManager) TableNode(com.servoy.j2db.persistence.TableNode) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 37 with FlattenedSolution

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

the class JSValueList method getFallbackValueList.

/**
 * Gets or sets the fallback valuelist.
 *
 * @sample
 * var myValueList = solutionModel.getValueList('myValueListHere')
 *  //get fallback value list
 * var fallbackValueList = myValueList.fallbackValueList
 */
@JSGetter
public JSValueList getFallbackValueList() {
    FlattenedSolution fs = application.getFlattenedSolution();
    int fallbackVLID = valuelist.getFallbackValueListID();
    ValueList fallbackVL = fs.getValueList(fallbackVLID);
    if (fallbackVL != null) {
        return new JSValueList(fallbackVL, application, false);
    } else {
        return null;
    }
}
Also used : IBaseSMValueList(com.servoy.base.solutionmodel.IBaseSMValueList) ValueList(com.servoy.j2db.persistence.ValueList) ISMValueList(com.servoy.j2db.solutionmodel.ISMValueList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSGetter(org.mozilla.javascript.annotations.JSGetter)

Example 38 with FlattenedSolution

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

the class LookupValueList method deregister.

public void deregister() {
    clear();
    if (tableListener != null && table != null) {
        FlattenedSolution fs = application.getFlattenedSolution();
        ((FoundSetManager) application.getFoundSetManager()).removeTableListener(table, tableListener);
        Relation[] relations = application.getFlattenedSolution().getRelationSequence(valueList.getRelationName());
        for (int i = 0; relations != null && i < relations.length - 1; i++) {
            ((FoundSetManager) application.getFoundSetManager()).removeTableListener(fs.getTable(relations[i].getForeignDataSource()), tableListener);
        }
        tableListener = null;
    }
}
Also used : Relation(com.servoy.j2db.persistence.Relation) FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Example 39 with FlattenedSolution

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

the class JSSolutionModel method getFormsInternal.

private JSForm[] getFormsInternal(String datasource) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Iterator<Form> forms = fs.getForms(datasource, true);
    ArrayList<JSForm> list = new ArrayList<JSForm>();
    while (forms.hasNext()) {
        list.add(instantiateForm(forms.next(), false));
    }
    return list.toArray(new JSForm[list.size()]);
}
Also used : Form(com.servoy.j2db.persistence.Form) ISMForm(com.servoy.j2db.solutionmodel.ISMForm) IBaseSMForm(com.servoy.base.solutionmodel.IBaseSMForm) ArrayList(java.util.ArrayList) FlattenedSolution(com.servoy.j2db.FlattenedSolution)

Example 40 with FlattenedSolution

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

the class JSSolutionModel method getValueLists.

/**
 * Gets an array of all valuelists for the currently active solution.
 *
 * NOTE: Changes to valuelist should be done before showing any form that has component using the valuelist.
 *
 * @sample
 * var valueLists = solutionModel.getValueLists();
 * if (valueLists != null && valueLists.length != 0)
 * 	for (var i in valueLists)
 * 		application.output(valueLists[i].name);
 *
 * @return an array of JSValueList objects
 */
@JSFunction
public JSValueList[] getValueLists() {
    FlattenedSolution fs = application.getFlattenedSolution();
    ArrayList<JSValueList> valuelists = new ArrayList<JSValueList>();
    Iterator<ValueList> iterator = fs.getValueLists(true);
    while (iterator.hasNext()) {
        valuelists.add(new JSValueList(iterator.next(), application, false));
    }
    return valuelists.toArray(new JSValueList[valuelists.size()]);
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) ArrayList(java.util.ArrayList) 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