Search in sources :

Example 1 with BaseComponent

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

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

the class WebForm method getBounds.

public Rectangle getBounds(IComponent component) {
    if (// $NON-NLS-1$
    component instanceof Component && Utils.getAsBoolean(formController.getApplication().getRuntimeProperties().get("enableAnchors"))) {
        IPersist persist = getPersist(((Component) component).getId());
        if (persist instanceof ISupportAnchors && ((ISupportAnchors) persist).getAnchors() > 0 && ((ISupportAnchors) persist).getAnchors() != IAnchorConstants.DEFAULT) {
            int anchors = ((ISupportAnchors) persist).getAnchors();
            IDataRenderer renderer = ((Component) component).findParent(IDataRenderer.class);
            int partHeight = 0;
            if (renderer != null) {
                partHeight = renderer.getSize().height;
            }
            int designWidth = formController.getForm().getWidth();
            int designHeight = 0;
            Part part = formController.getForm().getPartAt(((BaseComponent) persist).getLocation().y);
            if (part != null) {
                int top = formController.getForm().getPartStartYPos(part.getID());
                designHeight = part.getHeight() - top;
            }
            if (partHeight > 0 && formWidth > 0 && designWidth > 0 && designHeight > 0) {
                int navid = formController.getForm().getNavigatorID();
                int navigatorWidth = 0;
                if (navid == Form.NAVIGATOR_DEFAULT && formController.getForm().getView() != FormController.TABLE_VIEW && formController.getForm().getView() != FormController.LOCKED_TABLE_VIEW) {
                    navigatorWidth = WebDefaultRecordNavigator.DEFAULT_WIDTH;
                } else if (navid != Form.NAVIGATOR_NONE) {
                    ISupportNavigator navigatorSupport = findParent(ISupportNavigator.class);
                    if (navigatorSupport != null) {
                        FormController currentNavFC = navigatorSupport.getNavigator();
                        if (currentNavFC != null) {
                            navigatorWidth = currentNavFC.getForm().getWidth();
                        }
                    }
                }
                Rectangle bounds = new Rectangle(component.getLocation(), component.getSize());
                if ((anchors & IAnchorConstants.EAST) != 0 && (anchors & IAnchorConstants.WEST) == 0) {
                    bounds.x += formWidth - designWidth - navigatorWidth;
                }
                if ((anchors & IAnchorConstants.SOUTH) != 0 && (anchors & IAnchorConstants.NORTH) == 0) {
                    bounds.y += partHeight - designHeight;
                }
                if ((anchors & IAnchorConstants.EAST) != 0 && (anchors & IAnchorConstants.WEST) != 0 && (formWidth - designWidth - navigatorWidth > 0)) {
                    bounds.width += formWidth - designWidth - navigatorWidth;
                }
                if ((anchors & IAnchorConstants.SOUTH) != 0 && (anchors & IAnchorConstants.NORTH) != 0 && (partHeight - designHeight > 0)) {
                    bounds.height += partHeight - designHeight;
                }
                return bounds;
            }
        }
    }
    return null;
}
Also used : FormController(com.servoy.j2db.FormController) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) IPersist(com.servoy.j2db.persistence.IPersist) ISupportNavigator(com.servoy.j2db.ISupportNavigator) Part(com.servoy.j2db.persistence.Part) Rectangle(java.awt.Rectangle) IComponent(com.servoy.j2db.ui.IComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) Point(java.awt.Point)

Example 3 with BaseComponent

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

the class AngularFormGenerator method writePosition.

/**
 * @param writer
 * @param o
 */
