Search in sources :

Example 11 with FoundSetManager

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

the class TableView method setSortStatus.

public boolean setSortStatus(IFoundSetInternal foundset) {
    if (foundset != null) {
        List<SortColumn> sortCols = foundset.getSortColumns();
        if (sortCols != null && sortCols.size() > 0) {
            boolean found = false;
            for (SortColumn sc : sortCols) {
                for (int i = 0; (i < getColumnModel().getColumnCount()); i++) {
                    TableColumn tc = getColumnModel().getColumn(i);
                    if (tc instanceof CellAdapter) {
                        CellAdapter ca = (CellAdapter) tc;
                        if (ca.getDataProviderID() != null) {
                            List<String> sortingProviders = null;
                            Component renderer = ca.getRenderer();
                            if (renderer instanceof ISupportValueList && ((ISupportValueList) renderer).getValueList() != null) {
                                try {
                                    sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) renderer).getValueList().getValueList(), (Table) foundset.getTable(), ca.getDataProviderID(), application.getFoundSetManager());
                                } catch (RepositoryException ex) {
                                    Debug.error(ex);
                                }
                            }
                            if (sortingProviders == null) {
                                // no related sort, use sort on dataProviderID instead
                                sortingProviders = Collections.singletonList(ca.getDataProviderID());
                            }
                            for (String sortingProvider : sortingProviders) {
                                SortColumn existingSc;
                                try {
                                    FoundSetManager fsm = (FoundSetManager) foundset.getFoundSetManager();
                                    existingSc = fsm.getSortColumn(foundset.getTable(), sortingProvider, false);
                                } catch (Exception e) {
                                    Debug.error(e);
                                    continue;
                                }
                                if (sc.equalsIgnoreSortorder(existingSc)) {
                                    if (!found) {
                                        // clear old sort
                                        updateSortStatus(-1, true);
                                    }
                                    found = true;
                                    updateSortStatus(ca.getModelIndex(), sc.getSortOrder() == SortColumn.ASCENDING);
                                }
                            }
                        }
                    }
                }
            }
            return found;
        }
    }
    return false;
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) Table(com.servoy.j2db.persistence.Table) FixedJTable(com.servoy.j2db.gui.FixedJTable) ITable(com.servoy.j2db.persistence.ITable) JTable(javax.swing.JTable) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) RepositoryException(com.servoy.j2db.persistence.RepositoryException) CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Example 12 with FoundSetManager

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

the class ScrollResponseHeaderContainer method tableChanged.

/**
 * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
 */
