Search in sources :

Example 6 with FormManager

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

the class WebBaseButton method fireOnRender.

public void fireOnRender(boolean force) {
    if (scriptable != null) {
        boolean isFocused = false;
        IMainContainer currentContainer = ((FormManager) application.getFormManager()).getCurrentContainer();
        if (currentContainer instanceof MainPage) {
            isFocused = this.equals(((MainPage) currentContainer).getFocusedComponent());
        }
        if (force)
            scriptable.getRenderEventExecutor().setRenderStateChanged();
        scriptable.getRenderEventExecutor().fireOnRender(isFocused);
    }
}
Also used : FormManager(com.servoy.j2db.FormManager) IMainContainer(com.servoy.j2db.IMainContainer) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 7 with FormManager

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

the class WebBaseLabel method fireOnRender.

public void fireOnRender(boolean force) {
    if (scriptable instanceof ISupportOnRenderCallback) {
        boolean isFocused = false;
        IMainContainer currentContainer = ((FormManager) application.getFormManager()).getCurrentContainer();
        if (currentContainer instanceof MainPage) {
            isFocused = this.equals(((MainPage) currentContainer).getFocusedComponent());
        }
        if (force)
            ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor().setRenderStateChanged();
        ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor().fireOnRender(isFocused);
    }
}
Also used : FormManager(com.servoy.j2db.FormManager) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IMainContainer(com.servoy.j2db.IMainContainer) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 8 with FormManager

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

the class WebClient method getTriggerReqOnOtherPagesJS.

// generate JS requests on all other reachable browser tabs/browser windows that are open in this client
private List<String> getTriggerReqOnOtherPagesJS(RequestCycle rc, MainPage currentPage) {
    List<String> triggerJSs = null;
    if (rc != null && rc.getRequestTarget() instanceof AjaxRequestTarget) {
        FormManager fm = (FormManager) getFormManager();
        if (fm != null) {
            List<String> all = fm.getCreatedMainContainerKeys();
            triggerJSs = new ArrayList<String>(all.size());
            for (String key : all) {
                MainPage page = (MainPage) fm.getMainContainer(key);
                if (// should always be != null
                page != null && page != currentPage) {
                    String tmp = page.getTriggerBrowserRequestJS();
                    if (tmp != null)
                        triggerJSs.add(tmp);
                }
            }
            return triggerJSs;
        }
    }
    return triggerJSs;
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) FormManager(com.servoy.j2db.FormManager)

Example 9 with FormManager

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

Example 10 with FormManager

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

Aggregations

FormManager (com.servoy.j2db.FormManager)49 IMainContainer (com.servoy.j2db.IMainContainer)21 FormController (com.servoy.j2db.FormController)15 MainPage (com.servoy.j2db.server.headlessclient.MainPage)13 IForm (com.servoy.j2db.IForm)7 Form (com.servoy.j2db.persistence.Form)5 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)4 RepositoryException (com.servoy.j2db.persistence.RepositoryException)4 IComponent (com.servoy.j2db.ui.IComponent)4 Component (java.awt.Component)4 ArrayList (java.util.ArrayList)4 FlattenedSolution (com.servoy.j2db.FlattenedSolution)3 FormWindow (com.servoy.j2db.FormWindow)3 IBasicFormManager (com.servoy.j2db.IBasicFormManager)3 IFormController (com.servoy.j2db.IFormController)3 IFormManager (com.servoy.j2db.IFormManager)3 ITable (com.servoy.j2db.persistence.ITable)3 SwingFormManager (com.servoy.j2db.smart.SwingFormManager)3 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)3 ServoyException (com.servoy.j2db.util.ServoyException)3