01: /* PagingCommand.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Fri Aug 18 09:12:45 2006, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2006 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.PagingEvent;
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 PagingEvent}
35: * related command.
36: *
37: * @author tomyeh
38: */
39: public class PagingCommand extends Command {
40: public PagingCommand(String evtnm, int flags) {
41: super (evtnm, flags);
42: }
43:
44: //-- super --//
45: protected void process(AuRequest request) {
46: final Component comp = request.getComponent();
47: if (comp == null)
48: throw new UiException(
49: MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this );
50: final String[] data = request.getData();
51: if (data == null || data.length != 1)
52: throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA,
53: new Object[] { Objects.toString(data), this });
54:
55: final Pageable pageable = (Pageable) comp;
56: int pgi = Integer.parseInt(data[0]);
57: if (pgi < 0)
58: pgi = 0;
59: else {
60: final int pgcnt = pageable.getPageCount();
61: if (pgi >= pgcnt) {
62: pgi = pgcnt - 1;
63: if (pgi < 0)
64: pgi = 0;
65: }
66: }
67: pageable.setActivePage(pgi);
68: Events.postEvent(new PagingEvent(getId(), comp, pgi));
69: }
70: }
|