Search in sources :

Example 1 with FlattenedSolution

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

the class WebTabPanel method addTab.

public boolean addTab(IForm formController, String formName, String tabname, String tabText, String tabtooltip, String iconURL, String fg, String bg, String relationName, RelatedFoundSet relatedFs, int idx) {
    if (formController != null) {
        // to make sure we don't have recursion on adding a tab, to a tabpanel, that is based
        // on the form that the tabpanel is placed on
        WebForm webForm = findParent(WebForm.class);
        if (webForm != null) {
            FormController parentFormController = webForm.getController();
            if (parentFormController != null && parentFormController.equals(formController)) {
                return false;
            }
        }
    }
    WebTabFormLookup flp = (WebTabFormLookup) createFormLookupPanel(tabname, relationName, formName);
    if (formController != null)
        flp.setReadOnly(formController.isReadOnly());
    FlattenedSolution fl = application.getFlattenedSolution();
    int mediaId = -1;
    if (iconURL != null && !"".equals(iconURL)) {
        Media media = fl.getMedia(iconURL.replaceAll("media:///", ""));
        if (media != null)
            mediaId = media.getID();
        if (mediaId == -1) {
            Debug.warn("Form '" + formController.getName() + "' with tabpanel  '" + this.name + "' has tabicon  for tab '" + tabname + "'in with icon media url : " + iconURL + " not found");
        }
    }
    byte[] iconData = (mediaId == -1 ? null : ComponentFactory.loadIcon(fl, new Integer(mediaId)));
    int count = allTabs.size();
    int tabIndex = idx;
    if (tabIndex == -1 || tabIndex >= count) {
        tabIndex = count;
    }
    insertTab(application.getI18NMessageIfPrefixed(tabText), iconData, flp, application.getI18NMessageIfPrefixed(tabtooltip), tabIndex, true);
    if (fg != null)
        setTabForegroundAt(tabIndex, PersistHelper.createColor(fg));
    if (bg != null)
        setTabBackgroundAt(tabIndex, PersistHelper.createColor(bg));
    // from the relatedFs - which is already in the relationName param
    if (relatedFs != null && currentForm == flp) {
        FormController fp = flp.getWebForm().getController();
        if (fp != null && flp.getRelationName() != null && flp.getRelationName().equals(relationName)) {
            fp.loadData(relatedFs, null);
        }
    }
    return true;
}
Also used : FormController(com.servoy.j2db.FormController) WebForm(com.servoy.j2db.server.headlessclient.WebForm) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Point(java.awt.Point)

Example 2 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)

Example 3 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 4 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 5 with FlattenedSolution

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

the class JSForm method setDataSource.

@JSSetter
public void setDataSource(String arg) {
    // check syntax, do not accept invalid URIs
    if (arg != null) {
        try {
            new URI(arg);
        } catch (URISyntaxException e) {
            // $NON-NLS-1$//$NON-NLS-2$
            throw new RuntimeException("Invalid dataSource URI: '" + arg + "' :" + e.getMessage());
        }
    }
    checkModification();
    getForm().setDataSource(arg);
    // clear the data provider lookups affected by this change
    FlattenedSolution fs = application.getFlattenedSolution();
    fs.flushDataProviderLookups(getForm());
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) JSSetter(org.mozilla.javascript.annotations.JSSetter)

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