Search in sources :

Example 1 with Bean

use of com.servoy.j2db.persistence.Bean 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)

Example 2 with Bean

use of com.servoy.j2db.persistence.Bean in project servoy-client by Servoy.

the class WebDataRendererFactory method placeElements.

protected Map placeElements(IApplication app, Form form, IScriptExecuter listener, Map emptyDataRenderers, boolean printing, ControllerUndoManager undoManager, TabSequenceHelper<Component> tabSequence) throws Exception {
    // $NON-NLS-1$
    final boolean useAJAX = Utils.getAsBoolean(app.getRuntimeProperties().get("useAJAX"));
    IDataProviderLookup dataProviderLookup = app.getFlattenedSolution().getDataproviderLookup(app.getFoundSetManager(), form);
    Map listTocomplete = new HashMap();
    Map labelForComponents = new HashMap();
    String orientation = OrientationApplier.getHTMLContainerOrientation(app.getLocale(), app.getSolution().getTextOrientation());
    // $NON-NLS-1$
    boolean leftToRight = !"rtl".equalsIgnoreCase(orientation);
    // $NON-NLS-1$
    boolean isAnchoringEnabled = Utils.getAsBoolean(app.getRuntimeProperties().get("enableAnchors"));
    // Insets insets = new Insets(0, 0, 0, 0);
    for (IFormElement obj : Utils.iterate(form.getFormElementsSortedByFormIndex())) {
        Point l = null;
        l = (obj).getLocation();
        // unknown where to add
        if (l == null)
            continue;
        if (printing && obj instanceof ISupportPrinting) {
            if (!((ISupportPrinting) obj).getPrintable())
                continue;
        }
        Iterator it = emptyDataRenderers.values().iterator();
        while (it.hasNext()) {
            WebDataRenderer panel = (WebDataRenderer) it.next();
            // Border border = panel.getBorder();
            // if (border instanceof EmptyBorder)
            // {
            // insets = ((EmptyBorder)border).getBorderInsets();
            // }
            int start = panel.getLocation().y;
            if (l.y >= start && l.y < start + panel.getSize().height) {
                org.apache.wicket.Component comp = (org.apache.wicket.Component) ComponentFactory.createComponent(app, form, obj, dataProviderLookup, listener, printing);
                if (comp != null) {
                    if (obj instanceof Field) {
                        String name = ((Field) obj).getName();
                        if (name != null && !"".equals(name)) {
                            labelForComponents.put(name, comp);
                        }
                    } else if (obj instanceof GraphicalComponent && (comp instanceof WebBaseLabel || comp instanceof WebBaseSubmitLink)) {
                        String labelFor = ((GraphicalComponent) obj).getLabelFor();
                        if (labelFor != null && !"".equals(labelFor)) {
                            labelForComponents.put(comp, labelFor);
                        }
                    }
                    if ((obj instanceof ISupportTabSeq) && (tabSequence != null)) {
                        tabSequence.add(panel, (ISupportTabSeq) obj, comp);
                    }
                    org.apache.wicket.Component newComp = comp;
                    if (newComp instanceof IDisplay) {
                        panel.addDisplayComponent(obj, (IDisplay) newComp);
                    } else if (newComp instanceof WebImageBeanHolder) {
                        WebImageBeanHolder wiBeanHolder = (WebImageBeanHolder) newComp;
                        Object bean = wiBeanHolder.getDelegate();
                        if (bean instanceof IServoyAwareBean) {
                            IServoyAwareBean ourBean = (IServoyAwareBean) bean;
                            panel.addDisplayComponent(obj, ourBean);
                        }
                    }
                    ((IComponent) comp).setLocation(new Point((l.x), (l.y - start)));
                    if (form.getOnRecordEditStartMethodID() > 0 && comp instanceof IFieldComponent) {
                        if (useAJAX && comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null && !ScopesUtils.isVariableScope(((IDisplayData) comp).getDataProviderID())) {
                            StartEditOnFocusGainedEventBehavior.addNewBehaviour(comp);
                        }
                    }
                    // - beans
                    if (isAnchoringEnabled && (((obj instanceof Field) && WebAnchoringHelper.needsWrapperDivForAnchoring((Field) obj)) || (obj instanceof Bean) || ((obj instanceof GraphicalComponent) && ComponentFactory.isButton((GraphicalComponent) obj)))) {
                        panel.add(WebAnchoringHelper.getWrapperComponent(comp, obj, start, panel.getSize(), leftToRight, false));
                    } else {
                        panel.add(comp);
                    }
                }
            }
        }
    }
    Iterator it = labelForComponents.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Entry) it.next();
        Object key = entry.getKey();
        if (key instanceof WebBaseLabel || key instanceof WebBaseSubmitLink) {
            IFieldComponent component = (IFieldComponent) labelForComponents.get(entry.getValue());
            if (component != null) {
                if (key instanceof WebBaseLabel) {
                    ((WebBaseLabel) entry.getKey()).setLabelFor(component);
                } else {
                    ((WebBaseSubmitLink) entry.getKey()).setLabelFor(component);
                }
                (component).addLabelFor((ILabel) entry.getKey());
                if (!component.isVisible()) {
                    component.setComponentVisible(component.isVisible());
                }
                if (!component.isEnabled()) {
                    component.setComponentEnabled(component.isEnabled());
                }
            }
        }
    }
    it = emptyDataRenderers.values().iterator();
    while (it.hasNext()) {
        WebDataRenderer panel = (WebDataRenderer) it.next();
        panel.createDataAdapter(app, dataProviderLookup, listener, undoManager);
    }
    return listTocomplete;
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) IComponent(com.servoy.j2db.ui.IComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportTabSeq(com.servoy.j2db.persistence.ISupportTabSeq) Bean(com.servoy.j2db.persistence.Bean) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Field(com.servoy.j2db.persistence.Field) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) ISupportPrinting(com.servoy.j2db.persistence.ISupportPrinting) Component(org.apache.wicket.Component) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) Point(java.awt.Point) Point(java.awt.Point) IFormElement(com.servoy.j2db.persistence.IFormElement) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) HashMap(java.util.HashMap) Map(java.util.Map) IDataProviderLookup(com.servoy.j2db.persistence.IDataProviderLookup)

