Search in sources :

Example 1 with ISupportAnchors

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

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

the class ScrollResponseHeaderContainer method distributeExtraSpace.

private void distributeExtraSpace() {
    int totalDefaultWidth = 0;
    int totalWidthToStretch = 0;
    int stretchedElementsCount = 0;
    for (IPersist element : elementToColumnIdentifierComponent.keySet()) {
        Object scriptobject = elementToColumnIdentifierComponent.get(element);
        if (!((Component) scriptobject).isVisible())
            continue;
        if (scriptobject instanceof IScriptableProvider) {
            scriptobject = ((IScriptableProvider) scriptobject).getScriptObject();
        }
        if (scriptobject instanceof IRuntimeComponent) {
            int width = ((IRuntimeComponent) scriptobject).getWidth();
            totalDefaultWidth += width;
            if (element instanceof ISupportAnchors) {
                int anchors = ((ISupportAnchors) element).getAnchors();
                if (((anchors & IAnchorConstants.EAST) != 0) && ((anchors & IAnchorConstants.WEST) != 0)) {
                    totalWidthToStretch += width;
                    stretchedElementsCount++;
                }
            }
        }
    }
    boolean shouldFillAllHorizSpace = shouldFillAllHorizontalSpace();
    if (shouldFillAllHorizSpace) {
        if (stretchedElementsCount > 0) {
            int delta = getDisplayBodyWidthHint() - totalDefaultWidth;
            distributeExtraSpace(delta, totalWidthToStretch, null, true);
            setHeadersWidth();
        }
    }
}
Also used : ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) Point(java.awt.Point)

Example 3 with ISupportAnchors

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

the class SortableCellViewHeaders method isReorderableOrResizable.

private boolean isReorderableOrResizable() {
    if (// $NON-NLS-1$
    Utils.getAsBoolean(application.getRuntimeProperties().get("useAJAX"))) {
        boolean isReorderable = false;
        boolean isResizable = false;
        Iterator<IPersist> iter = cellview.getAllObjects();
        while (iter.hasNext()) {
            IPersist element = iter.next();
            if (element instanceof ISupportAnchors) {
                int anchors = ((ISupportAnchors) element).getAnchors();
                isResizable = ((anchors & IAnchorConstants.EAST) == IAnchorConstants.EAST) && ((anchors & IAnchorConstants.WEST) == IAnchorConstants.WEST);
                isResizable = isResizable && (!(cellview instanceof Portal) || ((Portal) cellview).getResizable());
                if (isResizable)
                    return true;
                isReorderable = !(((anchors & IAnchorConstants.NORTH) == IAnchorConstants.NORTH) && ((anchors & IAnchorConstants.SOUTH) == IAnchorConstants.SOUTH));
                isReorderable = isReorderable && (!(cellview instanceof Portal) || ((Portal) cellview).getReorderable());
                if (isReorderable)
                    return true;
            }
        }
    }
    return false;
}
Also used : ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) Portal(com.servoy.j2db.persistence.Portal)

Example 4 with ISupportAnchors

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

the class DataRendererFactory method placeElements.

// returns usesSliding
private Map placeElements(Iterator<IFormElement> e1, IApplication app, Form form, IScriptExecuter listner, Map emptyDataRenderers, int width, int XCorrection, int YCorrection, boolean printing, boolean cutDataProviderNames, ControllerUndoManager undoManager, boolean isPortal, TabSequenceHelper<Component> tabSequence) throws Exception {
    IDataProviderLookup dataProviderLookup = app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), form);
    Map listTocomplete = new HashMap();
    Map labelForComponents = new HashMap();
    // Insets insets = new Insets(0, 0, 0, 0);
    while (e1.hasNext()) {
        Point l = null;
        IPersist obj = e1.next();
        l = ((IFormElement) obj).getLocation();
        // unkown where to add
        if (l == null)
            continue;
        if (printing && obj instanceof ISupportPrinting) {
            if (!((ISupportPrinting) obj).getPrintable())
                continue;
        }
        Iterator it = emptyDataRenderers.values().iterator();
        while (it.hasNext()) {
            DataRenderer panel = (DataRenderer) it.next();
            int start = panel.getLocation().y;
            if (l.y >= start && l.y < start + panel.getSize().height) {
                Component comp = (Component) ComponentFactory.createComponent(app, form, obj, dataProviderLookup, listner, printing);
                // Test for a visible bean, then get the real component
                if (comp instanceof VisibleBean) {
                    comp = ((VisibleBean) comp).getDelegate();
                }
                if (comp != null) {
                    if (obj instanceof Field && comp instanceof JComponent) {
                        String name = ((Field) obj).getName();
                        if (name != null && !"".equals(name)) {
                            labelForComponents.put(name, comp);
                        }
                    } else if (obj instanceof GraphicalComponent && comp instanceof JLabel) {
                        String labelFor = ((GraphicalComponent) obj).getLabelFor();
                        if (labelFor != null && !"".equals(labelFor)) {
                            labelForComponents.put(comp, labelFor);
                        }
                    }
                    if (obj instanceof ISupportTabSeq && comp instanceof JComponent && (tabSequence != null)) {
                        tabSequence.add(panel, (ISupportTabSeq) obj, comp);
                    }
                    Component newComp = comp;
                    if (newComp instanceof IDisplay) {
                        // HACK:don;t no other way to do this.........
                        if (newComp instanceof IDisplayData && cutDataProviderNames) {
                            IDisplayData da = (IDisplayData) newComp;
                            String id = da.getDataProviderID();
                            if (id != null && !ScopesUtils.isVariableScope(id)) {
                                // only cut first relation (so you can have relation chain inside portal)
                                int index = id.indexOf('.');
                                // TODO:check if part before . is same as relation name (objToRender.getRelationID() )
                                if (index > 0) {
                                    id = id.substring(index + 1);
                                }
                                da.setDataProviderID(id);
                            }
                        }
                        panel.addDisplayComponent(obj, (IDisplay) newComp);
                    }
                    comp.setLocation((l.x) + XCorrection, (l.y - start) + YCorrection);
                    int index = 0;
                    if (!printing && obj instanceof ISupportAnchors) {
                        panel.add(comp, new Integer(((ISupportAnchors) obj).getAnchors()), index);
                    } else if (printing) {
                        if (obj instanceof ISupportPrintSliding && !isPortal) {
                            int slide = ((ISupportPrintSliding) obj).getPrintSliding();
                            if (slide != ISupportPrintSliding.NO_SLIDING) {
                                listTocomplete.put(comp, new Integer(slide));
                                panel.setUsingSliding(true);
                            }
                        }
                        panel.add(comp, index);
                    } else {
                        panel.add(comp, index);
                    }
                }
            }
        }
    }
    if (!printing) {
        Iterator it = labelForComponents.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Entry) it.next();
            if (entry.getKey() instanceof JLabel) {
                JComponent component = (JComponent) labelForComponents.get(entry.getValue());
                if (component != null) {
                    ((JLabel) entry.getKey()).setLabelFor(component);
                    if (component instanceof IFieldComponent) {
                        ((IFieldComponent) component).addLabelFor((ILabel) entry.getKey());
                        if (!((IFieldComponent) component).isVisible()) {
                            ((IFieldComponent) component).setComponentVisible(((IFieldComponent) component).isVisible());
                        }
                        if (!((IFieldComponent) component).isEnabled()) {
                            ((IFieldComponent) component).setComponentEnabled(((IFieldComponent) component).isEnabled());
                        }
                    }
                }
            }
        }
    }
    Iterator it = emptyDataRenderers.values().iterator();
    while (it.hasNext()) {
        DataRenderer panel = (DataRenderer) it.next();
        panel.createDataAdapter(app, dataProviderLookup, listner, undoManager);
    }
    return listTocomplete;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) Field(com.servoy.j2db.persistence.Field) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent) ISupportPrinting(com.servoy.j2db.persistence.ISupportPrinting) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) Point(java.awt.Point) ISupportPrintSliding(com.servoy.j2db.persistence.ISupportPrintSliding) Point(java.awt.Point) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IPersist(com.servoy.j2db.persistence.IPersist) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Example 5 with ISupportAnchors

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

