Search in sources :

Example 1 with IRuntimeComponent

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

the class DesignModeBehavior method renderHead.

/**
 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#renderHead(org.apache.wicket.markup.html.IHeaderResponse)
 */
@Override
public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    YUILoader.renderResize(response);
    final ArrayList<Component> markupIds = new ArrayList<Component>();
    final ArrayList<Component> dropMarkupIds = new ArrayList<Component>();
    ((MarkupContainer) getComponent()).visitChildren(IComponent.class, new IVisitor<Component>() {

        public Object component(Component component) {
            if (!(component instanceof WebDataRenderer)) {
                markupIds.add(component);
                if (component instanceof ITabPanel || component instanceof WebDataCalendar) {
                    return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            } else if (component instanceof WebDataRenderer) {
                dropMarkupIds.add(component);
            }
            return IVisitor.CONTINUE_TRAVERSAL;
        }
    });
    if (markupIds.size() > 0) {
        boolean webAnchorsEnabled = Utils.getAsBoolean(((WebClientSession) Session.get()).getWebClient().getRuntimeProperties().get("enableAnchors"));
        // WebClientSession webClientSession = (WebClientSession)getSession();
        // WebClient webClient = webClientSession.getWebClient();
        ArrayList<String> selectedComponentsId = new ArrayList<String>();
        StringBuilder sb = new StringBuilder(markupIds.size() * 10);
        sb.append("Servoy.ClientDesign.attach({");
        for (int i = 0; i < markupIds.size(); i++) {
            Component component = markupIds.get(i);
            Object clientdesign_handles = null;
            if (component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeComponent) {
                IRuntimeComponent sbmc = (IRuntimeComponent) ((IScriptableProvider) component).getScriptObject();
                // skip, elements with no name are not usable in CD
                if (sbmc.getName() == null)
                    continue;
                clientdesign_handles = sbmc.getClientProperty(CLIENTDESIGN.HANDLES);
                Object clientdesign_selectable = sbmc.getClientProperty(CLIENTDESIGN.SELECTABLE);
                // skip
                if (clientdesign_selectable != null && !Utils.getAsBoolean(clientdesign_selectable))
                    continue;
            }
            // $NON-NLS-1$
            String padding = "0px 0px 0px 0px";
            if (component instanceof ISupportWebBounds) {
                Insets p = ((ISupportWebBounds) component).getPaddingAndBorder();
                if (p != null)
                    padding = "0px " + (p.left + p.right) + "px " + (p.bottom + p.top) + "px 0px";
            }
            boolean editable = false;
            if (component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeInputComponent) {
                editable = ((IRuntimeInputComponent) ((IScriptableProvider) component).getScriptObject()).isEditable();
            }
            String compId;
            if (webAnchorsEnabled && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeComponent && needsWrapperDivForAnchoring(((IRuntimeComponent) ((IScriptableProvider) component).getScriptObject()).getElementType(), editable)) {
                compId = component.getMarkupId() + TemplateGenerator.WRAPPER_SUFFIX;
            } else {
                compId = component.getMarkupId();
            }
            sb.append(compId);
            if (component instanceof IComponent) {
                Iterator<IComponent> selectedComponentsIte = onSelectComponents.keySet().iterator();
                IComponent c;
                while (selectedComponentsIte.hasNext()) {
                    c = selectedComponentsIte.next();
                    if (c.getName().equals(((IComponent) component).getName())) {
                        onSelectComponents.put(c, compId);
                        selectedComponentsId.add(compId);
                        break;
                    }
                }
            }
            sb.append(":['");
            sb.append(padding);
            sb.append("'");
            if (clientdesign_handles instanceof Object[]) {
                sb.append(",[");
                Object[] array = (Object[]) clientdesign_handles;
                for (Object element : array) {
                    sb.append('\'');
                    sb.append(ScriptRuntime.escapeString(element.toString()));
                    sb.append("',");
                }
                // rollback last comma
                sb.setLength(sb.length() - 1);
                sb.append("]");
            }
            sb.append("],");
        }
        // rollback last comma
        sb.setLength(sb.length() - 1);
        sb.append("},'" + getCallbackUrl() + "')");
        if (selectedComponentsId.size() > 0) {
            for (int i = 0; i < selectedComponentsId.size(); i++) {
                sb.append(";Servoy.ClientDesign.selectedElementId[").append(i).append("]='").append(selectedComponentsId.get(i)).append("';");
            }
            sb.append("Servoy.ClientDesign.reattach();");
        }
        response.renderOnDomReadyJavascript(sb.toString());
    // if (dropMarkupIds.size() > 0)
    // {
    // StringBuilder attachDrop = new StringBuilder();
    // attachDrop.append("attachDrop([");
    // for (int i = 0; i < dropMarkupIds.size(); i++)
    // {
    // Component component = dropMarkupIds.get(i);
    // attachDrop.append("'");
    // attachDrop.append(component.getMarkupId());
    // attachDrop.append("',");
    // }
    // attachDrop.setLength(attachDrop.length() - 1);
    // attachDrop.append("])");
    // response.renderOnDomReadyJavascript(attachDrop.toString());
    // }
    }
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) WebDataRenderer(com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer) Insets(java.awt.Insets) IComponent(com.servoy.j2db.ui.IComponent) ArrayList(java.util.ArrayList) ITabPanel(com.servoy.j2db.ui.ITabPanel) Point(java.awt.Point) IRuntimeInputComponent(com.servoy.j2db.ui.runtime.IRuntimeInputComponent) ISupportWebBounds(com.servoy.j2db.ui.ISupportWebBounds) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IComponent(com.servoy.j2db.ui.IComponent) Component(org.apache.wicket.Component) IRuntimeInputComponent(com.servoy.j2db.ui.runtime.IRuntimeInputComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) WebDataCalendar(com.servoy.j2db.server.headlessclient.dataui.WebDataCalendar) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 2 with IRuntimeComponent

