Search in sources :

Example 16 with IDisplayData

use of com.servoy.j2db.dataprocessing.IDisplayData 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)

Example 17 with IDisplayData

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

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

the class CellAdapter method getCellEditorValue.

public Object getCellEditorValue() {
    // test if currentEditing state isn't deleted already
    if (currentEditingState == null || dataProviderID == null || (currentEditingState != null && currentEditingState.getParentFoundSet() == null))
        return null;
    Object comp = editor;
    if ((comp instanceof IDisplay && ((IDisplay) comp).isReadOnly()) || gettingEditorValue) {
        return currentEditingState.getValue(getDataProviderID());
    }
    try {
        gettingEditorValue = true;
        if (comp instanceof IDelegate<?>) {
            comp = ((IDelegate<?>) comp).getDelegate();
        }
        // HACK:needed for commit value copied from other hack 'processfocus' in DataField
        if (comp instanceof DataField && ((DataField) comp).isEditable()) {
            DataField edit = (DataField) comp;
            boolean needEntireState = edit.needEntireState();
            try {
                edit.setNeedEntireState(false);
                int fb = edit.getFocusLostBehavior();
                if (fb == JFormattedTextField.COMMIT || fb == JFormattedTextField.COMMIT_OR_REVERT) {
                    try {
                        edit.commitEdit();
                        // Give it a chance to reformat.
                        edit.setValueObject(edit.getValue());
                    } catch (ParseException pe) {
                        return null;
                    }
                } else if (fb == JFormattedTextField.REVERT) {
                    edit.setValueObject(edit.getValue());
                }
            } finally {
                edit.setNeedEntireState(needEntireState);
            }
        }
        Object obj = null;
        if (editor instanceof IDisplayData) {
            IDisplayData displayData = (IDisplayData) editor;
            obj = Utils.removeJavascripLinkFromDisplay(displayData, null);
            if (!findMode) {
                // use UI converter to convert from UI value to record value
                obj = ComponentFormat.applyUIConverterFromObject(displayData, obj, dataProviderID, application.getFoundSetManager());
            }
            // if the editor is not enable or is readonly dont try to set any value.
            if (!displayData.isEnabled() || displayData.isReadOnly())
                return obj;
            // this can happen when toggeling with readonly. case 233226 or 232188
            if (!currentEditingState.isEditing() && !currentEditingState.startEditing())
                return obj;
            try {
                if (// $NON-NLS-1$
                currentEditingState != null && (obj == null || "".equals(obj)) && currentEditingState.getValue(dataProviderID) == null) {
                    return null;
                }
            } catch (IllegalArgumentException iae) {
                Debug.error(iae);
            }
            Object oldVal = null;
            if (currentEditingState instanceof FindState) {
                if (displayData instanceof IScriptableProvider && ((IScriptableProvider) displayData).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) displayData).getScriptObject()).getComponentFormat() != null) {
                    ((FindState) currentEditingState).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) displayData).getScriptObject()).getComponentFormat().parsedFormat);
                }
                try {
                    oldVal = currentEditingState.getValue(dataProviderID);
                } catch (IllegalArgumentException iae) {
                    // $NON-NLS-1$
                    Debug.error("Error getting the previous value", iae);
                    oldVal = null;
                }
                currentEditingState.setValue(dataProviderID, obj);
                if (!Utils.equalObjects(oldVal, obj)) {
                    // call notifyLastNewValue changed so that the onChangeEvent will be fired and called when attached.
                    displayData.notifyLastNewValueWasChange(oldVal, obj);
                    obj = dal.getValueObject(currentEditingState, dataProviderID);
                }
            } else {
                if (!displayData.isValueValid() && Utils.equalObjects(lastInvalidValue, obj)) {
                    // already validated
                    return obj;
                }
                try {
                    adjusting = true;
                    try {
                        oldVal = currentEditingState.getValue(dataProviderID);
                    } catch (IllegalArgumentException iae) {
                        // $NON-NLS-1$
                        Debug.error("Error getting the previous value", iae);
                    }
                    try {
                        if (oldVal == Scriptable.NOT_FOUND && dal.getFormScope().has(dataProviderID, dal.getFormScope())) {
                            oldVal = dal.getFormScope().get(dataProviderID);
                            dal.getFormScope().put(dataProviderID, obj);
                            IFoundSetInternal foundset = currentEditingState.getParentFoundSet();
                            if (foundset instanceof FoundSet)
                                ((FoundSet) foundset).fireFoundSetChanged();
                        } else
                            currentEditingState.setValue(dataProviderID, obj);
                    } catch (IllegalArgumentException e) {
                        Debug.trace(e);
                        displayData.setValueValid(false, oldVal);
                        application.handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
                        Object stateValue = null;
                        try {
                            stateValue = dal.getValueObject(currentEditingState, dataProviderID);
                        } catch (IllegalArgumentException iae) {
                            Debug.error(iae);
                        }
                        Object displayValue;
                        if (Utils.equalObjects(oldVal, stateValue)) {
                            // reset display to typed value
                            displayValue = obj;
                        } else {
                            // reset display to changed value in validator method
                            displayValue = stateValue;
                        }
                        convertAndSetValue(displayData, displayValue);
                        return displayValue;
                    }
                    if (!Utils.equalObjects(oldVal, obj)) {
                        fireModificationEvent(currentEditingState);
                        displayData.notifyLastNewValueWasChange(oldVal, obj);
                        obj = dal.getValueObject(currentEditingState, dataProviderID);
                        // we also want to reset the value in the current display if changed by script
                        convertAndSetValue(displayData, obj);
                    } else if (!displayData.isValueValid()) {
                        displayData.notifyLastNewValueWasChange(null, obj);
                    } else {
                        displayData.setValueValid(true, null);
                    }
                } finally {
                    adjusting = false;
                    if (displayData.isValueValid()) {
                        lastInvalidValue = NONE;
                    } else {
                        lastInvalidValue = obj;
                    }
                }
            }
        }
        return obj;
    } finally {
        gettingEditorValue = false;
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) Point(java.awt.Point) FindState(com.servoy.j2db.dataprocessing.FindState) ApplicationException(com.servoy.j2db.ApplicationException) EventObject(java.util.EventObject) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFormatScriptComponent(com.servoy.j2db.ui.scripting.IFormatScriptComponent) ParseException(java.text.ParseException) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IDelegate(com.servoy.j2db.util.IDelegate)

