Example #1
0
  /**
   * this method returns the icon image that represents the first applied stereotype.
   *
   * @param element the stereotyped element
   * @return {@link image} of the icon
   */
  public static Image getIconElement(Element element, boolean withVisibilityDecorator) {

    List<Stereotype> stereotypeList = element.getAppliedStereotypes();
    if (stereotypeList == null || stereotypeList.isEmpty()) {
      return null;
    }
    return getIconElement(element, stereotypeList.get(0), withVisibilityDecorator);
  }
 protected String getStereotype(Element element) {
   final List stereotypes = element.getAppliedStereotypes();
   if (stereotypes != null && stereotypes.size() != 0) {
     final StringBuffer sb = new StringBuffer();
     appendStereotype(element, sb, false);
     return sb.toString();
   }
   return CoreStringUtil.Constants.EMPTY_STRING;
 }
  /**
   * Default Constructor.
   *
   * @param parentShell the parent shell
   * @param theElement the UML element to be modified
   */
  public ChooseSetStereotypeDialog(Shell parentShell, org.eclipse.uml2.uml.Element theElement) {
    super(parentShell, "Applicable Stereotypes: ", "Applied Stereotypes: ");
    labelProvider = new StereotypeLabelProvider();
    decoratedContentProposalProvider = new StereotypeContentProposalProvider();

    Iterator<Stereotype> stereotypes = theElement.getAppliedStereotypes().iterator();
    while (stereotypes.hasNext()) {
      selectedElementList.addElement(stereotypes.next());
    }

    stereotypes = theElement.getApplicableStereotypes().iterator();
    while (stereotypes.hasNext()) {
      Stereotype current = stereotypes.next();
      if (!selectedElementList.contains(current)) {
        possibleElementList.addElement(current);
      }
    }
  }
 protected void appendStereotype(
     final Element element, final StringBuffer sb, final boolean includeWrappers) {
   boolean first = true;
   final List stereotypes = element.getAppliedStereotypes();
   if (stereotypes.isEmpty()) {
     return;
   }
   if (includeWrappers) {
     sb.append("<<"); // $NON-NLS-1$
   }
   final Iterator iter = stereotypes.iterator();
   while (iter.hasNext()) {
     final Stereotype stereotype = (Stereotype) iter.next();
     if (!first) {
       sb.append(","); // $NON-NLS-1$
     }
     first = false;
     sb.append(stereotype.getName());
   }
   if (includeWrappers) {
     sb.append(">>"); // $NON-NLS-1$
   }
 }
  @Override
  public String stereotypesOnlyToDisplay() {
    Object hostModel = getHost().getModel();
    String result = ""; // $NON-NLS-1$
    View view = (View) hostModel;
    EObject viewElement = view.getElement();
    Element element = (Element) viewElement;
    Iterator<Stereotype> listStereotype = element.getAppliedStereotypes().iterator();
    StringBuffer buffer = new StringBuffer();
    while (listStereotype.hasNext()) {
      Stereotype stereotypec = listStereotype.next();
      String stereotype_string = stereotypec.getQualifiedName();
      buffer.append(stereotype_string);
      if (listStereotype.hasNext()) {
        buffer.append(","); // $NON-NLS-1$
      }
    }
    result = buffer.toString();

    if (result.length() != 0) {
      String stereotypespresentationKind =
          AppliedStereotypeHelper.getAppliedStereotypePresentationKind(view);

      // vertical representation
      if (UMLVisualInformationPapyrusConstant.STEREOTYPE_TEXT_VERTICAL_PRESENTATION.equals(
          stereotypespresentationKind)) {
        return Activator.ST_LEFT
            + stereotypesToDisplay(Activator.ST_RIGHT + "\n" + Activator.ST_LEFT, result, "")
            + Activator.ST_RIGHT;
      } else { // horizontal representation
        return Activator.ST_LEFT + stereotypesToDisplay(", ", result, "") + Activator.ST_RIGHT;
      }
    }

    return result;
  }
  /**
   * Drop a semantic element and create the corresponding view in the given container
   *
   * @param newContainer Semantic container
   * @param semanticElement Element to drop
   * @param containerView Container view
   * @param moveSemanticElement True to move the dropped semantic element or false to just show the
   *     element on a diagram
   */
  private void drop(
      final Element newContainer,
      final Element semanticElement,
      final DSemanticDecorator containerView,
      boolean moveSemanticElement) {
    final Session session = SessionManager.INSTANCE.getSession(newContainer);
    final Element oldContainer = semanticElement.getOwner();
    if (moveSemanticElement && oldContainer != newContainer) {
      // Manage stereotypes and profiles
      final List<Stereotype> stereotypesToApply = Lists.newArrayList();
      for (final Stereotype stereotype : semanticElement.getAppliedStereotypes()) {
        stereotypesToApply.add(stereotype);
      }

      // Move the semantic element to the selected container
      final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
      // The feature is set to null because the domain will deduce it
      Command cmd = AddCommand.create(domain, newContainer, null, semanticElement);
      if (cmd.canExecute()) {
        cmd.execute();
      }
      cmd = RemoveCommand.create(domain, oldContainer, null, semanticElement);
      if (cmd.canExecute()) {
        cmd.execute();
      }

      if (semanticElement instanceof UseCase) {
        // Reset the current element as subject
        cmd =
            SetCommand.create(
                domain,
                semanticElement,
                UMLPackage.Literals.USE_CASE__SUBJECT,
                SetCommand.UNSET_VALUE);
        if (cmd.canExecute()) {
          cmd.execute();
        }
        final List<Element> subjects = new ArrayList<Element>();
        subjects.add(newContainer);
        cmd =
            SetCommand.create(
                domain, semanticElement, UMLPackage.Literals.USE_CASE__SUBJECT, subjects);
        if (cmd.canExecute()) {
          cmd.execute();
        }
      }
      // Apply stereotypes on dropped element and apply the necessary
      // profiles automatically
      StereotypeServices.INSTANCE.applyAllStereotypes(semanticElement, stereotypesToApply);

      // Check if profile should be unapplied
      for (final Stereotype stereotype : stereotypesToApply) {
        StereotypeServices.INSTANCE.unapplyProfile(oldContainer, stereotype);
      }
    }

    // Show the semantic element on the diagram
    showView(
        semanticElement,
        containerView,
        session,
        "[self.getContainerView(newContainerView)/]"); //$NON-NLS-1$
  }