Search in sources :

Example 1 with IScriptableProvider

use of com.servoy.j2db.scripting.IScriptableProvider 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 IScriptableProvider

use of com.servoy.j2db.scripting.IScriptableProvider 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 IScriptableProvider

use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.

the class WebCellAdapter method valueChanged.

public void valueChanged(ModificationEvent e) {
    MainPage mp = view.findParent(MainPage.class);
    if (mp != null)
        mp.touch();
    IRecord record = e.getRecord();
    Iterator iterator = ((MarkupContainer) view.getTable()).iterator();
    while (iterator.hasNext()) {
        Object next = iterator.next();
        if (next instanceof ListItem) {
            ListItem li = (ListItem) next;
            Object modelObject = li.getModelObject();
            if (record == null || modelObject == record) {
                boolean hasOnRender = false;
                Iterator iterator2 = li.iterator();
                while (iterator2.hasNext()) {
                    ArrayList<Object> cellDisplays = new ArrayList<Object>();
                    Object cell = iterator2.next();
                    cell = CellContainer.getContentsForCell((Component) cell);
                    if (cell instanceof WebCellBasedViewListViewItem) {
                        Iterator listItemIte = ((WebCellBasedViewListViewItem) cell).iterator();
                        while (listItemIte.hasNext()) {
                            Object listItemDisplay = listItemIte.next();
                            if (listItemDisplay instanceof WrapperContainer) {
                                listItemDisplay = ((WrapperContainer) listItemDisplay).getDelegate();
                            }
                            cellDisplays.add(listItemDisplay);
                        }
                    } else {
                        cellDisplays.add(cell);
                    }
                    for (Object cellDisplay : cellDisplays) {
                        if (cellDisplay instanceof IProviderStylePropertyChanges && cellDisplay instanceof IDisplayData && ((IDisplayData) cellDisplay).getDataProviderID() == dataprovider) {
                            // only test if it is not already changed
                            view.checkForValueChanges(cellDisplay);
                            // do fire on render on all components for record change
                            if (cellDisplay instanceof ISupportOnRender && cellDisplay instanceof IScriptableProvider) {
                                IScriptable so = ((IScriptableProvider) cellDisplay).getScriptObject();
                                if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
                                    String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
                                    if (record != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
                                        ((ISupportOnRender) cellDisplay).fireOnRender(true);
                                        hasOnRender = true;
                                    }
                                }
                            }
                        }
                    }
                }
                if (record != null || (!hasOnRender && !canChangeValue(e)))
                    break;
            }
        }
    }
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) ISupportOnRender(com.servoy.j2db.ui.ISupportOnRender) IRecord(com.servoy.j2db.dataprocessing.IRecord) ArrayList(java.util.ArrayList) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) WebCellBasedViewListViewItem(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.WebCellBasedViewListViewItem) IScriptable(com.servoy.j2db.scripting.IScriptable) WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) Iterator(java.util.Iterator) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) ListItem(org.apache.wicket.markup.html.list.ListItem) Component(org.apache.wicket.Component) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 4 with IScriptableProvider

use of com.servoy.j2db.scripting.IScriptableProvider 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 IScriptableProvider

use of com.servoy.j2db.scripting.IScriptableProvider 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

IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)35 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)21 IComponent (com.servoy.j2db.ui.IComponent)20 IScriptable (com.servoy.j2db.scripting.IScriptable)18 Point (java.awt.Point)14 Component (org.apache.wicket.Component)13 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)11 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)11 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)9 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)8 JComponent (javax.swing.JComponent)8 BaseComponent (com.servoy.j2db.persistence.BaseComponent)7 AbstractRuntimeBaseComponent (com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent)7 IPortalComponent (com.servoy.j2db.ui.IPortalComponent)6 RenderEventExecutor (com.servoy.j2db.ui.RenderEventExecutor)6 Component (java.awt.Component)6 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)5 IPersist (com.servoy.j2db.persistence.IPersist)5 EventObject (java.util.EventObject)5 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)4