<%@ jet package="cruise.ui.jfx.templates.impl" imports="java.util.* cruise.model.abstractObjects.BackingObject cruise.umple.compiler.* cruise.ui.jfx.* " class="View" skeleton="../jfx.skeleton" %> <% BackingObject bckObject = (BackingObject) argument; String preffix=JFXProvider.properties.getProperty(cruise.model.Constants.PACKAGE_PREFIX); List mergeList= new ArrayList(); mergeList.addAll( bckObject.getConstructorOneAsociations()); mergeList.addAll(bckObject.getZeroOrOneAsociations()); List multipleZeroManyToOptionalAssociations=bckObject.getZeroManyToOptionalAssociations(); Iterator iterList; Iterator iterAssocList; %> package <%=preffix + ((bckObject.getPackageName().trim().length()>0)?("." + bckObject.getPackageName()):"")%>; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.paint.Color; import javafx.ext.swing.SwingComponent; import dao.keys.<%=bckObject.getPackageName()%>.*; import <%=(bckObject.getPackageName()!=null&&bckObject.getPackageName().trim().length()>0)?(bckObject.getPackageName().trim()+"."):""%><%=bckObject.getClassName()%>; import dao.utils.DAOUtils; import javafx.scene.Group; import java.awt.Dimension; import javafx.geometry.HPos; import javafx.scene.control.TextBox; import javafx.scene.control.Label; import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import com.sun.javafx.scene.control.caspian.ButtonSkin; import javafx.scene.shape.Rectangle; import javafx.geometry.Rectangle2D; import main.Application; import javafx.scene.Cursor; import javafx.geometry.VPos; import main.PopUp; import javafx.scene.paint.LinearGradient; import <%=preffix%>.components.IntegerBox; import <%=preffix%>.components.ScrollPane; import <%=preffix%>.components.BorderPanel; import javafx.scene.paint.Stop; import javafx.scene.Node; import javafx.scene.text.Text; import javafx.scene.effect.Reflection; <% for (Iterator i = bckObject.getImports().iterator(); i.hasNext(); ) { %> import <%=i.next().toString()%>; <% } %> public class <%=bckObject.getClassName()%>View { init { table.setPreferredSize(new Dimension(600, 140)); <% iterAssocList= multipleZeroManyToOptionalAssociations.iterator(); while (iterAssocList.hasNext()) { AssociationVariable assocVar=iterAssocList.next(); %> a<%=assocVar.getUpperCaseName()%>ListKeyTable.setPreferredSize(new Dimension(260, 120)); <% } %> } var edited<%=bckObject.getClassName()%>: <%=bckObject.getClassName()%> = null; var a<%=bckObject.getClassName()%>Table:<%=bckObject.getClassName()%>Table=new <%=bckObject.getClassName()%>Table(); var table = a<%=bckObject.getClassName()%>Table.create(); var tableComp = SwingComponent.wrap(table); var titleFont = Font.font("", FontWeight.BOLD, 16); var buttonText = "Add"; <% for (AttributeVariable attVar: bckObject.getAttVariables()) { %> <%=bckObject.getFragmentProvider().getDeclarationFragment(attVar)%> <% } %> <% for (AttributeVariable attVar: bckObject.getKeysAttributes()) { %> <%=bckObject.getFragmentProvider().getDeclarationFragment(attVar, attVar.getValue()!=null?"false":"true",attVar.getValue()!=null?attVar.getValue():"\"\"", "true", "Field", "true")%> <% } %> <%@ include file="includes/OneAssociations.javapart" %> <%@ include file="includes/ZeroManyToOptionalAssociations.javapart" %> <% int rowCount= bckObject.getKeysAttributes().size()+bckObject.getAttVariables().size()+mergeList.size(); %> function getImg(show:Boolean):Node{ if (show) return ImageView {image: Application.imageKey; viewport: Rectangle2D {width: 30, height: 24}} else return null; } var fieldsBox =VBox { spacing: 5 nodeHPos: HPos.RIGHT content: [ <% boolean added=false; iterList= bckObject.getKeysAttributes().iterator(); while (iterList.hasNext()) { AttributeVariable attVar=iterList.next(); added=true; %> HBox { spacing: 5; content: [Label {text: "<%=attVar.getUpperCaseName()%>: "}, <%=attVar.getName()%>FieldBox ]}<%=iterList.hasNext()?",":""%> <% } %> <% iterList= bckObject.getAttVariables().iterator(); while (iterList.hasNext()) { AttributeVariable attVar=iterList.next(); %><%=added?",":""%><% added=true; %> HBox { spacing: 5; content: [Label {text: "<%=attVar.getUpperCaseName()%>: "}, <%=attVar.getName()%>Box ]} <% } %> <% iterAssocList= mergeList.iterator(); while (iterAssocList.hasNext()) { AssociationVariable assocVar=iterAssocList.next(); %><%=added?",":""%><% added=true; %> HBox {nodeVPos: VPos.CENTER; spacing: 5; content: [Label {text: "<%=assocVar.getUpperCaseName()%>: "}, BorderPanel{ borderColor: Color.ORANGE borderWidth: 1 layoutPadding: 5 content: a<%=assocVar.getUpperCaseName()%>Box} ]} <% } %> <% iterAssocList= multipleZeroManyToOptionalAssociations.iterator(); while (iterAssocList.hasNext()) { AssociationVariable assocVar=iterAssocList.next(); %><%=added?",":""%><% added=true; %> HBox {nodeVPos: VPos.CENTER; spacing: 5; content: [Label {text: "<%=assocVar.getUpperCaseName()%>s: "}, a<%=assocVar.getUpperCaseName()%>sBox ]} <% } %> ] } var addButton: Button = Button { text: bind buttonText; action: function () { buttonText = "Add"; onSave(); } } var cancelButton: Button = Button { text: "Cancel" action: function () { onCancel(); } } var editButton: Button = Button { text: "Edit" action: function () { buttonText = "Update"; onEdit(); } } var deleteButton: Button = Button { text: "Delete" action: function () { onDelete(); } } function onSave() { try{ if (edited<%=bckObject.getClassName()%> == null) { var <%=bckObject.getClassName().toLowerCase()%>Instance:<%=bckObject.getClassName()%>=null; <% for (AttributeVariable attVar: bckObject.getAttVariables()) { %> <%=bckObject.getFragmentProvider().getPreConstructorFragment(attVar) %> <% } %> <% for (AttributeVariable attVar: bckObject.getKeysAttributes()) { %> <%=bckObject.getFragmentProvider().getPreConstructorFragment(attVar, "Field") %> <% } %> <% Iterator keyIter=bckObject.getKeysAttributes().iterator(); String signature=""; while (keyIter.hasNext()){ AttributeVariable att=keyIter.next(); signature=signature+" a"+ att.getUpperCaseName(); if(keyIter.hasNext()) signature=signature+", "; } %> var <%=bckObject.getClassName().toLowerCase()%>Key:<%=bckObject.getClassName()%>Key= new <%=bckObject.getClassName()%>Key(<%=signature%>); if(DAOUtils.getDAOFactory().get<%=bckObject.getClassName()%>DAO().findById(<%=bckObject.getClassName().toLowerCase()%>Key)!=null) throw new java.lang.RuntimeException("An entity with the same key field(s) exists!"); <%=bckObject.getClassName().toLowerCase()%>Instance = new <%=bckObject.getClassName()%>(<%=bckObject.getConstructorSignature()%>); <% for (AssociationVariable assocVar: multipleZeroManyToOptionalAssociations) { %> if (a<%=assocVar.getUpperCaseName()%>List !=null) for ( obj in a<%=assocVar.getUpperCaseName()%>List){ <%=bckObject.getClassName().toLowerCase()%>Instance.add<%=assocVar.getUpperCaseName()%>(obj as <%=assocVar.getType()%> ); } <%}%> <% for (AssociationVariable assocVar: bckObject.getZeroOrOneAsociations()) { %> <%=bckObject.getClassName().toLowerCase()%>Instance.set<%=assocVar.getUpperCaseName()%>(a<%=assocVar.getUpperCaseName()%>); <% } %> DAOUtils.getDAOFactory().get<%=bckObject.getClassName()%>DAO().save(<%=bckObject.getClassName().toLowerCase()%>Instance, <%=bckObject.getClassName().toLowerCase()%>Key); } else { <% for (AttributeVariable attVar: bckObject.getAttVariables()) { %> <%=bckObject.getFragmentProvider().getCopyFragment(attVar,"edited"+bckObject.getClassName()) %><% } %> <% for (AssociationVariable assocVar: mergeList) { %> edited<%=bckObject.getClassName()%>.set<%=assocVar.getUpperCaseName()%>(this.a<%=assocVar.getUpperCaseName()%>); <% } %> <% for (AssociationVariable assocVar: multipleZeroManyToOptionalAssociations) { %> if (a<%=assocVar.getUpperCaseName()%>List !=null) for ( obj in a<%=assocVar.getUpperCaseName()%>List){ if(edited<%=bckObject.getClassName()%>.indexOf<%=assocVar.getUpperCaseName()%>(obj as <%=assocVar.getType()%>)<0) this.edited<%=bckObject.getClassName()%>.add<%=assocVar.getUpperCaseName()%>(obj as <%=assocVar.getType()%>); } if (this.edited<%=bckObject.getClassName()%>.get<%=assocVar.getUpperCaseName()%>s()!=null){ var toRemove:ArrayList =new ArrayList(); for ( obj in this.edited<%=bckObject.getClassName()%>.get<%=assocVar.getUpperCaseName()%>s()){ if(a<%=assocVar.getUpperCaseName()%>List!=null and not a<%=assocVar.getUpperCaseName()%>List.contains(obj)) toRemove.add(obj); } for ( obj in toRemove){ this.edited<%=bckObject.getClassName()%>.remove<%=assocVar.getUpperCaseName()%>(obj as <%=assocVar.getType()%>); } } <% } %> } }catch(e: java.lang.RuntimeException){ javafx.stage.Alert.inform("Error", e.getMessage()); return; } a<%=bckObject.getClassName()%>Table.refresh(); onCancel(); } function onDelete() { this.edited<%=bckObject.getClassName()%> = a<%=bckObject.getClassName()%>Table.getSelected<%=bckObject.getClassName()%>(); DAOUtils.getDAOFactory().get<%=bckObject.getClassName()%>DAO().deleteTree(edited<%=bckObject.getClassName()%>); a<%=bckObject.getClassName()%>Table.refresh(); onCancel(); return ""; } function onCancel() { this.edited<%=bckObject.getClassName()%> = null; <% for (AttributeVariable attVar: bckObject.getAttVariables()) { Object obj= attVar.getValue(); if (obj!=null && !"Date".equals(attVar.getType()) ){ %> <%=bckObject.getFragmentProvider().getAsignationFragment(attVar, obj.toString()) %> <% }else if ("Date".equals(attVar.getType()) ){ %> <%=bckObject.getFragmentProvider().getAsignationFragment(attVar, "getInitial"+attVar.getUpperCaseName()+"()") %> <% }else{ %> <%=bckObject.getFragmentProvider().getAsignationFragment(attVar, "\"\"") %> <% } } %> <% for (AttributeVariable attVar: bckObject.getKeysAttributes()) { %> <% Object obj= attVar.getValue(); if (obj!=null && !"Date".equals(attVar.getType()) ){ %> <%=bckObject.getFragmentProvider().getAsignationFragment(attVar, obj.toString(), "Field") %> <% }else if ("Date".equals(attVar.getType()) ){ %> <%=bckObject.getFragmentProvider().getAsignationFragment(attVar, "getInitial"+attVar.getUpperCaseName()+"()", "Field") %> <% }else{ %> <%=bckObject.getFragmentProvider().getAsignationFragment(attVar, "\"\"", "Field") %> <% } } %> <% for (AttributeVariable attVar: bckObject.getAttVariables()) { %> <%=bckObject.getFragmentProvider().getGUICreateFragment(attVar)%> <%}%> <% for (AttributeVariable attVar: bckObject.getKeysAttributes()) { %> <%=bckObject.getFragmentProvider().getGUICreateFragment(attVar)%> <%}%> <% for (AssociationVariable assocVar: mergeList) { %> a<%=assocVar.getUpperCaseName()%>=null; <% BackingObject assBck=bckObject.getFragmentProvider().getClassMap().get(assocVar.getType()); %> <% for (AttributeVariable attVar: assBck.getKeysAttributes()) { %> <%=bckObject.getFragmentProvider().getAsignationFragment(attVar, "\"\"", assocVar.getUpperCaseName() +"Selected") %> <%}%> <%}%> <% for (AssociationVariable assocVar: multipleZeroManyToOptionalAssociations) { %> a<%=assocVar.getUpperCaseName()%>List.clear(); a<%=assocVar.getUpperCaseName()%>KeyTable.refresh(); <% } %> buttonText = "Add"; } function onEdit() { this.edited<%=bckObject.getClassName()%> =a<%=bckObject.getClassName()%>Table.getSelected<%=bckObject.getClassName()%>(); <% for (AttributeVariable attVar: bckObject.getAttVariables()) { %> <%=bckObject.getFragmentProvider().getReverseCopyFragment(attVar,"this.edited"+bckObject.getClassName()) %><% } %> <% for (AttributeVariable attVar: bckObject.getKeysAttributes()) { %> <%=bckObject.getFragmentProvider().getReverseCopyFragment(attVar,"this.edited"+bckObject.getClassName(), "Field" ) %> <% }%> <% for (AttributeVariable attVar: bckObject.getAttVariables()) { %> <%=bckObject.getFragmentProvider().getGUIEditFragment(attVar)%> <%}%> <% for (AttributeVariable attVar: bckObject.getKeysAttributes()) { %> <%=bckObject.getFragmentProvider().getGUIEditFragment(attVar)%> <%}%> <% for (AssociationVariable assocVar: mergeList) { %> a<%=assocVar.getUpperCaseName()%> =this.edited<%=bckObject.getClassName()%>.get<%=assocVar.getUpperCaseName()%>(); <% BackingObject assBck=bckObject.getFragmentProvider().getClassMap().get(assocVar.getType() ); %> <% for (AttributeVariable attVar: assBck.getKeysAttributes()) { %> <%=bckObject.getFragmentProvider().getReverseCopyFragment(attVar,"a"+assocVar.getUpperCaseName(),assocVar.getUpperCaseName()+ "Selected" ) %> <%}%> <%}%> <% for (AssociationVariable assocVar: multipleZeroManyToOptionalAssociations) { %> a<%=assocVar.getUpperCaseName()%>List.clear(); a<%=assocVar.getUpperCaseName()%>List.addAll(this.edited<%=bckObject.getClassName()%>.get<%=assocVar.getUpperCaseName()%>s()); a<%=assocVar.getUpperCaseName()%>KeyTable.refresh(); <% } %> } public var <%=bckObject.getClassName().toLowerCase()%>CRUDView = VBox { translateX: 20; spacing: 15 content: [ Label { text: "<%=bckObject.getClassName()%>" font: titleFont translateX: 0 translateY: 1 }, VBox { nodeHPos: HPos.RIGHT; spacing: 15; content:[fieldsBox, HBox { translateX: -40; spacing: 10; content: [addButton, cancelButton]}] }, VBox { spacing: 10; nodeHPos: HPos.RIGHT; content: [tableComp, HBox { spacing: 10; content: [editButton, deleteButton]}, ] } ] }; }