| /******************************************************************************* |
| * Copyright (c) 2011 Laurent CARON |
| * 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: |
| * Laurent CARON (laurent.caron at gmail dot com) - Initial implementation and API |
| *******************************************************************************/ |
| package org.mihalis.opal.preferenceWindow.widgets; |
| |
| import org.eclipse.swt.SWT; |
| import org.mihalis.opal.preferenceWindow.PreferenceWindow; |
| |
| /** |
| * Instances of this class are text box to type Strings. |
| */ |
| public class PWStringText extends PWText { |
| |
| /** |
| * Constructor. |
| * |
| * @param label associated label |
| * @param propertyKey associated key |
| */ |
| public PWStringText(final String label, final String propertyKey) { |
| super(label, propertyKey); |
| } |
| |
| /** |
| * Adds the verify listeners. |
| * |
| * @see org.mihalis.opal.preferenceWindow.widgets.PWText#addVerifyListeners() |
| */ |
| @Override |
| public void addVerifyListeners() { |
| } |
| |
| /** |
| * Check. |
| * |
| * @see org.mihalis.opal.preferenceWindow.widgets.PWWidget#check() |
| */ |
| @Override |
| public void check() { |
| final Object value = PreferenceWindow.getInstance().getValueFor(getPropertyKey()); |
| if (value == null) { |
| PreferenceWindow.getInstance().setValue(getPropertyKey(), ""); |
| } else { |
| if (!(value instanceof String)) { |
| throw new UnsupportedOperationException("The property '" + getPropertyKey() + "' has to be a String because it is associated to a stringtext"); |
| } |
| } |
| } |
| |
| /** |
| * Convert value. |
| * |
| * @return the object |
| * @see org.mihalis.opal.preferenceWindow.widgets.PWText#convertValue() |
| */ |
| @Override |
| public Object convertValue() { |
| return this.text.getText(); |
| } |
| |
| /** |
| * Gets the style. |
| * |
| * @return the style |
| * @see org.mihalis.opal.preferenceWindow.widgets.PWText#getStyle() |
| */ |
| @Override |
| public int getStyle() { |
| return SWT.NONE; |
| } |
| } |