Search in sources :

Example 1 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class JSI18N method getSystemMessages.

/**
 * Returns a dataset with rows that contains 3 columns: 'key' (i18n key), 'reference' (reference text for that key) and 'locale ([CURRENT_LOCALE])' (where [CURRENT_LOCALE] is the current language) - with the system messages of servoy.
 * This means all servoy messages, with all available translations.
 *
 * @sample
 * var set = i18n.getSystemMessages();
 * for(var i=1;i<=set.getMaxRowIndex();i++)
 * {
 * 	application.output(set.getValue(i, 1) + " " + set.getValue(i, 2)+ " " + set.getValue(i, 3));
 * }
 *
 * @return a JSDataSet with all the system messages.
 */
@JSFunction
public JSDataSet getSystemMessages() {
    Locale locale = application.getLocale();
    TreeMap<Object, Object> defaultJarMessages = new TreeMap<Object, Object>();
    try {
        Properties properties = new Properties();
        // $NON-NLS-1$
        properties.load(Messages.class.getClassLoader().getResourceAsStream("com/servoy/j2db/messages.properties"));
        defaultJarMessages.putAll(properties);
    } catch (Exception e) {
    // Debug.error(e);
    }
    Properties currentLocaleJarMessages = new Properties();
    try {
        currentLocaleJarMessages.load(// $NON-NLS-1$ //$NON-NLS-2$
        Messages.class.getClassLoader().getResourceAsStream("com/servoy/j2db/messages_" + locale.getLanguage() + ".properties"));
    } catch (Exception e) {
    // Debug.error(e);
    }
    try {
        // $NON-NLS-1$ //$NON-NLS-2$
        currentLocaleJarMessages.load(Messages.class.getClassLoader().getResourceAsStream("com/servoy/j2db/messages_" + locale + ".properties"));
    } catch (Exception e) {
    // Debug.error(e);
    }
    Object[][] rowData = new Object[defaultJarMessages.size()][3];
    int k = 0;
    Iterator<Entry<Object, Object>> it = defaultJarMessages.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<Object, Object> entry = it.next();
        Object key = entry.getKey();
        rowData[k][0] = key;
        rowData[k][1] = entry.getValue();
        rowData[k][2] = currentLocaleJarMessages.get(key);
        k++;
    }
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
    String[] cols = new String[] { "key", "reference", "locale (" + locale.getDisplayLanguage(locale) + ")" };
    BufferedDataSet set = new BufferedDataSet(cols, Arrays.asList(rowData));
    return new JSDataSet(application, set);
}
Also used : Locale(java.util.Locale) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) TreeMap(java.util.TreeMap) Properties(java.util.Properties) Entry(java.util.Map.Entry) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) Map(java.util.Map) TreeMap(java.util.TreeMap) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 2 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class JSI18N method getLanguages.

/**
 * Returns a dataset with rows that contains a language key (en) and the displayname (English) column.
 *
 * See http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt for a list that could be returned.
 *
 * @sample
 * var set = i18n.getLanguages();
 * for(var i=1;i<=set.getMaxRowIndex();i++)
 * {
 * 	application.output(set.getValue(i, 1) + " " + set.getValue(i, 2));
 * }
 *
 * @return a JSDataSet with all the languages.
 *
 * @link http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
 */
@JSFunction
public JSDataSet getLanguages() {
    Locale[] locales = Locale.getAvailableLocales();
    TreeMap<String, String> languages = new TreeMap<String, String>(StringComparator.INSTANCE);
    for (Locale element : locales) {
        String name = element.getDisplayLanguage(element);
        languages.put(element.getLanguage(), name);
    }
    ArrayList<Object[]> list = new ArrayList<Object[]>();
    Iterator<Entry<String, String>> it = languages.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<String, String> entry = it.next();
        list.add(new Object[] { entry.getKey(), entry.getValue() });
    }
    // $NON-NLS-1$ //$NON-NLS-2$
    BufferedDataSet set = new BufferedDataSet(new String[] { "language_key", "language_name" }, list);
    return new JSDataSet(application, set);
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) Map(java.util.Map) TreeMap(java.util.TreeMap) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 3 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class WebFormUI method getFormContext.

