public static void removeMessageFlow(
      TransactionalEditingDomain editingDomain,
      Message event,
      AbstractCatchMessageEvent target,
      DiagramEditPart dep) {

    EditPart ep = findEditPart(dep, target);
    CompositeCommand command = new CompositeCommand("Remove MessageFlows");

    for (Object connection : ((AbstractGraphicalEditPart) ep).getTargetConnections()) {
      if (connection instanceof MessageFlowEditPart) {
        MessageFlowEditPart connectionPart = (MessageFlowEditPart) connection;
        MessageFlow flow = (MessageFlow) connectionPart.resolveSemanticElement();
        SetCommand c =
            new SetCommand(
                editingDomain,
                flow.getTarget(),
                ProcessPackage.Literals.ABSTRACT_CATCH_MESSAGE_EVENT__EVENT,
                null);
        editingDomain.getCommandStack().execute(c);
        command.add(new DeleteCommand(editingDomain, connectionPart.getPrimaryView()));
        DestroyElementRequest req =
            new DestroyElementRequest(
                editingDomain, connectionPart.resolveSemanticElement(), false);
        DestroyElementCommand rmComd = new DestroyElementCommand(req);
        command.add(rmComd);
      }
    }

    dep.getDiagramEditDomain()
        .getDiagramCommandStack()
        .execute(new ICommandProxy(command.reduce()));
    dep.getDiagramEditDomain().getDiagramCommandStack().flush();
    dep.refresh();
  }
  public static void createMessageFlow(
      TransactionalEditingDomain editingDomain,
      Message event,
      ThrowMessageEvent source,
      AbstractCatchMessageEvent target,
      DiagramEditPart dep) {
    EditPart targetEP = findEditPart(dep, target);
    EditPart sourceEP = findEditPart(dep, source);

    CreateConnectionViewAndElementRequest request =
        new CreateConnectionViewAndElementRequest(
            ProcessElementTypes.MessageFlow_4002,
            ((IHintedType) ProcessElementTypes.MessageFlow_4002).getSemanticHint(),
            dep.getDiagramPreferencesHint());
    Command createMessageFlowCommand =
        CreateConnectionViewAndElementRequest.getCreateCommand(request, sourceEP, targetEP);
    if (createMessageFlowCommand.canExecute()) {
      dep.getDiagramEditDomain().getDiagramCommandStack().execute(createMessageFlowCommand);
      dep.getDiagramEditDomain().getDiagramCommandStack().flush();
      dep.refresh();

      ConnectionViewAndElementDescriptor desc =
          (ConnectionViewAndElementDescriptor) request.getNewObject();
      MessageFlow message = (MessageFlow) desc.getElementAdapter().getAdapter(MessageFlow.class);
      SetCommand setCommand =
          new SetCommand(
              editingDomain, message, ProcessPackage.Literals.ELEMENT__NAME, event.getName());
      editingDomain.getCommandStack().execute(setCommand);
    }
  }
 /**
  * {@inheritDoc}
  *
  * @see org.eclipse.jface.viewers.ColumnLabelProvider#getImage(java.lang.Object)
  */
 @Override
 public Image getImage(Object element) {
   Image result = null;
   if (columnIndex == 0 && diagramPart != null) {
     final DiagramEditPart diaEditPart = diagramPart.getDiagramEditPart();
     final Object obj = diaEditPart.getModel();
     if (obj instanceof View) {
       final EObject designerElement = ((View) obj).getElement();
       if (designerElement instanceof DDiagram) {
         final List<Layer> activatedLayers = ((DDiagram) designerElement).getActivatedLayers();
         Image img = null;
         if (EqualityHelper.contains(activatedLayers, (EObject) element)) {
           img = DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.ACTIVE_LAYER_ICON);
         } else {
           img =
               DiagramUIPlugin.getPlugin().getBundledImage(DiagramImagesPath.INACTIVE_LAYER_ICON);
         }
         result = img;
       }
     }
   } else if (columnIndex == 1) {
     if (element instanceof Layer) {
       Layer layer = (Layer) element;
       if (!StringUtil.isEmpty(layer.getIcon())) {
         result = ImageProvider.getImageFromPath(layer.getIcon());
       }
     }
   }
   return result;
 }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
   * org.eclipse.core.runtime.IAdaptable)
   */
  @Override
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {
    if (diagramEP != null && getEditingDomain() != null) {
      diagramEP.refresh();
      Namespace context = constraint.getContext();
      Collection<EditPart> allTopSemanticEditPart =
          DiagramEditPartsUtil.getAllTopSemanticEditPart(diagramEP);
      EditPart constraintEditPart = getEditPart(constraint, allTopSemanticEditPart);
      EditPart contextEditPart = getEditPart(context, allTopSemanticEditPart);

      if (constraintEditPart != null && contextEditPart != null) {
        Collection<EditPart> constraintAndContext = new ArrayList<EditPart>();
        constraintAndContext.add(constraintEditPart);
        constraintAndContext.add(contextEditPart);
        final Request request =
            new ShowHideRelatedLinkRequest(
                constraintAndContext, ShowHideKind.SHOW_ALL_LINK_BETWEEN_SELECTED_ELEMENT);
        final Command cmd = diagramEP.getCommand(request);
        if (cmd != null) {
          cmd.execute();
        }
      }
    }
    return null;
  }
  public void createObject(int x, int y) {
    if (availableForInsert && this.entry != null) {
      updateCursor(false);
      availableForInsert = false;
      switch (this.entry.getType()) {
        case TRIGGER_BLOCK:
        case CUSTOM_BLOCK:
          CreateUnspecifiedTypeRequest request =
              new CreateUnspecifiedTypeRequest(
                  Collections.singletonList(Neuro4jElementTypes.LogicNode_2017),
                  diagramEditPart.getDiagramPreferencesHint());

          request.setLocation(new Point(x, y));
          Command command = diagramEditPart.getCommand(request);
          command.execute();
          List newObject = (List) request.getNewObject();
          ViewAndElementDescriptor desc = (ViewAndElementDescriptor) newObject.get(0);
          ShapeImpl shape = (ShapeImpl) desc.getAdapter(ShapeImpl.class);
          LogicNode lNode = (LogicNode) shape.getElement();
          updateCustomBlock(lNode, this.entry);
          break;

        case CHILD:
          if (entry.getParent().getType() != ListEntryType.FLOW) {
            return;
          }
          request =
              new CreateUnspecifiedTypeRequest(
                  Collections.singletonList(Neuro4jElementTypes.CallNode_2008),
                  diagramEditPart.getDiagramPreferencesHint());

          request.setLocation(new Point(x, y));
          command = diagramEditPart.getCommand(request);
          command.execute();
          newObject = (List) request.getNewObject();
          desc = (ViewAndElementDescriptor) newObject.get(0);
          shape = (ShapeImpl) desc.getAdapter(ShapeImpl.class);
          CallNode cNode = (CallNode) shape.getElement();

          updateCallBlock(cNode, entry);

          break;

        default:
          break;
      }
      this.entry = null;
    }
  }
  private void updateCallBlock(final CallNode node, final ListEntry entry) {

    final TransactionalEditingDomain editingDomain =
        TransactionUtil.getEditingDomain(diagramEditPart.getModel());

    AbstractTransactionalCommand command =
        new AbstractTransactionalCommand(editingDomain, "Update CallNode", Collections.EMPTY_LIST) {
          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {

            String startNode = entry.getMessage();
            ListEntry parent = entry.getParent();
            String callFlow = parent.getMessage() + "-" + startNode;
            node.setName(callFlow.substring(callFlow.lastIndexOf("-") + 1));
            node.setFlowName(callFlow);

            return CommandResult.newOKCommandResult();
          }
        };

    try {
      OperationHistoryFactory.getOperationHistory()
          .execute(command, new SubProgressMonitor(new NullProgressMonitor(), 1), null);
    } catch (ExecutionException e) {
      Neuro4jDiagramEditorPlugin.getInstance()
          .logError("Unable to update call node", e); // $NON-NLS-1$
    }
  }
 /** @generated */
 protected void createDefaultEditPolicies() {
   super.createDefaultEditPolicies();
   installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ComponentDiagramItemSemanticEditPolicy());
   installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new ComponentDiagramCanonicalEditPolicy());
   installEditPolicy(
       EditPolicyRoles.CREATION_ROLE,
       new CreationEditPolicyWithCustomReparent(MultisimVisualIDRegistry.TYPED_INSTANCE));
   // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.POPUPBAR_ROLE);
 }
