/*
 * This is part of Geomajas, a GIS framework, http://www.geomajas.org/.
 *
 * Copyright 2008-2012 Geosparc nv, http://www.geosparc.com/, Belgium.
 *
 * The program is available in open source according to the GNU Affero
 * General Public License. All contributions in this program are covered
 * by the Geomajas Contributors License Agreement. For full licensing
 * details, see LICENSE.txt in the project root.
 */
package org.geomajas.plugin.deskmanager.client.gwt.manager.datalayer;

import org.geomajas.configuration.FeatureStyleInfo;
import org.geomajas.configuration.client.ClientVectorLayerInfo;
import org.geomajas.plugin.deskmanager.client.gwt.manager.common.AbstractConfigurationLayout;
import org.geomajas.plugin.deskmanager.client.gwt.manager.common.SaveButtonBar;
import org.geomajas.plugin.deskmanager.client.gwt.manager.i18n.ManagerMessages;
import org.geomajas.plugin.deskmanager.client.gwt.manager.service.ManagerCommandService;
import org.geomajas.plugin.deskmanager.domain.dto.LayerModelDto;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ColorPickerItem;
import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
import com.smartgwt.client.widgets.layout.VLayout;

/**
 * @author Kristof Heirwegh
 */
public class DatalayerStyle extends AbstractConfigurationLayout {

	private static final ManagerMessages MESSAGES = GWT.create(ManagerMessages.class);

	private LayerModelDto lmd;

	private DynamicForm form;

	private ColorPickerItem picker;

	private LayerModelDto layerModel;

	public DatalayerStyle() {
		super();
		setMargin(5);
		setWidth100();

		SaveButtonBar buttonBar = new SaveButtonBar(this);
		addMember(buttonBar);

		VLayout group = new VLayout();
		group.setPadding(10);
		group.setIsGroup(true);
		group.setGroupTitle(MESSAGES.datalayerStyleFormGroup());
		group.setOverflow(Overflow.AUTO);

//		form = new DynamicForm();
//		picker = new ColorPickerItem("selectColor", "Selecteer kleur: ");
//
//		picker.addChangedHandler(new com.smartgwt.client.widgets.form.fields.events.ChangedHandler() {
//
//			@Override
//			public void onChanged(ChangedEvent event) {
//				if (layerModel.getLayerConfiguration().getClientLayerInfo() instanceof ClientVectorLayerInfo) {
//					FeatureStyleInfo fs = ((ClientVectorLayerInfo) layerModel.getLayerConfiguration()
//							.getClientLayerInfo()).getNamedStyleInfo().getFeatureStyles().get(0);
//					fs.setFillColor(picker.getValueAsString());
//					fs.setStrokeColor(picker.getValueAsString());
//				}
//			}
//
//		});
//		form.setFields(picker);
//		group.addMember(form);

		addMember(group);
	}

	public void setLayerModel(LayerModelDto lmd) {
		layerModel = lmd;
//		if (layerModel.getLayerConfiguration().getClientLayerInfo() instanceof ClientVectorLayerInfo) {
//			FeatureStyleInfo fs = ((ClientVectorLayerInfo) layerModel.getLayerConfiguration()
//					.getClientLayerInfo()).getNamedStyleInfo().getFeatureStyles().get(0);
//			picker.setValue("" + fs.getFillColor());
//		}
		fireChangedHandler();
	}

	// -- SaveButtonBar events --------------------------------------------------------

	public boolean onEditClick(ClickEvent event) {
		return true;
	}

	public boolean onSaveClick(ClickEvent event) {
		return validate();
	}

	public boolean onCancelClick(ClickEvent event) {
		setLayerModel(lmd);
		return true;
	}

	public boolean validate() {
		// if (!form.validate()) {
		// SC.say(MESSAGES.formWarnNotvalid());
		// return false;
		// }
		return true;
	}

	public boolean onResetClick(ClickEvent event) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isDefault() {
		// TODO Auto-generated method stub
		return true;
	}
}

@@ -483,16 +483,18 @@
 layer;%0A%0A
+//
 import o
@@ -533,24 +533,26 @@
 eStyleInfo;%0A
+//
 import org.g
@@ -857,16 +857,18 @@
 ssages;%0A
+//
 import o
@@ -1146,24 +1146,26 @@
 ClickEvent;%0A
+//
 import com.s
@@ -1205,16 +1205,18 @@
 icForm;%0A
+//
 import c
@@ -1271,16 +1271,18 @@
 erItem;%0A
+//
 import c
@@ -1610,16 +1610,18 @@
 o lmd;%0A%0A
+//
 %09private
@@ -1640,16 +1640,18 @@
  form;%0A%0A
+//
 %09private
@@ -1676,16 +1676,18 @@
 icker;%0A%0A
+//
 %09private
@@ -2840,16 +2840,18 @@
  lmd) %7B%0A
+//
 %09%09layerM

Implement style definition on dynamic layers