/** Execution of the command */
  @Override
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {

    View view = getView();

    List<Edge> sourceList = ViewUtil.getSourceConnections(view);
    List<Edge> targetList = ViewUtil.getTargetConnections(view);

    for (Edge edge : sourceList) {
      IdentityAnchor anchor = (IdentityAnchor) edge.getSourceAnchor();
      if (anchor != null) {
        anchor.setId(getNewIdStr(anchor));
      }
    }

    for (Edge edge : targetList) {
      IdentityAnchor anchor = (IdentityAnchor) edge.getTargetAnchor();
      if (anchor != null) {
        anchor.setId(getNewIdStr(anchor));
      }
    }

    return CommandResult.newOKCommandResult();
  }
 /** @generated */
 public Edge createViewTableViewedTables_3002(
     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(ViewTableViewedTables2EditPart.VISUAL_ID));
   edge.setElement(null);
   // 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);
   }
   return edge;
 }
  @BeforeClass
  public static void initRelationship() throws Exception {

    // Prepare source and target
    View container =
        ViewUtil.getChildBySemanticHint(
            getDiagramView(), SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID);
    View blockStructureView =
        ViewUtil.getChildBySemanticHint(
            container, SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID);
    View actorPartSourceView =
        createGraphicalNode(
            SysMLElementTypes.ACTOR_PART_PROPERTY,
            SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID,
            blockStructureView);
    View actorPartTargetView =
        createGraphicalNode(
            SysMLElementTypes.ACTOR_PART_PROPERTY,
            SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID,
            blockStructureView);

    // Prepare relationship
    relationshipView =
        TestPrepareUtils.createGraphicalLink(
            UMLElementTypes.CONNECTOR,
            UMLGraphicalTypes.LINK_UML_CONNECTOR_ID,
            container,
            EditorUtils.getEditPart(actorPartSourceView),
            EditorUtils.getEditPart(actorPartTargetView));
  }
  /**
   * Checks if is correct graphical view.
   *
   * @param connectorEnd a connector end
   * @param view a view
   * @return <code>true</code> if the view represents the role of the connector AND if the view is
   *     encapsulated as required by the nested path of the connector end
   */
  protected boolean isCorrectGraphicalView(final ConnectorEnd connectorEnd, final View view) {
    final NestedConnectorEnd nestedConnectorEnd =
        org.eclipse.uml2.uml.util.UMLUtil.getStereotypeApplication(
            connectorEnd, NestedConnectorEnd.class);
    final Property partWithPort = connectorEnd.getPartWithPort();
    // final ConnectableElement role = end.getRole();
    // 1. we get the top view of this view with the same semantic element
    View localView = getTopViewWithSameSemanticElement(view);

    // 2. we verify the part with port
    if (partWithPort != null) {
      View parent = getTopViewWithSameSemanticElement(ViewUtil.getViewContainer(localView));
      if (parent.getElement() != partWithPort) {
        return false;
      }
    }

    // 3. we verify the nested path
    if (nestedConnectorEnd != null && nestedConnectorEnd.getPropertyPath().size() > 0) {
      View parent = view;
      final List<Property> paths = nestedConnectorEnd.getPropertyPath();
      for (int i = paths.size() - 1; i >= 0; i--) {
        final Property currentProperty = paths.get(i);
        parent = getTopViewWithSameSemanticElement(ViewUtil.getViewContainer(parent));
        if (parent.getElement() != currentProperty) {
          return false;
        }
      }
    }
    return true;
  }
  /** @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;
  }
  @BeforeClass
  public static void prepareContainerForTest() throws Exception {
    try {
      View blockView =
          ViewUtil.getChildBySemanticHint(
              getDiagramView(), SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID);
      View blockStructureView =
          ViewUtil.getChildBySemanticHint(
              blockView, SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID);
      View partView =
          createGraphicalNode(
              UMLElementTypes.PROPERTY,
              SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID,
              blockStructureView);
      containerView =
          ViewUtil.getChildBySemanticHint(
              partView, SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID);

      if (containerView == null) {
        throw new Exception("Unable to prepare container for test.");
      }

      // Ensure the compartment is visible (required for EditPart to be found)
      if (!containerView.isVisible()) {
        changeVisibility(containerView);
      }

    } catch (Exception e) {
      throw new Exception("Unable to prepare container for test.", e);
    }
  }
  /** @generated */
  public Node createPersistentTable_2003(
      EObject domainElement,
      View containerView,
      int index,
      boolean persisted,
      PreferencesHint preferencesHint) {
    Node node = NotationFactory.eINSTANCE.createNode();
    node.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
    node.getStyles().add(NotationFactory.eINSTANCE.createLineStyle());
    node.getStyles().add(NotationFactory.eINSTANCE.createFillStyle());

    node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
    node.setType(SqlmodelVisualIDRegistry.getType(PersistentTable2EditPart.VISUAL_ID));
    ViewUtil.insertChildView(containerView, node, index, persisted);
    node.setElement(domainElement);
    // 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));
    org.eclipse.swt.graphics.RGB fillRGB =
        PreferenceConverter.getColor(prefStore, IPreferenceConstants.PREF_FILL_COLOR);
    ViewUtil.setStructuralFeatureValue(
        node,
        NotationPackage.eINSTANCE.getFillStyle_FillColor(),
        FigureUtilities.RGBToInteger(fillRGB));
    return node;
  }
  /** @generated */
  public Node createAttribute_3001(
      EObject domainElement,
      View containerView,
      int index,
      boolean persisted,
      PreferencesHint preferencesHint) {
    Shape node = NotationFactory.eINSTANCE.createShape();
    node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
    node.setType(
        edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part
            .NECSIS14_ClassDiagramVisualIDRegistry.getType(
            edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.edit.parts.AttributeEditPart
                .VISUAL_ID));
    ViewUtil.insertChildView(containerView, node, index, persisted);
    node.setElement(domainElement);
    // 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 label5001 =
        createLabel(
            node,
            edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.part
                .NECSIS14_ClassDiagramVisualIDRegistry.getType(
                edu.toronto.cs.se.modelepedia.necsis14_classdiagram.diagram.edit.parts
                    .AttributeNameEditPart.VISUAL_ID));
    return node;
  }
  protected void createExitPoint(Edge edge, Diagram subdiagram) {
    Transition transition = (Transition) edge.getElement();
    // create semantic exit point
    Region exitPointContainer = getExitPointContainer(transition);
    Exit exitPoint = createSemanticExitPoint(transition);

    // create node for exit point
    View exitPointContainerView = helper.getViewForSemanticElement(exitPointContainer, subdiagram);
    View exitPointRegionCompartment =
        ViewUtil.getChildBySemanticHint(exitPointContainerView, SemanticHints.REGION_COMPARTMENT);
    Node exitNode =
        ViewService.createNode(
            exitPointRegionCompartment, exitPoint, SemanticHints.EXIT, preferencesHint);

    // re-wire existing transition to new exit point
    Vertex oldTarget = transition.getTarget();
    transition.setTarget(exitPoint);
    ViewService.createEdge(
        edge.getSource(), exitNode, transition, SemanticHints.TRANSITION, preferencesHint);

    // create transition from selected state to former transition target
    Transition exitPointTransition = SGraphFactory.eINSTANCE.createTransition();
    exitPointTransition.setSource((State) subdiagram.getElement());
    exitPointTransition.setTarget(oldTarget);
    ViewService.createEdge(
        getContextObject(),
        edge.getTarget(),
        exitPointTransition,
        SemanticHints.TRANSITION,
        preferencesHint);

    addExitPointSpec(exitPointTransition, exitPoint);
  }
 /** @generated */
 private Node createCompartment(
     View owner,
     String hint,
     boolean canCollapse,
     boolean hasTitle,
     boolean canSort,
     boolean canFilter) {
   // SemanticListCompartment rv = NotationFactory.eINSTANCE.createSemanticListCompartment();
   // rv.setShowTitle(showTitle);
   // rv.setCollapsed(isCollapsed);
   Node rv;
   if (canCollapse) {
     rv = NotationFactory.eINSTANCE.createBasicCompartment();
   } else {
     rv = NotationFactory.eINSTANCE.createDecorationNode();
   }
   if (hasTitle) {
     TitleStyle ts = NotationFactory.eINSTANCE.createTitleStyle();
     ts.setShowTitle(true);
     rv.getStyles().add(ts);
   }
   if (canSort) {
     rv.getStyles().add(NotationFactory.eINSTANCE.createSortingStyle());
   }
   if (canFilter) {
     rv.getStyles().add(NotationFactory.eINSTANCE.createFilteringStyle());
   }
   rv.setType(hint);
   ViewUtil.insertChildView(owner, rv, ViewUtil.APPEND, true);
   return rv;
 }
 public Rectangle getBounds() {
   View view = this.getNotationView();
   int width =
       ((Integer) getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getSize_Width()))
           .intValue();
   int height =
       ((Integer) getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getSize_Height()))
           .intValue();
   int x =
       ((Integer) getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X()))
           .intValue();
   int y =
       ((Integer) getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y()))
           .intValue();
   String prefElementId = ViewUtil.resolveSemanticElement(view).eClass().getName();
   IPreferenceStore store = UMLDiagramEditorPlugin.getInstance().getPreferenceStore();
   String preferenceConstantWitdh =
       PreferenceInitializerForElementHelper.getpreferenceKey(
           view, prefElementId, PreferencesConstantsHelper.WIDTH);
   String preferenceConstantHeight =
       PreferenceInitializerForElementHelper.getpreferenceKey(
           view, prefElementId, PreferencesConstantsHelper.HEIGHT);
   if (width <= 0) {
     width = store.getInt(preferenceConstantWitdh);
   }
   if (height <= 0) {
     height = store.getInt(preferenceConstantHeight);
   }
   return new Rectangle(x, y, width, height);
 }
  /**
   * initialize the background for a graphical element
   *
   * @param view the element to initialize
   * @param store the preference store
   * @param elementName the name to the element
   */
  public static void initBackgroundFromPrefs(
      View view, final IPreferenceStore store, String elementName) {
    if (!usePreferenceInitializer(view)) {
      return;
    }

    String fillColorConstant =
        getpreferenceKey(view, elementName, PreferenceConstantHelper.COLOR_FILL);
    String gradientColorConstant =
        getpreferenceKey(view, elementName, PreferenceConstantHelper.COLOR_GRADIENT);
    String gradientPolicyConstant =
        getpreferenceKey(view, elementName, PreferenceConstantHelper.GRADIENT_POLICY);
    String shadowConstant = getpreferenceKey(view, elementName, PreferenceConstantHelper.SHADOW);
    String elementIcon = getpreferenceKey(view, elementName, PreferenceConstantHelper.ELEMENTICON);
    String qualifiedName =
        getpreferenceKey(view, elementName, PreferenceConstantHelper.QUALIFIEDNAME);

    org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(store, fillColorConstant);
    ViewUtil.setStructuralFeatureValue(
        view,
        NotationPackage.eINSTANCE.getFillStyle_FillColor(),
        FigureUtilities.RGBToInteger(fillRGB));

    FillStyle fillStyle = (FillStyle) view.getStyle(NotationPackage.Literals.FILL_STYLE);
    fillStyle.setFillColor(FigureUtilities.RGBToInteger(fillRGB).intValue());

    if (store.getBoolean(gradientPolicyConstant)) {
      GradientPreferenceConverter gradientPreferenceConverter =
          new GradientPreferenceConverter(store.getString(gradientColorConstant));
      fillStyle.setGradient(gradientPreferenceConverter.getGradientData());
      fillStyle.setTransparency(gradientPreferenceConverter.getTransparency());
    }

    EditingDomain domain = EMFHelper.resolveEditingDomain(view);
    if (domain instanceof TransactionalEditingDomain) {
      TransactionalEditingDomain editingDomain = (TransactionalEditingDomain) domain;
      // shadow
      RecordingCommand shadowcommand =
          AnnotationStyleProvider.getSetShadowCommand(
              editingDomain, view, store.getBoolean(shadowConstant));
      if (shadowcommand.canExecute()) {
        shadowcommand.execute();
      }
      // icon label
      RecordingCommand namelabelIconCommand =
          AnnotationStyleProvider.getSetElementIconCommand(
              editingDomain, view, store.getBoolean(elementIcon));
      if (namelabelIconCommand.canExecute()) {
        namelabelIconCommand.execute();
      }
      // qualified name
      if (!store.getBoolean(qualifiedName)) {
        RecordingCommand qualifiedNameCommand =
            AnnotationStyleProvider.getSetQualifiedNameDepthCommand(editingDomain, view, 1000);
        if (qualifiedNameCommand.canExecute()) {
          qualifiedNameCommand.execute();
        }
      }
    }
  }
  protected void createEntryPoint(Edge edge, Diagram subdiagram) {
    Transition transition = (Transition) edge.getElement();
    Region entryPointContainer = getEntryPointContainer(transition);
    Entry entryPoint = createSemanticEntryPoint(transition);

    // re-wire old transition to targeting the selected state
    transition.setTarget((State) subdiagram.getElement());
    View oldTarget = edge.getTarget();
    edge.setTarget(getContextObject());

    // create node for entry point
    View entryPointContainerView =
        helper.getViewForSemanticElement(entryPointContainer, subdiagram);
    View entryPointRegionCompartment =
        ViewUtil.getChildBySemanticHint(entryPointContainerView, SemanticHints.REGION_COMPARTMENT);
    Node entryNode =
        ViewService.createNode(
            entryPointRegionCompartment, entryPoint, SemanticHints.ENTRY, preferencesHint);
    ViewService.createEdge(
        entryNode,
        oldTarget,
        entryPoint.getOutgoingTransitions().get(0),
        SemanticHints.TRANSITION,
        preferencesHint);

    addEntryPointSpec(transition, entryPoint);
  }
