Search in sources :

Example 51 with FormController

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

the class DataRenderer method getListCellRendererComponent.

public Component getListCellRendererComponent(JComponent rendererParentCanBeNull, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    this.selected = isSelected;
    // if (isSelected)
    // {
    // setBorder(focusBorder);
    // }
    // else
    // {
    // setBorder(noFocusBorder);
    // }
    boolean bgRowColorSet = false;
    // if in Renderer mode for a the List then a renderer can't stop editing.
    if (value instanceof IRecordInternal) {
        IRecordInternal val = (IRecordInternal) value;
        // if in list view, we need to set the render state for each list item here
        if (rendererParentCanBeNull != null) {
            DataAdapterList.setDataRendererComponentsRenderState(this, val);
        }
        dataAdapterList.setRecord(val, !isRenderer);
        // setOpaque(true);
        if (index != -1) {
            boolean specialStateCase = (val instanceof PrototypeState || val instanceof FindState || val.getRawData() == null);
            if (strRowBGColorProvider == null && !specialStateCase) {
                if (rendererParentCanBeNull instanceof ISupportRowBGColorScript) {
                    strRowBGColorProvider = ((ISupportRowBGColorScript) rendererParentCanBeNull).getRowBGColorScript();
                    rowBGColorArgs = ((ISupportRowBGColorScript) rendererParentCanBeNull).getRowBGColorArgs();
                }
                // $NON-NLS-1$
                if (strRowBGColorProvider == null)
                    strRowBGColorProvider = "servoy_row_bgcolor";
                isRowBGColorCalculation = val.getRawData().containsCalculation(strRowBGColorProvider);
                if (!isRowBGColorCalculation && strRowBGColorProvider.equals("servoy_row_bgcolor")) {
                    // $NON-NLS-1$
                    strRowBGColorProvider = "";
                }
                defaultColor = getBackground();
            }
            if (// $NON-NLS-1$
            strRowBGColorProvider != null && !"".equals(strRowBGColorProvider)) {
                IFoundSetInternal parent = val.getParentFoundSet();
                if (parent != null && !specialStateCase) {
                    Object bg_color = null;
                    if (isRowBGColorCalculation) {
                        bg_color = parent.getCalculationValue(val, strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(index), new Boolean(isSelected), null, null, Boolean.FALSE }), Utils.parseJSExpressions(rowBGColorArgs)), null);
                    } else {
                        try {
                            FormController currentForm = dataAdapterList.getFormController();
                            bg_color = currentForm.executeFunction(strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(index), new Boolean(isSelected), null, null, currentForm.getName(), val, Boolean.FALSE }), Utils.parseJSExpressions(rowBGColorArgs)), false, null, true, null);
                        } catch (Exception ex) {
                            Debug.error(ex);
                        }
                    }
                    if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
                        bgRowColorSet = true;
                        setBackground(PersistHelper.createColor(bg_color.toString()));
                    } else {
                        setBackground(defaultColor);
                    }
                } else {
                    setBackground(defaultColor);
                }
            }
            if (rendererParentCanBeNull instanceof ISupportRowStyling && !specialStateCase && !bgRowColorSet) {
                ISupportRowStyling oddEvenStyling = (ISupportRowStyling) rendererParentCanBeNull;
                IStyleSheet ss = oddEvenStyling.getRowStyleSheet();
                IStyleRule style = isSelected ? oddEvenStyling.getRowSelectedStyle() : null;
                if (style != null && style.getAttributeCount() == 0)
                    style = null;
                if (style == null) {
                    // because index = 0 means record = 1
                    style = (index % 2 == 0) ? oddEvenStyling.getRowOddStyle() : oddEvenStyling.getRowEvenStyle();
                }
                if (ss != null && style != null) {
                    Color bgColor = ss.getBackground(style);
                    if (bgColor != null) {
                        showSelection = false;
                        bgRowColorSet = true;
                        setBackground(bgColor);
                    }
                }
            }
        }
    }
    if (rendererParentCanBeNull != null) {
        if (rendererParentCanBeNull.isEnabled() != isEnabled()) {
            // Debug.trace(donotusecanbenullifinrecondview.getName()+" "+donotusecanbenullifinrecondview.isEnabled());
            // needed for portals
            setEnabled(rendererParentCanBeNull.isEnabled());
        }
        if (bgRowColorSet && !isOpaque()) {
            setOpaque(true);
        }
        dataRendererOnRenderWrapper.getRenderEventExecutor().fireOnRender(hasFocus());
    }
    return this;
}
Also used : FormController(com.servoy.j2db.FormController) ISupportRowBGColorScript(com.servoy.j2db.ui.ISupportRowBGColorScript) Undefined(org.mozilla.javascript.Undefined) ISupportRowStyling(com.servoy.j2db.ui.ISupportRowStyling) IStyleSheet(com.servoy.j2db.util.IStyleSheet) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Color(java.awt.Color) FindState(com.servoy.j2db.dataprocessing.FindState) IStyleRule(com.servoy.j2db.util.IStyleRule) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Example 52 with FormController

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

