Search in sources :

Example 21 with FormManager

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

the class FormPreviewPanel method process.

// build the chain and fill the renderers,returns number of pages
public int process() throws Exception {
    // clear
    root = null;
    // set size of this panel
    orgWidth = new Dimension((int) (currentPageFormat.getWidth() * (1 / factor)), (int) (currentPageFormat.getHeight() * (1 / factor)));
    applySize();
    part_panels = createPartPanels();
    Form form = controllerBeingPreviewed.getForm();
    // otherwise you cannot print multiple columns   (int) (application.getPageFormat().getImageableWidth()*(1/factor));
    int w = form.getWidth();
    try {
        // $NON-NLS-1$
        application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
        Map componentsUsingSliding = application.getDataRenderFactory().completeRenderers(application, form, controllerBeingPreviewed.getScriptExecuter(), part_panels, w, true, null, null);
        PropertyCopy.copyExistingPrintableProperties(application, controllerBeingPreviewed, part_panels);
        Iterator<DataRenderer> panels = part_panels.values().iterator();
        while (panels.hasNext()) {
            DataRenderer panel = panels.next();
            panel.setComponentsUsingSliding(componentsUsingSliding);
            DataRendererFactory.addSpringsBetweenComponents(application, panel);
        }
        // $NON-NLS-1$
        Debug.trace("usesSliding " + (componentsUsingSliding.size() != 0));
    } finally {
        // $NON-NLS-1$
        application.getRuntimeProperties().put("isPrinting", null);
    }
    // create list
    renderParent = application.getPrintingRendererParent();
    plist = new PageList(application, this, renderParent);
    PartNode node = null;
    // create the chain based on the sort,LAST node must be the body part (is virtal added if not present)
    Part body = null;
    FormController fp = ((FormManager) application.getFormManager()).leaseFormPanel(controllerBeingPreviewed.getName());
    if (fp != null && !fp.isShowingData()) {
        // List lst = fp.getFormModel().getLastSearchColumns();
        if (fp.wantEmptyFoundSet()) {
            if (fp.getFormModel() != null)
                fp.getFormModel().clear();
        } else {
            fp.loadAllRecords();
        }
    // fp.getFormModel().sort(lst);
    }
    List<SortColumn> sortColumns = ((FoundSet) formData).getLastSortColumns();
    if (formData.getSize() != 0) {
        if (sortColumns != null) {
            Set<String> consumed = new HashSet<String>();
            for (int i = 0; i < sortColumns.size(); i++) {
                SortColumn sc = sortColumns.get(i);
                Iterator<Part> it = part_panels.keySet().iterator();
                while (it.hasNext()) {
                    Part part = it.next();
                    DataRenderer dr = part_panels.get(part);
                    if (part.getPartType() == Part.BODY) {
                        body = part;
                        continue;
                    }
                    if (part.getPartType() != Part.LEADING_SUBSUMMARY && part.getPartType() != Part.TRAILING_SUBSUMMARY) {
                        IRecordInternal state = new PageNumberState(formData, plist);
                        plist.setNonRepeatingPart(part.getPartType(), new DataRendererDefinition(this, renderParent, part, dr, state));
                        continue;
                    }
                    boolean match = false;
                    int inlineCount = 0;
                    List<SortColumn> partSortColumns = new ArrayList<SortColumn>();
                    SortColumn lastMatch = sc;
                    String groupByDataproviders = part.getGroupbyDataProviderIDs() != null ? part.getGroupbyDataProviderIDs() : "";
                    // $NON-NLS-1$ //$NON-NLS-2$
                    StringTokenizer tk = new StringTokenizer("" + groupByDataproviders.toLowerCase(), ", ");
                    int tokenCount = tk.countTokens();
                    String[] ids = new String[tokenCount];
                    for (; inlineCount < tokenCount; inlineCount++) {
                        String id = tk.nextToken();
                        ids[inlineCount] = id;
                        if (lastMatch.getDataProviderID().equals(id)) {
                            partSortColumns.add(lastMatch);
                            if ((i + inlineCount + 1) < sortColumns.size()) {
                                lastMatch = sortColumns.get(i + inlineCount + 1);
                                if (part.getPartType() == Part.LEADING_SUBSUMMARY && consumed.contains(lastMatch)) {
                                    break;
                                }
                            } else {
                                break;
                            }
                        } else {
                            break;
                        }
                    }
                    if (// did all match?
                    tokenCount > 0 && partSortColumns.size() == tokenCount) {
                        match = true;
                        if (part.getPartType() == Part.LEADING_SUBSUMMARY) {
                            for (String element : ids) {
                                consumed.add(element);
                            }
                        }
                    }
                    if (match) {
                        SortColumn[] array = new SortColumn[partSortColumns.size()];
                        partSortColumns.toArray(array);
                        if (// create root
                        root == null) {
                            root = new PartNode(this, part, dr, renderParent, array);
                            node = root;
                        } else {
                            if (!tryToPlaceInExistingNodes(part, dr, array)) {
                                PartNode newNode = new PartNode(this, part, dr, renderParent, array);
                                node.setChild(newNode);
                                node = newNode;
                            }
                        }
                    }
                }
            }
            PartNode newNode = null;
            if (body == null) {
                // a virtual body (when no body is placed in the parts)
                newNode = new PartNode(this, null, null, renderParent, null);
            } else {
                // the body
                newNode = new PartNode(this, body, part_panels.get(body), renderParent, null);
            }
            if (node != null) {
                node.setChild(newNode);
            } else {
                root = newNode;
            }
        } else // no sort...
        {
            if (// search for body
            body == null) {
                Iterator<Part> it = part_panels.keySet().iterator();
                while (it.hasNext()) {
                    Part part = it.next();
                    DataRenderer dr = part_panels.get(part);
                    IRecordInternal state = new PageNumberState(formData, plist);
                    if (part.getPartType() == Part.BODY) {
                        body = part;
                        continue;
                    }
                    if (part.getPartType() != Part.LEADING_SUBSUMMARY && part.getPartType() != Part.TRAILING_SUBSUMMARY) {
                        plist.setNonRepeatingPart(part.getPartType(), new DataRendererDefinition(this, renderParent, part, dr, state));
                        continue;
                    }
                }
            }
            if (body == null) {
                // a virtual body (when no body is placed in the parts)
                root = new PartNode(this, null, null, renderParent, null);
            } else // if (body != null)
            {
                // the body
                root = new PartNode(this, body, part_panels.get(body), renderParent, null);
            }
        }
    }
    try {
        // $NON-NLS-1$
        application.getRuntimeProperties().put("isPrinting", Boolean.TRUE);
        long t1 = System.currentTimeMillis();
        // fill the renderers with data
        if (root != null) {
            // dump chain
            // $NON-NLS-1$
            Debug.trace("Root " + root);
            QuerySelect sqlString = ((FoundSet) formData).getQuerySelectForReading();
            Table table = formData.getSQLSheet().getTable();
            FoundSet fs = (FoundSet) ((FoundSetManager) application.getFoundSetManager()).getNewFoundSet(table, null, sortColumns);
            fs.browseAll(sqlString);
            long t3 = System.currentTimeMillis();
            List<DataRendererDefinition> childRetval = root.process(this, fs, table, sqlString);
            long t4 = System.currentTimeMillis();
            if (Debug.tracing()) {
                // $NON-NLS-1$ //$NON-NLS-2$
                Debug.trace("Database queries took " + ((t4 - t3) / 1000f) + " second");
            }
            if (childRetval != null) {
                for (int i = 0; i < childRetval.size(); i++) {
                    plist.addPanel(childRetval.get(i));
                }
            }
        }
        plist.finish();
        long t2 = System.currentTimeMillis();
        int pageCount = plist.getNumberOfPages();
        // dump
        if (Debug.tracing()) {
            Debug.trace(plist);
            // $NON-NLS-1$ //$NON-NLS-2$
            Debug.trace("Generated " + pageCount / ((t2 - t1) / 1000f) + " printable pages per second");
        }
    } finally {
        // $NON-NLS-1$
        application.getRuntimeProperties().put("isPrinting", null);
    }
    renderParent.removeAll();
    return plist.getNumberOfPages();
}
Also used : Form(com.servoy.j2db.persistence.Form) DataRenderer(com.servoy.j2db.smart.dataui.DataRenderer) ArrayList(java.util.ArrayList) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) FormManager(com.servoy.j2db.FormManager) HashSet(java.util.HashSet) FormController(com.servoy.j2db.FormController) Table(com.servoy.j2db.persistence.Table) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) Dimension(java.awt.Dimension) QuerySelect(com.servoy.j2db.query.QuerySelect) StringTokenizer(java.util.StringTokenizer) Part(com.servoy.j2db.persistence.Part) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 22 with FormManager

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

