private Collection<BindingInfo> getAllBindingInfosOnDiagram(DSemanticDiagram diagram) {
   Collection<BindingInfo> bindingInfos = new ArrayList<BindingInfo>();
   for (DNode node : diagram.getNodes()) {
     if (node.getTarget() instanceof BindingInfo) {
       bindingInfos.add((BindingInfo) node.getTarget());
     }
   }
   return bindingInfos;
 }
Ejemplo n.º 2
0
 /**
  * Returns the specified forbidden sides for the current DNode. This feature makes sense for
  * border nodes only.
  *
  * @return the list of forbidden {@link Side}
  */
 public List<Side> getForbiddenSide() {
   NodeStyle nodeStyle = node.getOwnedStyle();
   StyleDescription styleDescription = nodeStyle.getDescription();
   if (styleDescription instanceof NodeStyleDescription) {
     return ((NodeStyleDescription) styleDescription).getForbiddenSides();
   }
   return Collections.emptyList();
 }
Ejemplo n.º 3
0
 /**
  * Indicates if the label of the node is on border.
  *
  * @return true if the label of this node is on border, false otherwise
  */
 public boolean hasLabelOnBorder() {
   NodeMapping actualMapping = node.getActualMapping();
   if (actualMapping != null) {
     NodeStyleDescription style = actualMapping.getStyle();
     if (style != null) {
       LabelPosition labelPosition = style.getLabelPosition();
       return labelPosition.equals(LabelPosition.BORDER_LITERAL);
     }
   }
   return false;
 }
 /**
  * Builds the command which will execute the user-specified operations to create a new state.
  *
  * @param node the node on which to create the new state.
  * @param tool the tool to use to create the state.
  * @param startingEndPredecessor the event end graphically preceding the starting position of the
  *     new state.
  * @param finishingEndPredecessor the event end graphically preceding the finishing position of
  *     the new state.
  * @return a command to create the state.
  */
 public static Command buildCreateStateCommandFromTool(
     final DNode node,
     final StateCreationTool tool,
     final EventEnd startingEndPredecessor,
     final EventEnd finishingEndPredecessor) {
   CommandBuilder builder =
       new StateCreationCommandBuilder(
           tool, node, startingEndPredecessor, finishingEndPredecessor);
   Session session = SessionManager.INSTANCE.getSession(node.getTarget());
   return getCommand(builder, session);
 }
Ejemplo n.º 5
0
 /**
  * Indicates if the node as a non-empty name definition, i.e. that its label expression don't
  * always return an empty string.
  *
  * @return true if the node as a non-null and non-empty name, false otherwise
  */
 public boolean hasNonEmptyNameDefinition() {
   boolean hasEmptyNameDefinition = true;
   NodeMapping actualMapping = node.getActualMapping();
   if (actualMapping != null) {
     NodeStyleDescription style = actualMapping.getStyle();
     if (style != null) {
       String labelExpression = style.getLabelExpression();
       hasEmptyNameDefinition = labelExpression.trim().length() != 0;
     }
   }
   return hasEmptyNameDefinition;
 }
Ejemplo n.º 6
0
  /**
   * Return the default draw2D dimension according to the specified DNode.
   *
   * @return the default draw2D dimension according to the specified DNode.
   */
  public Dimension getDefaultDimension() {
    final Dimension result = DEFAULT_NODE_DIMENSION.getCopy();

    if (node.getStyle() instanceof WorkspaceImage) {
      final WorkspaceImage workspaceImage = (WorkspaceImage) node.getStyle();
      final String path = workspaceImage.getWorkspacePath();
      final Image image;
      image = WorkspaceImageFigure.getImageInstanceFromPath(path);
      if (image != null) {
        // Use default image size
        if (node.getWidth() == null || Integer.valueOf(node.getWidth()) == -1) {
          result.width = image.getBounds().width;
          result.height = image.getBounds().height;
        } else {
          // width is already defined, adapt height thanks to
          // image ratio
          final double ratio = (double) image.getBounds().width / image.getBounds().height;
          double newHeight = node.getWidth().intValue() / ratio;

          // Adapt to draw2D
          result.width = node.getWidth().intValue() * LayoutUtils.SCALE;
          result.height = (int) (newHeight * LayoutUtils.SCALE);
        }
      }
    } else {
      if (node.getWidth() != null) {
        result.width = node.getWidth().intValue();
      }
      if (node.getHeight() != null) {
        result.height = node.getHeight().intValue();
      }

      // Adapt to draw2D
      result.width = result.width * LayoutUtils.SCALE;
      result.height = result.height * LayoutUtils.SCALE;
    }

    return result;
  }
