use of com.servoy.j2db.persistence.ColumnWrapper in project servoy-client by Servoy.
the class DataProviderEditor method showDataEx.
public void showDataEx(IDataProvider dp) throws Exception {
relationsComboBox.removeItemListener(this);
if (dp instanceof ColumnWrapper) {
fillRelationsComboBox(((ColumnWrapper) dp).getRelations());
} else {
fillRelationsComboBox(relation == null ? null : new Relation[] { relation });
}
relationsComboBox.addItemListener(this);
list.setModel(new DefaultListModel());
fillDataProviderList();
if (dp instanceof ColumnWrapper) {
dp = ((ColumnWrapper) dp).getColumn();
}
if (dp != null)
list.setSelectedValue(dp, true);
}
use of com.servoy.j2db.persistence.ColumnWrapper 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.persistence.ColumnWrapper in project servoy-client by Servoy.
the class FoundSet method findColumnWrapperForColumn.
private ColumnWrapper findColumnWrapperForColumn(QuerySelect sqlSelect, QueryColumn qcolumn) throws RepositoryException {
List<Relation> relationSequence = findQueryRelationSequence(sqlSelect, qcolumn.getTable());
if (relationSequence == null) {
return null;
}
// found the relations, match the column (by sqlName)
ITable table = fsm.getTable(qcolumn.getTable().getDataSource());
if (table != null) {
IColumn column = table.getColumnBySqlname(qcolumn.getName());
if (column != null) {
return new ColumnWrapper(column, relationSequence.toArray(new Relation[relationSequence.size()]));
}
}
return null;
}
use of com.servoy.j2db.persistence.ColumnWrapper in project servoy-client by Servoy.
the class ComponentFormat method getComponentFormat.
public static ComponentFormat getComponentFormat(String format, IDataProvider dataProvider, IServiceProvider application, boolean autoFillMaxLength) {
int dpType = IColumnTypes.TEXT;
String formatProperty = format;
if (dataProvider != null) {
dpType = dataProvider.getDataProviderType();
IColumn column = null;
if (dataProvider instanceof ColumnWrapper) {
column = ((ColumnWrapper) dataProvider).getColumn();
} else if (dataProvider instanceof Column) {
column = (Column) dataProvider;
} else if (dataProvider instanceof ScriptCalculation) {
// When it is a stored calculation, the name of the calc is the name of he column
ScriptCalculation calc = (ScriptCalculation) dataProvider;
try {
ITable table = calc.getTable();
if (table != null) {
column = table.getColumn(calc.getName());
}
} catch (RepositoryException e) {
Debug.error(e);
}
}
if (column instanceof AggregateVariable) {
Column columnToAggregate = null;
try {
ITable table = column.getTable();
if (table != null) {
columnToAggregate = table.getColumn(((AggregateVariable) column).getDataProviderIDToAggregate());
}
} catch (RepositoryException e) {
Debug.error(e);
}
// Use aggregated column when they are of the same type (so not count(textcolumn))
if (columnToAggregate != null && column.getDataProviderType() == columnToAggregate.getDataProviderType()) {
column = columnToAggregate;
}
}
if (column instanceof Column) {
ColumnInfo ci = ((Column) column).getColumnInfo();
if (ci != null) {
if (formatProperty == null || formatProperty.length() == 0) {
if (ci.getDefaultFormat() != null && ci.getDefaultFormat().length() > 0) {
formatProperty = ci.getDefaultFormat();
}
}
dpType = application.getFoundSetManager().getConvertedTypeForColumn(column, true);
}
}
}
ComponentFormat componentFormat = ComponentFormat.getComponentFormat(formatProperty, dpType, application);
if (autoFillMaxLength && dataProvider != null && dataProvider.getLength() > 0 && componentFormat.parsedFormat != null && componentFormat.parsedFormat.getMaxLength() == null && (dpType == IColumnTypes.TEXT || dpType == IColumnTypes.MEDIA)) {
componentFormat.parsedFormat.updateMaxLength(Integer.valueOf(dataProvider.getLength()));
}
return componentFormat;
}
Aggregations