Search in sources :

Example 1 with IProviderStylePropertyChanges

use of com.servoy.j2db.ui.IProviderStylePropertyChanges in project servoy-client by Servoy.

the class WebCellAdapter method valueChanged.

public void valueChanged(ModificationEvent e) {
    MainPage mp = view.findParent(MainPage.class);
    if (mp != null)
        mp.touch();
    IRecord record = e.getRecord();
    Iterator iterator = ((MarkupContainer) view.getTable()).iterator();
    while (iterator.hasNext()) {
        Object next = iterator.next();
        if (next instanceof ListItem) {
            ListItem li = (ListItem) next;
            Object modelObject = li.getModelObject();
            if (record == null || modelObject == record) {
                boolean hasOnRender = false;
                Iterator iterator2 = li.iterator();
                while (iterator2.hasNext()) {
                    ArrayList<Object> cellDisplays = new ArrayList<Object>();
                    Object cell = iterator2.next();
                    cell = CellContainer.getContentsForCell((Component) cell);
                    if (cell instanceof WebCellBasedViewListViewItem) {
                        Iterator listItemIte = ((WebCellBasedViewListViewItem) cell).iterator();
                        while (listItemIte.hasNext()) {
                            Object listItemDisplay = listItemIte.next();
                            if (listItemDisplay instanceof WrapperContainer) {
                                listItemDisplay = ((WrapperContainer) listItemDisplay).getDelegate();
                            }
                            cellDisplays.add(listItemDisplay);
                        }
                    } else {
                        cellDisplays.add(cell);
                    }
                    for (Object cellDisplay : cellDisplays) {
                        if (cellDisplay instanceof IProviderStylePropertyChanges && cellDisplay instanceof IDisplayData && ((IDisplayData) cellDisplay).getDataProviderID() == dataprovider) {
                            // only test if it is not already changed
                            view.checkForValueChanges(cellDisplay);
                            // do fire on render on all components for record change
                            if (cellDisplay instanceof ISupportOnRender && cellDisplay instanceof IScriptableProvider) {
                                IScriptable so = ((IScriptableProvider) cellDisplay).getScriptObject();
                                if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
                                    String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
                                    if (record != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
                                        ((ISupportOnRender) cellDisplay).fireOnRender(true);
                                        hasOnRender = true;
                                    }
                                }
                            }
                        }
                    }
                }
                if (record != null || (!hasOnRender && !canChangeValue(e)))
                    break;
            }
        }
    }
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) ISupportOnRender(com.servoy.j2db.ui.ISupportOnRender) IRecord(com.servoy.j2db.dataprocessing.IRecord) ArrayList(java.util.ArrayList) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) WebCellBasedViewListViewItem(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.WebCellBasedViewListViewItem) IScriptable(com.servoy.j2db.scripting.IScriptable) WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) Iterator(java.util.Iterator) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) ListItem(org.apache.wicket.markup.html.list.ListItem) Component(org.apache.wicket.Component) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 2 with IProviderStylePropertyChanges

use of com.servoy.j2db.ui.IProviderStylePropertyChanges in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method setHeadersWidth.

// set headers width according to cell's width
private void setHeadersWidth() {
    Iterator<IPersist> columnPersistIte = elementToColumnIdentifierComponent.keySet().iterator();
    IPersist columnPersist;
    Component columnHeader, columnCell;
    while (columnPersistIte.hasNext()) {
        columnPersist = columnPersistIte.next();
        columnCell = elementToColumnIdentifierComponent.get(columnPersist);
        columnHeader = elementToColumnHeader.get(columnPersist);
        if (columnCell instanceof IProviderStylePropertyChanges) {
            // $NON-NLS-1$
            String width = ((IProviderStylePropertyChanges) columnCell).getStylePropertyChanges().getJSProperty("offsetWidth");
            if (columnHeader instanceof SortableCellViewHeader) {
                SortableCellViewHeader sortableColumnHeader = (SortableCellViewHeader) columnHeader;
                if (width != null)
                    sortableColumnHeader.setWidth(Integer.parseInt(width.substring(0, width.length() - 2)));
                else if (columnPersist instanceof BaseComponent)
                    sortableColumnHeader.setWidth(((BaseComponent) columnPersist).getSize().width);
            }
        }
    }
}
Also used : AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IPersist(com.servoy.j2db.persistence.IPersist) 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)

Example 3 with IProviderStylePropertyChanges

use of com.servoy.j2db.ui.IProviderStylePropertyChanges in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method resizeColumn.

