use of com.servoy.j2db.persistence.Relation 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.Relation in project servoy-client by Servoy.
the class FoundsetTypeSabloValue method attachToBaseObject.
@Override
public void attachToBaseObject(IChangeListener changeNotifier, IWebObjectContext webObjectCntxt) {
this.webObjectContext = webObjectCntxt;
dataAdapterList = null;
changeMonitor.setChangeNotifier(changeNotifier);
// get the foundset identifier, then the foundset itself
// foundset: {
// foundsetSelector: 'string',
// dataProviders: 'dataprovider[]'
// }
updateFoundset((IRecordInternal) null);
if (designJSONValue != null) {
JSONObject designValue = (JSONObject) designJSONValue;
JSONObject dataProvidersJSON = designValue.optJSONObject(FoundsetPropertyType.DATAPROVIDERS_KEY_FOR_DESIGN);
if (dataProvidersJSON != null) {
changeMonitor.dataProvidersChanged();
}
}
// register parent record changed listener
if (parentDAL != null) {
TargetDataLinks dataLinks = TargetDataLinks.LINKED_TO_ALL;
if (foundsetSelector != null && !FORM_FOUNDSET_SELECTOR.equals(foundsetSelector) && !DataSourceUtils.isDatasourceUri(foundsetSelector)) {
// it is a relation then, not a datasource (separate or named foundset)
int lastIndex = foundsetSelector.lastIndexOf('.');
if (lastIndex > 0) {
// if this is a nested relation the parent dal needs to know this. so it can monitor the parent relations.
Relation[] relations = getApplication().getFlattenedSolution().getRelationSequence(foundsetSelector.substring(0, lastIndex));
if (relations != null && relations.length > 0) {
dataLinks = new TargetDataLinks(null, true, relations);
}
}
}
parentDAL.addDataLinkedProperty(this, dataLinks);
}
// we now have a webObjectContext so getDataAdapterList() might return non-null now; in some cases this is all other properties need, they don't need the foundset itself
fireUnderlyingStateChangedListeners();
}
use of com.servoy.j2db.persistence.Relation 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.Relation in project servoy-client by Servoy.
the class NGClientWindow method registerAllowedRelation.
@Override
public String registerAllowedRelation(String relationName, INGFormElement element) {
String relName = "-1";
if (relationName != null) {
Relation[] relations = getSession().getClient().getFlattenedSolution().getRelationSequence(relationName);
if (relations != null) {
for (Relation relation : relations) {
if (relation != null) {
if ("-1".equals(relName)) {
relName = Integer.toHexString(relation.getID());
} else {
relName += Integer.toHexString(relation.getID());
}
}
}
}
}
WeakHashMap<INGFormElement, String> weakSet = allowedRelation.get(relName);
if (weakSet == null) {
weakSet = new WeakHashMap<>();
WeakHashMap<INGFormElement, String> current = allowedRelation.putIfAbsent(relName, weakSet);
if (current != null)
weakSet = current;
}
weakSet.put(element, relationName);
return relName;
}
use of com.servoy.j2db.persistence.Relation in project servoy-client by Servoy.
the class DataAdapterList method addVisibleChildForm.
public void addVisibleChildForm(IWebFormController form, String relation, boolean shouldUpdateParentFormController) {
if (form == formController) {
Debug.error("Form " + form + " is added as a visible child form over relation " + relation + " to itself ", new RuntimeException("Form " + form + " is added as a visible child form over relation " + relation + " to itself "));
return;
}
if (shouldUpdateParentFormController) {
form.setParentFormController(formController);
} else {
form.getFormUI().getDataAdapterList().addParentRelatedForm(getForm());
}
if (relation != null) {
HashMap<IWebFormController, String> childFormsCopy = getVisibleChildFormCopy();
for (Entry<IWebFormController, String> relatedFormEntry : childFormsCopy.entrySet()) {
IWebFormController relatedForm = relatedFormEntry.getKey();
String relatedFormRelation = relatedFormEntry.getValue();
if (relatedFormRelation != null) {
if (relatedFormRelation.startsWith(relation + ".") && relatedFormRelation.length() > relation.length()) {
if (!containsForm(form.getFormUI(), relatedForm.getFormUI())) {
form.getFormUI().getDataAdapterList().addVisibleChildForm(relatedForm, relatedFormRelation.substring(relation.length() + 1), false);
}
} else if (relation.startsWith(relatedFormRelation + ".") && relation.length() > relatedFormRelation.length()) {
if (!containsForm(relatedForm.getFormUI(), form.getFormUI())) {
relatedForm.getFormUI().getDataAdapterList().addVisibleChildForm(form, relation.substring(relatedFormRelation.length() + 1), false);
}
}
}
}
if (!isGlobalScopeListener) {
Relation[] relations = formController.getApplication().getFlattenedSolution().getRelationSequence(relation);
if (relations != null) {
for (Relation relationObj : relations) {
if (relationObj != null && relationObj.containsGlobal()) {
formController.getApplication().getScriptEngine().getScopesScope().getModificationSubject().addModificationListener(this);
isGlobalScopeListener = true;
break;
}
}
}
}
}
visibleChildForms.put(form, relation);
}
Aggregations