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;
}
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;
}
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);
}
}
Aggregations