2 * Copyright 2000-2018 Vaadin Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
17 package com.vaadin.v7.client.ui.optiongroup;
19 import com.vaadin.client.ApplicationConnection;
20 import com.vaadin.client.Paintable;
21 import com.vaadin.client.StyleConstants;
22 import com.vaadin.client.UIDL;
23 import com.vaadin.client.ui.VNativeButton;
24 import com.vaadin.v7.client.ui.AbstractFieldConnector;
25 import com.vaadin.v7.client.ui.VOptionGroupBase;
26 import com.vaadin.v7.client.ui.VTextField;
27 import com.vaadin.v7.shared.ui.select.AbstractSelectState;
29 public abstract class OptionGroupBaseConnector extends AbstractFieldConnector
30 implements Paintable {
33 public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
36 getWidget().client = client;
37 getWidget().paintableId = uidl.getId();
39 if (!isRealUpdate(uidl)) {
43 getWidget().selectedKeys = uidl.getStringArrayVariableAsSet("selected");
45 getWidget().setReadonly(isReadOnly());
46 getWidget().multiselect = "multi"
47 .equals(uidl.getStringAttribute("selectmode"));
48 getWidget().immediate = getState().immediate;
49 getWidget().nullSelectionAllowed = uidl
50 .getBooleanAttribute("nullselect");
51 getWidget().nullSelectionItemAvailable = uidl
52 .getBooleanAttribute("nullselectitem");
54 if (uidl.hasAttribute("cols")) {
55 getWidget().cols = uidl.getIntAttribute("cols");
57 if (uidl.hasAttribute("rows")) {
58 getWidget().rows = uidl.getIntAttribute("rows");
61 final UIDL ops = uidl.getChildUIDL(0);
63 if (getWidget().getColumns() > 0) {
64 getWidget().container.setWidth(getWidget().getColumns() + "em");
65 if (getWidget().container != getWidget().optionsContainer) {
66 getWidget().optionsContainer.setWidth("100%");
70 getWidget().buildOptions(ops);
72 if (uidl.getBooleanAttribute("allownewitem")) {
73 if (getWidget().newItemField == null) {
74 getWidget().newItemButton = new VNativeButton();
75 getWidget().newItemButton.setText("+");
76 getWidget().newItemButton.addClickHandler(getWidget());
77 getWidget().newItemButton
78 .addStyleName(StyleConstants.UI_WIDGET);
79 getWidget().newItemField = new VTextField();
80 getWidget().newItemField.client = getConnection();
81 getWidget().newItemField.paintableId = getConnectorId();
82 getWidget().newItemField.addKeyPressHandler(getWidget());
83 getWidget().newItemField.addStyleName(StyleConstants.UI_WIDGET);
86 getWidget().newItemField.setEnabled(
87 getWidget().isEnabled() && !getWidget().isReadonly());
88 getWidget().newItemButton.setEnabled(
89 getWidget().isEnabled() && !getWidget().isReadonly());
91 if (getWidget().newItemField == null || getWidget().newItemField
92 .getParent() != getWidget().container) {
93 getWidget().container.add(getWidget().newItemField);
94 getWidget().container.add(getWidget().newItemButton);
95 final int w = getWidget().container.getOffsetWidth()
96 - getWidget().newItemButton.getOffsetWidth();
97 getWidget().newItemField.setWidth(Math.max(w, 0) + "px");
99 } else if (getWidget().newItemField != null) {
100 getWidget().container.remove(getWidget().newItemField);
101 getWidget().container.remove(getWidget().newItemButton);
104 getWidget().setTabIndex(getState().tabIndex);
109 public VOptionGroupBase getWidget() {
110 return (VOptionGroupBase) super.getWidget();
114 public AbstractSelectState getState() {
115 return (AbstractSelectState) super.getState();