001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.modules.profiler.attach.wizard.steps;
042:
043: import javax.swing.event.ChangeListener;
044: import org.netbeans.modules.profiler.attach.wizard.WizardContext;
045: import org.netbeans.modules.profiler.attach.wizard.functors.ConditionalFunctor;
046: import org.netbeans.modules.profiler.attach.wizard.functors.TrueConditionalFunctor;
047: import org.netbeans.modules.profiler.attach.wizard.screen.WizardScreen;
048:
049: /**
050: *
051: * @author Jaroslav Bachorik
052: */
053: public class SimpleWizardStep implements WizardStep {
054: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
055:
056: private static final int NAVIGATION_STATE_BEGIN = 1;
057: private static final int NAVIGATION_STATE_END = 2;
058:
059: //~ Instance fields ----------------------------------------------------------------------------------------------------------
060:
061: private ConditionalFunctor condition;
062: private String title;
063: private WizardContext context;
064: private WizardScreen attachedScreen;
065: private boolean currentFlag = false;
066: private int navigationState = 0;
067:
068: //~ Constructors -------------------------------------------------------------------------------------------------------------
069:
070: public SimpleWizardStep(final String title,
071: final WizardScreen screen) {
072: this (null, title, screen);
073: }
074:
075: public SimpleWizardStep(final String title,
076: final WizardScreen screen,
077: final ConditionalFunctor condition) {
078: this (null, title, screen, condition);
079: }
080:
081: public SimpleWizardStep(final WizardContext context,
082: final String title, final WizardScreen screen) {
083: this (context, title, screen, new TrueConditionalFunctor());
084: }
085:
086: public SimpleWizardStep(final WizardContext context,
087: final String title, final WizardScreen screen,
088: final ConditionalFunctor condition) {
089: this .context = context;
090: this .title = title;
091: screen.setTitle(title);
092: this .attachedScreen = screen;
093: this .condition = condition;
094: }
095:
096: //~ Methods ------------------------------------------------------------------------------------------------------------------
097:
098: public WizardScreen getAttachedScreen() {
099: return this .attachedScreen;
100: }
101:
102: public boolean isBegin() {
103: return (this .navigationState & NAVIGATION_STATE_BEGIN) > 0;
104: }
105:
106: public void setCurrent() {
107: this .currentFlag = true;
108: }
109:
110: public boolean isCurrent() {
111: return this .currentFlag;
112: }
113:
114: public boolean isEnd() {
115: return (this .navigationState & NAVIGATION_STATE_END) > 0;
116: }
117:
118: public void setFirst() {
119: if (this .canHandle()) {
120: this .navigationState = 0;
121: this .currentFlag = true;
122:
123: if (context != null) {
124: this .attachedScreen.onEnter(this .context);
125: }
126: } else {
127: this .navigationState = NAVIGATION_STATE_BEGIN
128: + NAVIGATION_STATE_END;
129: }
130: }
131:
132: public boolean isFirst() {
133: return true;
134: }
135:
136: public void setLast() {
137: if (this .canHandle()) {
138: this .navigationState = 0;
139: this .currentFlag = true;
140:
141: if (context != null) {
142: this .attachedScreen.onEnter(this .context);
143: }
144: } else {
145: this .navigationState = NAVIGATION_STATE_BEGIN
146: + NAVIGATION_STATE_END;
147: }
148: }
149:
150: public boolean isLast() {
151: return true;
152: }
153:
154: public void setNext() {
155: if (context != null) {
156: this .attachedScreen.onExit(this .context);
157: }
158:
159: this .navigationState = NAVIGATION_STATE_END;
160: this .currentFlag = false;
161: }
162:
163: public void setPrevious() {
164: if (context != null) {
165: this .attachedScreen.onExit(this .context);
166: }
167:
168: this .navigationState = NAVIGATION_STATE_BEGIN;
169: this .currentFlag = false;
170: }
171:
172: public int getStepIndex() {
173: return 0;
174: }
175:
176: public String getTitle() {
177: return this .title;
178: }
179:
180: public void setWizardContext(WizardContext context) {
181: this .context = context;
182: }
183:
184: public void accept(WizardStepVisitor visitor,
185: WizardContext context, int level) {
186: if (this .canHandle()) {
187: visitor.visit(this , context, level);
188: }
189: }
190:
191: public void addChangeListener(ChangeListener listener) {
192: this .attachedScreen.addChangeListener(listener);
193: }
194:
195: public boolean canBack() {
196: return this .attachedScreen.canBack(context);
197: }
198:
199: public boolean canFinish() {
200: return this .attachedScreen.canFinish(context);
201: }
202:
203: public boolean canHandle() {
204: return this .condition.evaluate(context);
205: }
206:
207: public boolean canNext() {
208: return this .attachedScreen.canNext(context);
209: }
210:
211: public boolean onCancel() {
212: return this .attachedScreen.onCancel(this .context);
213: }
214:
215: public void onFinish() {
216: this .attachedScreen.onFinish(this .context);
217: }
218:
219: public void removeChangeListener(ChangeListener listener) {
220: this.attachedScreen.removeChangeListener(listener);
221: }
222: }
|