Search in sources :

Example 6 with WebFormComponent

use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.

the class ValueListTypeSabloValue method filterValuelist.

/**
 * Filters the values of the valuelist for type-ahead-like usage.
 */
private void filterValuelist(JSONObject newJSONValue) {
    if (!initialized) {
        Debug.warn("Trying to send to client an uninitialized valuelist property: " + vlPD + " of " + webObjectContext);
        return;
    }
    this.valuesRequested = true;
    this.handledIDForResponse = Long.valueOf(newJSONValue.getLong(ID_KEY));
    String filterString = newJSONValue.optString(FILTER);
    if (filteredValuelist == null) {
        filteredValuelist = createFilteredValueList();
        if (filteredValuelist != null) {
            filteredValuelist.addListDataListener(new ListDataListener() {

                @Override
                public void intervalRemoved(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }

                @Override
                public void intervalAdded(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }

                @Override
                public void contentsChanged(ListDataEvent e) {
                    changeMonitor.markFullyChanged(true);
                }
            });
        }
    }
    if (filteredValuelist != null) {
        try {
            valueList.removeListDataListener(this);
            Object realValue = dataAdapterListToUse.getValueObject(dataAdapterListToUse.getRecord(), dataproviderID);
            // do mark it as changed but don't notify yet (false arg) because fill below will probably trigger listener above and notify anyway; that would mean that although
            // we do call notify after fill that is likely to end up in a NO_OP changesToJSON in case of foundset-linked valuelist properties
            changeMonitor.markFullyChanged(false);
            boolean useContains = Utils.getAsBoolean(dataAdapterListToUse.getApplication().getClientProperty(IApplication.VALUELIST_CONTAINS_SEARCH));
            if (!useContains && webObjectContext != null && webObjectContext.getUnderlyingWebObject() instanceof WebFormComponent) {
                WebFormComponent webObject = (WebFormComponent) webObjectContext.getUnderlyingWebObject();
                RuntimeWebComponent webComponentElement = dataAdapterListToUse.getForm().getWebComponentElement(webObject.getFormElement().getRawName());
                if (webComponentElement != null && webComponentElement.getPrototype() instanceof RuntimeLegacyComponent) {
                    RuntimeLegacyComponent legacy = (RuntimeLegacyComponent) webComponentElement.getPrototype();
                    useContains = Utils.getAsBoolean(legacy.getClientProperty(IApplication.VALUELIST_CONTAINS_SEARCH, legacy));
                }
            }
            if (useContains && filterString != null)
                filterString = '%' + filterString;
            filteredValuelist.fill(dataAdapterListToUse.getRecord(), dataproviderID, filterString, realValue, false);
            // in case fill really somehow did not result in the filteredValuelist listener doing a notify
            changeMonitor.notifyOfChange();
            valueList.addListDataListener(this);
        } catch (ServoyException e) {
            Debug.error(e);
        }
    }
}
Also used : ListDataEvent(javax.swing.event.ListDataEvent) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) JSONObject(org.json.JSONObject) RuntimeLegacyComponent(com.servoy.j2db.server.ngclient.component.RuntimeLegacyComponent) ListDataListener(javax.swing.event.ListDataListener) RuntimeWebComponent(com.servoy.j2db.server.ngclient.component.RuntimeWebComponent) ServoyException(com.servoy.j2db.util.ServoyException)

Example 7 with WebFormComponent

use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.

the class RuntimeWebGroup method setLocation.

private void setLocation(int x, int y) {
    Rectangle bounds = getBounds();
    int dx = x - bounds.x;
    int dy = y - bounds.y;
    for (RuntimeWebComponent obj : runtimeWebComponents) {
        WebFormComponent component = obj.getComponent();
        Point location = (Point) component.getProperty("location");
        putProperty("location", new Object[] { location.x + dx, location.y + dy }, component);
    }
}
Also used : WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Point(java.awt.Point)

Example 8 with WebFormComponent

use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.

the class RuntimeWebGroup method setSize.

private void setSize(int width, int height) {
    Rectangle bounds = getBounds();
    float scalew = ((float) width) / bounds.width;
    float scaleh = ((float) height) / bounds.height;
    for (RuntimeWebComponent obj : runtimeWebComponents) {
        WebFormComponent component = obj.getComponent();
        Point location = (Point) component.getProperty("location");
        putProperty("location", new Object[] { bounds.x + (int) Math.floor(scalew * (location.x - bounds.x)), bounds.y + (int) Math.floor(scaleh * (location.y - bounds.y)) }, component);
        Dimension size = (Dimension) component.getProperty("size");
        putProperty("size", new Object[] { (int) Math.floor(scalew * size.width), (int) Math.floor(scaleh * size.height) }, component);
    }
}
Also used : WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Dimension(java.awt.Dimension)

Example 9 with WebFormComponent

use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.

the class WebFormController method notifyVisible.

