コード例 #1
0
  public PictogramElement add(IAddContext context) {
    IAddConnectionContext addConContext = (IAddConnectionContext) context;
    EActionLink addedEReference = (EActionLink) context.getNewObject();
    IPeCreateService peCreateService = Graphiti.getPeCreateService();

    // CONNECTION WITH POLYLINE
    Connection connection = peCreateService.createFreeFormConnection(getDiagram());
    connection.setStart(addConContext.getSourceAnchor());
    connection.setEnd(addConContext.getTargetAnchor());

    IGaService gaService = Graphiti.getGaService();
    Polyline polyline = gaService.createPolyline(connection);
    polyline.setLineWidth(3);
    polyline.setForeground(manageColor(IColorConstant.LIGHT_ORANGE));

    // create link and wire it
    link(connection, addedEReference);

    // add dynamic text decorator for the association name
    ConnectionDecorator textDecorator =
        peCreateService.createConnectionDecorator(connection, true, 0.5, true);
    Text text = gaService.createText(textDecorator);
    // createDefaultText(textDecorator);
    text.setForeground(manageColor(IColorConstant.BLACK));
    gaService.setLocation(text, 10, 0);
    text.setValue("has the action");

    return connection;
  }
コード例 #2
0
    private static void updateSPPFigure(SPPRef spp, PictogramElement pe, Color dark, Color bright) {
      ContainerShape container = (ContainerShape) pe;

      // we clear the figure and rebuild it
      GraphicsAlgorithm invisibleRect = pe.getGraphicsAlgorithm();
      invisibleRect.getGraphicsAlgorithmChildren().clear();

      createSPPFigure(spp, false, container, invisibleRect, dark, bright);

      GraphicsAlgorithm ga = container.getChildren().get(0).getGraphicsAlgorithm();
      if (ga instanceof Text) {
        ((Text) ga).setValue(spp.getName());
      }
    }
コード例 #3
0
  public boolean update(IUpdateContext context) {
    // retrieve name from business model
    String businessName = null;
    PictogramElement pictogramElement = context.getPictogramElement();
    Object bo = getBusinessObjectForPictogramElement(pictogramElement);
    if (bo instanceof EClass) {
      EClass eClass = (EClass) bo;
      businessName = eClass.getName();
    }

    // Set name in pictogram model
    if (pictogramElement instanceof ContainerShape) {
      ContainerShape cs = (ContainerShape) pictogramElement;
      for (Shape shape : cs.getChildren()) {
        if (shape.getGraphicsAlgorithm() instanceof Text) {
          Text text = (Text) shape.getGraphicsAlgorithm();
          text.setValue(businessName);
          return true;
        }
      }
    }

    return false;
  }
コード例 #4
0
  @Override
  public PictogramElement add(IAddContext context) {
    // TODO Auto-generated method stub
    IAddConnectionContext addConContext = (IAddConnectionContext) context;
    AdviceEdge edge = (AdviceEdge) context.getNewObject();
    IPeCreateService peCreateService = Graphiti.getPeCreateService();

    Connection connection = peCreateService.createFreeFormConnection(getDiagram());
    connection.setStart(addConContext.getSourceAnchor());
    connection.setEnd(addConContext.getTargetAnchor());

    IGaService gaService = Graphiti.getGaService();
    Polyline polyline = gaService.createPlainPolyline(connection);
    polyline.setStyle(StyleUtil.getStyleForElement(getDiagram()));
    polyline.setLineStyle(LineStyle.DOT);

    link(connection, edge);

    // add dynamic text decorator for the reference name
    ConnectionDecorator textDecorator =
        peCreateService.createConnectionDecorator(connection, true, 0.5, true);
    Text text = gaService.createPlainText(textDecorator);
    text.setStyle(StyleUtil.getStyleForTextDecorator((getDiagram())));
    gaService.setLocation(text, 10, 0);

    text.setValue(edge.getAdvicetype().toString());

    ConnectionDecorator cd;
    cd = peCreateService.createConnectionDecorator(connection, false, 1.0, true);
    int[] xy = {getPointCutR() * 2, 0, 0, -getPointCutR() * 2, 0, 0, 0, getPointCutR() * 2};
    Polygon polygon = Graphiti.getGaCreateService().createPolygon(cd, xy);
    polygon.setStyle(StyleUtil.getStyleForElement(getDiagram()));
    polygon.setLineStyle(LineStyle.DOT);

    return connection;
  }
コード例 #5
0
  @Override
  public boolean update(IUpdateContext context) {
    _hasDoneChanges = false;

    // retrieve name from business model
    ContainerShape cs = (ContainerShape) context.getPictogramElement();
    Reference reference = (Reference) getBusinessObjectForPictogramElement(cs);

    // remove it if it's gone
    if (!GraphitiInternal.getEmfService().isObjectAlive(reference)) {
      IRemoveContext removeContext = new RemoveContext(context.getPictogramElement());
      final IRemoveFeature removeFeature = getFeatureProvider().getRemoveFeature(removeContext);
      if (removeFeature != null && removeFeature.canRemove(removeContext)) {
        removeFeature.remove(removeContext);
        _hasDoneChanges = removeFeature.hasDoneChanges();
        return true;
      }
    }

    // Set name in pictogram model
    String pictogramName = null;
    Text foundText = GraphitiUtil.findChildGA(cs.getGraphicsAlgorithm(), Text.class);
    if (foundText != null) {
      pictogramName = foundText.getValue();
    }
    String businessName = reference.getName();
    boolean updateNameNeeded =
        ((pictogramName == null && businessName != null)
            || (pictogramName != null && !pictogramName.contentEquals(businessName)));
    if (updateNameNeeded) {
      foundText.setValue(businessName);
      _hasDoneChanges = true;
    }

    // update the wires
    final Set<Contract> existingConnections = getExistingConnections(cs);
    final Anchor anchor = cs.getAnchors().get(0);
    for (ComponentReference promotedReference : reference.getPromote()) {
      if (promotedReference != null && !existingConnections.remove(promotedReference)) {
        for (PictogramElement pe :
            getFeatureProvider().getAllPictogramElementsForBusinessObject(promotedReference)) {
          if (pe instanceof Anchor) {
            AddConnectionContext addContext = new AddConnectionContext((Anchor) pe, anchor);
            addContext.setNewObject(reference);
            updatePictogramElement(getFeatureProvider().addIfPossible(addContext));
            _hasDoneChanges = true;
            break;
          }
        }
      }
    }

    for (Connection connection : new ArrayList<Connection>(anchor.getIncomingConnections())) {
      Object bo = getBusinessObjectForPictogramElement(connection.getStart());
      if (bo == null || existingConnections.remove(bo)) {
        RemoveContext removeContext = new RemoveContext(connection);
        IRemoveFeature removeFeature = getFeatureProvider().getRemoveFeature(removeContext);
        if (removeFeature.canExecute(removeContext)) {
          removeFeature.execute(removeContext);
          _hasDoneChanges = _hasDoneChanges || removeFeature.hasDoneChanges();
        }
      }
    }

    return _hasDoneChanges;
  }