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.form;
19
20 import org.vectomatic.svg.edit.client.AppConstants;
21 import org.vectomatic.svg.edit.client.model.CssMetadata;
22
23 import com.extjs.gxt.ui.client.event.ButtonEvent;
24 import com.extjs.gxt.ui.client.event.SelectionListener;
25 import com.extjs.gxt.ui.client.widget.button.Button;
26 import com.extjs.gxt.ui.client.widget.form.AdapterField;
27
28 /**
29 * Reset button field. When clicked, it restores the
30 * associated property to its default value
31 * @author laaglu
32 */
33 public class ResetButtonField extends AdapterField {
34
35 public ResetButtonField(final CssMetadata<?> metadata) {
36 super(null);
37 Button resetButton = new Button(AppConstants.INSTANCE.clearButton());
38 setResizeWidget(true);
39 resetButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
40 @Override
41 public void componentSelected(ButtonEvent ce) {
42 // fire a change event
43 ResetButtonField.super.setValue(metadata.getDefaultValue());
44 }
45 });
46 widget = resetButton;
47 setFireChangeEventOnSetValue(true);
48 }
49
50 @Override
51 public Object getValue() {
52 return value;
53 }
54
55 @Override
56 public void setValue(Object value) {
57 // do not fire a change (the method is called because the associated
58 // field has changed)
59 this.value = value;
60 }
61 }