Search in sources :

Example 51 with FlattenedSolution

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

the class JSSolutionModel method getMediaList.

/**
 * Gets the list of all media objects.
 *
 * @sample
 * var mediaList = solutionModel.getMediaList();
 * if (mediaList.length != 0 && mediaList != null) {
 * 	for (var x in mediaList) {
 * 		application.output(mediaList[x]);
 * 	}
 * }
 *
 * 	@return a list with all the media objects.
 */
@JSFunction
public JSMedia[] getMediaList() {
    FlattenedSolution fs = application.getFlattenedSolution();
    ArrayList<JSMedia> lst = new ArrayList<JSMedia>();
    Iterator<Media> media = fs.getMedias(true);
    while (media.hasNext()) {
        lst.add(new JSMedia(media.next(), application.getFlattenedSolution(), false));
    }
    return lst.toArray(new JSMedia[lst.size()]);
}
Also used : ArrayList(java.util.ArrayList) Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 52 with FlattenedSolution

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

the class JSSolutionModel method removeValueList.

/**
 * Removes the specified valuelist.
 *
 * @sample
 * var vlName = "customValueList";
 * var vl = solutionModel.newValueList(vlName,JSValueList.CUSTOM_VALUES);
 * vl.customValues = "customvalue1\ncustomvalue2";
 *
 * var status = solutionModel.removeValueList(vlName);
 * if (status) application.output("Removal has been done.");
 * else application.output("ValueList not removed.");
 *
 * var vls = solutionModel.getValueLists();
 * if (vls != null) {
 * 	for (var i = 0; i < vls.length; i++) {
 * 		application.output(vls[i]);
 * 	}
 * 	application.output("");
 * }
 *
 * @param name name of the valuelist to be removed
 *
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeValueList(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    ValueList valueList = fs.getValueList(name);
    if (valueList != null) {
        fs.deletePersistCopy(valueList, false);
        return true;
    }
    return false;
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 53 with FlattenedSolution

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

the class JSSolutionModel method removeGlobalVariable.

/**
 * Removes the specified global variable.
 *
 * @sample
 * var v1 = solutionModel.newGlobalVariable('globals', 'globalVar1', JSVariable.INTEGER);
 * var v2 = solutionModel.newGlobalVariable('globals', 'globalVar2', JSVariable.TEXT);
 *
 * var success = solutionModel.removeGlobalVariable('globals', 'globalVar1');
 * if (success == false) application.output('!!! globalVar1 could not be removed !!!');
 *
 * var list = solutionModel.getGlobalVariables('globals');
 * for (var i = 0; i < list.length; i++) {
 * 	application.output(list[i].name + '[ ' + list[i].variableType + ']: ' + list[i].variableType);
 * }
 *
 * @param scopeName the scope in which the variable is declared
 * @param name the name of the global variable to be removed
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeGlobalVariable(String scopeName, String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    ScriptVariable sv = fs.getScriptVariable(scopeName, name);
    if (sv != null) {
        fs.deletePersistCopy(sv, false);
        return true;
    }
    return false;
}
Also used : ScriptVariable(com.servoy.j2db.persistence.ScriptVariable) FlattenedSolution(com.servoy.j2db.FlattenedSolution) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 54 with FlattenedSolution

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

the class JSSolutionModel method newMedia.

/**
 * Creates a new media object that can be assigned to a label or a button.
 *
 * @sample
 * var myMedia = solutionModel.newMedia('button01.gif',bytes)
 * //now set the imageMedia property of your label or button
 * //myButton.imageMedia = myMedia
 * // OR
 * //myLabel.imageMedia = myMedia
 *
 * @param name The name of the new media
 *
 * @param bytes The content
 *
 * @return a JSMedia object
 */
@JSFunction
public JSMedia newMedia(String name, byte[] bytes) {
    FlattenedSolution fs = application.getFlattenedSolution();
    try {
        Media media = fs.getSolutionCopy().createNewMedia(new ScriptNameValidator(fs), name);
        media.setPermMediaData(bytes);
        media.setMimeType(MimeTypes.getContentType(bytes));
        return new JSMedia(media, application.getFlattenedSolution(), true);
    } catch (RepositoryException e) {
        throw new RuntimeException("error createing new media with name " + name, e);
    }
}
Also used : Media(com.servoy.j2db.persistence.Media) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptNameValidator(com.servoy.j2db.persistence.ScriptNameValidator) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 55 with FlattenedSolution

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

the class JSSolutionModel method getValueList.

/**
 * Gets an existing valuelist by the specified name and returns a JSValueList Object that can be assigned to a field.
 *
 * NOTE: Changes to valuelist should be done before showing any form that has component using the valuelist.
 *
 * @sample
 * var myValueList = solutionModel.getValueList('myValueListHere')
 * //now set the valueList property of your field
 * //myField.valuelist = myValueList
 *
 * @param name the specified name of the valuelist
 *
 * @return a JSValueList object
 */
@JSFunction
public JSValueList getValueList(String name) {
    FlattenedSolution fs = application.getFlattenedSolution();
    ValueList valuelist = fs.getValueList(name);
    if (valuelist != null) {
        return new JSValueList(valuelist, application, false);
    }
    return null;
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) 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