Search in sources :

Example 31 with IRecordInternal

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

the class PageDefinition method toXML.

public void toXML(Writer w) throws IOException {
    // $NON-NLS-1$
    w.write("<PAGE>");
    // $NON-NLS-1$ //$NON-NLS-2$
    w.write("<PARTS count=\"" + panels.size() + "\" >");
    for (int i = 0; i < panels.size(); i++) {
        DataRendererDefinition drd = panels.get(i);
        IRecordInternal state = drd.getState();
        if (state instanceof PageNumberState) {
            ((PageNumberState) state).initPagePositionAndSize(this);
        }
        DataRenderer partpane = drd.getDataRenderer();
        // fill with data
        partpane.getDataAdapterList().setRecord(state, true);
        drd.toXML(w);
    }
    // $NON-NLS-1$
    w.write("</PARTS>");
    // $NON-NLS-1$
    w.write("</PAGE>");
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) DataRenderer(com.servoy.j2db.smart.dataui.DataRenderer)

Example 32 with IRecordInternal

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

the class PageNumberState method initPagePositionAndSize.

void initPagePositionAndSize(PageDefinition pd) {
    Iterator<DataRendererDefinition> it = pd.getPanels().iterator();
    while (it.hasNext()) {
        DataRendererDefinition drd = it.next();
        if (drd != null && drd.getPart() != null && drd.getPart().getPartType() == Part.BODY) {
            IRecordInternal rec = drd.getState();
            if (rec != null) {
                delegate_to_record = rec.getParentFoundSet();
                delegate_record_index = delegate_to_record.getRecordIndex(rec);
            }
        // do not break we want the last body record
        }
    }
    currentPage = list.getPageNumber(pd);
    totalPages = list.getPageSectionLength(pd);
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal)

Example 33 with IRecordInternal

use of com.servoy.j2db.dataprocessing.IRecordInternal 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 34 with IRecordInternal

use of com.servoy.j2db.dataprocessing.IRecordInternal 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 35 with IRecordInternal

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

the class CellAdapter method getTableCellEditorComponent.

/*
	 * @see TableCellEditor#getTableCellEditorComponent(JTable, Object, boolean, int, int)
	 */
