/**
   * Corresponds to ticket #1811. Check that after a creation of a diagram with ports (on node) from
   * the model content view , the layoutConstraint of all ports is not {0, 0}.
   */
  public void testPortLocationForCreationFromModelContentView() {

    // 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);
    // Get the class named "Class2"
    PackageableElement element = model.getPackagedElement("Class2");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class2 = (Class) element;

    // Get the class named "Class3"
    element = model.getPackagedElement("Class3");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class3 = (Class) element;

    final Property firstProperty = class3.getOwnedAttribute("Prop3to2", class2);
    final Property secondProperty = class3.getOwnedAttribute("OtherProp3to2", class2);

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

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram, 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(diagram, 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();
  }
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.papyrus.layout.LayouttoolInterface#getBounds(org.eclipse.gef.EditPart)
  */
 public Rectangle getBounds(EditPart element) {
   if (element.getModel() instanceof Node) {
     Node node = (Node) element.getModel();
     if (node.getLayoutConstraint() instanceof Bounds) {
       Bounds bounds = (Bounds) node.getLayoutConstraint();
       return new Rectangle(bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight());
     }
   }
   return null;
 }
  /** @generated */
  public Edge createAssociation_4001(
      EObject domainElement,
      View containerView,
      int index,
      boolean persisted,
      PreferencesHint preferencesHint) {
    Connector edge = NotationFactory.eINSTANCE.createConnector();
    edge.getStyles().add(NotationFactory.eINSTANCE.createFontStyle());
    RelativeBendpoints bendpoints = NotationFactory.eINSTANCE.createRelativeBendpoints();
    ArrayList<RelativeBendpoint> points = new ArrayList<RelativeBendpoint>(2);
    points.add(new RelativeBendpoint());
    points.add(new RelativeBendpoint());
    bendpoints.setPoints(points);
    edge.setBendpoints(bendpoints);
    ViewUtil.insertChildView(containerView, edge, index, persisted);
    edge.setType(
        edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part
            .NECSIS14_ClassDiagramVisualIDRegistry.getType(
            edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.edit.parts
                .AssociationEditPart.VISUAL_ID));
    edge.setElement(domainElement);
    // initializePreferences
    final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();

    org.eclipse.swt.graphics.RGB lineRGB =
        PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_LINE_COLOR);
    ViewUtil.setStructuralFeatureValue(
        edge,
        NotationPackage.eINSTANCE.getLineStyle_LineColor(),
        FigureUtilities.RGBToInteger(lineRGB));
    FontStyle edgeFontStyle = (FontStyle) edge.getStyle(NotationPackage.Literals.FONT_STYLE);
    if (edgeFontStyle != null) {
      FontData fontData =
          PreferenceConverter.getFontData(prefStore, IPreferenceConstants.PREF_DEFAULT_FONT);
      edgeFontStyle.setFontName(fontData.getName());
      edgeFontStyle.setFontHeight(fontData.getHeight());
      edgeFontStyle.setBold((fontData.getStyle() & SWT.BOLD) != 0);
      edgeFontStyle.setItalic((fontData.getStyle() & SWT.ITALIC) != 0);
      org.eclipse.swt.graphics.RGB fontRGB =
          PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_FONT_COLOR);
      edgeFontStyle.setFontColor(FigureUtilities.RGBToInteger(fontRGB).intValue());
    }
    Routing routing = Routing.get(prefStore.getInt(IPreferenceConstants.PREF_LINE_STYLE));
    if (routing != null) {
      ViewUtil.setStructuralFeatureValue(
          edge, NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing);
    }
    Node label6001 =
        createLabel(
            edge,
            edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part
                .NECSIS14_ClassDiagramVisualIDRegistry.getType(
                edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.edit.parts
                    .AssociationNameEditPart.VISUAL_ID));
    label6001.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
    Location location6001 = (Location) label6001.getLayoutConstraint();
    location6001.setX(0);
    location6001.setY(40);
    return edge;
  }
  /**
   * initialize label location.
   *
   * @param view the element to initialize
   * @param store the preference store
   * @param elementName the name to the element
   */
  public static void initLabelLocationFromPrefs(
      View view, final IPreferenceStore store, String elementName) {
    assert (view instanceof Node);

    Node label = (Node) view;
    Location location = (Location) label.getLayoutConstraint();

    String xKey = getpreferenceKey(view, elementName, PreferenceConstantHelper.LOCATION_X);
    String yKey = getpreferenceKey(view, elementName, PreferenceConstantHelper.LOCATION_Y);

    location.setX(store.getInt(xKey));
    location.setY(store.getInt(yKey));

    label.setLayoutConstraint(location);
  }