@Override
public JSDataSet getFormContext() {
    IDataSet set = new // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
    BufferedDataSet(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$//$NON-NLS-5$//$NON-NLS-6$
    new String[] { "windowname", "formname", "containername", "tabname", "tabindex", "tabindex1based" }, new ArrayList<Object[]>());
    set.addRow(new Object[] { null, formController.getName(), null, null, null, null });
    Object currentContainer = parentContainerOrWindowName;
    WebFormUI currentForm = this;
    while (currentContainer instanceof WebFormComponent) {
        WebFormComponent currentComponent = (WebFormComponent) currentContainer;
        int index = currentComponent.getFormIndex(currentForm);
        currentForm = currentComponent.findParent(WebFormUI.class);
        if (currentForm != null) {
            set.addRow(0, new Object[] { null, currentForm.formController.getName(), currentComponent.getName(), null, new Integer(index), new Integer(index + 1) });
            currentContainer = currentForm.getParentContainer();
        } else {
            currentContainer = null;
        }
    }
    if (currentContainer instanceof String) {
        // fill in window name
        for (int i = 0; i < set.getRowCount(); i++) {
            set.getRow(i)[0] = currentContainer;
        }
    }
    return new JSDataSet(formController.getApplication(), set);
}
Also used : BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) JSONObject(org.json.JSONObject) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) Point(java.awt.Point)

Example 4 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class TestNGClient method createDataServer.

