Search in sources :

Example 36 with IRecordInternal

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

the class CellAdapter method getTableCellRendererComponent.

/*
	 * @see TableCellRenderer#getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int)
	 */
public Component getTableCellRendererComponent(JTable jtable, Object value, boolean isSelected, boolean hasFocus, final int row, final int column) {
    if (renderer == null || !isVisible(renderer) || !(jtable.getModel() instanceof IFoundSetInternal)) {
        return empty;
    }
    final ISwingFoundSet foundset = (ISwingFoundSet) jtable.getModel();
    if (foundset != tableViewFoundset) {
        // foundset changed
        this.tableViewFoundset = foundset;
        rowAndDataprovider.clear();
    }
    final IRecordInternal state;
    try {
        state = foundset.getRecord(row);
    } catch (RuntimeException re) {
        // $NON-NLS-1$
        Debug.error("Error getting row ", re);
        return empty;
    }
    RenderEventExecutor renderEventExecutor = null;
    IScriptRenderMethods renderable = null;
    if (renderer instanceof IScriptableProvider) {
        IScriptable scriptable = ((IScriptableProvider) renderer).getScriptObject();
        if (scriptable instanceof ISupportOnRenderCallback) {
            renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
            renderable = ((ISupportOnRenderCallback) scriptable).getRenderable();
        }
    }
    Color bgColor = getBgColor(jtable, isSelected, row, false);
    if (bgColor != null && renderer instanceof JComponent)
        ((JComponent) renderer).setOpaque(true);
    Color fgColor = getFgColor(jtable, isSelected, row);
    Font font = getFont(jtable, isSelected, row);
    // so that getLocation and getWidth in scripting on tableviews do work.
    if (editor != null && editor.getParent() == null) {
        Rectangle cellRect = jtable.getCellRect(row, column, false);
        editor.setLocation(cellRect.x, cellRect.y);
        editor.setSize(cellRect.width, cellRect.height);
    }
    boolean isRenderWithOnRender = renderEventExecutor != null && renderEventExecutor.hasRenderCallback() && renderable instanceof RenderableWrapper;
    Color renderBgColor = null;
    if (isSelected) {
        if (!isRenderWithOnRender || renderEventExecutor.isDifferentRenderState(state, row, isSelected)) {
            Color tableSelectionColor = jtable.getSelectionForeground();
            if (bgColor != null) {
                tableSelectionColor = adjustColorDifference(bgColor, tableSelectionColor);
            }
            ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
            renderer.setForeground(fgColor != null ? fgColor : tableSelectionColor);
            ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
            renderBgColor = (bgColor != null ? bgColor : jtable.getSelectionBackground());
            renderer.setBackground(renderBgColor);
            if (font != null) {
                ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FONT);
                renderer.setFont(font);
            }
        } else if (isRenderWithOnRender && foundset.getSize() == 1) {
            // if the foundset contains a single record, we need to force trigger onRender
            // because renderEventExecutor refers already to the changed render state
            renderEventExecutor.setRenderStateChanged();
        }
    } else {
        if (isRenderWithOnRender) {
            if (renderEventExecutor.isDifferentRenderState(state, row, isSelected)) {
                Color newBGColor = bgColor != null ? bgColor : componentBgColor;
                if (newBGColor != null) {
                    ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
                    renderBgColor = newBGColor;
                    renderer.setBackground(renderBgColor);
                }
                Color newFGColor = fgColor != null ? fgColor : componentFgColor;
                if (newFGColor != null) {
                    ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
                    renderer.setForeground(newFGColor);
                } else if (newBGColor != null) {
                    renderer.setForeground(adjustColorDifference(newBGColor, jtable.getForeground()));
                }
                Font newFont = font != null ? font : componentFont;
                if (newFont != null) {
                    ((RenderableWrapper) renderable).clearProperty(RenderableWrapper.PROPERTY_FONT);
                    renderer.setFont(newFont);
                }
            }
        } else {
            // now get the editors background. if we don't do that then scripting doesn't show up
            Color background = editor.getBackground();
            if (background != null && !background.equals(lastEditorBgColor)) {
                unselectedBackground = background;
                lastEditorBgColor = background;
            }
            Font editorFont = editor.getFont();
            if (editorFont != null && !editorFont.equals(lastEditorFont)) {
                unselectedFont = editorFont;
            }
            if (editor instanceof IDisplayData && ((IDisplayData) editor).isValueValid() || !(editor instanceof IDisplayData)) {
                Color foreground = editor.getForeground();
                if (foreground != null && !foreground.equals(lastEditorFgColor)) {
                    unselectedForeground = foreground;
                }
                Color currentForeground = (fgColor != null ? fgColor : (unselectedForeground != null) ? unselectedForeground : jtable.getForeground());
                renderer.setForeground(currentForeground);
            }
            Color currentColor = (bgColor != null ? bgColor : (unselectedBackground != null) ? unselectedBackground : jtable.getBackground());
            renderer.setBackground(currentColor);
            Font currentFont = (font != null ? font : (unselectedFont != null) ? unselectedFont : jtable.getFont());
            renderer.setFont(currentFont);
        }
    }
    if (renderer instanceof JComponent) {
        applyRowBorder((JComponent) renderer, jtable, isSelected, row, hasFocus);
    }
    // $NON-NLS-1$
    boolean printing = Utils.getAsBoolean(application.getRuntimeProperties().get("isPrinting"));
    if (renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
        renderEventExecutor.setRenderState(state, row, isSelected, true);
    }
    if (renderer instanceof IDisplayRelatedData) {
        IDisplayRelatedData drd = (IDisplayRelatedData) renderer;
        String relationName = drd.getSelectedRelationName();
        if (state != null) {
            if (relationName != null) {
                if (!printing && !state.isRelatedFoundSetLoaded(relationName, null)) {
                    IApplication app = dal.getApplication();
                    ((IDisplayData) renderer).setValueObject(null);
                    // $NON-NLS-1$ //$NON-NLS-2$
                    String key = row + "_" + relationName + "_" + null;
                    if (!rowAndDataprovider.contains(key)) {
                        rowAndDataprovider.add(key);
                        Runnable r = new ASynchonizedCellLoad(app, jtable, foundset, row, jtable.convertColumnIndexToModel(column), relationName, drd.getDefaultSort(), null);
                        app.getScheduledExecutor().execute(r);
                    }
                    return renderer.isVisible() ? renderer : empty;
                }
            }
            drd.setRecord(state, true);
        }
    }
    if (renderer instanceof IDisplayData) {
        if (state != null) {
            Object data = null;
            if (dataProviderID != null) {
                int index = -1;
                if (!printing && (index = dataProviderID.indexOf('.')) > 0) {
                    if (!ScopesUtils.isVariableScope(dataProviderID)) {
                        String partName = dataProviderID.substring(0, index);
                        final String restName = dataProviderID.substring(index + 1);
                        String relationName = partName;
                        if (relationName != null && !state.isRelatedFoundSetLoaded(relationName, restName)) {
                            IApplication app = dal.getApplication();
                            ((IDisplayData) renderer).setValueObject(null);
                            // $NON-NLS-1$ //$NON-NLS-2$
                            String key = row + "_" + relationName + "_" + restName;
                            if (!rowAndDataprovider.contains(key)) {
                                rowAndDataprovider.add(key);
                                List<SortColumn> defaultPKSortColumns = null;
                                try {
                                    defaultPKSortColumns = app.getFoundSetManager().getDefaultPKSortColumns(app.getFlattenedSolution().getRelation(relationName).getForeignDataSource());
                                } catch (ServoyException e) {
                                    Debug.error(e);
                                }
                                Runnable r = new ASynchonizedCellLoad(app, jtable, foundset, row, jtable.convertColumnIndexToModel(column), relationName, defaultPKSortColumns, restName);
                                app.getScheduledExecutor().execute(r);
                            }
                            return renderer.isVisible() ? renderer : empty;
                        }
                        IFoundSetInternal rfs = state.getRelatedFoundSet(relationName);
                        if (rfs != null) {
                            int selected = rfs.getSelectedIndex();
                            // should still go through record 0
                            if (selected == -1 && rfs.getSize() > 0) {
                                selected = 0;
                            }
                            final IRecordInternal relState = rfs.getRecord(selected);
                            if (testCalc(restName, relState, row, jtable.convertColumnIndexToModel(column), foundset))
                                return renderer;
                        }
                    }
                }
                if (!((IDisplayData) renderer).needEntireState() && !printing && testCalc(dataProviderID, state, row, jtable.convertColumnIndexToModel(column), foundset)) {
                    return renderer;
                }
                try {
                    data = dal.getValueObject(state, dataProviderID);
                } catch (IllegalArgumentException iae) {
                    Debug.error(iae);
                    // $NON-NLS-1$
                    data = "<conversion error>";
                }
            }
            ((IDisplayData) renderer).setTagResolver(new ITagResolver() {

                public String getStringValue(String nm) {
                    return TagResolver.formatObject(dal.getValueObject(state, nm), dal.getApplication());
                }
            });
            if (data instanceof DbIdentValue) {
                data = ((DbIdentValue) data).getPkValue();
            }
            convertAndSetValue(((IDisplayData) renderer), data);
        }
    }
    if (renderer instanceof IServoyAwareBean && state != null) {
        ((IServoyAwareBean) renderer).setSelectedRecord(new ServoyBeanState(state, dal.getFormScope()));
    }
    if (!(renderer instanceof IDisplayData) && !(renderer instanceof IDisplayRelatedData) && renderEventExecutor != null && renderEventExecutor.hasRenderCallback()) {
        renderEventExecutor.fireOnRender(false);
    }
    // if the bgcolor is not changed during onRender
    if (isRenderWithOnRender && renderBgColor != null && ((RenderableWrapper) renderable).getProperty(RenderableWrapper.PROPERTY_BGCOLOR) == null) {
        renderer.setBackground(renderBgColor);
    }
    return renderer.isVisible() ? renderer : empty;
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) Rectangle(java.awt.Rectangle) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) Font(java.awt.Font) ServoyException(com.servoy.j2db.util.ServoyException) IScriptRenderMethods(com.servoy.j2db.ui.IScriptRenderMethods) IDisplayRelatedData(com.servoy.j2db.dataprocessing.IDisplayRelatedData) IServoyAwareBean(com.servoy.j2db.dataui.IServoyAwareBean) DbIdentValue(com.servoy.j2db.dataprocessing.ValueFactory.DbIdentValue) RenderableWrapper(com.servoy.j2db.ui.RenderableWrapper) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) ITagResolver(com.servoy.base.util.ITagResolver) Color(java.awt.Color) JComponent(javax.swing.JComponent) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) IScriptable(com.servoy.j2db.scripting.IScriptable) Point(java.awt.Point) IApplication(com.servoy.j2db.IApplication) ServoyBeanState(com.servoy.j2db.component.ServoyBeanState) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) EventObject(java.util.EventObject)