public void tableChanged(TableModelEvent e) {
    // as changed, as it will be faster on the client the component replace
    if ((e.getType() == TableModelEvent.UPDATE) && (e.getFirstRow() == e.getLastRow()) && (nrUpdatedListItems < 20)) {
        Component component = table.get(Integer.toString(e.getFirstRow()));
        if (component instanceof ListItem) {
            ((ListItem) component).visitChildren(IProviderStylePropertyChanges.class, new IVisitor<Component>() {

                public Object component(Component comp) {
                    if ((comp instanceof IDisplayData) || !(comp instanceof ILabel)) {
                        if (comp instanceof ISupportsNeedEntireState && ((ISupportsNeedEntireState) comp).needEntireState()) {
                            // it if has tags - mark as changed; it could be enhanced further by also know what was last-rendered on tags, not just simple dataproviders
                            ((IProviderStylePropertyChanges) comp).getStylePropertyChanges().setChanged();
                        } else {
                            // try to mark cells as changed only if there was a real value change; otherwise there is no use to replace the whole row...
                            checkForValueChanges(comp);
                        }
                    }
                    // else labels/buttons that don't display data are not changed
                    return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            });
            nrUpdatedListItems++;
            IModel<IRecordInternal> newModel = table.getListItemModel(table.getModel(), e.getFirstRow());
            IModel oldModel = ((ListItem) component).getModel();
            if (newModel != null && oldModel != null && newModel.getObject() != null && !newModel.getObject().equals(oldModel.getObject())) {
                // refresh model if it changed
                ((ListItem) component).setModel(newModel);
            }
        }
    } else {
        if (!isRendering && (!isScrollMode() || !(scrollBehavior != null && scrollBehavior.isGettingRows()))) {
            if (isScrollMode())
                resetScrollParams();
            getStylePropertyChanges().setValueChanged();
        }
    }
    // This is just an heuristic for filtering out the sort event from all table changed events that are raised.
    if (currentData != null && e.getColumn() == TableModelEvent.ALL_COLUMNS && e.getFirstRow() == 0 && elementToColumnHeader.size() > 0) {
        List<SortColumn> sortCols = currentData.getSortColumns();
        if (sortCols != null && sortCols.size() > 0) {
            Map<String, Boolean> sortMap = new HashMap<String, Boolean>();
            for (IPersist persist : elementToColumnHeader.keySet()) {
                SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
                sortableCellViewHeader.setResizeImage(R_ARROW_OFF);
            }
            for (SortColumn sc : sortCols) {
                for (IPersist persist : elementToColumnHeader.keySet()) {
                    Component comp = elementToColumnIdentifierComponent.get(persist);
                    SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
                    if (comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null) {
                        IDisplayData dispComp = (IDisplayData) comp;
                        List<String> sortingProviders = null;
                        if (dispComp instanceof ISupportValueList && ((ISupportValueList) dispComp).getValueList() != null) {
                            try {
                                sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) dispComp).getValueList().getValueList(), (Table) currentData.getTable(), dispComp.getDataProviderID(), currentData.getFoundSetManager());
                            } catch (RepositoryException ex) {
                                Debug.error(ex);
                            }
                        }
                        if (sortingProviders == null) {
                            // no related sort, use sort on dataProviderID instead
                            sortingProviders = Collections.singletonList(dispComp.getDataProviderID());
                        }
                        for (String sortingProvider : sortingProviders) {
                            SortColumn existingSc;
                            try {
                                FoundSetManager fsm = (FoundSetManager) currentData.getFoundSetManager();
                                existingSc = fsm.getSortColumn(currentData.getTable(), sortingProvider, false);
                            } catch (RepositoryException ex) {
                                Debug.error(ex);
                                continue;
                            }
                            if (sc.equalsIgnoreSortorder(existingSc)) {
                                boolean descending = sc.getSortOrder() == SortColumn.DESCENDING;
                                sortableCellViewHeader.setResizeImage(descending ? R_ARROW_UP : R_ARROW_DOWN);
                                sortMap.put(sortableCellViewHeader.getId(), Boolean.valueOf(!descending));
                            }
                        }
                    }
                }
            }
            headers.recordSort(sortMap);
        }
    }
    MainPage mp = table.findParent(MainPage.class);
    if (mp != null)
        mp.triggerBrowserRequestIfNeeded();
}
Also used : ISupportsNeedEntireState(com.servoy.j2db.dataprocessing.ISupportsNeedEntireState) ILabel(com.servoy.j2db.ui.ILabel) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) IComponent(com.servoy.j2db.ui.IComponent) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) MainPage(com.servoy.j2db.server.headlessclient.MainPage) IModel(org.apache.wicket.model.IModel) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) Table(com.servoy.j2db.persistence.Table) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPersist(com.servoy.j2db.persistence.IPersist) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 13 with FoundSetManager

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

the class ClientState method loadSecuritySettings.

public void loadSecuritySettings(FlattenedSolution root) throws ServoyException, RemoteException {
    if (clientInfo.getUserUid() != null) {
        Solution sol = root.getSolution();
        String[] groups = clientInfo.getUserGroups();
        if (// fall back on retrieval of groups based on user_uid
        groups == null) {
            groups = getUserManager().getUserGroups(clientInfo.getClientId(), clientInfo.getUserUid());
        }
        root.clearSecurityAccess();
        int[] sids = new int[] { sol.getSolutionID() };
        int[] srns = new int[] { sol.getReleaseNumber() };
        Solution[] modules = root.getModules();
        if (modules != null) {
            sids = new int[modules.length + 1];
            sids[0] = sol.getSolutionID();
            srns = new int[modules.length + 1];
            srns[0] = sol.getReleaseNumber();
            for (int i = 0; i < modules.length; i++) {
                Solution module = modules[i];
                sids[i + 1] = module.getSolutionID();
                srns[i + 1] = module.getReleaseNumber();
            }
        }
        Pair<Map<Object, Integer>, Set<Object>> securityAccess = getUserManager().getSecurityAccess(clientInfo.getClientId(), sids, srns, groups);
        root.addSecurityAccess(securityAccess);
        if (foundSetManager != null) {
            ((FoundSetManager) foundSetManager).flushSecuritySettings();
        }
    }
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) Set(java.util.Set) Map(java.util.Map) HashMap(java.util.HashMap) Solution(com.servoy.j2db.persistence.Solution)

Example 14 with FoundSetManager

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

the class ClientStub method notifyDataChange.

