Search in sources :

Example 41 with FlattenedSolution

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

the class JSSolutionModel method removeStyle.

/**
 * Removes the specified style.
 *
 * @sample
 * var s = solutionModel.newStyle("smStyle1",'form { background-color: yellow; }');
 * var status = solutionModel.removeStyle("smStyle1");
 * if (status == false) application.output("Could not remove style.");
 * else application.output("Style removed.");
 *
 * @param name the name of the style to be removed
 *
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeStyle(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Style style = fs.getStyle(name);
    if (style != null) {
        fs.removeStyle(name);
        return true;
    }
    return false;
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) Style(com.servoy.j2db.persistence.Style) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 42 with FlattenedSolution

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

the class JSSolutionModel method removeMedia.

/**
 * Removes the media item specified by name.
 *
 * @sample
 * var bytes1 = plugins.file.readFile('D:/Imgs/image1.png');
 * var image1 = solutionModel.newMedia('image1.png', bytes1);
 * var bytes2 = plugins.file.readFile('D:/Imgs/image2.jpg');
 * var image2 = solutionModel.newMedia('image2.jpg',bytes2);
 * var bytes3 = plugins.file.readFile('D:/Imgs/image3.jpg');
 * var image3 = solutionModel.newMedia('image3.jpg',bytes3);
 *
 * var f = solutionModel.newForm("newForm",databaseManager.getDataSource('example_data', 'orders'),null,false,500,350);
 * var l = f.newLabel('', 20, 70, 300, 200);
 * l.imageMedia = image1;
 * l.borderType =  solutionModel.createLineBorder(4,'#ff0000');
 * forms["newForm"].controller.show();
 *
 * var status = solutionModel.removeMedia('image1.jpg');
 * if (status) application.output("image1.png has been removed");
 * else application.output("image1.png has not been removed");
 *
 * var mediaList = solutionModel.getMediaList();
 * for (var i = 0; i < mediaList.length; i++) {
 * 	application.output(mediaList[i].getName() + ":" + mediaList[i].mimeType);
 * }
 *
 * @param name the name of the media item to be removed
 *
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeMedia(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    Media mediaItem = fs.getMedia(name);
    if (mediaItem != null) {
        fs.deletePersistCopy(mediaItem, false);
        return true;
    }
    return false;
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 43 with FlattenedSolution

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

the class JSSolutionModel method getGlobalVariable.

/**
 * Gets an existing global variable by the specified name.
 *
 * @sample
 * var globalVariable = solutionModel.getGlobalVariable('globals', 'globalVariableName');
 * application.output(globalVariable.name + " has the default value of " + globalVariable.defaultValue);
 *
 * @param scopeName the scope in which the variable is searched
 * @param name the specified name of the global variable
 *
 * @return a JSVariable
 */
@JSFunction
public JSVariable getGlobalVariable(String scopeName, String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    ScriptVariable variable = fs.getScriptVariable(scopeName, name);
    if (variable != null) {
        return new JSVariable(application, variable, false);
    }
    return null;
}
Also used : ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 44 with FlattenedSolution

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

the class JSSolutionModel method getRelations.

/**
 * @clonedesc getRelations(String)
 * @sampleas getRelations(String)
 * @param servername the specified name of the server for the specified table
 * @param tablename the specified name of the table
 *
 * @return an array of all relations (all elements in the array are of type JSRelation)
 */
@JSFunction
public JSRelation[] getRelations(String servername, String tablename) {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        Table primaryTable = null;
        if (servername != null && tablename != null) {
            IServer primaryServer = fs.getSolution().getServer(servername);
            if (primaryServer == null)
                throw new RuntimeException("can't list relations, primary server not found: " + servername);
            primaryTable = (Table) primaryServer.getTable(tablename);
            if (primaryTable == null)
                throw new RuntimeException("can't list relations, primary table not found: " + tablename);
        }
        List<JSRelation> relations = new ArrayList<JSRelation>();
        Iterator<Relation> iterator = fs.getRelations(primaryTable, true, true);
        while (iterator.hasNext()) {
            Relation relation = iterator.next();
            if (((primaryTable == null) == relation.isGlobal()) && !relation.isInternal()) {
                relations.add(new JSRelation(relation, application, false));
            }
        }
        return relations.toArray(new JSRelation[relations.size()]);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : IServer(com.servoy.j2db.persistence.IServer) ISMRelation(com.servoy.j2db.solutionmodel.ISMRelation) Relation(com.servoy.j2db.persistence.Relation) Table(com.servoy.j2db.persistence.Table) 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 45 with FlattenedSolution

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

the class JSSolutionModel method getForm.

/**
 * Gets the specified form object and returns information about the form (see JSForm node).
 *
 * @sample
 * var myForm = solutionModel.getForm('existingFormName');
 * //get the style of the form (for all other properties see JSForm node)
 * var styleName = myForm.styleName;
 *
 * @param name the specified name of the form
 *
 * @return a JSForm
 */
@JSFunction
public JSForm getForm(String name) {
    if (name == null)
        return null;
    Form form = application.getFormManager().getPossibleForm(name);
    if (form == null) {
        FlattenedSolution fs = application.getFlattenedSolution();
        form = fs.getForm(name);
        if (form == null) {
            // search ignoring case
            Iterator<Form> forms = fs.getForms(false);
            String lowerCaseName = Utils.toEnglishLocaleLowerCase(name);
            Form f;
            while (forms.hasNext() && form == null) {
                f = forms.next();
                if (Utils.toEnglishLocaleLowerCase(f.getName()).equals(lowerCaseName))
                    form = f;
            }
        }
    }
    if (form != null) {
        return instantiateForm(form, false);
    }
    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)

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