Search in sources :

Example 11 with IProviderStylePropertyChanges

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

the class DesignModeBehavior method respond.

/**
 * @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget)
 */
@Override
protected void respond(AjaxRequestTarget target) {
    Request request = RequestCycle.get().getRequest();
    String action = request.getParameter(DraggableBehavior.PARAM_ACTION);
    String id = extractId(request.getParameter(DraggableBehavior.PARAM_DRAGGABLE_ID));
    if (id != null) {
        final String finalId = id.endsWith(TemplateGenerator.WRAPPER_SUFFIX) ? id.substring(0, id.length() - 8) : id;
        MarkupContainer comp = (MarkupContainer) getComponent();
        Component child = (Component) comp.visitChildren(Component.class, new IVisitor<Component>() {

            public Object component(Component component) {
                String markupId = component.getMarkupId();
                if (finalId.equals(markupId))
                    return component;
                return IVisitor.CONTINUE_TRAVERSAL;
            }
        });
        if (action != null) {
            int height = stripUnitPart(request.getParameter(PARAM_RESIZE_HEIGHT));
            int width = stripUnitPart(request.getParameter(PARAM_RESIZE_WIDTH));
            int x = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_X));
            int y = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_Y));
            if (action.equals(ACTION_SELECT)) {
                if (!(child instanceof IComponent))
                    onSelectComponents.clear();
                else {
                    boolean isSelectionRemove = false;
                    if (!Boolean.parseBoolean(request.getParameter(PARAM_IS_CTRL_KEY)))
                        onSelectComponents.clear();
                    else {
                        isSelectionRemove = onSelectComponents.remove(child) != null;
                    }
                    IComponent[] param = onSelectComponents.keySet().toArray(new IComponent[isSelectionRemove ? onSelectComponents.size() : onSelectComponents.size() + 1]);
                    if (!isSelectionRemove)
                        param[onSelectComponents.size()] = (IComponent) child;
                    Object ret = callback.executeOnSelect(getJSEvent(EventType.action, 0, new Point(x, y), param));
                    if (ret instanceof Boolean && !((Boolean) ret).booleanValue()) {
                        onSelectComponents.clear();
                    } else {
                        if (!isSelectionRemove)
                            onSelectComponents.put((IComponent) child, id);
                        StringBuilder idsArray = new StringBuilder("new Array(");
                        Iterator<String> idsIte = onSelectComponents.values().iterator();
                        while (idsIte.hasNext()) {
                            idsArray.append('\'').append(idsIte.next()).append('\'');
                            if (idsIte.hasNext())
                                idsArray.append(',');
                        }
                        idsArray.append(')');
                        target.appendJavascript("Servoy.ClientDesign.attachElements(" + idsArray.toString() + ");");
                    }
                    if (Boolean.parseBoolean(request.getParameter(PARAM_IS_RIGHTCLICK))) {
                        callback.executeOnRightClick(getJSEvent(EventType.rightClick, 0, new Point(x, y), param));
                    } else if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
                        callback.executeOnDblClick(getJSEvent(EventType.doubleClick, 0, new Point(x, y), param));
                    }
                }
                WebEventExecutor.generateResponse(target, getComponent().getPage());
                target.appendJavascript("Servoy.ClientDesign.clearClickTimer();");
                return;
            }
            if (child instanceof IComponent) {
                if (!onSelectComponents.containsKey(child)) {
                    onSelectComponents.put((IComponent) child, id);
                }
                if (action.equals(ACTION_RESIZE)) {
                    if (width != -1 && height != -1) {
                        if (child instanceof ISupportWebBounds) {
                            Insets paddingAndBorder = ((ISupportWebBounds) child).getPaddingAndBorder();
                            if (paddingAndBorder != null) {
                                height += paddingAndBorder.bottom + paddingAndBorder.top;
                                width += paddingAndBorder.left + paddingAndBorder.right;
                            }
                        }
                        if (child instanceof IScriptableProvider) {
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setSize(width, height);
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x, y);
                        }
                        if (child instanceof IProviderStylePropertyChanges)
                            ((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
                    }
                    callback.executeOnResize(getJSEvent(EventType.onDrop, 0, new Point(x, y), new IComponent[] { (IComponent) child }));
                } else if (action.equals(DraggableBehavior.ACTION_DRAG_START)) {
                    Object onDragAllowed = callback.executeOnDrag(getJSEvent(EventType.onDrag, 0, new Point(x, y), onSelectComponents.keySet().toArray(new IComponent[onSelectComponents.size()])));
                    if ((onDragAllowed instanceof Boolean && !((Boolean) onDragAllowed).booleanValue()) || (onDragAllowed instanceof Number && ((Number) onDragAllowed).intValue() == DRAGNDROP.NONE)) {
                        onDragComponent = null;
                    } else {
                        onDragComponent = (IComponent) child;
                    }
                    WebEventExecutor.generateResponse(target, getComponent().getPage());
                    return;
                } else {
                    if (child == onDragComponent) {
                        if (x != -1 && y != -1) {
                            ((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x, y);
                            if (child instanceof IProviderStylePropertyChanges) {
                                // test if it is wrapped
                                if ((child).getParent() instanceof WrapperContainer) {
                                    // call for the changes on the wrapper container so that it will copy the right values over
                                    WrapperContainer wrapper = (WrapperContainer) (child).getParent();
                                    wrapper.getStylePropertyChanges().getChanges();
                                    wrapper.getStylePropertyChanges().setRendered();
                                }
                                ((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
                            }
                        }
                        callback.executeOnDrop(getJSEvent(EventType.onDrop, 0, new Point(x, y), onSelectComponents.keySet().toArray(new IComponent[onSelectComponents.size()])));
                    }
                    if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
                        callback.executeOnDblClick(getJSEvent(EventType.doubleClick, 0, new Point(x, y), new IComponent[] { (IComponent) child }));
                    }
                }
            }
        }
    }
    WebEventExecutor.generateResponse(target, getComponent().getPage());
    target.appendJavascript("Servoy.ClientDesign.reattach();");
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) Insets(java.awt.Insets) IVisitor(org.apache.wicket.Component.IVisitor) IComponent(com.servoy.j2db.ui.IComponent) Request(org.apache.wicket.Request) Point(java.awt.Point) Point(java.awt.Point) ISupportWebBounds(com.servoy.j2db.ui.ISupportWebBounds) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) 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) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Aggregations

IProviderStylePropertyChanges (com.servoy.j2db.ui.IProviderStylePropertyChanges)11 Component (org.apache.wicket.Component)8 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)7 IComponent (com.servoy.j2db.ui.IComponent)6 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)5 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)5 BaseComponent (com.servoy.j2db.persistence.BaseComponent)4 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)4 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)4 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)4 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)3 IPersist (com.servoy.j2db.persistence.IPersist)3 MainPage (com.servoy.j2db.server.headlessclient.MainPage)3 MarkupContainer (org.apache.wicket.MarkupContainer)3 ListItem (org.apache.wicket.markup.html.list.ListItem)3 IScriptable (com.servoy.j2db.scripting.IScriptable)2 WrapperContainer (com.servoy.j2db.server.headlessclient.WrapperContainer)2 ILabel (com.servoy.j2db.ui.ILabel)2 IStylePropertyChanges (com.servoy.j2db.ui.IStylePropertyChanges)2 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)2