Search in sources :

Example 51 with Solution

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

the class MainPage method init.

@SuppressWarnings("nls")
private void init(WebClient sc) {
    setStatelessHint(false);
    client = sc;
    webForms = new ArrayList<IFormUIInternal<?>>();
    // $NON-NLS-1$ //$NON-NLS-2$
    title = new Label("title", new Model<String>("Servoy Web Client"));
    title.setOutputMarkupId(true);
    add(title);
    // $NON-NLS-1$
    useAJAX = Utils.getAsBoolean(client.getRuntimeProperties().get("useAJAX"));
    // $NON-NLS-1$  //$NON-NLS-2$
    int dataNotifyFrequency = Utils.getAsInteger(sc.getSettings().getProperty("servoy.webclient.datanotify.frequency", "5"));
    if (dataNotifyFrequency > 0 && useAJAX) {
        add(new AbstractAjaxTimerBehavior(Duration.seconds(dataNotifyFrequency)) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onTimer(AjaxRequestTarget target) {
                if (isServoyEnabled() && !client.getFlattenedSolution().isInDesign(null) && String.valueOf(MainPage.this.getCurrentVersionNumber()).equals(RequestCycle.get().getRequest().getParameter("pvs"))) {
                    WebEventExecutor.generateResponse(target, MainPage.this);
                }
            }

            @Override
            public void renderHead(IHeaderResponse response) {
                if (isServoyEnabled()) {
                    super.renderHead(response);
                    String jsTimerScript = getJsTimeoutCall(getUpdateInterval());
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    response.renderJavascript("function restartTimer() {" + jsTimerScript + "}", "restartTimer");
                }
            }

            @Override
            protected CharSequence getPreconditionScript() {
                // $NON-NLS-1$
                return "onAjaxCall(); if(Servoy.DD.isDragging) Servoy.DD.isRestartTimerNeeded=true; return !Servoy.DD.isDragging && !Servoy.redirectingOnSolutionClose;";
            }

            @Override
            protected CharSequence getFailureScript() {
                // $NON-NLS-1$
                return "onAjaxError();restartTimer();";
            }

            @Override
            protected CharSequence getCallbackScript() {
                // if it is not enabled then just return an empty function. so that the timer stops.
                if (isServoyEnabled()) {
                    return generateCallbackScript(// $NON-NLS-1$
                    "wicketAjaxGet('" + getCallbackUrl(onlyTargetActivePage()) + "&ignoremp=true&pvs=" + MainPage.this.getCurrentVersionNumber() + // $NON-NLS-1$
                    "'");
                }
                return "Servoy.Utils.nop()";
            }

            @Override
            public CharSequence getCallbackUrl(boolean onlyTargetActivePage) {
                if (getComponent() == null) {
                    // $NON-NLS-1$
                    throw new IllegalArgumentException("Behavior must be bound to a component to create the URL");
                }
                return getComponent().urlFor(this, AlwaysLastPageVersionRequestListenerInterface.INTERFACE);
            }

            @Override
            protected String findIndicatorId() {
                // main page defines it and the timer shouldnt show it
                return null;
            }

            /*
				 * this can't be isEnabled(component) of the behavior itself because IE8 will constant call this on closed (modal)windows. So then this is
				 * marked as disabled and an AbortException is thrown what our code sees as a server error and will constantly restart the timer.
				 */
            private boolean isServoyEnabled() {
                return ((getController() != null && getController().isFormVisible()) || closingAsWindow);
            }
        });
    }
    add(new TriggerOrientationChangeAjaxBehavior());
    add(new TriggerResizeAjaxBehavior());
    add(new AbstractServoyLastVersionAjaxBehavior() {

        @Override
        protected void execute(AjaxRequestTarget target) {
            for (ServoyDivDialog divDialog : divDialogs.getOrderedByOpenSequence()) {
                if (!divDialog.isShown()) {
                    // this means a refresh was probably triggered and we must re-show these... because we do not keep closed dialogs in divDialogs
                    int x = divDialog.getX();
                    int y = divDialog.getY();
                    int w = divDialog.getWidth();
                    int h = divDialog.getHeight();
                    divDialog.show(target, null);
                    divDialog.setBounds(target, x, y, w, h, null);
                }
            }
            WebEventExecutor.generateResponse(target, MainPage.this);
        }

        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead(response);
            response.renderOnDomReadyJavascript(getCallbackScript(true).toString());
        }

        @Override
        public boolean isEnabled(Component component) {
            return divDialogs.size() > 0 && super.isEnabled(component);
        }
    });
    body = new // $NON-NLS-1$
    WebMarkupContainer(// $NON-NLS-1$
    "servoy_page") {

        private static final long serialVersionUID = 1L;

        /**
         * @see org.apache.wicket.Component#onComponentTag(org.apache.wicket.markup.ComponentTag)
         */
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.putAll(bodyAttributes);
        }
    };
    body.add(new AttributeModifier("dir", true, new // $NON-NLS-1$
    AbstractReadOnlyModel<String>() {

        @Override
        public String getObject() {
            String value = AttributeModifier.VALUELESS_ATTRIBUTE_REMOVE;
            Locale l = client.getLocale();
            Solution solution = client.getSolution();
            if (solution != null && l != null) {
                value = OrientationApplier.getHTMLContainerOrientation(l, solution.getTextOrientation());
            }
            return value;
        }
    }));
    add(body);
    pageContributor = new PageContributor(client, "contribution");
    body.add(pageContributor);
    Label loadingIndicator = new Label("loading_indicator", sc.getI18NMessage("servoy.general.loading"));
    loadingIndicator.add(new SimpleAttributeModifier("style", "display:none;"));
    body.add(loadingIndicator);
    divDialogsParent = new WebMarkupContainer(DIV_DIALOGS_REPEATER_PARENT_ID);
    divDialogsParent.setOutputMarkupPlaceholderTag(true);
    divDialogsParent.setVisible(false);
    body.add(divDialogsParent);
    if (useAJAX) {
        // for when another page needs to trigger an ajax update on this page using js (see media upload)
        add(new TriggerUpdateAjaxBehavior());
        divDialogRepeater = new RepeatingView(DIV_DIALOG_REPEATER_ID);
        divDialogsParent.add(divDialogRepeater);
        fileUploadWindow = new ServoyDivDialog(FILE_UPLOAD_DIALOG_ID);
        body.add(fileUploadWindow);
        fileUploadWindow.setModal(true);
        fileUploadWindow.setPageMapName(null);
        fileUploadWindow.setCookieName("dialog_fileupload");
        fileUploadWindow.setResizable(true);
        fileUploadWindow.setInitialHeight(150);
        fileUploadWindow.setInitialWidth(400);
        fileUploadWindow.setMinimalHeight(130);
        fileUploadWindow.setMinimalWidth(400);
        // no effect, can be removed
        fileUploadWindow.setUseInitialHeight(true);
        fileUploadWindow.setPageCreator(new ModalWindow.PageCreator() {

            private static final long serialVersionUID = 1L;

            public Page createPage() {
                return new MediaUploadPage(PageMap.forName(FILE_UPLOAD_PAGEMAP), mediaUploadCallback, mediaUploadMultiSelect, mediaUploadFilter, getController().getApplication());
            }
        });
        fileUploadWindow.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

            private static final long serialVersionUID = 1L;

            public void onClose(AjaxRequestTarget target) {
                divDialogs.remove(FILE_UPLOAD_PAGEMAP);
                fileUploadWindow.setPageMapName(null);
                fileUploadWindow.remove(fileUploadWindow.getContentId());
                restoreFocusedComponentInParentIfNeeded();
                WebEventExecutor.generateResponse(target, findPage());
            }
        });
    } else {
        divDialogsParent.add(new Label("divdialogs"));
        // $NON-NLS-1$
        body.add(new Label("fileuploaddialog"));
    }
    IModel<String> styleHrefModel = new AbstractReadOnlyModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            if (main != null) {
                return // $NON-NLS-1$
                getRequest().getRelativePathPrefixToContextRoot() + "servoy-webclient/templates/" + client.getClientProperty(WEBCONSTANTS.WEBCLIENT_TEMPLATES_DIR) + // $NON-NLS-1$
                "/servoy_web_client_default.css";
            }
            return null;
        }
    };
    // $NON-NLS-1$
    Label main_form_style = new Label("main_form_style");
    // $NON-NLS-1$
    main_form_style.add(new AttributeModifier("href", true, styleHrefModel));
    add(main_form_style);
    IModel<List<IFormUIInternal<?>>> loopModel = new AbstractReadOnlyModel<List<IFormUIInternal<?>>>() {

        private static final long serialVersionUID = 1L;

        @Override
        public List<IFormUIInternal<?>> getObject() {
            return webForms;
        }
    };
    listview = new // $NON-NLS-1$
    ListView<IFormUIInternal<?>>(// $NON-NLS-1$
    "forms", // $NON-NLS-1$
    loopModel) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(ListItem<IFormUIInternal<?>> item) {
            final WebForm form = (WebForm) item.getModelObject();
            tempRemoveMainForm = true;
            try {
                if (form.getParent() != null) {
                    // TODO isn't this already done by item.add(form) below in wicket's impl?
                    form.remove();
                }
                item.add(form);
            } finally {
                tempRemoveMainForm = false;
            }
            IFormLayoutProvider layoutProvider = FormLayoutProviderFactory.getFormLayoutProvider(client, client.getSolution(), form.getController().getForm(), form.getController().getName());
            TextualStyle styleToReturn = null;
            if ((navigator != null) && (form == navigator.getFormUI())) {
                styleToReturn = layoutProvider.getLayoutForForm(navigator.getForm().getSize().width, true, false);
            } else if (form == main) {
                int customNavWidth = 0;
                if (navigator != null)
                    customNavWidth = navigator.getForm().getSize().width;
                styleToReturn = layoutProvider.getLayoutForForm(customNavWidth, false, false);
            }
            if (styleToReturn != null) {
                form.add(new StyleAppendingModifier(styleToReturn) {

                    @Override
                    public boolean isEnabled(Component component) {
                        // Laurian: looks like bogus condition, shouldn't this be || as in WebForm ?
                        return (component.findParent(WebTabPanel.class) == null) && (component.findParent(WebSplitPane.class) == null);
                    }
                });
            }
            TabIndexHelper.setUpTabIndexAttributeModifier(item, ISupportWebTabSeq.SKIP);
        }

        @Override
        protected ListItem<IFormUIInternal<?>> newItem(final int index) {
            return new ListItem<IFormUIInternal<?>>(index, getListItemModel(getModel(), index)) {

                @Override
                public void remove(Component component) {
                    super.remove(component);
                    // for example when a form is shown in a popup form (window plugin) it must know that it's main page changed
                    if (!tempRemoveMainForm && component instanceof WebForm) {
                        WebForm formUI = ((WebForm) component);
                        if (MainPage.this == formUI.getMainPage()) {
                            // (could be triggered by a browser back button)
                            if (formUI.getController().isFormVisible()) {
                                List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
                                formUI.getController().notifyVisible(false, invokeLaterRunnables);
                                Utils.invokeLater(client, invokeLaterRunnables);
                            }
                            formUI.setMainPage(null);
                        }
                    }
                }
            };
        }

        /**
         * @see org.apache.wicket.markup.html.list.ListView#onBeforeRender()
         */
        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            // now first initialize all the tabs so that data from
            // tab x doesn't change anymore (so that it could alter data in tab y)
            // don't know if this still does anything because we need to do it
            // in the onBeforeRender of WebTabPanel itself, else tableviews don't have there models yet..
            visitChildren(WebTabPanel.class, new IVisitor<WebTabPanel>() {

                public Object component(WebTabPanel wtp) {
                    wtp.initalizeFirstTab();
                    return IVisitor.CONTINUE_TRAVERSAL;
                }
            });
            addWebAnchoringInfoIfNeeded();
        }
    };
    listview.setReuseItems(true);
    // if versioning is disabled then table views can go wrong (don't rollback on a submit)
    // listview.setVersioned(false);
    // $NON-NLS-1$
    Form form = new ServoyForm("servoy_dataform");
    // $NON-NLS-1$ //$NON-NLS-2$
    form.add(new SimpleAttributeModifier("autocomplete", "off"));
    // $NON-NLS-1$ //$NON-NLS-2$
    if (useAJAX)
        form.add(new SimpleAttributeModifier("onsubmit", "return false;"));
    form.add(listview);
    // $NON-NLS-1$
    WebMarkupContainer defaultButton = new WebMarkupContainer("defaultsubmitbutton", new Model());
    defaultButton.setVisible(!useAJAX);
    form.add(defaultButton);
    StylePropertyChangeMarkupContainer container = new StylePropertyChangeMarkupContainer("externaldivsparent");
    form.add(container);
    PageContributorRepeatingView repeatingView = new PageContributorRepeatingView("externaldivs", container);
    container.add(repeatingView);
    pageContributor.addRepeatingView(repeatingView);
    body.add(form);
}
Also used : Locale(java.util.Locale) Label(org.apache.wicket.markup.html.basic.Label) RepeatingView(org.apache.wicket.markup.repeater.RepeatingView) PageContributorRepeatingView(com.servoy.j2db.server.headlessclient.dataui.PageContributorRepeatingView) SimpleAttributeModifier(org.apache.wicket.behavior.SimpleAttributeModifier) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page) WebSplitPane(com.servoy.j2db.server.headlessclient.dataui.WebSplitPane) StylePropertyChangeMarkupContainer(com.servoy.j2db.server.headlessclient.dataui.StylePropertyChangeMarkupContainer) WebTabPanel(com.servoy.j2db.server.headlessclient.dataui.WebTabPanel) ArrayList(java.util.ArrayList) List(java.util.List) IFormUIInternal(com.servoy.j2db.IFormUIInternal) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow) StyleAppendingModifier(com.servoy.j2db.server.headlessclient.dataui.StyleAppendingModifier) AbstractServoyLastVersionAjaxBehavior(com.servoy.j2db.server.headlessclient.dataui.AbstractServoyLastVersionAjaxBehavior) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AbstractAjaxTimerBehavior(org.apache.wicket.ajax.AbstractAjaxTimerBehavior) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) Form(org.apache.wicket.markup.html.form.Form) PageContributorRepeatingView(com.servoy.j2db.server.headlessclient.dataui.PageContributorRepeatingView) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) TextualStyle(com.servoy.j2db.server.headlessclient.dataui.TemplateGenerator.TextualStyle) IHeaderResponse(org.apache.wicket.markup.html.IHeaderResponse) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) Solution(com.servoy.j2db.persistence.Solution) AttributeModifier(org.apache.wicket.AttributeModifier) SimpleAttributeModifier(org.apache.wicket.behavior.SimpleAttributeModifier) Point(java.awt.Point) ComponentTag(org.apache.wicket.markup.ComponentTag) IModel(org.apache.wicket.model.IModel) Model(org.apache.wicket.model.Model) AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) IFormLayoutProvider(com.servoy.j2db.server.headlessclient.dataui.IFormLayoutProvider) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 52 with Solution

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