Ejemplo n.º 7
0
 /**
  * Tests whether or not the node allows the user to change its horizontal size, according to the
  * {@link ResizeKind} specified in the VSM.
  *
  * @return <code>true</code> if the node allow the user to change its horizontal size.
  */
 public boolean allowsHorizontalResize() {
   ResizeKind allowed = node.getResizeKind();
   return allowed == ResizeKind.NSEW_LITERAL || allowed == ResizeKind.EAST_WEST_LITERAL;
 }
Ejemplo n.º 8
0
 /**
  * Tests whether or not the node allows the user to change its vertical size, according to the
  * {@link ResizeKind} specified in the VSM.
  *
  * @return <code>true</code> if the node allow the user to change its vertical size.
  */
 public boolean allowsVerticalResize() {
   ResizeKind allowed = node.getResizeKind();
   return allowed == ResizeKind.NSEW_LITERAL || allowed == ResizeKind.NORTH_SOUTH_LITERAL;
 }
  /**
   * Corresponds to ticket #1811. Check that after a creation of a diagram with ports from an
   * existing diagram, the layoutConstraint of all ports is not {0, 0}.
   */
  public void testPortLocationForCreationFromNavigation() {
    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);
    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);

    // Open the editor (and refresh it)
    final IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    // Set the focus to the desired package
    assertTrue(
        "We should have a DiagramDocumentEditor", editorPart instanceof DiagramDocumentEditor);

    final DiagramDocumentEditor diagramEditor = (DiagramDocumentEditor) editorPart;

    // Get the package named "SubPackage"
    PackageableElement element = model.getPackagedElement("SubPackage");
    assertTrue("Corrupted input data", element instanceof Package);
    final Package packageSubPackage = (Package) element;

    IMenuManager popupMenu = new MenuManager();
    popupMenu.add(
        new MenuManager(
            IWorkbenchActionConstants.MB_ADDITIONS,
            IWorkbenchActionConstants.MB_ADDITIONS)); // $NON-NLS-1$ //$NON-NLS-2$
    popupMenu.add(new MenuManager("popup.new", "popup.new")); // $NON-NLS-1$

    // Set the focus to package SubPackage
    IGraphicalEditPart elementEditPart =
        getEditPart(getFirstDiagramElement(diagram, packageSubPackage));
    diagramEditor.getDiagramGraphicalViewer().setFocus(elementEditPart);

    DNode focusedElement =
        (DNode)
            ((GraphicalEditPart) diagramEditor.getDiagramGraphicalViewer().getFocusEditPart())
                .resolveSemanticElement();
    assertTrue(
        "This is not the good focused element", focusedElement.getTarget() instanceof Package);
    assertEquals(
        "This is not the good focused element",
        "SubPackage",
        ((Package) focusedElement.getTarget()).getName());

    ContributionItemService.getInstance().contributeToPopupMenu(popupMenu, diagramEditor);

    // Check the popup menu.
    IMenuManager newRepresentationMenu = (IMenuManager) popupMenu.find("popup.new");
    IContributionItem[] items = newRepresentationMenu.getItems();

    boolean inNewRepresentationToGroup = false;

    ActionContributionItem actionContribution = null;

    for (int i = 0; i < items.length; i++) {
      if (items[i] instanceof Separator) {
        Separator sep = (Separator) items[i];
        if ("createRepresentationGroup".equals(sep.getId())) {
          inNewRepresentationToGroup = true;
        } else {
          inNewRepresentationToGroup = false;
        }
      }
      if (inNewRepresentationToGroup && items[i] instanceof ActionContributionItem) {
        assertNull("There should be only one ActionContributionItem", actionContribution);
        actionContribution = (ActionContributionItem) items[i];
      }
    }

    assertNotNull("There should be one ActionContributionItem", actionContribution);
    final IAction action = actionContribution.getAction();

    assertEquals("Action has not the correct text", "New diagram", action.getText());

    // Disabling ui callback of diagram command factory
    final Object adapter = diagramEditor.getAdapter(IDiagramCommandFactoryProvider.class);
    final IDiagramCommandFactoryProvider diagramCmdFactoryProvider =
        (IDiagramCommandFactoryProvider) adapter;
    final IDiagramCommandFactory diagramCommandFactory =
        diagramCmdFactoryProvider.getCommandFactory(session.getTransactionalEditingDomain());
    diagramCommandFactory.setUserInterfaceCallBack(new NoUICallback());

    action.run();

    IEditorPart editor2 =
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    assertTrue("We should have a DiagramDocumentEditor", editor2 instanceof DiagramDocumentEditor);

    final DiagramDocumentEditor diagramEditor2 = (DiagramDocumentEditor) editor2;
    GraphicalEditPart diagramPart = (GraphicalEditPart) diagramEditor2.getDiagramEditPart();
    final DSemanticDiagram diagram2 = (DSemanticDiagram) diagramPart.resolveSemanticElement();

    assertEquals(
        "The opened diagram is not valid", diagram2.getTarget(), focusedElement.getTarget());

    // Get the class named "SubClass1"
    element = packageSubPackage.getPackagedElement("SubClass1");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class subClass1 = (Class) element;

    final Property firstProperty = subClass1.getOwnedAttribute("Prop1", subClass1);
    final Property secondProperty = subClass1.getOwnedAttribute("Prop2", subClass1);

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram2, firstProperty);
    assertNotNull(
        "The first property has no corresponding diagramElement", firstPropertyDiagramElement);
    final Node firstPropertyNode = getGmfNode(firstPropertyDiagramElement);
    assertNotNull("The first property has no corresponding GMF node", firstPropertyNode);
    assertTrue(
        "Bag layout constraint type", firstPropertyNode.getLayoutConstraint() instanceof Location);
    final Location firstLocation = (Location) firstPropertyNode.getLayoutConstraint();
    final DDiagramElement secondPropertyDiagramElement =
        getFirstDiagramElement(diagram2, secondProperty);
    assertNotNull(
        "The second property has no corresponding diagramElement", secondPropertyDiagramElement);
    final Node secondPropertyNode = getGmfNode(secondPropertyDiagramElement);
    assertNotNull("The second property has no corresponding GMF node", secondPropertyNode);
    assertTrue(
        "Bag layout constraint type", secondPropertyNode.getLayoutConstraint() instanceof Location);
    final Location secondLocation = (Location) secondPropertyNode.getLayoutConstraint();

    assertFalse(
        "All the layout constraints of the ports should not be in {0,0}",
        firstLocation.getX() == 0
            && firstLocation.getY() == 0
            && secondLocation.getX() == 0
            && secondLocation.getY() == 0);
    assertTrue(
        "All the layout constraints of the ports should be different",
        firstLocation.getX() != secondLocation.getX()
            || firstLocation.getY() != secondLocation.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();

    DialectUIManager.INSTANCE.closeEditor(editor2, false);
    TestsUtil.synchronizationWithUIThread();
  }