Search in sources :

Example 1 with IFoundSetInternal

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

the class DebugJ2DBClient method destroyForm.

/**
 * @param formController
 * @return
 */
private void destroyForm(IFormController formController) {
    refreshI18NMessages(true);
    if (formController.isFormVisible()) {
        IFoundSetInternal foundSet = formController.getFormModel();
        if (foundSet instanceof FoundSet) {
            ((FoundSet) foundSet).refresh();
        }
        String name = null;
        if (formController.getForm() != null)
            name = formController.getForm().getName();
        if (name == null)
            name = formController.getName();
        if (getFormManager().getCurrentForm() == formController) {
            formController.destroy();
            getFormManager().showFormInCurrentContainer(name);
        } else {
            SwingForm swingForm = (SwingForm) formController.getFormUI();
            Container container = swingForm.getParent();
            boolean isNavigator = false;
            boolean isWindow = false;
            boolean isLookupPanel = false;
            if (container instanceof MainPanel) {
                isNavigator = ((MainPanel) container).getNavigator() == formController;
            } else if (container instanceof FormLookupPanel) {
                isLookupPanel = true;
            } else {
                while (container != null && !(container instanceof FormWindow)) {
                    container = container.getParent();
                }
                if (container instanceof FormWindow) {
                    isWindow = true;
                }
            }
            formController.destroy();
            if (isLookupPanel) {
                FormLookupPanel flp = (FormLookupPanel) container;
                FormController newFormController = flp.getFormPanel();
                if (newFormController != null) {
                    // deleted in developer ?
                    newFormController.loadData(foundSet, null);
                    List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
                    newFormController.notifyVisible(true, invokeLaterRunnables);
                    Utils.invokeLater(this, invokeLaterRunnables);
                }
            } else if (isNavigator) {
                // TODO isNavigator check will always be false for NGClient?
                FormController navigator = ((FormManager) getFormManager()).getFormController(name, container);
                if (navigator != null) {
                    navigator.loadData(foundSet, null);
                    List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
                    navigator.notifyVisible(true, invokeLaterRunnables);
                    Utils.invokeLater(this, invokeLaterRunnables);
                }
                mainPanel.setNavigator(navigator);
            } else if (isWindow) {
                // TODO isWindow check will always be false for NGClient?
                FormWindow w = (FormWindow) container;
                ((FormManager) getFormManager()).showFormInMainPanel(name, w.getMainContainer(), w.getTitle(), false, w.getName());
            }
        }
    } else {
        formController.destroy();
    }
    return;
}
Also used : IFormController(com.servoy.j2db.IFormController) FormController(com.servoy.j2db.FormController) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ArrayList(java.util.ArrayList) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) FormWindow(com.servoy.j2db.FormWindow) SwingForm(com.servoy.j2db.smart.SwingForm) IMainContainer(com.servoy.j2db.IMainContainer) Container(java.awt.Container) MainPanel(com.servoy.j2db.smart.MainPanel) FormManager(com.servoy.j2db.FormManager) SwingFormManager(com.servoy.j2db.smart.SwingFormManager) ArrayList(java.util.ArrayList) List(java.util.List) FormLookupPanel(com.servoy.j2db.smart.dataui.FormLookupPanel)

Example 2 with IFoundSetInternal

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

the class SessionClient method getContext.