the class NGClientWindow method getRealFormURLAndSeeIfItIsACopy.

protected Pair<String, Boolean> getRealFormURLAndSeeIfItIsACopy(Form form, String realFormName) {
    FlattenedSolution fs = getSession().getClient().getFlattenedSolution();
    Solution sc = fs.getSolutionCopy(false);
    String realUrl = getDefaultFormURLStart(form, realFormName);
    boolean copy = false;
    if (sc != null && sc.getChild(form.getUUID()) != null) {
        realUrl = realUrl + "?lm:" + form.getLastModified() + "&clientnr=" + getSession().getSessionKey().getClientnr();
        copy = true;
    } else if (!form.getName().endsWith(realFormName)) {
        realUrl = realUrl + "?lm:" + form.getLastModified() + "&clientnr=" + getSession().getSessionKey().getClientnr();
    } else {
        realUrl = realUrl + "?clientnr=" + getSession().getSessionKey().getClientnr();
    }
    return new Pair<String, Boolean>(realUrl, Boolean.valueOf(copy));
}
Also used : FlattenedSolution(com.servoy.j2db.FlattenedSolution) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution) Pair(com.servoy.j2db.util.Pair)

Example 53 with Solution

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

the class AngularIndexPageWriter method writeStartupJs.

/**
 * @param request
 * @param servletResponse
 * @param solutionName
 * @throws IOException
 * @throws ServletException
 * @throws JSONException
 */