public Component getTableCellEditorComponent(JTable jtable, Object value, boolean isSelected, int row, int column) {
    if (editor == null || !isVisible(editor) || !(jtable.getModel() instanceof IFoundSetInternal)) {
        return empty;
    }
    IRecordInternal newRec = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
    if (isSelected) {
        Color bgColor = getBgColor(jtable, isSelected, row, true);
        if (bgColor != null && editor instanceof JComponent)
            ((JComponent) editor).setOpaque(true);
        if (bgColor == null) {
            // unselected background is the default background color of the editor.
            bgColor = unselectedBackground;
        }
        lastEditorBgColor = bgColor;
        if (editor instanceof ISupportsDoubleBackground) {
            ((ISupportsDoubleBackground) editor).setBackground(bgColor, unselectedBackground);
        } else {
            editor.setBackground(bgColor);
        }
        Color fgColor = getFgColor(jtable, isSelected, row);
        if (fgColor == null) {
            // unselected foreground is the default foreground color of the editor.
            fgColor = unselectedForeground;
        }
        lastEditorFgColor = fgColor;
        if (editor instanceof ISupportsDoubleBackground) {
            ((ISupportsDoubleBackground) editor).setForeground(fgColor, unselectedForeground);
        } else {
            editor.setForeground(fgColor);
        }
        Font font = getFont(jtable, isSelected, row);
        if (font == null) {
            // unselected font is the default font of the editor.
            font = unselectedFont;
        }
        lastEditorFont = font;
        editor.setFont(font);
        Border styleBorder = getBorder(jtable, isSelected, row);
        if (styleBorder != null && editor instanceof JComponent) {
            if (editor instanceof AbstractButton && !((AbstractButton) editor).isBorderPainted()) {
                ((AbstractButton) editor).setBorderPainted(true);
            }
            Border marginBorder = null;
            if (noFocusBorder instanceof EmptyBorder) {
                marginBorder = noFocusBorder;
            } else if (noFocusBorder instanceof CompoundBorder && ((CompoundBorder) noFocusBorder).getInsideBorder() instanceof EmptyBorder) {
                marginBorder = ((CompoundBorder) noFocusBorder).getInsideBorder();
            }
            // if we have margin set on the component, keep it along with the style border
            if (marginBorder != null) {
                styleBorder = new CompoundBorder(styleBorder, marginBorder);
            }
            ((JComponent) editor).setBorder(styleBorder);
        }
    }
    // try
    // {
    // if (currentEditingState != null && newRec != currentEditingState && currentEditingState.isEditing())
    // {
    // currentEditingState.stopEditing();
    // }
    // }
    // catch (Exception e)
    // {
    // Debug.error(e);
    // }
    currentEditingState = newRec;
    if (currentEditingState != null) {
        if (editor instanceof IScriptableProvider) {
            IScriptable scriptable = ((IScriptableProvider) editor).getScriptObject();
            if (scriptable instanceof ISupportOnRenderCallback) {
                RenderEventExecutor renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
                if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
                    renderEventExecutor.setRenderState(currentEditingState, row, isSelected, true);
                }
            }
        }
        // if not enabled or not editable do not start the edit
        if (editor instanceof IDisplay && ((IDisplay) editor).isEnabled() && !((IDisplay) editor).isReadOnly()) {
            DisplaysAdapter.startEdit(dal, (IDisplay) editor, currentEditingState);
        }
        if (editor instanceof IDisplayRelatedData) {
            IDisplayRelatedData drd = (IDisplayRelatedData) editor;
            IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
            if (state != null) {
                drd.setRecord(state, true);
            }
        }
        if (// && dataProviderID != null)
        editor instanceof IDisplayData) {
            try {
                Object data = dal.getValueObject(currentEditingState, dataProviderID);
                if (data instanceof DbIdentValue) {
                    data = ((DbIdentValue) data).getPkValue();
                }
                convertAndSetValue(((IDisplayData) editor), data);
            } catch (IllegalArgumentException iae) {
                Debug.error(iae);
            }
        }
        if (editor instanceof IServoyAwareBean) {
            ((IServoyAwareBean) editor).setSelectedRecord(new ServoyBeanState(currentEditingState, dal.getFormScope()));
        }
        if (editor instanceof IScriptableProvider && !(editor instanceof IDisplayData) && !(editor instanceof IDisplayRelatedData)) {
            IScriptable scriptable = ((IScriptableProvider) editor).getScriptObject();
            if (scriptable instanceof ISupportOnRenderCallback) {
                RenderEventExecutor renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
                if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
                    renderEventExecutor.fireOnRender(editor instanceof JTextComponent ? ((JTextComponent) editor).isEditable() : false);
                }
            }
        }
    }
    return editor.isVisible() ? editor : empty;
}
Also used : AbstractButton(javax.swing.AbstractButton) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Color(java.awt.Color) JComponent(javax.swing.JComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) JTextComponent(javax.swing.text.JTextComponent) Font(java.awt.Font) IScriptable(com.servoy.j2db.scripting.IScriptable) IDisplayRelatedData(com.servoy.j2db.dataprocessing.IDisplayRelatedData) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) ServoyBeanState(com.servoy.j2db.component.ServoyBeanState) DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) CompoundBorder(javax.swing.border.CompoundBorder) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) EventObject(java.util.EventObject) EmptyBorder(javax.swing.border.EmptyBorder) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) SpecialMatteBorder(com.servoy.j2db.util.gui.SpecialMatteBorder) ISupportsDoubleBackground(com.servoy.j2db.ui.ISupportsDoubleBackground)

Aggregations

IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)63 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)26 Point (java.awt.Point)12 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)11 FormController (com.servoy.j2db.FormController)9 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)7 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)7 RepositoryException (com.servoy.j2db.persistence.RepositoryException)7 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)7 ServoyException (com.servoy.j2db.util.ServoyException)7 JSONObject (org.json.JSONObject)7 IComponent (com.servoy.j2db.ui.IComponent)6 ArrayList (java.util.ArrayList)6 FindState (com.servoy.j2db.dataprocessing.FindState)5 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)5 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)5 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)5 JComponent (javax.swing.JComponent)5 Component (org.apache.wicket.Component)5 ApplicationException (com.servoy.j2db.ApplicationException)4