the class RuntimeWebComponent method isApiFunctionEnabled.

protected boolean isApiFunctionEnabled(String functionName) {
    boolean isLocationOrSize = "getLocationX".equals(functionName) || "getLocationY".equals(functionName) || "getWidth".equals(functionName) || "getHeight".equals(functionName);
    if (isLocationOrSize) {
        // if parent form not visible, don't call api, let it get from the model on the server
        Container parent = component.getParent();
        while (parent != null) {
            if (parent instanceof WebFormUI) {
                boolean isFormVisible = false;
                IWindow currentWindow = CurrentWindow.safeGet();
                if (currentWindow instanceof INGClientWindow) {
                    isFormVisible = ((INGClientWindow) currentWindow).hasForm(parent.getName());
                }
                if (isFormVisible) {
                    // it is reported to be still on the client
                    // but do check also if it is not about to be hidden, by having
                    // formVisible already set to false in the controller
                    isFormVisible = ((WebFormUI) parent).getController().isFormVisible();
                }
                if (!isFormVisible) {
                    return false;
                }
                // if this form is in designer mode then it has to go to the client to get the current size/location
                if (((WebFormUI) parent).getController().getDesignModeCallbacks() != null)
                    return true;
                break;
            }
            parent = parent.getParent();
        }
        // if it is not table view (it can have columns moved/resize) and not anchored, no need to call api, let it get from the model on the server
        FormElement fe = component.getFormElement();
        if (fe.isLegacy() && fe.getPersistIfAvailable() instanceof ISupportAnchors && (fe.getForm().getView() != FormController.TABLE_VIEW && fe.getForm().getView() != FormController.LOCKED_TABLE_VIEW)) {
            // ((ISupportAnchors)fe.getPersistIfAvailable()).getAnchors();
            int anchor = Utils.getAsInteger(component.getProperty(StaticContentSpecLoader.PROPERTY_ANCHORS.getPropertyName()));
            if ((anchor == 0 || anchor == (IAnchorConstants.NORTH + IAnchorConstants.WEST))) {
                return false;
            }
        }
    }
    return true;
}
Also used : Container(org.sablo.Container) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) IWindow(org.sablo.websocket.IWindow) FormElement(com.servoy.j2db.server.ngclient.FormElement)

Aggregations

ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)9 IPersist (com.servoy.j2db.persistence.IPersist)7 Point (java.awt.Point)7 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)4 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)4 BaseComponent (com.servoy.j2db.persistence.BaseComponent)3 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)3 IComponent (com.servoy.j2db.ui.IComponent)3 Rectangle (java.awt.Rectangle)3 HashMap (java.util.HashMap)3 Component (org.apache.wicket.Component)3 Field (com.servoy.j2db.persistence.Field)2 Part (com.servoy.j2db.persistence.Part)2 Portal (com.servoy.j2db.persistence.Portal)2 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)2 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)2 ISupportWebBounds (com.servoy.j2db.ui.ISupportWebBounds)2 Dimension (java.awt.Dimension)2 WeakHashMap (java.util.WeakHashMap)2 FormController (com.servoy.j2db.FormController)1