the class FormLookupPanel method createFormPanel.

private FormController createFormPanel() {
    FormManager fm = (FormManager) application.getFormManager();
    FormController fp = fm.getFormController(formName, this);
    if (fp != null) {
        IFormUIInternal ui = fp.getFormUI();
        if (ui instanceof Component) {
            add((Component) ui, BorderLayout.CENTER);
            // just to be sure the cardlayout of main panel does return them as not visible
            ui.setComponentVisible(true);
            // delegate readOnly, really set it once from the form manager state
            fp.setReadOnly(fm.isFormReadOnly(formName));
            Container con = getParent();
            if (con != null && (con instanceof ITabPaneAlike) && !con.isEnabled()) {
                // reaply the isEnabled state of the tabpanel to its child tabs (tabs are added after enabled state is set); only if the tabpanel is disabled
                this.setEnabled(con.isEnabled());
            }
            while (con != null) {
                if (con instanceof IFormUIInternal) {
                    fp.getUndoManager().setFormUndoManager(((IFormUIInternal) con).getUndoManager());
                    break;
                }
                con = con.getParent();
            }
            // invalidate later so that everything is first visible (like the datamodel of a tableview)
            application.invokeLater(new Runnable() {

                public void run() {
                    validate();
                }
            });
        }
    }
    return fp;
}
Also used : FormController(com.servoy.j2db.FormController) Container(java.awt.Container) FormManager(com.servoy.j2db.FormManager) ITabPaneAlike(com.servoy.j2db.util.ITabPaneAlike) IFormUIInternal(com.servoy.j2db.IFormUIInternal) Component(java.awt.Component)