@SuppressWarnings("nls")
public static void writePosition(JSONWriter writer, IPersist o, Form form, WebFormComponent webComponent, boolean isDesigner) {
    if (o instanceof BaseComponent && ((BaseComponent) o).getCssPosition() != null) {
        CSSPosition position = ((BaseComponent) o).getCssPosition();
        if (webComponent != null) {
            Object runtimeValue = webComponent.getProperty(IContentSpecConstants.PROPERTY_CSS_POSITION);
            if (runtimeValue instanceof CSSPosition) {
                position = (CSSPosition) runtimeValue;
            }
        }
        writer.key("position");
        writer.object();
        if (CSSPositionUtils.isSet(position.left)) {
            writer.key("left").value(CSSPositionUtils.getCSSValue(position.left));
        }
        if (CSSPositionUtils.isSet(position.top)) {
            String top = position.top;
            if (!isDesigner) {
                Point location = CSSPositionUtils.getLocation((BaseComponent) o);
                Part prt = form.getPartAt(location.y);
                if (prt != null) {
                    int topStart = form.getPartStartYPos(prt.getID());
                    if (topStart > 0) {
                        if (top.endsWith("px")) {
                            top = top.substring(0, top.length() - 2);
                        }
                        int topInteger = Utils.getAsInteger(top, -1);
                        if (topInteger != -1) {
                            top = String.valueOf(topInteger - topStart);
                        } else {
                            top = "calc(" + top + "-" + topStart + "px)";
                        }
                    }
                }
            }
            writer.key("top").value(CSSPositionUtils.getCSSValue(top));
        }
        if (CSSPositionUtils.isSet(position.bottom)) {
            writer.key("bottom").value(CSSPositionUtils.getCSSValue(position.bottom));
        }
        if (CSSPositionUtils.isSet(position.right)) {
            writer.key("right").value(CSSPositionUtils.getCSSValue(position.right));
        }
        if (CSSPositionUtils.isSet(position.width)) {
            if (CSSPositionUtils.isSet(position.left) && CSSPositionUtils.isSet(position.right)) {
                writer.key("min-width").value(CSSPositionUtils.getCSSValue(position.width));
            } else {
                writer.key("width").value(CSSPositionUtils.getCSSValue(position.width));
            }
        }
        if (CSSPositionUtils.isSet(position.height)) {
            if (CSSPositionUtils.isSet(position.top) && CSSPositionUtils.isSet(position.bottom)) {
                writer.key("min-height").value(CSSPositionUtils.getCSSValue(position.height));
            } else {
                writer.key("height").value(CSSPositionUtils.getCSSValue(position.height));
            }
        }
        writer.endObject();
    } else {
        Point location = ((IFormElement) o).getLocation();
        Dimension size = ((IFormElement) o).getSize();
        if (webComponent != null) {
            Object runtimeValue = webComponent.getProperty(IContentSpecConstantsBase.PROPERTY_LOCATION);
            if (runtimeValue instanceof Point) {
                location = (Point) runtimeValue;
            }
            runtimeValue = webComponent.getProperty(IContentSpecConstantsBase.PROPERTY_SIZE);
            if (runtimeValue instanceof Dimension) {
                size = (Dimension) runtimeValue;
            }
        }
        if (location != null && size != null) {
            int anchorFlags = ((BaseComponent) o).getAnchors();
            boolean anchoredTop = (anchorFlags & IAnchorConstants.NORTH) != 0;
            boolean anchoredRight = (anchorFlags & IAnchorConstants.EAST) != 0;
            boolean anchoredBottom = (anchorFlags & IAnchorConstants.SOUTH) != 0;
            boolean anchoredLeft = (anchorFlags & IAnchorConstants.WEST) != 0;
            if (!anchoredLeft && !anchoredRight)
                anchoredLeft = true;
            if (!anchoredTop && !anchoredBottom)
                anchoredTop = true;
            writer.key("position");
            writer.object();
            if (anchoredTop) {
                writer.key("top");
                writer.value(location.y + "px");
            }
            if (anchoredBottom) {
                writer.key("bottom");
                int partHeight = form.getSize().height;
                if (!isDesigner) {
                    // search for element's part using its design time location
                    Part prt = form.getPartAt(((IFormElement) o).getLocation().y);
                    if (prt != null) {
                        int prtEnd = form.getPartEndYPos(prt.getID());
                        if (prtEnd > form.getSize().height)
                            prtEnd = form.getSize().height;
                        partHeight = prtEnd - form.getPartStartYPos(prt.getID());
                    }
                }
                writer.value(partHeight - location.y - size.height + "px");
            }
            if (!anchoredTop || !anchoredBottom) {
                writer.key("height");
                writer.value(size.height + "px");
            }
            if (anchoredLeft) {
                writer.key("left");
                writer.value(location.x + "px");
            }
            if (anchoredRight) {
                writer.key("right");
                writer.value((form.getWidth() - location.x - size.width) + "px");
            }
            if (!anchoredLeft || !anchoredRight) {
                writer.key("width");
                writer.value(size.width + "px");
            }
            if (anchoredTop && anchoredBottom) {
                writer.key("min-height");
                writer.value(size.height + "px");
            }
            if (anchoredLeft && anchoredRight) {
                writer.key("min-width");
                writer.value(size.width + "px");
            }
            writer.endObject();
        }
    }
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) BaseComponent(com.servoy.j2db.persistence.BaseComponent) Part(com.servoy.j2db.persistence.Part) CSSPosition(com.servoy.j2db.persistence.CSSPosition) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 4 with BaseComponent

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

