2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.openecomp.portalsdk.analytics.controller;
24 import org.openecomp.portalsdk.analytics.model.base.*;
25 import org.openecomp.portalsdk.analytics.model.definition.*;
26 import org.openecomp.portalsdk.analytics.system.*;
27 import org.openecomp.portalsdk.analytics.util.*;
29 public class WizardSequence extends Vector {
30 // private String currentStep = AppConstants.WS_DEFINITION;
31 private int currentStepIdx = 0;
33 private String currentSubStep = "";
35 private int nextElemIdx = 0;
37 public void resetNext() {
41 public void resetNext(int toPos) {
45 public boolean hasNext() {
46 return (nextElemIdx < size());
49 public String getNext() {
50 return hasNext() ? getStep(nextElemIdx++) : null;
53 // *****************************************************
55 public WizardSequence() {
56 add(AppConstants.WS_DEFINITION);
59 private String getStep(int index) {
60 return (String) get(index);
63 private int getStepIndex(String step) {
64 for (int i = 0; i < size(); i++)
65 if (getStep(i).equals(step))
68 throw new IndexOutOfBoundsException();
72 * private String getInitialStep() { return getStep(0); } // getInitialStep
74 * private String getFinalStep() { return getStep(getStepCount()-1); } //
77 private boolean isInitialStep(int index) {
82 * private boolean isInitialStep(String step) { return
83 * isInitialStep(getStepIndex(step)); } // isInitialStep
85 private boolean isFinalStep(int index) {
89 return (index == (getStepCount() - 1));
93 * private boolean isFinalStep(String step) { return
94 * isFinalStep(getStepIndex(step)); } // isFinalStep
97 private int getNextStepIndex(int index) {
98 return (index == (getStepCount() - 1)) ? index : (index + 1);
102 * private String getNextStep(String step) { return
103 * getStep(getNextStepIndex(getStepIndex(step))); } // getNextStep
105 * private String getNextStep(String step, String subStep) {
106 * if(subStep.length()>0) return step;
108 * return getNextStep(step); } // getNextStep
110 private int getPrevStepIndex(int index) {
111 return (index == 0) ? index : (index - 1);
112 } // getPrevStepIndex
115 * private String getPrevStep(String step) { return
116 * getStep(getPrevStepIndex(getStepIndex(step))); } // getPrevStep
118 * private String getPrevStep(String step, String subStep) {
119 * if(subStep.length()>0) return step;
121 * return getPrevStep(step); } // getPrevStep
123 // *****************************************************
124 public int getStepCount() {
128 public int getCurrentStepIndex() {
129 return currentStepIdx + 1;
130 } // getCurrentStepIndex
132 public String getCurrentStep() {
133 return getStep(currentStepIdx);
136 public String getCurrentSubStep() {
137 return currentSubStep;
138 } // getCurrentSubStep
140 public boolean isInitialStep() {
141 return isInitialStep(currentStepIdx);
144 public boolean isFinalStep() {
145 return isFinalStep(currentStepIdx);
148 public void performAction(String action, ReportDefinition rdef) {
149 if (action.equals(AppConstants.WA_BACK))
150 if (currentSubStep.length() > 0)
153 currentStepIdx = getPrevStepIndex(currentStepIdx);
154 else if (action.equals(AppConstants.WA_NEXT)) {
155 if (currentSubStep.length() > 0)
158 currentStepIdx = getNextStepIndex(currentStepIdx);
160 if (!rdef.getReportDefType().equals(AppConstants.RD_SQL_BASED))
161 if (getCurrentStep().equals(AppConstants.WS_TABLES)
162 && (rdef.getDataSourceList().getDataSource().size() == 0))
163 currentSubStep = AppConstants.WSS_ADD;
164 else if (getCurrentStep().equals(AppConstants.WS_COLUMNS)
165 && (rdef.getAllColumns().size() == 0))
166 currentSubStep = (rdef.getReportType().equals(
167 AppConstants.RT_CROSSTAB) ? AppConstants.WSS_ADD
168 : AppConstants.WSS_ADD_MULTI);
170 } else if (action.equals(AppConstants.WA_EDIT) || action.equals(AppConstants.WA_ADD)
171 || action.equals(AppConstants.WA_ADD_MULTI)
172 || action.equals(AppConstants.WA_ORDER_ALL)|| action.equals(AppConstants.WSS_ADD_BLANK) || action.equals(AppConstants.WA_MODIFY)) {
173 currentSubStep = action;
175 else if (currentSubStep.equals(AppConstants.WSS_ADD)
176 || currentSubStep.equals(AppConstants.WSS_EDIT))
177 currentSubStep = AppConstants.WSS_EDIT;
182 public void performGoToStep(String step) {
183 int stepIdx = getStepIndex(step);
185 if (stepIdx >= 0 && stepIdx < getStepCount()) {
186 currentStepIdx = stepIdx;