BrightSide Workbench Full Report + Source Code
ReportToolbarbutton.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.lang.Strings;
22 import org.zkoss.zk.ui.event.Event;
23 import org.zkoss.zk.ui.event.EventListener;
24 import org.zkoss.zk.ui.event.Events;
25 import org.zkoss.zk.ui.ext.AfterCompose;
26 import org.zkoss.zul.Menuitem;
27 import org.zkoss.zul.Menupopup;
28 import org.zkoss.zul.Toolbarbutton;
29 
34 public abstract class ReportToolbarbutton extends Toolbarbutton implements AfterCompose {
35 
36  protected boolean showValues = true, showLabels = true;
37 
39  super();
40  }
41 
42  public void setShowLabels(boolean showLabels) {
43  this.showLabels = showLabels;
44  }
45 
46  public void setShowValues(boolean showValues) {
47  this.showValues = showValues;
48  }
49 
50  @Override
51  public void afterCompose() {
52  init();
53  }
54 
55  private void init() {
56  if(showValues) {
57  if(showLabels) {
58  if(Strings.isBlank(getLabel())) setLabel(I_.get("Print"));
59  } else {
60  if(Strings.isBlank(getTooltiptext())) setTooltiptext(I_.get("Print"));
61  }
62  if(Strings.isBlank(getImage())) setImage("/_zul/images/printer.png");
63  } else {
64  if(showLabels) {
65  if(Strings.isBlank(getLabel())) setLabel(I_.get("Print with no values"));
66  } else {
67  if(Strings.isBlank(getTooltiptext())) setTooltiptext(I_.get("Print with no values"));
68  }
69  if(Strings.isBlank(getImage())) setImage("/_zul/images/printer-novalues.png");
70  }
71  Menupopup menu = new Menupopup();
72  for (final ReportTypeEnum rt : ReportTypeEnum.values()) {
73  Menuitem mi = new Menuitem(rt.getLabel(), rt.getImage());
74  mi.addEventListener(Events.ON_CLICK, new EventListener() {
75  @Override
76  public void onEvent(Event event) throws Exception {
77  print(rt.getType());
78  }
79  });
80  menu.appendChild(mi);
81  }
82  getParent().appendChild(menu);
83  setContext(menu);
84  addEventListener(Events.ON_CLICK, new EventListener() {
85  @Override
86  public void onEvent(Event event) throws Exception {
87  print((String) ReportTypeEnum.PRINT_PDF.getType());
88  }
89  });
90  }
91 
92  public void doPrint() {
93  print((String) ReportTypeEnum.PRINT_PDF.getType());
94  }
95 
96  protected abstract void print(String type);
97 }
static String get(String msg)
Definition: I_.java:41
abstract void print(String type)