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.PaintField;
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   * Binding class for PaintField
30   * @author laaglu
31   */
32  public class PaintFieldBinding extends DelayedBindingBase {
33  	private Listener<FieldEvent> afterEditListener;
34  
35  	public PaintFieldBinding(PaintField field, String property) {
36  		super(field, property);
37  		afterEditListener = new Listener<FieldEvent>() {
38  			@Override
39  			public void handleEvent(FieldEvent be) {
40  				commitChanges();
41  			}			
42  		};
43  	}
44  	
45  	@Override
46  	public void bind(ModelData model) {
47  		GWT.log("PaintFieldBinding.bind(" + model + ")");
48  		super.bind(model);
49  		field.addListener(Events.AfterEdit, afterEditListener);
50  		currentValue = model.get(property);
51  	}
52  	
53  	@Override
54  	public void unbind() {
55  		field.removeListener(Events.AfterEdit, afterEditListener);
56  		super.unbind();
57  	}
58  }