Search in sources :

Example 1 with GraphicalComponent

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

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

the class SortableCellViewHeader method setWidth.

public void setWidth(int width) {
    int borderWidth = 0;
    Iterator<IPersist> it2 = cellview.getAllObjects();
    while (it2.hasNext()) {
        IPersist element = it2.next();
        if (id.equals(ComponentFactory.getWebID(form, element))) {
            GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
            if (gc != null) {
                TextualStyle styleObj = new TextualStyle();
                BorderAndPadding ins = TemplateGenerator.applyBaseComponentProperties(gc, view.fc.getForm(), styleObj, (Insets) TemplateGenerator.DEFAULT_LABEL_PADDING.clone(), null, application);
                if (ins.border != null)
                    borderWidth = ins.border.left + ins.border.right;
            }
        }
    }
    int headerPadding = TemplateGenerator.SORTABLE_HEADER_PADDING;
    // If there is no label-for, we leave place for the default border placed at the right of headers.
    if (view.labelsFor.size() == 0) {
        int extraWidth = TemplateGenerator.NO_LABELFOR_DEFAULT_BORDER_WIDTH;
        String headerBorder = view.getHeaderBorder();
        if (headerBorder != null) {
            Properties properties = new Properties();
            Insets borderIns = ComponentFactoryHelper.createBorderCSSProperties(headerBorder, properties);
            extraWidth = borderIns.left + borderIns.right;
            headerPadding = 0;
        }
        borderWidth += extraWidth;
    }
    // we have only left padding
    int clientWidth = width - headerPadding - borderWidth;
    // if we have grid_style for the header, then don't change the header width
    this.width = (view.labelsFor.size() == 0 && view.getHeaderBorder() != null) ? width : clientWidth;
    StyleAppendingModifier widthStyleModifier = new StyleAppendingModifier(new Model<String>() {

        @Override
        public String getObject() {
            // $NON-NLS-1$//$NON-NLS-2$
            return "width: " + SortableCellViewHeader.this.width + "px";
        }
    });
    add(widthStyleModifier);
    headerColumnTable.add(widthStyleModifier);
    labelResolver.setWidth(clientWidth - SortableCellViewHeader.ARROW_WIDTH);
    getStylePropertyChanges().setChanged();
}
Also used : Insets(java.awt.Insets) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) ISupportName(com.servoy.j2db.persistence.ISupportName) BorderAndPadding(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.BorderAndPadding) Properties(java.util.Properties) TextualStyle(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle) IPersist(com.servoy.j2db.persistence.IPersist)

Example 3 with GraphicalComponent

use of com.servoy.j2db.persistence.GraphicalComponent 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 4 with GraphicalComponent

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

the class EventCallTest method fillTestSolution.

@Override
protected void fillTestSolution() throws ServoyException {
    Form form = solution.createNewForm(validator, null, "test", null, false, new Dimension(600, 400));
    form.setNavigatorID(-1);
    form.createNewScriptVariable(DummyValidator.INSTANCE, "testVar", IColumnTypes.INTEGER);
    GraphicalComponent button = form.createNewGraphicalComponent(new Point(10, 10));
    button.setShowClick(true);
    button.setShowFocus(true);
    ScriptMethod sm = form.createNewScriptMethod(DummyValidator.INSTANCE, "test");
    sm.setDeclaration("function test() {testVar = 10}");
    button.setOnActionMethodID(sm.getID());
    form.createNewScriptVariable(DummyValidator.INSTANCE, "testVar2", IColumnTypes.TEXT);
    GraphicalComponent button2 = form.createNewGraphicalComponent(new Point(10, 10));
    button2.setName(uuid);
    button2.setShowClick(true);
    button2.setShowFocus(true);
    ScriptMethod sm2 = form.createNewScriptMethod(DummyValidator.INSTANCE, "test2");
    sm2.setDeclaration("function test2() {testVar2 = elements['" + uuid + "'].getName()}");
    button2.setOnActionMethodID(sm2.getID());
}
Also used : Form(com.servoy.j2db.persistence.Form) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) Dimension(java.awt.Dimension) Point(java.awt.Point) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Example 5 with GraphicalComponent

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

Aggregations

GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)27 Point (java.awt.Point)14 IPersist (com.servoy.j2db.persistence.IPersist)10 JSFunction (org.mozilla.javascript.annotations.JSFunction)10 Field (com.servoy.j2db.persistence.Field)7 IFormElement (com.servoy.j2db.persistence.IFormElement)6 Part (com.servoy.j2db.persistence.Part)6 RepositoryException (com.servoy.j2db.persistence.RepositoryException)6 Dimension (java.awt.Dimension)6 ArrayList (java.util.ArrayList)6 Bean (com.servoy.j2db.persistence.Bean)5 Form (com.servoy.j2db.persistence.Form)4 ISupportName (com.servoy.j2db.persistence.ISupportName)4 Portal (com.servoy.j2db.persistence.Portal)4 HashMap (java.util.HashMap)4 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)3 BaseComponent (com.servoy.j2db.persistence.BaseComponent)3 IComponent (com.servoy.j2db.ui.IComponent)3 ServoyClientSupport (com.servoy.base.scripting.annotations.ServoyClientSupport)2 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)2