Esempio n. 8
0
 /**
  * Instantiates a new model adapter.
  *
  * @param diagramEditPart the diagram edit part
  * @param attributes the attributes
  * @param propertyProvider the property provider
  */
 public ModelAdapter(
     DiagramEditPart diagramEditPart,
     Map<String, String> attributes,
     IInterchangePropertyProvider propertyProvider) {
   super();
   this.diagramEditPart = diagramEditPart;
   this.eObject = diagramEditPart.resolveSemanticElement();
   this.attributeMap = (attributes == null ? new HashMap<String, String>() : attributes);
   this.propertyProvider = propertyProvider;
 }
 @Override
 protected Request createTargetRequest() {
   // DirectEditRequest request = new DirectEditRequest();
   EPackage epackage =
       org.eclipse.emf.ecore.EPackage.Registry.INSTANCE.getEPackage("http://vespucci.editor");
   Vespucci_modelPackage vesPackage = (Vespucci_modelPackage) epackage;
   IElementType elementType =
       ElementTypeRegistry.getInstance().getElementType(vesPackage.getEnsemble());
   // TODO is there a way to get VespucciElementTypes.Ensemble_2001 over a methode call?
   elementType = VespucciElementTypes.Ensemble_2001;
   // Get the selected edit part
   EditPart epart = getTargetEditPart();
   if (epart == null)
     return new CreateViewRequest(new CreateViewRequest.ViewDescriptor(null, null));
   // GraphicalEditPart p = (GraphicalEditPart) epart;
   DiagramEditPart p = (DiagramEditPart) epart;
   CreateViewRequest request =
       CreateViewRequestFactory.getCreateShapeRequest(elementType, p.getDiagramPreferencesHint());
   request.setType(REQ_DROPNEWENSEMBLE);
   return request;
 }
 /** @param input */
 private void setInput(Object input) {
   Diagram diagram = null;
   if (input instanceof Pageflow) {
     Pageflow pageflow = (Pageflow) input;
     diagram = fetchDiagram(pageflow.eResource());
   } else if (input instanceof Diagram) {
     diagram = (Diagram) input;
   } else if (input instanceof Resource) {
     Resource res = (Resource) input;
     diagram = fetchDiagram(res);
   } else if (input instanceof ResourceSet) {
     Resource res = ((ResourceSet) input).getResources().get(0);
     diagram = fetchDiagram(res);
   } else if (input instanceof List) {
     Resource res = (Resource) ((List<?>) input).get(0);
     diagram = fetchDiagram(res);
   }
   if (diagram != null) {
     TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain(
         diagram.eResource().getResourceSet());
     RootEditPart rootEP = EditPartService.getInstance().createRootEditPart(diagram);
     if (rootEP instanceof DiagramRootEditPart) {
       ((DiagramRootEditPart) rootEP)
           .setPreferencesHint(PageflowDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
     }
     viewer.setRootEditPart(rootEP);
     viewer.setEditPartFactory(new PageflowEditPartFactory());
     viewer.setContents(diagram);
     viewer.flush();
     if (viewer.getContents() instanceof DiagramEditPart) {
       DiagramEditPart dp = (DiagramEditPart) viewer.getContents();
       dp.disableEditMode();
     }
   }
   return;
 }
  /** @generated */
  public static View findView(
      DiagramEditPart diagramEditPart,
      EObject targetElement,
      LazyElement2ViewMap lazyElement2ViewMap) {
    boolean hasStructuralURI = false;
    if (targetElement.eResource() instanceof XMLResource) {
      hasStructuralURI = ((XMLResource) targetElement.eResource()).getID(targetElement) == null;
    }

    View view = null;
    LinkedList<EditPart> editPartHolder = new LinkedList<EditPart>();
    if (hasStructuralURI && !lazyElement2ViewMap.getElement2ViewMap().isEmpty()) {
      view = lazyElement2ViewMap.getElement2ViewMap().get(targetElement);
    } else if (findElementsInDiagramByID(diagramEditPart, targetElement, editPartHolder) > 0) {
      EditPart editPart = editPartHolder.get(0);
      view = editPart.getModel() instanceof View ? (View) editPart.getModel() : null;
    }

    return (view == null) ? diagramEditPart.getDiagramView() : view;
  }
  /** @generated */
  private static int findElementsInDiagramByID(
      DiagramEditPart diagramPart, EObject element, List<EditPart> editPartCollector) {
    IDiagramGraphicalViewer viewer = (IDiagramGraphicalViewer) diagramPart.getViewer();
    final int intialNumOfEditParts = editPartCollector.size();

    if (element instanceof View) { // support notation element lookup
      EditPart editPart = (EditPart) viewer.getEditPartRegistry().get(element);
      if (editPart != null) {
        editPartCollector.add(editPart);
        return 1;
      }
    }

    String elementID = EMFCoreUtil.getProxyID(element);
    @SuppressWarnings("unchecked")
    List<EditPart> associatedParts =
        viewer.findEditPartsForElement(elementID, IGraphicalEditPart.class);
    // perform the possible hierarchy disjoint -> take the top-most parts only
    for (EditPart nextPart : associatedParts) {
      EditPart parentPart = nextPart.getParent();
      while (parentPart != null && !associatedParts.contains(parentPart)) {
        parentPart = parentPart.getParent();
      }
      if (parentPart == null) {
        editPartCollector.add(nextPart);
      }
    }

    if (intialNumOfEditParts == editPartCollector.size()) {
      if (!associatedParts.isEmpty()) {
        editPartCollector.add(associatedParts.get(0));
      } else {
        if (element.eContainer() != null) {
          return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector);
        }
      }
    }
    return editPartCollector.size() - intialNumOfEditParts;
  }
  public static void removeMessageFlow(
      TransactionalEditingDomain editingDomain,
      Message event,
      ThrowMessageEvent source,
      DiagramEditPart dep) {
    EditPart ep = findEditPart(dep, source);
    CompositeCommand command = new CompositeCommand("Remove MessageFlows");

    for (Object connection : ((AbstractGraphicalEditPart) ep).getSourceConnections()) {
      if (connection instanceof MessageFlowEditPart) {
        MessageFlowEditPart connectionPart = (MessageFlowEditPart) connection;
        MessageFlow flow = (MessageFlow) connectionPart.resolveSemanticElement();
        if (flow.getTarget().getEvent() == null
            || flow.getTarget().getEvent().equals(event.getName())) {
          List<Message> events = new ArrayList<Message>();
          ModelHelper.findAllEvents(source, events);
          for (Message ev : events) {
            if (ev.eContainer().equals(source) && !ev.equals(event)) {
              if (ev.getTargetProcessExpression() != null
                  && event.getTargetProcessExpression() != null
                  && ev.getTargetProcessExpression()
                      .getContent()
                      .equals(event.getTargetProcessExpression().getContent())
                  && ev.getTargetElementExpression() != null
                  && ev.getTargetElementExpression().getContent() != null
                  && event.getTargetElementExpression() != null
                  && ev.getTargetElementExpression()
                      .getContent()
                      .equals(event.getTargetElementExpression().getContent())) {
                SetCommand setCommand =
                    new SetCommand(
                        editingDomain,
                        ev,
                        ProcessPackage.Literals.MESSAGE__TARGET_PROCESS_EXPRESSION,
                        null);
                editingDomain.getCommandStack().execute(setCommand);
                setCommand =
                    new SetCommand(
                        editingDomain,
                        ev,
                        ProcessPackage.Literals.MESSAGE__TARGET_ELEMENT_EXPRESSION,
                        null);
                editingDomain.getCommandStack().execute(setCommand);
              }
            }
          }
          SetCommand c =
              new SetCommand(
                  editingDomain,
                  flow.getTarget(),
                  ProcessPackage.Literals.ABSTRACT_CATCH_MESSAGE_EVENT__EVENT,
                  null);
          editingDomain.getCommandStack().execute(c);
          command.add(new DeleteCommand(editingDomain, connectionPart.getPrimaryView()));
          DestroyElementRequest req =
              new DestroyElementRequest(
                  editingDomain, connectionPart.resolveSemanticElement(), false);
          DestroyElementCommand rmComd = new DestroyElementCommand(req);
          command.add(rmComd);
        }
      }
    }
    dep.getDiagramEditDomain()
        .getDiagramCommandStack()
        .execute(new ICommandProxy(command.reduce()));
    dep.getDiagramEditDomain().getDiagramCommandStack().flush();
    dep.refresh();
  }
  /**
   * Performs a <code>DropObjectsRequest</code> in a modal context thread. Verifies that the diagram
   * refreshes on the UI thread.
   *
   * @throws Exception if an unexpected exception occurs
   */
  public void test_drop_modalContextThread() throws Exception {

    // Open the test fixture diagram
    getTestFixture().openDiagram();
    final DiagramEditPart diagramEditPart = getDiagramEditPart();

    // Create an AND gate in the semantic model
    ICommand andCommand =
        new AbstractTransactionalCommand(
            getTestFixture().getEditingDomain(), "Create AND Gate", null) { // $NON-NLS-1$

          protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
              throws ExecutionException {

            AndGate newElement =
                (AndGate)
                    SemanticPackage.eINSTANCE
                        .getEFactoryInstance()
                        .create(SemanticPackage.eINSTANCE.getAndGate());

            ContainerElement semanticElement =
                (ContainerElement) diagramEditPart.resolveSemanticElement();

            semanticElement.getChildren().add(newElement);
            return CommandResult.newOKCommandResult(newElement);
          }
        };

    andCommand.execute(new NullProgressMonitor(), null);
    AndGate andGate = (AndGate) andCommand.getCommandResult().getReturnValue();

    // Get the initial number of edit parts on the diagram
    List primaryEditParts = diagramEditPart.getPrimaryEditParts();
    int initialEditPartCount = primaryEditParts.size();

    // Get the command to drop the AND gate onto the diagram
    Point dropLocation = ICanonicalShapeCompartmentLayout.UNDEFINED.getLocation();
    DropObjectsRequest request = new DropObjectsRequest();
    request.setObjects(Collections.singletonList(andGate));
    request.setAllowedDetail(DND.DROP_COPY);
    request.setLocation(dropLocation);

    Command command = diagramEditPart.getCommand(request);
    final CommandProxy proxy = new CommandProxy(command);

    // Execute the command in a forking progress monitor dialog
    IRunnableWithProgress runnable =
        new IRunnableWithProgress() {

          public void run(IProgressMonitor monitor)
              throws InvocationTargetException, InterruptedException {

            try {
              OperationHistoryFactory.getOperationHistory().execute(proxy, monitor, null);

            } catch (ExecutionException e) {
              throw new InvocationTargetException(e);
            }
          }
        };

    new ProgressMonitorDialog(null).run(true, true, runnable);

    // Verify that a new edit part has been added to the diagram for the AND gate
    primaryEditParts = getDiagramEditPart().getPrimaryEditParts();

    assertTrue(
        "Size of primary edit parts should have increased.",
        primaryEditParts.size() > initialEditPartCount); // $NON-NLS-1$

    IGraphicalEditPart andGateEditPart = null;
    for (Iterator i = primaryEditParts.iterator(); i.hasNext(); ) {
      IGraphicalEditPart nextEditPart = (IGraphicalEditPart) i.next();

      if (andGate.equals(nextEditPart.resolveSemanticElement())) {
        andGateEditPart = nextEditPart;
        break;
      }
    }
    assertNotNull("Expected a new edit part for the AND gate", andGateEditPart); // $NON-NLS-1$
  }
 @Override
 protected void handleNotificationEvent(Notification notification) {
   super.handleNotificationEvent(notification);
   // notify all SemanticFigures of the changes.
   FigureUtils.notifySemanticFigures(this, notification);
 }
 /** @generated */
 protected void createDefaultEditPolicies() {
   super.createDefaultEditPolicies();
   installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ModuleItemSemanticEditPolicy());
   installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new ModuleCanonicalEditPolicy());
   // removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.POPUPBAR_ROLE);
 }