use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method newGlobalMethod.
/**
* Creates a new global method with the specified code in a scope.
*
* @sample
* var method = solutionModel.newGlobalMethod('globals', 'function myglobalmethod(){foundset.newRecord()}')
*
* @param scopeName the scope in which the method is created
* @param code the specified code for the global method
*
* @return a JSMethod object
*/
@JSFunction
public JSMethod newGlobalMethod(String scopeName, String code) {
FlattenedSolution fs = application.getFlattenedSolution();
String name = JSMethod.parseName(code);
try {
String scope = scopeName == null ? ScriptVariable.GLOBAL_SCOPE : scopeName;
ScriptMethod method = fs.getSolutionCopy().createNewGlobalScriptMethod(new ScriptNameValidator(application.getFlattenedSolution()), scope, name);
method.setDeclaration(code);
application.getScriptEngine().getScopesScope().getGlobalScope(scope).put(method, method);
JSMethod jsMethod = new JSMethod(method, application, true);
return jsMethod;
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method newForm.
protected JSForm newForm(String name, String dataSource, String styleName, boolean show_in_menu, int width, int height, boolean isResponsive) {
FlattenedSolution fs = application.getFlattenedSolution();
try {
Style style = null;
if (styleName != null) {
style = fs.getStyle(styleName);
}
Form form = createNewForm(style, IdentDocumentValidator.checkName(name), dataSource, show_in_menu, new Dimension(width, height));
if (!isResponsive) {
form.createNewPart(Part.BODY, height);
} else {
form.setResponsiveLayout(true);
}
if (fs.getSolution().getSolutionType() == SolutionMetaData.MOBILE) {
// mobile solution, make the form mobile
form.putCustomMobileProperty(IMobileProperties.MOBILE_FORM.propertyName, Boolean.TRUE);
// set internal style name
form.setStyleName("_servoy_mobile");
}
application.getFormManager().addForm(form, false);
return instantiateForm(form, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method getMedia.
/**
* Gets the specified media object; can be assigned to a button/label.
*
* @sample
* var myMedia = solutionModel.getMedia('button01.gif')
* //now set the imageMedia property of your label or button
* //myButton.imageMedia = myMedia
* // OR
* //myLabel.imageMedia = myMedia
*
* @param name the specified name of the media object
*
* @return a JSMedia element
*/
@JSFunction
public JSMedia getMedia(String name) {
FlattenedSolution fs = application.getFlattenedSolution();
Media media = fs.getMedia(name);
if (media != null) {
return new JSMedia(media, application.getFlattenedSolution(), false);
}
return null;
}
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);
}
}
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);
}
}
Aggregations