use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class CellAdapter method getCellEditorValue.
public Object getCellEditorValue() {
// test if currentEditing state isn't deleted already
if (currentEditingState == null || dataProviderID == null || (currentEditingState != null && currentEditingState.getParentFoundSet() == null))
return null;
Object comp = editor;
if ((comp instanceof IDisplay && ((IDisplay) comp).isReadOnly()) || gettingEditorValue) {
return currentEditingState.getValue(getDataProviderID());
}
try {
gettingEditorValue = true;
if (comp instanceof IDelegate<?>) {
comp = ((IDelegate<?>) comp).getDelegate();
}
// HACK:needed for commit value copied from other hack 'processfocus' in DataField
if (comp instanceof DataField && ((DataField) comp).isEditable()) {
DataField edit = (DataField) comp;
boolean needEntireState = edit.needEntireState();
try {
edit.setNeedEntireState(false);
int fb = edit.getFocusLostBehavior();
if (fb == JFormattedTextField.COMMIT || fb == JFormattedTextField.COMMIT_OR_REVERT) {
try {
edit.commitEdit();
// Give it a chance to reformat.
edit.setValueObject(edit.getValue());
} catch (ParseException pe) {
return null;
}
} else if (fb == JFormattedTextField.REVERT) {
edit.setValueObject(edit.getValue());
}
} finally {
edit.setNeedEntireState(needEntireState);
}
}
Object obj = null;
if (editor instanceof IDisplayData) {
IDisplayData displayData = (IDisplayData) editor;
obj = Utils.removeJavascripLinkFromDisplay(displayData, null);
if (!findMode) {
// use UI converter to convert from UI value to record value
obj = ComponentFormat.applyUIConverterFromObject(displayData, obj, dataProviderID, application.getFoundSetManager());
}
// if the editor is not enable or is readonly dont try to set any value.
if (!displayData.isEnabled() || displayData.isReadOnly())
return obj;
// this can happen when toggeling with readonly. case 233226 or 232188
if (!currentEditingState.isEditing() && !currentEditingState.startEditing())
return obj;
try {
if (// $NON-NLS-1$
currentEditingState != null && (obj == null || "".equals(obj)) && currentEditingState.getValue(dataProviderID) == null) {
return null;
}
} catch (IllegalArgumentException iae) {
Debug.error(iae);
}
Object oldVal = null;
if (currentEditingState instanceof FindState) {
if (displayData instanceof IScriptableProvider && ((IScriptableProvider) displayData).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) displayData).getScriptObject()).getComponentFormat() != null) {
((FindState) currentEditingState).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) displayData).getScriptObject()).getComponentFormat().parsedFormat);
}
try {
oldVal = currentEditingState.getValue(dataProviderID);
} catch (IllegalArgumentException iae) {
// $NON-NLS-1$
Debug.error("Error getting the previous value", iae);
oldVal = null;
}
currentEditingState.setValue(dataProviderID, obj);
if (!Utils.equalObjects(oldVal, obj)) {
// call notifyLastNewValue changed so that the onChangeEvent will be fired and called when attached.
displayData.notifyLastNewValueWasChange(oldVal, obj);
obj = dal.getValueObject(currentEditingState, dataProviderID);
}
} else {
if (!displayData.isValueValid() && Utils.equalObjects(lastInvalidValue, obj)) {
// already validated
return obj;
}
try {
adjusting = true;
try {
oldVal = currentEditingState.getValue(dataProviderID);
} catch (IllegalArgumentException iae) {
// $NON-NLS-1$
Debug.error("Error getting the previous value", iae);
}
try {
if (oldVal == Scriptable.NOT_FOUND && dal.getFormScope().has(dataProviderID, dal.getFormScope())) {
oldVal = dal.getFormScope().get(dataProviderID);
dal.getFormScope().put(dataProviderID, obj);
IFoundSetInternal foundset = currentEditingState.getParentFoundSet();
if (foundset instanceof FoundSet)
((FoundSet) foundset).fireFoundSetChanged();
} else
currentEditingState.setValue(dataProviderID, obj);
} catch (IllegalArgumentException e) {
Debug.trace(e);
displayData.setValueValid(false, oldVal);
application.handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
Object stateValue = null;
try {
stateValue = dal.getValueObject(currentEditingState, dataProviderID);
} catch (IllegalArgumentException iae) {
Debug.error(iae);
}
Object displayValue;
if (Utils.equalObjects(oldVal, stateValue)) {
// reset display to typed value
displayValue = obj;
} else {
// reset display to changed value in validator method
displayValue = stateValue;
}
convertAndSetValue(displayData, displayValue);
return displayValue;
}
if (!Utils.equalObjects(oldVal, obj)) {
fireModificationEvent(currentEditingState);
displayData.notifyLastNewValueWasChange(oldVal, obj);
obj = dal.getValueObject(currentEditingState, dataProviderID);
// we also want to reset the value in the current display if changed by script
convertAndSetValue(displayData, obj);
} else if (!displayData.isValueValid()) {
displayData.notifyLastNewValueWasChange(null, obj);
} else {
displayData.setValueValid(true, null);
}
} finally {
adjusting = false;
if (displayData.isValueValid()) {
lastInvalidValue = NONE;
} else {
lastInvalidValue = obj;
}
}
}
}
return obj;
} finally {
gettingEditorValue = false;
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class CellAdapter method getStyleAttributeForRow.
private Object getStyleAttributeForRow(JTable jtable, boolean isSelected, int row, ISupportRowStyling.ATTRIBUTE rowStyleAttribute) {
Object rowStyleAttrValue = null;
IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
boolean specialStateCase = (state instanceof PrototypeState || state instanceof FindState);
if (/* !(renderer instanceof JButton) && */
!specialStateCase) {
if (jtable instanceof ISupportRowStyling) {
ISupportRowStyling oddEvenStyling = (ISupportRowStyling) jtable;
IStyleSheet ss = oddEvenStyling.getRowStyleSheet();
IStyleRule style = isSelected ? oddEvenStyling.getRowSelectedStyle() : null;
if (style != null && style.getAttributeCount() == 0)
style = null;
if (style == null) {
// because index = 0 means record = 1
style = (row % 2 == 0) ? oddEvenStyling.getRowOddStyle() : oddEvenStyling.getRowEvenStyle();
}
rowStyleAttrValue = getStyleAttribute(ss, style, rowStyleAttribute);
}
}
return rowStyleAttrValue;
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class PortalComponent method valueChanged.
private void valueChanged(ListSelectionEvent eventCanBeNull, boolean stopAnyEdit) {
IFoundSetInternal s = null;
if (table != null) {
TableModel tm = table.getModel();
if (tm instanceof IFoundSetInternal) {
s = (IFoundSetInternal) tm;
}
} else {
ListModel tm = list.getModel();
if (tm instanceof IFoundSetInternal) {
s = (IFoundSetInternal) tm;
}
}
if (s != null) {
if (dal != null) {
int index = getRecordIndex();
if (index != -1) {
IRecordInternal state = s.getRecord(index);
if (// can happen when notified from client and itself not having a selection yet
state != null) {
if (eventCanBeNull != null && eventCanBeNull.getValueIsAdjusting()) {
if (lastAdjusting != index) {
lastAdjusting = index;
application.getFoundSetManager().getEditRecordList().stopIfEditing(s);
}
} else {
lastAdjusting = -1;
dal.setRecord(state, stopAnyEdit);
}
} else {
dal.setRecord(null, stopAnyEdit);
}
} else {
dal.setRecord(null, stopAnyEdit);
}
}
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class SpecialTabPanel method showFoundSet.
protected 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);
}
ITagResolver resolver = getTagResolver(parentState);
// refresh tab text
int i = enclosingComponent.getTabIndex(flp);
String element = i < originalTabText.size() ? originalTabText.get(i) : null;
if (element != null) {
enclosingComponent.setTitleAt(i, Text.processTags(element, resolver));
}
String tooltip = i < originalTabTooltip.size() ? originalTabTooltip.get(i) : null;
if (tooltip != null) {
enclosingComponent.setToolTipTextAt(i, Text.processTags(tooltip, resolver));
}
} catch (RuntimeException re) {
application.handleException("Error setting the foundset of the relation " + flp.getRelationName() + " on the tab with form " + flp.getFormName(), re);
throw re;
}
}
use of com.servoy.j2db.dataprocessing.IFoundSetInternal in project servoy-client by Servoy.
the class SpecialTabPanel 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());
}
}
Aggregations