Package com.google.gdt.eclipse.designer.model.property.accessor

Examples of com.google.gdt.eclipse.designer.model.property.accessor.CellExpressionAccessor


        ClassLoader editorLoader = JavaInfoUtils.getClassLoader(panel);
        // "width"
        GenericPropertyImpl widthProperty;
        {
          ExpressionAccessor expressionAccessor =
              new CellExpressionAccessor(panel, "setCellWidth", "java.lang.String");
          widthProperty =
              new GenericPropertyImpl(component,
                  "width",
                  new ExpressionAccessor[]{expressionAccessor},
                  "",
                  StringConverter.INSTANCE,
                  StringPropertyEditor.INSTANCE);
        }
        // "height"
        GenericPropertyImpl heightProperty;
        {
          ExpressionAccessor expressionAccessor =
              new CellExpressionAccessor(panel, "setCellHeight", "java.lang.String");
          heightProperty =
              new GenericPropertyImpl(component,
                  "height",
                  new ExpressionAccessor[]{expressionAccessor},
                  "",
                  StringConverter.INSTANCE,
                  StringPropertyEditor.INSTANCE);
        }
        // "horizontalAlignment"
        GenericPropertyImpl horizontalAlignmentProperty;
        {
          StaticFieldPropertyEditor propertyEditor = new StaticFieldPropertyEditor();
          Class<?> hasHorizontalAlignmentClass =
              editorLoader.loadClass("com.google.gwt.user.client.ui.HasHorizontalAlignment");
          ExpressionAccessor expressionAccessor =
              new CellExpressionAccessor(panel,
                  "setCellHorizontalAlignment",
                  "com.google.gwt.user.client.ui.HasHorizontalAlignment.HorizontalAlignmentConstant");
          propertyEditor.configure(hasHorizontalAlignmentClass, new String[]{
              "ALIGN_LEFT",
              "ALIGN_CENTER",
              "ALIGN_RIGHT",
              "ALIGN_DEFAULT"});
          Object defaultValue =
              ReflectionUtils.getFieldObject(hasHorizontalAlignmentClass, "ALIGN_DEFAULT");
          horizontalAlignmentProperty =
              new GenericPropertyImpl(component,
                  "horizontalAlignment",
                  new ExpressionAccessor[]{expressionAccessor},
                  defaultValue,
                  null,
                  propertyEditor);
        }
        // "verticalAlignment"
        GenericPropertyImpl verticalAlignmentProperty;
        {
          StaticFieldPropertyEditor propertyEditor = new StaticFieldPropertyEditor();
          Class<?> hasVerticalAlignmentClass =
              editorLoader.loadClass("com.google.gwt.user.client.ui.HasVerticalAlignment");
          propertyEditor.configure(hasVerticalAlignmentClass, new String[]{
              "ALIGN_TOP",
              "ALIGN_MIDDLE",
              "ALIGN_BOTTOM"});
          ExpressionAccessor expressionAccessor =
              new CellExpressionAccessor(panel,
                  "setCellVerticalAlignment",
                  "com.google.gwt.user.client.ui.HasVerticalAlignment.VerticalAlignmentConstant");
          Object defaultValue =
              ReflectionUtils.getFieldObject(hasVerticalAlignmentClass, "ALIGN_TOP");
          verticalAlignmentProperty =
View Full Code Here


            "}");
    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));
  }
View Full Code Here

TOP

Related Classes of com.google.gdt.eclipse.designer.model.property.accessor.CellExpressionAccessor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.