use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class WebEventExecutor method setSelectedIndex.
/**
* @param component
*/
@SuppressWarnings("nls")
public static boolean setSelectedIndex(Component component, AjaxRequestTarget target, int modifiers, boolean bHandleMultiselect) {
WebForm parentForm = component.findParent(WebForm.class);
WebCellBasedView tableView = null;
if (parentForm != null) {
int parentFormViewType = parentForm.getController().getForm().getView();
if (parentFormViewType == FormController.TABLE_VIEW || parentFormViewType == FormController.LOCKED_TABLE_VIEW || parentFormViewType == IForm.LIST_VIEW || parentFormViewType == FormController.LOCKED_LIST_VIEW) {
tableView = component.findParent(WebCellBasedView.class);
if (tableView == null) {
// the component is not part of the table view (it is on other form part), so ignore selection change
return true;
} else
tableView.setSelectionMadeByCellAction();
if (parentFormViewType == IForm.LIST_VIEW || parentFormViewType == FormController.LOCKED_LIST_VIEW) {
if (component instanceof WebCellBasedViewListViewItem) {
((WebCellBasedViewListViewItem) component).markSelected(target);
} else {
WebCellBasedViewListViewItem listViewItem = component.findParent(WebCellBasedView.WebCellBasedViewListViewItem.class);
if (listViewItem != null) {
listViewItem.markSelected(target);
}
}
}
}
}
// search for recordItem model
Component recordItemModelComponent = component;
IModel<?> someModel = recordItemModelComponent.getDefaultModel();
while (!(someModel instanceof RecordItemModel)) {
recordItemModelComponent = recordItemModelComponent.getParent();
if (recordItemModelComponent == null)
break;
someModel = recordItemModelComponent.getDefaultModel();
}
if (someModel instanceof RecordItemModel) {
if (!(component instanceof WebCellBasedViewListViewItem)) {
// update the last rendered value for the events component (if updated)
((RecordItemModel) someModel).updateRenderedValue(component);
}
IRecordInternal rec = (IRecordInternal) someModel.getObject();
if (rec != null) {
int index;
IFoundSetInternal fs = rec.getParentFoundSet();
if (someModel instanceof FoundsetRecordItemModel) {
index = ((FoundsetRecordItemModel) someModel).getRowIndex();
} else {
// this is used only on "else", because a "plugins.rawSQL.flushAllClientsCache" could result in index = -1 although the record has not changed (but record & underlying row instances changed)
index = fs.getRecordIndex(rec);
}
if (fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect()) {
// set the selected record
ClientProperties clp = ((WebClientInfo) Session.get().getClientInfo()).getProperties();
String navPlatform = clp.getNavigatorPlatform();
int controlMask = (navPlatform != null && navPlatform.toLowerCase().indexOf("mac") != -1) ? Event.META_MASK : Event.CTRL_MASK;
boolean toggle = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & controlMask) != 0);
boolean extend = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.SHIFT_MASK) != 0);
boolean isRightClick = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.ALT_MASK) != 0);
if (!isRightClick) {
if (!toggle && !extend && tableView != null && tableView.getDragNDropController() != null && Arrays.binarySearch(((FoundSet) fs).getSelectedIndexes(), index) > -1) {
return true;
}
if (toggle || extend) {
if (bHandleMultiselect) {
if (toggle) {
int[] selectedIndexes = ((FoundSet) fs).getSelectedIndexes();
ArrayList<Integer> selectedIndexesA = new ArrayList<Integer>();
Integer selectedIndex = new Integer(index);
for (int selected : selectedIndexes) selectedIndexesA.add(new Integer(selected));
if (selectedIndexesA.indexOf(selectedIndex) != -1) {
if (selectedIndexesA.size() > 1) {
((ISwingFoundSet) fs).getSelectionModel().removeSelectionInterval(selectedIndex, selectedIndex);
}
} else {
((ISwingFoundSet) fs).getSelectionModel().addSelectionInterval(selectedIndex, selectedIndex);
}
} else if (extend) {
int anchor = ((FoundSet) fs).getSelectedIndex();
int min = Math.min(anchor, index);
int max = Math.max(anchor, index);
((ISwingFoundSet) fs).getSelectionModel().setSelectionInterval(min, max);
}
}
} else if (index != -1 || fs.getSize() == 0) {
fs.setSelectedIndex(index);
}
}
} else if (!isIndexSelected(fs, index))
fs.setSelectedIndex(index);
if (!isIndexSelected(fs, index) && !(fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect())) {
// setSelectedIndex failed, probably due to validation failed, do a blur()
if (target != null)
target.appendJavascript("var toBlur = document.getElementById(\"" + component.getMarkupId() + "\");if (toBlur) toBlur.blur();");
return false;
}
}
}
return true;
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class DataAdapterList method createRelationListeners.
private void createRelationListeners(IDataLinkedPropertyValue propertyValue) {
// first remove the previous ones
Pair<Relation[], List<RelatedListener>> pair = toWatchRelations.get(propertyValue);
pair.getRight().forEach(listener -> listener.dispose());
pair.getRight().clear();
if (this.record != null) {
Relation[] relationsToWatch = pair.getLeft();
IRecordInternal current = this.record;
ArrayList<RelatedListener> listeners = new ArrayList<>(relationsToWatch.length);
for (Relation element : relationsToWatch) {
IFoundSetInternal related = current.getRelatedFoundSet(element.getName());
if (related != null) {
// if selection changes or the current record changes then an update should happen.
listeners.add(new RelatedListener(propertyValue, related));
current = related.getRecord(related.getSelectedIndex());
if (current == null)
break;
} else
break;
}
pair.setRight(listeners);
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class FoundsetTest method foundsetViewportAddRemove.
@Test
public // add / remove rows in viewport, near viewport
void foundsetViewportAddRemove() throws // add / remove rows in viewport, near viewport
JSONException, // add / remove rows in viewport, near viewport
ServoyException {
IWebFormController form = (IWebFormController) client.getFormManager().showFormInCurrentContainer("test");
Assert.assertNotNull(form);
FoundsetTypeSabloValue rawPropertyValue = (FoundsetTypeSabloValue) form.getFormUI().getWebComponent("mycustombean").getRawPropertyValue("myfoundset");
FoundsetTypeViewport viewPort = rawPropertyValue.getViewPort();
viewPort.setPreferredViewportSize(1);
viewPort.setBounds(1, 1);
IFoundSetInternal foundSet = rawPropertyValue.getFoundset();
foundSet.newRecord(1, false);
Assert.assertEquals(1, viewPort.size);
Assert.assertEquals(1, viewPort.startIndex);
Assert.assertEquals(19, rawPropertyValue.getFoundset().getSize());
StringWriter stringWriter = new StringWriter();
JSONWriter jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.addViewPort(jsonWriter);
Assert.assertTrue(new JSONObject("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\".null;_1\",\"lastname\":null,\"firstname\":null}]}").similar(new JSONObject(stringWriter.toString())));
foundSet.deleteRecord(1);
Assert.assertEquals(18, rawPropertyValue.getFoundset().getSize());
stringWriter.getBuffer().setLength(0);
jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.addViewPort(jsonWriter);
Assert.assertTrue(new JSONObject("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.2;_1\",\"lastname\":\"value4\",\"firstname\":\"value3\"}]}").similar(new JSONObject(stringWriter.toString())));
foundSet.newRecord(0, false);
stringWriter.getBuffer().setLength(0);
jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.addViewPort(jsonWriter);
Assert.assertTrue(new JSONObject("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.1;_1\",\"lastname\":\"value2\",\"firstname\":\"value1\"}]}").similar(new JSONObject(stringWriter.toString())));
foundSet.newRecord(3, false);
Assert.assertEquals(20, rawPropertyValue.getFoundset().getSize());
stringWriter.getBuffer().setLength(0);
jsonWriter = new JSONWriter(stringWriter);
rawPropertyValue.addViewPort(jsonWriter);
Assert.assertTrue(new JSONObject("{\"startIndex\":1,\"size\":1,\"rows\":[{\"_svyRowId\":\"1.1;_1\",\"lastname\":\"value2\",\"firstname\":\"value1\"}]}").similar(new JSONObject(stringWriter.toString())));
// delete records added in this test
foundSet.deleteRecord(0);
// last record is now at index 2
foundSet.deleteRecord(2);
Assert.assertEquals(18, rawPropertyValue.getFoundset().getSize());
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class WebSplitPane method registerSelectionListeners.
private void registerSelectionListeners(IRecordInternal parentState, String relationName) {
// $NON-NLS-1$
String[] parts = relationName.split("\\.");
IRecordInternal currentRecord = parentState;
for (int i = 0; currentRecord != null && i < parts.length - 1; i++) {
IFoundSetInternal fs = currentRecord.getRelatedFoundSet(parts[i]);
if (fs instanceof ISwingFoundSet) {
related.add((ISwingFoundSet) fs);
((ISwingFoundSet) fs).getSelectionModel().addListSelectionListener(this);
}
currentRecord = (fs == null) ? null : fs.getRecord(fs.getSelectedIndex());
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class RecordPropertyType method fromJSON.
@Override
public IRecordInternal fromJSON(Object newJSONValue, IRecordInternal previousSabloValue, PropertyDescription pd, IBrowserConverterContext dataConverterContext, ValueReference<Boolean> returnValueAdjustedIncommingValue) {
IRecordInternal record = null;
if (newJSONValue instanceof JSONObject) {
JSONObject jsonRecord = (JSONObject) newJSONValue;
BaseWebObject webObject = dataConverterContext.getWebObject();
if (webObject != null && jsonRecord.has(FoundsetTypeSabloValue.ROW_ID_COL_KEY)) {
String rowIDValue = jsonRecord.optString(FoundsetTypeSabloValue.ROW_ID_COL_KEY);
Pair<String, Integer> splitHashAndIndex = FoundsetTypeSabloValue.splitPKHashAndIndex(rowIDValue);
if (jsonRecord.has(FoundsetTypeSabloValue.FOUNDSET_ID)) {
int foundsetID = Utils.getAsInteger(jsonRecord.get(FoundsetTypeSabloValue.FOUNDSET_ID));
if (foundsetID >= 0 && webObject instanceof IContextProvider) {
IFoundSetInternal foundset = ((IContextProvider) webObject).getDataConverterContext().getApplication().getFoundSetManager().findFoundset(foundsetID);
if (foundset != null) {
int recordIndex = foundset.getRecordIndex(splitHashAndIndex.getLeft(), splitHashAndIndex.getRight().intValue());
if (recordIndex != -1) {
return foundset.getRecord(recordIndex);
}
}
}
}
Collection<PropertyDescription> properties = webObject.getSpecification().getProperties(FoundsetPropertyType.INSTANCE);
for (PropertyDescription foundsetPd : properties) {
FoundsetTypeSabloValue fsSablo = (FoundsetTypeSabloValue) webObject.getProperty(foundsetPd.getName());
int recordIndex = fsSablo.getFoundset().getRecordIndex(splitHashAndIndex.getLeft(), splitHashAndIndex.getRight().intValue());
if (recordIndex != -1) {
record = fsSablo.getFoundset().getRecord(recordIndex);
break;
}
}
}
if (// $NON-NLS-1$
record == null && jsonRecord.has("recordhash")) {
// $NON-NLS-1$
record = getReference(jsonRecord.optString("recordhash"));
}
}
return record;
}
Aggregations