BrightSide Workbench Full Report + Source Code
OverrideInput.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero 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  * This program 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 Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zkoss.input;
20 
21 import org.turro.elephant.util.Images;
22 import org.turro.i18n.I_;
23 import org.turro.zkoss.label.LabelTypes;
24 import org.zkoss.zk.ui.event.Event;
25 import org.zkoss.zk.ui.event.EventListener;
26 import org.zkoss.zk.ui.event.Events;
27 import org.zkoss.zk.ui.ext.AfterCompose;
28 import org.zkoss.zul.Button;
29 import org.zkoss.zul.Hlayout;
30 import org.zkoss.zul.Label;
31 import org.zkoss.zul.impl.InputElement;
32 
37 public abstract class OverrideInput extends Hlayout implements AfterCompose {
38 
39  private Button reset;
40  private Label information;
41 
42  public void updateStatus() {
44  information.setValue(isCalculated() ? I_.get("Calculated") : I_.get("Manual"));
45  }
46 
47  protected abstract InputElement getEditor();
48  protected abstract void resetValue();
49  protected abstract void setEditorValue();
50  public abstract boolean isCalculated();
51 
52  @Override
53  public void afterCompose() {
54  setSclass("z-valign-middle");
55  setValign("middle");
56  setSpacing("5px");
57  InputElement editor = getEditor();
58  editor.addEventListener(Events.ON_CHANGE, new EventListener<Event>() {
59  @Override
60  public void onEvent(Event event) throws Exception {
61  information.setValue(isCalculated() ? I_.get("Calculated") : I_.get("Manual"));
62  }
63  });
64  appendChild(editor);
65  information = LabelTypes.getSoftLabel(isCalculated() ? I_.get("Calculated") : I_.get("Manual"));
66  appendChild(information);
67  reset = new Button();
68  reset.setTooltiptext(I_.get("Reset value"));
69  reset.setImage(Images.getImage("synchronize"));
70  reset.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
71  @Override
72  public void onEvent(Event event) throws Exception {
73  resetValue();
74  information.setValue(isCalculated() ? I_.get("Calculated") : I_.get("Manual"));
75  }
76  });
77  appendChild(reset);
78  }
79 }
static String getImage(String image)
Definition: Images.java:36
static String get(String msg)
Definition: I_.java:41
abstract InputElement getEditor()
static Label getSoftLabel(String value)
Definition: LabelTypes.java:28