Search in sources :

Example 1 with WicketEvent

use of com.servoy.j2db.server.headlessclient.eventthread.WicketEvent in project servoy-client by Servoy.

the class MainPage method createDivDialog.

private ServoyDivDialog createDivDialog(MainPage dialogContainer, String name) {
    final ServoyDivDialog divDialog = new ServoyDivDialog(divDialogRepeater.newChildId()) {

        @Override
        public void show(AjaxRequestTarget target) {
            super.show(target);
            Component toFocus = ((MainPage) page).getFocusedComponent();
            if (toFocus == null)
                toFocus = page;
            target.focusComponent(toFocus);
        }
    };
    divDialog.setPageMapName(null);
    divDialog.setCookieName(COOKIE_PREFIX + name);
    divDialog.setModal(true);
    dialogContainer.showingInDialog = true;
    dialogContainer.showingInWindow = false;
    divDialog.setPageCreator(new ModalWindow.PageCreator() {

        private static final long serialVersionUID = 1L;

        public Page createPage() {
            MainPage mp = (MainPage) ((FormManager) client.getFormManager()).getOrCreateMainContainer(divDialog.getPageMapName());
            divDialog.setPage(mp);
            return mp;
        }
    });
    divDialog.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {

        private static final long serialVersionUID = 1L;

        public void onClose(AjaxRequestTarget target) {
            divDialogRepeater.remove(divDialog);
            String divDialogPageMapName = divDialog.getPageMapName();
            if (divDialogs.get(divDialogPageMapName) == divDialog) {
                divDialogs.remove(divDialogPageMapName);
            }
            if (divDialogs.size() == 0) {
                divDialogsParent.setVisible(false);
            } else {
                addJSAction(new DivDialogAction(divDialog, DivDialogAction.OP_DIALOG_ADDED_OR_REMOVED, new Object[] { divDialogsParent }));
            }
            divDialog.setPageMapName(null);
            restoreFocusedComponentInParentIfNeeded();
            WebEventExecutor.generateResponse(target, findPage());
        }
    });
    divDialog.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {

        private static final long serialVersionUID = 1L;

        public boolean onCloseButtonClicked(AjaxRequestTarget target) {
            if (!divDialog.isShown()) {
                // double clicked?
                return false;
            }
            FormManager fm = ((FormManager) client.getFormManager());
            IMainContainer divDialogContainer = fm.getMainContainer(divDialog.getPageMapName());
            IMainContainer currentContainer = fm.getCurrentContainer();
            // get a lock on the dialog container (form onHide code will execute, make sure another req. on the dialog itself is not running at the same time)
            if (divDialogContainer instanceof MainPage) {
                ((MainPage) divDialogContainer).touch();
            }
            // temporary set the dialog container as the current container (the close event is processed by the main container, not the dialog)
            fm.setCurrentContainer(divDialogContainer, divDialogContainer.getContainerName());
            if (client.getEventDispatcher() != null) {
                client.getEventDispatcher().addEvent(new WicketEvent(client, new Runnable() {

                    public void run() {
                        client.getRuntimeWindowManager().closeFormInWindow(divDialog.getPageMapName(), divDialog.getCloseAll());
                    }
                }));
            } else {
                client.getRuntimeWindowManager().closeFormInWindow(divDialog.getPageMapName(), divDialog.getCloseAll());
            }
            // reset current container again
            fm.setCurrentContainer(currentContainer, currentContainer.getContainerName());
            if (divDialogContainer instanceof MainPage) {
                target.addComponent(divDialog);
            }
            WebEventExecutor.generateResponse(target, divDialog.getPage());
            return false;
        }
    });
    divDialogRepeater.add(divDialog);
    divDialogsParent.setVisible(true);
    addJSAction(new DivDialogAction(divDialog, DivDialogAction.OP_DIALOG_ADDED_OR_REMOVED, new Object[] { divDialogsParent }));
    divDialogs.put(name, divDialog);
    return divDialog;
}
Also used : DivDialogAction(com.servoy.j2db.server.headlessclient.PageJSActionBuffer.DivDialogAction) WicketEvent(com.servoy.j2db.server.headlessclient.eventthread.WicketEvent) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) FormManager(com.servoy.j2db.FormManager) IMainContainer(com.servoy.j2db.IMainContainer) 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) ModalWindow(org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow)

Example 2 with WicketEvent

use of com.servoy.j2db.server.headlessclient.eventthread.WicketEvent in project servoy-client by Servoy.

the class WebClient method executeEvents.

@SuppressWarnings("nls")
public void executeEvents() {
    if (blockEventExecution)
        return;
    List<Runnable> runnables = null;
    // so the events array may be not initialized yet.
    if (events != null) {
        synchronized (events) {
            if (events.size() > 0) {
                runnables = new ArrayList<Runnable>(events);
                events.clear();
            }
        }
        List<Runnable> list = requestEvents.get();
        if (list.size() > 0) {
            if (runnables == null) {
                runnables = new ArrayList<Runnable>(list);
            } else
                runnables.addAll(list);
            list.clear();
        }
    }
    if (runnables != null) {
        if (getEventDispatcher() != null) {
            getEventDispatcher().addEvent(new WicketEvent(this, new EventsRunnable(runnables)));
        } else {
            new EventsRunnable(this, runnables).run();
        }
    }
    return;
}
Also used : WicketEvent(com.servoy.j2db.server.headlessclient.eventthread.WicketEvent)

Example 3 with WicketEvent

use of com.servoy.j2db.server.headlessclient.eventthread.WicketEvent in project servoy-client by Servoy.

the class WebEventExecutor method onEvent.

public void onEvent(final EventType type, final AjaxRequestTarget target, final Component comp, final int webModifiers, final Point mouseLocation, final Point absoluteMouseLocation) {
    ServoyForm form = comp.findParent(ServoyForm.class);
    if (form == null) {
        return;
    }
    // JS might change the page this form belongs to... so remember it now
    final Page page = form.getPage();
    IEventDispatcher<WicketEvent> eventDispatcher = WebClientSession.get().getWebClient().getEventDispatcher();
    if (eventDispatcher != null) {
        eventDispatcher.addEvent(new WicketEvent(WebClientSession.get().getWebClient(), new Runnable() {

            public void run() {
                handleEvent(type, target, comp, webModifiers, mouseLocation, absoluteMouseLocation, page);
            }
        }));
    } else {
        handleEvent(type, target, comp, webModifiers, mouseLocation, absoluteMouseLocation, page);
    }
    if (target != null) {
        generateResponse(target, page);
    }
}
Also used : WicketEvent(com.servoy.j2db.server.headlessclient.eventthread.WicketEvent) Page(org.apache.wicket.Page) MainPage(com.servoy.j2db.server.headlessclient.MainPage) ServoyForm(com.servoy.j2db.server.headlessclient.ServoyForm)

Aggregations

WicketEvent (com.servoy.j2db.server.headlessclient.eventthread.WicketEvent)3 Page (org.apache.wicket.Page)2 FormManager (com.servoy.j2db.FormManager)1 IMainContainer (com.servoy.j2db.IMainContainer)1 MainPage (com.servoy.j2db.server.headlessclient.MainPage)1 DivDialogAction (com.servoy.j2db.server.headlessclient.PageJSActionBuffer.DivDialogAction)1 ServoyForm (com.servoy.j2db.server.headlessclient.ServoyForm)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 Component (org.apache.wicket.Component)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 ModalWindow (org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow)1 WebPage (org.apache.wicket.markup.html.WebPage)1 FormComponent (org.apache.wicket.markup.html.form.FormComponent)1