use of com.servoy.j2db.persistence.ScriptVariable in project servoy-client by Servoy.
the class FlattenedSolution method getGlobalDataProviderEx.
private IDataProvider getGlobalDataProviderEx(String id, boolean quiet) throws RepositoryException {
if (id == null)
return null;
Pair<String, String> scope = ScopesUtils.getVariableScope(id);
if (scope.getLeft() != null) /* global scope */
{
// search all objects,will return globals
ScriptVariable global = AbstractBase.selectByName(getScriptVariables(scope.getLeft(), false), scope.getRight());
if (global != null) {
return global;
}
// try @enum global variables
return getEnumDataProvider(id);
}
// in case of multi-level relations we have more that 1 dot
int indx = id.lastIndexOf('.');
if (indx > 0) {
String rel_name = id.substring(0, indx);
String col = id.substring(indx + 1);
Relation[] relations = getRelationSequence(rel_name);
if (relations == null) {
return null;
}
Relation r = relations[relations.length - 1];
if (quiet) {
boolean missingSrv = true;
String ds = r.getForeignDataSource();
if (ds != null) {
String[] st = DataSourceUtilsBase.getDBServernameTablename(ds);
if (st != null && st.length == 2) {
try {
missingSrv = (r.getRootObject().getServer(st[0]) == null);
} catch (RemoteException e) {
// we are in developer here - shouldn't happen
}
}
}
if (missingSrv)
return null;
}
// TODO if this is refactord out to be resolved outside the relation also look at the DataProviderConverter
// the call from that class to flattenedSolution.getGlobalDataProvider(value);
Column[] cols = r.getForeignColumns(this);
if (cols == null || cols.length == 0)
return null;
IDataProvider c = getDataProviderForTable(getTable(r.getForeignDataSource()), col);
if (r != null && c instanceof IColumn) {
return new ColumnWrapper((IColumn) c, relations);
}
return c;
}
return null;
}
use of com.servoy.j2db.persistence.ScriptVariable in project servoy-client by Servoy.
the class FormScope method remove.
@Override
public void remove(ScriptVariable var) {
ScriptVariable newVar = null;
for (ScriptVariable loopVar : Utils.iterate(getScriptLookup().getScriptVariables(false))) {
if (loopVar.getName().equals(var.getName())) {
newVar = loopVar;
break;
}
}
if (newVar == null) {
super.remove(var);
} else {
Form form = getFormController().getForm();
Form deletedVarForm = (Form) var.getParent();
Form newVarForm = (Form) newVar.getParent();
while (form != null) {
// when the deleted form var is found first in the hiearchy
if (form.getName().equals(deletedVarForm.getName())) {
// then remove this var, and put the new one in.
super.remove(var);
put(newVar);
break;
} else if (form.getName().equals(newVarForm.getName())) {
// else if the newVarForm is still found first (then it is already the current one)
return;
}
form = form.getExtendsForm();
}
}
}
use of com.servoy.j2db.persistence.ScriptVariable in project servoy-client by Servoy.
the class DataRenderer method createDataAdapter.
void createDataAdapter(IApplication app, IDataProviderLookup dataProviderLookup, IScriptExecuter el, ControllerUndoManager undoManager) throws Exception {
// IScriptExecutor can be null for a design component
FormController formController = el == null ? null : el.getFormController();
dataAdapterList = new DataAdapterList(app, dataProviderLookup, fieldComponents, formController, null, undoManager);
// make it really fields only
HashMap<IPersist, IDisplay> f = new HashMap<IPersist, IDisplay>();
Iterator<Map.Entry<IPersist, IDisplay>> it = fieldComponents.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<IPersist, IDisplay> element = it.next();
if (element.getValue() instanceof IDisplayData) {
String id = ((IDisplayData) element.getValue()).getDataProviderID();
if (dataProviderLookup.getDataProvider(id) instanceof ScriptVariable) {
globalFields.add(element.getValue());
}
f.put(element.getKey(), element.getValue());
}
}
fieldComponents = f;
}
use of com.servoy.j2db.persistence.ScriptVariable in project servoy-client by Servoy.
the class FoundSet method getPrototype.
public Scriptable getPrototype() {
if (prototypeScope == null) {
LazyCompilationScope scope = new LazyCompilationScope(this, fsm.getApplication().getScriptEngine(), new ISupportScriptProviders() {
public Iterator<? extends IScriptProvider> getScriptMethods(boolean sort) {
List<ScriptMethod> methods = null;
Iterator<TableNode> tableNodes = fsm.getApplication().getFlattenedSolution().getTableNodes(getTable());
while (tableNodes.hasNext()) {
TableNode tn = tableNodes.next();
Iterator<ScriptMethod> fsMethods = tn.getFoundsetMethods(sort);
if (methods == null) {
if (!tableNodes.hasNext()) {
// just 1
return fsMethods;
}
methods = new ArrayList<ScriptMethod>();
}
while (fsMethods.hasNext()) {
methods.add(fsMethods.next());
}
}
return methods == null ? Collections.<ScriptMethod>emptyList().iterator() : methods.iterator();
}
public Iterator<ScriptVariable> getScriptVariables(boolean b) {
return Collections.<ScriptVariable>emptyList().iterator();
}
public ScriptMethod getScriptMethod(int methodId) {
// not called by LCS
return null;
}
}) {
@Override
public String getClassName() {
// $NON-NLS-1$
return "FoundSetScope";
}
@Override
public String getScopeName() {
return getDataSource();
}
};
// make sure functions like getSize cannot be overridden
scope.setFunctionParentScriptable(this);
prototypeScope = scope;
}
return prototypeScope;
}
use of com.servoy.j2db.persistence.ScriptVariable in project servoy-client by Servoy.
the class JSForm method getVariables.
/**
* An array consisting of all form variables for this form.
*
* @sample
* var frm = solutionModel.getForm("myForm");
* var variables = frm.getVariables();
* for (var i in variables)
* application.output(variables[i].name);
*
* @param returnInheritedElements boolean true to also return the elements from the parent form
* @return an array of all variables on this form
*/
@JSFunction
public JSVariable[] getVariables(boolean returnInheritedElements) {
List<JSVariable> variables = new ArrayList<JSVariable>();
Form form2use = returnInheritedElements ? getFlattenedContainer() : getForm();
Iterator<ScriptVariable> scriptVariables = form2use.getScriptVariables(true);
while (scriptVariables.hasNext()) {
variables.add(new JSVariable(application, this, scriptVariables.next(), false));
}
return variables.toArray(new JSVariable[variables.size()]);
}
Aggregations