Search in sources :

Example 6 with IFormUIInternal

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

the class MainPanel method show.

public void show(String name) {
    forms.show(tableFormPanel, name);
    Component cmp = null;
    for (int i = 0; i < tableFormPanel.getComponentCount(); i++) {
        Component c = tableFormPanel.getComponent(i);
        if ((c != null) && c.isVisible()) {
            cmp = c;
            break;
        }
    }
    // Place into the tab sequence the current form and, if exists, the navigator.
    tabSeqComponentList.clear();
    if (cmp instanceof SwingForm) {
        SwingForm sf = (SwingForm) cmp;
        tabSeqComponentList.add(sf);
    }
    if (getNavigator() != null) {
        IFormUIInternal fui = getNavigator().getFormUI();
        if (fui instanceof SwingForm) {
            SwingForm sf = (SwingForm) fui;
            tabSeqComponentList.add(sf);
        }
    }
}
Also used : JComponent(javax.swing.JComponent) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) IFormUIInternal(com.servoy.j2db.IFormUIInternal)

Example 7 with IFormUIInternal

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

Aggregations

IFormUIInternal (com.servoy.j2db.IFormUIInternal)7 FormController (com.servoy.j2db.FormController)5 Component (java.awt.Component)3 ArrayList (java.util.ArrayList)3 IComponent (com.servoy.j2db.ui.IComponent)2 Point (java.awt.Point)2 List (java.util.List)2 AbstractActiveSolutionHandler (com.servoy.j2db.AbstractActiveSolutionHandler)1 BasicFormController (com.servoy.j2db.BasicFormController)1 FlattenedSolution (com.servoy.j2db.FlattenedSolution)1 FormManager (com.servoy.j2db.FormManager)1 IApplication (com.servoy.j2db.IApplication)1 IForm (com.servoy.j2db.IForm)1 Form (com.servoy.j2db.persistence.Form)1 IRepository (com.servoy.j2db.persistence.IRepository)1 Part (com.servoy.j2db.persistence.Part)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1 Solution (com.servoy.j2db.persistence.Solution)1 PrintPreview (com.servoy.j2db.printing.PrintPreview)1 WebForm (com.servoy.j2db.server.headlessclient.WebForm)1