Пример #1
0
 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());
   }
 }
Пример #2
0
 /** 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());
   }
 }
Пример #3
0
 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);
       }
     }
   }
 }
 /** @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;
 }
Пример #5
0
 ////////////////////////////////////////////////////////////////////////////
 //
 // 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());
   }
 }
Пример #6
0
 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());
   }
 }
Пример #7
0
 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);
 }
Пример #11
0
 /** @return the text for current color value. */
 @Override
 public String getText(Property property) throws Exception {
   return (String) property.getValue();
 }