Search in sources :

Example 1 with FormManager

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

the class ComponentFactory method createBean.

protected static IComponent createBean(IApplication application, Form form, Bean bean, FlattenedSolution flattenedSolution) {
    IComponent c = null;
    try {
        Object obj = getBeanInstanceFromXML(application, bean.getBeanClassName(), bean.getBeanXML());
        if (flattenedSolution != null && obj != null) {
            obj = flattenedSolution.setBeanDesignInstance(bean, obj);
        }
        if (obj instanceof Component) {
            ((Component) obj).setName(bean.getName());
        } else if (obj instanceof IComponent) {
            ((IComponent) obj).setName(bean.getName());
        }
        if (obj instanceof IServoyAwareBean) {
            ((IServoyAwareBean) obj).initialize((IClientPluginAccess) application.getPluginAccess());
        }
        if (obj instanceof IServoyBeanFactory) {
            testReturnTypesForBean(application, obj);
            obj = ((IServoyBeanFactory) obj).getBeanInstance(application.getApplicationType(), (IClientPluginAccess) application.getPluginAccess(), new Object[] { ComponentFactory.getWebID(form, bean), form.getName(), form.getStyleName() });
        }
        testReturnTypesForBean(application, obj);
        if (obj instanceof Applet) {
            ((FormManager) application.getFormManager()).initializeApplet((Applet) obj, bean.getSize());
        }
        if (obj == null) {
            c = application.getItemFactory().createLabel(ComponentFactory.getWebID(form, bean), "bean missing " + bean.getBeanClassName());
        } else if (!(obj instanceof java.awt.Component) && !(obj instanceof IComponent)) {
            c = application.getItemFactory().createInvisibleBean(ComponentFactory.getWebID(form, bean), obj);
        } else if (!(obj instanceof IComponent)) {
            c = application.getItemFactory().createBeanHolder(ComponentFactory.getWebID(form, bean), (Component) obj, bean.getAnchors());
        } else {
            c = (IComponent) obj;
        }
        // beans do not store the transparent property, keep the value from component
        boolean isOpaque = c.isOpaque();
        applyBasicComponentProperties(application, c, bean, null);
        c.setOpaque(isOpaque);
    } catch (// sometimes setting size or location throws exception or even error...create label instead
    Throwable e) {
        Debug.error(e);
        c = application.getItemFactory().createLabel(bean.getName(), "error acessing bean" + bean.getBeanClassName());
        java.awt.Dimension dim = bean.getSize();
        if (dim != null)
            c.setSize(bean.getSize());
    }
    return c;
}
Also used : IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) IServoyBeanFactory(com.servoy.j2db.IServoyBeanFactory) Applet(java.applet.Applet) FormManager(com.servoy.j2db.FormManager) IComponent(com.servoy.j2db.ui.IComponent) IClientPluginAccess(com.servoy.j2db.plugins.IClientPluginAccess) ServoyJSONObject(com.servoy.j2db.util.ServoyJSONObject) Dimension(java.awt.Dimension) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) AbstractRuntimeValuelistComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeValuelistComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) IAnchoredComponent(com.servoy.j2db.ui.IAnchoredComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) WebComponent(com.servoy.j2db.persistence.WebComponent) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Example 2 with FormManager

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

the class DataProviderEditor method fillDataProviderList.

