use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class FormatTypeSabloValue method getSabloValue.
protected ComponentFormat getSabloValue(String formatValue, String dataproviderId, Object valuelistId, String foundsetId, IWebObjectContext webObjectCntxt) {
INGApplication application = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getApplication();
IDataProviderLookup dataProviderLookup = null;
// IMPORTANT: here we use the for: configs in .spec file
//
// if you have for: [valuelist, dataprovider] then 2 things can happen:
// - valuelist if it has both real and display values - forces the type; it is either TEXT (custom vl., global method vl.) or the 'display' column type in case it's a DB valuelist
// - valuelist if not real/display but only one kind of values: here it is required in docs in the spec file that the valuelist property also defines "for": dataprovider if format
// defines both "for" valuelist and dataprovider => valuelist doesn't force the type and then the dataprovider will decide the type
//
// if you have just for: dataprovider the the dataprovider property determines the type
// if you have just for: valuelist (TODO) - this is currently not properly supported - as here we should get the type always from the VL (for both display and real values) - as we don't have a dataprovider to fall back on
isValuelistFormatSet = false;
if (valuelistId != null) {
// if we have a "for" valuelist, see if this valuelist forces the format type due to display values (when they are separate from real values)
// otherwise it will do nothing and loop/fallback to the other if clause below which checks the "for" dataprovider
ValueList valuelistPersist = ValueListTypeSabloValue.getValuelistPersist(valuelistId, application);
if (valuelistPersist != null) {
IDataProvider dataProvider = null;
ITable table;
try {
if (valuelistPersist.getRelationName() != null) {
Relation[] relations = application.getFlattenedSolution().getRelationSequence(valuelistPersist.getRelationName());
table = application.getFlattenedSolution().getTable(relations[relations.length - 1].getForeignDataSource());
} else {
table = application.getFlattenedSolution().getTable(valuelistPersist.getDataSource());
}
if (table != null) {
// if the format is for a table valuelist - the type to be used is the one of the dp chosen as 'display' in the valuelist
String dp = null;
// if show == real then we can use show anyway cause there is only one value for both real and display; if show != real we care about show
int showDataProviders = valuelistPersist.getShowDataProviders();
if ((showDataProviders & 1) != 0) {
dp = valuelistPersist.getDataProviderID1();
}
if ((showDataProviders & 2) != 0) {
// display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
if (dp != null)
return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
dp = valuelistPersist.getDataProviderID2();
}
if ((showDataProviders & 4) != 0) {
// display value is a concat of multiple columns, so a string; not even sure if format property makes sense, but it is for a String then
if (dp != null)
return ComponentFormat.getComponentFormat(formatValue, IColumnTypes.TEXT, application);
dp = valuelistPersist.getDataProviderID3();
}
if (dp != null) {
dataProvider = application.getFlattenedSolution().getDataProviderForTable(table, dp);
}
isValuelistFormatSet = true;
return ComponentFormat.getComponentFormat(formatValue, dataProvider, application, true);
} else if (valuelistPersist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
IValueList realValuelist = null;
ValueListTypeSabloValue valuelistSabloValue = (ValueListTypeSabloValue) FoundsetLinkedTypeSabloValue.unwrapIfNeeded(webObjectContext.getProperty(propertyDependencies.valueListPropertyName));
if (valuelistSabloValue != null) {
// take it from property, may not be the shared instance in case setvaluelistitems on component was used
realValuelist = valuelistSabloValue.getValueList();
}
if (realValuelist == null) {
realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, ComponentFormat.getComponentFormat(formatValue, dataproviderId, null, application, true).parsedFormat, null, true);
}
if (realValuelist.hasRealValues()) {
// if custom vl has both real and display values, the display values are TEXT (format is for those)
// of if it has displayValueType set, use that
isValuelistFormatSet = true;
int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
}
} else if (valuelistPersist.getValueListType() == IValueListConstants.GLOBAL_METHOD_VALUES) {
PropertyDescription vlPD = webObjectCntxt.getPropertyDescription(propertyDependencies.valueListPropertyName);
Object vlPDConfig = null;
if (vlPD != null) {
vlPDConfig = vlPD.getConfig();
if (vlPDConfig instanceof FoundsetLinkedConfig)
vlPDConfig = ((FoundsetLinkedConfig) vlPDConfig).getWrappedConfig();
}
boolean lazyLoad = valuelistPersist.getLazyLoading() && vlPDConfig instanceof ValueListConfig && ((ValueListConfig) vlPDConfig).getLazyLoading();
if (!lazyLoad) {
IValueList realValuelist = com.servoy.j2db.component.ComponentFactory.getRealValueList(application, valuelistPersist, true, Types.OTHER, null, null, true);
if (realValuelist instanceof GlobalMethodValueList) {
((GlobalMethodValueList) realValuelist).fill(null, "", null);
if (realValuelist.hasRealValues() || realValuelist.getSize() == 0 || (realValuelist.getSize() == 1 && valuelistPersist.getAddEmptyValue() == IValueListConstants.EMPTY_VALUE_ALWAYS)) {
// if global method vl has both real and display values, the display values are TEXT (format is for those)
// of if it has displayValueType set, use that
isValuelistFormatSet = true;
int realValueDisplayType = realValuelist.getValueList().getDisplayValueType();
return ComponentFormat.getComponentFormat(formatValue, realValueDisplayType != 0 ? realValueDisplayType : IColumnTypes.TEXT, application);
}
}
}
}
} catch (Exception ex) {
Debug.error(ex);
}
}
// here - we want to fall back to the dataprovider if available in for: [ ..., dataprovider] if valuelist didn't force a certain display type on the format
}
if (dataproviderId != null && foundsetId != null) {
ITable table = null;
Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
// always assume now that the the properties has the foundset property name.
FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) webObjectCntxt.getUnderlyingWebObject().getProperty(this.propertyDependencies.foundsetPropertyName);
if (runtimeValOfFoundset != null && runtimeValOfFoundset.getFoundset() != null && runtimeValOfFoundset.getFoundset().getDataSource().equals(foundsetId)) {
table = runtimeValOfFoundset.getFoundset().getTable();
}
if (table == null)
table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(foundsetId, application, form);
if (table != null) {
dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
}
// else it will be searched for in form's context and table as below
}
if (dataProviderLookup == null) {
WebObjectSpecification spec = ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getSpecification();
if (spec != null) {
Collection<PropertyDescription> formComponentProperties = spec.getProperties(FormComponentPropertyType.INSTANCE);
if (formComponentProperties != null) {
for (PropertyDescription property : formComponentProperties) {
if (property.getConfig() instanceof ComponentTypeConfig && ((ComponentTypeConfig) property.getConfig()).forFoundset != null) {
FoundsetTypeSabloValue runtimeValOfFoundset = (FoundsetTypeSabloValue) ((WebFormComponent) webObjectCntxt.getUnderlyingWebObject()).getParent().getProperty(((ComponentTypeConfig) property.getConfig()).forFoundset);
ITable table = null;
Form form = ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm();
if (runtimeValOfFoundset.getFoundset() != null)
table = runtimeValOfFoundset.getFoundset().getTable();
if (table == null)
table = FoundsetTypeSabloValue.getTableBasedOfFoundsetPropertyFromFoundsetIdentifier(runtimeValOfFoundset.getFoundsetSelector(), application, form);
if (table != null) {
dataProviderLookup = new FormAndTableDataProviderLookup(application.getFlattenedSolution(), form, table);
}
break;
}
}
}
}
}
if (dataProviderLookup == null && application != null)
dataProviderLookup = application.getFlattenedSolution().getDataproviderLookup(application.getFoundSetManager(), ((IContextProvider) webObjectCntxt.getUnderlyingWebObject()).getDataConverterContext().getForm().getForm());
ComponentFormat format = ComponentFormat.getComponentFormat(formatValue, dataproviderId, dataProviderLookup, application, true);
return format;
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class DebugUtils method getScopesAndFormsToReload.
public static Set<IFormController>[] getScopesAndFormsToReload(final ClientState clientState, Collection<IPersist> changes) {
Set<IFormController> scopesToReload = new HashSet<IFormController>();
final Set<IFormController> formsToReload = new HashSet<IFormController>();
final SpecProviderState specProviderState = WebComponentSpecProvider.getSpecProviderState();
final Set<Form> formsUpdated = new HashSet<Form>();
for (IPersist persist : changes) {
clientState.getFlattenedSolution().updatePersistInSolutionCopy(persist);
if (persist instanceof ScriptMethod) {
if (persist.getParent() instanceof Form) {
Form form = (Form) persist.getParent();
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
scopesToReload.add(formController);
}
} else if (persist.getParent() instanceof Solution) {
LazyCompilationScope scope = clientState.getScriptEngine().getScopesScope().getGlobalScope(((ScriptMethod) persist).getScopeName());
scope.remove((IScriptProvider) persist);
scope.put((IScriptProvider) persist, (IScriptProvider) persist);
} else if (persist.getParent() instanceof TableNode) {
clientState.getFoundSetManager().reloadFoundsetMethod(((TableNode) persist.getParent()).getDataSource(), (IScriptProvider) persist);
}
if (clientState instanceof DebugJ2DBClient) {
// ((DebugJ2DBClient)clientState).clearUserWindows(); no need for this as window API was refactored and it allows users to clean up dialogs
((DebugSwingFormMananger) ((DebugJ2DBClient) clientState).getFormManager()).fillScriptMenu();
}
} else if (persist instanceof ScriptVariable) {
ScriptVariable sv = (ScriptVariable) persist;
if (persist.getParent() instanceof Solution) {
clientState.getScriptEngine().getScopesScope().getGlobalScope(sv.getScopeName()).put(sv);
}
if (persist.getParent() instanceof Form) {
Form form = (Form) persist.getParent();
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
FormScope scope = formController.getFormScope();
scope.put(sv);
}
}
} else if (persist.getAncestor(IRepository.FORMS) != null) {
final Form form = (Form) persist.getAncestor(IRepository.FORMS);
if (form != null && form.isFormComponent().booleanValue()) {
// if the changed form is a reference form we need to check if that is referenced by a loaded form..
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
for (IFormController fc : cachedFormControllers) {
fc.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof WebComponent) {
WebComponent wc = (WebComponent) o;
WebObjectSpecification spec = FormTemplateGenerator.getWebObjectSpecification(wc);
Collection<PropertyDescription> properties = spec != null ? spec.getProperties(FormComponentPropertyType.INSTANCE) : null;
if (properties != null && properties.size() > 0) {
Form persistForm = (Form) wc.getAncestor(IRepository.FORMS);
for (PropertyDescription pd : properties) {
Form frm = FormComponentPropertyType.INSTANCE.getForm(wc.getProperty(pd.getName()), clientState.getFlattenedSolution());
if (frm != null && (form.equals(frm) || FlattenedForm.hasFormInHierarchy(frm, form) || isReferenceFormUsedInForm(clientState, form, frm)) && !formsUpdated.contains(persistForm)) {
formsUpdated.add(persistForm);
List<IFormController> cfc = clientState.getFormManager().getCachedFormControllers(persistForm);
for (IFormController formController : cfc) {
formsToReload.add(formController);
}
}
}
}
}
return IPersistVisitor.CONTINUE_TRAVERSAL;
}
});
}
} else if (!formsUpdated.contains(form)) {
formsUpdated.add(form);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
formsToReload.add(formController);
}
}
if (persist instanceof Form && clientState.getFormManager() instanceof DebugUtils.DebugUpdateFormSupport) {
((DebugUtils.DebugUpdateFormSupport) clientState.getFormManager()).updateForm((Form) persist);
}
} else if (persist instanceof ScriptCalculation) {
ScriptCalculation sc = (ScriptCalculation) persist;
if (((RemoteDebugScriptEngine) clientState.getScriptEngine()).recompileScriptCalculation(sc)) {
List<String> al = new ArrayList<String>();
al.add(sc.getDataProviderID());
try {
String dataSource = clientState.getFoundSetManager().getDataSource(sc.getTable());
((FoundSetManager) clientState.getFoundSetManager()).getRowManager(dataSource).clearCalcs(null, al);
((FoundSetManager) clientState.getFoundSetManager()).flushSQLSheet(dataSource);
} catch (Exception e) {
Debug.error(e);
}
}
// if (clientState instanceof DebugJ2DBClient)
// {
// ((DebugJ2DBClient)clientState).clearUserWindows(); no need for this as window API was refactored and it allows users to clean up dialogs
// }
} else if (persist instanceof Relation) {
((FoundSetManager) clientState.getFoundSetManager()).flushSQLSheet((Relation) persist);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
try {
String primary = ((Relation) persist).getPrimaryDataSource();
for (IFormController formController : cachedFormControllers) {
if (primary.equals(formController.getDataSource())) {
final IFormController finalController = formController;
final Relation finalRelation = (Relation) persist;
formController.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof Tab && Utils.equalObjects(finalRelation.getName(), ((Tab) o).getRelationName())) {
formsToReload.add(finalController);
return o;
}
if (o instanceof Field && ((Field) o).getValuelistID() > 0) {
ValueList vl = clientState.getFlattenedSolution().getValueList(((Field) o).getValuelistID());
if (vl != null && Utils.equalObjects(finalRelation.getName(), vl.getRelationName())) {
formsToReload.add(finalController);
return o;
}
}
if (o instanceof WebComponent) {
WebComponent webComponent = (WebComponent) o;
WebObjectSpecification spec = specProviderState == null ? null : specProviderState.getWebComponentSpecification(webComponent.getTypeName());
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(RelationPropertyType.INSTANCE);
for (PropertyDescription pd : properties) {
if (Utils.equalObjects(webComponent.getFlattenedJson().opt(pd.getName()), finalRelation.getName())) {
formsToReload.add(finalController);
return o;
}
}
}
}
return CONTINUE_TRAVERSAL;
}
});
}
}
} catch (Exception e) {
Debug.error(e);
}
} else if (persist instanceof ValueList) {
ComponentFactory.flushValueList(clientState, (ValueList) persist);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
for (IFormController formController : cachedFormControllers) {
final IFormController finalController = formController;
final ValueList finalValuelist = (ValueList) persist;
formController.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof Field && ((Field) o).getValuelistID() > 0 && ((Field) o).getValuelistID() == finalValuelist.getID()) {
formsToReload.add(finalController);
return o;
}
if (o instanceof WebComponent) {
WebComponent webComponent = (WebComponent) o;
WebObjectSpecification spec = specProviderState == null ? null : specProviderState.getWebComponentSpecification(webComponent.getTypeName());
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(ValueListPropertyType.INSTANCE);
for (PropertyDescription pd : properties) {
if (Utils.equalObjects(webComponent.getFlattenedJson().opt(pd.getName()), finalValuelist.getUUID().toString())) {
formsToReload.add(finalController);
return o;
}
}
}
}
return CONTINUE_TRAVERSAL;
}
});
}
} else if (persist instanceof Style) {
ComponentFactory.flushStyle(null, ((Style) persist));
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
String styleName = ((Style) persist).getName();
for (IFormController formController : cachedFormControllers) {
if (styleName.equals(formController.getForm().getStyleName())) {
formsToReload.add(formController);
}
}
}
}
return new Set[] { scopesToReload, formsToReload };
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class ComponentFactory method createField.
private static IComponent createField(IApplication application, Form form, Field field, IDataProviderLookup dataProviderLookup, IScriptExecuter el, boolean printing) {
ValueList valuelist = application.getFlattenedSolution().getValueList(field.getValuelistID());
ComponentFormat fieldFormat = ComponentFormat.getComponentFormat(field.getFormat(), field.getDataProviderID(), dataProviderLookup, application);
IDataProvider dp = null;
if (field.getDataProviderID() != null && dataProviderLookup != null) {
try {
dp = dataProviderLookup.getDataProvider(field.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
}
// apply any style
Insets style_margin = null;
int style_halign = -1;
boolean hasBorder = false;
Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, field, form);
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
style_margin = ss.getMargin(s);
style_halign = ss.getHAlign(s);
hasBorder = ss.hasBorder(s);
}
}
IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
IFieldComponent fl;
AbstractRuntimeField<? extends IFieldComponent> scriptable;
switch(field.getDisplayType()) {
case Field.PASSWORD:
{
RuntimeDataPassword so;
scriptable = so = new RuntimeDataPassword(jsChangeRecorder, application);
fl = application.getItemFactory().createDataPassword(so, getWebID(form, field));
so.setComponent(fl, field);
}
break;
case Field.RTF_AREA:
{
RuntimeRtfArea so;
scriptable = so = new RuntimeRtfArea(jsChangeRecorder, application);
fl = application.getItemFactory().createDataTextEditor(so, getWebID(form, field), RTF_AREA, field.getEditable());
so.setComponent(fl, field);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
break;
case Field.HTML_AREA:
{
RuntimeHTMLArea so;
scriptable = so = new RuntimeHTMLArea(jsChangeRecorder, application);
fl = application.getItemFactory().createDataTextEditor(so, getWebID(form, field), HTML_AREA, field.getEditable());
so.setComponent(fl, field);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
break;
case Field.TEXT_AREA:
{
RuntimeTextArea so;
scriptable = so = new RuntimeTextArea(jsChangeRecorder, application);
fl = application.getItemFactory().createDataTextArea(so, getWebID(form, field));
so.setComponent(fl, field);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
break;
case Field.CHECKS:
{
AbstractRuntimeValuelistComponent<IFieldComponent> so;
if (valuelist != null) {
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
if (isSingleValue(valuelist)) {
scriptable = so = new RuntimeCheckbox(jsChangeRecorder, application);
fl = application.getItemFactory().createCheckBox((RuntimeCheckbox) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), list);
} else {
scriptable = so = new RuntimeCheckBoxChoice(jsChangeRecorder, application);
fl = application.getItemFactory().createDataChoice((RuntimeCheckBoxChoice) so, getWebID(form, field), list, false, fieldFormat == null || fieldFormat.dpType == IColumnTypes.TEXT);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
} else {
scriptable = so = new RuntimeCheckbox(jsChangeRecorder, application);
fl = application.getItemFactory().createCheckBox((RuntimeCheckbox) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), null);
}
so.setComponent(fl, field);
}
break;
case Field.RADIOS:
{
AbstractRuntimeValuelistComponent<IFieldComponent> so;
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
if (isSingleValue(valuelist)) {
scriptable = so = new RuntimeRadioButton(jsChangeRecorder, application);
fl = application.getItemFactory().createRadioButton((RuntimeRadioButton) so, getWebID(form, field), application.getI18NMessageIfPrefixed(field.getText()), list);
} else {
scriptable = so = new RuntimeRadioChoice(jsChangeRecorder, application);
fl = application.getItemFactory().createDataChoice((RuntimeRadioChoice) so, getWebID(form, field), list, true, false);
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
}
so.setComponent(fl, field);
}
break;
case Field.COMBOBOX:
{
RuntimeDataCombobox so;
scriptable = so = new RuntimeDataCombobox(jsChangeRecorder, application);
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
fl = application.getItemFactory().createDataComboBox(so, getWebID(form, field), list);
so.setComponent(fl, field);
}
break;
case Field.CALENDAR:
{
RuntimeDataCalendar so;
scriptable = so = new RuntimeDataCalendar(jsChangeRecorder, application);
fl = application.getItemFactory().createDataCalendar(so, getWebID(form, field));
so.setComponent(fl, field);
}
break;
case Field.IMAGE_MEDIA:
{
RuntimeMediaField so;
scriptable = so = new RuntimeMediaField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataImgMediaField(so, getWebID(form, field));
if (fl instanceof IScrollPane) {
applyScrollBarsProperty((IScrollPane) fl, field);
}
so.setComponent(fl, field);
}
break;
case Field.TYPE_AHEAD:
if (field.getValuelistID() > 0) {
fl = createTypeAheadWithValueList(application, form, field, dataProviderLookup, fieldFormat.uiType, fieldFormat.parsedFormat, jsChangeRecorder);
if (fl == null)
return null;
scriptable = (AbstractRuntimeField<? extends IFieldComponent>) fl.getScriptObject();
break;
}
if (// only allow plain columns
dp != null && dp.getColumnWrapper() != null && dp.getColumnWrapper().getRelations() == null) {
RuntimeDataLookupField so;
scriptable = so = new RuntimeDataLookupField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataLookupField(so, getWebID(form, field), form.getServerName(), form.getTableName(), dp == null ? field.getDataProviderID() : dp.getDataProviderID());
so.setComponent(fl, field);
break;
} else {
RuntimeDataField so;
scriptable = so = new RuntimeDataField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataField(so, getWebID(form, field));
so.setComponent(fl, field);
break;
}
// $FALL-THROUGH$
case Field.LIST_BOX:
case Field.MULTISELECT_LISTBOX:
{
boolean multiSelect = (field.getDisplayType() == Field.MULTISELECT_LISTBOX);
RuntimeListBox so;
scriptable = so = new RuntimeListBox(jsChangeRecorder, application, multiSelect);
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
fl = application.getItemFactory().createListBox(so, getWebID(form, field), list, multiSelect);
so.setComponent(fl, field);
}
break;
case Field.SPINNER:
{
RuntimeSpinner so;
scriptable = so = new RuntimeSpinner(jsChangeRecorder, application);
IValueList list = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, field.getDataProviderID());
fl = application.getItemFactory().createSpinner(so, getWebID(form, field), list);
so.setComponent(fl, field);
break;
}
// else treat as the default case: TEXT_FIELD
default:
// Field.TEXT_FIELD
if (field.getValuelistID() > 0) {
fl = createTypeAheadWithValueList(application, form, field, dataProviderLookup, fieldFormat.uiType, fieldFormat.parsedFormat, jsChangeRecorder);
if (fl == null)
return null;
scriptable = (AbstractRuntimeField<? extends IFieldComponent>) fl.getScriptObject();
} else {
RuntimeDataField so;
scriptable = so = new RuntimeDataField(jsChangeRecorder, application);
fl = application.getItemFactory().createDataField(so, getWebID(form, field));
so.setComponent(fl, field);
}
}
if (fl instanceof ISupportAsyncLoading) {
((ISupportAsyncLoading) fl).setAsyncLoadingEnabled(!printing);
}
fl.setSelectOnEnter(field.getSelectOnEnter());
fl.setEditable(field.getEditable());
try {
int halign = field.getHorizontalAlignment();
if (halign != -1) {
fl.setHorizontalAlignment(halign);
} else if (style_halign != -1) {
fl.setHorizontalAlignment(style_halign);
}
} catch (RuntimeException e) {
// just ignore...Debug.error(e);
}
fl.setToolTipText(application.getI18NMessageIfPrefixed(field.getToolTipText()));
fl.setTitleText(application.getI18NMessageIfPrefixed(field.getText()));
fl.setDataProviderID(dp == null ? field.getDataProviderID() : dp.getDataProviderID());
if (field.getDataProviderID() != null && dataProviderLookup != null) {
if (scriptable instanceof IFormatScriptComponent) {
((IFormatScriptComponent) scriptable).setComponentFormat(fieldFormat);
}
if (dp != null) {
// if (valuelist != null && valuelist.getValueListType() != ValueList.CUSTOM_VALUES) type = valuelist.getDisplayValueType();
int l = dp.getLength();
int defaultType = Column.mapToDefaultType(fieldFormat.dpType);
boolean skipMaxLength = false;
if (valuelist != null) {
// if the display values are different than the real values, then maxlength should be skipped
IValueList vl = getRealValueList(application, valuelist, true, fieldFormat.dpType, fieldFormat.parsedFormat, dp.getDataProviderID());
skipMaxLength = vl.hasRealValues();
}
if (l > 0 && (defaultType == IColumnTypes.TEXT || defaultType == IColumnTypes.MEDIA) && !skipMaxLength) {
fl.setMaxLength(l);
}
}
}
// fl.setOpaque(!field.getTransparent());
if (field.getDisplaysTags()) {
fl.setNeedEntireState(true);
if (field.getDataProviderID() == null && field.getText() != null && fl instanceof IDisplayTagText) {
((IDisplayTagText) fl).setTagText(field.getText());
}
}
if (// el is an ActionListener
el != null) {
fl.addScriptExecuter(el);
Object[] cmds = combineMethodsToCommands(form, form.getOnElementFocusGainedMethodID(), "onElementFocusGainedMethodID", field, field.getOnFocusGainedMethodID(), "onFocusGainedMethodID");
if (cmds != null)
fl.setEnterCmds((String[]) cmds[0], (Object[][]) cmds[1]);
cmds = combineMethodsToCommands(form, form.getOnElementFocusLostMethodID(), "onElementFocusLostMethodID", field, field.getOnFocusLostMethodID(), "onFocusLostMethodID");
if (cmds != null)
fl.setLeaveCmds((String[]) cmds[0], (Object[][]) cmds[1]);
if (field.getOnActionMethodID() > 0)
fl.setActionCmd(Integer.toString(field.getOnActionMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onActionMethodID")));
if (field.getOnDataChangeMethodID() > 0)
fl.setChangeCmd(Integer.toString(field.getOnDataChangeMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onDataChangeMethodID")));
if (field.getOnRightClickMethodID() > 0)
fl.setRightClickCommand(Integer.toString(field.getOnRightClickMethodID()), Utils.parseJSExpressions(field.getFlattenedMethodArguments("onRightClickMethodID")));
}
int onRenderMethodID = field.getOnRenderMethodID();
AbstractBase onRenderPersist = field;
if (onRenderMethodID <= 0) {
onRenderMethodID = form.getOnRenderMethodID();
onRenderPersist = form;
}
if (onRenderMethodID > 0) {
RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
IForm rendererForm = application.getFormManager().getForm(form.getName());
IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
}
applyBasicComponentProperties(application, fl, field, styleInfo);
if (fl instanceof INullableAware) {
INullableAware nullAware = (INullableAware) fl;
boolean allowNull = true;
// become 0 (because it is unchecked) so that the user does not need to check/uncheck it for save
try {
if (dataProviderLookup != null && dataProviderLookup.getTable() != null && field.getDataProviderID() != null) {
String dataproviderId = dp == null ? field.getDataProviderID() : dp.getDataProviderID();
if (dataProviderLookup.getTable().getColumn(dataproviderId) != null) {
allowNull = dataProviderLookup.getTable().getColumn(dataproviderId).getAllowNull();
}
}
} catch (RepositoryException e) {
// maybe this field is not linked to a table column... so leave it true
}
nullAware.setAllowNull(allowNull);
}
Insets m = field.getMargin();
if (m == null)
m = style_margin;
if (m != null) {
fl.setMargin(m);
if (fl instanceof IMarginAwareBorder) {
if (field.getBorderType() != null || hasBorder) {
Border b = fl.getBorder();
if (b != null) {
fl.setBorder(BorderFactory.createCompoundBorder(b, BorderFactory.createEmptyBorder(m.top, m.left, m.bottom, m.right)));
}
}
}
}
if (fl.getScriptObject() instanceof HasRuntimePlaceholder) {
((HasRuntimePlaceholder) fl.getScriptObject()).setPlaceholderText(field.getPlaceholderText());
}
return fl;
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class LookupListModel method fillDBValueListValues.
/**
* @param txt
* @throws Exception
* @throws RepositoryException
* @throws RemoteException
*/
private void fillDBValueListValues(String filter) throws ServoyException {
ValueList valueList = ((LookupValueList) lookup).getValueList();
QuerySelect sqlParts = AbstractBaseQuery.deepClone(creationSQLParts);
if (!generateWherePart(filter, valueList, sqlParts, sqlParts.getTable())) {
ArrayList<IQuerySort> sorts = getSortColumnsForQuery(sqlParts);
if (sorts != null)
sqlParts.setSorts(sorts);
}
try {
FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), sqlParts);
if (// apply name as filter on column valuelist_name in creationSQLParts
nameFilter != null) {
if (tableFilterParams == null) {
tableFilterParams = new ArrayList<TableFilter>();
}
tableFilterParams.add(nameFilter);
}
SQLStatement trackingInfo = null;
if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), table.getName(), null, null);
trackingInfo.setTrackingData(sqlParts.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
}
IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, sqlParts, null, tableFilterParams, !sqlParts.isUnique(), 0, 100, IDataServer.VALUELIST_QUERY, trackingInfo);
String[] displayFormat = (lookup instanceof LookupValueList) ? ((LookupValueList) lookup).getDisplayFormat() : null;
for (int i = 0; i < set.getRowCount(); i++) {
Object[] row = processRow(set.getRow(i));
DisplayString display = CustomValueList.handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application);
if (display != null) {
alDisplay.add(display);
alReal.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, row, application));
}
}
hadMoreRows = set.hadMoreRows();
} catch (RemoteException e) {
throw new RepositoryException(e);
}
}
use of com.servoy.j2db.persistence.ValueList in project servoy-client by Servoy.
the class LookupListModel method fillRelatedValueListValues.
/**
* @param txt
* @throws RemoteException
* @throws Exception
*/
private void fillRelatedValueListValues(IRecordInternal parentState, String filter) throws ServoyException {
if (parentState == null)
return;
String txt = filter;
ValueList valueList = ((LookupValueList) lookup).getValueList();
Relation[] relations = application.getFlattenedSolution().getRelationSequence(valueList.getRelationName());
Pair<QuerySelect, BaseQueryTable> pair = RelatedValueList.createRelatedValuelistQuery(application, valueList, relations, parentState);
if (pair == null) {
return;
}
QuerySelect select = pair.getLeft();
BaseQueryTable qTable = pair.getRight();
generateWherePart(txt, valueList, select, qTable);
try {
FoundSetManager foundSetManager = ((FoundSetManager) application.getFoundSetManager());
String transaction_id = foundSetManager.getTransactionID(table.getServerName());
ArrayList<TableFilter> tableFilterParams = foundSetManager.getTableFilterParams(table.getServerName(), select);
if (// apply name as filter on column valuelist_name in creationSQLParts
nameFilter != null) {
if (tableFilterParams == null) {
tableFilterParams = new ArrayList<TableFilter>();
}
tableFilterParams.add(nameFilter);
}
SQLStatement trackingInfo = null;
if (foundSetManager.getEditRecordList().hasAccess(table, IRepository.TRACKING_VIEWS)) {
trackingInfo = new SQLStatement(ISQLActionTypes.SELECT_ACTION, table.getServerName(), qTable.getName(), null, null);
trackingInfo.setTrackingData(select.getColumnNames(), new Object[][] {}, new Object[][] {}, application.getUserUID(), foundSetManager.getTrackingInfo(), application.getClientID());
}
IDataSet set = application.getDataServer().performQuery(application.getClientID(), table.getServerName(), transaction_id, select, null, tableFilterParams, true, 0, 100, IDataServer.VALUELIST_QUERY, trackingInfo);
String[] displayFormat = (lookup instanceof LookupValueList) ? ((LookupValueList) lookup).getDisplayFormat() : null;
for (int i = 0; i < set.getRowCount(); i++) {
Object[] row = processRow(set.getRow(i));
DisplayString display = CustomValueList.handleDisplayData(valueList, displayFormat, concatShowValues, showValues, row, application);
if (display != null) {
alDisplay.add(display);
alReal.add(CustomValueList.handleRowData(valueList, concatReturnValues, returnValues, row, application));
}
}
hadMoreRows = set.hadMoreRows();
} catch (RemoteException e) {
throw new RepositoryException(e);
}
}
Aggregations