Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/SelectProvider.java @ 49:d573ae975330
Some refactoring (imports, etc).
flys-client/trunk@1497 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 17 Mar 2011 11:39:27 +0000 |
parents | 7142386e86c2 |
children | a2923d63f530 |
line wrap: on
line source
package de.intevation.flys.client.client.ui; import java.util.LinkedHashMap; import com.google.gwt.core.client.GWT; import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.IButton; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.ComboBoxItem; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import de.intevation.flys.client.shared.model.Data; import de.intevation.flys.client.shared.model.DataItem; import de.intevation.flys.client.shared.model.DefaultData; import de.intevation.flys.client.shared.model.DefaultDataItem; import de.intevation.flys.client.client.FLYSMessages; /** * This UIProvider displays the DataItems of the Data object in a combo box. * * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> */ public class SelectProvider extends AbstractUIProvider { /** The message class that provides i18n strings.*/ protected FLYSMessages messages = GWT.create(FLYSMessages.class); /** The combobox.*/ protected ComboBoxItem combobox; /** The name of the data object.*/ protected String dataName; /** * This method currently returns a * {@link com.smartgwt.client.widgets.form.DynamicForm} that contains all * data items in a combobox stored in <i>data</i>. * * @param data The {@link Data} object. * * @return a combobox. */ public Canvas create(Data data) { dataName = data.getLabel(); VLayout v = new VLayout(); Canvas content = createWidget(data); IButton button = new IButton(messages.next(), this); v.addMember(content); v.addMember(button); return v; } /** * This method creates the content of the widget. * * @param data The {@link Data} object. * * @return a combobox. */ protected Canvas createWidget(Data data) { GWT.log("SelectProvider - create()"); HLayout layout = new HLayout(); Label label = new Label(data.getDescription()); DynamicForm form = new DynamicForm(); combobox = new ComboBoxItem(data.getLabel()); LinkedHashMap<String, String> it = new LinkedHashMap<String, String>(); for (DataItem item: data.getItems()) { it.put(item.getStringValue(), item.getLabel()); } label.setWidth(50); combobox.setValueMap(it); combobox.setShowTitle(false); form.setItems(combobox); layout.addMember(label); layout.addMember(form); label.setValign(VerticalAlignment.TOP); layout.setAlign(VerticalAlignment.TOP); return layout; } protected Data[] getData() { String selection = combobox.getValueAsString(); DataItem item = new DefaultDataItem(dataName, null, selection); return new Data[] { new DefaultData( dataName, null, null, new DataItem[] { item }, null) }; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :