Search in sources :

Example 46 with IRecordInternal

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;
}
Also used : FormController(com.servoy.j2db.FormController) Undefined(org.mozilla.javascript.Undefined) ISupportRowStyling(com.servoy.j2db.ui.ISupportRowStyling) IStyleSheet(com.servoy.j2db.util.IStyleSheet) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Point(java.awt.Point) NoSuchElementException(java.util.NoSuchElementException) IStyleRule(com.servoy.j2db.util.IStyleRule)

Example 47 with IRecordInternal

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());
    }
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Point(java.awt.Point) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet)

Example 48 with IRecordInternal

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;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) IOException(java.io.IOException) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet)

Example 49 with IRecordInternal

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;
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet)

Example 50 with IRecordInternal

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;
        }
    };
}
Also used : Context(org.mozilla.javascript.Context) IWebObjectContext(org.sablo.IWebObjectContext) IBrowserConverterContext(org.sablo.specification.property.IBrowserConverterContext) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) WebBaseFunction(com.servoy.j2db.server.ngclient.scripting.WebBaseFunction) Scriptable(org.mozilla.javascript.Scriptable)

Aggregations

IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)63 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)26 Point (java.awt.Point)12 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)11 FormController (com.servoy.j2db.FormController)9 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)7 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)7 RepositoryException (com.servoy.j2db.persistence.RepositoryException)7 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)7 ServoyException (com.servoy.j2db.util.ServoyException)7 JSONObject (org.json.JSONObject)7 IComponent (com.servoy.j2db.ui.IComponent)6 ArrayList (java.util.ArrayList)6 FindState (com.servoy.j2db.dataprocessing.FindState)5 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)5 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)5 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)5 JComponent (javax.swing.JComponent)5 Component (org.apache.wicket.Component)5 ApplicationException (com.servoy.j2db.ApplicationException)4