01: /* PageSizeCommand.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Sat Jun 30 20:55:36 2007, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zul.au.in;
20:
21: import org.zkoss.lang.Objects;
22:
23: import org.zkoss.zk.mesg.MZk;
24: import org.zkoss.zk.ui.Component;
25: import org.zkoss.zk.ui.UiException;
26: import org.zkoss.zk.ui.event.Events;
27: import org.zkoss.zk.au.AuRequest;
28: import org.zkoss.zk.au.Command;
29: import org.zkoss.zul.event.PageSizeEvent;
30: import org.zkoss.zul.ext.Pageable;
31: import org.zkoss.zul.ext.Paginal;
32:
33: /**
34: * Used only by {@link AuRequest} to implement the {@link PageSizeEvent}
35: * related command.
36: *
37: * @author tomyeh
38: * @since 2.4.1
39: */
40: public class PageSizeCommand extends Command {
41: public PageSizeCommand(String evtnm, int flags) {
42: super (evtnm, flags);
43: }
44:
45: //-- super --//
46: protected void process(AuRequest request) {
47: final Component comp = request.getComponent();
48: if (comp == null)
49: throw new UiException(
50: MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this );
51: final String[] data = request.getData();
52: if (data == null || data.length != 1)
53: throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA,
54: new Object[] { Objects.toString(data), this });
55:
56: int pgsz = Integer.parseInt(data[0]);
57: if (pgsz <= 0)
58: pgsz = 1;
59: ((Pageable) comp).setPageSize(pgsz);
60: if (!(comp instanceof Paginal))
61: Events.postEvent(new PageSizeEvent(getId(), comp, pgsz));
62: }
63: }
|