use of com.servoy.j2db.persistence.ScriptNameValidator 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.persistence.ScriptNameValidator 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);
}
}
use of com.servoy.j2db.persistence.ScriptNameValidator 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);
}
}
use of com.servoy.j2db.persistence.ScriptNameValidator in project servoy-client by Servoy.
the class JSForm method newMethod.
/**
* Creates a new form JSMethod - based on the specified code.
*
* @sample
* var form = solutionModel.newForm('newForm1', myDatasource, null, true, 800, 600);
* var method = form.newMethod('function aMethod(event){application.output("Hello world!");}');
* var button = myListViewForm.newButton('Show message!',50,50,100,30,method);
* forms['newForm1'].controller.show();
*
* @param code the specified code for the new method
*
* @return a new JSMethod object for this form
*/
@JSFunction
public JSMethod newMethod(String code) {
checkModification();
String name = JSMethod.parseName(code);
try {
ScriptMethod method = getForm().createNewScriptMethod(new ScriptNameValidator(application.getFlattenedSolution()), name);
method.setDeclaration(code);
// addMethodToScopes(method);
refreshFromScopes();
return new JSMethod(this, method, application, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.persistence.ScriptNameValidator in project servoy-client by Servoy.
the class JSMethod method setCode.
@JSSetter
public void setCode(String content) {
// if a default constant
if (sm == null)
return;
checkModification();
String name = parseName(content);
if (!name.equals(sm.getName())) {
try {
sm.updateName(new ScriptNameValidator(application.getFlattenedSolution()), name);
} catch (RepositoryException e) {
// $NON-NLS-1$ //$NON-NLS-2$
throw new RuntimeException("Error updating the name from " + sm.getName() + " to " + name, e);
}
}
sm.setDeclaration(content);
if (parent instanceof JSDataSourceNode) {
// foundset method
application.getFoundSetManager().reloadFoundsetMethod(((JSDataSourceNode) parent).getSupportChild().getDataSource(), sm);
} else if (parent == null && application.getScriptEngine().getScopesScope().has(sm.getScopeName(), null)) {
// global method
application.getScriptEngine().getScopesScope().getGlobalScope(sm.getScopeName()).put(sm, sm);
}
}
Aggregations