19 package org.turro.financials.relation;
21 import java.util.List;
22 import org.turro.financials.entity.Document;
23 import org.turro.financials.entity.DocumentDefinition;
24 import org.turro.financials.entity.DocumentRelation;
25 import org.turro.financials.entity.DocumentWorkflow;
26 import org.turro.relationship.Graph;
27 import org.turro.relationship.Node;
28 import org.turro.relationship.Relationship;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.event.Events;
31 import org.zkoss.zul.Hbox;
47 this.document = document;
51 Events.postEvent(
new Event(Events.ON_CHANGE,
this));
56 getChildren().clear();
57 if(document !=
null && document.
getContract() !=
null) {
65 private void generateGraph() {
67 Node center =
new Node(
"/document/" + document.
getId(), document);
69 addDescendants(document);
70 addAncestors(document);
71 graph.generateGraph();
74 private void addDescendants(Document document) {
75 for(DocumentRelation dr : document.getDescendants()) {
76 Node start =
new Node(
"/document/" + dr.getAncestor().getId(), dr.getAncestor()),
77 end =
new Node(
"/document/" + dr.getDescendant().getId(), dr.getDescendant());
78 Relationship relationship =
new Relationship(
"/document-relation/" + dr.getId(), dr, start, end);
79 if(graph.addRelationship(relationship)) {
82 addDescendants(dr.getDescendant());
83 addAncestors(dr.getDescendant());
88 private void addAncestors(Document document) {
89 for(DocumentRelation dr : document.getAncestors()) {
90 Node start =
new Node(
"/document/" + dr.getAncestor().getId(), dr.getAncestor()),
91 end =
new Node(
"/document/" + dr.getDescendant().getId(), dr.getDescendant());
92 Relationship relationship =
new Relationship(
"/document-relation/" + dr.getId(), dr, start, end);
93 if(graph.addRelationship(relationship)) {
96 addDescendants(dr.getAncestor());
97 addAncestors(dr.getAncestor());
102 private void addToGraph(Node node) {
103 Document doc = (Document) node.getData();
104 if(doc.isBlank())
return;
105 if(graph.addNode(node)) {
106 List l = getChildren();
107 for(
int i = 0; i < l.size(); i++) {
108 RelationshipColumn rc = (RelationshipColumn) l.get(i);
109 if(rc.getDocumentDefinition().getId() == doc.getDocumentDefinition().getId()) {
110 rc.appendChild(
new DocumentBox(doc));
118 private DocumentRelationMode getRelationMode(DocumentDefinition docDef) {
119 for(DocumentWorkflow dw : document.getContract().getContractDefinition().getDocumentWorkflows()) {
120 if(dw.getAncestor().getId() == docDef.getId() &&
121 dw.getDescendant().getId() == document.getDocumentDefinition().getId()) {
122 return DocumentRelationMode.RELATE_TO_ANCESTORS;
123 }
else if(dw.getDescendant().getId() == docDef.getId() &&
124 dw.getAncestor().getId() == document.getDocumentDefinition().getId()) {
125 return DocumentRelationMode.RELATE_TO_DESCENDANTS;
128 return DocumentRelationMode.RELATE_TO_NONE;
List< DocumentDefinition > getWorkflow()
ContractDefinition getContractDefinition()
void setDocument(Document document)