/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.cvsSupport2.ui.experts;

import com.intellij.ide.wizard.AbstractWizard;
import com.intellij.openapi.project.Project;

import javax.swing.*;

/**
 * author: lesya
 */
public class CvsWizard extends AbstractWizard<WizardStep> {
  protected CvsWizard(String title, Project project) {
    super(title, project);
  }

  protected void init() {
    super.init();
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        final boolean isLastStep = (getCurrentStep() + 1) == getNumberOfSteps();
        getRootPane().setDefaultButton(isLastStep ? getFinishButton() : getNextButton());
        updateStep();
      }
    });
  }

  protected String getHelpID() {
    return null;
  }

  @Override
  protected void doNextAction() {
    if ((myCurrentStep + 1) >= mySteps.size()) return;
    final WizardStep nextStep = mySteps.get(myCurrentStep + 1);
    if (! nextStep.preNextCheck()) {
      return;
    }

    super.doNextAction();
  }

  public void updateStep() {
    super.updateStep();
    if (getNumberOfSteps() == 0) return;
    WizardStep currentStep = getCurrentStepObject();
    if (!currentStep.setActive()){
      doPreviousAction();
      return;
    }
    currentStep.getPreferredFocusedComponent().requestFocus();
    if (!currentStep.nextIsEnabled()) {
      getNextButton().setEnabled(false);
      getFinishButton().setEnabled(false);
    }
    else {
      getFinishButton().setEnabled((getCurrentStep() + 1) == getNumberOfSteps());
    }
  }

  public void disableNextAndFinish() {
    if (getNextButton().isEnabled() || getFinishButton().isEnabled()) {
      updateStep();
    }
  }

  public void enableNextAndFinish() {
    if ((!getNextButton().isEnabled()) || (!getFinishButton().isEnabled())) {
      updateStep();
    }
  }

  protected void doOKAction() {
    for (final WizardStep step : mySteps) {
      step.saveState();
    }
    super.doOKAction();
  }

  public void dispose() {
    try {
      for (final WizardStep step : mySteps) {
        step.dispose();
      }
    }
    finally {
      super.dispose();
    }
  }

  public void goToPrevious() {
    doPreviousAction();
  }
}

@@ -1393,10 +1393,9 @@
  1) 
-%3E=
+%3C
  myS
@@ -1407,24 +1407,20 @@
 size()) 
-return;%0A
+%7B%0A  
     fina
@@ -1475,24 +1475,26 @@
 p + 1);%0A    
+  
 if (! nextSt
@@ -1516,32 +1516,34 @@
 ()) %7B%0A      
+  
 return;%0A
     %7D%0A%0A    s
@@ -1534,15 +1534,22 @@
 rn;%0A
+      %7D%0A
     %7D%0A
-%0A
     
@@ -1636,30 +1636,75 @@
     
-if (getNumberOfSteps()
+final int numberOfSteps = getNumberOfSteps();%0A    if (numberOfSteps
  == 
@@ -1718,16 +1718,22 @@
 rn;%0A    
+final 
 WizardSt
@@ -2111,36 +2111,33 @@
 tStep() + 1) == 
-getN
+n
 umberOfSteps());
@@ -2132,18 +2132,16 @@
 rOfSteps
-()
 );%0A    %7D
@@ -2723,24 +2723,24 @@
 .dispose();%0A
+
     %7D%0A  %7D%0A%0A 
@@ -2740,67 +2740,7 @@
 %0A  %7D
-%0A%0A  public void goToPrevious() %7B%0A    doPreviousAction();%0A  %7D
 %0A%7D%0A

Fix CVS wizards