Exemplo n.º 5
0
  /** @generated */
  public Node createStakeHolder_2011(
      EObject domainElement,
      View containerView,
      int index,
      boolean persisted,
      PreferencesHint preferencesHint) {
    Shape node = NotationFactory.eINSTANCE.createShape();
    node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
    node.setType(RdalVisualIDRegistry.getType(StakeHolderEditPart.VISUAL_ID));
    ViewUtil.insertChildView(containerView, node, index, persisted);
    node.setElement(domainElement);
    stampShortcut(containerView, node);
    // initializeFromPreferences
    final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();

    org.eclipse.swt.graphics.RGB lineRGB =
        PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_LINE_COLOR);
    ViewUtil.setStructuralFeatureValue(
        node,
        NotationPackage.eINSTANCE.getLineStyle_LineColor(),
        FigureUtilities.RGBToInteger(lineRGB));
    FontStyle nodeFontStyle = (FontStyle) node.getStyle(NotationPackage.Literals.FONT_STYLE);
    if (nodeFontStyle != null) {
      FontData fontData =
          PreferenceConverter.getFontData(prefStore, IPreferenceConstants.PREF_DEFAULT_FONT);
      nodeFontStyle.setFontName(fontData.getName());
      nodeFontStyle.setFontHeight(fontData.getHeight());
      nodeFontStyle.setBold((fontData.getStyle() & SWT.BOLD) != 0);
      nodeFontStyle.setItalic((fontData.getStyle() & SWT.ITALIC) != 0);
      org.eclipse.swt.graphics.RGB fontRGB =
          PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_FONT_COLOR);
      nodeFontStyle.setFontColor(FigureUtilities.RGBToInteger(fontRGB).intValue());
    }
    org.eclipse.swt.graphics.RGB fillRGB =
        PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_FILL_COLOR);
    ViewUtil.setStructuralFeatureValue(
        node,
        NotationPackage.eINSTANCE.getFillStyle_FillColor(),
        FigureUtilities.RGBToInteger(fillRGB));
    Node label5018 =
        createLabel(node, RdalVisualIDRegistry.getType(StakeHolderNameEditPart.VISUAL_ID));
    label5018.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
    Location location5018 = (Location) label5018.getLayoutConstraint();
    location5018.setX(0);
    location5018.setY(5);
    return node;
  }
 /** @generated */
 public Edge createForeignKey_3001(
     EObject domainElement,
     View containerView,
     int index,
     boolean persisted,
     PreferencesHint preferencesHint) {
   Edge edge = NotationFactory.eINSTANCE.createEdge();
   edge.getStyles().add(NotationFactory.eINSTANCE.createRoutingStyle());
   edge.getStyles().add(NotationFactory.eINSTANCE.createFontStyle());
   RelativeBendpoints bendpoints = NotationFactory.eINSTANCE.createRelativeBendpoints();
   ArrayList points = new ArrayList(2);
   points.add(new RelativeBendpoint());
   points.add(new RelativeBendpoint());
   bendpoints.setPoints(points);
   edge.setBendpoints(bendpoints);
   ViewUtil.insertChildView(containerView, edge, index, persisted);
   edge.setType(SqlmodelVisualIDRegistry.getType(ForeignKeyEditPart.VISUAL_ID));
   edge.setElement(domainElement);
   // initializePreferences
   final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();
   FontStyle edgeFontStyle = (FontStyle) edge.getStyle(NotationPackage.Literals.FONT_STYLE);
   if (edgeFontStyle != null) {
     FontData fontData =
         PreferenceConverter.getFontData(prefStore, IPreferenceConstants.PREF_DEFAULT_FONT);
     edgeFontStyle.setFontName(fontData.getName());
     edgeFontStyle.setFontHeight(fontData.getHeight());
     edgeFontStyle.setBold((fontData.getStyle() & SWT.BOLD) != 0);
     edgeFontStyle.setItalic((fontData.getStyle() & SWT.ITALIC) != 0);
     org.eclipse.swt.graphics.RGB fontRGB =
         PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_FONT_COLOR);
     edgeFontStyle.setFontColor(FigureUtilities.RGBToInteger(fontRGB).intValue());
   }
   Routing routing = Routing.get(prefStore.getInt(IPreferenceConstants.PREF_LINE_STYLE));
   if (routing != null) {
     ViewUtil.setStructuralFeatureValue(
         edge, NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing);
   }
   Node label4003 =
       createLabel(edge, SqlmodelVisualIDRegistry.getType(ForeignKeyNameEditPart.VISUAL_ID));
   label4003.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
   Location location4003 = (Location) label4003.getLayoutConstraint();
   location4003.setX(1);
   location4003.setY(-15);
   return edge;
 }
 /** @generated */
 public View createView(
     IAdaptable semanticAdapter,
     View containerView,
     String semanticHint,
     int index,
     boolean persisted,
     PreferencesHint preferencesHint) {
   Node view =
       (Node)
           super.createView(
               semanticAdapter, containerView, semanticHint, index, persisted, preferencesHint);
   Location location = (Location) view.getLayoutConstraint();
   IMapMode mapMode =
       MeasurementUnitHelper.getMapMode(containerView.getDiagram().getMeasurementUnit());
   location.setX(mapMode.DPtoLP(0));
   location.setY(mapMode.DPtoLP(5));
   return view;
 }
 protected void setPreferredSize() {
   Node node = (Node) getContextObject();
   Bounds bounds = (Bounds) node.getLayoutConstraint();
   bounds.setWidth(-1);
   bounds.setHeight(-1);
 }
  /**
   * Check that :
   *
   * <UL>
   *   <LI>the size of new collapsed bordered nodes is 1x1 (and not the same as not collapsed),
   *   <LI>the space between two new collapsed bordered nodes is the same as between two new normal
   *       bordered nodes.
   *   <LI>the size of an existing bordered nodes is 1x1 after collapse filter application, and its
   *       location is contains in the original bounds.
   * </UL>
   *
   * Steps of this test:
   *
   * <UL>
   *   <LI>Open a first diagram
   *       <UL>
   *         <LI>modify the semantic (causing creation of new ports),
   *         <LI>take the bounds of new ports (without collapse filter),
   *         <LI>take the space between them,
   *         <LI>apply the collapse filter,
   *         <LI>check that the size of the port is 1x1 and its new location is contained in the old
   *             bounds,
   *         <LI>close the diagram,
   *         <LI>undo the semantic modifications,
   *       </UL>
   *   <LI>Open a new diagram,
   *       <UL>
   *         <LI>enable the collapse filter,
   *         <LI>make the same semantic modifications (causing creation of new ports),
   *         <LI>compare the size ans the space with previous diagram.
   *       </UL>
   * </UL>
   *
   * See VP-3833
   */
  public void testPortLocationsAndMoreWithForCollapseFilter() {
    // Get the desired package
    final Model model = (Model) semanticModel;
    assertNotNull("Corrupted input data", model);

    // Get the class named "Class2"
    PackageableElement element = model.getPackagedElement("Class2");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class2 = (Class) element;

    // Get the class named "Class3"
    element = model.getPackagedElement("Class3");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class3 = (Class) element;

    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);
    // Open the editor (and refresh it)
    IEditorPart editorPart =
        DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();

    // Add 3 Property to class3 (that will cause the creation of 3
    // new ports during refresh)
    String prefix = "aPort";
    addProperties(class3, class2, "aPort", 3);
    // Refresh the diagram
    refresh(diagram);

    Property thirdProperty = class3.getOwnedAttribute(prefix + 1, class2);
    DDiagramElement thirdPropertyDiagramElement = getFirstDiagramElement(diagram, thirdProperty);
    Node thirdPropertyNode = getGmfNode(thirdPropertyDiagramElement);
    final Bounds expectedThirdBounds = (Bounds) thirdPropertyNode.getLayoutConstraint();

    Property fourthProperty = class3.getOwnedAttribute(prefix + 2, class2);
    DDiagramElement fourthPropertyDiagramElement = getFirstDiagramElement(diagram, fourthProperty);
    Node fourthPropertyNode = getGmfNode(fourthPropertyDiagramElement);
    final Bounds expectedFourthBounds = (Bounds) fourthPropertyNode.getLayoutConstraint();

    Property fifthProperty = class3.getOwnedAttribute(prefix + 3, class2);
    DDiagramElement fifthPropertyDiagramElement = getFirstDiagramElement(diagram, fifthProperty);
    Node fifthPropertyNode = getGmfNode(fifthPropertyDiagramElement);
    final Bounds expectedFifthBounds = (Bounds) fifthPropertyNode.getLayoutConstraint();
    // Activate the filter
    activateFilter(diagram, "FilterPropertyStartingWithA");
    // Refresh the diagram
    refresh(diagram);
    // Check the size and the new location of one of the collapsed bordered
    // node
    final Bounds collapseThirdBounds = (Bounds) thirdPropertyNode.getLayoutConstraint();
    assertEquals(
        "The width of the collapse bordered node is not OK.", 1, collapseThirdBounds.getWidth());
    assertEquals(
        "The height of the collapse bordered node is not OK.", 1, collapseThirdBounds.getHeight());
    assertTrue(
        "The new collapsed location should be contains in the not collapsed bounds.",
        new Rectangle(
                expectedThirdBounds.getX(),
                expectedThirdBounds.getY(),
                expectedThirdBounds.getWidth(),
                expectedThirdBounds.getHeight())
            .contains(new Point(collapseThirdBounds.getX(), collapseThirdBounds.getY())));

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

    // Remove the 3 added properties
    removeProperties(class3, 3);

    // Get the diagram for the root of this model.
    diagram = (DDiagram) createRepresentation(NODE_REPRESENTATION_DESC_NAME, model);
    // Open the editor (and refresh it)
    editorPart = DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor());
    TestsUtil.synchronizationWithUIThread();
    // Activate the filter
    activateFilter(diagram, "FilterPropertyStartingWithA");

    // Add 3 Property to class3 (that will cause the creation of 3
    // new ports during refresh)
    addProperties(class3, class2, "aPort", 3);
    // Refresh the diagram
    refresh(diagram);

    thirdProperty = class3.getOwnedAttribute(prefix + 1, class2);
    thirdPropertyDiagramElement = getFirstDiagramElement(diagram, thirdProperty);
    thirdPropertyNode = getGmfNode(thirdPropertyDiagramElement);
    Bounds thirdCollapseBounds = (Bounds) thirdPropertyNode.getLayoutConstraint();
    assertEquals(
        "The width of a new collapsed bordered node is not correct.",
        1,
        thirdCollapseBounds.getWidth());
    assertEquals(
        "The height of a new collapsed bordered node is not correct.",
        1,
        thirdCollapseBounds.getHeight());

    fourthProperty = class3.getOwnedAttribute(prefix + 2, class2);
    fourthPropertyDiagramElement = getFirstDiagramElement(diagram, fourthProperty);
    fourthPropertyNode = getGmfNode(fourthPropertyDiagramElement);
    Bounds fourthCollapseBounds = (Bounds) fourthPropertyNode.getLayoutConstraint();
    assertEquals(
        "The width of a new collapsed bordered node is not correct.",
        1,
        fourthCollapseBounds.getWidth());
    assertEquals(
        "The height of a new collapsed bordered node is not correct.",
        1,
        fourthCollapseBounds.getHeight());

    fifthProperty = class3.getOwnedAttribute(prefix + 3, class2);
    fifthPropertyDiagramElement = getFirstDiagramElement(diagram, fifthProperty);
    fifthPropertyNode = getGmfNode(fifthPropertyDiagramElement);
    Bounds fifthCollapseBounds = (Bounds) fifthPropertyNode.getLayoutConstraint();
    assertEquals(
        "The width of a new collapsed bordered node is not correct.",
        1,
        fifthCollapseBounds.getWidth());
    assertEquals(
        "The height of a new collapsed bordered node is not correct.",
        1,
        fifthCollapseBounds.getHeight());

    assertEquals(
        "The space bewteen the collapsed bordered nodes should be the same as between the not collapsed bordered nodes.",
        expectedFourthBounds.getY() - expectedThirdBounds.getY(),
        fourthCollapseBounds.getY() - thirdCollapseBounds.getY());
    assertEquals(
        "The space bewteen the collapsed bordered nodes should be the same as between the not collapsed bordered nodes.",
        expectedFifthBounds.getY() - expectedFourthBounds.getY(),
        fifthCollapseBounds.getY() - fourthCollapseBounds.getY());

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();
  }
  /**
   * Open the diagram, modify the semantic (causing creation of new ports), check the position of
   * new ports (not the same). See VP-3095
   */
  protected void testPortLocationAfterRefresh(boolean activateCollapseFilter) {
    // 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);
    // Get the class named "Class2"
    PackageableElement element = model.getPackagedElement("Class2");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class2 = (Class) element;

    // Get the class named "Class3"
    element = model.getPackagedElement("Class3");
    assertTrue("Corrupted input data", element instanceof Class);
    final Class class3 = (Class) element;

    final Property firstProperty = class3.getOwnedAttribute("Prop3to2", class2);
    final Property secondProperty = class3.getOwnedAttribute("OtherProp3to2", class2);

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

    if (activateCollapseFilter) {
      activateFilter(diagram, "FilterPropertyStartingWithA");
    }

    // Add 3 Property to class3 (that will cause the creation of 3
    // new ports during refresh).
    addProperties(class3, class2, "Prop3to2_", 3);
    // Refresh the diagram
    refresh(diagram);

    final DDiagramElement firstPropertyDiagramElement =
        getFirstDiagramElement(diagram, 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(diagram, 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());

    final Property thirdProperty = class3.getOwnedAttribute("Prop3to2_1", class2);
    final Property fourthProperty = class3.getOwnedAttribute("Prop3to2_2", class2);
    final Property fifthProperty = class3.getOwnedAttribute("Prop3to2_3", class2);
    final DDiagramElement thirdPropertyDiagramElement =
        getFirstDiagramElement(diagram, thirdProperty);
    assertNotNull(
        "The third property has no corresponding diagramElement", thirdPropertyDiagramElement);
    final Node thirdPropertyNode = getGmfNode(thirdPropertyDiagramElement);
    assertNotNull("The third property has no corresponding GMF node", thirdPropertyNode);
    assertTrue(
        "Bag layout constraint type", thirdPropertyNode.getLayoutConstraint() instanceof Location);
    final Location thirdLocation = (Location) thirdPropertyNode.getLayoutConstraint();
    final DDiagramElement fourthPropertyDiagramElement =
        getFirstDiagramElement(diagram, fourthProperty);
    assertNotNull(
        "The fourth property has no corresponding diagramElement", fourthPropertyDiagramElement);
    final Node fourthPropertyNode = getGmfNode(fourthPropertyDiagramElement);
    assertNotNull("The fourth property has no corresponding GMF node", fourthPropertyNode);
    assertTrue(
        "Bag layout constraint type", fourthPropertyNode.getLayoutConstraint() instanceof Location);
    final Location fourthLocation = (Location) fourthPropertyNode.getLayoutConstraint();
    final DDiagramElement fifthPropertyDiagramElement =
        getFirstDiagramElement(diagram, fifthProperty);
    assertNotNull(
        "The fifth property has no corresponding diagramElement", fifthPropertyDiagramElement);
    final Node fifthPropertyNode = getGmfNode(fifthPropertyDiagramElement);
    assertNotNull("The fifth property has no corresponding GMF node", fifthPropertyNode);
    assertTrue(
        "Bag layout constraint type", fifthPropertyNode.getLayoutConstraint() instanceof Location);
    final Location fifthLocation = (Location) fifthPropertyNode.getLayoutConstraint();

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

    DialectUIManager.INSTANCE.closeEditor(editorPart, false);
    TestsUtil.synchronizationWithUIThread();
  }
  /**
   * 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();
  }