public void resizeColumn(SortableCellViewHeader headerColumn, int x) {
    int totalWidthToStretch = 0;
    IPersist resizedPersist = null;
    for (IPersist p : elementToColumnHeader.keySet()) {
        Component c = elementToColumnIdentifierComponent.get(p);
        if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent) {
            IRuntimeComponent ic = (IRuntimeComponent) ((IScriptableProvider) c).getScriptObject();
            if (elementToColumnHeader.get(p).equals(headerColumn)) {
                int height = ic.getHeight();
                Iterator<Component> alreadyAddedComponents = cellToElement.keySet().iterator();
                if (alreadyAddedComponents.hasNext()) {
                    Component firstAddedComponent = alreadyAddedComponents.next();
                    if ((firstAddedComponent instanceof IComponent))
                        height = ((IComponent) firstAddedComponent).getSize().height;
                }
                ic.setSize(ic.getWidth() + x, height);
                if (ic instanceof IProviderStylePropertyChanges) {
                    resizedComponent = c;
                    // avoid the tableview to render because of this change
                    ((IProviderStylePropertyChanges) ic).getStylePropertyChanges().setRendered();
                }
                resizedPersist = p;
                // set width for all cell of the column
                Iterator<Entry<Component, IPersist>> cellToElementIte = cellToElement.entrySet().iterator();
                Entry<Component, IPersist> cellToElementEntry;
                Component cellComponent;
                while (cellToElementIte.hasNext()) {
                    cellToElementEntry = cellToElementIte.next();
                    cellComponent = cellToElementEntry.getKey();
                    if (p.equals(cellToElementEntry.getValue()) && cellComponent instanceof IScriptableProvider && ((IScriptableProvider) cellComponent).getScriptObject() instanceof IRuntimeComponent) {
                        IRuntimeComponent cellScriptComponent = (IRuntimeComponent) ((IScriptableProvider) cellComponent).getScriptObject();
                        cellScriptComponent.setSize(cellScriptComponent.getWidth() + x, cellScriptComponent.getHeight());
                        if (cellComponent instanceof IProviderStylePropertyChanges) {
                            // avoid the tableview to render because of this change
                            ((IProviderStylePropertyChanges) cellComponent).getStylePropertyChanges().setRendered();
                        }
                    }
                }
            } else {
                totalWidthToStretch += ic.getWidth();
            }
        }
    }
    if (shouldFillAllHorizontalSpace())
        distributeExtraSpace(-x, totalWidthToStretch, resizedPersist, false);
    setHeadersWidth();
}
Also used : Entry(java.util.Map.Entry) IPersist(com.servoy.j2db.persistence.IPersist) IComponent(com.servoy.j2db.ui.IComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) 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) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) Point(java.awt.Point)

Example 4 with IProviderStylePropertyChanges

use of com.servoy.j2db.ui.IProviderStylePropertyChanges in project servoy-client by Servoy.

the class TabIndexHelper method setUpTabIndexAttributeModifierInternal.

private static void setUpTabIndexAttributeModifierInternal(Component comp, int newTabIndex) {
    TabIndexAttributeModifier modifier = null;
    final Component component = comp;
    for (Object obeh : component.getBehaviors()) {
        IBehavior beh = (IBehavior) obeh;
        if (beh instanceof TabIndexAttributeModifier) {
            modifier = (TabIndexAttributeModifier) beh;
            break;
        }
    }
    boolean componentChanged = true;
    boolean changeForClientSide = false;
    if (modifier == null) {
        if (newTabIndex != ISupportWebTabSeq.DEFAULT && isTabIndexSupported(component))
            component.add(new TabIndexAttributeModifier(newTabIndex));
    } else if (newTabIndex != ISupportWebTabSeq.DEFAULT) {
        if (newTabIndex != modifier.getTabIndex()) {
            modifier.setTabIndex(newTabIndex);
            if (!(component instanceof IProviderStylePropertyChanges) || !((IProviderStylePropertyChanges) component).getStylePropertyChanges().isChanged()) {
                // if is already changed leave it to server side
                changeForClientSide = true;
            }
        } else {
            componentChanged = false;
        }
    } else {
        component.remove(modifier);
    }
    if (componentChanged) {
        MainPage page = component.findParent(MainPage.class);
        if (changeForClientSide) {
            if (page != null) {
                page.getPageContributor().addTabIndexChange(component.getMarkupId(), newTabIndex);
            } else {
                changeForClientSide = false;
            }
        }
        if (!changeForClientSide && component instanceof IProviderStylePropertyChanges) {
            IProviderStylePropertyChanges changeable = (IProviderStylePropertyChanges) component;
            changeable.getStylePropertyChanges().setChanged();
            if (page != null) {
                page.getPageContributor().addTabIndexChange(component.getMarkupId(), ISupportWebTabSeq.DEFAULT);
            }
        }
    }
}
Also used : IBehavior(org.apache.wicket.behavior.IBehavior) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) Component(org.apache.wicket.Component)

Example 5 with IProviderStylePropertyChanges

use of com.servoy.j2db.ui.IProviderStylePropertyChanges 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)

Aggregations

IProviderStylePropertyChanges (com.servoy.j2db.ui.IProviderStylePropertyChanges)11 Component (org.apache.wicket.Component)8 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)7 IComponent (com.servoy.j2db.ui.IComponent)6 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)5 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)5 BaseComponent (com.servoy.j2db.persistence.BaseComponent)4 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)4 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)4 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)4 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)3 IPersist (com.servoy.j2db.persistence.IPersist)3 MainPage (com.servoy.j2db.server.headlessclient.MainPage)3 MarkupContainer (org.apache.wicket.MarkupContainer)3 ListItem (org.apache.wicket.markup.html.list.ListItem)3 IScriptable (com.servoy.j2db.scripting.IScriptable)2 WrapperContainer (com.servoy.j2db.server.headlessclient.WrapperContainer)2 ILabel (com.servoy.j2db.ui.ILabel)2 IStylePropertyChanges (com.servoy.j2db.ui.IStylePropertyChanges)2 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)2