コード例 #1
0
    /*
     * (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;
    }
コード例 #2
0
  private void handleModelPropertyChange(final PropertyEvent event) {
    final IModelElement element = event.element();
    final ModelProperty property = event.property();
    ModelElementList<IModelElement> newList =
        (ModelElementList<IModelElement>) element.read(property);

    List<ShapePart> children = getChildren();
    List<IModelElement> oldList = new ArrayList<IModelElement>(children.size());
    for (ShapePart shapePart : children) {
      oldList.add(shapePart.getLocalModelElement());
    }

    List<IModelElement> deletedShapes = ListUtil.ListDiff(oldList, newList);
    List<IModelElement> newShapes = ListUtil.ListDiff(newList, oldList);
    if (deletedShapes.isEmpty() && newShapes.isEmpty() && ListUtil.ListDiffers(oldList, newList)) {
      // List has been re-ordered
      List<ShapePart> newChildren = new ArrayList<ShapePart>();
      for (IModelElement listEle : newList) {
        ShapePart shapePart = getShapePart(listEle);
        newChildren.add(shapePart);
      }
      this.children.clear();
      this.children.addAll(newChildren);
      broadcast(new ShapeReorderEvent(this));
    } else {
      for (IModelElement deletedShape : deletedShapes) {
        ShapePart shapePart = getShapePart(deletedShape);
        if (shapePart != null) {
          shapePart.dispose();
          this.children.remove(shapePart);
          broadcast(new ShapeDeleteEvent(shapePart));
        }
      }
      for (IModelElement newShape : newShapes) {
        ShapeFactoryCaseDef shapeFactoryCase = getShapeFactoryCase(newShape);

        ShapePart shapePart = createShapePart(shapeFactoryCase, newShape);
        this.children.add(shapePart);
        broadcast(new ShapeAddEvent(shapePart));
      }
    }
  }