public static void writeStartupJs(HttpServletRequest request, HttpServletResponse response, String solutionName) throws IOException, ServletException {
    if (request.getCharacterEncoding() == null)
        request.setCharacterEncoding("UTF8");
    String uri = request.getRequestURI();
    String clientnr = getClientNr(uri, request);
    Pair<FlattenedSolution, Boolean> pair = getFlattenedSolution(solutionName, clientnr, request, response);
    JSONObject json = new JSONObject();
    json.put("pathName", request.getRequestURI().replaceAll("[^/]*/[^/]*/startup.js$", "index.html"));
    json.put("querystring", HTTPUtils.generateQueryString(request.getParameterMap(), request.getCharacterEncoding()));
    // in case there is a forwarding proxy
    String ipaddr = request.getHeader("X-Forwarded-For");
    if (ipaddr == null) {
        ipaddr = request.getRemoteAddr();
    }
    json.put("ipaddr", ipaddr);
    // in case there is a forwarding proxy
    String remoteHost = request.getHeader("X-Forwarded-Host");
    if (remoteHost == null) {
        remoteHost = request.getRemoteHost();
    }
    json.put("hostaddr", remoteHost);
    if (pair.getLeft() != null) {
        Solution solution = pair.getLeft().getSolution();
        json.put("orientation", solution.getTextOrientation());
        JSONObject defaultTranslations = new JSONObject();
        defaultTranslations.put("servoy.ngclient.reconnecting", getSolutionDefaultMessage(solution, request.getLocale(), "servoy.ngclient.reconnecting"));
        json.put("defaultTranslations", defaultTranslations);
    }
    StringBuilder sb = new StringBuilder(256);
    sb.append("window.svyData=");
    sb.append(json.toString());
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/javascript");
    response.setContentLengthLong(sb.length());
    response.getWriter().write(sb.toString());
    if (pair.getRight().booleanValue())
        pair.getLeft().close(null);
}
Also used : JSONObject(org.json.JSONObject) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Utils.getAsBoolean(com.servoy.j2db.util.Utils.getAsBoolean) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 54 with Solution

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