Exemple #14
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;
  }
  /**
   * Get the snap back hint for the view.
   *
   * @param view the view to snap back.
   * @return the snap back hint.
   */
  private String getSnapBackHint(View view) {

    String diagramType = view.getDiagram().getType();
    String parentType = ViewUtil.getViewContainer(view).getType();
    String labelType = view.getType();

    return diagramType + "_" + parentType + "-" + labelType;
  }
Exemple #16
0
 /** @generated */
 public Node createRequirementsGroup_2007(
     EObject domainElement,
     View containerView,
     int index,
     boolean persisted,
     PreferencesHint preferencesHint) {
   Node node = NotationFactory.eINSTANCE.createNode();
   node.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
   node.getStyles().add(NotationFactory.eINSTANCE.createFontStyle());
   node.getStyles().add(NotationFactory.eINSTANCE.createFillStyle());
   node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
   node.setType(RdalVisualIDRegistry.getType(RequirementsGroupEditPart.VISUAL_ID));
   ViewUtil.insertChildView(containerView, node, index, persisted);
   node.setElement(domainElement);
   stampShortcut(containerView, node);
   // initializeFromPreferences
   final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();
   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 label5013 =
       createLabel(node, RdalVisualIDRegistry.getType(RequirementsGroupNameEditPart.VISUAL_ID));
   createCompartment(
       node,
       RdalVisualIDRegistry.getType(RequirementsGroupRequirementsCompartmentEditPart.VISUAL_ID),
       true,
       false,
       false,
       false);
   return node;
 }
      protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info)
          throws ExecutionException {

        if (null == viewAdapter || null == newValue)
          return CommandResult.newCancelledCommandResult();

        View view = (View) viewAdapter.getAdapter(View.class);
        Point p = (Point) newValue.getAdapter(IPropertyValueDeferred.class);
        ViewUtil.setStructuralFeatureValue(
            view, NotationPackage.eINSTANCE.getLocation_X(), Integer.valueOf(p.x));
        ViewUtil.setStructuralFeatureValue(
            view, NotationPackage.eINSTANCE.getLocation_Y(), Integer.valueOf(p.y));

        // clear for garbage collection
        viewAdapter = null;
        newValue = null;
        return CommandResult.newOKCommandResult();
      }
 /** @generated */
 protected Command getSemanticCommand(IEditCommandRequest request) {
   IEditCommandRequest completedRequest = completeRequest(request);
   Object editHelperContext = completedRequest.getEditHelperContext();
   if (editHelperContext instanceof View
       || (editHelperContext instanceof IEditHelperContext
           && ((IEditHelperContext) editHelperContext).getEObject() instanceof View)) {
     // no semantic commands are provided for pure design elements
     return null;
   }
   if (editHelperContext == null) {
     editHelperContext = ViewUtil.resolveSemanticElement((View) getHost().getModel());
   }
   IElementType elementType = ElementTypeRegistry.getInstance().getElementType(editHelperContext);
   if (elementType
       == ElementTypeRegistry.getInstance()
           .getType("org.eclipse.gmf.runtime.emf.type.core.default")) { // $NON-NLS-1$
     elementType = null;
   }
   Command semanticCommand = getSemanticCommandSwitch(completedRequest);
   if (elementType != null) {
     if (semanticCommand != null) {
       ICommand command =
           semanticCommand instanceof ICommandProxy
               ? ((ICommandProxy) semanticCommand).getICommand()
               : new CommandProxy(semanticCommand);
       completedRequest.setParameter(
           FlowDesigner.diagram.edit.helpers.FlowDesignerBaseEditHelper.EDIT_POLICY_COMMAND,
           command);
     }
     ICommand command = elementType.getEditCommand(completedRequest);
     if (command != null) {
       if (!(command instanceof CompositeTransactionalCommand)) {
         TransactionalEditingDomain editingDomain =
             ((IGraphicalEditPart) getHost()).getEditingDomain();
         command =
             new CompositeTransactionalCommand(editingDomain, command.getLabel()).compose(command);
       }
       semanticCommand = new ICommandProxy(command);
     }
   }
   boolean shouldProceed = true;
   if (completedRequest instanceof DestroyRequest) {
     shouldProceed = shouldProceed((DestroyRequest) completedRequest);
   }
   if (shouldProceed) {
     if (completedRequest instanceof DestroyRequest) {
       TransactionalEditingDomain editingDomain =
           ((IGraphicalEditPart) getHost()).getEditingDomain();
       Command deleteViewCommand =
           new ICommandProxy(new DeleteCommand(editingDomain, (View) getHost().getModel()));
       semanticCommand =
           semanticCommand == null ? deleteViewCommand : semanticCommand.chain(deleteViewCommand);
     }
     return semanticCommand;
   }
   return null;
 }
  /** @generated */
  public Node createViewTable_1002(
      EObject domainElement,
      View containerView,
      int index,
      boolean persisted,
      PreferencesHint preferencesHint) {
    Node node = NotationFactory.eINSTANCE.createNode();
    node.getStyles().add(NotationFactory.eINSTANCE.createDescriptionStyle());
    node.getStyles().add(NotationFactory.eINSTANCE.createFontStyle());

    FillStyle fillStyle = NotationFactory.eINSTANCE.createFillStyle();
    Color color = ViewTableEditPart.getDeclaredBackgroundColor();
    fillStyle.setFillColor(FigureUtilities.colorToInteger(color));
    node.getStyles().add(fillStyle);
    LineStyle lineStyle = NotationFactory.eINSTANCE.createLineStyle();
    lineStyle.setLineColor(FigureUtilities.RGBToInteger(new org.eclipse.swt.graphics.RGB(0, 0, 0)));
    node.getStyles().add(lineStyle);

    node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
    node.setType(SqlmodelVisualIDRegistry.getType(ViewTableEditPart.VISUAL_ID));
    ViewUtil.insertChildView(containerView, node, index, persisted);
    node.setElement(domainElement);
    stampShortcut(containerView, node);
    // initializeFromPreferences
    final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();
    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());
    }
    Node label4002 =
        createLabel(node, SqlmodelVisualIDRegistry.getType(ViewTableNameEditPart.VISUAL_ID));
    createCompartment(
        node,
        SqlmodelVisualIDRegistry.getType(ViewTableViewedColumnsEditPart.VISUAL_ID),
        false,
        false,
        true,
        true);
    createCompartment(
        node,
        SqlmodelVisualIDRegistry.getType(ViewTableViewedTablesEditPart.VISUAL_ID),
        false,
        false,
        true,
        true);
    return node;
  }
  @BeforeClass
  public static void prepareContainerForTest() throws Exception {
    try {
      View blockView =
          ViewUtil.getChildBySemanticHint(
              getDiagramView(), SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID);
      View blockStructureView =
          ViewUtil.getChildBySemanticHint(
              blockView, SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID);
      View partView =
          createGraphicalNode(
              SysMLElementTypes.PART_PROPERTY,
              SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID,
              blockStructureView);
      View partContainerView =
          ViewUtil.getChildBySemanticHint(
              partView, SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID);
      if (partContainerView == null) {
        throw new Exception("Unable to prepare container for test.");
      }

      View nestedPartView =
          createGraphicalNode(
              UMLElementTypes.PROPERTY,
              SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID,
              partContainerView);
      containerView =
          ViewUtil.getChildBySemanticHint(
              nestedPartView, SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID);
      if (containerView == null) {
        throw new Exception("Unable to prepare nested container for test.");
      }

      // prepare container package (getDiagramView references the shown Block).
      containerPackage =
          EMFCoreUtil.getContainer(
              getDiagramView().getElement(), UMLPackage.eINSTANCE.getPackage());

    } catch (Exception e) {
      throw new Exception("Unable to prepare container for test.", e);
    }
  }
  @Override
  protected void initializeFromPreferences(View view) {
    super.initializeFromPreferences(view);

    IPreferenceStore store = (IPreferenceStore) getPreferencesHint().getPreferenceStore();
    if (store == null) {
      return;
    }

    // Get default size from preferences use set view size.
    String preferenceConstantWitdh =
        PreferenceInitializerForElementHelper.getpreferenceKey(
            view, view.getType(), PreferenceConstantHelper.WIDTH);
    String preferenceConstantHeight =
        PreferenceInitializerForElementHelper.getpreferenceKey(
            view, view.getType(), PreferenceConstantHelper.HEIGHT);
    ViewUtil.setStructuralFeatureValue(
        view, NotationPackage.eINSTANCE.getSize_Width(), store.getInt(preferenceConstantWitdh));
    ViewUtil.setStructuralFeatureValue(
        view, NotationPackage.eINSTANCE.getSize_Height(), store.getInt(preferenceConstantHeight));
  }
  /**
   * This methods looks for inconsistent views to delete in case a Part aggregation kind changes.
   *
   * @param modifiedObject the modified {@link EObject}
   * @return the list of {@link View} to delete
   */
  protected Set<View> getViewsToDestroy(EObject modifiedObject) {
    Set<View> viewsToDestroy = new HashSet<View>();

    Iterator<View> viewIt =
        CrossReferencerUtil.getCrossReferencingViews(modifiedObject, ElementTypes.DIAGRAM_ID)
            .iterator();
    while (viewIt.hasNext()) {
      View view = viewIt.next();

      String containerType =
          ViewUtil.getViewContainer(view) != null
              ? ViewUtil.getViewContainer(view).getType()
              : null;

      if (SysMLGraphicalTypes.COMPARTMENT_SYSML_PART_AS_LIST_ID.equals(containerType)) {
        viewsToDestroy.add(view);
      }
    }

    return viewsToDestroy;
  }
  /**
   * This operation checks if, after resizing the ShapeNodeEditPart, all links anchors will fit
   * inside the figure in case their positions are preserved
   *
   * @param shapeEP That shape being resized
   * @param sizeDelta The SizeDelta for the resize
   * @param preserveAxis The axisxxx
   * @return The new SizeDelta to preserve anchors' positions
   */
  public static Dimension getSizeDeltaToFitAnchors(
      ShapeNodeEditPart shapeEP, Dimension sizeDelta, int preserveAxis) {

    Dimension newSizeDelta = new Dimension(sizeDelta);
    View view = (View) shapeEP.getModel();
    Rectangle figureBounds = shapeEP.getFigure().getBounds();

    List<Edge> sourceList = ViewUtil.getSourceConnections(view);
    List<Edge> targetList = ViewUtil.getTargetConnections(view);

    for (Edge edge : sourceList) {
      IdentityAnchor anchor = (IdentityAnchor) edge.getSourceAnchor();
      modifySizeDeltaToFitAnchor(anchor, newSizeDelta, preserveAxis, figureBounds);
    }
    for (Edge edge : targetList) {
      IdentityAnchor anchor = (IdentityAnchor) edge.getTargetAnchor();
      modifySizeDeltaToFitAnchor(anchor, newSizeDelta, preserveAxis, figureBounds);
    }

    return newSizeDelta;
  }
 public int getViewChildrenSize() {
   int count = 0;
   Lifeline lifeline = ((Lifeline) getParentEditPart().getNotationView().getElement());
   EList children = getParentEditPart().getNotationView().getChildren();
   for (Object object : children) {
     View view = (View) object;
     if (lifeline != ViewUtil.resolveSemanticElement(view)) {
       count++;
     }
   }
   return count;
 }
  /**
   * initialize the routing for a graphical element
   *
   * @param view the element to initialize
   * @param store the preference store
   * @param elementName the name to the element
   */
  public static void initRoutingFromPrefs(
      View view, final IPreferenceStore store, String elementName) {
    if (!usePreferenceInitializer(view)) {
      return;
    }

    Routing routing =
        Routing.get(
            store.getInt(
                getpreferenceKey(view, elementName, PreferenceConstantHelper.ROUTING_STYLE)));
    if (routing != null) {
      ViewUtil.setStructuralFeatureValue(
          view, NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing);
    }
    Smoothness smoothness =
        Smoothness.get(
            store.getInt(getpreferenceKey(view, elementName, PreferenceConstantHelper.SMOOTHNESS)));
    if (routing != null) {
      ViewUtil.setStructuralFeatureValue(
          view, NotationPackage.eINSTANCE.getRoutingStyle_Smoothness(), smoothness);
    }
    JumpLinkStatus jumpLinkStatus =
        JumpLinkStatus.get(
            getpreferenceKey(view, elementName, PreferenceConstantHelper.JUMPLINK_STATUS));
    if (routing != null) {
      ViewUtil.setStructuralFeatureValue(
          view, NotationPackage.eINSTANCE.getRoutingStyle_JumpLinkStatus(), jumpLinkStatus);
    }

    JumpLinkType jumpLinkType =
        JumpLinkType.get(
            getpreferenceKey(view, elementName, PreferenceConstantHelper.JUMPLINK_TYPE));
    if (routing != null) {
      ViewUtil.setStructuralFeatureValue(
          view, NotationPackage.eINSTANCE.getRoutingStyle_JumpLinkType(), jumpLinkType);
    }
    boolean jumpLinksReverse =
        store.getBoolean(
            getpreferenceKey(view, elementName, PreferenceConstantHelper.JUMPLINK_REVERSE));
    ViewUtil.setStructuralFeatureValue(
        view, NotationPackage.eINSTANCE.getRoutingStyle_JumpLinksReverse(), jumpLinksReverse);

    boolean routingObstruction =
        store.getBoolean(
            getpreferenceKey(
                view, elementName, PreferenceConstantHelper.ROUTING_POLICY_OBSTRUCTION));
    ViewUtil.setStructuralFeatureValue(
        view, NotationPackage.eINSTANCE.getRoutingStyle_AvoidObstructions(), routingObstruction);

    boolean routingDistance =
        store.getBoolean(
            getpreferenceKey(view, elementName, PreferenceConstantHelper.ROUTING_POLICY_DISTANCE));
    ViewUtil.setStructuralFeatureValue(
        view, NotationPackage.eINSTANCE.getRoutingStyle_ClosestDistance(), routingDistance);
  }
 /** Creates a new {@link Diagram} and copies child elements */
 protected Diagram createSubdiagram() {
   View contextView = getContextObject();
   State contextElement = (State) contextView.getElement();
   Diagram subdiagram =
       ViewService.createDiagram(contextElement, StatechartDiagramEditor.ID, preferencesHint);
   View figureCompartment =
       ViewUtil.getChildBySemanticHint(contextView, SemanticHints.STATE_FIGURE_COMPARTMENT);
   getResource().getContents().add(subdiagram);
   while (figureCompartment.getChildren().size() > 0) {
     subdiagram.insertChild((View) figureCompartment.getChildren().get(0));
   }
   return subdiagram;
 }
  /**
   * initialize the foreground for a graphical element
   *
   * @param view the element to initialize
   * @param store the preference store
   * @param elementName the name to the element
   */
  public static void initForegroundFromPrefs(
      View view, final IPreferenceStore store, String elementName) {
    if (!usePreferenceInitializer(view)) {
      return;
    }

    String lineColorConstant =
        getpreferenceKey(view, elementName, PreferenceConstantHelper.COLOR_LINE);
    org.eclipse.swt.graphics.RGB lineRGB = PreferenceConverter.getColor(store, lineColorConstant);
    ViewUtil.setStructuralFeatureValue(
        view,
        NotationPackage.eINSTANCE.getLineStyle_LineColor(),
        FigureUtilities.RGBToInteger(lineRGB));
  }
  @BeforeClass
  public static void prepareContainerForTest() throws Exception {
    try {
      createNodeFromPalette("blockdefinition.tool.interface", getDiagramView(), true);
      View blockView =
          ViewUtil.getChildBySemanticHint(
              getDiagramView(), UMLGraphicalTypes.SHAPE_UML_INTERFACE_AS_CLASSIFIER_ID);
      containerView =
          ViewUtil.getChildBySemanticHint(
              blockView, UMLGraphicalTypes.COMPARTMENT_UML_PROPERTY_AS_LIST_ID);

      if (containerView == null) {
        throw new Exception("Unable to prepare container for test.");
      }

      // Ensure the compartment is visible (required for EditPart to be found)
      if (!containerView.isVisible()) {
        changeVisibility(containerView);
      }

    } catch (Exception e) {
      throw new Exception("Unable to prepare container for test.", e);
    }
  }
  /**
   * initialize the status of the compartment for the node (Showed or hidden)
   *
   * @param view the element to initialize
   * @param store the preference store
   * @param elementName the name to the element
   */
  public static void initCompartmentsStatusFromPrefs(
      View view, final IPreferenceStore store, String elementName) {
    EList<?> children = view.getPersistedChildren();
    if (children != null) {
      for (Object object : children) {

        // we look for the name of the compartment for this view
        EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View) object);
        IGraphicalEditPart epp = (IGraphicalEditPart) dummyEP;
        IFigure fig1 = epp.getFigure();

        if (fig1 instanceof ResizableCompartmentFigure) {
          String compartmentName = ((ResizableCompartmentFigure) fig1).getCompartmentTitle();
          if (compartmentName != null) {
            String diagramKind = view.getDiagram().getType();
            String preferenceKey =
                PreferenceConstantHelper.getCompartmentElementConstant(
                    diagramKind + "_" + elementName,
                    compartmentName,
                    PreferenceConstantHelper.COMPARTMENT_VISIBILITY); // $NON-NLS-1$
            boolean value = store.getBoolean(preferenceKey);

            if (!value) { // the default value is true : nothing to
              // do
              ENamedElement namedElement =
                  PackageUtil.getElement("notation.View.visible"); // $NON-NLS-1$
              ViewUtil.setStructuralFeatureValue(
                  (View) object, (EStructuralFeature) namedElement, value);
            }

            String compartmentNameVisibilityPreference =
                PreferenceConstantHelper.getCompartmentElementConstant(
                    diagramKind + "_" + elementName,
                    compartmentName,
                    PreferenceConstantHelper.COMPARTMENT_NAME_VISIBILITY); // $NON-NLS-1$
            boolean showCompartmentName = store.getBoolean(compartmentNameVisibilityPreference);
            View childView = (View) object;
            TitleStyle style =
                (TitleStyle) childView.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
            if (style != null) {
              style.setShowTitle(showCompartmentName);
            }
          }
        }
        dummyEP = null;
      }
    }
  }
 private Float getPosition(InteractionFragment fragment) {
   if (fragment == null) {
     return null;
   }
   View view = getGraphicalView(fragment);
   if (view == null) {
     return null;
   }
   Float[] preferPosition = cachePositions != null ? cachePositions.get(view) : null;
   EObject hostElement = ViewUtil.resolveSemanticElement(view);
   EditPart editPart = DiagramEditPartsUtil.getEditPartFromView(view, fragmentRootEditPart);
   if (fragment instanceof MessageOccurrenceSpecification
       && hostElement instanceof Message
       && editPart instanceof ConnectionNodeEditPart) {
     boolean isStart = fragment == ((Message) hostElement).getSendEvent();
     Point location =
         getAbsoluteEdgeExtremity((ConnectionNodeEditPart) editPart, isStart, preferPosition);
     if (location != null) {
       return isStart ? location.y - HALF_UNIT : location.y + HALF_UNIT;
     }
   } else if (fragment instanceof ExecutionOccurrenceSpecification
       && hostElement instanceof ExecutionSpecification
       && editPart instanceof IGraphicalEditPart) {
     Rectangle bounds = getAbsoluteBounds((IGraphicalEditPart) editPart, preferPosition);
     if (bounds != null) {
       if (bounds.height <= 0) {
         bounds.height = 50; // LifelineXYLayoutEditPolicy.EXECUTION_INIT_HEIGHT;
       }
       if (fragment == ((ExecutionSpecification) hostElement).getStart()) {
         return bounds.y - HALF_UNIT;
       } else {
         return bounds.bottom() + HALF_UNIT;
       }
     }
   } else if (view instanceof Shape && editPart instanceof IGraphicalEditPart) {
     Rectangle bounds = getAbsoluteBounds((IGraphicalEditPart) editPart, preferPosition);
     if (bounds != null) {
       return bounds.y * CONVERT_UNIT;
     }
   }
   return null;
 }