Skip to content

Commit

Permalink
Support non-AbstractFieldConnector fields with Grid Editor (#19440)
Browse files Browse the repository at this point in the history
Change-Id: Ib3eaf0b35cfe88391c8ab3b5fcbe668d67c2dd3c
  • Loading branch information
Teemu Suo-Anttila authored and Vaadin Code Review committed Jan 7, 2016
1 parent bdec494 commit c752035
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 6 deletions.
12 changes: 6 additions & 6 deletions client/src/com/vaadin/client/connectors/GridConnector.java
Expand Up @@ -48,7 +48,7 @@
import com.vaadin.client.communication.StateChangeEvent.StateChangeHandler;
import com.vaadin.client.connectors.RpcDataSourceConnector.DetailsListener;
import com.vaadin.client.connectors.RpcDataSourceConnector.RpcDataSource;
import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.AbstractComponentConnector;
import com.vaadin.client.ui.AbstractHasComponentsConnector;
import com.vaadin.client.ui.ConnectorFocusAndBlurHandler;
import com.vaadin.client.ui.SimpleManagedLayout;
Expand Down Expand Up @@ -160,7 +160,7 @@ private class CustomGridColumn extends Grid.Column<Object, JsonObject> {

private AbstractRendererConnector<Object> rendererConnector;

private AbstractFieldConnector editorConnector;
private AbstractComponentConnector editorConnector;

private HandlerRegistration errorStateHandler;

Expand Down Expand Up @@ -196,12 +196,12 @@ public Object getValue(final JsonObject obj) {
return null;
}

private AbstractFieldConnector getEditorConnector() {
private AbstractComponentConnector getEditorConnector() {
return editorConnector;
}

private void setEditorConnector(
final AbstractFieldConnector editorConnector) {
final AbstractComponentConnector editorConnector) {
this.editorConnector = editorConnector;

if (errorStateHandler != null) {
Expand Down Expand Up @@ -328,7 +328,7 @@ public Widget getWidget(Grid.Column<?, JsonObject> column) {
assert column != null;

if (column instanceof CustomGridColumn) {
AbstractFieldConnector c = ((CustomGridColumn) column)
AbstractComponentConnector c = ((CustomGridColumn) column)
.getEditorConnector();

if (c == null) {
Expand Down Expand Up @@ -1033,7 +1033,7 @@ private static void updateColumnFromState(CustomGridColumn column,
column.setHidingToggleCaption(state.hidingToggleCaption);

column.setEditable(state.editable);
column.setEditorConnector((AbstractFieldConnector) state.editorConnector);
column.setEditorConnector((AbstractComponentConnector) state.editorConnector);
}

/**
Expand Down
154 changes: 154 additions & 0 deletions uitest/src/com/vaadin/tests/components/grid/GridWithLabelEditor.java
@@ -0,0 +1,154 @@
/*
* Copyright 2000-2014 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.tests.components.grid;

import java.util.Collection;

import com.vaadin.data.Validator;
import com.vaadin.data.Validator.InvalidValueException;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Field;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Label;

public class GridWithLabelEditor extends AbstractTestUI {

public class LabelEditor extends Label implements Field<String> {

@Override
public void focus() {
super.focus();
}

@Override
public boolean isInvalidCommitted() {
return false;
}

@Override
public void setInvalidCommitted(boolean isCommitted) {
}

@Override
public void commit() throws SourceException, InvalidValueException {
}

@Override
public void discard() throws SourceException {
}

@Override
public void setBuffered(boolean buffered) {
}

@Override
public boolean isBuffered() {
return false;
}

@Override
public boolean isModified() {
return false;
}

@Override
public void addValidator(Validator validator) {
}

@Override
public void removeValidator(Validator validator) {
}

@Override
public void removeAllValidators() {
}

@Override
public Collection<Validator> getValidators() {
return null;
}

@Override
public boolean isValid() {
return true;
}

@Override
public void validate() throws InvalidValueException {
}

@Override
public boolean isInvalidAllowed() {
return false;
}

@Override
public void setInvalidAllowed(boolean invalidValueAllowed)
throws UnsupportedOperationException {
}

@Override
public int getTabIndex() {
return -1;
}

@Override
public void setTabIndex(int tabIndex) {
}

@Override
public boolean isRequired() {
return false;
}

@Override
public void setRequired(boolean required) {
}

@Override
public void setRequiredError(String requiredMessage) {
}

@Override
public String getRequiredError() {
return null;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public void clear() {
}

}

@Override
protected void setup(VaadinRequest request) {
Grid grid = new Grid();
addComponent(grid);

grid.setEditorEnabled(true);
grid.addColumn("Foo", String.class).setEditorField(new LabelEditor());
grid.addRow("FooFoo");

grid.editItem(grid.getContainerDataSource().firstItemId());
}

}
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2014 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.tests.components.grid;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import com.vaadin.testbench.elements.GridElement;
import com.vaadin.tests.tb3.SingleBrowserTest;

public class GridWithLabelEditorTest extends SingleBrowserTest {

@Test
public void testNoExceptionOnEdit() {
setDebug(true);
openTestURL();

assertNoErrorNotifications();

assertEquals("LabelEditor content not correct.", "FooFoo",
$(GridElement.class).first().getEditor().getField(0).getText());
}
}

0 comments on commit c752035

Please sign in to comment.