Search in sources :

Example 1 with INGClientWindow

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

the class RuntimeWebComponent method isApiFunctionEnabled.

protected boolean isApiFunctionEnabled(String functionName) {
    boolean isLocationOrSize = "getLocationX".equals(functionName) || "getLocationY".equals(functionName) || "getWidth".equals(functionName) || "getHeight".equals(functionName);
    if (isLocationOrSize) {
        // if parent form not visible, don't call api, let it get from the model on the server
        Container parent = component.getParent();
        while (parent != null) {
            if (parent instanceof WebFormUI) {
                boolean isFormVisible = false;
                IWindow currentWindow = CurrentWindow.safeGet();
                if (currentWindow instanceof INGClientWindow) {
                    isFormVisible = ((INGClientWindow) currentWindow).hasForm(parent.getName());
                }
                if (isFormVisible) {
                    // it is reported to be still on the client
                    // but do check also if it is not about to be hidden, by having
                    // formVisible already set to false in the controller
                    isFormVisible = ((WebFormUI) parent).getController().isFormVisible();
                }
                if (!isFormVisible) {
                    return false;
                }
                // if this form is in designer mode then it has to go to the client to get the current size/location
                if (((WebFormUI) parent).getController().getDesignModeCallbacks() != null)
                    return true;
                break;
            }
            parent = parent.getParent();
        }
        // if it is not table view (it can have columns moved/resize) and not anchored, no need to call api, let it get from the model on the server
        FormElement fe = component.getFormElement();
        if (fe.isLegacy() && fe.getPersistIfAvailable() instanceof ISupportAnchors && (fe.getForm().getView() != FormController.TABLE_VIEW && fe.getForm().getView() != FormController.LOCKED_TABLE_VIEW)) {
            // ((ISupportAnchors)fe.getPersistIfAvailable()).getAnchors();
            int anchor = Utils.getAsInteger(component.getProperty(StaticContentSpecLoader.PROPERTY_ANCHORS.getPropertyName()));
            if ((anchor == 0 || anchor == (IAnchorConstants.NORTH + IAnchorConstants.WEST))) {
                return false;
            }
        }
    }
    return true;
}
Also used : Container(org.sablo.Container) ISupportAnchors(com.servoy.j2db.persistence.ISupportAnchors) IWebFormUI(com.servoy.j2db.server.ngclient.IWebFormUI) WebFormUI(com.servoy.j2db.server.ngclient.WebFormUI) INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) IWindow(org.sablo.websocket.IWindow) FormElement(com.servoy.j2db.server.ngclient.FormElement)

Example 2 with INGClientWindow

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

the class WebFormController method destroy.

@Override
public void destroy() {
    if (isFormVisible() && application.isSolutionLoaded()) {
        destroyOnHide = true;
    } else {
        try {
            unload();
            if (formUI != null) {
                formUI.destroy();
                formUI = null;
            }
            super.destroy();
            IWindow window = CurrentWindow.safeGet();
            if (window instanceof INGClientWindow && application.isSolutionLoaded()) {
                ((INGClientWindow) window).destroyForm(getName());
            }
            if (getBasicFormManager() != null)
                getBasicFormManager().removeFormController(this);
        } finally {
            application.getFlattenedSolution().deregisterLiveForm(form, namedInstance);
        }
    }
}
Also used : INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) IWindow(org.sablo.websocket.IWindow)

Example 3 with INGClientWindow

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

the class FormPropertyType method toJSON.

@Override
public JSONWriter toJSON(JSONWriter writer, String key, Object sabloValue, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
    if (key != null) {
        writer.key(key);
    }
    String formName = null;
    if (sabloValue instanceof String) {
        formName = (String) sabloValue;
        if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof IContextProvider) {
            FlattenedSolution flattenedSolution = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution();
            Form form = flattenedSolution.getForm(formName);
            // form name
            if (form == null) {
                form = (Form) flattenedSolution.searchPersist((String) sabloValue);
            }
            if (form != null) {
                formName = form.getName();
            }
        }
    } else if (sabloValue instanceof CharSequence) {
        formName = ((CharSequence) sabloValue).toString();
    } else if (sabloValue instanceof Form) {
        formName = ((Form) sabloValue).getName();
    } else if (sabloValue instanceof FormController) {
        formName = ((FormController) sabloValue).getName();
    } else if (sabloValue instanceof FormScope) {
        formName = ((FormScope) sabloValue).getFormController().getName();
    } else {
        formName = null;
        Debug.error("Cannot handle unknown value for Form type: " + sabloValue);
    }
    writer.value(formName);
    if (CurrentWindow.get() instanceof INGClientWindow) {
        // if this is a web component that triggered it, register to only allow this form for that component
        if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof WebFormComponent)
            ((INGClientWindow) CurrentWindow.get()).registerAllowedForm(formName, ((WebFormComponent) dataConverterContext.getWebObject()).getFormElement());
        else
            // else register it for null then this form is allowed globally (a form in dialog of popup)
            ((INGClientWindow) CurrentWindow.get()).registerAllowedForm(formName, null);
    }
    return writer;
}
Also used : FormController(com.servoy.j2db.FormController) IContextProvider(com.servoy.j2db.server.ngclient.IContextProvider) INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) FlattenedSolution(com.servoy.j2db.FlattenedSolution) FormScope(com.servoy.j2db.scripting.FormScope)

Example 4 with INGClientWindow

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

