18 package org.turro.zkoss.grid;
20 import java.io.ByteArrayOutputStream;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.Iterator;
25 import java.util.logging.Level;
26 import java.util.logging.Logger;
27 import org.turro.string.Strings;
28 import org.turro.command.Command;
29 import org.turro.command.Context;
30 import org.turro.elephant.context.ElephantContext;
31 import org.turro.i18n.I_;
32 import org.turro.zkoss.dialog.InputDialog;
33 import org.turro.zkoss.dialog.InputField;
34 import org.zkoss.exporter.pdf.PdfExporter;
35 import org.zkoss.util.media.AMedia;
36 import org.zkoss.zk.ui.Component;
37 import org.zkoss.zk.ui.HtmlBasedComponent;
38 import org.zkoss.zk.ui.event.Event;
39 import org.zkoss.zk.ui.event.Events;
40 import org.zkoss.zul.*;
48 private int maxResults = 30;
49 private String pagingMold =
"default", refineValue =
null;
50 private String varColumns;
51 private boolean defaultBehavior =
true;
55 Columns cols =
new Columns();
56 for(
int i = 0; i < columns; i++) {
57 Column col =
new Column();
59 cols.appendChild(col);
66 String hfs[] = hflexs.split(
",");
67 Columns cols =
new Columns();
68 for(
int i = 0; i < hfs.length; i++) {
69 Column col =
new Column();
70 if(hfs[i].startsWith(
"right-")) {
71 col.setAlign(
"right");
72 col.setHflex(hfs[i].substring(6));
76 cols.appendChild(col);
84 I_.
get(
"Refine search"),
86 new InputField(
"Text", refineValue, null, 0)
89 public Object execute(Context context) {
91 if(fields.length > 0) {
93 if(
"Text".equals(f.getLabel())) {
104 return defaultBehavior;
108 this.defaultBehavior = defaultBehavior;
116 this.refineValue = value;
126 this.maxResults = maxResults;
134 this.pagingMold = pagingMold;
138 return getRows().getChildren().size();
142 if(defaultBehavior) {
144 if(rows > maxResults) {
148 setPagingPosition(
"bottom");
149 getPagingChild().setMold(pagingMold);
152 setAutopaging(
false);
156 setPageSize((
int) (maxResults * 0.80));
157 setPagingPosition(
"both");
158 getPagingChild().setMold(pagingMold);
175 this.varColumns = varColumns;
179 return varColumns ==
null ?
180 (defaultCols ==
null ?
new ArrayList<String>() :
181 Arrays.asList(defaultCols.split(
"\\s*\\,\\s*"))) :
182 Arrays.asList(varColumns.split(
"\\s*\\,\\s*"));
190 Column c =
new Column();
192 if(caption !=
null) {
193 c.appendChild(caption);
199 for(Component row :
getRows().getChildren()) {
200 Detail d = ((Row)row).getDetailChild();
203 Events.postEvent(
new Event(Events.ON_OPEN, d));
217 getRows(
true).getChildren().clear();
223 Iterator<Component> it = (Iterator<Component>) rows.getChildren().iterator();
224 while(it.hasNext()) {
225 Row row = (Row) it.next();
226 if(row instanceof Group) {
227 Group group = (Group) row;
228 if(group.getItemCount() == 0) {
237 Columns cols = super.getColumns();
238 if(create && cols ==
null) {
239 cols =
new Columns();
240 cols.setSizable(
true);
248 if(create && rows ==
null) {
258 if(create && foot ==
null) {
277 ByteArrayOutputStream out =
new ByteArrayOutputStream();
278 PdfExporter exporter =
new PdfExporter();
279 exporter.export(
this, out);
280 AMedia amedia =
new AMedia(
"GridReport.pdf",
"pdf",
"application/pdf", out.toByteArray());
281 Filedownload.save(amedia);
283 }
catch (Exception ex) {
288 private void doRefine() {
291 for(Component row : rows.getChildren()) {
292 if(!(row instanceof Group)) {
293 if(Strings.isBlank(refineValue)) {
294 row.setVisible(
true);
296 boolean show =
false;
297 show = processChildren(row, show);
298 row.setVisible(show);
302 for(Component row : rows.getChildren()) {
303 if(row instanceof Group) {
304 Group group = (Group) row;
305 group.setVisible(group.getVisibleItemCount() > 0);
311 private boolean processChildren(Component comp,
boolean show) {
312 for (Component c : (Collection<Component>) comp.getChildren()) {
313 if (c instanceof Label) {
315 if (Strings.findsIgnoreCase(l.getValue(), refineValue)) {
318 }
else if (c instanceof Toolbarbutton) {
319 Toolbarbutton l = (Toolbarbutton) c;
320 if (Strings.findsIgnoreCase(l.getLabel(), refineValue)) {
323 }
else if (c instanceof A) {
325 if (Strings.findsIgnoreCase(a.getLabel(), refineValue)) {
329 show = processChildren(c, show);
static String logMsg(String msg)
static String get(String msg)
void setColumns(int columns)
Foot getFoot(boolean create)
Columns getColumns(boolean create)
boolean isDefaultBehavior()
void setVarColumns(String varColumns)
void setPagingMold(String pagingMold)
Rows getRows(boolean create)
void setHeadersVisible(boolean value)
void setColumns(String hflexs)
void setMaxResults(int maxResults)
Collection< String > getVarColumnsList(String defaultCols)
void addDetailColumn(HtmlBasedComponent caption)
void setRowCount(int rows)
void setRefineValue(String value)
boolean isHeadersVisible()
void setDefaultBehavior(boolean defaultBehavior)