use of com.servoy.j2db.scripting.SelectedRecordScope in project servoy-client by Servoy.
the class BasicFormController method setModel.
protected boolean setModel(IFoundSetInternal newModel) throws ServoyException {
if (newModel == formModel || adjustingModel) {
// same or adjusting do nothing
return true;
}
ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
if (newModel != null && ((formTable == null && newModel.getTable() != null) || (formTable != null && !formTable.equals(newModel.getTable())))) {
throw new IllegalArgumentException(application.getI18NMessage("servoy.formPanel.error.wrongFoundsetTable", new Object[] { // $NON-NLS-1$
newModel.getTable() == null ? "NONE" : newModel.getTable().getName(), // $NON-NLS-1$
form.getTableName() }));
}
try {
IView view = getViewComponent();
if (view != null && view.isEditing()) {
// TODO if save fails don't set the newModel??
int stopped = application.getFoundSetManager().getEditRecordList().stopEditing(false);
if (stopped != ISaveConstants.STOPPED && stopped != ISaveConstants.AUTO_SAVE_BLOCKED) {
return false;
}
}
adjustingModel = true;
if (formModel != null) {
try {
((ISwingFoundSet) formModel).getSelectionModel().removeListSelectionListener(this);
((ISwingFoundSet) formModel).getSelectionModel().removeFormController(this);
((ISwingFoundSet) formModel).removeTableModelListener(this);
// to make sure all data is gc'ed
if (formModel instanceof FoundSet)
((FoundSet) formModel).flushAllCachedItems();
} catch (Exception ex) {
Debug.error(ex);
}
}
setFormModelInternal(newModel == null ? ((FoundSetManager) application.getFoundSetManager()).getEmptyFoundSet(this) : newModel);
if (formScope != null) {
// $NON-NLS-1$
formScope.putWithoutFireChange("foundset", formModel);
if (formScope.getPrototype() == null) {
formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
}
}
if (isFormVisible) {
((ISwingFoundSet) formModel).getSelectionModel().addListSelectionListener(this);
((ISwingFoundSet) formModel).getSelectionModel().addFormController(this);
((ISwingFoundSet) formModel).addTableModelListener(this);
if (// it may not yet exist
view != null) {
view.setModel(formModel);
}
// this was former a call to aggregateChange, but now does now unwanted parent traverse...
int[] idx = null;
if (getView() == RECORD_VIEW || getView() == LOCKED_RECORD_VIEW) {
int selIdx = formModel.getSelectedIndex();
if (selIdx != -1)
idx = new int[] { selIdx };
} else {
idx = formModel.getSelectedIndexes();
}
if (idx == null || idx.length == 0) {
refreshAllPartRenderers(new IRecordInternal[] { formModel.getPrototypeState() });
} else {
IRecordInternal[] row = new IRecordInternal[idx.length];
for (int i = 0; i < idx.length; i++) row[i] = formModel.getRecord(idx[i]);
refreshAllPartRenderers(row);
}
}
} finally {
adjustingModel = false;
}
return true;
}
use of com.servoy.j2db.scripting.SelectedRecordScope in project servoy-client by Servoy.
the class BasicFormController method initForJSUsage.
/**
* Initialize this FormController(or related classes/methods) to be used in javascript
*/
public synchronized JSForm initForJSUsage(CreationalPrototype creationalPrototype) {
if (formScope == null) {
try {
// make scope for state delegation via prototype mechanism
List<Form> forms = application.getFlattenedSolution().getFormHierarchy(form);
List<ISupportScriptProviders> scriptProviders = new ArrayList<ISupportScriptProviders>();
for (Form frm : forms) {
scriptProviders.add(new RuntimeSupportScriptProviders(application, frm));
}
formScope = new FormScope(this, scriptProviders.toArray(new ISupportScriptProviders[scriptProviders.size()]));
if (formModel != null) {
ITable formTable = application.getFoundSetManager().getTable(form.getDataSource());
formScope.setPrototype(new SelectedRecordScope(this, formTable == null ? null : application.getScriptEngine().getTableScope(formTable)));
// $NON-NLS-1$
formScope.putWithoutFireChange("foundset", formModel);
}
// create JS place holder for this object
scriptableForm = new BasicFormController.JSForm(this);
// set parent scope
NativeJavaObject formObject = new NativeJavaObject(formScope, scriptableForm, ScriptObjectRegistry.getJavaMembers(FormController.JSForm.class, formScope));
// $NON-NLS-1$
formScope.putWithoutFireChange("controller", formObject);
// register the place holder 'scriptableForm' in CreationalPrototype scope
creationalPrototype.setLocked(false);
// $NON-NLS-1$
creationalPrototype.put(((Integer) creationalPrototype.get("length", creationalPrototype)).intValue(), creationalPrototype, formScope);
creationalPrototype.put(getName(), creationalPrototype, formScope);
creationalPrototype.setLocked(true);
formScope.createVars();
} catch (Exception ex) {
// $NON-NLS-1$
application.reportError(application.getI18NMessage("servoy.formPanel.error.initFormScope") + ": " + getName(), ex);
return null;
}
}
return scriptableForm;
}
Aggregations