1919import org .openlowcode .design .data .DataObjectDefinition ;
2020import org .openlowcode .design .data .MethodAdditionalProcessing ;
2121import org .openlowcode .design .data .Property ;
22+ import org .openlowcode .design .data .PropertyBusinessRule ;
2223import org .openlowcode .design .data .PropertyGenerics ;
2324import org .openlowcode .design .data .argument .ObjectIdArgument ;
2425import org .openlowcode .design .generation .SourceGenerator ;
@@ -297,8 +298,8 @@ public class LinkFromLeftTableWidget
297298 super ("LINKFROMLEFTTABLE" );
298299 this .parentproperty = parentproperty ;
299300 typed = (Typed ) this .parentproperty .getParent ().getPropertyByName ("TYPED" );
300- typerestrictionforleft = (ConstraintOnLinkTypeRestrictionForLeft ) parentproperty
301- .getLinkObjectProperty (). getBusinessRuleByName ("TYPERESTRICTIONFORLEFT" );
301+ typerestrictionforleft = (ConstraintOnLinkTypeRestrictionForLeft ) parentproperty . getLinkObjectProperty ()
302+ .getBusinessRuleByName ("TYPERESTRICTIONFORLEFT" );
302303 }
303304
304305 @ Override
@@ -310,7 +311,7 @@ public String[] getImportStatements() {
310311 importstatements .add ("import org.openlowcode.server.graphic.widget.SObjectArrayField;" );
311312 importstatements .add ("import org.openlowcode.server.graphic.widget.SObjectSearcher;" );
312313 importstatements .add ("import org.openlowcode.server.graphic.widget.SPopupButton;" );
313- if (typerestrictionforleft != null ) {
314+ if (typerestrictionforleft != null ) {
314315 importstatements .add ("import java.util.ArrayList;" );
315316 }
316317 String linkobjectvariable = StringFormatter
@@ -365,16 +366,17 @@ public void generateWidgetCode(
365366 sg .wl (" // Display " + linkobjectclass );
366367 sg .wl (" // ------------------------------------------------------------------------------------------" );
367368 sg .wl ("" );
368- if (this .typerestrictionforleft !=null ) {
369- sg .wl (" ArrayList<SPageNode> left" + linkobjectvariable + "nodes = new ArrayList<SPageNode>();" );
369+ if (this .typerestrictionforleft != null ) {
370+ sg .wl (" ArrayList<SPageNode> left" + linkobjectvariable
371+ + "nodes = new ArrayList<SPageNode>();" );
370372 sg .wl (" left" + linkobjectvariable + "nodes.add(new SPageText(\" "
371373 + parentproperty .getLinkObjectProperty ().getLabelFromLeft ()
372374 + "\" ,SPageText.TYPE_TITLE,this));" );
373375 } else {
374-
375- sg .wl (" " + locationname + ".addElement(new SPageText(\" "
376- + parentproperty .getLinkObjectProperty ().getLabelFromLeft ()
377- + "\" ,SPageText.TYPE_TITLE,this));" );
376+
377+ sg .wl (" " + locationname + ".addElement(new SPageText(\" "
378+ + parentproperty .getLinkObjectProperty ().getLabelFromLeft ()
379+ + "\" ,SPageText.TYPE_TITLE,this));" );
378380 }
379381 sg .wl (" SObjectArray<" + linkobjectclass + "> left" + linkobjectvariable + "s = new SObjectArray<"
380382 + linkobjectclass + ">(\" LEFT" + linkobjectclass .toUpperCase () + "\" ," );
@@ -497,26 +499,27 @@ public void generateWidgetCode(
497499 + ", this);" );
498500 sg .wl (" left" + linkobjectvariable + "buttonbar.addElement(deleteoneofleft" + linkobjectvariable
499501 + "button);" );
500- if (this .typerestrictionforleft != null ) {
502+ if (this .typerestrictionforleft != null ) {
501503 sg .wl (" left" + linkobjectvariable + "nodes.add(left" + linkobjectvariable + "buttonbar);" );
502504 sg .wl (" left" + linkobjectvariable + "nodes.add(left" + linkobjectvariable + "s);" );
503505 ChoiceValue [] allowedtypes = this .typerestrictionforleft .getAllowedTypes ();
504-
506+
505507 sg .wl (" mainband.addConditionalElements(this.getTypechoice()," );
506508 sg .wl (" new ChoiceValue[] { " );
507- for (int t = 0 ; t < allowedtypes .length ;t ++) {
509+ for (int t = 0 ; t < allowedtypes .length ; t ++) {
508510 ;
509- sg .wl (" " +(t >0 ?"," :"" )+StringFormatter .formatForJavaClass (this .typed .getTypes ().getName ())+"ChoiceDefinition.get()." +allowedtypes [t ].getName ());
511+ sg .wl (" " + (t > 0 ? "," : "" )
512+ + StringFormatter .formatForJavaClass (this .typed .getTypes ().getName ())
513+ + "ChoiceDefinition.get()." + allowedtypes [t ].getName ());
510514 }
511515 sg .wl (" }, left" + linkobjectvariable + "nodes.toArray(new SPageNode[0]));" );
512516
513-
514517 } else {
515518 sg .wl (" " + locationname + ".addElement(left" + linkobjectvariable + "buttonbar);" );
516519 sg .wl (" " + locationname + ".addElement(left" + linkobjectvariable + "s);" );
517-
520+
518521 }
519- } else {
522+ } else {
520523 // -------------------------------------------------------------------------------------------------
521524 // show link as field array
522525 }
@@ -529,4 +532,23 @@ public WidgetDisplayPriority getWidgetPriority() {
529532 }
530533
531534 }
535+
536+ /**
537+ * utility method telling is the link is unique for left, restricting widgets
538+ * when needed in (especially in creation page)
539+ *
540+ * @return
541+ */
542+ public boolean isUniqueLinkFromLeft () {
543+ LinkObject <?, ?> linkobject = this .getLinkObjectProperty ();
544+ for (int i = 0 ; i < linkobject .getBusinessRuleNumber (); i ++) {
545+ PropertyBusinessRule <?> businessrule = linkobject .getBusinessRule (i );
546+ if (businessrule instanceof ConstraintOnLinkMaxOneFromLeft )
547+ return true ;
548+ if (businessrule instanceof ConstraintOnLinkUniqueForLeftAndRight )
549+ return true ;
550+ }
551+ return false ;
552+ }
553+
532554}
0 commit comments