use of com.servoy.j2db.ui.runtime.IRuntimeComponent 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 3 with IRuntimeComponent

use of com.servoy.j2db.ui.runtime.IRuntimeComponent 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 4 with IRuntimeComponent

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

the class ScrollResponseHeaderContainer method initializeComponent.

@SuppressWarnings("nls")
private void initializeComponent(final Component c, AbstractBase view, IPersist element) {
    if (dal != null && dal.isDestroyed()) {
        Debug.error("Trying to initialize a component: " + c + " of " + view + " element: " + element + " that is in a destroyed tableview", new RuntimeException());
        return;
    }
    if (// Don't know any other place for this
    view instanceof Portal && c instanceof IDisplayData) {
        String id = ((IDisplayData) c).getDataProviderID();
        if (id != null && !ScopesUtils.isVariableScope(id) && id.startsWith(((Portal) view).getRelationName() + '.')) {
            ((IDisplayData) c).setDataProviderID(id.substring(((Portal) cellview).getRelationName().length() + 1));
        }
    }
    if (!isListViewMode() && c instanceof WebDataCheckBox) {
        // $NON-NLS-1$
        ((WebDataCheckBox) c).setText("");
    }
    if (element != null) {
        // apply to this cell the state of the columnIdentifier IComponent, do keep the location that is set by the tableview when creating these components the first time.
        // for listview this is the location to use.
        Point loc = ((IComponent) c).getLocation();
        int height = ((IComponent) c).getSize().height;
        PropertyCopy.copyElementProps((IComponent) elementToColumnIdentifierComponent.get(element), (IComponent) c);
        if (!isListViewMode()) {
            ((IComponent) c).setLocation(loc);
            // it shouldn't be possible to change the height
            if (c instanceof IScriptableProvider) {
                IScriptable so = ((IScriptableProvider) c).getScriptObject();
                if (so instanceof IRuntimeComponent) {
                    IRuntimeComponent ic = (IRuntimeComponent) so;
                    if (ic.getHeight() != height) {
                        ic.setSize(ic.getWidth(), height);
                    }
                }
            }
        }
    } else {
        // $NON-NLS-1$
        Debug.log("Cannot find the IPersist element for cell " + c.getMarkupId());
    }
    if (c instanceof IDisplayData) {
        IDisplayData cdd = (IDisplayData) c;
        if (!(dal != null && dal.getFormScope() != null && cdd.getDataProviderID() != null && // skip for form variables
        dal.getFormScope().get(cdd.getDataProviderID()) != Scriptable.NOT_FOUND)) {
            cdd.setValidationEnabled(validationEnabled);
        }
    } else if (c instanceof IDisplayRelatedData) {
        ((IDisplayRelatedData) c).setValidationEnabled(validationEnabled);
    } else if (c instanceof IServoyAwareBean) {
        ((IServoyAwareBean) c).setValidationEnabled(validationEnabled);
    }
    addClassToCellComponent(c);
    if (// the check could be extended against IDelegate<?>
    c instanceof WebDataCompositeTextField) {
        Object delegate = ((WebDataCompositeTextField) c).getDelegate();
        if (delegate instanceof Component) {
            // make sure that this class is added accordingly in TemplateGenerator as a style selector containing relevant properties
            addClassToCellComponent((Component) delegate);
        }
    }
    if (c instanceof ISupportValueList) {
        ISupportValueList idVl = (ISupportValueList) elementToColumnIdentifierComponent.get(element);
        IValueList list;
        if (idVl != null && (list = idVl.getValueList()) != null) {
            ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
            if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
                ((ISupportValueList) c).setValueList(list);
            }
        }
    }
    applyClientProperties(c, element);
}
Also used : ValueList(com.servoy.j2db.persistence.ValueList) DBValueList(com.servoy.j2db.dataprocessing.DBValueList) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) IValueList(com.servoy.j2db.dataprocessing.IValueList) IComponent(com.servoy.j2db.ui.IComponent) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) Point(java.awt.Point) Point(java.awt.Point) IScriptable(com.servoy.j2db.scripting.IScriptable) IDisplayRelatedData(com.servoy.j2db.dataprocessing.IDisplayRelatedData) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) 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) IValueList(com.servoy.j2db.dataprocessing.IValueList)

