BrightSide Workbench Full Report + Source Code
HandshakeQueueGrid.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 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.handshake;
20 
21 import org.turro.command.Command;
22 import org.turro.command.Context;
23 import org.turro.elephant.util.Images;
24 import org.turro.elephant.util.Messages;
25 import org.turro.i18n.I_;
26 import org.turro.zkoss.grid.PagingGrid;
27 import org.zkoss.zk.ui.event.Event;
28 import org.zkoss.zk.ui.event.EventListener;
29 import org.zkoss.zk.ui.event.Events;
30 import org.zkoss.zk.ui.ext.AfterCompose;
31 import org.zkoss.zul.Column;
32 import org.zkoss.zul.Columns;
33 import org.zkoss.zul.Hlayout;
34 import org.zkoss.zul.Label;
35 import org.zkoss.zul.Row;
36 import org.zkoss.zul.Rows;
37 import org.zkoss.zul.Toolbarbutton;
38 
43 public class HandshakeQueueGrid extends PagingGrid implements AfterCompose {
44 
45  private HandshakeList handshakes;
46 
47  public void reload() {
48  if(getRows() != null) {
49  getRows().detach();
50  }
51  addRows();
52  }
53 
54  @Override
55  public void afterCompose() {
56  handshakes = new HandshakeList();
57  handshakes.populate();
58  addColumns();
59  addRows();
60  }
61 
62  private void addRows() {
63  if(handshakes == null && handshakes.isEmpty()) return;
64 
65  Rows rows = getRows(true);
66 
67  for(final HandshakeItem item : handshakes) {
68  final Row row = new Row();
69  row.setValue(item);
70  rows.appendChild(row);
71  row.appendChild(new Label(item.getFrom()));
72  row.appendChild(new Label(item.getDescription()));
73  final Hlayout hbox = new Hlayout();
74  row.appendChild(hbox);
75  if(HandshakeItemStatus.HSITEM_NEW.equals(item.getStatus())) {
76  if(item.getConnectImage() != null) {
77  Toolbarbutton connect = new Toolbarbutton();
78  hbox.appendChild(connect);
79  connect.setImage(item.getConnectImage());
80  connect.setTooltiptext(I_.get("Connect to..."));
81  connect.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
82  @Override
83  public void onEvent(Event event) throws Exception {
84  item.connect(new Command() {
85  @Override
86  public Object execute(Context context) {
87  hbox.getChildren().clear();
88  return null;
89  }
90  });
91  }
92  });
93  }
94  if(item.getCreateImage() != null) {
95  Toolbarbutton connect = new Toolbarbutton();
96  hbox.appendChild(connect);
97  connect.setImage(item.getCreateImage());
98  connect.setTooltiptext(I_.get("Create new"));
99  connect.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
100  @Override
101  public void onEvent(Event event) throws Exception {
102  if(item.create()) hbox.getChildren().clear();
103  }
104  });
105  }
106  }
107  if(item.getFile() != null) {
108  Toolbarbutton delete = new Toolbarbutton();
109  hbox.appendChild(delete);
110  delete.setImage(Images.getImage("delete"));
111  delete.setTooltiptext(I_.get("Delete"));
112  delete.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
113  @Override
114  public void onEvent(Event event) throws Exception {
115  Messages.confirmDeletion().add(item.getDescription()).show(() -> {
116  if(item.deleteFile()) row.detach();
117  });
118  }
119  });
120  }
121  }
122 
123  setRowCount(handshakes.size());
124  }
125 
126  private void addColumns() {
127  Columns cols = getColumns(true);
128  appendChild(cols);
129 
130  Column col = new Column(I_.get("From"));
131  col.setHflex("1");
132  cols.appendChild(col);
133 
134  col = new Column(I_.get("Description"));
135  col.setHflex("2");
136  cols.appendChild(col);
137 
138  col = new Column();
139  col.setHflex("1");
140  cols.appendChild(col);
141 
142  }
143 
144 }
static String get(String msg)
Definition: I_.java:41
Rows getRows(boolean create)