Search in sources :

Example 1 with IComponent

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

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

the class DesignModeBehavior method getJSEvent.

private JSEvent getJSEvent(EventType type, int modifiers, Point point, IComponent[] selected) {
    JSEvent event = new JSEvent();
    event.setFormName(controller.getName());
    event.setType(type);
    event.setModifiers(modifiers);
    event.setLocation(point);
    List<Object> selection = new ArrayList<Object>();
    if (selected != null) {
        for (IComponent component : selected) {
            if (component instanceof IScriptableProvider) {
                selection.add(0, ((IScriptableProvider) component).getScriptObject());
            } else {
                selection.add(0, component);
            }
        }
    }
    event.setData(selection.toArray());
    // event.setSource(e)
    return event;
}
Also used : JSEvent(com.servoy.j2db.scripting.JSEvent) IComponent(com.servoy.j2db.ui.IComponent) ArrayList(java.util.ArrayList) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 3 with IComponent

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

the class ScrollResponseHeaderContainer method createScriptEvent.

public JSDNDEvent createScriptEvent(EventType type, IComponent dragSource, Point xy, int modifiers) {
    JSDNDEvent jsEvent = new JSDNDEvent();
    jsEvent.setType(type);
    jsEvent.setFormName(getDragFormName());
    if (dragSource instanceof IDataRenderer) {
        IDataRenderer dr = (IDataRenderer) dragSource;
        FormController fct = dr.getDataAdapterList().getFormController();
        jsEvent.setSource(fct.getFormScope());
    } else {
        jsEvent.setSource(dragSource);
        if (dragSource != null) {
            if (dragSource instanceof Component) {
                WebCellBasedViewListItem listItem = ((Component) dragSource).findParent(WebCellBasedViewListItem.class);
                if (listItem != null) {
                    IRecordInternal dragRecord = listItem.getModelObject();
                    if (dragRecord instanceof Record)
                        jsEvent.setRecord((Record) dragRecord);
                }
            }
            String dragSourceName = dragSource.getName();
            if (dragSourceName == null)
                dragSourceName = dragSource.getId();
            jsEvent.setElementName(dragSourceName);
        }
    }
    if (xy != null)
        jsEvent.setLocation(xy);
    jsEvent.setModifiers(modifiers);
    return jsEvent;
}
Also used : FormController(com.servoy.j2db.FormController) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) JSDNDEvent(com.servoy.j2db.dnd.JSDNDEvent) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) Record(com.servoy.j2db.dataprocessing.Record) 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)

Example 4 with IComponent

use of com.servoy.j2db.ui.IComponent 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 5 with IComponent

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

the class ScrollResponseHeaderContainer method createComponents.

private void createComponents(final IApplication app, final Form form, final AbstractBase view, final IDataProviderLookup dataProviderLookup, final IScriptExecuter el, final int viewStartY, final int viewEndY, final ItemAdd output) {
    List<IPersist> elements = ComponentFactory.sortElementsOnPositionAndGroup(view.getAllObjectsAsList());
    int startX = 0;
    for (int i = 0; i < elements.size(); i++) {
        IPersist element = elements.get(i);
        if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
            if (!isListViewMode()) {
                if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
                    if (isInView(cellview, ((GraphicalComponent) element).getLabelFor())) {
                        labelsFor.put(((GraphicalComponent) element).getLabelFor(), element);
                    }
                    continue;
                }
            }
            Point l = ((IFormElement) element).getLocation();
            if (l == null) {
                // unknown where to add
                continue;
            }
            if (l.y >= viewStartY && l.y < viewEndY) {
                IComponent c = ComponentFactory.createComponent(app, form, element, dataProviderLookup, el, false);
                if (cellview instanceof Portal && c instanceof IScriptableProvider) {
                    IScriptable s = ((IScriptableProvider) c).getScriptObject();
                    if (s instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) s).getRenderEventExecutor() != null)
                        ComponentFactoryHelper.addPortalOnRenderCallback((Portal) cellview, ((ISupportOnRenderCallback) s).getRenderEventExecutor(), element, fc != null ? fc.getScriptExecuter() : null);
                }
                initializeComponent((Component) c, view, element);
                output.add(element, (Component) c);
                if (!isListViewMode()) {
                    // reset location.x as defined in this order, elements are ordered by location.x which is modified in drag-n-drop
                    Point loc = c.getLocation();
                    if (loc != null) {
                        c.setLocation(new Point(startX, loc.y));
                    }
                    Dimension csize = c.getSize();
                    startX += (csize != null) ? csize.width : ((IFormElement) element).getSize().width;
                }
            }
        }
    }
}
Also used : IComponent(com.servoy.j2db.ui.IComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) Point(java.awt.Point) Dimension(java.awt.Dimension) Point(java.awt.Point) IScriptable(com.servoy.j2db.scripting.IScriptable) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Bean(com.servoy.j2db.persistence.Bean) Field(com.servoy.j2db.persistence.Field) IFormElement(com.servoy.j2db.persistence.IFormElement) IPersist(com.servoy.j2db.persistence.IPersist) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Aggregations

IComponent (com.servoy.j2db.ui.IComponent)34 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)17 Point (java.awt.Point)16 Component (org.apache.wicket.Component)14 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)13 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)12 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)12 BaseComponent (com.servoy.j2db.persistence.BaseComponent)10 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)8 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)7 Component (java.awt.Component)7 JComponent (javax.swing.JComponent)7 IPersist (com.servoy.j2db.persistence.IPersist)6 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)6 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)6 IScriptable (com.servoy.j2db.scripting.IScriptable)4 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)4 ITabPanel (com.servoy.j2db.ui.ITabPanel)4 Dimension (java.awt.Dimension)4 MarkupContainer (org.apache.wicket.MarkupContainer)4