Search in sources :

Example 1 with IMainContainer

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);
}
Also used : FormController(com.servoy.j2db.FormController) FormManager(com.servoy.j2db.FormManager) IMainContainer(com.servoy.j2db.IMainContainer)

Example 2 with IMainContainer

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;
}
Also used : FormDialog(com.servoy.j2db.gui.FormDialog) IMainContainer(com.servoy.j2db.IMainContainer) IBasicMainContainer(com.servoy.j2db.IBasicMainContainer) Container(java.awt.Container) FormManager(com.servoy.j2db.FormManager) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IMainContainer(com.servoy.j2db.IMainContainer) Component(java.awt.Component)

Example 3 with IMainContainer

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;
}
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 4 with IMainContainer

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;
}
Also used : IBasicFormManager(com.servoy.j2db.IBasicFormManager) FormManager(com.servoy.j2db.FormManager) IMainContainer(com.servoy.j2db.IMainContainer)

Example 5 with IMainContainer

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);
        }
    }
}
Also used : WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) FormPreviewPanel(com.servoy.j2db.printing.FormPreviewPanel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StreamPrintService(javax.print.StreamPrintService) ServoyException(com.servoy.j2db.util.ServoyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ServoyException(com.servoy.j2db.util.ServoyException) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) IApplication(com.servoy.j2db.IApplication) SimpleDoc(javax.print.SimpleDoc) IBasicFormManager(com.servoy.j2db.IBasicFormManager) FormManager(com.servoy.j2db.FormManager) IMainContainer(com.servoy.j2db.IMainContainer) Doc(javax.print.Doc) SimpleDoc(javax.print.SimpleDoc) WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) ClientInfo(org.apache.wicket.request.ClientInfo) StreamPrintServiceFactory(javax.print.StreamPrintServiceFactory) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Aggregations

IMainContainer (com.servoy.j2db.IMainContainer)25 FormManager (com.servoy.j2db.FormManager)20 MainPage (com.servoy.j2db.server.headlessclient.MainPage)13 FormController (com.servoy.j2db.FormController)3 FormWindow (com.servoy.j2db.FormWindow)3 FormDialog (com.servoy.j2db.gui.FormDialog)3 ISmartRuntimeWindow (com.servoy.j2db.plugins.ISmartRuntimeWindow)3 JSWindow (com.servoy.j2db.scripting.JSWindow)3 RuntimeWindow (com.servoy.j2db.scripting.RuntimeWindow)3 Window (java.awt.Window)3 IBasicFormManager (com.servoy.j2db.IBasicFormManager)2 IComponent (com.servoy.j2db.ui.IComponent)2 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)2 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)2 Container (java.awt.Container)2 Component (org.apache.wicket.Component)2 IApplication (com.servoy.j2db.IApplication)1 IBasicMainContainer (com.servoy.j2db.IBasicMainContainer)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 BaseComponent (com.servoy.j2db.persistence.BaseComponent)1