use of com.servoy.j2db.dataprocessing.FoundSetManager in project servoy-client by Servoy.
the class TableView method setSortStatus.
public boolean setSortStatus(IFoundSetInternal foundset) {
if (foundset != null) {
List<SortColumn> sortCols = foundset.getSortColumns();
if (sortCols != null && sortCols.size() > 0) {
boolean found = false;
for (SortColumn sc : sortCols) {
for (int i = 0; (i < getColumnModel().getColumnCount()); i++) {
TableColumn tc = getColumnModel().getColumn(i);
if (tc instanceof CellAdapter) {
CellAdapter ca = (CellAdapter) tc;
if (ca.getDataProviderID() != null) {
List<String> sortingProviders = null;
Component renderer = ca.getRenderer();
if (renderer instanceof ISupportValueList && ((ISupportValueList) renderer).getValueList() != null) {
try {
sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) renderer).getValueList().getValueList(), (Table) foundset.getTable(), ca.getDataProviderID(), application.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(ca.getDataProviderID());
}
for (String sortingProvider : sortingProviders) {
SortColumn existingSc;
try {
FoundSetManager fsm = (FoundSetManager) foundset.getFoundSetManager();
existingSc = fsm.getSortColumn(foundset.getTable(), sortingProvider, false);
} catch (Exception e) {
Debug.error(e);
continue;
}
if (sc.equalsIgnoreSortorder(existingSc)) {
if (!found) {
// clear old sort
updateSortStatus(-1, true);
}
found = true;
updateSortStatus(ca.getModelIndex(), sc.getSortOrder() == SortColumn.ASCENDING);
}
}
}
}
}
}
return found;
}
}
return false;
}
use of com.servoy.j2db.dataprocessing.FoundSetManager in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method tableChanged.
/**
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
*/
public void tableChanged(TableModelEvent e) {
// as changed, as it will be faster on the client the component replace
if ((e.getType() == TableModelEvent.UPDATE) && (e.getFirstRow() == e.getLastRow()) && (nrUpdatedListItems < 20)) {
Component component = table.get(Integer.toString(e.getFirstRow()));
if (component instanceof ListItem) {
((ListItem) component).visitChildren(IProviderStylePropertyChanges.class, new IVisitor<Component>() {
public Object component(Component comp) {
if ((comp instanceof IDisplayData) || !(comp instanceof ILabel)) {
if (comp instanceof ISupportsNeedEntireState && ((ISupportsNeedEntireState) comp).needEntireState()) {
// it if has tags - mark as changed; it could be enhanced further by also know what was last-rendered on tags, not just simple dataproviders
((IProviderStylePropertyChanges) comp).getStylePropertyChanges().setChanged();
} else {
// try to mark cells as changed only if there was a real value change; otherwise there is no use to replace the whole row...
checkForValueChanges(comp);
}
}
// else labels/buttons that don't display data are not changed
return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
});
nrUpdatedListItems++;
IModel<IRecordInternal> newModel = table.getListItemModel(table.getModel(), e.getFirstRow());
IModel oldModel = ((ListItem) component).getModel();
if (newModel != null && oldModel != null && newModel.getObject() != null && !newModel.getObject().equals(oldModel.getObject())) {
// refresh model if it changed
((ListItem) component).setModel(newModel);
}
}
} else {
if (!isRendering && (!isScrollMode() || !(scrollBehavior != null && scrollBehavior.isGettingRows()))) {
if (isScrollMode())
resetScrollParams();
getStylePropertyChanges().setValueChanged();
}
}
// This is just an heuristic for filtering out the sort event from all table changed events that are raised.
if (currentData != null && e.getColumn() == TableModelEvent.ALL_COLUMNS && e.getFirstRow() == 0 && elementToColumnHeader.size() > 0) {
List<SortColumn> sortCols = currentData.getSortColumns();
if (sortCols != null && sortCols.size() > 0) {
Map<String, Boolean> sortMap = new HashMap<String, Boolean>();
for (IPersist persist : elementToColumnHeader.keySet()) {
SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
sortableCellViewHeader.setResizeImage(R_ARROW_OFF);
}
for (SortColumn sc : sortCols) {
for (IPersist persist : elementToColumnHeader.keySet()) {
Component comp = elementToColumnIdentifierComponent.get(persist);
SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
if (comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null) {
IDisplayData dispComp = (IDisplayData) comp;
List<String> sortingProviders = null;
if (dispComp instanceof ISupportValueList && ((ISupportValueList) dispComp).getValueList() != null) {
try {
sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) dispComp).getValueList().getValueList(), (Table) currentData.getTable(), dispComp.getDataProviderID(), currentData.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(dispComp.getDataProviderID());
}
for (String sortingProvider : sortingProviders) {
SortColumn existingSc;
try {
FoundSetManager fsm = (FoundSetManager) currentData.getFoundSetManager();
existingSc = fsm.getSortColumn(currentData.getTable(), sortingProvider, false);
} catch (RepositoryException ex) {
Debug.error(ex);
continue;
}
if (sc.equalsIgnoreSortorder(existingSc)) {
boolean descending = sc.getSortOrder() == SortColumn.DESCENDING;
sortableCellViewHeader.setResizeImage(descending ? R_ARROW_UP : R_ARROW_DOWN);
sortMap.put(sortableCellViewHeader.getId(), Boolean.valueOf(!descending));
}
}
}
}
}
headers.recordSort(sortMap);
}
}
MainPage mp = table.findParent(MainPage.class);
if (mp != null)
mp.triggerBrowserRequestIfNeeded();
}
use of com.servoy.j2db.dataprocessing.FoundSetManager in project servoy-client by Servoy.
the class ClientState method loadSecuritySettings.
public void loadSecuritySettings(FlattenedSolution root) throws ServoyException, RemoteException {
if (clientInfo.getUserUid() != null) {
Solution sol = root.getSolution();
String[] groups = clientInfo.getUserGroups();
if (// fall back on retrieval of groups based on user_uid
groups == null) {
groups = getUserManager().getUserGroups(clientInfo.getClientId(), clientInfo.getUserUid());
}
root.clearSecurityAccess();
int[] sids = new int[] { sol.getSolutionID() };
int[] srns = new int[] { sol.getReleaseNumber() };
Solution[] modules = root.getModules();
if (modules != null) {
sids = new int[modules.length + 1];
sids[0] = sol.getSolutionID();
srns = new int[modules.length + 1];
srns[0] = sol.getReleaseNumber();
for (int i = 0; i < modules.length; i++) {
Solution module = modules[i];
sids[i + 1] = module.getSolutionID();
srns[i + 1] = module.getReleaseNumber();
}
}
Pair<Map<Object, Integer>, Set<Object>> securityAccess = getUserManager().getSecurityAccess(clientInfo.getClientId(), sids, srns, groups);
root.addSecurityAccess(securityAccess);
if (foundSetManager != null) {
((FoundSetManager) foundSetManager).flushSecuritySettings();
}
}
}
use of com.servoy.j2db.dataprocessing.FoundSetManager in project servoy-client by Servoy.
the class ClientStub method notifyDataChange.
public void notifyDataChange(final String server_name, final String table_name, final IDataSet pks, final int sql_action, final Object[] insertColumnData) {
if (client.isShutDown())
return;
if (Debug.tracing()) {
Debug.trace(// $NON-NLS-1$//$NON-NLS-2$
"Notify Data Change get from the server for dataserver: " + server_name + " table: " + table_name + ". Pks: " + (pks != null ? "not null" : "null") + ". Action type: " + sql_action);
}
synchronized (datachanges) {
datachanges.push(new Object[] { server_name, table_name, pks, new Integer(sql_action), insertColumnData });
if (datachangesHandler == null) {
datachangesHandler = new Runnable() {
public void run() {
while (datachangesHandler != null) {
final Object[] array;
synchronized (datachanges) {
if (datachanges.isEmpty()) {
// done
datachangesHandler = null;
break;
}
array = datachanges.pop();
}
client.invokeLater(new Runnable() {
public void run() {
if (client.isShutDown() || !client.isSolutionLoaded())
return;
String sname = (String) array[0];
String tname = (String) array[1];
IDataSet pksDataSet = (IDataSet) array[2];
int action = ((Integer) array[3]).intValue();
Object[] insertColumndata = (Object[]) array[4];
IDataServer ds = client.getDataServer();
if (ds instanceof DataServerProxy) {
// possibly switched from multiple servers to the same destination server.
for (String srv : ((DataServerProxy) ds).getReverseMappedServerNames(sname)) {
((FoundSetManager) client.getFoundSetManager()).notifyDataChange(DataSourceUtils.createDBTableDataSource(srv, tname), pksDataSet, action, insertColumndata);
}
return;
}
// not switched
((FoundSetManager) client.getFoundSetManager()).notifyDataChange(DataSourceUtils.createDBTableDataSource(sname, tname), pksDataSet, action, insertColumndata);
}
});
}
}
};
client.getScheduledExecutor().execute(datachangesHandler);
}
}
}
use of com.servoy.j2db.dataprocessing.FoundSetManager 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);
}
}
Aggregations