Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3253c6f5c8d8d07fc5f741cb7bdbac96d8f98e01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/***************************************************************************
 * Copyright (c) 2004-2007 Eike Stepper, Germany.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 **************************************************************************/
package org.eclipse.net4j.ui.wizards;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author Eike Stepper
 */
public class SteppingWizardPage extends WizardPage
{
  private int index;

  private List<Step> steps = new ArrayList(0);

  public SteppingWizardPage(int index)
  {
    super("page" + index);
    this.index = index;
  }

  public SteppingWizardPage(int index, String title, ImageDescriptor titleImage)
  {
    super("page" + index, title, titleImage);
  }

  public final int getIndex()
  {
    return index;
  }

  public List<Step> getWizardSteps()
  {
    return Collections.unmodifiableList(steps);
  }

  public boolean isEmpty()
  {
    for (Step step : steps)
    {
      if (step instanceof ValueStep)
      {
        return false;
      }
    }

    return true;
  }

  public void createControl(Composite parent)
  {
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(2, false));

    for (Step step : steps)
    {
      if (step instanceof ValueStep)
      {
        ValueStep valueStep = (ValueStep)step;
        if (valueStep.getControl() != null)
        {
          addValueControl(composite, valueStep);
        }
      }
      else if (step instanceof DecisionStep)
      {
        DecisionStep decisionStep = (DecisionStep)step;
        Group group = new Group(composite, SWT.BORDER);
        group.setText(decisionStep.getLabel());
        // for (Step decision : decisionStep)
        // {
        //
        // }
        //
        // decisionStep.createControl(composite);
      }
    }

    validate();
    setControl(composite);
  }

  protected void addValueControl(Composite composite, ValueStep valueStep)
  {
    new Label(composite, SWT.NONE).setText(valueStep.getLabel() + ":");
    Control control = valueStep.createControl(composite);
    valueStep.setControl(control);
  }

  protected void validate()
  {
    String errorMessage = null;
    for (Step step : steps)
    {
      if (step instanceof ValueStep)
      {
        errorMessage = ((ValueStep)step).validate();
        if (errorMessage != null)
        {
          break;
        }
      }
    }

    setErrorMessage(errorMessage);
    setPageComplete(errorMessage == null);
  }

  void addWizardStep(Step step)
  {
    steps.add(step);
    step.setWizardPage(this);
  }
}

Back to the top