private Pair<IRecordInternal, FormScope> getContext(String contextName) {
    try {
        String visibleFormName = contextName;
        String dataContext = null;
        if (contextName != null) {
            // $NON-NLS-1$
            StringTokenizer tk = new StringTokenizer(contextName, ".");
            String token = tk.nextToken();
            if (// $NON-NLS-1$
            token.equals("forms") && tk.hasMoreTokens()) {
                visibleFormName = tk.nextToken();
                if (tk.hasMoreTokens())
                    token = tk.nextToken();
            }
            if (// $NON-NLS-1$
            !token.equals("foundset")) {
                // todo why is this always also assigned to the datacontext?
                // shouldnt the above if be: if (token.equals("foundset") && st.hasMoreTokes()) dataContext == st.nextToken();
                // because now this data context will just be set to a form name if the contextName is just a form. (which in many cases it is defined like that)
                dataContext = token;
            }
        }
        if (visibleFormName == null) {
            IForm tmp = ((FormManager) getFormManager()).getCurrentForm();
            if (tmp != null)
                visibleFormName = tmp.getName();
        }
        if (visibleFormName != null) {
            // just overwrite the above assignment again if the datacontext is really also the form, so it wont be used later on.
            if (Utils.stringSafeEquals(visibleFormName, dataContext)) {
                dataContext = null;
            }
            FormController fp = ((FormManager) getFormManager()).leaseFormPanel(visibleFormName);
            if (!fp.isShowingData()) {
                if (fp.wantEmptyFoundSet()) {
                    if (fp.getFormModel() != null)
                        fp.getFormModel().clear();
                } else {
                    fp.loadAllRecords();
                }
            }
            IFoundSetInternal fs = fp.getFoundSet();
            if (fs != null) {
                int idx = fs.getSelectedIndex();
                if (idx < 0)
                    idx = 0;
                IRecordInternal r = fs.getRecord(idx);
                if (r != null) {
                    if (dataContext != null) {
                        IFoundSetInternal rfs = r.getRelatedFoundSet(dataContext);
                        // rfs can be null because dataContext can just be a anything see above
                        if (rfs != null) {
                            r = rfs.getRecord(rfs.getSelectedIndex());
                        }
                    }
                    return new Pair<IRecordInternal, FormScope>(r, fp.getFormScope());
                }
            }
            return new Pair<IRecordInternal, FormScope>(null, fp.getFormScope());
        }
    } catch (Exception e) {
        Debug.error(e);
    }
    return null;
}
Also used : FormController(com.servoy.j2db.FormController) IFormController(com.servoy.j2db.IFormController) StringTokenizer(java.util.StringTokenizer) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) FormManager(com.servoy.j2db.FormManager) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) IForm(com.servoy.j2db.IForm) ApplicationException(com.servoy.j2db.ApplicationException) RemoteException(java.rmi.RemoteException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServoyException(com.servoy.j2db.util.ServoyException) IOException(java.io.IOException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) Pair(com.servoy.j2db.util.Pair)

Example 3 with IFoundSetInternal

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

the class WebAccordionPanel method registerSelectionListeners.

private void registerSelectionListeners(IRecordInternal parentState, String relationName) {
    // $NON-NLS-1$
    String[] parts = relationName.split("\\.");
    IRecordInternal currentRecord = parentState;
    for (int i = 0; currentRecord != null && i < parts.length - 1; i++) {
        IFoundSetInternal fs = currentRecord.getRelatedFoundSet(parts[i]);
        if (fs instanceof ISwingFoundSet) {
            related.add((ISwingFoundSet) fs);
            ((ISwingFoundSet) fs).getSelectionModel().addListSelectionListener(this);
        }
        currentRecord = (fs == null) ? null : fs.getRecord(fs.getSelectedIndex());
    }
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Point(java.awt.Point) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet)

Example 4 with IFoundSetInternal

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

the class WebAccordionPanel method showFoundSet.

protected void showFoundSet(WebTabFormLookup flp, IRecordInternal parentState, List<SortColumn> sort) {
    deregisterSelectionListeners();
    if (!flp.isReady())
        return;
    FormController fp = flp.getWebForm().getController();
    if (fp != null && flp.getRelationName() != null) {
        IFoundSetInternal relatedFoundset = parentState == null ? null : parentState.getRelatedFoundSet(flp.getRelationName(), sort);
        registerSelectionListeners(parentState, flp.getRelationName());
        fp.loadData(relatedFoundset, null);
    }
    ITagResolver resolver = getTagResolver(parentState);
    // refresh tab text
    for (int i = 0; i < allTabs.size(); i++) {
        WebTabHolder element = allTabs.get(i);
        if (element.getPanel() == flp) {
            element.refreshTagStrings(resolver);
            break;
        }
    }
}
Also used : FormController(com.servoy.j2db.FormController) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ITagResolver(com.servoy.base.util.ITagResolver) Point(java.awt.Point)

Example 5 with IFoundSetInternal

use of com.servoy.j2db.dataprocessing.IFoundSetInternal 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

IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)55 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)26 Point (java.awt.Point)13 FormController (com.servoy.j2db.FormController)12 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)11 ServoyException (com.servoy.j2db.util.ServoyException)8 ArrayList (java.util.ArrayList)8 IApplication (com.servoy.j2db.IApplication)6 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)6 EventObject (java.util.EventObject)6 ITagResolver (com.servoy.base.util.ITagResolver)5 FindState (com.servoy.j2db.dataprocessing.FindState)5 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)5 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)5 RepositoryException (com.servoy.j2db.persistence.RepositoryException)5 JSONObject (org.json.JSONObject)5 FormManager (com.servoy.j2db.FormManager)4 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)4 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)4 Color (java.awt.Color)4