Example 23 with FormManager

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

the class JSDataSourceNode method removeMethod.

/**
 * Removes the foundset method specified by name.
 *
 * @sample
 * var method1 = solutionModel.getDataSourceNode("db:/example_data/customers").newMethod("function myFoundsetMethod1() { return 123; }");
 * var method2 = solutionModel.getDataSourceNode("db:/example_data/customers").newCalculation("function myFoundsetMethod2() { return '20'; }");
 *
 * var m = solutionModel.getDataSourceNode("db:/example_data/customers").getMethod("myFoundsetMethod1");
 * application.output("Name: " + m.getName());
 *
 * solutionModel.getDataSourceNode("db:/example_data/customers").removeMethod("myFoundsetMethod1");
 * m = solutionModel.getDataSourceNode("db:/example_data/customers").getCalculation("myFoundsetMethod1");
 * if (m != null) { application.output("myFoundsetMethod1 could not be removed."); }
 *
 * var allMethods = solutionModel.getDataSourceNode("db:/example_data/customers").getMethod();
 * for (var i = 0; i < allMethods; i++)
 * {
 * 	application.output(allMethods[i]);
 * }
 *
 * @param name the name of the method to be removed
 *
 * @return true if the removal was successful, false otherwise
 */
@JSFunction
public boolean removeMethod(String name) {
    try {
        FlattenedSolution fs = application.getFlattenedSolution();
        TableNode tablenode = fs.getSolutionCopyTableNode(dataSource);
        ScriptMethod sc = tablenode.getFoundsetMethod(name);
        if (sc != null) {
            tablenode.removeChild(sc);
            return true;
        }
        // it is a design time method, therefore we "hide" it
        sc = fs.getFoundsetMethod(name, dataSource);
        if (sc != null) {
            fs.addToRemovedPersists(sc);
            if (application.getFormManager() instanceof FormManager)
                ((FormManager) application.getFormManager()).fillScriptMenu();
            return true;
        }
        // not found
        return false;
    } catch (RepositoryException e) {
        throw new RuntimeException(e);
    }
}
Also used : FormManager(com.servoy.j2db.FormManager) TableNode(com.servoy.j2db.persistence.TableNode) FlattenedSolution(com.servoy.j2db.FlattenedSolution) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) JSFunction(org.mozilla.javascript.annotations.JSFunction)

Example 24 with FormManager

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

the class J2DBClient method createMainPanel.