the class FormWrapper method getBaseComponents.

public Collection<IFormElement> getBaseComponents() {
    if (this.baseComponents != null)
        return this.baseComponents;
    List<IFormElement> components = new ArrayList<>();
    Collection<BaseComponent> excludedComponents = null;
    if ((isListView && !design) || isTableView) {
        excludedComponents = getBodyComponents();
    }
    List<IFormElement> persists = form.getFlattenedObjects(Form.FORM_INDEX_COMPARATOR);
    for (IFormElement persist : persists) {
        if (isSecurityVisible(persist)) {
            if ((excludedComponents == null || !excludedComponents.contains(persist)))
                components.add(persist);
            checkFormComponents(components, FormElementHelper.INSTANCE.getFormElement(persist, context.getSolution(), null, design), new HashSet<String>());
        }
    }
    if ((isListView && !design) || isTableView) {
        components.add(new BodyPortal(form));
    }
    if (form.getNavigatorID() == Form.NAVIGATOR_DEFAULT) {
        components.add(DefaultNavigator.INSTANCE);
    }
    this.baseComponents = components;
    return components;
}
Also used : IFormElement(com.servoy.j2db.persistence.IFormElement) BaseComponent(com.servoy.j2db.persistence.BaseComponent) BodyPortal(com.servoy.j2db.server.ngclient.BodyPortal) ArrayList(java.util.ArrayList)

Example 5 with BaseComponent

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

the class JSPortal method setX.

/**
 * @see com.servoy.j2db.scripting.solutionmodel.JSComponent#setX(int)
 */
@Override
@JSSetter
public void setX(int x) {
    int xDif = x - getX();
    Iterator<IPersist> allObjects = getBaseComponent(true).getAllObjects();
    while (allObjects.hasNext()) {
        IPersist persist = allObjects.next();
        if (persist instanceof BaseComponent) {
            BaseComponent baseComponent = (BaseComponent) persist;
            Point location = baseComponent.getLocation();
            ((BaseComponent) persist).setLocation(new Point(location.x + xDif, location.y));
        }
    }
    super.setX(x);
}
Also used : BaseComponent(com.servoy.j2db.persistence.BaseComponent) IPersist(com.servoy.j2db.persistence.IPersist) Point(java.awt.Point) Point(java.awt.Point) JSSetter(org.mozilla.javascript.annotations.JSSetter)

Aggregations

BaseComponent (com.servoy.j2db.persistence.BaseComponent)15 Point (java.awt.Point)10 IPersist (com.servoy.j2db.persistence.IPersist)8 Part (com.servoy.j2db.persistence.Part)7 ArrayList (java.util.ArrayList)5 Form (com.servoy.j2db.persistence.Form)4 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)4 IFormElement (com.servoy.j2db.persistence.IFormElement)4 JSONObject (org.json.JSONObject)3 IForm (com.servoy.j2db.IForm)2 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)2 Portal (com.servoy.j2db.persistence.Portal)2 TabPanel (com.servoy.j2db.persistence.TabPanel)2 BodyPortal (com.servoy.j2db.server.ngclient.BodyPortal)2 IComponent (com.servoy.j2db.ui.IComponent)2 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)2 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2