use of com.servoy.j2db.dataprocessing.RelatedFoundSet in project servoy-client by Servoy.
the class WebSplitPane method setForm.
public boolean setForm(boolean bLeftForm, Object form, Object relation) {
FormController f = null;
String fName = null;
boolean readOnly = false;
if (form instanceof FormController) {
f = (FormController) form;
readOnly = f.isReadOnly();
}
if (form instanceof BasicFormController.JSForm) {
f = (FormController) ((BasicFormController.JSForm) form).getFormPanel();
readOnly = f.isReadOnly();
}
if (f != null)
fName = f.getName();
if (form instanceof String)
fName = (String) form;
if (fName != null) {
String tabname = fName;
RelatedFoundSet relatedFs = null;
String relationName = null;
if (relation instanceof RelatedFoundSet) {
relatedFs = (RelatedFoundSet) relation;
} else if (relation instanceof String) {
relationName = (String) relation;
}
if (relatedFs != null) {
relationName = relatedFs.getRelationName();
if (f != null && !relatedFs.getDataSource().equals(f.getDataSource())) {
return false;
}
// TODO do this check to check if the parent table has this relation? How to get the parent table
// Table parentTable = null;
// application.getSolution().getRelations(Solution.SOLUTION+Solution.MODULES, parentTable, true, false);
}
IFormLookupPanel replacedForm = bLeftForm ? getLeftForm() : getRightForm();
if (replacedForm != null) {
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
boolean bNotifyVisibleForm = notifyVisibleForm(false, bLeftForm ? 0 : 1, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
if (!bNotifyVisibleForm)
return false;
}
WebTabFormLookup flp = (WebTabFormLookup) createFormLookupPanel(tabname, relationName, fName);
if (f != null)
flp.setReadOnly(readOnly);
if (bLeftForm)
setLeftForm(flp);
else
setRightForm(flp);
if (relatedFs != null) {
FormController fp = flp.getWebForm().getController();
if (fp != null && flp.getRelationName() != null && flp.getRelationName().equals(relationName)) {
fp.loadData(relatedFs, null);
}
}
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
boolean bNotifyVisibleForm = notifyVisibleForm(true, bLeftForm ? 0 : 1, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
if (bNotifyVisibleForm) {
paneChanged[bLeftForm ? 0 : 1] = true;
}
return bNotifyVisibleForm;
} else if (form == null) {
IFormLookupPanel replacedForm = bLeftForm ? getLeftForm() : getRightForm();
if (replacedForm != null) {
List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>(0);
boolean bNotifyVisibleForm = notifyVisibleForm(false, bLeftForm ? 0 : 1, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
if (!bNotifyVisibleForm)
return false;
}
splitComponents[bLeftForm ? 0 : 1].replace(new Label("webform", new Model<String>("")));
webTabs[bLeftForm ? 0 : 1] = null;
paneChanged[bLeftForm ? 0 : 1] = true;
return true;
}
return false;
}
use of com.servoy.j2db.dataprocessing.RelatedFoundSet in project servoy-client by Servoy.
the class JSForm method newPortal.
/**
* Creates a new JSPortal object on the form - including the name of the JSPortal object; the relation the JSPortal object is based on, the "x" and "y" position of the JSPortal object in pixels, as well as the width and height of the JSPortal object in pixels.
*
* @sample
* var form = solutionModel.newForm('newForm1', 'db:/server1/table1', null, true, 800, 600);
* var relation = solutionModel.newRelation('parentToChild','db:/server1/table1','db:/server2/table2',JSRelation.INNER_JOIN);
* relation.newRelationItem('another_parent_table_id', '=', 'another_child_table_parent_id');
* var portal = form.newPortal('portal',relation,200,200,300,300);
* portal.newField('someColumn',JSField.TEXT_FIELD,200,200,120);
* forms['newForm1'].controller.show();
*
* @param name the specified name of the JSPortal object
* @param relation the relation of the JSPortal object
* @param x the horizontal "x" position of the JSPortal object in pixels
* @param y the vertical "y" position of the JSPortal object in pixels
* @param width the width of the JSPortal object in pixels
* @param height the height of the JSPortal object in pixels
*
* @return a JSPortal object
*/
@JSFunction
public JSPortal newPortal(String name, Object relation, int x, int y, int width, int height) {
checkModification();
try {
Portal portal = getContainer().createNewPortal(IdentDocumentValidator.checkName(name), new Point(x, y));
CSSPositionUtils.setSize(portal, width, height);
String relationName = null;
if (relation instanceof RelatedFoundSet) {
relationName = ((RelatedFoundSet) relation).getRelationName();
} else if (relation instanceof String) {
relationName = (String) relation;
} else if (relation instanceof JSRelation) {
relationName = ((JSRelation) relation).getName();
}
portal.setRelationName(relationName);
return new JSPortal(this, portal, application, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
use of com.servoy.j2db.dataprocessing.RelatedFoundSet in project servoy-client by Servoy.
the class UsedDataProviderTracker method usedFromRecord.
/**
* Used name from Record,
* @param record may be null (for global relations)
* @param name
*/
protected void usedFromRecord(IRecordInternal record, String name) {
IRecordInternal currentRecord = record;
try {
// $NON-NLS-1$
String[] parts = name.split("\\.");
for (String part : parts) {
Relation relation = flattenedSolution.getRelation(part);
if (relation != null) {
// calc depends on the relation, add a dependency for the primary data providers for the relation
IDataProvider[] primaryDataProviders = relation.getPrimaryDataProviders(flattenedSolution);
for (IDataProvider prim : primaryDataProviders) {
if (prim instanceof LiteralDataprovider)
continue;
String primdp = prim.getDataProviderID();
if (ScopesUtils.isVariableScope(primdp)) {
// global
usedGlobal(primdp);
} else {
// column
if (currentRecord != null) {
if (currentRecord.getRawData() == null) {
if (currentRecord instanceof PrototypeState) {
Debug.trace("Calculation '" + name + "' depends on field '" + part + "' from PrototypeState " + currentRecord);
} else {
// should not happen
Debug.error("Unexpected state: calculation '" + name + "' depends on column '" + part + "' from record without pk: " + currentRecord, new IllegalStateException());
}
} else {
usedColumn(currentRecord.getParentFoundSet().getDataSource(), currentRecord.getRawData().getPKHashKey(), primdp);
}
}
}
}
IFoundSetInternal foundSet = null;
if (currentRecord != null)
foundSet = currentRecord.getRelatedFoundSet(relation.getName());
currentRecord = null;
if (foundSet instanceof RelatedFoundSet) {
usedRelatedFoundSet(relation.getName(), (RelatedFoundSet) foundSet);
currentRecord = foundSet.getRecord(foundSet.getSelectedIndex());
}
} else {
if (currentRecord != null) {
IFoundSetInternal foundSet = currentRecord.getParentFoundSet();
if (foundSet.getSQLSheet().containsAggregate(part)) {
// aggregate
usedAggregate(foundSet, part);
} else {
// field or calc
if (currentRecord.has(part)) {
if (currentRecord.getRawData() == null) {
if (currentRecord instanceof PrototypeState) {
Debug.trace("Calculation '" + name + "' depends on field '" + part + "' from PrototypeState " + currentRecord);
} else {
// should not happen
Debug.error("Unexpected state: calculation '" + name + "' depends on field '" + part + "' from record without pk: " + currentRecord, new IllegalStateException());
}
} else {
usedColumn(foundSet.getDataSource(), currentRecord.getRawData().getPKHashKey(), part);
}
}
}
}
return;
}
if (currentRecord == null) {
return;
}
}
} catch (RepositoryException e) {
Debug.error(e);
}
}
use of com.servoy.j2db.dataprocessing.RelatedFoundSet in project servoy-client by Servoy.
the class AbstractRuntimeTabPaneAlike method js_addTab.
@SuppressWarnings("nls")
public boolean js_addTab(Object[] vargs) {
if (vargs.length < 1)
return false;
int index = 0;
Object form = vargs[index++];
IForm formController = null;
String formName = null;
if (form instanceof IForm) {
formController = (IForm) form;
}
if (form instanceof BasicFormController.JSForm) {
formController = ((BasicFormController.JSForm) form).getFormPanel();
}
if (formController != null)
formName = formController.getName();
if (form instanceof String)
formName = (String) form;
if (formName == null) {
return false;
}
String tabName = formName;
if (vargs.length >= 2) {
tabName = (String) vargs[index++];
}
String tabText = tabName;
if (vargs.length >= 3) {
tabText = (String) vargs[index++];
}
String tooltip = "";
if (vargs.length >= 4) {
tooltip = (String) vargs[index++];
}
String iconURL = "";
if (vargs.length >= 5) {
iconURL = (String) vargs[index++];
}
String fg = null;
if (vargs.length >= 6) {
fg = (String) vargs[index++];
}
String bg = null;
if (vargs.length >= 7) {
bg = (String) vargs[index++];
}
RelatedFoundSet relatedFs = null;
String relationName = null;
int tabIndex = -1;
if (vargs.length > 7) {
Object object = vargs[index++];
if (object instanceof RelatedFoundSet) {
relatedFs = (RelatedFoundSet) object;
relationName = relatedFs.getRelationName();
if (formController != null && !relatedFs.getDataSource().equals(formController.getDataSource())) {
return false;
}
// TODO do this check to check if the parent table has this relation? How to get the parent table
// Table parentTable = null;
// application.getSolution().getRelations(Solution.SOLUTION+Solution.MODULES, parentTable, true, false);
} else if (object instanceof String) {
relationName = (String) object;
} else if (object instanceof Number) {
tabIndex = ((Number) object).intValue();
}
}
if (vargs.length > 8) {
tabIndex = Utils.getAsInteger(vargs[index++]);
}
testTabName(tabName);
return getComponent().addTab(formController, formName, tabName, tabText, tooltip, iconURL, fg, bg, relationName, relatedFs, tabIndex);
}
use of com.servoy.j2db.dataprocessing.RelatedFoundSet in project servoy-client by Servoy.
the class JSTabPanel method newTab.
/**
* Adds a new tab with the text label and JSForm and JSRelation (can be null for unrelated).
*
* @sample
* // Create a parent form.
* var form = solutionModel.newForm('parentForm', 'db:/example_data/parent_table', null, false, 640, 480);
* // Create a first child form.
* var childOne = solutionModel.newForm('childOne', 'db:/example_data/child_table', null, false, 400, 300);
* childOne.newField('child_table_text', JSField.TEXT_FIELD, 10, 10, 100, 20);
* // Create a relation to link the parent form to the first child form.
* var parentToChild = solutionModel.newRelation('parentToChild','db:/example_data/parent_table','db:/example_data/child_table',JSRelation.INNER_JOIN);
* parentToChild.newRelationItem('parent_table_id','=','child_table_parent_id');
* // Create a second child form.
* var childTwo = solutionModel.newForm('childTwo', 'db:/example_data/my_table', null, false, 400, 300);
* childTwo.newField('my_table_image', JSField.IMAGE_MEDIA, 10, 10, 100, 100);
* // Create a tab panel and add two tabs to it, with the two child forms.
* var tabPanel = form.newTabPanel('tabs', 10, 10, 620, 460);
* tabPanel.newTab('tab1', 'Child Two', childOne, parentToChild); // The first form uses the relation.
* tabPanel.newTab('tab2', 'Child Two', childTwo);
*
* @param name The name of the new tab.
*
* @param text The text to be displayed on the new tab.
*
* @param form The JSForm instance that should be displayed in the new tab.
*
* @param relation A JSRelation object that relates the parent form with the form
* that will be displayed in the new tab.
*
* @return A JSTab instance representing the newly created and added tab.
*/
@JSFunction
public JSTab newTab(String name, String text, IBaseSMForm form, Object relation) {
String relationName = null;
if (relation instanceof RelatedFoundSet) {
relationName = ((RelatedFoundSet) relation).getRelationName();
} else if (relation instanceof String) {
relationName = (String) relation;
} else if (relation instanceof JSRelation) {
relationName = ((JSRelation) relation).getName();
}
try {
if (relationName != null && application.getFlattenedSolution().getRelationSequence(relationName) == null) {
// invalid relation
return null;
}
Tab newTab = getBaseComponent(true).createNewTab(text, relationName, ((JSForm) form).getSupportChild());
newTab.setName(name);
return new JSTab(this, newTab, application, true);
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
Aggregations