use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class WebDataRenderer method getParentViewBgColor.
private String getParentViewBgColor() {
if (parentView != null) {
String rowBGColorCalculation = parentView.getRowBGColorScript();
IRecordInternal rec = (IRecordInternal) getDefaultModelObject();
if (rec != null && rec.getRawData() != null) {
IFoundSetInternal parentFoundSet = rec.getParentFoundSet();
int recIndex = parentFoundSet.getSelectedIndex();
boolean isSelected = recIndex == parentFoundSet.getRecordIndex(rec);
if (rowBGColorCalculation != null) {
Object bg_color = null;
if (rec.getRawData().containsCalculation(rowBGColorCalculation)) {
// data renderer is always on the selected index.
bg_color = parentFoundSet.getCalculationValue(rec, rowBGColorCalculation, Utils.arrayMerge(new Object[] { new Integer(recIndex), new Boolean(isSelected), null, null, Boolean.FALSE }, Utils.parseJSExpressions(parentView.getRowBGColorArgs())), null);
} else {
try {
FormController currentForm = dataAdapterList.getFormController();
bg_color = currentForm.executeFunction(rowBGColorCalculation, Utils.arrayMerge(new Object[] { new Integer(parentFoundSet.getSelectedIndex()), new Boolean(isSelected), null, null, currentForm.getName(), rec, Boolean.FALSE }, Utils.parseJSExpressions(parentView.getRowBGColorArgs())), true, null, true, null);
} catch (Exception ex) {
Debug.error(ex);
}
}
if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
return bg_color.toString();
}
}
if (parentView instanceof ISupportRowStyling) {
ISupportRowStyling parentViewWithRowStyling = (ISupportRowStyling) parentView;
IStyleSheet ss = parentViewWithRowStyling.getRowStyleSheet();
IStyleRule style = isSelected ? parentViewWithRowStyling.getRowSelectedStyle() : null;
if (style != null && style.getAttributeCount() == 0)
style = null;
if (style == null) {
style = (recIndex % 2 == 0) ? parentViewWithRowStyling.getRowEvenStyle() : parentViewWithRowStyling.getRowOddStyle();
}
if (ss != null && style != null) {
return PersistHelper.createColorString(ss.getBackground(style));
}
}
}
}
return null;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class WebTabPanel method registerSelectionListeners.
private void registerSelectionListeners(IRecordInternal parentState, String relationName) {
// $NON-NLS-1$
String[] parts = relationName.split("\\.");
IRecordInternal currentRecord = parentState;
for (int i = 0; currentRecord != null && i < parts.length - 1; i++) {
IFoundSetInternal fs = currentRecord.getRelatedFoundSet(parts[i]);
if (fs instanceof ISwingFoundSet) {
related.add((ISwingFoundSet) fs);
((ISwingFoundSet) fs).getSelectionModel().addListSelectionListener(this);
}
currentRecord = (fs == null) ? null : fs.getRecord(fs.getSelectedIndex());
}
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class MediaURLStreamHandler method getBlobLoaderMedia.
public static byte[] getBlobLoaderMedia(IServiceProvider application, String urlQueryPart) throws IOException {
// cannot work without a solution
if (application.getSolution() == null)
return null;
String datasource = null;
String serverName = null;
String tableName = null;
try {
if (urlQueryPart == null)
return null;
String dataProvider = null;
List<String> pks = new SafeArrayList<String>();
// $NON-NLS-1$
StringTokenizer tk = new StringTokenizer(urlQueryPart, "?&");
while (tk.hasMoreTokens()) {
String token = tk.nextToken();
if (// $NON-NLS-1$
token.startsWith("global=")) {
// $NON-NLS-1$
String globalName = token.substring("global=".length());
Object obj = application.getScriptEngine().getScopesScope().get(null, globalName);
if (obj instanceof byte[]) {
return (byte[]) obj;
}
if (obj instanceof String) {
// TODO check can we always just convert to the default encoding of this machine (server if web)
return ((String) obj).getBytes();
}
return null;
}
if (// $NON-NLS-1$
token.startsWith("servername=")) {
// $NON-NLS-1$
serverName = token.substring("servername=".length());
} else if (// $NON-NLS-1$
token.startsWith("tablename=")) {
// $NON-NLS-1$
tableName = token.substring("tablename=".length());
} else if (// $NON-NLS-1$
token.startsWith("datasource=")) {
// $NON-NLS-1$
datasource = token.substring("datasource=".length());
} else if (// $NON-NLS-1$
token.startsWith("dataprovider=")) {
// $NON-NLS-1$
dataProvider = token.substring("dataprovider=".length());
} else if (// $NON-NLS-1$
token.startsWith("rowid")) {
// get id
int index = Utils.getAsInteger(token.substring(5, 6));
if (index > 0) {
// get value after 'rowidX='
pks.add(index - 1, token.substring(7));
} else {
// get value after 'rowid='
pks.add(0, token.substring(6));
}
}
}
if (datasource == null && serverName != null && tableName != null) {
datasource = DataSourceUtils.createDBTableDataSource(serverName, tableName);
}
if (application.getFoundSetManager().getTable(datasource) == null) {
// $NON-NLS-1$
throw new IOException(Messages.getString("servoy.exception.serverAndTableNotFound", DataSourceUtils.getDBServernameTablename(datasource)));
}
FoundSet fs = (FoundSet) application.getFoundSetManager().getNewFoundSet(datasource);
// use mutable list here, elements are overwritten with Column.getAsRightType equivalent
List<Object[]> rows = new ArrayList<Object[]>(1);
rows.add(pks.toArray());
if (!fs.loadExternalPKList(new BufferedDataSet(null, null, rows))) {
return null;
}
IRecordInternal rec = fs.getRecord(0);
if (rec == null) {
return null;
}
Object blob_value = rec.getValue(dataProvider);
if (blob_value instanceof byte[]) {
return (byte[]) blob_value;
}
if (blob_value instanceof String) {
// TODO check can we always just convert to the default encoding of this machine (server if web)
return ((String) blob_value).getBytes();
}
} catch (Exception e) {
throw new IOException(e.getMessage());
}
return null;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class FormManager method ifRootFormInFind.
private boolean ifRootFormInFind(FormController fc) {
boolean result = false;
if (fc.isFormVisible() && fc.isInFindMode()) {
IFoundSetInternal foundSet = fc.getFoundSet();
if (foundSet instanceof RelatedFoundSet) {
// see if any parent foundset is in find mode; if not, then add it as root
// form in find mode
List<IRecordInternal> parentRecords = ((RelatedFoundSet) foundSet).getParents();
boolean hasParentsInFindMode = false;
for (IRecordInternal record : parentRecords) {
IFoundSetInternal parentFoundSet = record.getParentFoundSet();
if (parentFoundSet instanceof FoundSet && ((FoundSet) parentFoundSet).isInFindMode()) {
hasParentsInFindMode = true;
break;
}
}
if (!hasParentsInFindMode) {
result = true;
}
} else {
result = true;
}
}
return result;
}
use of com.servoy.j2db.dataprocessing.IRecordInternal in project servoy-client by Servoy.
the class RowReferencePropertyType method toRhinoValue.
@Override
public Object toRhinoValue(final String webComponentValue, PropertyDescription pd, IWebObjectContext componentOrService, Scriptable startScriptable) {
// TODO change this to another function class as it's not a call-to-client function in it's javadoc maybe? this is actually all on server
return new WebBaseFunction(null) {
@Override
public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
IRecordInternal record = null;
if (args != null && args.length == 1 && args[0] instanceof IFoundSetInternal) {
Pair<String, Integer> splitHashAndIndex = FoundsetTypeSabloValue.splitPKHashAndIndex(webComponentValue);
int recordIndex = ((IFoundSetInternal) args[0]).getRecordIndex(splitHashAndIndex.getLeft(), splitHashAndIndex.getRight().intValue());
if (recordIndex != -1)
record = ((IFoundSetInternal) args[0]).getRecord(recordIndex);
}
return record;
}
};
}
Aggregations