Search in sources :

Example 1 with ISupportWebBounds

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

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

the class WebForm method getFormAnchorInfo.

@SuppressWarnings("unchecked")
public FormAnchorInfo getFormAnchorInfo() {
    formAnchorInfo = new FormAnchorInfo(formController.getName(), formController.getForm().getSize(), formController.getForm().getUUID());
    final Map<String, ISupportAnchors> elements = new HashMap<String, ISupportAnchors>();
    Iterator<IPersist> e1 = formController.getForm().getAllObjects();
    while (e1.hasNext()) {
        IPersist obj = e1.next();
        if (obj instanceof ISupportAnchors && obj instanceof ISupportBounds) {
            elements.put(ComponentFactory.getWebID(formController.getForm(), obj), (ISupportAnchors) obj);
        }
    }
    // In case we are in table view.
    if (view instanceof WebCellBasedView) {
        WebCellBasedView formPart = (WebCellBasedView) view;
        formAnchorInfo.addPart(Part.getDisplayName(Part.BODY), formPart.getMarkupId(), 50);
        formAnchorInfo.isTableView = true;
        formAnchorInfo.bodyContainerId = formPart.getMarkupId();
    }
    // Find the id of the form navigator, if any.
    visitChildren(Component.class, new IVisitor() {

        public Object component(Component component) {
            if (component instanceof WebDefaultRecordNavigator) {
                formAnchorInfo.navigatorWebId = component.getMarkupId();
                return IVisitor.CONTINUE_TRAVERSAL;
            } else if (component instanceof WebTabPanel) {
                return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
            } else
                return IVisitor.CONTINUE_TRAVERSAL;
        }
    });
    visitChildren(WebDataRenderer.class, new IVisitor() {

        public Object component(Component component) {
            WebDataRenderer formPart = (WebDataRenderer) component;
            final FormPartAnchorInfo part = formAnchorInfo.addPart(formPart.getFormPartName(), formPart.getMarkupId(), formPart.getSize().height);
            if (Part.getDisplayName(Part.BODY).equals(formPart.getFormPartName())) {
                Component parent = formPart.getParent();
                formAnchorInfo.bodyContainerId = parent.getMarkupId();
            }
            formPart.visitChildren(ISupportWebBounds.class, new IVisitor() {

                public Object component(Component comp) {
                    String id = comp.getId();
                    ISupportAnchors obj = elements.get(id);
                    if (obj != null) {
                        int anchors = obj.getAnchors();
                        if (((anchors > 0 && anchors != IAnchorConstants.DEFAULT)) || (comp instanceof WebTabPanel) || (comp instanceof IButton)) {
                            Rectangle r = ((ISupportWebBounds) comp).getWebBounds();
                            if (r != null) {
                                if (anchors == 0)
                                    anchors = IAnchorConstants.DEFAULT;
                                int hAlign = -1;
                                int vAlign = -1;
                                if (obj instanceof ISupportTextSetup) {
                                    ISupportTextSetup alignedObj = (ISupportTextSetup) obj;
                                    hAlign = alignedObj.getHorizontalAlignment();
                                    vAlign = alignedObj.getVerticalAlignment();
                                }
                                String imageDisplayURL = null;
                                boolean isRandomParamRemoved = false;
                                if (comp instanceof IImageDisplay) {
                                    Object[] aImageDisplayURL = WebBaseButton.getImageDisplayURL((IImageDisplay) comp, false);
                                    imageDisplayURL = (String) aImageDisplayURL[0];
                                    isRandomParamRemoved = ((Boolean) aImageDisplayURL[1]).booleanValue();
                                }
                                part.addAnchoredElement(comp.getMarkupId(), anchors, r, hAlign, vAlign, comp.getClass(), imageDisplayURL, isRandomParamRemoved);
                            }
                        }
                    }
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
        }
    });
    return formAnchorInfo;
}
Also used : FormPartAnchorInfo(com.servoy.j2db.server.headlessclient.FormAnchorInfo.FormPartAnchorInfo) WebDataRenderer(com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer) HashMap(java.util.HashMap) WeakHashMap(java.util.WeakHashMap) IImageDisplay(com.servoy.j2db.server.headlessclient.dataui.IImageDisplay) ISupportTextSetup(com.servoy.j2db.persistence.ISupportTextSetup) Rectangle(java.awt.Rectangle) ISupportBounds(com.servoy.j2db.persistence.ISupportBounds) WebCellBasedView(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView) Point(java.awt.Point) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) ISupportWebBounds(com.servoy.j2db.ui.ISupportWebBounds) IPersist(com.servoy.j2db.persistence.IPersist) WebDefaultRecordNavigator(com.servoy.j2db.server.headlessclient.dataui.WebDefaultRecordNavigator) IButton(com.servoy.j2db.ui.IButton) WebTabPanel(com.servoy.j2db.server.headlessclient.dataui.WebTabPanel) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) ScriptableObject(org.mozilla.javascript.ScriptableObject) 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)