Example 3 with Bean

use of com.servoy.j2db.persistence.Bean in project servoy-client by Servoy.

the class ComponentFactory method createComponentEx.

protected static IComponent createComponentEx(IApplication application, Form form, IPersist meta, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
    IComponent comp = null;
    switch(meta.getTypeID()) {
        case IRepository.FIELDS:
            comp = createField(application, form, (Field) meta, dataProviderLookup, el, printing);
            break;
        case IRepository.GRAPHICALCOMPONENTS:
            comp = createGraphicalComponent(application, form, (GraphicalComponent) meta, el, dataProviderLookup);
            break;
        case IRepository.RECTSHAPES:
            comp = createRectangle(application, form, (RectShape) meta);
            break;
        case IRepository.PORTALS:
            comp = createPortal(application, form, (Portal) meta, dataProviderLookup, el, printing);
            break;
        case IRepository.PARTS:
            comp = createPart(application, (Part) meta);
            break;
        case IRepository.TABPANELS:
            TabPanel tabPanelMeta = (TabPanel) meta;
            int orient = tabPanelMeta.getTabOrientation();
            if (orient == TabPanel.SPLIT_HORIZONTAL || orient == TabPanel.SPLIT_VERTICAL)
                comp = createSplitPane(application, form, tabPanelMeta, el);
            else
                comp = createTabPanel(application, form, tabPanelMeta, el);
            break;
        case IRepository.BEANS:
            comp = createBean(application, form, (Bean) meta, null);
            break;
        case IRepository.WEBCOMPONENTS:
            comp = createWebComponentPlaceholder(application, form, (WebComponent) meta);
            break;
        default:
            Debug.error("ComponentFactory:unkown type " + meta.getTypeID() + ", uuid: " + meta.getUUID() + ", parent:" + meta.getParent());
            IStandardLabel label = application.getItemFactory().createLabel(getWebID(form, meta), "ComponentFactory:unkown type " + meta.getTypeID());
            label.setSize(new Dimension(200, 20));
            comp = label;
    }
    if (comp instanceof JComponent) {
        ((JComponent) comp).putClientProperty("Id", ComponentFactory.getWebID(form, meta));
    }
    return comp;
}
Also used : ITabPanel(com.servoy.j2db.ui.ITabPanel) TabPanel(com.servoy.j2db.persistence.TabPanel) RuntimeTabPanel(com.servoy.j2db.ui.scripting.RuntimeTabPanel) RectShape(com.servoy.j2db.persistence.RectShape) IComponent(com.servoy.j2db.ui.IComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension) IStandardLabel(com.servoy.j2db.ui.IStandardLabel) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) Bean(com.servoy.j2db.persistence.Bean) RuntimeMediaField(com.servoy.j2db.ui.scripting.RuntimeMediaField) RuntimeDataLookupField(com.servoy.j2db.ui.scripting.RuntimeDataLookupField) Field(com.servoy.j2db.persistence.Field) RuntimeDataField(com.servoy.j2db.ui.scripting.RuntimeDataField) AbstractRuntimeField(com.servoy.j2db.ui.scripting.AbstractRuntimeField) WebComponent(com.servoy.j2db.persistence.WebComponent) Part(com.servoy.j2db.persistence.Part) Portal(com.servoy.j2db.persistence.Portal) RuntimePortal(com.servoy.j2db.ui.scripting.RuntimePortal)

