use of com.servoy.j2db.IMainContainer in project servoy-client by Servoy.
the class SwingRuntimeWindow method doOldShowInWindow.
private void doOldShowInWindow(String formName) {
FormManager fm = ((FormManager) getApplication().getFormManager());
boolean toFront = createFrameIfNeeded(fm);
FormFrame frame = (FormFrame) wrappedWindow;
if (frame.isVisible()) {
frame.storeBounds();
}
IMainContainer container = frame.getMainContainer();
final FormController fp = fm.showFormInMainPanel(formName, container, title, true, windowName);
finalizeShowWindow(fp, formName, container, true, false, toFront);
}
use of com.servoy.j2db.IMainContainer in project servoy-client by Servoy.
the class SwingRuntimeWindowManager method getOrderedContainers.
@Override
protected List<String> getOrderedContainers() {
// here we have to close in reverse order of the opening
FormManager fm = ((FormManager) application.getFormManager());
List<String> orderedDialogs = new ArrayList<String>();
Map<FormDialog, String> dialogs = new HashMap<FormDialog, String>();
List<String> all = fm.getCreatedMainContainerKeys();
for (String key : all) {
if (key != null) {
IMainContainer mContainer = fm.getMainContainer(key);
if (fm.getMainContainer(null) != mContainer) {
Container parent = ((Component) mContainer).getParent();
while (parent != null && !(parent instanceof FormDialog)) {
parent = parent.getParent();
}
if (parent instanceof FormDialog) {
dialogs.put((FormDialog) parent, key);
continue;
}
}
}
}
for (FormDialog dialog : dialogs.keySet()) {
addDialogsInOrder(dialog, dialogs, orderedDialogs);
}
if (orderedDialogs.size() < all.size()) {
for (String key : all) {
if (!orderedDialogs.contains(key)) {
orderedDialogs.add(key);
}
}
}
return orderedDialogs;
}
use of com.servoy.j2db.IMainContainer 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.IMainContainer in project servoy-client by Servoy.
the class WebForm method findMainPage.
public MainPage findMainPage() {
WebForm currentForm = this;
while (currentForm != null) {
MainPage parentPage = currentForm.getMainPage();
if (parentPage != null)
return parentPage;
currentForm = currentForm.findParent(WebForm.class);
}
IMainContainer currentContainer = ((FormManager) formController.getApplication().getFormManager()).getCurrentContainer();
if (currentContainer instanceof MainPage) {
return (MainPage) currentContainer;
}
return null;
}
use of com.servoy.j2db.IMainContainer in project servoy-client by Servoy.
the class WebForm method print.
// public void print(boolean showDialogs, boolean printCurrentRecordOnly, boolean showPrinterSelectDialog, int zoomFactor, PrinterJob printerJob)
// {
// print(showDialogs, printCurrentRecordOnly, showPrinterSelectDialog, printerJob);
// }
/**
* @see com.servoy.j2db.IFormUIInternal#print(boolean, boolean, boolean, java.awt.print.PrinterJob)
*/
public void print(boolean showDialogs, boolean printCurrentRecordOnly, boolean showPrinterSelectDialog, PrinterJob printerJob) {
IFoundSetInternal fs = formController.getFoundSet();
try {
if (printCurrentRecordOnly) {
fs = fs.copyCurrentRecordFoundSet();
}
} catch (ServoyException e1) {
Debug.error(e1);
}
IApplication application = formController.getApplication();
ByteArrayOutputStream baos = null;
MainPage page = null;
if (printerJob == null) {
page = (MainPage) findPage();
if (page == null) {
IMainContainer tmp = ((FormManager) application.getFormManager()).getCurrentContainer();
if (tmp instanceof MainPage)
page = (MainPage) tmp;
}
// if "page" is still null then there is no wicket front-end for this client - so printing is not intended to reach the client; print on the server instead
// (can happen for batch processors for example)
}
if (page != null) {
baos = new ByteArrayOutputStream();
StreamPrintServiceFactory[] factories = null;
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PAGEABLE;
ClassLoader savedClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(((PluginManager) application.getPluginManager()).getClassLoader());
// $NON-NLS-1$
factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, "application/pdf");
if (factories == null || factories.length == 0) {
// $NON-NLS-1$
Debug.error("No suitable pdf printer found");
return;
}
} finally {
Thread.currentThread().setContextClassLoader(savedClassLoader);
}
try {
FormPreviewPanel fpp = new FormPreviewPanel(application, formController, fs);
// AWT stuff happens here, so execute it in the AWT Event Thread - else exceptions can occur
// for example in JEditorPane while getting the preferred size & stuff
processFppInAWTEventQueue(fpp, application);
StreamPrintService sps = factories[0].getPrintService(baos);
Doc doc = new SimpleDoc(fpp.getPageable(), flavor, null);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
sps.createPrintJob().print(doc, pras);
fpp.destroy();
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.formPanel.error.printDocument"), ex);
}
// $NON-NLS-1$
String contentType = "application/pdf";
// BTW, "application/octet-stream" works for all browsers, but it is not that accurate
if (// if it's not batch processor/jsp, because if it is, then getClientInfo() gives NullPointerException
application.getApplicationType() != IApplication.HEADLESS_CLIENT) {
ClientInfo info = Session.get().getClientInfo();
if (info instanceof WebClientInfo) {
String userAgent = ((WebClientInfo) info).getProperties().getNavigatorUserAgent();
if (// $NON-NLS-1$
userAgent != null && userAgent.toLowerCase().contains("safari")) {
// $NON-NLS-1$
contentType = "application/octet-stream";
}
}
}
// $NON-NLS-1$ //$NON-NLS-2$
String url = page.serveResource(formController.getName() + ".pdf", baos.toByteArray(), contentType, "attachment");
// $NON-NLS-1$
page.setShowURLCMD(url, "_self", null, 0, false);
} else {
try {
FormPreviewPanel fpp = new FormPreviewPanel(application, formController, fs);
// AWT stuff happens here, so execute it in the AWT Event Thread - else exceptions can occur
// for example in JEditorPane while getting the preferred size & stuff
processFppInAWTEventQueue(fpp, application);
PrintPreview.startPrinting(application, fpp.getPageable(), printerJob, formController.getPreferredPrinterName(), false, true);
fpp.destroy();
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.formPanel.error.printDocument"), ex);
}
}
}
Aggregations