Example 19 with IDisplayData

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

the class DataComboBox method setDataProviderID.

public void setDataProviderID(String id) {
    dataProviderID = id;
    getListModelWrapper().setDataProviderID(id);
    if (// for debugging so component has name
    isEditable()) {
        Component comp = getEditor().getEditorComponent();
        comp.setName(id);
        if (comp instanceof IDisplayData) {
            ((IDisplayData) comp).setDataProviderID(dataProviderID);
        }
    }
}
Also used : IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) IFormattingComponent(com.servoy.j2db.ui.IFormattingComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 20 with IDisplayData

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

the class ScrollResponseHeaderContainer method tableChanged.

/**
 * @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
 */
public void tableChanged(TableModelEvent e) {
    // as changed, as it will be faster on the client the component replace
    if ((e.getType() == TableModelEvent.UPDATE) && (e.getFirstRow() == e.getLastRow()) && (nrUpdatedListItems < 20)) {
        Component component = table.get(Integer.toString(e.getFirstRow()));
        if (component instanceof ListItem) {
            ((ListItem) component).visitChildren(IProviderStylePropertyChanges.class, new IVisitor<Component>() {

                public Object component(Component comp) {
                    if ((comp instanceof IDisplayData) || !(comp instanceof ILabel)) {
                        if (comp instanceof ISupportsNeedEntireState && ((ISupportsNeedEntireState) comp).needEntireState()) {
                            // it if has tags - mark as changed; it could be enhanced further by also know what was last-rendered on tags, not just simple dataproviders
                            ((IProviderStylePropertyChanges) comp).getStylePropertyChanges().setChanged();
                        } else {
                            // try to mark cells as changed only if there was a real value change; otherwise there is no use to replace the whole row...
                            checkForValueChanges(comp);
                        }
                    }
                    // else labels/buttons that don't display data are not changed
                    return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
                }
            });
            nrUpdatedListItems++;
            IModel<IRecordInternal> newModel = table.getListItemModel(table.getModel(), e.getFirstRow());
            IModel oldModel = ((ListItem) component).getModel();
            if (newModel != null && oldModel != null && newModel.getObject() != null && !newModel.getObject().equals(oldModel.getObject())) {
                // refresh model if it changed
                ((ListItem) component).setModel(newModel);
            }
        }
    } else {
        if (!isRendering && (!isScrollMode() || !(scrollBehavior != null && scrollBehavior.isGettingRows()))) {
            if (isScrollMode())
                resetScrollParams();
            getStylePropertyChanges().setValueChanged();
        }
    }
    // This is just an heuristic for filtering out the sort event from all table changed events that are raised.
    if (currentData != null && e.getColumn() == TableModelEvent.ALL_COLUMNS && e.getFirstRow() == 0 && elementToColumnHeader.size() > 0) {
        List<SortColumn> sortCols = currentData.getSortColumns();
        if (sortCols != null && sortCols.size() > 0) {
            Map<String, Boolean> sortMap = new HashMap<String, Boolean>();
            for (IPersist persist : elementToColumnHeader.keySet()) {
                SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
                sortableCellViewHeader.setResizeImage(R_ARROW_OFF);
            }
            for (SortColumn sc : sortCols) {
                for (IPersist persist : elementToColumnHeader.keySet()) {
                    Component comp = elementToColumnIdentifierComponent.get(persist);
                    SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
                    if (comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null) {
                        IDisplayData dispComp = (IDisplayData) comp;
                        List<String> sortingProviders = null;
                        if (dispComp instanceof ISupportValueList && ((ISupportValueList) dispComp).getValueList() != null) {
                            try {
                                sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) dispComp).getValueList().getValueList(), (Table) currentData.getTable(), dispComp.getDataProviderID(), currentData.getFoundSetManager());
                            } catch (RepositoryException ex) {
                                Debug.error(ex);
                            }
                        }
                        if (sortingProviders == null) {
                            // no related sort, use sort on dataProviderID instead
                            sortingProviders = Collections.singletonList(dispComp.getDataProviderID());
                        }
                        for (String sortingProvider : sortingProviders) {
                            SortColumn existingSc;
                            try {
                                FoundSetManager fsm = (FoundSetManager) currentData.getFoundSetManager();
                                existingSc = fsm.getSortColumn(currentData.getTable(), sortingProvider, false);
                            } catch (RepositoryException ex) {
                                Debug.error(ex);
                                continue;
                            }
                            if (sc.equalsIgnoreSortorder(existingSc)) {
                                boolean descending = sc.getSortOrder() == SortColumn.DESCENDING;
                                sortableCellViewHeader.setResizeImage(descending ? R_ARROW_UP : R_ARROW_DOWN);
                                sortMap.put(sortableCellViewHeader.getId(), Boolean.valueOf(!descending));
                            }
                        }
                    }
                }
            }
            headers.recordSort(sortMap);
        }
    }
    MainPage mp = table.findParent(MainPage.class);
    if (mp != null)
        mp.triggerBrowserRequestIfNeeded();
}
Also used : ISupportsNeedEntireState(com.servoy.j2db.dataprocessing.ISupportsNeedEntireState) ILabel(com.servoy.j2db.ui.ILabel) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) IComponent(com.servoy.j2db.ui.IComponent) AbstractRuntimeBaseComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeBaseComponent) BaseComponent(com.servoy.j2db.persistence.BaseComponent) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) IPortalComponent(com.servoy.j2db.ui.IPortalComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) MainPage(com.servoy.j2db.server.headlessclient.MainPage) IModel(org.apache.wicket.model.IModel) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) Table(com.servoy.j2db.persistence.Table) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPersist(com.servoy.j2db.persistence.IPersist) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) ListItem(org.apache.wicket.markup.html.list.ListItem)

Aggregations

IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)24 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)8 IDisplay (com.servoy.j2db.dataprocessing.IDisplay)7 HashMap (java.util.HashMap)7 JComponent (javax.swing.JComponent)7 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)6 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)6 Point (java.awt.Point)6 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)5 IPersist (com.servoy.j2db.persistence.IPersist)5 IScriptable (com.servoy.j2db.scripting.IScriptable)5 IComponent (com.servoy.j2db.ui.IComponent)5 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)5 Component (java.awt.Component)5 EventObject (java.util.EventObject)5 Iterator (java.util.Iterator)5 Component (org.apache.wicket.Component)5 FindState (com.servoy.j2db.dataprocessing.FindState)4 IDisplayRelatedData (com.servoy.j2db.dataprocessing.IDisplayRelatedData)4 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)4