Example 37 with IRecordInternal

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

the class CellAdapter method getStyleAttributeForRow.

private Object getStyleAttributeForRow(JTable jtable, boolean isSelected, int row, ISupportRowStyling.ATTRIBUTE rowStyleAttribute) {
    Object rowStyleAttrValue = null;
    IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
    boolean specialStateCase = (state instanceof PrototypeState || state instanceof FindState);
    if (/* !(renderer instanceof JButton) && */
    !specialStateCase) {
        if (jtable instanceof ISupportRowStyling) {
            ISupportRowStyling oddEvenStyling = (ISupportRowStyling) jtable;
            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 = (row % 2 == 0) ? oddEvenStyling.getRowOddStyle() : oddEvenStyling.getRowEvenStyle();
            }
            rowStyleAttrValue = getStyleAttribute(ss, style, rowStyleAttribute);
        }
    }
    return rowStyleAttrValue;
}
Also used : ISupportRowStyling(com.servoy.j2db.ui.ISupportRowStyling) FindState(com.servoy.j2db.dataprocessing.FindState) IStyleSheet(com.servoy.j2db.util.IStyleSheet) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) IStyleRule(com.servoy.j2db.util.IStyleRule) EventObject(java.util.EventObject) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Example 38 with IRecordInternal

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

