Project

General

Profile

« Previous | Next » 

Revision bc5816ee

Added by Andreas Kohlbecker almost 7 years ago

ref #6612 Team and Person editor widgets implemented and integrated in reference editor

View differences:

src/main/java/eu/etaxonomy/vaadin/component/SwitchableTextField.java
13 13
import com.vaadin.data.fieldgroup.FieldGroup;
14 14
import com.vaadin.ui.Component;
15 15
import com.vaadin.ui.CssLayout;
16
import com.vaadin.ui.CustomField;
17 16
import com.vaadin.ui.TextField;
18 17

  
19 18

  
......
22 21
 * @since May 11, 2017
23 22
 *
24 23
 */
25
public class SwitchableTextField extends CustomField<String> {
24
public class SwitchableTextField extends CompositeCustomField<String> {
26 25

  
27 26
    private static final long serialVersionUID = -4760153886584883137L;
28 27

  
......
40 39
        textField.setCaption(caption);
41 40
        unlockSwitch.addValueChangeListener(e -> {
42 41
            textField.setEnabled(unlockSwitch.getValue());
42
            textField.focus();
43 43
        });
44 44
        unlockSwitch.setValueSetLister(e -> {
45 45
            textField.setEnabled(unlockSwitch.getValue());
46 46
        });
47

  
48
        addSizedComponent(root);
49
        addSizedComponent(textField);
50

  
51
        addStyledComponent(textField);
52
        addStyledComponent(unlockSwitch);
47 53
    }
48 54

  
49 55
    /**
......
57 63
        textField.setWidth(getWidth(), getWidthUnits());
58 64
        root.addComponent(unlockSwitch);
59 65
        setPrimaryStyleName(PRIMARY_STYLE);
66

  
60 67
        return root;
61 68
    }
62 69

  
......
68 75
        return String.class;
69 76
    }
70 77

  
71
    /**
72
     * @return the serialversionuid
73
     */
74
    public static long getSerialversionuid() {
75
        return serialVersionUID;
76
    }
77

  
78 78
    /**
79 79
     * @return the textField
80 80
     */
......
99 99
     * {@inheritDoc}
100 100
     */
101 101
    @Override
102
    public void setWidthUndefined() {
103
        super.setWidthUndefined();
104
        root.setWidthUndefined();
105
        textField.setWidthUndefined();
106
    }
102
    protected void addDefaultStyles() {
103
        // no default styles
107 104

  
108
    /**
109
     * {@inheritDoc}
110
     */
111
    @Override
112
    public void setWidth(String width) {
113
        super.setWidth(width);
114
        root.setWidth(width);
115
        textField.setWidth(width);
116
    }
117

  
118
    @Override
119
    public void setWidth(float width, Unit unit){
120
        super.setWidth(width, unit);
121
        if(root != null){
122
            root.setWidth(width, unit);
123
            textField.setWidth(width, unit);
124
        }
125 105
    }
126 106

  
127
    @Override
128
    public void setStyleName(String style) {
129
        super.setStyleName(style);
130
        textField.setStyleName(style);
131
        unlockSwitch.setStyleName(style);
132
    }
133

  
134
    @Override
135
    public void addStyleName(String style) {
136
        super.addStyleName(style);
137
        textField.addStyleName(style);
138
        unlockSwitch.addStyleName(style);
139
    }
140

  
141
    private class SwitchButton extends Switch {
142

  
143
        private static final long serialVersionUID = 2557108593729214773L;
144

  
145
        private ValueChangeListener valueSetListener = null;
146

  
147
        /**
148
         * {@inheritDoc}
149
         */
150
        @Override
151
        protected void setInternalValue(Boolean newValue) {
152
            super.setInternalValue(newValue);
153
            if(valueSetListener != null){
154
                valueSetListener.valueChange(new ValueChangeEvent(this));
155
            }
156
        }
157

  
158
        public void setValueSetLister(ValueChangeListener valueSetListener){
159
            this.valueSetListener = valueSetListener;
160
        }
161

  
162

  
163

  
164
    }
165 107
}

Also available in: Unified diff