/*
     * (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;
    }
 @Override
 public boolean applicable(final ServiceContext context, final Class<? extends Service> service) {
   final ValueProperty property = context.find(ValueProperty.class);
   final IModelElement element = context.find(IModelElement.class);
   return (property != null
       && property.hasAnnotation(NoDuplicates.class)
       && element.parent() instanceof ModelElementList);
 }
  /*
   * (non-Javadoc)
   * @see org.eclipse.sapphire.services.RelativePathService#roots()
   */
  @Override
  public List<Path> roots() {
    List<Path> roots = new ArrayList<Path>();
    IModelElement modelElement = context(IHook.class);
    IProject project = modelElement.adapt(IProject.class);
    IFolder[] folders = ProjectUtil.getSourceFolders(project);

    for (IFolder folder : folders) {
      roots.add(new Path(folder.getLocation().toPortableString()));
    }

    return roots;
  }
    @Override
    public void init(SapphireAction action, ISapphireActionHandlerDef def) {
      super.init(action, def);
      final IModelElement rootModel = action.getPart().getModelElement();
      final ModelProperty modelProperty =
          rootModel.getModelElementType().getProperty(this.strModelProperty);

      String labelText = modelProperty.getLabel(false, CapitalizationType.FIRST_WORD_ONLY, true);
      String actionLabel = getActionLabel(labelText);
      setLabel(actionLabel);

      ModelElementType propModelElementType = modelProperty.getType();
      addImage(propModelElementType.image());
    }
예제 #5
0
 private ShapeFactoryCaseDef getShapeFactoryCase(IModelElement listEntryModelElement) {
   for (ShapeFactoryCaseDef shapeFactoryCase : this.shapeFactoryDef.getCases()) {
     JavaType javaType = shapeFactoryCase.getType().resolve();
     Class<?> cl = javaType.artifact();
     if (cl.isAssignableFrom(listEntryModelElement.getClass())) {
       return shapeFactoryCase;
     }
   }
   return null;
 }
예제 #6
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));
      }
    }
  }
  @Override
  protected void initEnablementService() {
    final IModelElement element = context(IModelElement.class);

    IModelParticle parent = element.parent();

    if (!(parent instanceof IModelElement)) {
      parent = parent.parent();
    }

    this.parentElement = (IModelElement) parent;
    this.parentProperty = element.getParentProperty();

    this.listener =
        new FilteredListener<PropertyEnablementEvent>() {
          @Override
          protected void handleTypedEvent(final PropertyEnablementEvent event) {
            refresh();
          }
        };

    this.parentElement.attach(this.listener, this.parentProperty);
  }