BrightSide Workbench Full Report + Source Code
WizardOld.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.wizard;
19 
20 import java.util.LinkedList;
21 import org.turro.elephant.zkoss.Modal;
22 import org.turro.i18n.I_;
23 import org.zkoss.zk.ui.Page;
24 import org.zkoss.zk.ui.event.Event;
25 import org.zkoss.zk.ui.event.EventListener;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zul.*;
28 
33 public class WizardOld extends Window {
34 
35  private Button prior, next, finish, cancel;
36  private Tabbox body;
37  private Tabs tabs;
38  private Tabpanels panels;
39  private LinkedList<WizardPanelOld> wpanels;
40 
41  public WizardOld() {
42  addComponents();
43  }
44 
46  if(wpanels == null) {
47  wpanels = new LinkedList<WizardPanelOld>();
48  }
49  wpanels.add(panel);
50  panel.setWizard(this);
51  Tab tab = new Tab(wpanels.size() + " - " + panel.getLabel());
52  tabs.appendChild(tab);
53  Tabpanel tpanel = new Tabpanel();
54  panels.appendChild(tpanel);
55  tpanel.appendChild(panel);
56  return panel;
57  }
58 
59  public void show(Page page) {
60  setPage(page);
61  if(tabs.getChildren().isEmpty()) {
62  return;
63  }
64  body.setSelectedIndex(0);
65  setMode("modal");
66  Modal.doModal(this, null);
67  }
68 
69  protected void doPrior() {
70  priorPanel();
71  }
72 
73  protected void doNext() {
74  nextPanel();
75  }
76 
77  protected void doFinish() {
78  detach();
79  }
80 
81  protected void doCancel() {
82  detach();
83  }
84 
85  protected void priorPanel() {
86  int current = body.getSelectedIndex();
87  if(current < 1) return;
88  if(wpanels.get(current).doLeave()) {
89  current--;
90  for(int i = current; i > 0; i--) {
91  WizardPanelOld wp = wpanels.get(i);
92  if(!wp.isShouldSkip()) {
93  if(wp.doEnter()) {
94  body.setSelectedIndex(i);
95  }
96  break;
97  }
98  }
99  }
100  }
101 
102  public void nextPanel() {
103  int current = body.getSelectedIndex();
104  if(current > wpanels.size() - 2) return;
105  if(wpanels.get(current).doLeave()) {
106  current++;
107  for(int i = current; i < wpanels.size(); i++) {
108  WizardPanelOld wp = wpanels.get(i);
109  if(!wp.isShouldSkip()) {
110  if(wp.doEnter()) {
111  body.setSelectedIndex(i);
112  }
113  break;
114  }
115  }
116  }
117  }
118 
119  public void setPriorStatus(boolean enabled) {
120  prior.setDisabled(!enabled);
121  }
122 
123  public void setNextStatus(boolean enabled) {
124  next.setDisabled(!enabled);
125  }
126 
127  public void setFinishStatus(boolean enabled) {
128  finish.setDisabled(!enabled);
129  }
130 
131  public void setCancelStatus(boolean enabled) {
132  cancel.setDisabled(!enabled);
133  }
134 
135  private void addComponents() {
136  Borderlayout layout = new Borderlayout();
137  appendChild(layout);
138  Center center = new Center();
139  layout.appendChild(center);
140  South south = new South();
141  layout.appendChild(south);
142  body = new Tabbox();
143  center.appendChild(body);
144  tabs = new Tabs();
145  panels = new Tabpanels();
146  body.appendChild(tabs);
147  body.appendChild(panels);
148  Hbox buttons = new Hbox();
149  south.appendChild(buttons);
150  buttons.setAlign("end");
151  buttons.setPack("center");
152  prior = new Button(I_.get("<< Previous"));
153  prior.addEventListener(Events.ON_CLICK, new EventListener() {
154  @Override
155  public void onEvent(Event event) throws Exception {
156  doPrior();
157  }
158  });
159  buttons.appendChild(prior);
160  next = new Button(I_.get("Next >>"));
161  next.addEventListener(Events.ON_CLICK, new EventListener() {
162  @Override
163  public void onEvent(Event event) throws Exception {
164  doNext();
165  }
166  });
167  buttons.appendChild(next);
168  finish = new Button(I_.get("Finish"));
169  finish.addEventListener(Events.ON_CLICK, new EventListener() {
170  @Override
171  public void onEvent(Event event) throws Exception {
172  doFinish();
173  }
174  });
175  buttons.appendChild(finish);
176  cancel = new Button(I_.get("Cancel"));
177  cancel.addEventListener(Events.ON_CLICK, new EventListener() {
178  @Override
179  public void onEvent(Event event) throws Exception {
180  doCancel();
181  }
182  });
183  buttons.appendChild(cancel);
184  }
185 
186 }
static int doModal(String file)
Definition: Modal.java:38
static String get(String msg)
Definition: I_.java:41
void setNextStatus(boolean enabled)
Definition: WizardOld.java:123
void setCancelStatus(boolean enabled)
Definition: WizardOld.java:131
void setFinishStatus(boolean enabled)
Definition: WizardOld.java:127
WizardPanelOld addPanel(WizardPanelOld panel)
Definition: WizardOld.java:45
void setPriorStatus(boolean enabled)
Definition: WizardOld.java:119