Search in sources :

Example 6 with IDisplay

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

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

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

the class WebDataRenderer method createDataAdapter.

void createDataAdapter(IApplication app, IDataProviderLookup dataProviderLookup, IScriptExecuter el, ControllerUndoManager undoManager) throws Exception {
    dataAdapterList = new DataAdapterList(app, dataProviderLookup, fieldComponents, el.getFormController(), null, undoManager);
    // make it really fields only
    HashMap<IPersist, IDisplay> f = new HashMap<IPersist, IDisplay>();
    Iterator<Map.Entry<IPersist, IDisplay>> it = fieldComponents.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<IPersist, IDisplay> element = it.next();
        if (element.getValue() instanceof IDisplayData) {
            // String id = ((IDisplayData)element.getValue()).getDataProviderID();
            // if (dataProviderLookup.getDataProvider(id) instanceof ScriptVariable)
            // {
            // globalFields.add(element.getValue());
            // }
            f.put(element.getKey(), element.getValue());
        }
    }
    fieldComponents = f;
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) HashMap(java.util.HashMap) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) IDisplay(com.servoy.j2db.dataprocessing.IDisplay) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IDisplay (com.servoy.j2db.dataprocessing.IDisplay)8 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)7 IPersist (com.servoy.j2db.persistence.IPersist)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 DataAdapterList (com.servoy.j2db.dataprocessing.DataAdapterList)3 Point (java.awt.Point)3 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)2 IServoyAwareBean (com.servoy.j2db.dataui.IServoyAwareBean)2 Field (com.servoy.j2db.persistence.Field)2 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)2 IDataProviderLookup (com.servoy.j2db.persistence.IDataProviderLookup)2 ISupportPrinting (com.servoy.j2db.persistence.ISupportPrinting)2 ISupportTabSeq (com.servoy.j2db.persistence.ISupportTabSeq)2 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)2 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)2 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)2 EventObject (java.util.EventObject)2 Iterator (java.util.Iterator)2 Entry (java.util.Map.Entry)2