use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class DataproviderTypeSabloValue method getRelatedFoundsets.
private ArrayList<IFoundSetInternal> getRelatedFoundsets(IRecordInternal record, String relName) {
ArrayList<IFoundSetInternal> returnRelatedFoundsets = new ArrayList<IFoundSetInternal>();
if (record != null) {
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(relName, ".");
String r = null;
while (st.hasMoreTokens()) {
if (r == null)
r = st.nextToken();
else
// $NON-NLS-1$
r = r + "." + st.nextToken();
IFoundSetInternal fs = record.getRelatedFoundSet(r);
if (fs != null) {
returnRelatedFoundsets.add(fs);
}
}
}
return returnRelatedFoundsets;
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class ColumnSortListener method mouseClicked.
/*
* (non-Javadoc)
*
* @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (!table.isEnabled())
return;
if (e.getButton() == MouseEvent.BUTTON1) {
if (fc != null)
fc.setLastKeyModifiers(e.getModifiers());
TableColumnModel colModel = table.getColumnModel();
if (colModel == null) {
return;
}
int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
if (columnModelIndex < 0) {
return;
}
final TableColumn column = colModel.getColumn(columnModelIndex);
if (column == null) {
return;
}
int modelIndex = column.getModelIndex();
if (modelIndex < 0) {
return;
}
if (table.getModel() instanceof IFoundSetInternal && application.getFoundSetManager().getEditRecordList().stopIfEditing((IFoundSetInternal) table.getModel()) != ISaveConstants.STOPPED) {
return;
}
Integer columnIndex = Integer.valueOf(columnModelIndex);
if (lastColumnIndex.containsKey(columnIndex)) {
lastSortAsc = !lastColumnIndex.get(columnIndex).booleanValue();
} else {
lastSortAsc = true;
if (fc != null && column instanceof CellAdapter && ((CellAdapter) column).getDataProviderID() != null && e.getClickCount() <= 1 && table.getModel() instanceof IFoundSetInternal) {
IFoundSetInternal foundset = (IFoundSetInternal) table.getModel();
List<SortColumn> sortCols = foundset.getSortColumns();
if (sortCols != null && sortCols.size() > 0) {
CellAdapter ca = (CellAdapter) column;
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 ex) {
Debug.error(ex);
continue;
}
for (SortColumn sc : sortCols) {
if (sc.equalsIgnoreSortorder(existingSc)) {
lastSortAsc = sc.getSortOrder() == SortColumn.DESCENDING;
}
}
}
}
}
}
if (!e.isShiftDown()) {
// clear previous data
lastColumnIndex.clear();
}
lastColumnIndex.put(columnIndex, Boolean.valueOf(lastSortAsc));
if (column instanceof CellAdapter && table.getModel() instanceof IFoundSetInternal) {
try {
if (sortTimer != null) {
sortTimer.stop();
}
sortTimer = new Timer(300, new AbstractAction() {
public void actionPerformed(ActionEvent event) {
try {
String dataProviderID = ((CellAdapter) column).getDataProviderID();
int labelForOnActionMethodId = 0;
if (((CellAdapter) column).getHeaderRenderer() instanceof LFAwareSortableHeaderRenderer) {
labelForOnActionMethodId = ((LFAwareSortableHeaderRenderer) ((CellAdapter) column).getHeaderRenderer()).getOnActionMethodID();
}
if (fc != null && labelForOnActionMethodId > 0) {
LFAwareSortableHeaderRenderer renderer = (LFAwareSortableHeaderRenderer) (((CellAdapter) column).getHeaderRenderer());
fc.executeFunction(String.valueOf(labelForOnActionMethodId), Utils.arrayMerge((new Object[] { getJavaScriptEvent(e, JSEvent.EventType.action, renderer.getName()) }), Utils.parseJSExpressions(renderer.getFlattenedMethodArguments("onActionMethodID"))), true, null, false, // $NON-NLS-1$//$NON-NLS-2$
"onActionMethodID");
} else if (fc != null && fc.getForm().getOnSortCmdMethodID() > 0) {
// Also execute the on sort command on none data providers (like a label) then they can do there own sort.
fc.executeFunction(String.valueOf(fc.getForm().getOnSortCmdMethodID()), Utils.arrayMerge((new Object[] { dataProviderID, Boolean.valueOf(lastSortAsc), getJavaScriptEvent(e, JSEvent.EventType.none, null) }), Utils.parseJSExpressions(fc.getForm().getFlattenedMethodArguments("onSortCmdMethodID"))), true, null, false, // $NON-NLS-1$//$NON-NLS-2$
"onSortCmdMethodID");
} else if (dataProviderID != null && fc.getForm().getOnSortCmdMethodID() != -1) {
List<String> sortingProviders = null;
IFoundSetInternal model = (IFoundSetInternal) table.getModel();
Component renderer = ((CellAdapter) column).getRenderer();
if (renderer instanceof ISupportValueList && ((ISupportValueList) renderer).getValueList() != null) {
try {
sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) renderer).getValueList().getValueList(), (Table) model.getTable(), dataProviderID, application.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(dataProviderID);
}
try {
List<SortColumn> list = e.isShiftDown() ? model.getSortColumns() : new ArrayList<SortColumn>();
for (String sortingProvider : sortingProviders) {
FoundSetManager fsm = ((FoundSetManager) model.getFoundSetManager());
SortColumn sc = fsm.getSortColumn(model.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(lastSortAsc ? SortColumn.ASCENDING : SortColumn.DESCENDING);
}
model.sort(list, false);
}
} catch (Exception ex) {
Debug.error(ex);
}
}
} finally {
sortTimer.stop();
}
}
});
sortTimer.start();
} catch (Exception ex) {
Debug.error(ex);
}
}
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class DataLookupField method dependencyChanged.
public void dependencyChanged(IRecordInternal record) {
this.parentState = record;
if (list != null) {
Object o = getValue();
int index = -1;
if (dataProviderID != null && !ScopesUtils.isVariableScope(dataProviderID)) {
index = dataProviderID.lastIndexOf('.');
}
if (index == -1 || parentState == null || dataProviderID == null) {
list.fill(parentState);
} else {
IFoundSetInternal relatedFoundSet = parentState.getRelatedFoundSet(dataProviderID.substring(0, index));
if (relatedFoundSet == null) {
list.fill(parentState.getParentFoundSet().getPrototypeState());
} else if (relatedFoundSet.getSize() == 0) {
list.fill(relatedFoundSet.getPrototypeState());
} else {
IRecordInternal relatedRecord = relatedFoundSet.getRecord(relatedFoundSet.getSelectedIndex());
list.fill(relatedRecord);
}
}
if (editProvider != null) {
editProvider.setAdjusting(true);
}
try {
setValue(null);
setValue(o);
} finally {
if (editProvider != null) {
editProvider.setAdjusting(false);
}
}
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class PortalComponent method setRecord.
public void setRecord(IRecordInternal state, boolean stopEditing) {
if (stopEditing) {
stopUIEditing(true);
}
IFoundSetInternal relatedFoundSet = state == null ? null : state.getRelatedFoundSet(relationName, getDefaultSort());
// if is same changes are seen by model listener
if (currentData == relatedFoundSet)
return;
if (currentData != null) {
currentData.removeTableModelListener(this);
ListSelectionModel lsm = currentData.getSelectionModel();
lsm.removeListSelectionListener(this);
}
currentData = (ISwingFoundSet) relatedFoundSet;
ISupportOnRenderCallback portalRenderComponent = null;
if (table != null) {
if (currentData == null) {
// safety
table.removeEditor();
table.setSelectionModel(EMPTY_SELECTION);
table.setModel(EMPTY_DATA);
} else {
ListSelectionModel lsm = currentData.getSelectionModel();
int selected = currentData.getSelectedIndex();
table.setSelectionModel(lsm);
table.setModel((IFoundSetInternal) currentData);
currentData.setSelectedIndex(selected);
currentData.addTableModelListener(this);
lsm.addListSelectionListener(this);
valueChanged(null, stopEditing);
}
portalRenderComponent = table.getOnRenderComponent();
} else {
if (currentData == null) {
list.setSelectionModel(EMPTY_SELECTION);
list.setModel(new AbstractEditListModel() {
public Object getElementAt(int i) {
return null;
}
public int getSize() {
return 0;
}
});
} else {
list.setSelectionModel(EMPTY_SELECTION);
ListSelectionModel lsm = currentData.getSelectionModel();
list.setModel(currentData);
list.setSelectionModel(lsm);
currentData.addTableModelListener(this);
lsm.addListSelectionListener(this);
valueChanged(null, stopEditing);
}
portalRenderComponent = list.getOnRender();
}
scriptable.setFoundset(currentData);
if (currentData != null && portalRenderComponent != null && portalRenderComponent.getRenderEventExecutor().hasRenderCallback()) {
portalRenderComponent.getRenderEventExecutor().setRenderState(null, -1, false, true);
portalRenderComponent.getRenderEventExecutor().fireOnRender(false);
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class SpecialSplitPane method showFoundSet.
private void showFoundSet(FormLookupPanel flp, IRecordInternal parentState, List<SortColumn> sort) {
deregisterSelectionListeners();
if (!flp.isReady())
return;
try {
FormController fp = flp.getFormPanel();
if (fp != null && flp.getRelationName() != null) {
IFoundSetInternal relatedFoundSet = parentState == null ? null : parentState.getRelatedFoundSet(flp.getRelationName(), sort);
registerSelectionListeners(parentState, flp.getRelationName());
fp.loadData(relatedFoundSet, null);
}
} catch (RuntimeException re) {
application.handleException("Error setting the foundset of the relation " + flp.getRelationName() + " on the tab with form " + flp.getFormName(), re);
throw re;
}
}
Aggregations