the class CellAdapter method getBgColor.

private Color getBgColor(JTable jtable, boolean isSelected, int row, boolean isEdited) {
    Color bgColor = null;
    IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
    boolean specialStateCase = (state instanceof PrototypeState || state instanceof FindState || state == null || state.getRawData() == null);
    if (/* !(renderer instanceof JButton) && */
    !specialStateCase) {
        ISwingFoundSet foundset = (ISwingFoundSet) jtable.getModel();
        bgColor = (Color) getStyleAttributeForRow(jtable, isSelected, row, ISupportRowStyling.ATTRIBUTE.BGCOLOR);
        String strRowBGColorProvider = null;
        List<Object> rowBGColorArgs = null;
        if (jtable instanceof IView) {
            strRowBGColorProvider = ((IView) jtable).getRowBGColorScript();
            rowBGColorArgs = ((IView) jtable).getRowBGColorArgs();
        }
        // $NON-NLS-1$
        if (strRowBGColorProvider == null)
            strRowBGColorProvider = "servoy_row_bgcolor";
        boolean isRowBGColorCalculation = state.getRawData().containsCalculation(strRowBGColorProvider);
        if (// $NON-NLS-1$
        !isRowBGColorCalculation && strRowBGColorProvider.equals("servoy_row_bgcolor")) {
            // $NON-NLS-1$
            strRowBGColorProvider = "";
        }
        if (// $NON-NLS-1$
        strRowBGColorProvider != null && !"".equals(strRowBGColorProvider)) {
            Object bg_color = null;
            // TODO this should be done better....
            Record.VALIDATE_CALCS.set(Boolean.FALSE);
            try {
                String type = (editor instanceof IScriptableProvider && ((IScriptableProvider) editor).getScriptObject() instanceof IRuntimeComponent) ? ((IRuntimeComponent) ((IScriptableProvider) editor).getScriptObject()).getElementType() : null;
                String nm = (editor instanceof IDisplayData) ? ((IDisplayData) editor).getDataProviderID() : null;
                if (isRowBGColorCalculation) {
                    bg_color = foundset.getCalculationValue(state, strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(row), new Boolean(isSelected), type, nm, new Boolean(isEdited) }), Utils.parseJSExpressions(rowBGColorArgs)), null);
                } else {
                    try {
                        FormController currentForm = dal.getFormController();
                        bg_color = currentForm.executeFunction(strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(row), new Boolean(isSelected), type, nm, currentForm.getName(), state, new Boolean(isEdited) }), Utils.parseJSExpressions(rowBGColorArgs)), false, null, true, null);
                    } catch (Exception ex) {
                        Debug.error(ex);
                    }
                }
            } finally {
                Record.VALIDATE_CALCS.set(null);
            }
            if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
                bgColor = PersistHelper.createColor(bg_color.toString());
            }
        }
    }
    return bgColor;
}
Also used : FormController(com.servoy.j2db.FormController) Undefined(org.mozilla.javascript.Undefined) IView(com.servoy.j2db.IView) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Color(java.awt.Color) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) ServoyException(com.servoy.j2db.util.ServoyException) ParseException(java.text.ParseException) ApplicationException(com.servoy.j2db.ApplicationException) FindState(com.servoy.j2db.dataprocessing.FindState) EventObject(java.util.EventObject) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider)

Example 53 with FormController

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

the class FormLookupPanel method getDefaultSort.

public List<SortColumn> getDefaultSort() {
    if (defaultSort == null) {
        try {
            FormController fc = getFormPanel();
            if (fc != null) {
                Form f = fc.getForm();
                defaultSort = ((FoundSetManager) application.getFoundSetManager()).getSortColumns(f.getDataSource(), f.getInitialSort());
            }
        } catch (RepositoryException e) {
            Debug.error(e);
            defaultSort = new ArrayList<SortColumn>(1);
        }
    }
    return defaultSort;
}
Also used : FormController(com.servoy.j2db.FormController) Form(com.servoy.j2db.persistence.Form) ArrayList(java.util.ArrayList) RepositoryException(com.servoy.j2db.persistence.RepositoryException)

Example 54 with FormController

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

the class SpecialSplitPane method setForm.

