Mercurial > dive4elements > river
view flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/StyleEditorWindow.java @ 1290:f4deeafa60b3
Build up the editor window from CollectionItemAttribute response.
flys-client/trunk@2887 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Tue, 04 Oct 2011 16:04:16 +0000 |
parents | 95ecb98c6015 |
children | 1d04f35b2cc0 |
line wrap: on
line source
package de.intevation.flys.client.client.ui.chart; import com.google.gwt.core.client.GWT; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.Button; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.CheckboxItem; import com.smartgwt.client.widgets.form.fields.SpinnerItem; import com.smartgwt.client.widgets.form.fields.ColorPickerItem; import com.smartgwt.client.widgets.form.fields.ComboBoxItem; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.types.Alignment; import de.intevation.flys.client.shared.model.Collection; import de.intevation.flys.client.shared.model.CollectionItemAttribute; import de.intevation.flys.client.shared.model.Style; import de.intevation.flys.client.shared.model.StyleSetting; import de.intevation.flys.client.client.ui.CollectionView; import de.intevation.flys.client.client.FLYSConstants; /** * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> */ public class StyleEditorWindow extends Window implements ClickHandler { /** The interface that provides i18n messages. */ protected FLYSConstants MSG = GWT.create(FLYSConstants.class); /** The collection */ protected Collection collection; /** The parent collection view */ protected CollectionView view; /** The attributes */ protected CollectionItemAttribute attributes; /** Main layout */ protected VLayout layout; public StyleEditorWindow ( Collection collection, CollectionItemAttribute attributes) { this.collection = collection; this.attributes = attributes; this.layout = new VLayout(); init(); initPanels(); } protected void init() { setTitle(MSG.properties()); setWidth(270); setHeight(200); setCanDragReposition(true); setCanDragResize(true); setKeepInParentRect(true); layout.setWidth100(); layout.setHeight100(); } protected void initPanels() { HLayout buttons = new HLayout(); Button accept = new Button(MSG.label_ok()); Button cancel = new Button(MSG.label_cancel()); cancel.addClickHandler(this); accept.addClickHandler(new ClickHandler() { public void onClick(ClickEvent e) { } }); buttons.addMember(accept); buttons.addMember(cancel); buttons.setAlign(Alignment.RIGHT); layout.addMember(createPropertyGrid("LongitudinalSectionW"));; layout.addMember(buttons); addItem(layout); } public void setCollectionView (CollectionView view) { this.view = view; setParentElement(this.view.getParentElement()); } public void onClick(ClickEvent event) { this.hide(); } protected VLayout createPropertyGrid(String stylename) { //TODO use the style-(theme-)name from response to get the correct //attribute set. VLayout properties = new VLayout(); // get the correct style using the name. Style s = attributes.getStyle(0); for (int i = 0; i < s.getNumSettings(); i ++) { final StyleSetting set = s.getSetting(i); DynamicForm property = createPropertyUI( set.getDisplayName(), set.getName(), set.getType(), set.getDefaultValue()); properties.addMember(property); } return properties; } protected DynamicForm createPropertyUI( String dname, String name, String type, String value) { DynamicForm df = new DynamicForm(); FormItem f; if(type.equals("int")) { SpinnerItem s = new SpinnerItem(name, dname); s.setMin(1); s.setMax(10); f = s; } else if (type.equals("boolean")) { CheckboxItem c = new CheckboxItem(name, dname); if(value.equals("true")) { c.setValue(true); } else { c.setValue(false); } c.setLabelAsTitle(true); f = c; } else if (type.equals("Color")) { f = new ColorPickerItem(name, dname); } else if (type.equals("Dash")) { f = new ComboBoxItem(name, dname); } else { f = new FormItem(); } f.setValue(value); f.setTitleStyle("color:#000; width:120px"); f.setTitleAlign(Alignment.LEFT); df.setFields(f); return df; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :