"}");
frame.refresh();
ComplexPanelInfo panel = (ComplexPanelInfo) frame.getChildrenWidgets().get(0);
WidgetInfo button = panel.getChildrenWidgets().get(0);
// prepare accessor
ExpressionAccessor accessor = new CellExpressionAccessor(panel, "setFoo", "int");
// initially no Expression
assertNull(accessor.getExpression(button));
// try to remove Expression, no changes
{
String expectedSource = m_lastEditor.getSource();
boolean success = accessor.setExpression(button, null);
assertFalse(success);
assertEditor(expectedSource, m_lastEditor);
}
// add new Expression
{
boolean success = accessor.setExpression(button, "111");
assertTrue(success);
assertEditor(
"public class Test implements EntryPoint {",
" public void onModuleLoad() {",
" RootPanel rootPanel = RootPanel.get();",
" MyPanel panel = new MyPanel();",
" rootPanel.add(panel);",
" {",
" Button button = new Button();",
" button.setEnabled(true);",
" panel.add(button);",
" panel.setFoo(button, 111);",
" button.setEnabled(true);",
" }",
" }",
"}");
}
// now we have Expression
{
Expression expression = accessor.getExpression(button);
assertNotNull(expression);
assertEquals("111", m_lastEditor.getSource(expression));
}
// update Expression
{
boolean hasChanges = accessor.setExpression(button, "222");
assertTrue(hasChanges);
assertEditor(
"public class Test implements EntryPoint {",
" public void onModuleLoad() {",
" RootPanel rootPanel = RootPanel.get();",
" MyPanel panel = new MyPanel();",
" rootPanel.add(panel);",
" {",
" Button button = new Button();",
" button.setEnabled(true);",
" panel.add(button);",
" panel.setFoo(button, 222);",
" button.setEnabled(true);",
" }",
" }",
"}");
}
// set same Expression, no changes
{
String expectedSource = m_lastEditor.getSource();
boolean success = accessor.setExpression(button, "222");
assertTrue(success);
assertEditor(expectedSource, m_lastEditor);
}
// remove Expression
{
boolean success = accessor.setExpression(button, null);
assertTrue(success);
assertEditor(
"public class Test implements EntryPoint {",
" public void onModuleLoad() {",
" RootPanel rootPanel = RootPanel.get();",
" MyPanel panel = new MyPanel();",
" rootPanel.add(panel);",
" {",
" Button button = new Button();",
" button.setEnabled(true);",
" panel.add(button);",
" button.setEnabled(true);",
" }",
" }",
"}");
}
// again no Expression
assertNull(accessor.getExpression(button));
}