@Override
public boolean notifyVisible(boolean visible, List<Runnable> invokeLaterRunnables) {
    if (isFormVisible == visible)
        return true;
    if (!visible && destroyOnHide) {
        Runnable run = new Runnable() {

            public void run() {
                destroy();
            }
        };
        invokeLaterRunnables.add(run);
    }
    boolean notifyVisibleSuccess = super.notifyVisible(visible, invokeLaterRunnables);
    if (notifyVisibleSuccess) {
        for (WebComponent comp : getFormUI().getComponents()) {
            RuntimeWebComponent runtimeComponent = getFormUI().getRuntimeWebComponent(comp.getName());
            if (runtimeComponent != null) {
                WebObjectFunctionDefinition function = null;
                if (visible)
                    function = comp.getSpecification().getInternalApiFunction("onShow");
                else
                    function = comp.getSpecification().getInternalApiFunction("onHide");
                if (function != null) {
                    runtimeComponent.executeScopeFunction(function, new Object[0]);
                }
            }
        }
    }
    if (visible && !isFormVisible) {
        // note: the show operation (visible = true in if above) of a form cannot be denied, so we can update things before the call to super.notifyVisible below
        for (WebComponent comp : getFormUI().getComponents()) {
            if ((comp instanceof WebFormComponent) && ((WebFormComponent) comp).getFormElement().getPersistIfAvailable() instanceof TabPanel) {
                Object visibleTabPanel = comp.getProperty("visible");
                if (visibleTabPanel instanceof Boolean && !((Boolean) visibleTabPanel).booleanValue())
                    continue;
                Object tabIndex = comp.getProperty("tabIndex");
                Object tabs = comp.getProperty("tabs");
                if (tabs instanceof List && ((List) tabs).size() > 0) {
                    List tabsList = (List) tabs;
                    TabPanel tabpanel = (TabPanel) ((WebFormComponent) comp).getFormElement().getPersistIfAvailable();
                    if (tabpanel.getTabOrientation() == TabPanel.SPLIT_HORIZONTAL || tabpanel.getTabOrientation() == TabPanel.SPLIT_VERTICAL) {
                        for (Object element : tabsList) {
                            Map<String, Object> tab = (Map<String, Object>) element;
                            if (tab != null) {
                                String relationName = tab.get("relationName") != null ? tab.get("relationName").toString() : null;
                                Object tabForm = tab.get("containsFormId");
                                if (tabForm != null) {
                                    getFormUI().getDataAdapterList().addVisibleChildForm(getApplication().getFormManager().getForm(tabForm.toString()), relationName, true);
                                }
                            }
                        }
                    } else {
                        Map<String, Object> visibleTab = null;
                        if (tabIndex instanceof Number && tabsList.size() > 0 && ((Number) tabIndex).intValue() <= tabsList.size()) {
                            int index = ((Number) tabIndex).intValue() - 1;
                            if (index < 0) {
                                index = 0;
                            }
                            visibleTab = (Map<String, Object>) (tabsList.get(index));
                        } else if (tabIndex instanceof String || tabIndex instanceof CharSequence) {
                            for (Object element : tabsList) {
                                Map<String, Object> tab = (Map<String, Object>) element;
                                if (Utils.equalObjects(tabIndex, tab.get("name"))) {
                                    visibleTab = tab;
                                    break;
                                }
                            }
                        }
                        if (visibleTab != null) {
                            String relationName = visibleTab.get("relationName") != null ? visibleTab.get("relationName").toString() : null;
                            Object tabForm = visibleTab.get("containsFormId");
                            if (tabForm != null) {
                                getFormUI().getDataAdapterList().addVisibleChildForm(getApplication().getFormManager().getForm(tabForm.toString()), relationName, true);
                            }
                        }
                    }
                }
            }
        }
    }
    // TODO should notifyVisibleSuccess be altered here? See WebFormUI/WebFormComponent notifyVisible calls.
    if (notifyVisibleSuccess)
        notifyVisibleOnChildren(visible, invokeLaterRunnables);
    return notifyVisibleSuccess;
}
Also used : TabPanel(com.servoy.j2db.persistence.TabPanel) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) WebObjectFunctionDefinition(org.sablo.specification.WebObjectFunctionDefinition) Point(java.awt.Point) WebComponent(org.sablo.WebComponent) IDataAdapterList(com.servoy.j2db.server.ngclient.IDataAdapterList) List(java.util.List) ArrayList(java.util.ArrayList) SortedList(com.servoy.j2db.util.SortedList) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 10 with WebFormComponent

use of com.servoy.j2db.server.ngclient.WebFormComponent in project servoy-client by Servoy.

the class WebFormController method getJSEvent.

@Override
protected JSEvent getJSEvent(Object src, String eventName) {
    JSEvent event = new JSEvent();
    event.setType(JSEvent.EventType.form);
    if (eventName != null)
        event.setName(RepositoryHelper.getDisplayName(eventName, Form.class));
    event.setFormName(getName());
    event.setSource(src);
    if (src instanceof WebFormComponent)
        event.setElementName(((WebFormComponent) src).getFormElement().getRawName());
    else
        event.setElementName(src instanceof WebComponent ? ((WebComponent) src).getName() : null);
    return event;
}
Also used : WebComponent(org.sablo.WebComponent) JSEvent(com.servoy.j2db.scripting.JSEvent) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent)

Aggregations

WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)31 Test (org.junit.Test)14 Form (com.servoy.j2db.persistence.Form)12 FormElement (com.servoy.j2db.server.ngclient.FormElement)10 IWebFormController (com.servoy.j2db.server.ngclient.IWebFormController)10 ServoyJSONObject (com.servoy.j2db.util.ServoyJSONObject)10 JSONObject (org.json.JSONObject)10 BrowserConverterContext (org.sablo.specification.property.BrowserConverterContext)10 StringWriter (java.io.StringWriter)7 JSONWriter (org.json.JSONWriter)7 DataConversion (org.sablo.websocket.utils.DataConversion)7 IDataAdapterList (com.servoy.j2db.server.ngclient.IDataAdapterList)6 Point (java.awt.Point)6 DataAdapterList (com.servoy.j2db.server.ngclient.DataAdapterList)5 ServoyDataConverterContext (com.servoy.j2db.server.ngclient.ServoyDataConverterContext)5 Map (java.util.Map)5 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)4 IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)4 HashMap (java.util.HashMap)4 FlattenedSolution (com.servoy.j2db.FlattenedSolution)3