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;
}
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;
}
}
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;
}
Aggregations