Search in sources :

Example 1 with IRuntimeInputComponent

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

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

the class DesignModeBehavior method setSelectedComponents.

public void setSelectedComponents(String[] selectedComponentsNames) {
    onSelectComponents.clear();
    if (selectedComponentsNames != null && selectedComponentsNames.length > 0) {
        IComponent c;
        String compId;
        boolean webAnchorsEnabled = Utils.getAsBoolean(((WebClientSession) Session.get()).getWebClient().getRuntimeProperties().get("enableAnchors"));
        boolean editable;
        for (String selectedComponentName : selectedComponentsNames) {
            c = getWicketComponentForName(selectedComponentName);
            editable = false;
            if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeInputComponent) {
                editable = ((IRuntimeInputComponent) ((IScriptableProvider) c).getScriptObject()).isEditable();
            }
            if (webAnchorsEnabled && c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent && needsWrapperDivForAnchoring(((IRuntimeComponent) ((IScriptableProvider) c).getScriptObject()).getElementType(), editable)) {
                compId = ((Component) c).getMarkupId() + TemplateGenerator.WRAPPER_SUFFIX;
            } else {
                compId = ((Component) c).getMarkupId();
            }
            onSelectComponents.put(c, compId);
        }
    }
}
Also used : IRuntimeInputComponent(com.servoy.j2db.ui.runtime.IRuntimeInputComponent) IComponent(com.servoy.j2db.ui.IComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) 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)

Aggregations

IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)2 IComponent (com.servoy.j2db.ui.IComponent)2 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)2 IRuntimeInputComponent (com.servoy.j2db.ui.runtime.IRuntimeInputComponent)2 Component (org.apache.wicket.Component)2 WebDataCalendar (com.servoy.j2db.server.headlessclient.dataui.WebDataCalendar)1 WebDataRenderer (com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer)1 ISupportWebBounds (com.servoy.j2db.ui.ISupportWebBounds)1 ITabPanel (com.servoy.j2db.ui.ITabPanel)1 Insets (java.awt.Insets)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 MarkupContainer (org.apache.wicket.MarkupContainer)1