Example 3 with ISupportWebBounds

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

the class WebAnchoringHelper method getWrapperComponent.

public static Component getWrapperComponent(Component comp, IFormElement obj, int start, Dimension panelSize, boolean leftToRight, boolean isInListView) {
    MarkupContainer compWrapper = new WrapperContainer(ComponentFactory.getWebID(null, obj) + TemplateGenerator.WRAPPER_SUFFIX, comp);
    Point l = (obj).getLocation();
    if (isInListView) {
        // substract left indicator
        l.x = Math.max(l.x - 3, 0);
    }
    Dimension s = (obj).getSize();
    int anchors = 0;
    if (obj instanceof ISupportAnchors)
        anchors = ((ISupportAnchors) obj).getAnchors();
    int offsetWidth = s.width;
    int offsetHeight = s.height;
    if (comp instanceof ISupportWebBounds) {
        Rectangle b = ((ISupportWebBounds) comp).getWebBounds();
        offsetWidth = b.width;
        offsetHeight = b.height;
    }
    final String styleToReturn = WebAnchoringHelper.computeWrapperDivStyle(l.y, l.x, offsetWidth, offsetHeight, s.width, s.height, anchors, start, start + panelSize.height, panelSize.width, leftToRight);
    // first the default
    compWrapper.add(new StyleAppendingModifier(new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            return styleToReturn;
        }
    }));
    // then the style t hat can be set on the wrapped component
    compWrapper.add(StyleAttributeModifierModel.INSTANCE);
    // TODO: this needs to be done in a cleaner way. See what is the relation between
    // margin, padding and border when calculating the websize in ChangesRecorder vs. TemplateGenerator.
    // Looks like one of the three is not taken into account during calculations. For now decided to remove
    // the margin and leave the padding and border.
    comp.add(new StyleAppendingModifier(new AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            // $NON-NLS-1$
            return "margin: 0px;";
        }
    }));
    return compWrapper;
}
Also used : WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) MarkupContainer(org.apache.wicket.MarkupContainer) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) ISupportWebBounds(com.servoy.j2db.ui.ISupportWebBounds) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 4 with ISupportWebBounds

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

ISupportWebBounds (com.servoy.j2db.ui.ISupportWebBounds)4 Point (java.awt.Point)4 IComponent (com.servoy.j2db.ui.IComponent)3 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)3 Component (org.apache.wicket.Component)3 MarkupContainer (org.apache.wicket.MarkupContainer)3 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)2 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)2 WebDataRenderer (com.servoy.j2db.server.headlessclient.dataui.WebDataRenderer)2 IRuntimeInputComponent (com.servoy.j2db.ui.runtime.IRuntimeInputComponent)2 Insets (java.awt.Insets)2 Rectangle (java.awt.Rectangle)2 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1 IPersist (com.servoy.j2db.persistence.IPersist)1 ISupportBounds (com.servoy.j2db.persistence.ISupportBounds)1 ISupportTextSetup (com.servoy.j2db.persistence.ISupportTextSetup)1 FormPartAnchorInfo (com.servoy.j2db.server.headlessclient.FormAnchorInfo.FormPartAnchorInfo)1 WrapperContainer (com.servoy.j2db.server.headlessclient.WrapperContainer)1 IImageDisplay (com.servoy.j2db.server.headlessclient.dataui.IImageDisplay)1 WebCellBasedView (com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView)1