use of com.servoy.j2db.dataprocessing.Record in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method createScriptEvent.
public JSDNDEvent createScriptEvent(EventType type, IComponent dragSource, Point xy, int modifiers) {
JSDNDEvent jsEvent = new JSDNDEvent();
jsEvent.setType(type);
jsEvent.setFormName(getDragFormName());
if (dragSource instanceof IDataRenderer) {
IDataRenderer dr = (IDataRenderer) dragSource;
FormController fct = dr.getDataAdapterList().getFormController();
jsEvent.setSource(fct.getFormScope());
} else {
jsEvent.setSource(dragSource);
if (dragSource != null) {
if (dragSource instanceof Component) {
WebCellBasedViewListItem listItem = ((Component) dragSource).findParent(WebCellBasedViewListItem.class);
if (listItem != null) {
IRecordInternal dragRecord = listItem.getModelObject();
if (dragRecord instanceof Record)
jsEvent.setRecord((Record) dragRecord);
}
}
String dragSourceName = dragSource.getName();
if (dragSourceName == null)
dragSourceName = dragSource.getId();
jsEvent.setElementName(dragSourceName);
}
}
if (xy != null)
jsEvent.setLocation(xy);
jsEvent.setModifiers(modifiers);
return jsEvent;
}
use of com.servoy.j2db.dataprocessing.Record in project servoy-client by Servoy.
the class WebDataRenderer method createScriptEvent.
private JSDNDEvent createScriptEvent(EventType type, IComponent dragSource, Point xy, int modifiers) {
JSDNDEvent jsEvent = new JSDNDEvent();
jsEvent.setType(type);
jsEvent.setFormName(getDragFormName());
IRecordInternal dragRecord = getDragRecord(xy);
if (dragRecord instanceof Record)
jsEvent.setRecord((Record) dragRecord);
if (dragSource instanceof IDataRenderer) {
IDataRenderer dr = (IDataRenderer) dragSource;
FormController fct = dr.getDataAdapterList().getFormController();
jsEvent.setSource(fct.getFormScope());
} else {
jsEvent.setSource(dragSource);
if (dragSource != null) {
String dragSourceName = dragSource.getName();
if (dragSourceName == null)
dragSourceName = dragSource.getId();
jsEvent.setElementName(dragSourceName);
}
}
if (xy != null)
jsEvent.setLocation(xy);
jsEvent.setModifiers(modifiers);
return jsEvent;
}
use of com.servoy.j2db.dataprocessing.Record in project servoy-client by Servoy.
the class FormDataTransferHandler method createScriptEvent.
@Override
protected JSDNDEvent createScriptEvent(EventType type, ICompositeDragNDrop ddComponent, Object event) {
JSDNDEvent jsEvent = super.createScriptEvent(type, ddComponent, event);
if (ddComponent instanceof IFormDataDragNDrop) {
IFormDataDragNDrop formDataDDComponent = (IFormDataDragNDrop) ddComponent;
jsEvent.setFormName(formDataDDComponent.getDragFormName());
Point location = getEventXY(event);
if (location != null) {
Object dragSource = ddComponent.getDragSource(location);
if (dragSource instanceof IDataRenderer) {
IDataRenderer dr = (IDataRenderer) dragSource;
FormController fc = dr.getDataAdapterList().getFormController();
jsEvent.setSource(fc.getFormScope());
} else if (dragSource instanceof IComponent) {
jsEvent.setSource(dragSource);
if (dragSource != null) {
String name = ((IComponent) dragSource).getName();
if (name != null && name.startsWith(ComponentFactory.WEB_ID_PREFIX)) {
name = null;
}
jsEvent.setElementName(name);
}
}
IRecordInternal dragRecord = formDataDDComponent.getDragRecord(location);
if (dragRecord instanceof Record)
jsEvent.setRecord((Record) dragRecord);
}
}
return jsEvent;
}
use of com.servoy.j2db.dataprocessing.Record in project servoy-client by Servoy.
the class TableScope method getCalculationValue.
private Object getCalculationValue(Function calculation, String name) {
Scriptable proto = getPrototype();
// we can't return then anything.
if (proto == null) {
return null;
}
Object[] array = getThreadLocalArray();
List<String> callStack = (List<String>) array[2];
if (callStack == null) {
callStack = new ArrayList<String>();
array[2] = callStack;
}
Record record = null;
String callStackName = name;
if (proto instanceof Record) {
record = (Record) proto;
callStackName = callStackName + '_' + record.getRawData().getPKHashKey();
}
UsedDataProviderTracker tracker = null;
try {
boolean contains = callStack.contains(callStackName);
// first add before doing anything else!
callStack.add(callStackName);
// now we decide if we try to return from row cache or calculate again
if (contains) {
if (record != null) {
return record.getRawData().getValue(name);
}
// $NON-NLS-1$
throw new RuntimeException(Messages.getString("servoy.error.cycleDetected", new Object[] { name, table.getName(), callStack }));
}
tracker = usedDataProviderTracker.get();
if (tracker != null) {
((RecordingScriptable) getFunctionParentScriptable()).pushRecordingTracker(tracker);
setUsedDataProviderTracker(null);
}
Object o = scriptEngine.executeFunction(calculation, this, getFunctionParentScriptable(), (Object[]) array[1], false, false);
// record value trick
if (o instanceof Undefined && record != null)
o = record.getRawData().getValue(name);
return o;
} catch (Exception e) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getString("servoy.error.executingCalculation", new Object[] { name, table.getName(), e.toString() }), e);
} finally {
if (tracker != null) {
((RecordingScriptable) getFunctionParentScriptable()).popRecordingTracker();
}
callStack.remove(callStackName);
if (callStack.size() == 0) {
// clear the thread locals.
values.remove();
}
}
}
use of com.servoy.j2db.dataprocessing.Record in project servoy-client by Servoy.
the class Utils method getScriptableString.
/**
* Returns a js/json string representation of the given {@link Scriptable}
* @param scriptable
* @param processed map to prevent loops in graph
* @return the scriptable as string
*/
private static CharSequence getScriptableString(Scriptable scriptable, Map<Scriptable, CharSequence> processed) {
Context.enter();
try {
if (scriptable instanceof Record || scriptable instanceof FoundSet)
return scriptable.toString();
if (scriptable instanceof XMLObject || scriptable instanceof NativeError)
return scriptable.toString();
CharSequence processedString = processed.get(scriptable);
if (processedString != null) {
return processedString;
}
if (processed.size() > 10)
return scriptable.toString();
if (// $NON-NLS-1$
scriptable instanceof NativeArray)
// $NON-NLS-1$
processed.put(scriptable, "Array[SelfRef]");
else
// $NON-NLS-1$
processed.put(scriptable, "Object[SelfRef]");
Object[] ids = scriptable.getIds();
if (ids != null && ids.length > 0) {
StringBuilder sb = new StringBuilder();
if (scriptable instanceof NativeArray)
sb.append('[');
else
sb.append('{');
for (Object object : ids) {
if (!(object instanceof Integer)) {
sb.append(object);
sb.append(':');
}
Object value = null;
if (object instanceof String) {
value = scriptable.get((String) object, scriptable);
} else if (object instanceof Number) {
value = scriptable.get(((Number) object).intValue(), scriptable);
}
if (!(value instanceof NativeJavaMethod)) {
if (value instanceof Scriptable) {
sb.append(getScriptableString((Scriptable) value, processed));
} else {
sb.append(value);
}
sb.append(',');
}
}
sb.setLength(sb.length() - 1);
if (scriptable instanceof NativeArray)
sb.append(']');
else
sb.append('}');
processed.put(scriptable, sb);
return sb;
}
Object defaultValue;
try {
defaultValue = scriptable.getDefaultValue(String.class);
} catch (Exception e) {
defaultValue = null;
}
if (defaultValue == null)
defaultValue = scriptable.toString();
processed.put(scriptable, defaultValue.toString());
return defaultValue.toString();
} finally {
Context.exit();
}
}
Aggregations