use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method removeGlobalMethod.
/**
* Removes the specified global method.
*
* @sample
* var m1 = solutionModel.newGlobalMethod('globals', 'function myglobalmethod1(){application.output("Global Method 1");}');
* var m2 = solutionModel.newGlobalMethod('globals', 'function myglobalmethod2(){application.output("Global Method 2");}');
*
* var success = solutionModel.removeGlobalMethod('globals', 'myglobalmethod1');
* if (success == false) application.output('!!! myglobalmethod1 could not be removed !!!');
*
* var list = solutionModel.getGlobalMethods('globals');
* for (var i = 0; i < list.length; i++) {
* application.output(list[i].code);
* }
*
* @param scopeName the scope in which the method is declared
* @param name the name of the global method to be removed
* @return true if the removal was successful, false otherwise
*/
@JSFunction
public boolean removeGlobalMethod(String scopeName, String name) {
FlattenedSolution fs = application.getFlattenedSolution();
ScriptMethod sm = fs.getScriptMethod(scopeName, name);
if (sm != null) {
fs.deletePersistCopy(sm, false);
if (application.getFormManager() instanceof FormManager)
((FormManager) application.getFormManager()).fillScriptMenu();
return true;
}
return false;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method removeRelation.
/**
* Removes the relation specified by name. You cannot remove the relation if it is touched within the application.
* So even if you remove all the ui elements using it, like tabs, it still can't be removed, because of underlying created and cached data.
*
* @sample
* var success = solutionModel.removeRelation('myRelation');
* if (success) { application.output("Relation has been removed");}
* else {application.output("Relation could not be removed");}
*
* @param name the name of the relation to be removed
*
* @return true if the removal was successful, false otherwise
*/
@JSFunction
public boolean removeRelation(String name) {
FlattenedSolution fs = application.getFlattenedSolution();
Relation rel = fs.getRelation(name);
if (rel != null) {
try {
if (((FoundSetManager) application.getFoundSetManager()).getSQLGenerator().getCachedTableSQLSheet(rel.getForeignDataSource()).getRelatedSQLDescription(name) != null) {
return false;
}
fs.deletePersistCopy(rel, false);
} catch (ServoyException e) {
Debug.error(e);
return false;
}
return true;
}
return false;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method revertForm.
/**
* Reverts the specified form to the original (blueprint) version of the form; will result in an exception error if the form is not an original form.
*
* NOTE: Make sure you call history.remove first in your Servoy method (script) or call form.controller.recreateUI() before the script ends.
*
* @sample
* // revert the form to the original solution form, removing any changes done to it through the solution model.
* var revertedForm = solutionModel.revertForm('myForm')
* // add a label on a random place.
* revertedForm.newLabel("MyLabel",Math.random()*100,Math.random()*100,80,20);
* // make sure that the ui is up to date.
* forms.myForm.controller.recreateUI();
*
* @param name the specified name of the form to revert
*
* @return a JSForm object
*/
@JSFunction
public JSForm revertForm(String name) {
FlattenedSolution fs = application.getFlattenedSolution();
Form form = fs.revertForm(name);
if (form != null) {
application.getFormManager().addForm(form, false);
return instantiateForm(form, false);
} else {
form = application.getFormManager().getPossibleForm(name);
if (form != null) {
application.getFormManager().removeForm(form);
}
}
return null;
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method getAllRelations.
/**
* Gets an array of all relations.
*
* @sample
* var relations = solutionModel.getAllRelations();
* if (relations.length != 0)
* for (var i in relations)
* application.output(relations[i].name);
*
* @return an array of all relations (all elements in the array are of type JSRelation)
*/
@JSFunction
public JSRelation[] getAllRelations() {
FlattenedSolution fs = application.getFlattenedSolution();
try {
List<JSRelation> relations = new ArrayList<JSRelation>();
Iterator<Relation> iterator = fs.getRelations(true);
while (iterator.hasNext()) {
relations.add(new JSRelation(iterator.next(), application, false));
}
return relations.toArray(new JSRelation[relations.size()]);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.FlattenedSolution in project servoy-client by Servoy.
the class JSSolutionModel method getGlobalMethod.
/**
* Gets an existing global method by the specified name.
*
* @sample
* var method = solutionModel.getGlobalMethod('globals', 'nameOfGlobalMethod');
* if (method != null) application.output(method.code);
*
* @param scopeName the scope in which the method is searched
* @param name the name of the specified global method
*
* @return a JSMethod
*/
@JSFunction
public JSMethod getGlobalMethod(String scopeName, String name) {
FlattenedSolution fs = application.getFlattenedSolution();
ScriptMethod sm = fs.getScriptMethod(scopeName, name);
if (sm != null) {
return new JSMethod(sm, application, false);
}
return null;
}
Aggregations