the class FormPropertyType method toTemplateJSONValue.

@Override
public JSONWriter toTemplateJSONValue(JSONWriter writer, String key, Object formElementValue, PropertyDescription pd, DataConversion browserConversionMarkers, FormElementContext formElementContext) throws JSONException {
    if (formElementValue == null)
        return writer;
    FlattenedSolution fs = formElementContext.getFlattenedSolution();
    Form form = null;
    if (formElementValue instanceof Integer) {
        form = fs.getForm(((Integer) formElementValue).intValue());
    } else if (formElementValue instanceof String || formElementValue instanceof UUID) {
        form = fs.getForm(formElementValue.toString());
        if (form == null) {
            form = (Form) fs.searchPersist(formElementValue.toString());
        }
    }
    if (form != null) {
        writer.key(key);
        writer.value(form.getName());
        if (CurrentWindow.safeGet() instanceof INGClientWindow) {
            ((INGClientWindow) CurrentWindow.get()).registerAllowedForm(form.getName(), formElementContext.getFormElement());
        }
    }
    return writer;
}
Also used : INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) FlattenedSolution(com.servoy.j2db.FlattenedSolution) UUID(com.servoy.j2db.util.UUID)

Example 5 with INGClientWindow

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

the class WebFormController method recreateUI.

@Override
public boolean recreateUI() {
    Form oldForm = form;
    // update flattened form reference cause now we probably need to use a SM modified version
    Form f = application.getFlattenedSolution().getForm(form.getName());
    // don't use cached, make sure it updates the cache
    form = application.getFlattenedSolution().getFlattenedForm(f, false);
    INGClientWindow allWindowsProxy = new NGClientWebsocketSessionWindows(getApplication().getWebsocketSession());
    if (allWindowsProxy.hasFormChangedSinceLastSendToClient(form, getName())) {
        // hide all visible children; here is an example that explains why it's needed:
        // parent form has tabpanel with child1 and child2; child2 is visible (second tab)
        // if you recreateUI on parent, child1 would turn out visible after recreateUI without a hide event on child2 if we wouldn't do the notifyVisible below;
        // but also when you would afterwards change tab to child2 it's onShow won't be called because it thinks it's still visible which is strange;
        List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
        notifyVisibleOnChildren(false, invokeLaterRunnables);
        Utils.invokeLater(application, invokeLaterRunnables);
        tabSequence = null;
        f = application.getFlattenedSolution().getForm(form.getName());
        form = application.getFlattenedSolution().getFlattenedForm(f);
        getFormUI().init();
        getApplication().recreateForm(form, getName());
        if (isFormVisible) {
            invokeLaterRunnables = new ArrayList<Runnable>();
            notifyVisibleOnChildren(true, invokeLaterRunnables);
            Utils.invokeLater(application, invokeLaterRunnables);
            if (getDesignModeCallbacks() != null) {
                // this form is in design mode, let the client know the ui is created:
                RuntimeWebComponent[] components = getWebComponentElements();
                String[] names = new String[components.length];
                for (int i = 0; i < names.length; i++) {
                    names[i] = components[i].getComponent().getName();
                }
                getApplication().getWebsocketSession().getClientService(ClientDesignService.NAME).executeAsyncServiceCall("recreateUI", new Object[] { getName(), names });
            }
        }
    } else {
        // in case it's not already loaded on client side - so we can't rely on endpoint URL differeces - but it is modified by Solution Model and recreateUI is called, it's formUI needs to reinitialize as well
        if ((oldForm != form || application.isInDeveloper()) && !allWindowsProxy.hasForm(getName())) {
            tabSequence = null;
            getFormUI().init();
            Debug.trace("RecreateUI on form " + getName() + " only recreated form ui on server, because that form is not present client-side...");
        } else
            Debug.trace("RecreateUI on form " + getName() + " was ignored because that form was not changed or at least not since last being sent to client...");
    }
    application.getFlattenedSolution().deregisterLiveForm(form, namedInstance);
    application.getFlattenedSolution().registerLiveForm(form, namedInstance);
    return true;
}
Also used : INGClientWindow(com.servoy.j2db.server.ngclient.INGClientWindow) Form(com.servoy.j2db.persistence.Form) NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) ArrayList(java.util.ArrayList) Point(java.awt.Point)

Aggregations

INGClientWindow (com.servoy.j2db.server.ngclient.INGClientWindow)5 Form (com.servoy.j2db.persistence.Form)3 FlattenedSolution (com.servoy.j2db.FlattenedSolution)2 JSForm (com.servoy.j2db.scripting.solutionmodel.JSForm)2 IWindow (org.sablo.websocket.IWindow)2 FormController (com.servoy.j2db.FormController)1 ISupportAnchors (com.servoy.j2db.persistence.ISupportAnchors)1 FormScope (com.servoy.j2db.scripting.FormScope)1 FormElement (com.servoy.j2db.server.ngclient.FormElement)1 IContextProvider (com.servoy.j2db.server.ngclient.IContextProvider)1 IWebFormUI (com.servoy.j2db.server.ngclient.IWebFormUI)1 WebFormComponent (com.servoy.j2db.server.ngclient.WebFormComponent)1 WebFormUI (com.servoy.j2db.server.ngclient.WebFormUI)1 NGClientWebsocketSessionWindows (com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows)1 UUID (com.servoy.j2db.util.UUID)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 Container (org.sablo.Container)1