protected void fillDataProviderList() {
    try {
        ITable table = null;
        if (definedTable == null) {
            FormManager fm = (FormManager) application.getFormManager();
            FormController fc = fm.getCurrentMainShowingFormController();
            if (fc != null) {
                Form form = fc.getForm();
                table = application.getFlattenedSolution().getTable(form.getDataSource());
            }
        } else {
            if (!showRelatedOptionsOnly)
                table = definedTable;
        }
        DefaultListModel model = (DefaultListModel) list.getModel();
        model.removeAllElements();
        if (showNoneOption)
            model.addElement("-none-");
        if (!showColumnsOnly)
            model.addElement("*columns");
        Object o = relationsComboBox.getSelectedItem();
        if (o != null) {
            if (o instanceof String) {
            // table = form.getTable();
            } else {
                table = application.getFlattenedSolution().getTable(((Relation) o).getForeignDataSource());
            }
            if (table != null) {
                Iterator<Column> it = table.getColumnsSortedByName();
                while (it.hasNext()) {
                    IColumn c = it.next();
                    ColumnInfo ci = c.getColumnInfo();
                    if (ci != null && ci.isExcluded()) {
                        continue;
                    }
                    if (hideMediaColumns) {
                        // use dataprovider type as defined by column converter
                        ComponentFormat componentFormat = ComponentFormat.getComponentFormat(null, c, application);
                        if (componentFormat.dpType == IColumnTypes.MEDIA) {
                            continue;
                        }
                    }
                    model.addElement(c);
                }
            }
        }
        FlattenedSolution s = application.getFlattenedSolution();
        if (table != null && !showColumnsOnly) {
            Iterator it = s.getScriptCalculations(table, true);
            if (it.hasNext()) {
                model.addElement("*calculations");
            }
            while (it.hasNext()) {
                ScriptCalculation sc = (ScriptCalculation) it.next();
                for (int i = 0; i < model.size(); i++) {
                    Object obj = model.elementAt(i);
                    if (obj instanceof IDataProvider) {
                        IDataProvider dp = (IDataProvider) obj;
                        if (dp.getDataProviderID().equals(sc.getDataProviderID())) {
                            // remove the column from the list if use by
                            model.remove(i);
                            // stored calc
                            break;
                        }
                    }
                }
                model.addElement(sc);
            }
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
            Iterator it3 = s.getAggregateVariables(table, true);
            if (it3.hasNext()) {
                model.addElement("*aggregates");
            }
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (table != null && showColumnsOnly && showSortableOnly) {
            Iterator it3 = s.getAggregateVariables(table, true);
            while (it3.hasNext()) {
                model.addElement(it3.next());
            }
        }
        if (showGlobalsOption && showColumnsOnly) {
            Iterator it2 = s.getScriptVariables(true);
            if (it2.hasNext()) {
                model.addElement("*globals");
            }
            while (it2.hasNext()) {
                model.addElement(it2.next());
            }
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
}
Also used : FormController(com.servoy.j2db.FormController) Form(com.servoy.j2db.persistence.Form) DefaultListModel(javax.swing.DefaultListModel) ColumnInfo(com.servoy.j2db.persistence.ColumnInfo) FlattenedSolution(com.servoy.j2db.FlattenedSolution) IDataProvider(com.servoy.j2db.persistence.IDataProvider) ScriptCalculation(com.servoy.j2db.persistence.ScriptCalculation) Relation(com.servoy.j2db.persistence.Relation) FormManager(com.servoy.j2db.FormManager) IColumn(com.servoy.j2db.persistence.IColumn) Column(com.servoy.j2db.persistence.Column) IColumn(com.servoy.j2db.persistence.IColumn) Iterator(java.util.Iterator) ITable(com.servoy.j2db.persistence.ITable) ComponentFormat(com.servoy.j2db.component.ComponentFormat)

Example 3 with FormManager

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

the class DataProviderEditor method fillRelationsComboBox.

protected void fillRelationsComboBox(Relation[] relations) throws Exception {
    boolean relationsAdded = false;
    String item = null;
    ITable table = null;
    if (definedTable == null) {
        FormManager fm = (FormManager) application.getFormManager();
        FormController fc = fm.getCurrentMainShowingFormController();
        if (fc != null) {
            Form form = fc.getForm();
            table = application.getFlattenedSolution().getTable(form.getDataSource());
        }
    } else {
        table = definedTable;
    // definedTable = null;//clear!
    }
    if (relationsComboBox.getItemCount() > 0)
        relationsComboBox.removeAllItems();
    Iterator it = application.getFlattenedSolution().getRelations(table, true, true);
    while (it.hasNext()) {
        Relation rel = (Relation) it.next();
        if (!showSortableOnly || (showSortableOnly && rel.isUsableInSort())) {
            relationsComboBox.addItem(rel);
            relationsAdded = true;
        }
    }
    if (!showRelatedOptionsOnly) {
        // $NON-NLS-1$
        String tname = "";
        if (table != null)
            tname = table.getName();
        item = "DataProviders for " + tname;
        if (relationsComboBox.getModel().getSize() > 0) {
            relationsComboBox.insertItemAt(item, 0);
        } else {
            relationsComboBox.addItem(item);
        }
    }
    if (relations == null) {
        if (item == null) {
            if (relationsComboBox.getModel().getSize() != 0)
                relationsComboBox.setSelectedIndex(0);
        } else {
            relationsComboBox.setSelectedItem(item);
        }
    } else {
        relationsComboBox.setSelectedItem(relations[0]);
    }
    relationsComboBox.setEnabled(relationsAdded && !showRelatedOptionsOnly);
}
Also used : FormController(com.servoy.j2db.FormController) Relation(com.servoy.j2db.persistence.Relation) FormManager(com.servoy.j2db.FormManager) Form(com.servoy.j2db.persistence.Form) Iterator(java.util.Iterator) ITable(com.servoy.j2db.persistence.ITable)

Example 4 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 5 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)

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