Search in sources :

Example 1 with IFormDataDragNDrop

use of com.servoy.j2db.dnd.IFormDataDragNDrop in project servoy-client by Servoy.

the class WebEventExecutor method generateDragAttach.

/**
 * @param component2
 * @param response
 */
@SuppressWarnings("nls")
public static void generateDragAttach(Component component, IHeaderResponse response) {
    DraggableBehavior draggableBehavior = null;
    Component behaviorComponent = component;
    if ((behaviorComponent instanceof IComponent) && !(behaviorComponent instanceof IFormDataDragNDrop)) {
        behaviorComponent = (Component) component.findParent(IFormDataDragNDrop.class);
    }
    if (behaviorComponent != null) {
        Iterator<IBehavior> behaviors = behaviorComponent.getBehaviors().iterator();
        Object behavior;
        while (behaviors.hasNext()) {
            behavior = behaviors.next();
            if (behavior instanceof DraggableBehavior) {
                draggableBehavior = (DraggableBehavior) behavior;
                break;
            }
        }
    }
    if (draggableBehavior == null)
        return;
    boolean bUseProxy = draggableBehavior.isUseProxy();
    boolean bResizeProxyFrame = draggableBehavior.isResizeProxyFrame();
    boolean bXConstraint = draggableBehavior.isXConstraint();
    boolean bYConstraint = draggableBehavior.isYConstraint();
    CharSequence dragUrl = draggableBehavior.getCallbackUrl();
    String jsCode = null;
    if (behaviorComponent instanceof IFormDataDragNDrop) {
        final StringBuilder sbAttachDrag = new StringBuilder(100);
        sbAttachDrag.append("Servoy.DD.attachDrag([");
        final StringBuilder sbAttachDrop = new StringBuilder(100);
        sbAttachDrop.append("Servoy.DD.attachDrop([");
        final boolean hasDragEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDragMethodID() > 0 || ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDragOverMethodID() > 0;
        final boolean hasDropEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDropMethodID() > 0;
        if (component instanceof WebDataRenderer || component instanceof WebCellBasedView) {
            if (hasDragEvent)
                sbAttachDrag.append('\'').append(component.getMarkupId()).append("',");
            if (hasDropEvent)
                sbAttachDrop.append('\'').append(component.getMarkupId()).append("',");
            if (component instanceof WebDataRenderer) {
                Iterator<? extends Component> dataRendererIte = ((WebDataRenderer) component).iterator();
                Object dataRendererChild;
                while (dataRendererIte.hasNext()) {
                    dataRendererChild = dataRendererIte.next();
                    if (dataRendererChild instanceof IWebFormContainer)
                        continue;
                    if (dataRendererChild instanceof WrapperContainer)
                        dataRendererChild = ((WrapperContainer) dataRendererChild).getDelegate();
                    if (dataRendererChild instanceof IComponent && ((IComponent) dataRendererChild).isEnabled()) {
                        updateDragAttachOutput(dataRendererChild, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
                    }
                }
            } else if (component instanceof WebCellBasedView) {
                ListView<IRecordInternal> table = ((WebCellBasedView) component).getTable();
                table.visitChildren(new IVisitor<Component>() {

                    public Object component(Component comp) {
                        if (comp instanceof IComponent && comp.isEnabled()) {
                            updateDragAttachOutput(comp, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
                        }
                        return null;
                    }
                });
            }
        } else if (component != null && component.isEnabled()) {
            updateDragAttachOutput(component, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
        }
        if (sbAttachDrag.length() > 25) {
            sbAttachDrag.setLength(sbAttachDrag.length() - 1);
            sbAttachDrag.append("],'");
            sbAttachDrag.append(dragUrl);
            sbAttachDrag.append("', ");
            sbAttachDrag.append(bUseProxy);
            sbAttachDrag.append(", ");
            sbAttachDrag.append(bResizeProxyFrame);
            sbAttachDrag.append(", ");
            sbAttachDrag.append(bXConstraint);
            sbAttachDrag.append(", ");
            sbAttachDrag.append(bYConstraint);
            sbAttachDrag.append(");");
            jsCode = sbAttachDrag.toString();
        }
        if (sbAttachDrop.length() > 25) {
            sbAttachDrop.setLength(sbAttachDrop.length() - 1);
            sbAttachDrop.append("],'");
            sbAttachDrop.append(dragUrl);
            sbAttachDrop.append("');");
            if (jsCode != null)
                jsCode += '\n' + sbAttachDrop.toString();
            else
                jsCode = sbAttachDrop.toString();
        }
        if (jsCode != null) {
            if (response == null) {
                jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode).append("</script>\n")).toString();
                Response cyleResponse = RequestCycle.get().getResponse();
                cyleResponse.write(jsCode);
            } else
                response.renderOnDomReadyJavascript(jsCode);
        }
    } else // default handling
    {
        jsCode = "Servoy.DD.attachDrag(['" + component.getMarkupId() + "'],'" + dragUrl + "', " + bUseProxy + ", " + bResizeProxyFrame + ", " + bXConstraint + ", " + bYConstraint + ")";
        if (response == null) {
            jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode).append("</script>\n")).toString();
            Response cyleResponse = RequestCycle.get().getResponse();
            cyleResponse.write(jsCode);
        } else
            response.renderOnDomReadyJavascript(jsCode);
    }
}
Also used : IVisitor(org.apache.wicket.Component.IVisitor) IComponent(com.servoy.j2db.ui.IComponent) WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) Response(org.apache.wicket.Response) IHeaderResponse(org.apache.wicket.markup.html.IHeaderResponse) IFormDataDragNDrop(com.servoy.j2db.dnd.IFormDataDragNDrop) ListView(org.apache.wicket.markup.html.list.ListView) DraggableBehavior(com.servoy.j2db.server.headlessclient.dnd.DraggableBehavior) IBehavior(org.apache.wicket.behavior.IBehavior) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Aggregations

IFormDataDragNDrop (com.servoy.j2db.dnd.IFormDataDragNDrop)1 WrapperContainer (com.servoy.j2db.server.headlessclient.WrapperContainer)1 DraggableBehavior (com.servoy.j2db.server.headlessclient.dnd.DraggableBehavior)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)1 Component (org.apache.wicket.Component)1 IVisitor (org.apache.wicket.Component.IVisitor)1 Response (org.apache.wicket.Response)1 IBehavior (org.apache.wicket.behavior.IBehavior)1 IHeaderResponse (org.apache.wicket.markup.html.IHeaderResponse)1 FormComponent (org.apache.wicket.markup.html.form.FormComponent)1 ListView (org.apache.wicket.markup.html.list.ListView)1