@Override
protected IDataServer createDataServer() {
    return new IDataServer() {

        private final HashMap<String, IDataSet> dataSetMap = new HashMap<String, IDataSet>();

        @Override
        public void setServerMaintenanceMode(boolean maintenanceMode) throws RemoteException {
        }

        @Override
        public void logMessage(String msg) throws RemoteException {
        }

        @Override
        public boolean isInServerMaintenanceMode() throws RemoteException {
            return false;
        }

        @Override
        public boolean releaseLocks(String client_id, String server_name, String table_name, Set<Object> pkhashkeys) throws RemoteException, RepositoryException {
            return false;
        }

        @Override
        public IDataSet acquireLocks(String client_id, String server_name, String table_name, Set<Object> pkhashkeys, QuerySelect lockSelect, String transaction_id, ArrayList<TableFilter> filters, int chunkSize) throws RemoteException, RepositoryException {
            return null;
        }

        @Override
        public String startTransaction(String clientId, String server_name) throws RepositoryException, RemoteException {
            return null;
        }

        @Override
        public Object[] performUpdates(String clientId, ISQLStatement[] statements) throws ServoyException, RemoteException {
            return statements;
        }

        @Override
        public IDataSet[] performQuery(String client_id, String server_name, String transaction_id, QueryData[] array) throws ServoyException, RemoteException {
            if (array.length > 0) {
                String ds = array[0].getSqlSelect().getTable().getDataSource();
                if ("mem:relatedtest".equals(ds)) {
                    IDataSet set = dataSetMap.get(ds);
                    IDataSet[] returnDataSet = new IDataSet[array.length];
                    for (int i = 0; i < array.length; i++) {
                        returnDataSet[i] = new BufferedDataSet();
                        for (int k = 0; k < set.getRowCount(); k++) {
                            Object[][] value = (Object[][]) ((Placeholder) ((SetCondition) ((QuerySelect) array[i].getSqlSelect()).getConditions().values().iterator().next().getConditions().get(0)).getValues()).getValue();
                            if (set.getRow(k)[1].equals(value[0][0])) {
                                returnDataSet[i].addRow(new Object[] { set.getRow(k)[0], set.getRow(k)[1], set.getRow(k)[2], set.getRow(k)[3] });
                            }
                        }
                    }
                    return returnDataSet;
                }
            }
            return null;
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve, boolean updateIdleTimestamp) throws ServoyException, RemoteException {
            // don't know the
            return dataSetMap.values().iterator().next();
        // datasource,
        // just return
        // the first
        // dataset
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, boolean updateIdleTimestamp) throws ServoyException, RemoteException {
            return dataSetMap.get(sqlSelect.getTable().getDataSource());
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve, int type) throws ServoyException, RemoteException {
            // don't know the
            return dataSetMap.values().iterator().next();
        // datasource,
        // just return
        // the first
        // dataset
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type, ITrackingSQLStatement trackingInfo) throws ServoyException, RemoteException {
            return dataSetMap.get(sqlSelect.getTable().getDataSource());
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type) throws ServoyException, RemoteException {
            IDataSet set = dataSetMap.get(sqlSelect.getTable().getDataSource());
            if (sqlSelect instanceof QuerySelect && ((QuerySelect) sqlSelect).getColumns().size() == 1) {
                // pk select
                int lastRow = Math.min(set.getRowCount(), startRow + rowsToRetrieve);
                BufferedDataSet ds = BufferedDataSetInternal.createBufferedDataSet(null, null, new SafeArrayList<Object[]>(0), lastRow < set.getRowCount());
                for (int i = startRow; i < lastRow; i++) {
                    ds.addRow(new Object[] { set.getRow(i)[0] });
                }
                return ds;
            }
            return set;
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String driverTableName, String transaction_id, String sql, Object[] questiondata, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
            // don't know the
            return dataSetMap.values().iterator().next();
        // datasource,
        // just return
        // the first
        // dataset
        }

        @Override
        public IDataSet performQuery(String client_id, String server_name, String transaction_id, ISQLSelect sqlSelect, ColumnType[] resultTypes, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
            return dataSetMap.get(sqlSelect.getTable().getDataSource());
        }

        @Override
        public IDataSet performCustomQuery(String client_id, String server_name, String driverTableName, String transaction_id, ISQLSelect sqlSelect, ArrayList<TableFilter> filters, int startRow, int rowsToRetrieve) throws ServoyException, RemoteException {
            return dataSetMap.get(sqlSelect.getTable().getDataSource());
        }

        @Override
        public boolean notifyDataChange(String client_id, String server_name, String tableName, IDataSet pks, int action, String transaction_id) throws RemoteException {
            return false;
        }

        @Override
        public ITable insertQueryResult(String client_id, String queryServerName, String queryTid, ISQLSelect sqlSelect, ArrayList<TableFilter> filters, boolean distinctInMemory, int startRow, int rowsToRetrieve, int type, String dataSource, String targetServerName, String targetTableName, String targetTid, ColumnType[] columnTypes, String[] pkNames) throws ServoyException, RemoteException {
            return null;
        }

        @Override
        public InsertResult insertDataSet(String client_id, IDataSet set, final String dataSource, String serverName, String tableName, String tid, ColumnType[] columnTypes, String[] pkNames, HashMap<String, ColumnInfoDef> columnInfoDefinitions) throws ServoyException, RemoteException {
            dataSetMap.put(dataSource, set);
            Table table = new Table(serverName, serverName, true, ITable.TABLE, null, null);
            table.setDataSource(dataSource);
            for (int i = 0; i < set.getColumnCount(); i++) {
                Column col = new Column(table, set.getColumnNames()[i], set.getColumnTypes()[i], 50, 50, true);
                table.addColumn(col);
                if (Arrays.binarySearch(pkNames, col.getName()) >= 0) {
                    col.setDatabasePK(true);
                }
            }
            return new InsertResult(table, new Object[0]);
        }

        @Override
        public QuerySet getSQLQuerySet(String serverName, ISQLQuery sqlQuery, ArrayList<TableFilter> filters, int startRow, int rowsToRetrieve, boolean forceQualifyColumns, boolean disableUseArrayForIn) throws RepositoryException, RemoteException {
            QuerySet qs = new QuerySet();
            qs.setSelect(new QueryString("select from test", false));
            return qs;
        }

        @Override
        public Object getNextSequence(String serverName, String tableName, String columnName, int columnInfoID, String columnInfoServer) throws RepositoryException, RemoteException {
            return null;
        }

        @Override
        public Blob getBlob(String clientId, String serverName, ISQLSelect blobSelect, ArrayList<TableFilter> filters, String tid) throws RepositoryException, RemoteException {
            return null;
        }

        @Override
        public boolean endTransactions(String client_id, String[] transaction_id, boolean commit) throws RepositoryException, RemoteException {
            return false;
        }

        @Override
        public void dropTemporaryTable(String client_id, String serverName, String tableName) throws RemoteException, RepositoryException {
        }

        @Override
        public ISQLStatement createSQLStatement(int action, String server_name, String tableName, Object[] pkColumnData, String tid, ISQLUpdate sqlUpdate, ArrayList<TableFilter> filters) throws RemoteException {
            return null;
        }

        @Override
        public ISQLStatement createSQLStatement(int action, String server_name, String tableName, Object[] pkColumnData, String tid, String sql, Object[] questiondata) throws RemoteException, RepositoryException {
            return null;
        }

        @Override
        public void addClientAsTableUser(String client_id, String serverName, String tableName) throws RemoteException, RepositoryException {
        }

        @Override
        public IDataSet[] executeProcedure(String clientId, String server_name, String tid, Procedure procedure, Object[] arguments) throws RepositoryException, RemoteException {
            return null;
        }
    };
}
Also used : Set(java.util.Set) QuerySet(com.servoy.j2db.persistence.QuerySet) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SafeArrayList(com.servoy.j2db.util.SafeArrayList) QuerySet(com.servoy.j2db.persistence.QuerySet) QueryString(com.servoy.j2db.persistence.QueryString) SetCondition(com.servoy.j2db.query.SetCondition) BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) Column(com.servoy.j2db.persistence.Column) Procedure(com.servoy.j2db.persistence.Procedure) ITable(com.servoy.j2db.persistence.ITable) Table(com.servoy.j2db.persistence.Table) IDataServer(com.servoy.j2db.dataprocessing.IDataServer) QueryString(com.servoy.j2db.persistence.QueryString) QuerySelect(com.servoy.j2db.query.QuerySelect) ISQLUpdate(com.servoy.j2db.query.ISQLUpdate) ITrackingSQLStatement(com.servoy.j2db.dataprocessing.ITrackingSQLStatement) ISQLQuery(com.servoy.j2db.query.ISQLQuery) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) ISQLSelect(com.servoy.j2db.query.ISQLSelect)