the class EventExecutor method executeEvent.

public Object executeEvent(WebComponent component, String eventType, int eventId, Object[] eventArgs) {
    Scriptable scope = null;
    Function f = null;
    Object[] newargs = eventArgs != null ? Arrays.copyOf(eventArgs, eventArgs.length) : null;
    if (eventId > 0) {
        ScriptMethod scriptMethod = formController.getApplication().getFlattenedSolution().getScriptMethod(eventId);
        if (scriptMethod != null) {
            if (scriptMethod.getParent() instanceof Form) {
                FormScope formScope = formController.getFormScope();
                f = formScope.getFunctionByName(scriptMethod.getName());
                if (f != null && f != Scriptable.NOT_FOUND) {
                    scope = formScope;
                }
            } else // is it a global method
            if (scriptMethod.getParent() instanceof Solution) {
                scope = formController.getApplication().getScriptEngine().getScopesScope().getGlobalScope(scriptMethod.getScopeName());
                if (scope != null) {
                    f = ((GlobalScope) scope).getFunctionByName(scriptMethod.getName());
                }
            } else // very like a foundset/entity method
            {
                Scriptable foundsetScope = null;
                if (component instanceof WebFormComponent) {
                    IRecord rec = ((WebFormComponent) component).getDataAdapterList().getRecord();
                    if (rec != null) {
                        foundsetScope = (Scriptable) rec.getParentFoundSet();
                    }
                }
                if (foundsetScope == null)
                    foundsetScope = (Scriptable) formController.getFormModel();
                if (foundsetScope != null) {
                    // TODO ViewFoundSets should be come a scriptable if they have foundset methods..
                    scope = foundsetScope;
                    Object scopeMethod = scope.getPrototype().get(scriptMethod.getName(), scope);
                    if (scopeMethod instanceof Function)
                        f = (Function) scopeMethod;
                }
            }
            if (f == null) {
                Debug.error(// $NON-NLS-1$ //$NON-NLS-2$
                "No function found for " + scriptMethod + " when trying to execute the event " + eventType + '(' + eventId + ") of component: " + component, // $NON-NLS-1$
                new RuntimeException());
                return null;
            }
        } else {
            Debug.warn("Couldn't find the ScriptMethod for event: " + eventType + " with event id: " + eventId + " to execute for component " + component);
        }
    }
    // $NON-NLS-1$
    if (formController.isInFindMode() && !Utils.getAsBoolean(f.get("_AllowToRunInFind_", f)))
        return null;
    if (newargs != null) {
        for (int i = 0; i < newargs.length; i++) {
            if (newargs[i] instanceof JSONObject && "event".equals(((JSONObject) newargs[i]).optString("type"))) {
                JSONObject json = (JSONObject) newargs[i];
                JSEvent event = new JSEvent();
                JSEventType.fillJSEvent(event, json, component, formController);
                event.setType(getEventType(eventType));
                event.setName(RepositoryHelper.getDisplayName(eventType, BaseComponent.class));
                newargs[i] = event;
            } else {
                // try to convert the received arguments
                WebObjectFunctionDefinition propertyDesc = component.getSpecification().getHandler(eventType);
                List<PropertyDescription> parameters = propertyDesc.getParameters();
                if (i < parameters.size()) {
                    PropertyDescription parameterPropertyDescription = parameters.get(i);
                    ValueReference<Boolean> returnValueAdjustedIncommingValueForIndex = new ValueReference<Boolean>(Boolean.FALSE);
                    newargs[i] = NGConversions.INSTANCE.convertSabloComponentToRhinoValue(JSONUtils.fromJSON(null, newargs[i], parameterPropertyDescription, new BrowserConverterContext(component, PushToServerEnum.allow), returnValueAdjustedIncommingValueForIndex), parameterPropertyDescription, component, scope);
                }
            // TODO? if in propertyDesc.getAsPropertyDescription().getConfig() we have  "type":"${dataproviderType}" and parameterPropertyDescription.getType() is Object
            // then get the type from the dataprovider and try to convert the json to that type instead of simply object
            }
        }
    }
    if (component instanceof WebFormComponent) {
        IPersist persist = ((WebFormComponent) component).getFormElement().getPersistIfAvailable();
        if (persist instanceof AbstractBase) {
            List<Object> instanceMethodArguments = ((AbstractBase) persist).getFlattenedMethodArguments(eventType);
            if (instanceMethodArguments != null && instanceMethodArguments.size() > 0) {
                // create entries for the instanceMethodArguments if they are more then callback arguments
                if (instanceMethodArguments.size() > newargs.length) {
                    newargs = Utils.arrayJoin(newargs, new Object[instanceMethodArguments.size() - newargs.length]);
                }
                // use instanceMethodArguments if not null, else just use the callback argument
                for (int i = 0; i < instanceMethodArguments.size(); i++) {
                    Object value = instanceMethodArguments.get(i);
                    if (value != null && value != JSONObject.NULL) {
                        newargs[i] = Utils.parseJSExpression(value);
                    }
                }
            }
        }
    }
    try {
        formController.getApplication().updateLastAccessed();
        return formController.getApplication().getScriptEngine().executeFunction(f, scope, scope, newargs, false, false);
    } catch (Exception ex) {
        formController.getApplication().reportJSError(ex.getMessage(), ex);
        return null;
    }
}
Also used : GlobalScope(com.servoy.j2db.scripting.GlobalScope) BaseComponent(com.servoy.j2db.persistence.BaseComponent) Form(com.servoy.j2db.persistence.Form) WebFormComponent(com.servoy.j2db.server.ngclient.WebFormComponent) WebObjectFunctionDefinition(org.sablo.specification.WebObjectFunctionDefinition) FormScope(com.servoy.j2db.scripting.FormScope) Function(org.mozilla.javascript.Function) BrowserConverterContext(org.sablo.specification.property.BrowserConverterContext) Solution(com.servoy.j2db.persistence.Solution) ValueReference(org.sablo.util.ValueReference) JSEvent(com.servoy.j2db.scripting.JSEvent) IJSEvent(com.servoy.base.scripting.api.IJSEvent) IRecord(com.servoy.j2db.dataprocessing.IRecord) AbstractBase(com.servoy.j2db.persistence.AbstractBase) Scriptable(org.mozilla.javascript.Scriptable) JSONException(org.json.JSONException) PropertyDescription(org.sablo.specification.PropertyDescription) JSONObject(org.json.JSONObject) IPersist(com.servoy.j2db.persistence.IPersist) JSONObject(org.json.JSONObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod)

