Change-Id: I5355b9e37d5e7590b002b954804252597ead54c3tags/7.4.0.beta1
@@ -82,10 +82,10 @@ public class EditorRow<T> { | |||
boolean rowVisible = grid.getEscalator().getVisibleRowRange() | |||
.contains(rowIndex); | |||
if (!rowVisible) { | |||
grid.scrollToRow(rowIndex, ScrollDestination.MIDDLE); | |||
if (rowVisible) { | |||
show(); | |||
} else { | |||
grid.getEscalator().getBody().refreshRows(rowIndex, 1); | |||
grid.scrollToRow(rowIndex, ScrollDestination.MIDDLE); | |||
} | |||
} | |||
@@ -96,14 +96,16 @@ public class EditorRow<T> { | |||
* if this editor row is not in edit mode | |||
*/ | |||
public void cancel() { | |||
if (!enabled) { | |||
throw new IllegalStateException( | |||
"Cannot cancel edit: EditorRow is not enabled"); | |||
} | |||
if (state == State.INACTIVE) { | |||
throw new IllegalStateException( | |||
"Cannot cancel edit: EditorRow is not in edit mode"); | |||
} | |||
state = State.INACTIVE; | |||
hideOverlay(); | |||
grid.getEscalator().getBody().refreshRows(rowIndex, 1); | |||
state = State.INACTIVE; | |||
} | |||
public boolean isEnabled() { | |||
@@ -127,8 +129,27 @@ public class EditorRow<T> { | |||
this.enabled = enabled; | |||
} | |||
protected void setGrid(Grid<T> grid) { | |||
protected void show() { | |||
if (state == State.ACTIVATING) { | |||
state = State.ACTIVE; | |||
showOverlay(grid.getEscalator().getBody().getRowElement(rowIndex)); | |||
} | |||
} | |||
protected void setGrid(final Grid<T> grid) { | |||
assert grid != null : "Grid cannot be null"; | |||
assert this.grid == null : "Can only attach EditorRow to Grid once"; | |||
this.grid = grid; | |||
grid.addDataAvailableHandler(new DataAvailableHandler() { | |||
@Override | |||
public void onDataAvailable(DataAvailableEvent event) { | |||
if (event.getAvailableRows().contains(rowIndex)) { | |||
show(); | |||
} | |||
} | |||
}); | |||
} | |||
protected State getState() { |
@@ -1001,13 +1001,6 @@ public class Grid<T> extends Composite implements | |||
cell.getElement().removeAllChildren(); | |||
} | |||
} | |||
if (rowIndex == editorRow.getRow()) { | |||
if (editorRow.getState() == State.ACTIVATING) { | |||
editorRow.setState(State.ACTIVE); | |||
editorRow.showOverlay(rowElement); | |||
} | |||
} | |||
} | |||
@Override |
@@ -17,6 +17,7 @@ | |||
package com.vaadin.client.ui.grid; | |||
import com.google.gwt.dom.client.Element; | |||
import com.google.gwt.dom.client.TableRowElement; | |||
/** | |||
* A representation of the rows in each of the sections (header, body and | |||
@@ -182,8 +183,8 @@ public interface RowContainer { | |||
* @throws IllegalStateException | |||
* if {@code index} is currently not available in the DOM | |||
*/ | |||
public Element getRowElement(int index) throws IndexOutOfBoundsException, | |||
IllegalStateException; | |||
public TableRowElement getRowElement(int index) | |||
throws IndexOutOfBoundsException, IllegalStateException; | |||
/** | |||
* Returns the root element of RowContainer |
@@ -17,20 +17,28 @@ package com.vaadin.tests.components.grid.basicfeatures.client; | |||
import static org.junit.Assert.assertNotNull; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import com.vaadin.tests.components.grid.basicfeatures.GridBasicClientFeaturesTest; | |||
public class GridEditorRowTest extends GridBasicClientFeaturesTest { | |||
@Test | |||
public void testEditorRowOpening() throws Exception { | |||
@Before | |||
public void setUp() { | |||
openTestURL(); | |||
selectMenuPath("Component", "State", "Editor row", "Enabled"); | |||
} | |||
@Test | |||
public void testProgrammaticOpening() throws Exception { | |||
selectMenuPath("Component", "State", "Editor row", "Edit row 5"); | |||
assertNotNull(getEditorRow()); | |||
} | |||
@Test | |||
public void testProgrammaticOpeningWithScroll() throws Exception { | |||
selectMenuPath("Component", "State", "Editor row", "Edit row 100"); | |||
assertNotNull(getEditorRow()); | |||
} | |||
} |