/** We should remove enclosing "Cell" element if it has no attributes. */ public void test_propertyCell_removeElement() throws Exception { XmlObjectInfo panel = parse( "// filler filler filler filler filler", "<ui:UiBinder>", " <g:HorizontalPanel>", " <g:Cell width='100px'>", " <g:Button/>", " </g:Cell>", " </g:HorizontalPanel>", "</ui:UiBinder>"); refresh(); WidgetInfo button = (WidgetInfo) panel.getChildren().get(0); // "width" { Property property = PropertyUtils.getByPath(button, "Cell/width"); // remove value property.setValue(Property.UNKNOWN_VALUE); assertXML( "// filler filler filler filler filler", "<ui:UiBinder>", " <g:HorizontalPanel>", " <g:Button/>", " </g:HorizontalPanel>", "</ui:UiBinder>"); // no value assertFalse(property.isModified()); assertEquals(Property.UNKNOWN_VALUE, property.getValue()); } }
/** Test for "Edge" property, contributed to child {@link WidgetInfo}. */ public void test_propertyEdge() throws Exception { DockLayoutPanelInfo panel = parse( "// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>", " <g:DockLayoutPanel unit='CM'>", " <g:west size='1.0'>", " <g:Button wbp:name='button'/>", " </g:west>", " </g:DockLayoutPanel>", "</ui:UiBinder>"); refresh(); WidgetInfo button = getObjectByName("button"); // prepare "Edge" property Property property = button.getPropertyByTitle("Edge"); assertNotNull(property); assertEquals("WEST", getPropertyText(property)); assertInstanceOf(StringListPropertyEditor.class, property.getEditor()); // set value property.setValue("NORTH"); assertXML( "// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>", " <g:DockLayoutPanel unit='CM'>", " <g:north size='1.0'>", " <g:Button wbp:name='button'/>", " </g:north>", " </g:DockLayoutPanel>", "</ui:UiBinder>"); assertEquals("NORTH", panel.getEdge(button)); }
private void createAutobindings(List<FieldBindingInfo> bindings, boolean full) throws Exception { BeanObserveInfo beanObserveObject = null; if (full) { if (m_gridSelectionModel == null) { if (m_model instanceof BeanObserveInfo) { beanObserveObject = (BeanObserveInfo) m_model; } } else { beanObserveObject = m_gridSelectionModel; } } WidgetObserveInfo formPanel = (WidgetObserveInfo) m_target; for (WidgetObserveInfo field : formPanel.getChildren()) { Property property = field.getJavaInfo().getPropertyByTitle("name"); if (property != null) { Object nameValue = property.getValue(); if (nameValue instanceof String && !StringUtils.isEmpty(nameValue.toString())) { FieldBindingInfo binding = field.createFieldBinding(field.getSelfProperty(), "\"" + nameValue.toString() + "\""); if (full) { if (beanObserveObject == null) { binding.setModel(m_model, null); } else { binding.setModel( beanObserveObject, beanObserveObject.resolvePropertyReference(binding.getParsedProperty(), null)); } } binding.setAutobind(true); binding.setParentBinding(this); bindings.add(binding); } } } }
//////////////////////////////////////////////////////////////////////////// // // Change "Unit" property // //////////////////////////////////////////////////////////////////////////// public void test_propertyUnit() throws Exception { DockLayoutPanelInfo panel = parse( "// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>", " <g:DockLayoutPanel/>", "</ui:UiBinder>"); refresh(); // Unit property Property unitProperty = panel.getPropertyByTitle("Unit"); assertNotNull(unitProperty); assertTrue(unitProperty.getCategory().isSystem()); // default value assertFalse(unitProperty.isModified()); assertEquals("PX", getPropertyText(unitProperty)); // set value setPropertyText(unitProperty, "MM"); assertXML( "// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>", " <g:DockLayoutPanel unit='MM'/>", "</ui:UiBinder>"); assertTrue(unitProperty.isModified()); assertEquals("MM", getPropertyText(unitProperty)); }
/** @return <code>true</code> if this is horizontal layout. */ public boolean isHorizontal() throws Exception { Property property = getPropertyByTitle(LayoutConstants.ATTR_ORIENTATION); if (property == null) { return false; } int value = (Integer) property.getValue(); // LinearLayout.VERTICAL return value != 1; }
public void test_operations() throws Exception { dontUseSharedGWTState(); setFileContentSrc( "test/client/MyButton.java", getJavaSource( "import com.google.gwt.uibinder.client.UiConstructor;", "// filler filler filler filler filler", "// filler filler filler filler filler", "public class MyButton extends Button {", " @UiConstructor", " public MyButton(int foo) {", " }", "}")); waitForAutoBuild(); // parse parse( "// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>", " <g:FlowPanel>", " <t:MyButton wbp:name='button' foo='1'/>", " </g:FlowPanel>", "</ui:UiBinder>"); refresh(); WidgetInfo button = getObjectByName("button"); // prepare property Property property = PropertyUtils.getByPath(button, "UiConstructor/foo"); // initial value assertEquals(1, property.getValue()); // set new value property.setValue(2); assertXML( "// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>", " <g:FlowPanel>", " <t:MyButton wbp:name='button' foo='2'/>", " </g:FlowPanel>", "</ui:UiBinder>"); // no delete property.setValue(Property.UNKNOWN_VALUE); assertXML( "// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>", " <g:FlowPanel>", " <t:MyButton wbp:name='button' foo='2'/>", " </g:FlowPanel>", "</ui:UiBinder>"); }
/** * @return <code>true</code> if widget has gravity flag equivalent to given <code>position</code>. */ final boolean hasGravityValue(ViewInfo child, boolean isHorizontal, int position) throws Exception { Property property = getLayoutPropertyByTitle(child, LayoutConstants.ATTR_GRAVITY); if (property == null) { return false; } Object value = property.getValue(); if (Property.UNKNOWN_VALUE == value) { return false; } int mask = isHorizontal ? 0x07 : 0x70; int toSearch = positionToGravity(position, isHorizontal); int gravity = (Integer) value & mask; return gravity == toSearch; }
/** Opens editing dialog. */ private void openDialog(Property property) throws Exception { // set initial color { Object value = property.getValue(); if (value instanceof String) { RGB rgb = ColorDialog.getRGB((String) value); if (rgb != null) { m_colorDialog.setColorInfo(new ColorInfo(null, rgb)); } } } // open dialog if (m_colorDialog.open() == Window.OK) { ColorInfo colorInfo = m_colorDialog.getColorInfo(); String colorString = getColorString(colorInfo); property.setValue(colorString); } }
final void setGravity(ViewInfo child, boolean isHorizontal, int position) throws Exception { Property property = getLayoutPropertyByTitle(child, LayoutConstants.ATTR_GRAVITY); if (property == null) { return; } Object value = property.getValue(); if (Property.UNKNOWN_VALUE == value) { value = 0; } int toSet = positionToGravity(position, isHorizontal); int mask = isHorizontal ? 0x07 : 0x70; int keepBits = (Integer) value & ~mask; GenericPropertyImpl genericProperty = (GenericPropertyImpl) property; // the 'gravity' property should have a special editor, use it to setup the expression. FlagsPropertyEditor editor = (FlagsPropertyEditor) genericProperty.getDescription().getEditor(); String expression = editor.getValueSource(property, keepBits | toSet); genericProperty.setExpression(expression, Property.UNKNOWN_VALUE); }
public void test_propertyCell_existingElement_horizontalAlignment() throws Exception { parse( "// filler filler filler filler filler", "<ui:UiBinder>", " <g:HorizontalPanel>", " <g:Cell>", " <g:Button wbp:name='button'/>", " </g:Cell>", " </g:HorizontalPanel>", "</ui:UiBinder>"); refresh(); WidgetInfo button = getObjectByName("button"); // "horizontalAlignment" { Property property = PropertyUtils.getByPath(button, "Cell/horizontalAlignment"); // no value initially assertFalse(property.isModified()); assertEquals("ALIGN_LEFT", getPropertyText(property)); // check items { addComboPropertyItems(property); List<String> items = getComboPropertyItems(); assertThat(items).containsExactly("ALIGN_LEFT", "ALIGN_CENTER", "ALIGN_RIGHT"); } // set value setComboPropertyValue(property, 1); assertXML( "// filler filler filler filler filler", "<ui:UiBinder>", " <g:HorizontalPanel>", " <g:Cell horizontalAlignment='ALIGN_CENTER'>", " <g:Button wbp:name='button'/>", " </g:Cell>", " </g:HorizontalPanel>", "</ui:UiBinder>"); // has value assertTrue(property.isModified()); assertEquals("ALIGN_CENTER", getPropertyText(property)); } }
public void test_propertyCell_noElement() throws Exception { parse( "// filler filler filler filler filler", "<ui:UiBinder>", " <g:HorizontalPanel>", " <g:Button wbp:name='button'/>", " </g:HorizontalPanel>", "</ui:UiBinder>"); refresh(); WidgetInfo button = getObjectByName("button"); // "width" { Property property = PropertyUtils.getByPath(button, "Cell/width"); // no value assertFalse(property.isModified()); assertEquals(Property.UNKNOWN_VALUE, property.getValue()); // set value, materialize "Cell" property.setValue("100px"); assertXML( "// filler filler filler filler filler", "<ui:UiBinder>", " <g:HorizontalPanel>", " <g:Cell width='100px'>", " <g:Button wbp:name='button'/>", " </g:Cell>", " </g:HorizontalPanel>", "</ui:UiBinder>"); // has value assertTrue(property.isModified()); assertEquals("100px", property.getValue()); } }
//////////////////////////////////////////////////////////////////////////// // // Cell property // //////////////////////////////////////////////////////////////////////////// public void test_propertyCell_existingElement() throws Exception { parse( "// filler filler filler filler filler", "<ui:UiBinder>", " <g:HorizontalPanel>", " <g:Cell>", " <g:Button wbp:name='button'/>", " </g:Cell>", " </g:HorizontalPanel>", "</ui:UiBinder>"); refresh(); WidgetInfo button = getObjectByName("button"); // get "Cell" property { Property cellProperty = button.getPropertyByTitle("Cell"); assertNotNull(cellProperty); assertTrue(cellProperty.getCategory().isSystem()); } // "width" { Property property = PropertyUtils.getByPath(button, "Cell/width"); // no value initially assertFalse(property.isModified()); assertEquals(Property.UNKNOWN_VALUE, property.getValue()); // set value property.setValue("100px"); assertXML( "// filler filler filler filler filler", "<ui:UiBinder>", " <g:HorizontalPanel>", " <g:Cell width='100px'>", " <g:Button wbp:name='button'/>", " </g:Cell>", " </g:HorizontalPanel>", "</ui:UiBinder>"); // has value assertTrue(property.isModified()); assertEquals("100px", property.getValue()); } }
public void test_hasUiConstructor() throws Exception { dontUseSharedGWTState(); setFileContentSrc( "test/client/MyButton.java", getJavaSource( "import com.google.gwt.uibinder.client.UiConstructor;", "// filler filler filler filler filler", "// filler filler filler filler filler", "public class MyButton extends Button {", " @UiConstructor", " public MyButton(int foo, String bar) {", " }", "}")); waitForAutoBuild(); // parse parse( "// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>", " <g:FlowPanel>", " <t:MyButton wbp:name='button' foo='1' bar='abc'/>", " </g:FlowPanel>", "</ui:UiBinder>"); refresh(); WidgetInfo button = getObjectByName("button"); // "foo" { Property fooProperty = PropertyUtils.getByPath(button, "UiConstructor/foo"); assertNotNull(fooProperty); assertNotNull(fooProperty.getEditor()); assertEquals(1, fooProperty.getValue()); } // "bar" { Property barProperty = PropertyUtils.getByPath(button, "UiConstructor/bar"); assertNotNull(barProperty); assertNotNull(barProperty.getEditor()); assertEquals("abc", barProperty.getValue()); } }
/** @return the text for current color value. */ @Override public String getText(Property property) throws Exception { return (String) property.getValue(); }