Example 55 with Solution

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

the class NGRuntimeWindow method sendTitle.

private void sendTitle(String title) {
    String titleString = "";
    if (windowType == JSWindow.WINDOW) {
        Solution solution = getApplication().getSolution();
        String solutionTitle = solution.getTitleText();
        if (solutionTitle == null) {
            titleString = solution.getName();
        } else if (// $NON-NLS-1$
        !solutionTitle.equals("<empty>")) {
            titleString = solutionTitle;
        }
        titleString = getApplication().getI18NMessageIfPrefixed(titleString);
        if (// $NON-NLS-1$ //$NON-NLS-2$
        title != null && !title.trim().equals("") && !"<empty>".equals(title) && title != null) {
            String nameString = getApplication().getI18NMessageIfPrefixed(title);
            IWebFormController formController = getController();
            if (formController != null) {
                String name2 = Text.processTags(nameString, formController.getFormUI().getDataAdapterList());
                if (name2 != null)
                    nameString = name2;
            } else {
                String name2 = Text.processTags(nameString, TagResolver.createResolver(new PrototypeState(null)));
                if (name2 != null)
                    nameString = name2;
            }
            if (// $NON-NLS-1$
            !nameString.trim().equals("")) {
                if (// $NON-NLS-1$
                "".equals(titleString)) {
                    titleString += nameString;
                } else {
                    // $NON-NLS-1$
                    titleString += " - " + nameString;
                }
            }
        }
        // $NON-NLS-1$
        String appName = "Servoy NG Client";
        // $NON-NLS-1$ //$NON-NLS-2$
        boolean branding = Utils.getAsBoolean(getApplication().getSettings().getProperty("servoy.branding", "false"));
        // $NON-NLS-1$
        String appTitle = getApplication().getSettings().getProperty("servoy.branding.windowtitle");
        Object runtimeAppTitle = getApplication().getClientProperty(NGCONSTANTS.WINDOW_BRANDING_TITLE);
        if (runtimeAppTitle instanceof String) {
            appTitle = (String) runtimeAppTitle;
        }
        if (branding && appTitle != null) {
            appName = appTitle;
        }
        if (// $NON-NLS-1$
        titleString.equals("")) {
            titleString = appName;
        } else if (// $NON-NLS-1$
        !appName.trim().equals("")) {
            // $NON-NLS-1$
            titleString += " - " + appName;
        }
    } else {
        titleString = getApplication().getI18NMessageIfPrefixed(title);
    }
    getApplication().getWebsocketSession().getClientService(NGRuntimeWindowManager.WINDOW_SERVICE).executeAsyncServiceCall(// $NON-NLS-1$
    "setTitle", new Object[] { this.getName(), titleString });
}
Also used : JSONObject(org.json.JSONObject) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) Solution(com.servoy.j2db.persistence.Solution)

Aggregations

Solution (com.servoy.j2db.persistence.Solution)59 FlattenedSolution (com.servoy.j2db.FlattenedSolution)17 Form (com.servoy.j2db.persistence.Form)16 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)12 ArrayList (java.util.ArrayList)9 RemoteException (java.rmi.RemoteException)8 HashMap (java.util.HashMap)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 IPersist (com.servoy.j2db.persistence.IPersist)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ServoyException (com.servoy.j2db.util.ServoyException)6 JSONObject (org.json.JSONObject)6 IFormController (com.servoy.j2db.IFormController)5 Map (java.util.Map)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 JavaScriptException (org.mozilla.javascript.JavaScriptException)5 IRepository (com.servoy.j2db.persistence.IRepository)4 List (java.util.List)4 ApplicationException (com.servoy.j2db.ApplicationException)3