import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHTML;
import com.vaadin.client.communication.StateChangeEvent;
-import com.vaadin.client.ui.AbstractFieldConnector;
+import com.vaadin.client.ui.HasErrorIndicator;
+import com.vaadin.client.ui.HasRequiredIndicator;
import com.vaadin.client.ui.Icon;
import com.vaadin.client.ui.ImageIcon;
import com.vaadin.client.ui.aria.AriaHelper;
import com.vaadin.shared.AbstractComponentState;
-import com.vaadin.shared.AbstractFieldState;
import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.ui.ComponentStateUtil;
boolean hasIcon = owner.getState().resources
.containsKey(ComponentConstants.ICON_RESOURCE);
boolean showRequired = false;
- boolean showError = owner.getState().errorMessage != null;
- if (owner.getState() instanceof AbstractFieldState) {
- AbstractFieldState abstractFieldState = (AbstractFieldState) owner
- .getState();
- showError = showError && !abstractFieldState.hideErrors;
+ boolean showError = false;
+ if (owner instanceof HasRequiredIndicator) {
+ showRequired = ((HasRequiredIndicator) owner)
+ .isRequiredIndicatorVisible();
}
- if (owner instanceof AbstractFieldConnector) {
- showRequired = ((AbstractFieldConnector) owner).isRequired();
+ if (owner instanceof HasErrorIndicator) {
+ showError = ((HasErrorIndicator) owner).isErrorIndicatorVisible();
}
if (icon != null) {
}
}
- public static boolean isNeeded(AbstractComponentState state) {
+ public static boolean isNeeded(ComponentConnector connector) {
+ AbstractComponentState state = connector.getState();
if (state.caption != null) {
return true;
}
if (state.resources.containsKey(ComponentConstants.ICON_RESOURCE)) {
return true;
}
- if (state.errorMessage != null) {
+ if (connector instanceof HasErrorIndicator
+ && ((HasErrorIndicator) connector).isErrorIndicatorVisible()) {
return true;
}
- if (state instanceof AbstractFieldState) {
- if (((AbstractFieldState) state).required) {
- return true;
- }
+ if (connector instanceof HasRequiredIndicator
+ && ((HasRequiredIndicator) connector)
+ .isRequiredIndicatorVisible()) {
+ return true;
}
return false;
+
}
/**
import com.vaadin.shared.ui.TabIndexState;
public abstract class AbstractComponentConnector extends AbstractConnector
- implements ComponentConnector {
+ implements ComponentConnector, HasErrorIndicator {
private HandlerRegistration contextHandler = null;
* primary style name of the widget returned by {@link #getWidget()}
* <p>
* This method can be overridden to provide additional style names for the
- * component, for example see
- * {@link AbstractFieldConnector#updateWidgetStyleNames()}
+ * component, for example see {@code AbstractFieldConnector}
* </p>
*/
protected void updateWidgetStyleNames() {
public void flush() {
// No generic implementation. Override if needed
}
+
+ @Override
+ public boolean isErrorIndicatorVisible() {
+ return getState().errorMessage != null;
+ }
}
import com.vaadin.client.StyleConstants;
import com.vaadin.shared.AbstractFieldState;
-public abstract class AbstractFieldConnector
- extends AbstractComponentConnector {
+public abstract class AbstractFieldConnector extends AbstractComponentConnector
+ implements HasRequiredIndicator, HasErrorIndicator {
@Override
public AbstractFieldState getState() {
*
* @return true if required indicator should be shown
*/
- public boolean isRequired() {
+ @Override
+ public boolean isRequiredIndicatorVisible() {
return getState().required && !isReadOnly();
}
+ @Override
+ public boolean isErrorIndicatorVisible() {
+ return super.isErrorIndicatorVisible() && !getState().hideErrors;
+ }
+
@Override
protected void updateWidgetStyleNames() {
super.updateWidgetStyleNames();
// add / remove error style name to Fields
setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(),
- StyleConstants.REQUIRED_EXT, isRequired());
+ StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible());
- getWidget().setStyleName(StyleConstants.REQUIRED, isRequired());
+ getWidget().setStyleName(StyleConstants.REQUIRED,
+ isRequiredIndicatorVisible());
}
}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client.ui;
+
+import com.vaadin.client.ComponentConnector;
+
+/**
+ * Implemented by connectors supporting an error indicator.
+ */
+public interface HasErrorIndicator extends ComponentConnector {
+
+ /**
+ * Checks if an error indicator should be shown for the given connector.
+ *
+ * @return <code>true</code> to show an indicator, <code>false</code>
+ * otherwise
+ */
+ boolean isErrorIndicatorVisible();
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client.ui;
+
+import com.vaadin.client.ComponentConnector;
+
+/**
+ * Implemented by connectors supporting a required flag.
+ */
+public interface HasRequiredIndicator extends ComponentConnector {
+
+ /**
+ * Checks if a required indicator should be shown for the given connector.
+ *
+ * @return <code>true</code> to show an indicator, <code>false</code>
+ * otherwise
+ */
+ boolean isRequiredIndicatorVisible();
+
+}
return res;
}
- /** Update caption for given widget */
- public void updateCaption(ComponentConnector paintable) {
- Widget widget = paintable.getWidget();
+ /**
+ * Update caption for the given child connector.
+ */
+ public void updateCaption(ComponentConnector childConnector) {
+ Widget widget = childConnector.getWidget();
if (widget.getParent() != this) {
// Widget has not been added because the location was not found
return;
}
VCaptionWrapper wrapper = childWidgetToCaptionWrapper.get(widget);
- if (VCaption.isNeeded(paintable.getState())) {
+ if (VCaption.isNeeded(childConnector)) {
if (wrapper == null) {
// Add a wrapper between the layout and the child widget
final String loc = getLocation(widget);
super.remove(widget);
- wrapper = new VCaptionWrapper(paintable, client);
+ wrapper = new VCaptionWrapper(childConnector, client);
super.add(wrapper, locationToElement.get(loc));
childWidgetToCaptionWrapper.put(widget, wrapper);
}
removeStyleDependentName("hasdescription");
}
- boolean required = owner instanceof AbstractFieldConnector
- && ((AbstractFieldConnector) owner).isRequired();
+ boolean required = owner instanceof HasRequiredIndicator
+ && ((HasRequiredIndicator) owner).isRequiredIndicatorVisible();
AriaHelper.handleInputRequired(owner.getWidget(), required);
* .client.ComponentConnector)
*/
@Override
- public void updateCaption(ComponentConnector component) {
+ public void updateCaption(ComponentConnector childConnector) {
VAbsoluteLayout absoluteLayoutWidget = getWidget();
- boolean captionIsNeeded = VCaption.isNeeded(component.getState());
+ boolean captionIsNeeded = VCaption.isNeeded(childConnector);
VCaption caption = absoluteLayoutWidget
- .getWidgetCaption(component.getWidget());
+ .getWidgetCaption(childConnector.getWidget());
if (captionIsNeeded) {
if (caption == null) {
- caption = new VCaption(component, getConnection());
+ caption = new VCaption(childConnector, getConnection());
}
- absoluteLayoutWidget.setWidgetCaption(component.getWidget(),
+ absoluteLayoutWidget.setWidgetCaption(childConnector.getWidget(),
caption);
} else if (caption != null) {
- absoluteLayoutWidget.setWidgetCaption(component.getWidget(), null);
+ absoluteLayoutWidget.setWidgetCaption(childConnector.getWidget(),
+ null);
}
}
getWidget().setAriaInvalid(false);
}
- getWidget().setAriaRequired(isRequired());
+ getWidget().setAriaRequired(isRequiredIndicatorVisible());
if (isReadOnly()) {
getWidget().setEnabled(false);
}
String childId = child.getConnectorId();
VCaption caption = childIdToCaption.get(childId);
- if (VCaption.isNeeded(child.getState())) {
+ if (VCaption.isNeeded(child)) {
if (caption == null) {
caption = new VCaption(child, getConnection());
childIdToCaption.put(childId, caption);
import com.vaadin.client.Util;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.communication.StateChangeEvent;
-import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.AbstractLayoutConnector;
+import com.vaadin.client.ui.HasErrorIndicator;
import com.vaadin.client.ui.LayoutClickEventHandler;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.client.ui.VFormLayout;
component.getState(), component.isEnabled());
boolean hideErrors = false;
- // FIXME This incorrectly depends on AbstractFieldConnector
- if (component instanceof AbstractFieldConnector) {
- hideErrors = ((AbstractFieldConnector) component)
- .getState().hideErrors;
+ if (component instanceof HasErrorIndicator) {
+ hideErrors = !((HasErrorIndicator) component)
+ .isErrorIndicatorVisible();
}
getWidget().table.updateError(component.getWidget(),
public void updateCaption(ComponentConnector childConnector) {
VGridLayout layout = getWidget();
Cell cell = layout.widgetToCell.get(childConnector.getWidget());
- if (VCaption.isNeeded(childConnector.getState())) {
+ if (VCaption.isNeeded(childConnector)) {
VLayoutSlot layoutSlot = cell.slot;
VCaption caption = layoutSlot.getCaption();
if (caption == null) {
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
-import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.AbstractLayoutConnector;
+import com.vaadin.client.ui.HasErrorIndicator;
+import com.vaadin.client.ui.HasRequiredIndicator;
import com.vaadin.client.ui.Icon;
import com.vaadin.client.ui.LayoutClickEventHandler;
import com.vaadin.client.ui.aria.AriaHelper;
import com.vaadin.client.ui.layout.ElementResizeEvent;
import com.vaadin.client.ui.layout.ElementResizeListener;
-import com.vaadin.shared.AbstractFieldState;
import com.vaadin.shared.ComponentConstants;
import com.vaadin.shared.communication.URLReference;
import com.vaadin.shared.ui.AlignmentInfo;
List<String> styles = child.getState().styles;
String error = child.getState().errorMessage;
- boolean showError = error != null;
- if (child.getState() instanceof AbstractFieldState) {
- AbstractFieldState abstractFieldState = (AbstractFieldState) child
- .getState();
- showError = showError && !abstractFieldState.hideErrors;
+ boolean showError = false;
+ if (child instanceof HasErrorIndicator) {
+ showError = ((HasErrorIndicator) child).isErrorIndicatorVisible();
}
boolean required = false;
- if (child instanceof AbstractFieldConnector) {
- required = ((AbstractFieldConnector) child).isRequired();
+ if (child instanceof HasRequiredIndicator) {
+ required = ((HasRequiredIndicator) child)
+ .isRequiredIndicatorVisible();
}
boolean enabled = child.isEnabled();
getWidget().setIconUri(null, client);
}
- getWidget().setErrorIndicatorVisible(null != getState().errorMessage);
+ getWidget().setErrorIndicatorVisible(isErrorIndicatorVisible());
// We may have actions attached to this panel
if (uidl.getChildCount() > 0) {
}
@Override
- public void updateCaption(ComponentConnector component) {
- if (VCaption.isNeeded(component.getState())) {
+ public void updateCaption(ComponentConnector childConnector) {
+ if (VCaption.isNeeded(childConnector)) {
if (getWidget().popup.captionWrapper != null) {
getWidget().popup.captionWrapper.updateCaption();
} else {
getWidget().popup.captionWrapper = new VCaptionWrapper(
- component, getConnection());
+ childConnector, getConnection());
getWidget().popup.setWidget(getWidget().popup.captionWrapper);
getWidget().popup.captionWrapper.updateCaption();
}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.client.v7.ui.checkbox;
-
-import com.vaadin.client.ui.checkbox.CheckBoxConnector;
-import com.vaadin.shared.ui.Connect;
-import com.vaadin.v7.ui.CheckBox;
-
-@Connect(CheckBox.class)
-public class LegacyCheckBoxConnector extends CheckBoxConnector {
-
-}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.v7.client.ui;
+
+import com.vaadin.client.StyleConstants;
+import com.vaadin.client.ui.AbstractComponentConnector;
+import com.vaadin.client.ui.HasErrorIndicator;
+import com.vaadin.client.ui.HasRequiredIndicator;
+import com.vaadin.shared.AbstractFieldState;
+
+@Deprecated
+public abstract class AbstractFieldConnector extends AbstractComponentConnector
+ implements HasRequiredIndicator, HasErrorIndicator {
+
+ @Override
+ public AbstractFieldState getState() {
+ return (AbstractFieldState) super.getState();
+ }
+
+ @Override
+ public boolean isReadOnly() {
+ return super.isReadOnly() || getState().propertyReadOnly;
+ }
+
+ public boolean isModified() {
+ return getState().modified;
+ }
+
+ /**
+ * Checks whether the required indicator should be shown for the field.
+ *
+ * Required indicators are hidden if the field or its data source is
+ * read-only.
+ *
+ * @return true if required indicator should be shown
+ */
+ @Override
+ public boolean isRequiredIndicatorVisible() {
+ return getState().required && !isReadOnly();
+ }
+
+ @Override
+ public boolean isErrorIndicatorVisible() {
+ return super.isErrorIndicatorVisible() && !getState().hideErrors;
+ }
+
+ @Override
+ protected void updateWidgetStyleNames() {
+ super.updateWidgetStyleNames();
+
+ // add / remove modified style name to Fields
+ setWidgetStyleName(StyleConstants.MODIFIED, isModified());
+
+ // add / remove error style name to Fields
+ setWidgetStyleNameWithPrefix(getWidget().getStylePrimaryName(),
+ StyleConstants.REQUIRED_EXT, isRequiredIndicatorVisible());
+
+ getWidget().setStyleName(StyleConstants.REQUIRED,
+ isRequiredIndicatorVisible());
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.v7.client.ui.checkbox;
+
+import com.google.gwt.dom.client.Style.Display;
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Event;
+import com.vaadin.client.MouseEventDetailsBuilder;
+import com.vaadin.client.VCaption;
+import com.vaadin.client.VTooltip;
+import com.vaadin.client.annotations.OnStateChange;
+import com.vaadin.client.communication.StateChangeEvent;
+import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
+import com.vaadin.client.ui.Icon;
+import com.vaadin.client.ui.VCheckBox;
+import com.vaadin.shared.EventId;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
+import com.vaadin.shared.ui.checkbox.CheckBoxState;
+import com.vaadin.v7.client.ui.AbstractFieldConnector;
+import com.vaadin.v7.ui.CheckBox;
+
+@Connect(CheckBox.class)
+public class CheckBoxConnector extends AbstractFieldConnector
+ implements ClickHandler {
+
+ @Override
+ public boolean delegateCaptionHandling() {
+ return false;
+ }
+
+ @Override
+ protected void init() {
+ super.init();
+
+ getWidget().addClickHandler(this);
+ getWidget().client = getConnection();
+ getWidget().id = getConnectorId();
+
+ ConnectorFocusAndBlurHandler.addHandlers(this);
+ }
+
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+
+ if (null != getState().errorMessage) {
+ getWidget().setAriaInvalid(true);
+
+ if (getWidget().errorIndicatorElement == null) {
+ getWidget().errorIndicatorElement = DOM.createSpan();
+ getWidget().errorIndicatorElement.setInnerHTML(" ");
+ DOM.setElementProperty(getWidget().errorIndicatorElement,
+ "className", "v-errorindicator");
+ DOM.appendChild(getWidget().getElement(),
+ getWidget().errorIndicatorElement);
+ DOM.sinkEvents(getWidget().errorIndicatorElement,
+ VTooltip.TOOLTIP_EVENTS | Event.ONCLICK);
+ } else {
+ getWidget().errorIndicatorElement.getStyle().clearDisplay();
+ }
+ } else if (getWidget().errorIndicatorElement != null) {
+ getWidget().errorIndicatorElement.getStyle()
+ .setDisplay(Display.NONE);
+
+ getWidget().setAriaInvalid(false);
+ }
+
+ getWidget().setAriaRequired(isRequiredIndicatorVisible());
+ if (isReadOnly()) {
+ getWidget().setEnabled(false);
+ }
+
+ if (getWidget().icon != null) {
+ getWidget().getElement().removeChild(getWidget().icon.getElement());
+ getWidget().icon = null;
+ }
+ Icon icon = getIcon();
+ if (icon != null) {
+ getWidget().icon = icon;
+ DOM.insertChild(getWidget().getElement(), icon.getElement(), 1);
+ icon.sinkEvents(VTooltip.TOOLTIP_EVENTS);
+ icon.sinkEvents(Event.ONCLICK);
+ }
+
+ // Set text
+ VCaption.setCaptionText(getWidget(), getState());
+
+ getWidget().setValue(getState().checked);
+ getWidget().immediate = getState().immediate;
+ }
+
+ @Override
+ public CheckBoxState getState() {
+ return (CheckBoxState) super.getState();
+ }
+
+ @Override
+ public VCheckBox getWidget() {
+ return (VCheckBox) super.getWidget();
+ }
+
+ @Override
+ public void onClick(ClickEvent event) {
+ if (!isEnabled()) {
+ return;
+ }
+
+ // We get click events also from the label text, which do not alter the
+ // actual value. The server-side is only interested in real changes to
+ // the state.
+ if (getState().checked != getWidget().getValue()) {
+ getState().checked = getWidget().getValue();
+
+ // Add mouse details
+ MouseEventDetails details = MouseEventDetailsBuilder
+ .buildMouseEventDetails(event.getNativeEvent(),
+ getWidget().getElement());
+ getRpcProxy(CheckBoxServerRpc.class).setChecked(getState().checked,
+ details);
+ if (getState().immediate) {
+ getConnection().sendPendingVariableChanges();
+ }
+ }
+ }
+
+ private boolean contextEventSunk = false;
+
+ @OnStateChange("registeredEventListeners")
+ void sinkContextClickEvent() {
+ if (!contextEventSunk && hasEventListener(EventId.CONTEXT_CLICK)) {
+ // CheckBox.sinkEvents works differently than all other widgets:
+ // "Unlike other widgets the CheckBox sinks on its inputElement, not
+ // its wrapper"
+ DOM.sinkEvents(getWidget().getElement(), Event.ONCONTEXTMENU);
+ contextEventSunk = true;
+ }
+ }
+}
import com.vaadin.client.UIDL;
import com.vaadin.client.communication.RpcProxy;
import com.vaadin.client.communication.StateChangeEvent;
-import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.SimpleManagedLayout;
import com.vaadin.shared.EventId;
import com.vaadin.shared.communication.FieldRpc.FocusAndBlurServerRpc;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.combobox.ComboBoxServerRpc;
import com.vaadin.shared.ui.combobox.ComboBoxState;
+import com.vaadin.v7.client.ui.AbstractFieldConnector;
import com.vaadin.v7.client.ui.VFilterSelect;
import com.vaadin.v7.client.ui.VFilterSelect.DataReceivedHandler;
import com.vaadin.v7.client.ui.VFilterSelect.FilterSelectSuggestion;
import com.vaadin.client.Paintable;
import com.vaadin.client.UIDL;
import com.vaadin.client.VConsole;
-import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.VDateField;
import com.vaadin.shared.ui.datefield.DateFieldConstants;
import com.vaadin.shared.ui.datefield.Resolution;
+import com.vaadin.v7.client.ui.AbstractFieldConnector;
public class AbstractDateFieldConnector extends AbstractFieldConnector
implements Paintable {
import com.vaadin.client.Paintable;
import com.vaadin.client.StyleConstants;
import com.vaadin.client.UIDL;
-import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.VNativeButton;
import com.vaadin.client.ui.VOptionGroupBase;
import com.vaadin.client.v7.ui.VLegacyTextField;
import com.vaadin.shared.ui.select.AbstractSelectState;
+import com.vaadin.v7.client.ui.AbstractFieldConnector;
public abstract class OptionGroupBaseConnector extends AbstractFieldConnector
implements Paintable {
package com.vaadin.v7.client.ui.progressindicator;
import com.vaadin.client.communication.StateChangeEvent;
-import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.VProgressBar;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.progressindicator.ProgressBarState;
+import com.vaadin.v7.client.ui.AbstractFieldConnector;
import com.vaadin.v7.ui.ProgressBar;
/**
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.Paintable;
import com.vaadin.client.UIDL;
-import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.SimpleManagedLayout;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.Connect.LoadStyle;
import com.vaadin.shared.ui.textarea.RichTextAreaState;
import com.vaadin.shared.util.SharedUtil;
+import com.vaadin.v7.client.ui.AbstractFieldConnector;
import com.vaadin.v7.client.ui.VRichTextArea;
import com.vaadin.v7.ui.RichTextArea;
import com.vaadin.client.TooltipInfo;
import com.vaadin.client.UIDL;
import com.vaadin.client.WidgetUtil;
-import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.table.TableConstants;
import com.vaadin.shared.ui.table.TableConstants.Section;
+import com.vaadin.v7.client.ui.AbstractFieldConnector;
import com.vaadin.v7.client.ui.VScrollTable;
import com.vaadin.v7.client.ui.VScrollTable.ContextMenuDetails;
import com.vaadin.v7.client.ui.VScrollTable.FooterCell;
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.vaadin.v7.ui;
+
+import java.util.Collection;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+
+import com.vaadin.event.FieldEvents.BlurEvent;
+import com.vaadin.event.FieldEvents.BlurListener;
+import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
+import com.vaadin.event.FieldEvents.FocusEvent;
+import com.vaadin.event.FieldEvents.FocusListener;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
+import com.vaadin.shared.ui.checkbox.CheckBoxState;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
+import com.vaadin.v7.data.Property;
+
+public class CheckBox extends AbstractField<Boolean> {
+
+ private CheckBoxServerRpc rpc = new CheckBoxServerRpc() {
+
+ @Override
+ public void setChecked(boolean checked,
+ MouseEventDetails mouseEventDetails) {
+ if (isReadOnly()) {
+ return;
+ }
+
+ /*
+ * Client side updates the state before sending the event so we need
+ * to make sure the cached state is updated to match the client. If
+ * we do not do this, a reverting setValue() call in a listener will
+ * not cause the new state to be sent to the client.
+ *
+ * See #11028, #10030.
+ */
+ getUI().getConnectorTracker().getDiffState(CheckBox.this)
+ .put("checked", checked);
+
+ final Boolean oldValue = getValue();
+ final Boolean newValue = checked;
+
+ if (!newValue.equals(oldValue)) {
+ // The event is only sent if the switch state is changed
+ setValue(newValue);
+ }
+
+ }
+ };
+
+ FocusAndBlurServerRpcImpl focusBlurRpc = new FocusAndBlurServerRpcImpl(
+ this) {
+ @Override
+ protected void fireEvent(Event event) {
+ CheckBox.this.fireEvent(event);
+ }
+ };
+
+ /**
+ * Creates a new checkbox.
+ */
+ public CheckBox() {
+ registerRpc(rpc);
+ registerRpc(focusBlurRpc);
+ setValue(Boolean.FALSE);
+ }
+
+ /**
+ * Creates a new checkbox with a set caption.
+ *
+ * @param caption
+ * the Checkbox caption.
+ */
+ public CheckBox(String caption) {
+ this();
+ setCaption(caption);
+ }
+
+ /**
+ * Creates a new checkbox with a caption and a set initial state.
+ *
+ * @param caption
+ * the caption of the checkbox
+ * @param initialState
+ * the initial state of the checkbox
+ */
+ public CheckBox(String caption, boolean initialState) {
+ this(caption);
+ setValue(initialState);
+ }
+
+ /**
+ * Creates a new checkbox that is connected to a boolean property.
+ *
+ * @param state
+ * the Initial state of the switch-button.
+ * @param dataSource
+ */
+ public CheckBox(String caption, Property<?> dataSource) {
+ this(caption);
+ setPropertyDataSource(dataSource);
+ }
+
+ @Override
+ public Class<Boolean> getType() {
+ return Boolean.class;
+ }
+
+ @Override
+ protected CheckBoxState getState() {
+ return (CheckBoxState) super.getState();
+ }
+
+ /*
+ * Overridden to keep the shared state in sync with the LegacyAbstractField
+ * internal value. Should be removed once LegacyAbstractField is refactored
+ * to use shared state.
+ *
+ * See tickets #10921 and #11064.
+ */
+ @Override
+ protected void setInternalValue(Boolean newValue) {
+ super.setInternalValue(newValue);
+ if (newValue == null) {
+ newValue = false;
+ }
+ getState().checked = newValue;
+ }
+
+ public void addBlurListener(BlurListener listener) {
+ addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
+ BlurListener.blurMethod);
+ }
+
+ /**
+ * @deprecated As of 7.0, replaced by {@link #addBlurListener(BlurListener)}
+ **/
+ @Deprecated
+ public void addListener(BlurListener listener) {
+ addBlurListener(listener);
+ }
+
+ public void removeBlurListener(BlurListener listener) {
+ removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
+ }
+
+ /**
+ * @deprecated As of 7.0, replaced by
+ * {@link #removeBlurListener(BlurListener)}
+ **/
+ @Deprecated
+ public void removeListener(BlurListener listener) {
+ removeBlurListener(listener);
+ }
+
+ public void addFocusListener(FocusListener listener) {
+ addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
+ FocusListener.focusMethod);
+ }
+
+ /**
+ * @deprecated As of 7.0, replaced by
+ * {@link #addFocusListener(FocusListener)}
+ **/
+ @Deprecated
+ public void addListener(FocusListener listener) {
+ addFocusListener(listener);
+ }
+
+ public void removeFocusListener(FocusListener listener) {
+ removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
+ }
+
+ /**
+ * @deprecated As of 7.0, replaced by
+ * {@link #removeFocusListener(FocusListener)}
+ **/
+ @Deprecated
+ public void removeListener(FocusListener listener) {
+ removeFocusListener(listener);
+ }
+
+ /**
+ * Get the boolean value of the button state.
+ *
+ * @return True iff the button is pressed down or checked.
+ *
+ * @deprecated As of 7.0, use {@link #getValue()} instead and, if needed,
+ * handle null values.
+ */
+ @Deprecated
+ public boolean booleanValue() {
+ Boolean value = getValue();
+ return (null == value) ? false : value.booleanValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element,
+ * com.vaadin.ui.declarative.DesignContext)
+ */
+ @Override
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
+ if (design.hasAttr("checked")) {
+ this.setValue(DesignAttributeHandler.readAttribute("checked",
+ design.attributes(), Boolean.class), false, true);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.AbstractField#getCustomAttributes()
+ */
+ @Override
+ protected Collection<String> getCustomAttributes() {
+ Collection<String> attributes = super.getCustomAttributes();
+ attributes.add("checked");
+ return attributes;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.AbstractField#writeDesign(org.jsoup.nodes.Element,
+ * com.vaadin.ui.declarative.DesignContext)
+ */
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+ CheckBox def = (CheckBox) designContext
+ .getDefaultInstance(this);
+ Attributes attr = design.attributes();
+ DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
+ def.getValue(), Boolean.class);
+ }
+
+ @Override
+ public void clear() {
+ setValue(Boolean.FALSE);
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return getValue() == null || getValue().equals(Boolean.FALSE);
+
+ }
+
+}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package com.vaadin.v7.ui;
-
-import java.util.Collection;
-
-import org.jsoup.nodes.Attributes;
-import org.jsoup.nodes.Element;
-
-import com.vaadin.event.FieldEvents.BlurEvent;
-import com.vaadin.event.FieldEvents.BlurListener;
-import com.vaadin.event.FieldEvents.FocusAndBlurServerRpcImpl;
-import com.vaadin.event.FieldEvents.FocusEvent;
-import com.vaadin.event.FieldEvents.FocusListener;
-import com.vaadin.shared.MouseEventDetails;
-import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
-import com.vaadin.shared.ui.checkbox.CheckBoxState;
-import com.vaadin.ui.declarative.DesignAttributeHandler;
-import com.vaadin.ui.declarative.DesignContext;
-import com.vaadin.v7.data.Property;
-
-public class CheckBox extends AbstractField<Boolean> {
-
- private CheckBoxServerRpc rpc = new CheckBoxServerRpc() {
-
- @Override
- public void setChecked(boolean checked,
- MouseEventDetails mouseEventDetails) {
- if (isReadOnly()) {
- return;
- }
-
- /*
- * Client side updates the state before sending the event so we need
- * to make sure the cached state is updated to match the client. If
- * we do not do this, a reverting setValue() call in a listener will
- * not cause the new state to be sent to the client.
- *
- * See #11028, #10030.
- */
- getUI().getConnectorTracker().getDiffState(CheckBox.this)
- .put("checked", checked);
-
- final Boolean oldValue = getValue();
- final Boolean newValue = checked;
-
- if (!newValue.equals(oldValue)) {
- // The event is only sent if the switch state is changed
- setValue(newValue);
- }
-
- }
- };
-
- FocusAndBlurServerRpcImpl focusBlurRpc = new FocusAndBlurServerRpcImpl(
- this) {
- @Override
- protected void fireEvent(Event event) {
- CheckBox.this.fireEvent(event);
- }
- };
-
- /**
- * Creates a new checkbox.
- */
- public CheckBox() {
- registerRpc(rpc);
- registerRpc(focusBlurRpc);
- setValue(Boolean.FALSE);
- }
-
- /**
- * Creates a new checkbox with a set caption.
- *
- * @param caption
- * the Checkbox caption.
- */
- public CheckBox(String caption) {
- this();
- setCaption(caption);
- }
-
- /**
- * Creates a new checkbox with a caption and a set initial state.
- *
- * @param caption
- * the caption of the checkbox
- * @param initialState
- * the initial state of the checkbox
- */
- public CheckBox(String caption, boolean initialState) {
- this(caption);
- setValue(initialState);
- }
-
- /**
- * Creates a new checkbox that is connected to a boolean property.
- *
- * @param state
- * the Initial state of the switch-button.
- * @param dataSource
- */
- public CheckBox(String caption, Property<?> dataSource) {
- this(caption);
- setPropertyDataSource(dataSource);
- }
-
- @Override
- public Class<Boolean> getType() {
- return Boolean.class;
- }
-
- @Override
- protected CheckBoxState getState() {
- return (CheckBoxState) super.getState();
- }
-
- /*
- * Overridden to keep the shared state in sync with the LegacyAbstractField
- * internal value. Should be removed once LegacyAbstractField is refactored
- * to use shared state.
- *
- * See tickets #10921 and #11064.
- */
- @Override
- protected void setInternalValue(Boolean newValue) {
- super.setInternalValue(newValue);
- if (newValue == null) {
- newValue = false;
- }
- getState().checked = newValue;
- }
-
- public void addBlurListener(BlurListener listener) {
- addListener(BlurEvent.EVENT_ID, BlurEvent.class, listener,
- BlurListener.blurMethod);
- }
-
- /**
- * @deprecated As of 7.0, replaced by {@link #addBlurListener(BlurListener)}
- **/
- @Deprecated
- public void addListener(BlurListener listener) {
- addBlurListener(listener);
- }
-
- public void removeBlurListener(BlurListener listener) {
- removeListener(BlurEvent.EVENT_ID, BlurEvent.class, listener);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeBlurListener(BlurListener)}
- **/
- @Deprecated
- public void removeListener(BlurListener listener) {
- removeBlurListener(listener);
- }
-
- public void addFocusListener(FocusListener listener) {
- addListener(FocusEvent.EVENT_ID, FocusEvent.class, listener,
- FocusListener.focusMethod);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #addFocusListener(FocusListener)}
- **/
- @Deprecated
- public void addListener(FocusListener listener) {
- addFocusListener(listener);
- }
-
- public void removeFocusListener(FocusListener listener) {
- removeListener(FocusEvent.EVENT_ID, FocusEvent.class, listener);
- }
-
- /**
- * @deprecated As of 7.0, replaced by
- * {@link #removeFocusListener(FocusListener)}
- **/
- @Deprecated
- public void removeListener(FocusListener listener) {
- removeFocusListener(listener);
- }
-
- /**
- * Get the boolean value of the button state.
- *
- * @return True iff the button is pressed down or checked.
- *
- * @deprecated As of 7.0, use {@link #getValue()} instead and, if needed,
- * handle null values.
- */
- @Deprecated
- public boolean booleanValue() {
- Boolean value = getValue();
- return (null == value) ? false : value.booleanValue();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element,
- * com.vaadin.ui.declarative.DesignContext)
- */
- @Override
- public void readDesign(Element design, DesignContext designContext) {
- super.readDesign(design, designContext);
- if (design.hasAttr("checked")) {
- this.setValue(DesignAttributeHandler.readAttribute("checked",
- design.attributes(), Boolean.class), false, true);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.ui.AbstractField#getCustomAttributes()
- */
- @Override
- protected Collection<String> getCustomAttributes() {
- Collection<String> attributes = super.getCustomAttributes();
- attributes.add("checked");
- return attributes;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.vaadin.ui.AbstractField#writeDesign(org.jsoup.nodes.Element,
- * com.vaadin.ui.declarative.DesignContext)
- */
- @Override
- public void writeDesign(Element design, DesignContext designContext) {
- super.writeDesign(design, designContext);
- CheckBox def = (CheckBox) designContext
- .getDefaultInstance(this);
- Attributes attr = design.attributes();
- DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
- def.getValue(), Boolean.class);
- }
-
- @Override
- public void clear() {
- setValue(Boolean.FALSE);
- }
-
- @Override
- public boolean isEmpty() {
- return getValue() == null || getValue().equals(Boolean.FALSE);
-
- }
-
-}