protected void createMainPanel() {
    // init the frame
    frame = new JFrame();
    frame.addWindowFocusListener(new WindowAdapter() {

        @Override
        public void windowGainedFocus(WindowEvent e) {
            if (getFormManager() != null)
                ((FormManager) getFormManager()).setCurrentContainer(null, null);
        }
    });
    rootPane = frame.getRootPane();
    InputMap im = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    // $NON-NLS-1$
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.SHIFT_DOWN_MASK + InputEvent.CTRL_DOWN_MASK + InputEvent.ALT_DOWN_MASK), "enabletracing");
    ActionMap am = rootPane.getActionMap();
    am.put("enabletracing", new // $NON-NLS-1$
    AbstractAction() {

        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            Debug.toggleTracing();
        }
    });
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.setName(IApplication.APP_WINDOW_NAME);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.setTitle(getDisplayApplicationName());
    // $NON-NLS-1$ //$NON-NLS-2$
    String branding = getSettings().getProperty("servoy.branding", "false");
    // $NON-NLS-1$
    String windowicon = getSettings().getProperty("servoy.branding.windowicon");
    if (// $NON-NLS-1$
    branding.equals("true") && windowicon != null && Utils.isSwingClient(getApplicationType())) {
        frame.setIconImage(getWindowIcon(windowicon));
    } else {
        // $NON-NLS-1$
        frame.setIconImage(loadImage("windowicon.png").getImage());
    }
    mainPanel = new MainPanel(this, null);
    mainPanel.setPreferredSize(new Dimension(Settings.INITIAL_CLIENT_WIDTH, Settings.INITIAL_CLIENT_HEIGHT));
    frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
    frame.pack();
    // $NON-NLS-1$
    Debug.trace("Main frame packed");
    // block when visible
    Component glassPane = rootPane.getGlassPane();
    glassPane.addMouseListener(new MouseAdapter() {
    });
    glassPane.addMouseMotionListener(new MouseMotionAdapter() {
    });
    glassPane.addKeyListener(new KeyAdapter() {
    });
}
Also used : ActionMap(javax.swing.ActionMap) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) IBasicFormManager(com.servoy.j2db.IBasicFormManager) FormManager(com.servoy.j2db.FormManager) WindowEvent(java.awt.event.WindowEvent) InputMap(javax.swing.InputMap) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 25 with FormManager

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

the class SwingForm method printPreview.

/**
 * @see com.servoy.j2db.IFormUIInternal#printPreview(boolean, boolean, java.awt.print.PrinterJob)
 */
public void printPreview(boolean showDialogs, boolean printCurrentRecordOnly, int zoomFactor, PrinterJob printerJob) {
    ISmartClientApplication application = (ISmartClientApplication) formController.getApplication();
    try {
        // TODO do a print preview even if records are not saved?
        if (application.getFoundSetManager().getEditRecordList().stopEditing(false) != ISaveConstants.STOPPED)
            return;
        IFoundSetInternal set = formController.getFormModel();
        if (set == null) {
            if (showDialogs) {
                // $NON-NLS-1$
                JOptionPane.showMessageDialog(// $NON-NLS-1$
                application.getMainApplicationFrame(), // $NON-NLS-1$
                Messages.getString("servoy.formPanel.error.noRecordsToPrint"), Messages.getString("servoy.general.warning"), // $NON-NLS-1$
                JOptionPane.INFORMATION_MESSAGE);
            }
            return;
        }
        if (showDialogs) {
            if (// test if foundset is zero. if so ask if really want to print/preview
            set.getSize() == 0) {
                int val = JOptionPane.showConfirmDialog(application.getMainApplicationFrame(), // $NON-NLS-1$//$NON-NLS-2$
                Messages.getString("servoy.formPanel.error.noRecordsToPrint"), // $NON-NLS-1$//$NON-NLS-2$
                Messages.getString("servoy.general.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
                if (val != JOptionPane.OK_OPTION) {
                    return;
                }
            } else if (!printCurrentRecordOnly) {
                int option = willingToPrint(set);
                if (option == 2) {
                    printCurrentRecordOnly = true;
                } else if (option == 1) {
                    // cancel
                    return;
                }
            }
        }
        if (printCurrentRecordOnly) {
            set = set.copyCurrentRecordFoundSet();
        }
        ((FormManager) application.getFormManager()).showPreview(formController, set, zoomFactor, printerJob);
    } catch (Exception ex) {
        // $NON-NLS-1$
        application.reportError(Messages.getString("servoy.formPanel.error.printPreview"), ex);
    }
}
Also used : ISmartClientApplication(com.servoy.j2db.ISmartClientApplication) FormManager(com.servoy.j2db.FormManager) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Point(java.awt.Point)

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