public boolean setForm(boolean bLeftForm, Object form, Object relation) {
    FormController f = null;
    String fName = null;
    boolean readOnly = false;
    if (form instanceof FormController) {
        f = (FormController) form;
        readOnly = f.isReadOnly();
    }
    if (form instanceof FormController.JSForm) {
        f = (FormController) ((FormController.JSForm) form).getFormPanel();
        readOnly = f.isReadOnly();
    }
    if (f != null)
        fName = f.getName();
    if (form instanceof String)
        fName = (String) form;
    if (fName != null) {
        String name = fName;
        RelatedFoundSet relatedFs = null;
        String relationName = null;
        if (relation instanceof RelatedFoundSet) {
            relatedFs = (RelatedFoundSet) relation;
        } else if (relation instanceof String) {
            relationName = (String) relation;
        }
        if (relatedFs != null) {
            relationName = relatedFs.getRelationName();
            if (f != null && !relatedFs.getDataSource().equals(f.getDataSource())) {
                return false;
            }
        // TODO do this check to check if the parent table has this relation? How to get the parent table
        // Table parentTable = null;
        // application.getSolution().getRelations(Solution.SOLUTION+Solution.MODULES, parentTable, true, false);
        }
        IFormLookupPanel replacedForm = bLeftForm ? getLeftForm() : getRightForm();
        if (replacedForm != null) {
            List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
            boolean bNotifyVisibleForm = notifyVisibleForm(false, (FormLookupPanel) replacedForm, invokeLaterRunnables);
            Utils.invokeLater(application, invokeLaterRunnables);
            if (!bNotifyVisibleForm)
                return false;
        }
        FormLookupPanel flp = createFormLookupPanel(name, relationName, fName);
        if (f != null)
            flp.setReadOnly(readOnly);
        if (bLeftForm)
            setLeftForm(flp);
        else
            setRightForm(flp);
        if (relatedFs != null) {
            FormController fp = flp.getFormPanel();
            if (fp != null && flp.getRelationName() != null && flp.getRelationName().equals(relationName)) {
                fp.loadData(relatedFs, null);
            }
        }
        List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
        boolean bNotifyVisibleForm = notifyVisibleForm(true, flp, invokeLaterRunnables);
        Utils.invokeLater(application, invokeLaterRunnables);
        return bNotifyVisibleForm;
    } else if (form == null) {
        IFormLookupPanel replacedForm = bLeftForm ? getLeftForm() : getRightForm();
        if (replacedForm != null) {
            List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
            boolean bNotifyVisibleForm = notifyVisibleForm(false, (FormLookupPanel) replacedForm, invokeLaterRunnables);
            Utils.invokeLater(application, invokeLaterRunnables);
            if (!bNotifyVisibleForm)
                return false;
        }
        if (bLeftForm)
            setLeftForm(null);
        else
            setRightForm(null);
        return true;
    }
    return false;
}
Also used : FormController(com.servoy.j2db.FormController) RelatedFoundSet(com.servoy.j2db.dataprocessing.RelatedFoundSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IFormLookupPanel(com.servoy.j2db.ui.IFormLookupPanel) IFormLookupPanel(com.servoy.j2db.ui.IFormLookupPanel)

Example 55 with FormController

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

the class SpecialTabPanel method showFoundSet.

protected void showFoundSet(FormLookupPanel flp, IRecordInternal parentState, List<SortColumn> sort) {
    deregisterSelectionListeners();
    if (!flp.isReady())
        return;
    try {
        FormController fp = flp.getFormPanel();
        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
        int i = enclosingComponent.getTabIndex(flp);
        String element = i < originalTabText.size() ? originalTabText.get(i) : null;
        if (element != null) {
            enclosingComponent.setTitleAt(i, Text.processTags(element, resolver));
        }
        String tooltip = i < originalTabTooltip.size() ? originalTabTooltip.get(i) : null;
        if (tooltip != null) {
            enclosingComponent.setToolTipTextAt(i, Text.processTags(tooltip, resolver));
        }
    } catch (RuntimeException re) {
        application.handleException("Error setting the foundset of the relation " + flp.getRelationName() + " on the tab with form " + flp.getFormName(), re);
        throw re;
    }
}
Also used : FormController(com.servoy.j2db.FormController) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ITagResolver(com.servoy.base.util.ITagResolver)

Aggregations

FormController (com.servoy.j2db.FormController)70 FormManager (com.servoy.j2db.FormManager)15 Form (com.servoy.j2db.persistence.Form)13 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)12 RepositoryException (com.servoy.j2db.persistence.RepositoryException)10 Point (java.awt.Point)10 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)9 ArrayList (java.util.ArrayList)9 IFormController (com.servoy.j2db.IFormController)8 BasicFormController (com.servoy.j2db.BasicFormController)7 IForm (com.servoy.j2db.IForm)7 WebForm (com.servoy.j2db.server.headlessclient.WebForm)7 FlattenedSolution (com.servoy.j2db.FlattenedSolution)6 IFormUIInternal (com.servoy.j2db.IFormUIInternal)5 IDataProvider (com.servoy.j2db.persistence.IDataProvider)5 List (java.util.List)5 ApplicationException (com.servoy.j2db.ApplicationException)4 IMainContainer (com.servoy.j2db.IMainContainer)4 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)4 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)4