public void notifyDataChange(final String server_name, final String table_name, final IDataSet pks, final int sql_action, final Object[] insertColumnData) {
    if (client.isShutDown())
        return;
    if (Debug.tracing()) {
        Debug.trace(// $NON-NLS-1$//$NON-NLS-2$
        "Notify Data Change get from the server for dataserver: " + server_name + " table: " + table_name + ". Pks: " + (pks != null ? "not null" : "null") + ". Action type: " + sql_action);
    }
    synchronized (datachanges) {
        datachanges.push(new Object[] { server_name, table_name, pks, new Integer(sql_action), insertColumnData });
        if (datachangesHandler == null) {
            datachangesHandler = new Runnable() {

                public void run() {
                    while (datachangesHandler != null) {
                        final Object[] array;
                        synchronized (datachanges) {
                            if (datachanges.isEmpty()) {
                                // done
                                datachangesHandler = null;
                                break;
                            }
                            array = datachanges.pop();
                        }
                        client.invokeLater(new Runnable() {

                            public void run() {
                                if (client.isShutDown() || !client.isSolutionLoaded())
                                    return;
                                String sname = (String) array[0];
                                String tname = (String) array[1];
                                IDataSet pksDataSet = (IDataSet) array[2];
                                int action = ((Integer) array[3]).intValue();
                                Object[] insertColumndata = (Object[]) array[4];
                                IDataServer ds = client.getDataServer();
                                if (ds instanceof DataServerProxy) {
                                    // possibly switched from multiple servers to the same destination server.
                                    for (String srv : ((DataServerProxy) ds).getReverseMappedServerNames(sname)) {
                                        ((FoundSetManager) client.getFoundSetManager()).notifyDataChange(DataSourceUtils.createDBTableDataSource(srv, tname), pksDataSet, action, insertColumndata);
                                    }
                                    return;
                                }
                                // not switched
                                ((FoundSetManager) client.getFoundSetManager()).notifyDataChange(DataSourceUtils.createDBTableDataSource(sname, tname), pksDataSet, action, insertColumndata);
                            }
                        });
                    }
                }
            };
            client.getScheduledExecutor().execute(datachangesHandler);
        }
    }
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) IDataServer(com.servoy.j2db.dataprocessing.IDataServer) IDataSet(com.servoy.j2db.dataprocessing.IDataSet) DataServerProxy(com.servoy.j2db.dataprocessing.DataServerProxy)

Example 15 with FoundSetManager

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

the class SortableCellViewHeaderGroup method sort.

