Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0db30a6e372fce617f082ef1415287958f2434e5 (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
/***************************************************************************
 * 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.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;

/**
 * @author Eike Stepper
 */
public class StringStep extends ValueStep<String>
{
  public StringStep(String label, String key)
  {
    super(label, key, String.class);
  }

  public StringStep(String key)
  {
    this(key, key);
  }

  @Override
  protected String validateValue(String value)
  {
    if (value == null || value.length() == 0)
    {
      return super.validateValue(null);
    }

    return null;
  }

  @Override
  protected Control createControl(Composite parent)
  {
    final Text control = new Text(parent, SWT.BORDER);
    String value = getValue();
    if (value != null)
    {
      control.setText(value);
    }

    control.setLayoutData(createLayoutData());
    control.addModifyListener(new ModifyListener()
    {
      public void modifyText(ModifyEvent e)
      {
        setValue(control.getText());
      }
    });

    return control;
  }

  protected GridData createLayoutData()
  {
    return new GridData(SWT.FILL, SWT.TOP, true, false);
  }
}

Back to the top