use of com.servoy.j2db.dataprocessing.FindState in project servoy-client by Servoy.
the class DataproviderTypeSabloValue method dataProviderOrRecordChanged.
@Override
public void dataProviderOrRecordChanged(final IRecordInternal record, final String dataProvider, final boolean isFormDP, final boolean isGlobalDP, boolean fireChangeEvent) {
// TODO can type or fieldFormat change, for example in scripting the format is reset (but type shouldn't really change)
IDataProviderLookup dpLookup = new FormAndTableDataProviderLookup(servoyDataConverterContext.getApplication().getFlattenedSolution(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null);
Collection<PropertyDescription> properties = webObjectContext.getProperties(TypesRegistry.getType(FormatPropertyType.TYPE_NAME));
FormatTypeSabloValue formatSabloValue = null;
for (PropertyDescription formatPd : properties) {
// see whether format if "for" this property (dataprovider)
Object formatConfig = formatPd.getConfig();
if (formatConfig instanceof String[] && Arrays.asList((String[]) formatConfig).indexOf(dpPD.getName()) != -1) {
INGApplication application = servoyDataConverterContext.getApplication();
formatSabloValue = (FormatTypeSabloValue) webObjectContext.getProperty(formatPd.getName());
if (formatSabloValue != null) {
if (formatSabloValue.getFormatDesignValue() != null) {
fieldFormat = ComponentFormat.getComponentFormat(formatSabloValue.getFormatDesignValue(), dataProviderID, dpLookup, application);
}
break;
}
}
}
if (fieldFormat != null) {
typeOfDP = NGUtils.getDataProviderPropertyDescription(fieldFormat.uiType, getDataProviderConfig().hasParseHtml(), fieldFormat.parsedFormat.useLocalDateTime());
if (record instanceof FindState) {
((FindState) record).setFormat(dataProviderID, fieldFormat.parsedFormat);
}
} else {
// see type of dataprovider; this is done only once - first time we get a new record
typeOfDP = NGUtils.getDataProviderPropertyDescription(dataProviderID, servoyDataConverterContext.getApplication(), servoyDataConverterContext.getForm().getForm(), record != null ? record.getParentFoundSet().getTable() : null, getDataProviderConfig().hasParseHtml(), formatSabloValue != null ? formatSabloValue.getComponentFormat().parsedFormat.useLocalDateTime() : false);
}
if (dpPD.hasTag(TAG_TYPE_NAME)) {
IPropertyType<?> specType = TypesRegistry.getType((String) dpPD.getTag(TAG_TYPE_NAME));
if (specType != null && (typeOfDP == null || !specType.getClass().isAssignableFrom(typeOfDP.getClass()))) {
typeOfDP = new PropertyDescriptionBuilder().withName("Spec type hint").withType(specType).build();
}
}
String dpID = dataProviderID;
IDataProvider dp = null;
if (dpLookup != null) {
try {
dp = dpLookup.getDataProvider(dataProviderID);
if (dp != null) {
dpID = dp.getDataProviderID();
}
} catch (RepositoryException e) {
Debug.error(e);
}
}
if (globalRelationName != null) {
try {
IFoundSetInternal newRelatedFoundset = servoyDataConverterContext.getApplication().getFoundSetManager().getGlobalRelatedFoundSet(globalRelationName);
if (newRelatedFoundset != globalRelatedFoundset) {
if (globalRelatedFoundsetListener == null) {
globalRelatedFoundsetListener = new IFoundSetEventListener() {
@Override
public void foundSetChanged(FoundSetEvent e) {
if (e.getType() == FoundSetEvent.CONTENTS_CHANGED) {
dataProviderOrRecordChanged(DataproviderTypeSabloValue.this.dataAdapterList.getRecord(), null, false, false, true);
}
}
};
} else if (globalRelatedFoundset != null) {
globalRelatedFoundset.removeFoundSetEventListener(globalRelatedFoundsetListener);
}
globalRelatedFoundset = newRelatedFoundset;
globalRelatedFoundset.addFoundSetEventListener(globalRelatedFoundsetListener);
}
} catch (Exception ex) {
Debug.error(ex);
}
}
if (relatedFoundsetSelectionListener != null) {
try {
ArrayList<IFoundSetInternal> newRelatedFoundsets = getRelatedFoundsets(record, relationName);
boolean equals = testByReference(newRelatedFoundsets, this.relatedFoundsets);
if (!equals) {
IDataProvider column = dp;
if (column instanceof ColumnWrapper) {
column = ((ColumnWrapper) column).getColumn();
}
boolean isAggregate = (column instanceof IColumn) ? ((IColumn) column).isAggregate() : false;
if (isAggregate && relatedFoundsets.size() > 0) {
relatedFoundsets.get(relatedFoundsets.size() - 1).removeAggregateModificationListener(relatedRecordModificationListener);
}
for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
((ISwingFoundSet) relatedFoundset).getSelectionModel().removeListSelectionListener(relatedFoundsetSelectionListener);
}
relatedFoundsets = newRelatedFoundsets;
for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
((ISwingFoundSet) relatedFoundset).getSelectionModel().addListSelectionListener(relatedFoundsetSelectionListener);
}
if (isAggregate && relatedFoundsets.size() > 0) {
relatedFoundsets.get(relatedFoundsets.size() - 1).addAggregateModificationListener(relatedRecordModificationListener);
}
}
} catch (Exception ex) {
Debug.error(ex);
}
}
if (relatedRecordModificationListener != null) {
try {
ArrayList<IRecordInternal> newRelatedRecords = getRelatedRecords(record, relationName);
boolean equals = testByReference(newRelatedRecords, this.relatedRecords);
if (!equals) {
for (IRecordInternal relatedRecord : relatedRecords) {
relatedRecord.removeModificationListener(relatedRecordModificationListener);
}
relatedRecords = newRelatedRecords;
for (IRecordInternal relatedRecord : relatedRecords) {
relatedRecord.addModificationListener(relatedRecordModificationListener);
}
}
} catch (Exception ex) {
Debug.error(ex);
}
}
Object v = com.servoy.j2db.dataprocessing.DataAdapterList.getValueObject(record, servoyDataConverterContext.getForm().getFormScope(), dpID);
if (v == Scriptable.NOT_FOUND)
v = null;
if (fieldFormat != null && !findMode) {
// if it has an UI converter, transform it from the record/scope value into the UI value
v = ComponentFormat.applyUIConverterToObject(v, dataProviderID, servoyDataConverterContext.getApplication().getFoundSetManager(), fieldFormat);
}
v = replaceTagsIfNeeded(v);
boolean changed = ((v != uiValue) && (v == null || !v.equals(uiValue)));
uiValue = v;
if (changed) {
jsonValue = null;
}
if (// if it is a foundset related DAL then always call valuechanged (the value can be of a previous row)
fireChangeEvent && (changed || dataAdapterList instanceof FoundsetDataAdapterList)) {
changeMonitor.valueChanged();
}
}
use of com.servoy.j2db.dataprocessing.FindState in project servoy-client by Servoy.
the class RecordItemModel method setValue.
/**
* @param obj
* @param dataProviderID
* @param prevValue
*/
public void setValue(Component component, String dataProviderID, Object value) {
Object obj = value;
String compDpid = getDataProviderID(component);
boolean ownComponentsValue = compDpid != null && dataProviderID.endsWith(compDpid);
Object prevValue = null;
if (ownComponentsValue && component instanceof IResolveObject) {
obj = ((IResolveObject) component).resolveRealValue(obj);
}
if (component instanceof IDisplayData) {
obj = Utils.removeJavascripLinkFromDisplay((IDisplayData) component, new Object[] { obj });
}
WebForm webForm = component.findParent(WebForm.class);
IRecordInternal record = (IRecordInternal) RecordItemModel.this.getObject();
// use UI converter to convert from UI value to record value
if (!(record instanceof FindState)) {
obj = ComponentFormat.applyUIConverterFromObject(component, obj, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
}
FormScope fs = webForm.getController().getFormScope();
try {
Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
if (scope.getLeft() != null) {
if (record == null) {
webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().getGlobalScope(scope.getLeft()).put(scope.getRight(), obj);
} else {
// does an additional fire in foundset!
prevValue = record.getParentFoundSet().setDataProviderValue(dataProviderID, obj);
}
} else if (fs.has(dataProviderID, fs)) {
prevValue = fs.get(dataProviderID);
fs.put(dataProviderID, obj);
} else {
if (record != null && record.startEditing()) {
try {
prevValue = record.getValue(dataProviderID);
record.setValue(dataProviderID, obj);
} catch (IllegalArgumentException e) {
Debug.trace(e);
((WebClientSession) Session.get()).getWebClient().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
Object stateValue = record.getValue(dataProviderID);
if (!Utils.equalObjects(prevValue, stateValue)) {
// reset display to changed value in validator method
obj = stateValue;
}
if (ownComponentsValue) {
((IDisplayData) component).setValueValid(false, prevValue);
}
return;
}
if (ownComponentsValue && record instanceof FindState && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat() != null) {
((FindState) record).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat().parsedFormat);
}
}
}
// then dont call notify
if (ownComponentsValue) {
((IDisplayData) component).notifyLastNewValueWasChange(prevValue, obj);
}
} finally {
// then touch the lastInvalidValue
if (ownComponentsValue) {
if (((IDisplayData) component).isValueValid()) {
lastInvalidValue = NONE;
} else {
lastInvalidValue = obj;
}
}
}
return;
}
use of com.servoy.j2db.dataprocessing.FindState in project servoy-client by Servoy.
the class RecordItemModel method getValue.
/**
* Gets the value for dataProviderID in the context of this record and the form determined using given component. The component is only used for getting the
* form, otherwise it does not affect the returned value.
*
* @param component the component used to determine the form (in case of global or form variables).
* @param dataProviderID the data provider id pointing to a data provider in the record, a form or a global variable.
* @return the value.
*/
public Object getValue(Component component, String dataProviderID) {
Object value = null;
WebForm webForm = component.findParent(WebForm.class);
if (webForm == null) {
// component.toString() may cause stackoverflow here
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
Debug.error(// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
"Component " + component.getClass() + " with dp: " + dataProviderID + " already removed from its parent form.", new RuntimeException());
return null;
}
FormScope fs = webForm.getController().getFormScope();
IRecord record = (IRecord) RecordItemModel.this.getObject();
if (ScopesUtils.isVariableScope(dataProviderID)) {
value = webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().get(null, dataProviderID);
} else if (record != null) {
value = record.getValue(dataProviderID);
}
if (value == Scriptable.NOT_FOUND && fs != null && fs.has(dataProviderID, fs)) {
value = fs.get(dataProviderID);
}
if (value instanceof DbIdentValue) {
value = ((DbIdentValue) value).getPkValue();
}
if (value == Scriptable.NOT_FOUND) {
value = null;
} else if (!(record instanceof FindState)) {
// use UI converter to convert from record value to UI value
value = ComponentFormat.applyUIConverterToObject(component, value, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
}
return value;
}
use of com.servoy.j2db.dataprocessing.FindState 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;
}
use of com.servoy.j2db.dataprocessing.FindState 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;
}
Aggregations