Example 5 with BufferedDataSet

use of com.servoy.j2db.dataprocessing.BufferedDataSet in project servoy-client by Servoy.

the class JSSecurity method js_getElementUUIDs.

/**
 * Returns the form elements UUID's as dataset, the one with no name is the form itself.
 *
 * @sample var formElementsUUIDDataSet = security.getElementUUIDs('orders_form');
 *
 * @param formname the formname to retieve the dataset for
 * @return dataset with element info
 */
public // return dataset with name, uuid (note: null name is form uuid)
JSDataSet js_getElementUUIDs(// return dataset with name, uuid (note: null name is form uuid)
String formname) {
    Form f = application.getFlattenedSolution().getForm(formname);
    if (f == null)
        f = application.getFormManager().getPossibleForm(formname);
    if (f != null) {
        List elements = new ArrayList();
        elements.add(new Object[] { null, f.getUUID() });
        Iterator<? extends IPersist> it = f.isResponsiveLayout() ? f.getFlattenedObjects(NameComparator.INSTANCE).iterator() : f.getAllObjects();
        while (it.hasNext()) {
            IPersist elem = it.next();
            int type = elem.getTypeID();
            if (type == IRepository.GRAPHICALCOMPONENTS || type == IRepository.FIELDS || type == IRepository.PORTALS || type == IRepository.RECTSHAPES || type == IRepository.SHAPES || type == IRepository.BEANS || type == IRepository.TABPANELS || type == IRepository.WEBCOMPONENTS) {
                if (elem instanceof ISupportName && ((ISupportName) elem).getName() != null) {
                    elements.add(new Object[] { ((ISupportName) elem).getName(), elem.getUUID() });
                }
            }
        }
        IDataSet set = new BufferedDataSet(new String[] { "name", "uuid" }, elements);
        return new JSDataSet(application, set);
    }
    return new JSDataSet(application);
}
Also used : BufferedDataSet(com.servoy.j2db.dataprocessing.BufferedDataSet) Form(com.servoy.j2db.persistence.Form) IPersist(com.servoy.j2db.persistence.IPersist) ISupportName(com.servoy.j2db.persistence.ISupportName) ArrayList(java.util.ArrayList) JSDataSet(com.servoy.j2db.dataprocessing.JSDataSet) ArrayList(java.util.ArrayList) List(java.util.List) IDataSet(com.servoy.j2db.dataprocessing.IDataSet)

Aggregations

BufferedDataSet (com.servoy.j2db.dataprocessing.BufferedDataSet)11 JSDataSet (com.servoy.j2db.dataprocessing.JSDataSet)7 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)5 ArrayList (java.util.ArrayList)5 Point (java.awt.Point)3 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)2 Column (com.servoy.j2db.persistence.Column)2 IServer (com.servoy.j2db.persistence.IServer)2 Table (com.servoy.j2db.persistence.Table)2 IComponent (com.servoy.j2db.ui.IComponent)2 SafeArrayList (com.servoy.j2db.util.SafeArrayList)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 TreeMap (java.util.TreeMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 WebMarkupContainer (org.apache.wicket.markup.html.WebMarkupContainer)2 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)2 ScriptableObject (org.mozilla.javascript.ScriptableObject)2