protected final void sort(final String name, final WebCellBasedView view, int modifiers) {
    direction = Utils.getAsBoolean(sorted.get(name));
    direction = !direction;
    FormController fc = null;
    try {
        Iterator<IPersist> it = cellview.getAllObjects();
        while (it.hasNext()) {
            IPersist element = it.next();
            if (element instanceof ISupportName && element instanceof ISupportDataProviderID) {
                if (name.equals(ComponentFactory.getWebID(form, element))) {
                    IFoundSetInternal fs = ((FoundSetListWrapper) listView.getList()).getFoundSet();
                    if (fs != null) {
                        WebForm wf = listView.findParent(WebForm.class);
                        if (wf != null)
                            fc = wf.getController();
                        GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
                        int labelForOnActionMethodId = 0;
                        if (gc != null) {
                            labelForOnActionMethodId = gc.getOnActionMethodID();
                        }
                        if (fc != null && labelForOnActionMethodId > 0) {
                            // execute on action
                            JSEvent event = new JSEvent();
                            event.setType(JSEvent.EventType.action);
                            event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
                            event.setFormName(view.getDataAdapterList().getFormController().getName());
                            event.setModifiers(modifiers);
                            event.setElementName(gc.getName());
                            fc.executeFunction(String.valueOf(labelForOnActionMethodId), // $NON-NLS-1$
                            Utils.arrayMerge((new Object[] { event }), Utils.parseJSExpressions(gc.getFlattenedMethodArguments("onActionMethodID"))), true, null, false, // $NON-NLS-1$
                            "onActionMethodID");
                        }
                        String id = ((ISupportDataProviderID) element).getDataProviderID();
                        if (id != null) {
                            if (cellview instanceof Portal && !ScopesUtils.isVariableScope(id)) {
                                int idx = id.lastIndexOf('.');
                                if (idx > 0) {
                                    id = id.substring(idx + 1);
                                }
                            }
                            IDataProvider dataProvider = null;
                            if (fc != null) {
                                dataProvider = fs.getFoundSetManager().getApplication().getFlattenedSolution().getDataproviderLookup(fs.getFoundSetManager(), fc.getForm()).getDataProvider(id);
                            }
                            if (!(fc != null && labelForOnActionMethodId > 0)) {
                                // in case there is no onAction definned
                                if (cellview instanceof Portal || fc == null || fc.getForm().getOnSortCmdMethodID() == 0) {
                                    List<String> sortingProviders = null;
                                    try {
                                        sortingProviders = DBValueList.getShowDataproviders(fs.getFoundSetManager().getApplication().getFlattenedSolution().getValueList(((ISupportDataProviderID) element).getValuelistID()), (Table) fs.getTable(), dataProvider == null ? id : dataProvider.getDataProviderID(), fs.getFoundSetManager());
                                    } catch (RepositoryException ex) {
                                        Debug.error(ex);
                                    }
                                    if (sortingProviders == null) {
                                        // no related sort, use sort on dataProviderID instead
                                        sortingProviders = Collections.singletonList(dataProvider == null ? id : dataProvider.getDataProviderID());
                                    }
                                    List<SortColumn> list = (modifiers & Event.SHIFT_MASK) != 0 ? fs.getSortColumns() : new ArrayList<SortColumn>();
                                    for (String sortingProvider : sortingProviders) {
                                        FoundSetManager fsm = (FoundSetManager) fs.getFoundSetManager();
                                        SortColumn sc = fsm.getSortColumn(fs.getTable(), sortingProvider, false);
                                        if (sc != null && sc.getColumn().getDataProviderType() != IColumnTypes.MEDIA) {
                                            for (SortColumn oldColumn : list) {
                                                if (oldColumn.equalsIgnoreSortorder(sc)) {
                                                    sc = oldColumn;
                                                    break;
                                                }
                                            }
                                            if (!list.contains(sc))
                                                list.add(sc);
                                            sc.setSortOrder(direction ? SortColumn.ASCENDING : SortColumn.DESCENDING);
                                        }
                                        fs.sort(list, false);
                                    }
                                } else if (fc != null && fc.getForm().getOnSortCmdMethodID() != -1) {
                                    JSEvent event = new JSEvent();
                                    event.setType(JSEvent.EventType.none);
                                    event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
                                    event.setFormName(view.getDataAdapterList().getFormController().getName());
                                    event.setModifiers(modifiers);
                                    fc.executeFunction(String.valueOf(fc.getForm().getOnSortCmdMethodID()), Utils.arrayMerge((new Object[] { dataProvider == null ? id : dataProvider.getDataProviderID(), Boolean.valueOf(direction), event }), // $NON-NLS-1$
                                    Utils.parseJSExpressions(fc.getForm().getFlattenedMethodArguments("onSortCmdMethodID"))), true, null, false, // $NON-NLS-1$
                                    "onSortCmdMethodID");
                                }
                            }
                            if ((modifiers & Event.SHIFT_MASK) == 0) {
                                sorted.clear();
                            }
                            sorted.put(name, new Boolean(direction));
                            listView.setCurrentPage(0);
                        }
                    }
                    break;
                }
            }
        }
        listView.modelChanged();
    } catch (Exception e) {
        if (fc != null) {
            if (e instanceof ServoyException) {
                ((ServoyException) e).setContext(fc.toString());
            } else {
                ServoyException se = new ServoyException();
                se.initCause(e);
                se.setContext(fc.toString());
                e = se;
            }
        }
        Debug.error("error sorting foundset: " + sorted, e);
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ISupportName(com.servoy.j2db.persistence.ISupportName) FoundSetListWrapper(com.servoy.j2db.dataprocessing.FoundSetListWrapper) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IDataProvider(com.servoy.j2db.persistence.IDataProvider) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) ServoyException(com.servoy.j2db.util.ServoyException) Portal(com.servoy.j2db.persistence.Portal) FormController(com.servoy.j2db.FormController) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) JSEvent(com.servoy.j2db.scripting.JSEvent) Table(com.servoy.j2db.persistence.Table) ISupportDataProviderID(com.servoy.j2db.persistence.ISupportDataProviderID) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPersist(com.servoy.j2db.persistence.IPersist)

Aggregations

FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)17 RepositoryException (com.servoy.j2db.persistence.RepositoryException)9 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)5 Table (com.servoy.j2db.persistence.Table)4 ServoyException (com.servoy.j2db.util.ServoyException)4 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)3 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)3 IPersist (com.servoy.j2db.persistence.IPersist)3 ISupportValueList (com.servoy.j2db.ui.ISupportValueList)3 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)2 IDataServer (com.servoy.j2db.dataprocessing.IDataServer)2 IDataSet (com.servoy.j2db.dataprocessing.IDataSet)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)2 SwingFoundSetFactory (com.servoy.j2db.dataprocessing.SwingFoundSetFactory)2 Form (com.servoy.j2db.persistence.Form)2 Relation (com.servoy.j2db.persistence.Relation)2 ScriptNameValidator (com.servoy.j2db.persistence.ScriptNameValidator)2 Solution (com.servoy.j2db.persistence.Solution)2