Example 5 with IRuntimeComponent

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

the class BasicFormController method getElements.

public IRuntimeComponent[] getElements() {
    Object elementScope = formScope == null ? null : formScope.get("elements");
    if (elementScope instanceof DefaultScope) {
        Object[] values = ((DefaultScope) elementScope).getValues();
        List<IRuntimeComponent> elements = new ArrayList<IRuntimeComponent>(values.length);
        for (Object value : values) {
            if (value instanceof Wrapper) {
                value = ((Wrapper) value).unwrap();
            }
            if (value instanceof IRuntimeComponent) {
                elements.add((IRuntimeComponent) value);
            }
        }
        return elements.toArray(new IRuntimeComponent[elements.size()]);
    }
    return new IRuntimeComponent[0];
}
Also used : Wrapper(org.mozilla.javascript.Wrapper) ArrayList(java.util.ArrayList) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ITwoNativeJavaObject(com.servoy.j2db.scripting.ITwoNativeJavaObject) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) DefaultScope(com.servoy.j2db.scripting.DefaultScope)

Aggregations

IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)20 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)15 IComponent (com.servoy.j2db.ui.IComponent)10 Point (java.awt.Point)10 Component (org.apache.wicket.Component)9 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)6 BaseComponent (com.servoy.j2db.persistence.BaseComponent)5 IScriptable (com.servoy.j2db.scripting.IScriptable)5 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)5 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)4 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)4 IPersist (com.servoy.j2db.persistence.IPersist)3 IProviderStylePropertyChanges (com.servoy.j2db.ui.IProviderStylePropertyChanges)3 IRuntimeInputComponent (com.servoy.j2db.ui.runtime.IRuntimeInputComponent)3 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)2 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)2 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)2 RuntimeGroup (com.servoy.j2db.scripting.RuntimeGroup)2 ILabel (com.servoy.j2db.ui.ILabel)2 ISupportWebBounds (com.servoy.j2db.ui.ISupportWebBounds)2