the class PortalComponent method toXML.

public void toXML(Writer w, Rectangle rec) throws IOException {
    if (currentData != null) {
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
        w.write("<ROWSCOMPONENT x=\"" + rec.x + "\" y=\"" + rec.y + "\" width=\"" + rec.width + "\" height=\"" + rec.height + "\" >");
        if (table == null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            w.write("<ROWS count=\"" + currentData.getSize() + "\" >");
            DataRenderer formRenderer = (DataRenderer) list.getCellRenderer();
            for (int ii = 0; ii < currentData.getSize(); ii++) {
                // $NON-NLS-1$
                w.write("<ROW>");
                IRecordInternal state = currentData.getRecord(ii);
                formRenderer.getDataAdapterList().setRecord(state, true);
                Component[] comps = formRenderer.getComponents();
                for (Component component : comps) {
                    XMLPrintHelper.handleComponent(w, component, component.getBounds(), null);
                }
                // $NON-NLS-1$
                w.write("</ROW>");
            }
            // $NON-NLS-1$
            w.write("</ROWS>");
        } else {
            // $NON-NLS-1$//$NON-NLS-2$
            w.write("<ROWS count=\"" + currentData.getSize() + "\" >");
            for (int ii = 0; ii < currentData.getSize(); ii++) {
                // $NON-NLS-1$
                w.write("<ROW>");
                IRecordInternal state = currentData.getRecord(ii);
                TableColumnModel tcm = table.getColumnModel();
                for (int i = 0; i < tcm.getColumnCount(); i++) {
                    CellAdapter ca = (CellAdapter) tcm.getColumn(i);
                    String dataProviderID = ca.getDataProviderID();
                    Component component = ca.getRenderer();
                    XMLPrintHelper.handleComponent(w, component, component.getBounds(), state.getValue(dataProviderID));
                }
                // $NON-NLS-1$
                w.write("</ROW>");
            }
            // $NON-NLS-1$
            w.write("</ROWS>");
        }
        // $NON-NLS-1$
        w.write("</ROWSCOMPONENT>");
    }
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) TableColumnModel(javax.swing.table.TableColumnModel) Component(java.awt.Component) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) JComponent(javax.swing.JComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Example 39 with IRecordInternal

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

the class PortalComponent method valueChanged.

private void valueChanged(ListSelectionEvent eventCanBeNull, boolean stopAnyEdit) {
    IFoundSetInternal s = null;
    if (table != null) {
        TableModel tm = table.getModel();
        if (tm instanceof IFoundSetInternal) {
            s = (IFoundSetInternal) tm;
        }
    } else {
        ListModel tm = list.getModel();
        if (tm instanceof IFoundSetInternal) {
            s = (IFoundSetInternal) tm;
        }
    }
    if (s != null) {
        if (dal != null) {
            int index = getRecordIndex();
            if (index != -1) {
                IRecordInternal state = s.getRecord(index);
                if (// can happen when notified from client and itself not having a selection yet
                state != null) {
                    if (eventCanBeNull != null && eventCanBeNull.getValueIsAdjusting()) {
                        if (lastAdjusting != index) {
                            lastAdjusting = index;
                            application.getFoundSetManager().getEditRecordList().stopIfEditing(s);
                        }
                    } else {
                        lastAdjusting = -1;
                        dal.setRecord(state, stopAnyEdit);
                    }
                } else {
                    dal.setRecord(null, stopAnyEdit);
                }
            } else {
                dal.setRecord(null, stopAnyEdit);
            }
        }
    }
}
Also used : IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) AbstractEditListModel(com.servoy.j2db.util.editlist.AbstractEditListModel) ListModel(javax.swing.ListModel) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel)

Example 40 with IRecordInternal

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

the class SpecialTabPanel 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) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet)

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