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.SvgrealApp;
21  import org.vectomatic.svg.edit.client.model.AbstractModel;
22  
23  import com.extjs.gxt.ui.client.binding.FieldBinding;
24  import com.extjs.gxt.ui.client.data.ModelData;
25  import com.extjs.gxt.ui.client.widget.form.Field;
26  import com.google.gwt.core.client.GWT;
27  
28  /**
29   * Base class for bindings which do not immediately
30   * commit their value to the model when the field is changed
31   * @author laaglu
32   */
33  public abstract class DelayedBindingBase extends FieldBinding {
34  	protected Object currentValue;
35  
36  	public DelayedBindingBase(Field<?> field, String property) {
37  		super(field, property);
38  	}
39  	
40  	@Override
41  	public void bind(ModelData model) {
42  		super.bind(model);
43  		currentValue = model.get(property);
44  	}
45  
46  	@Override
47  	public void updateModel() {
48  		GWT.log("DelayedBindingBase.updateModel()");
49  		Object val = field.getValue();
50  		GWT.log("/\\/\\/\\/\\/\\/\\/\\/\\/\\ updateModel: " + val);
51  		model.set(property, val);
52  		if (SvgrealApp.getApp().getCommandFactorySelector().isSuspended()) {
53  			currentValue = val;
54  		}
55  	}
56  	
57  	protected void commitChanges() {
58  		GWT.log("DelayedBindingBase.commitChanges: " + currentValue);
59  		AbstractModel<?> amodel = (AbstractModel<?>)model;
60  		amodel.setSilent(true);
61  		model.set(property, currentValue);
62  		amodel.setSilent(false);
63  		super.updateModel();
64  		currentValue = field.getValue();
65  	}
66  
67  }