001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     bstefanescu
016 */
017package org.nuxeo.ecm.webengine.ui.wizard;
018
019import java.io.Serializable;
020
021import org.nuxeo.ecm.webengine.forms.validation.Form;
022
023/**
024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
025 */
026public class WizardPage implements Serializable {
027
028    private static final long serialVersionUID = -1156377274574342525L;
029
030    public static final String NEXT_PAGE = "";
031
032    public static final int NEXT = 1;
033
034    public static final int BACK = 2;
035
036    public static final int CANCEL = 4;
037
038    public static final int OK = 8;
039
040    public static final int INITIAL = NEXT | CANCEL;
041
042    public static final int MIDDLE = INITIAL | BACK;
043
044    public static final int LAST = OK | BACK | CANCEL;
045
046    protected int index;
047
048    protected final String nextPageId;
049
050    protected final Class<? extends Form> formType;
051
052    protected final String id;
053
054    protected final int style;
055
056    protected Form form; // the submitted form if any
057
058    protected WizardPage prev; // to implement a stack of pages
059
060    public WizardPage(String id, Class<? extends Form> formType) {
061        this(id, formType, MIDDLE);
062    }
063
064    public WizardPage(String id, Class<? extends Form> formType, int style) {
065        this(id, formType, NEXT_PAGE, style);
066    }
067
068    public WizardPage(String id, Class<? extends Form> formType, String nextPageId) {
069        this(id, formType, nextPageId, MIDDLE);
070    }
071
072    public WizardPage(String id, Class<? extends Form> formType, String nextPageId, int style) {
073        this.id = id;
074        this.formType = formType;
075        this.nextPageId = nextPageId;
076        this.style = style;
077        this.prev = null;
078    }
079
080    public Class<? extends Form> getFormType() {
081        return formType;
082    }
083
084    public String getId() {
085        return id;
086    }
087
088    public boolean isNextEnabled() {
089        return (style & NEXT) != 0;
090    }
091
092    public boolean isBackEnabled() {
093        return (style & BACK) != 0;
094    }
095
096    public boolean isOkEnabled() {
097        return (style & OK) != 0;
098    }
099
100    public boolean isCancelEnabled() {
101        return (style & CANCEL) != 0;
102    }
103
104    public void setForm(Form form) {
105        this.form = form;
106    }
107
108    public Form getForm() {
109        return form;
110    }
111
112    public void setIndex(int index) {
113        this.index = index;
114    }
115
116    public int getIndex() {
117        return index;
118    }
119
120    public <T extends Form> String getNextPage(Wizard wizard, T form) {
121        return nextPageId;
122    }
123
124}