BrightSide Workbench Full Report + Source Code
ReportButton.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.zkoss.print;
19 
20 import org.turro.i18n.I_;
21 import org.zkoss.zk.ui.event.Event;
22 import org.zkoss.zk.ui.event.EventListener;
23 import org.zkoss.zk.ui.event.Events;
24 import org.zkoss.zk.ui.ext.AfterCompose;
25 import org.zkoss.zul.Button;
26 import org.zkoss.zul.Menuitem;
27 import org.zkoss.zul.Menupopup;
28 
33 public abstract class ReportButton extends Button implements AfterCompose {
34 
35  protected boolean showValues = true, showLabels = true;
36 
37  public ReportButton() {
38  super();
39  }
40 
41  public void setShowLabels(boolean showLabels) {
42  this.showLabels = showLabels;
43  }
44 
45  public void setShowValues(boolean showValues) {
46  this.showValues = showValues;
47  }
48 
49  @Override
50  public void afterCompose() {
51  init();
52  }
53 
54  private void init() {
55  if(showValues) {
56  if(showLabels) {
57  setLabel(I_.get("Print"));
58  } else {
59  setTooltiptext(I_.get("Print"));
60  }
61  setImage("/_zul/images/printer.png");
62  } else {
63  if(showLabels) {
64  setLabel(I_.get("Print with no values"));
65  } else {
66  setTooltiptext(I_.get("Print with no values"));
67  }
68  setImage("/_zul/images/printer-novalues.png");
69  }
70  Menupopup menu = new Menupopup();
71  for (final ReportTypeEnum rt : ReportTypeEnum.values()) {
72  Menuitem mi = new Menuitem(rt.getLabel(), rt.getImage());
73  mi.addEventListener(Events.ON_CLICK, new EventListener() {
74  @Override
75  public void onEvent(Event event) throws Exception {
76  print(rt.getType());
77  }
78  });
79  menu.appendChild(mi);
80  }
81  getParent().appendChild(menu);
82  setContext(menu);
83  addEventListener(Events.ON_CLICK, new EventListener() {
84  @Override
85  public void onEvent(Event event) throws Exception {
86  print((String) ReportTypeEnum.PRINT_PDF.getType());
87  }
88  });
89  }
90 
91  protected abstract void print(String type);
92 }
static String get(String msg)
Definition: I_.java:41
void setShowValues(boolean showValues)
void setShowLabels(boolean showLabels)
abstract void print(String type)