View Javadoc

1   /**********************************************
2    * Copyright (C) 2011 Lukas Laag
3    * This file is part of svgreal.
4    * 
5    * svgreal is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * svgreal is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with svgreal.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.svg.edit.client.gxt.binding;
19  
20  import org.vectomatic.svg.edit.client.gxt.form.DashArrayField;
21  
22  import com.extjs.gxt.ui.client.data.ModelData;
23  import com.extjs.gxt.ui.client.event.Events;
24  import com.extjs.gxt.ui.client.event.FieldEvent;
25  import com.extjs.gxt.ui.client.event.Listener;
26  import com.google.gwt.core.client.GWT;
27  
28  /**
29   * Binds a DashArrayField with a 
30   * CSS property of an SVGStyleElementModel.
31   * @author laaglu
32   */
33  public class DashArrayFieldBinding extends DelayedBindingBase {
34  	private Listener<FieldEvent> afterEditListener;
35  
36  	public DashArrayFieldBinding(DashArrayField field, String property) {
37  		super(field, property);
38  		afterEditListener = new Listener<FieldEvent>() {
39  			@Override
40  			public void handleEvent(FieldEvent be) {
41  				commitChanges();
42  			}			
43  		};
44  	}
45  
46  	@Override
47  	public void bind(ModelData model) {
48  		GWT.log("DashArrayFieldBinding.bind(" + model + ")");
49  		super.bind(model);
50  		field.addListener(Events.AfterEdit, afterEditListener);
51  		currentValue = model.get(property);
52  	}
53  	
54  	@Override
55  	public void unbind() {
56  		field.removeListener(Events.AfterEdit, afterEditListener);
57  		super.unbind();
58  	}
59  
60  }