/*
     * (non-Javadoc)
     * @see org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.SapphireRenderingContext)
     */
    @Override
    protected Object run(SapphireRenderingContext context) {

      final IModelElement rootModel = context.getPart().getModelElement();
      final ModelProperty modelProperty =
          rootModel.getModelElementType().getProperty(this.strModelProperty);
      Object obj = rootModel.read(modelProperty);
      IModelElement mElement = null;

      if (obj instanceof ModelElementList<?>) {
        // System.out.println( "QuickActionsHandlerFactory.Handler.run()" + obj.getClass() );
        ModelElementList<?> list = (ModelElementList<?>) obj;
        mElement = list.addNewElement();
      } else {
        throw new UnsupportedOperationException(
            Resources.bind(Resources.unsuportedOperation, this.strModelProperty));
      }

      // Select the ndoe
      final MasterDetailsEditorPagePart page = getPart().nearest(MasterDetailsEditorPagePart.class);
      final MasterDetailsContentNode root = page.getContentOutline().getRoot();
      final MasterDetailsContentNode node = root.findNodeByModelElement(mElement);
      if (node != null) {
        node.select();
      }

      return mElement;
    }
 public void moveChild(ShapePart childPart, int newIndex) {
   ModelElementList<IModelElement> list = this.modelElement.read(this.modelProperty);
   int oldIndex = list.indexOf(childPart.getLocalModelElement());
   this.modelElement.detach(this.shapePropertyListener, this.propertyName);
   if (oldIndex < newIndex) {
     for (int i = oldIndex; i < newIndex; i++) {
       list.moveDown(childPart.getLocalModelElement());
     }
   } else {
     for (int i = newIndex; i < oldIndex; i++) {
       list.moveUp(childPart.getLocalModelElement());
     }
   }
   this.modelElement.attach(this.shapePropertyListener, this.propertyName);
   this.children.remove(childPart);
   this.children.add(newIndex, childPart);
   broadcast(new ShapeReorderEvent(this));
 }
  public void testWithModelElementList() {
    final TestModelRoot root = TestModelRoot.TYPE.instantiate();
    final ModelElementList<TestModelElementA> list = root.getList1();
    final FunctionContext context = new ModelElementFunctionContext(root);

    TestModelElementA a;

    testForExpectedValue(context, "${ Avg( List1 ) }", new BigDecimal("0"));
    testForExpectedValue(context, "${ Avg( List1, 'Value1' ) }", new BigDecimal("0"));
    testForExpectedValue(context, "${ Avg( List1, 'Value2' ) }", new BigDecimal("0"));

    a = list.insert();
    a.setValue1("1");
    a.setValue2(2);

    testForExpectedValue(context, "${ Avg( List1 ) }", new BigDecimal("1"));
    testForExpectedValue(context, "${ Avg( List1, 'Value1' ) }", new BigDecimal("1"));
    testForExpectedValue(context, "${ Avg( List1, 'Value2' ) }", new BigDecimal("2"));

    a = list.insert();
    a.setValue1("2");
    a.setValue2(3);

    a = list.insert();
    a.setValue1("3.5");
    a.setValue2(4);

    testForExpectedValue(context, "${ Avg( List1 ) }", new BigDecimal("2.2"));
    testForExpectedValue(context, "${ Avg( List1, 'Value1' ) }", new BigDecimal("2.2"));
    testForExpectedValue(context, "${ Avg( List1, 'Value2' ) }", new BigDecimal("3"));

    testForExpectedError(
        context, "${ Avg( List1, 'abc' ) }", "Property TestModelElementA.abc could not be found.");
    testForExpectedError(
        context,
        "${ Avg( List1, 'Element1' ) }",
        "Property TestModelElementA.Element1 is not a value property.");
    testForExpectedError(
        context,
        "${ Avg( List2 ) }",
        "Element type TestModelElementB does not contain a value property.");

    final FunctionResult result =
        ExpressionLanguageParser.parse("${ Avg( List1, 'Value1' ) }").evaluate(context);

    assertEquals(new BigDecimal("2.2"), result.value());

    list.get(0).setValue1("2");
    list.get(1).setValue1("3.5");

    assertEquals(new BigDecimal("3.0"), result.value());

    a = list.insert();
    a.setValue1("5.2");

    assertEquals(new BigDecimal("3.6"), result.value());
  }
 public ShapePart newShape(JavaType javaType) {
   ModelElementList<?> list = this.modelElement.read(this.modelProperty);
   final Class cl = javaType.artifact();
   IModelElement element = list.insert(cl);
   return getShapePart(element);
 }