use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class SortableCellViewHeaderGroup method sort.
protected final void sort(final String name, final WebCellBasedView view, int modifiers) {
direction = Utils.getAsBoolean(sorted.get(name));
direction = !direction;
FormController fc = null;
try {
Iterator<IPersist> it = cellview.getAllObjects();
while (it.hasNext()) {
IPersist element = it.next();
if (element instanceof ISupportName && element instanceof ISupportDataProviderID) {
if (name.equals(ComponentFactory.getWebID(form, element))) {
IFoundSetInternal fs = ((FoundSetListWrapper) listView.getList()).getFoundSet();
if (fs != null) {
WebForm wf = listView.findParent(WebForm.class);
if (wf != null)
fc = wf.getController();
GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
int labelForOnActionMethodId = 0;
if (gc != null) {
labelForOnActionMethodId = gc.getOnActionMethodID();
}
if (fc != null && labelForOnActionMethodId > 0) {
// execute on action
JSEvent event = new JSEvent();
event.setType(JSEvent.EventType.action);
event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
event.setFormName(view.getDataAdapterList().getFormController().getName());
event.setModifiers(modifiers);
event.setElementName(gc.getName());
fc.executeFunction(String.valueOf(labelForOnActionMethodId), // $NON-NLS-1$
Utils.arrayMerge((new Object[] { event }), Utils.parseJSExpressions(gc.getFlattenedMethodArguments("onActionMethodID"))), true, null, false, // $NON-NLS-1$
"onActionMethodID");
}
String id = ((ISupportDataProviderID) element).getDataProviderID();
if (id != null) {
if (cellview instanceof Portal && !ScopesUtils.isVariableScope(id)) {
int idx = id.lastIndexOf('.');
if (idx > 0) {
id = id.substring(idx + 1);
}
}
IDataProvider dataProvider = null;
if (fc != null) {
dataProvider = fs.getFoundSetManager().getApplication().getFlattenedSolution().getDataproviderLookup(fs.getFoundSetManager(), fc.getForm()).getDataProvider(id);
}
if (!(fc != null && labelForOnActionMethodId > 0)) {
// in case there is no onAction definned
if (cellview instanceof Portal || fc == null || fc.getForm().getOnSortCmdMethodID() == 0) {
List<String> sortingProviders = null;
try {
sortingProviders = DBValueList.getShowDataproviders(fs.getFoundSetManager().getApplication().getFlattenedSolution().getValueList(((ISupportDataProviderID) element).getValuelistID()), (Table) fs.getTable(), dataProvider == null ? id : dataProvider.getDataProviderID(), fs.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(dataProvider == null ? id : dataProvider.getDataProviderID());
}
List<SortColumn> list = (modifiers & Event.SHIFT_MASK) != 0 ? fs.getSortColumns() : new ArrayList<SortColumn>();
for (String sortingProvider : sortingProviders) {
FoundSetManager fsm = (FoundSetManager) fs.getFoundSetManager();
SortColumn sc = fsm.getSortColumn(fs.getTable(), sortingProvider, false);
if (sc != null && sc.getColumn().getDataProviderType() != IColumnTypes.MEDIA) {
for (SortColumn oldColumn : list) {
if (oldColumn.equalsIgnoreSortorder(sc)) {
sc = oldColumn;
break;
}
}
if (!list.contains(sc))
list.add(sc);
sc.setSortOrder(direction ? SortColumn.ASCENDING : SortColumn.DESCENDING);
}
fs.sort(list, false);
}
} else if (fc != null && fc.getForm().getOnSortCmdMethodID() != -1) {
JSEvent event = new JSEvent();
event.setType(JSEvent.EventType.none);
event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
event.setFormName(view.getDataAdapterList().getFormController().getName());
event.setModifiers(modifiers);
fc.executeFunction(String.valueOf(fc.getForm().getOnSortCmdMethodID()), Utils.arrayMerge((new Object[] { dataProvider == null ? id : dataProvider.getDataProviderID(), Boolean.valueOf(direction), event }), // $NON-NLS-1$
Utils.parseJSExpressions(fc.getForm().getFlattenedMethodArguments("onSortCmdMethodID"))), true, null, false, // $NON-NLS-1$
"onSortCmdMethodID");
}
}
if ((modifiers & Event.SHIFT_MASK) == 0) {
sorted.clear();
}
sorted.put(name, new Boolean(direction));
listView.setCurrentPage(0);
}
}
break;
}
}
}
listView.modelChanged();
} catch (Exception e) {
if (fc != null) {
if (e instanceof ServoyException) {
((ServoyException) e).setContext(fc.toString());
} else {
ServoyException se = new ServoyException();
se.initCause(e);
se.setContext(fc.toString());
e = se;
}
}
Debug.error("error sorting foundset: " + sorted, e);
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class DataproviderTypeSabloValue method detach.
@Override
public void detach() {
// unregister listeners
dataAdapterList.removeDataLinkedProperty(this);
dataAdapterList.removeFindModeAwareProperty(this);
if (globalRelatedFoundset != null) {
globalRelatedFoundset.removeFoundSetEventListener(globalRelatedFoundsetListener);
}
globalRelatedFoundset = null;
globalRelatedFoundsetListener = null;
if (relatedFoundsets.size() > 0 && relatedRecordModificationListener != null) {
// just remove it, no need to test this because a remove will be just a NOP when it was not registered anyway.
relatedFoundsets.get(relatedFoundsets.size() - 1).removeAggregateModificationListener(relatedRecordModificationListener);
}
for (IFoundSetInternal relatedFoundset : relatedFoundsets) {
((ISwingFoundSet) relatedFoundset).getSelectionModel().removeListSelectionListener(relatedFoundsetSelectionListener);
}
relatedFoundsets = Collections.emptyList();
if (relatedRecordModificationListener != null) {
for (IRecordInternal relatedRecord : relatedRecords) {
relatedRecord.removeModificationListener(relatedRecordModificationListener);
}
}
relatedRecords = Collections.emptyList();
webObjectContext = null;
changeMonitor = null;
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal 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.IFoundSetInternal in project servoy-client by Servoy.
the class FoundsetTypeSabloValue method updateFoundset.
/**
* Find the foundset to be used based on the design value of "foundsetSelector".\n
* It can be either:
* <ul>
* <li>a related foundset based on the component's current record (as one would access it in scripting). Example: "customers_to_orders";</li>
* <li>the component's foundset (as if in scripting you would say 'foundset') - if foundsetSelector is not specified at design time or null;</li>
* <li>a new foundset based on the given datasource (as if you would do DatabaseManager.getFoundset(datasource) in scripting). Example: "db:/example_data/customers".</li>
* </ul>
*
* @param record the record this component is attached to; can be null. (form not linked to table or no records for example)
*
* @return true if the foundset was update, false otherwise.
*/
protected void updateFoundset(IRecordInternal record) {
// this foundset is only meant to be set from Rhino scripting; do not automatically set it and do not automatically clear it once it's set from Rhino
if (foundsetSelector == null)
return;
IFoundSetInternal newFoundset = null;
if (FORM_FOUNDSET_SELECTOR.equals(foundsetSelector)) {
// it is the form's foundset then
if (record != null) {
newFoundset = record.getParentFoundSet();
}
} else if (!DataSourceUtils.isDatasourceUri(foundsetSelector)) {
// it is a relation then or a shared named foundset (set somewhere on a form in designer)
if (record != null) {
Object o = record.getValue(foundsetSelector);
if (o instanceof IFoundSetInternal) {
// it is a related foundset then if we were able to get it from current record
newFoundset = (IFoundSetInternal) o;
if (chainedRelatedFoundsetSelectionMonitor == null) {
chainedRelatedFoundsetSelectionMonitor = new ChainedRelatedFoundsetSelectionMonitor(new IRelatedFoundsetChainSelectionChangeListener() {
@Override
public void selectionChanged(IRecordInternal rootRecord, String nestedRelationNames) {
updateFoundset(rootRecord);
}
});
}
chainedRelatedFoundsetSelectionMonitor.update(newFoundset, record, foundsetSelector);
} else {
// if it is not a related foundset it must be a shared/named foundset
try {
newFoundset = (IFoundSetInternal) getFoundSetManager().getNamedFoundSet(foundsetSelector);
} catch (ServoyException e) {
Debug.error(e);
}
}
}
} else // DataSourceUtils.isDatasourceUri(foundsetSelector)
{
// that will only reinitialize constantly this FoundsetType/Table with a new foundset - on every dataprovider change.
if (foundset != null)
newFoundset = foundset;
else {
try {
// if we want to use this type on services as well we need extra code here to get the application
newFoundset = (IFoundSetInternal) getFoundSetManager().getFoundSet(foundsetSelector);
if (((JSONObject) designJSONValue).optBoolean(FoundsetPropertyType.LOAD_ALL_RECORDS_FOR_SEPARATE, false)) {
newFoundset.loadAllRecords();
}
} catch (ServoyException e) {
if (record != null && !(record instanceof PrototypeState))
Debug.error(e);
}
}
}
updateFoundset(newFoundset);
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class DebugNGClient method refreshForms.
private void refreshForms(Collection<IFormController> forms, boolean forcePageReload) {
boolean reload = forcePageReload;
if (forms != null && forms.size() > 0) {
reload = true;
List<IFormController> cachedFormControllers = getFormManager().getCachedFormControllers();
for (IFormController formController : cachedFormControllers) {
if (formController.getFormUI() instanceof WebFormUI) {
((WebFormUI) formController.getFormUI()).clearCachedFormElements();
}
}
// should we also use these?
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
for (IFormController controller : forms) {
boolean isVisible = controller.isFormVisible();
if (isVisible)
controller.notifyVisible(false, invokeLaterRunnables);
if (controller.getFormModel() != null && !Utils.stringSafeEquals(controller.getDataSource(), controller.getFormModel().getDataSource())) {
// for now we just destroy the form and recreate it with the other datasource;
// TODO we just load the shared foundset for that datasource - can we improve this somehow so that the loaded foundset is closer to the current runtime situation of the form? (related tabs etc.)
String name = controller.getName();
controller.destroy();
controller = getFormManager().leaseFormPanel(name);
IFoundSetInternal foundset;
try {
foundset = getFoundSetManager().getSharedFoundSet(controller.getDataSource());
foundset.loadAllRecords();
controller.loadRecords(foundset);
} catch (ServoyException e) {
Debug.error(e);
}
} else {
if (!controller.isDestroyed())
((WebFormController) controller).initFormUI();
}
if (isVisible)
controller.notifyVisible(true, invokeLaterRunnables);
}
}
if (reload) {
WebsocketSessionWindows allendpoints = new NGClientWebsocketSessionWindows(getWebsocketSession());
allendpoints.executeAsyncServiceCall(getWebsocketSession().getClientService(NGRuntimeWindowManager.WINDOW_SERVICE), "reload", null, null);
try {
allendpoints.flush();
} catch (IOException e) {
reportError("error sending changes to the client", e);
}
}
}
Aggregations