Search in sources :

Example 51 with IPersist

use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.

the class DataRendererFactory method createPortalRenderer.

public IDataRenderer createPortalRenderer(IApplication app, Portal objToRender, Form dataProviderLookup, IScriptExecuter listner, boolean printing, ControllerUndoManager undoManager) throws Exception {
    List<IPersist> allObjectsAsList = objToRender.getAllObjectsAsList();
    List<IFormElement> formElements = new ArrayList<IFormElement>(allObjectsAsList.size());
    for (IPersist persist : allObjectsAsList) {
        if (persist instanceof IFormElement) {
            formElements.add((IFormElement) persist);
        }
    }
    List<IFormElement> children = new SortedList<IFormElement>(new Comparator<IFormElement>() {

        public int compare(IFormElement o1, IFormElement o2) {
            // reverse order, right order for tab sequence
            int result = -PositionComparator.XY_PERSIST_COMPARATOR.compare(o1, o2);
            if (result == 0) {
                return (o1.getFormIndex() - o2.getFormIndex());
            }
            return result;
        }
    }, formElements);
    Iterator<IFormElement> e1 = children.iterator();
    Map emptyDataRenderers = new LinkedHashMap();
    DataRenderer dr = null;
    int height = objToRender.getRowHeight();
    boolean calculateHeight = (height == 0);
    // for safety
    if (height == 0)
        height = 100;
    // int leftBorder = 0;
    // int bottomBorder = 0;
    // if (objToRender.getShowHorizontalLines())
    // {
    // bottomBorder = 1;
    // }
    // if (objToRender.getShowVerticalLines())
    // {
    // leftBorder = 4;
    // }
    boolean showSelection = objToRender.getShowVerticalLines();
    dr = (DataRenderer) getEmptyDataRenderer(ComponentFactory.getWebID(dataProviderLookup, objToRender), "portal_" + objToRender.getName(), app, showSelection);
    setBasicSettings(dr, objToRender.getBackground(), new Dimension(objToRender.getSize().width, height), new Point(0, 0), printing);
    // first is dummy saying is portal
    emptyDataRenderers.put(new Boolean(true), dr);
    dr.setLocation(objToRender.getLocation());
    Border b = ComponentFactoryHelper.createBorder(objToRender.getBorderType());
    Insets ins = new Insets(0, 0, 0, 0);
    if (b != null) {
        ins = ComponentFactoryHelper.getBorderInsetsForNoComponent(b);
    }
    // if (b instanceof EmptyBorder)
    // {
    // ins = ((EmptyBorder)b).getBorderInsets();
    // }
    placeElements(e1, app, dataProviderLookup, listner, emptyDataRenderers, objToRender.getSize().width, -(objToRender.getLocation().x + ins.right), -ins.top, printing, true, undoManager, true, null);
    int biggest_width = 10;
    int biggest_height = calculateHeight ? 0 : height;
    Component[] comps = dr.getComponents();
    boolean hasRowBGColorCalc = objToRender.getRowBGColorCalculation() != null;
    for (Component element : comps) {
        int w = element.getLocation().x + element.getSize().width;
        if (w > biggest_width)
            biggest_width = w;
        if (hasRowBGColorCalc && element instanceof JComponent)
            ((JComponent) element).setOpaque(false);
        if (calculateHeight) {
            int h = element.getLocation().y + element.getSize().height;
            if (h > biggest_height)
                biggest_height = h;
        }
    }
    dr.setSize(new Dimension(biggest_width, biggest_height));
    dr.setPreferredSize(new Dimension(biggest_width, biggest_height));
    if (printing) {
        // sliding inside a multiline portal renderer is nor supported, be we have to attach the springs for resizes
        addSpringsBetweenComponents(app, dr);
    }
    return dr;
}
Also used : Insets(java.awt.Insets) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) ArrayList(java.util.ArrayList) SortedList(com.servoy.j2db.util.SortedList) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) Point(java.awt.Point) Point(java.awt.Point) LinkedHashMap(java.util.LinkedHashMap) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Border(javax.swing.border.Border)

Example 52 with IPersist

use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method putClientProperty.

/**
 * put client property for current and future components.
 */
