BrightSide Workbench Full Report + Source Code
RelationshipColumn.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.financials.relation;
20 
21 import org.turro.command.Command;
22 import org.turro.command.Context;
23 import org.turro.financials.document.logic.DocumentWrapper;
24 import org.turro.financials.entity.Document;
25 import org.turro.financials.entity.DocumentDefinition;
26 import org.zkoss.zk.ui.event.Event;
27 import org.zkoss.zk.ui.event.EventListener;
28 import org.zkoss.zk.ui.event.Events;
29 import org.zkoss.zul.Hlayout;
30 import org.zkoss.zul.Label;
31 import org.zkoss.zul.Toolbarbutton;
32 import org.zkoss.zul.Vbox;
33 
38 public class RelationshipColumn extends Vbox {
39 
40  private DocumentDefinition documentDefinition;
41  private DocumentRelationMode mode;
42 
43  public RelationshipColumn(DocumentDefinition documentDefinition, DocumentRelationMode mode) {
44  this.documentDefinition = documentDefinition;
45  this.mode = mode;
46  setSclass("docDefCol");
47  setStyle("border-right: solid 1px #bbb;padding: 5px;width: 180px;height: 300px;");
48  updateColumn();
49  }
50 
52  return documentDefinition;
53  }
54 
56  return mode;
57  }
58 
59  private void updateColumn() {
60  getChildren().clear();
61  Hlayout hbox = new Hlayout();
62  hbox.setHflex("1");
63  hbox.setSclass("captionBox");
64  hbox.setSpacing("5px");
65  appendChild(hbox);
66  hbox.appendChild(new Label(documentDefinition.getName()));
67  if(!mode.equals(DocumentRelationMode.RELATE_TO_NONE)) {
68  Toolbarbutton addButton = new Toolbarbutton(null, "/_zul/images/list-add.png");
69  addButton.addEventListener(Events.ON_CLICK, new EventListener() {
70  @Override
71  public void onEvent(Event event) throws Exception {
72  if(mode.equals(DocumentRelationMode.RELATE_TO_ANCESTORS)) {
73  new DocumentWrapper(getDocument()).relateAncestors(documentDefinition, new Command() {
74  @Override
75  public Object execute(Context context) {
76  notifyChange();
77  return null;
78  }
79  });
80  } else if(mode.equals(DocumentRelationMode.RELATE_TO_DESCENDANTS)) {
81  new DocumentWrapper(getDocument()).relateDescendants(documentDefinition, new Command() {
82  @Override
83  public Object execute(Context context) {
84  notifyChange();
85  return null;
86  }
87  });
88  }
89  }
90  });
91  hbox.appendChild(addButton);
92  } else {
93  hbox.appendChild(new Toolbarbutton(null, "/_zul/images/empty_img.png"));
94  }
95  }
96 
97  private void notifyChange() {
98  ((RelationshipViewer) getParent()).notifyChange();
99  }
100 
102  return ((RelationshipViewer) getParent()).getDocument();
103  }
104 
105 }
RelationshipColumn(DocumentDefinition documentDefinition, DocumentRelationMode mode)