Example 4 with Bean

use of com.servoy.j2db.persistence.Bean in project servoy-client by Servoy.

the class JSForm method newBean.

/**
 * Creates a new JSBean object on the form - including the name of the JSBean object; the classname the JSBean object is based on, the "x" and "y" position of the JSBean object in pixels, as well as the width and height of the JSBean object in pixels.
 *
 * @sample
 * var form = solutionModel.newForm('newForm1', 'db:/server1/table1', null, true, 800, 600);
 * var bean = form.newBean('bean','com.servoy.extensions.beans.dbtreeview.DBTreeView',200,200,300,300);
 * forms['newForm1'].controller.show();
 *
 * @param name the specified name of the JSBean object
 * @param className the class name of the JSBean object
 * @param x the horizontal "x" position of the JSBean object in pixels
 * @param y the vertical "y" position of the JSBean object in pixels
 * @param width the width of the JSBean object in pixels
 * @param height the height of the JSBean object in pixels
 *
 * @return a JSBean object
 */
@JSFunction
public JSBean newBean(String name, String className, int x, int y, int width, int height) {
    checkModification();
    try {
        Bean bean = getContainer().createNewBean(IdentDocumentValidator.checkName(name), className);
        bean.setSize(new Dimension(width, height));
        bean.setLocation(new Point(x, y));
        return new JSBean(this, bean, true);
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : RepositoryException(com.servoy.j2db.persistence.RepositoryException) Dimension(java.awt.Dimension) Point(java.awt.Point) Bean(com.servoy.j2db.persistence.Bean) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 5 with Bean

use of com.servoy.j2db.persistence.Bean in project servoy-client by Servoy.

the class JSForm method removeBean.

/**
 * Removes a JSBean that has the specified name. Returns true if removal was successful, false otherwise.
 *
 * @sample
 * var form = solutionModel.getForm('myform');
 * form.removeBean('mybean')
 *
 * @param name the specified name of the JSBean to be removed
 *
 * @return true if the JSBean has been removed; false otherwise
 */
@ServoyClientSupport(mc = true, ng = true, wc = true, sc = true)
@JSFunction
public boolean removeBean(String name) {
    if (name == null)
        return false;
    checkModification();
    Iterator<Bean> beans = getContainer().getBeans();
    while (beans.hasNext()) {
        Bean bean = beans.next();
        if (name.equals(bean.getName())) {
            getContainer().removeChild(bean);
            return true;
        }
    }
    return false;
}
Also used : Bean(com.servoy.j2db.persistence.Bean) JSFunction(org.mozilla.javascript.annotations.JSFunction) ServoyClientSupport(com.servoy.base.scripting.annotations.ServoyClientSupport)

Aggregations

Bean (com.servoy.j2db.persistence.Bean)8 Field (com.servoy.j2db.persistence.Field)5 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)5 Dimension (java.awt.Dimension)4 Point (java.awt.Point)4 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)3 IFormElement (com.servoy.j2db.persistence.IFormElement)3 IPersist (com.servoy.j2db.persistence.IPersist)3 Portal (com.servoy.j2db.persistence.Portal)3 IComponent (com.servoy.j2db.ui.IComponent)3 JSFunction (org.mozilla.javascript.annotations.JSFunction)3 ISupportName (com.servoy.j2db.persistence.ISupportName)2 Part (com.servoy.j2db.persistence.Part)2 RuntimePortal (com.servoy.j2db.ui.scripting.RuntimePortal)2 HashMap (java.util.HashMap)2 ServoyClientSupport (com.servoy.base.scripting.annotations.ServoyClientSupport)1 IForm (com.servoy.j2db.IForm)1 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)1 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)1 AbstractBase (com.servoy.j2db.persistence.AbstractBase)1