public void putClientProperty(IPersist persist, Object key, Object value) {
    Map<Object, Object> clientProperties = elementToClientProperties.get(persist);
    if (clientProperties == null) {
        elementToClientProperties.put(persist, clientProperties = new HashMap<Object, Object>());
    }
    clientProperties.put(key, value);
    for (Entry<Component, IPersist> entry : cellToElement.entrySet()) {
        if (entry.getValue().equals(persist)) {
            Component component = entry.getKey();
            if (component instanceof IScriptableProvider) {
                IScriptable scriptObject = ((IScriptableProvider) component).getScriptObject();
                if (scriptObject instanceof HasRuntimeClientProperty) {
                    ((HasRuntimeClientProperty) scriptObject).putClientProperty(key, value);
                }
            }
        }
    }
}
Also used : HasRuntimeClientProperty(com.servoy.j2db.ui.runtime.HasRuntimeClientProperty) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) IPersist(com.servoy.j2db.persistence.IPersist) 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) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 53 with IPersist

use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method setTabSeqComponents.

public void setTabSeqComponents(List<Component> list) {
    if (list == null || list.size() == 0) {
        if (elementTabIndexes.size() > 0)
            getStylePropertyChanges().setChanged();
        elementTabIndexes.clear();
    } else {
        getStylePropertyChanges().setChanged();
        elementTabIndexes.clear();
        int columnTabIndex = 0;
        for (Component rowIdComponent : list) {
            for (Entry<IPersist, Component> entry : elementToColumnIdentifierComponent.entrySet()) {
                if (componentIdentifiesColumn(rowIdComponent, entry.getValue())) {
                    elementTabIndexes.put(entry.getKey(), Integer.valueOf(columnTabIndex));
                    columnTabIndex++;
                    break;
                }
            }
        }
    }
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) 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) Point(java.awt.Point)

Example 54 with IPersist

use of com.servoy.j2db.persistence.IPersist 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 55 with IPersist

use of com.servoy.j2db.persistence.IPersist in project servoy-client by Servoy.

the class ScrollResponseHeaderContainer method getCellToFocus.

/**
 * @param columnIdentifierComponent
 * @return
 */
private Component getCellToFocus(final Component columnIdentifierComponent) {
    Component cell = null;
    // this means that the given column of the cell view wants to be focused =>
    // we must focus the cell component that is part of the currently selected record
    int selectedIndex = currentData.getSelectedIndex();
    if (selectedIndex < 0 && currentData.getSize() > 0) {
        selectedIndex = 0;
    }
    if (selectedIndex >= 0) {
        // we found a record to use - now we must locate the cell component inside this record
        ListItem<IRecordInternal> li = (ListItem<IRecordInternal>) table.get(Integer.toString(selectedIndex));
        if (li != null) {
            Iterator<? extends Component> cells = li.iterator();
            while (cells.hasNext()) {
                Component someCell = cells.next();
                if (isListViewMode()) {
                    if (someCell instanceof WebCellBasedViewListItem) {
                        someCell = ((WebCellBasedViewListItem) someCell).getListContainer();
                    }
                    if (someCell instanceof MarkupContainer) {
                        for (int i = 0; i < ((MarkupContainer) someCell).size(); i++) {
                            Component currentComponent = ((MarkupContainer) someCell).get(i);
                            if (currentComponent instanceof WrapperContainer)
                                currentComponent = ((WrapperContainer) currentComponent).getDelegate();
                            IPersist element = cellToElement.get(currentComponent);
                            if (element != null && elementToColumnIdentifierComponent.get(element) == columnIdentifierComponent) {
                                return currentComponent;
                            }
                        }
                    }
                } else {
                    someCell = CellContainer.getContentsForCell(someCell);
                    IPersist element = cellToElement.get(someCell);
                    if (element != null && elementToColumnIdentifierComponent.get(element) == columnIdentifierComponent) {
                        cell = someCell;
                        break;
                    }
                }
            }
        }
    }
    return cell;
}
Also used : WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) MarkupContainer(org.apache.wicket.MarkupContainer) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IPersist(com.servoy.j2db.persistence.IPersist) ListItem(org.apache.wicket.markup.html.list.ListItem) 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) Point(java.awt.Point)

Aggregations

IPersist (com.servoy.j2db.persistence.IPersist)84 Point (java.awt.Point)26 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)23 Form (com.servoy.j2db.persistence.Form)22 ArrayList (java.util.ArrayList)22 IFormElement (com.servoy.j2db.persistence.IFormElement)20 BaseComponent (com.servoy.j2db.persistence.BaseComponent)19 HashMap (java.util.HashMap)16 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)14 IComponent (com.servoy.j2db.ui.IComponent)13 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)13 Component (org.apache.wicket.Component)13 AbstractBase (com.servoy.j2db.persistence.AbstractBase)12 JSONObject (org.json.JSONObject)10 PropertyDescription (org.sablo.specification.PropertyDescription)10 RepositoryException (com.servoy.j2db.persistence.RepositoryException)8 Tab (com.servoy.j2db.persistence.Tab)8 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)7