コード例 #1
0
  @Override
  protected boolean isCompatibleMetaclass(Object containerElement, Object metaclass) {
    Element semanticElement = UMLUtil.resolveUMLElement(containerElement);

    if (semanticElement == null) {
      return false;
    }

    if (metaclass instanceof Stereotype) {
      Stereotype stereotype = (Stereotype) metaclass;
      boolean res = semanticElement.getAppliedStereotype(stereotype.getQualifiedName()) != null;
      if (!res) {
        EClass definition = stereotype.getDefinition();
        for (EObject e : semanticElement.getStereotypeApplications()) {
          EClass c = e.eClass();
          if (definition != null && definition.isSuperTypeOf(c)) {
            res = true;
            break;
          }
        }
      }
      return res;
    }

    // TODO : We should use super.isCompatibleMetaclass(), but the super-implementation
    // may not be compatible with our implementation of getAdaptedValue()
    if (metaclass instanceof EClassifier) {
      return ((EClassifier) metaclass).isInstance(semanticElement);
    }

    return false;
  }
コード例 #2
0
 /** Refreshes the stereotype display */
 protected void refreshAppliedStereotypesPropertiesInCompartment(
     String stereotypesPropertiesToDisplay, IPapyrusNodeUMLElementFigure figure) {
   final boolean displayInCompartment =
       AppliedStereotypeHelper.hasAppliedStereotypesPropertiesToDisplay(
           (View) (View) getHost().getModel(),
           UMLVisualInformationPapyrusConstant.STEREOTYPE_COMPARTMENT_LOCATION);
   // if the string is not empty, then, the figure has to display it. Else,
   // it displays nothing
   final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
   final View node = editPart.getNotationView();
   int i = 0;
   // we go through all sub nodes
   while (i < node.getChildren().size()) {
     if ((node.getChildren().get(i)) instanceof Node) {
       final Node currentNode = (Node) (node.getChildren().get(i));
       if (currentNode.getType().equals(AppliedStereotypeConpartmentEditPart.ID)) {
         EObject stereotypeApplication = currentNode.getElement();
         Stereotype stereotype = UMLUtil.getStereotype(stereotypeApplication);
         if (stereotype != null
             && stereotypesPropertiesToDisplay.contains(stereotype.getQualifiedName())) {
           setVisivility(currentNode, displayInCompartment);
         } else {
           setVisivility(currentNode, false);
         }
       }
     }
     i++;
   }
 }
コード例 #3
0
    /**
     * Gets the proposals.
     *
     * @param contents the contents
     * @param position the position
     * @return the proposals
     */
    @Override
    public DecoratedContentProposal[] getProposals(String contents, int position) {
      ArrayList<DecoratedContentProposal> proposals = new ArrayList<DecoratedContentProposal>();

      if (possibleElementList != null) {
        Iterator it = possibleElementList.getElements().iterator();
        while (it.hasNext()) {
          final Stereotype stereotype = (Stereotype) it.next();
          final String simpleName = stereotype.getName();
          final String qualifiedName = stereotype.getQualifiedName();

          if (position < simpleName.length()
              && contents
                  .substring(0, position)
                  .equalsIgnoreCase(simpleName.substring(0, position))) {
            proposals.add(new DecoratedContentProposal(stereotype, labelProvider));
          }

          if (position < qualifiedName.length()
              && contents
                  .substring(0, position)
                  .equalsIgnoreCase(qualifiedName.substring(0, position))) {
            proposals.add(new DecoratedContentProposal(stereotype, qualifiedLabelProvider));
          }
        }
      }

      Collections.sort(proposals);
      return proposals.toArray(new DecoratedContentProposal[proposals.size()]);
    }
コード例 #4
0
 /**
  * Checks if is selectable element.
  *
  * @param text the text
  * @return true, if is selectable element
  */
 @Override
 protected boolean isSelectableElement(String text) {
   // iterate through all possibilities and return true if text corresponds
   Iterator<Stereotype> it = possibleElementList.getElements().iterator();
   while (it.hasNext()) {
     Stereotype element = it.next();
     if (text.equalsIgnoreCase(element.getName())
         || text.equalsIgnoreCase(element.getQualifiedName())) {
       return true;
     }
   }
   return false;
 }
コード例 #5
0
 /**
  * Run add element.
  *
  * @param name the name
  */
 @Override
 protected void runAddElement(String name) {
   // find the stereotype in the list
   Stereotype stereotype = null;
   Iterator<Stereotype> it = possibleElementList.getElements().iterator();
   while (it.hasNext()) {
     Stereotype element = it.next();
     if (name.equalsIgnoreCase(element.getName())
         || name.equalsIgnoreCase(element.getQualifiedName())) {
       stereotype = element;
     }
   }
   if (stereotype != null) {
     runActionAdd(stereotype);
   }
 }
  @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;
  }
コード例 #7
0
 /**
  * Returns a String that displays stereotypes (using their simple name or their qualified name)
  * and their properties
  *
  * @param editPart the edit part for which the label is edited
  * @param separator the separator used to split the string representing the stereotypes.
  * @param stereotypesToDisplay the list of stereotypes displayed
  * @param stereotypeWithQualifiedName the list of stereotypes displayed using their qualified
  *     names
  * @param stereotypesPropertiesToDisplay the list of properties to display
  * @return a string that displays stereotypes (using their simple name or their qualified name)
  *     and their properties
  */
 public String stereotypesAndPropertiesToDisplay(
     GraphicalEditPart editPart,
     String separator,
     String stereotypesToDisplay,
     String stereotypeWithQualifiedName,
     String stereotypesPropertiesToDisplay) {
   // Get the preference from PreferenceStore. there should be an assert
   final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
   if (store == null) {
     Activator.log.warn("The preference store was not found");
     return "";
   }
   // retrieve if the name of the stereotype has to put to lower case or
   // not
   String sNameAppearance =
       store.getString(UMLVisualInformationPapyrusConstant.P_STEREOTYPE_NAME_APPEARANCE);
   // changes the string of properties into a map, where the entries of the
   // map are the
   // stereotype qualified name, and the properties to display are the data
   Map<String, List<String>> propertiesToDisplay =
       parseStereotypeProperties(editPart, stereotypesToDisplay, stereotypesPropertiesToDisplay);
   StringTokenizer strQualifiedName = new StringTokenizer(stereotypesToDisplay, ",");
   String out = "";
   while (strQualifiedName.hasMoreElements()) {
     String currentStereotype = strQualifiedName.nextToken();
     // check if current stereotype is applied
     final Element umlElement = getUMLElement(editPart);
     Stereotype stereotype = umlElement.getAppliedStereotype(currentStereotype);
     if (stereotype != null) {
       String name = currentStereotype;
       if ((stereotypeWithQualifiedName.indexOf(currentStereotype)) == -1) {
         // property value contains qualifiedName ==> extract name
         // from it
         StringTokenizer strToken = new StringTokenizer(currentStereotype, "::");
         while (strToken.hasMoreTokens()) {
           name = strToken.nextToken();
         }
       }
       // AL Changes Feb. 07 - Beg
       // Handling STEREOTYPE_NAME_APPEARANCE preference (from
       // ProfileApplicationPreferencePage)
       // Previously lowercase forced onto first letter (standard UML)
       // stereotypesToDisplay = stereotypesToDisplay+name.substring(0,
       // 1).toLowerCase()+name.substring(1,
       // name.length())+","+separator;
       // check that the name has not already been added to the
       // displayed string
       if (sNameAppearance.equals(
           UMLVisualInformationPapyrusConstant.P_STEREOTYPE_NAME_DISPLAY_USER_CONTROLLED)) {
         if (out.indexOf(name) == -1) {
           out = out + Activator.ST_LEFT + name + Activator.ST_RIGHT + separator;
         }
       } else { // VisualInformationPapyrusConstants.P_STEREOTYPE_NAME_DISPLAY_UML_CONFORM))
         // {
         name = name.substring(0, 1).toLowerCase() + name.substring(1, name.length());
         if (out.indexOf(name) == -1) {
           out = out + Activator.ST_LEFT + name + Activator.ST_RIGHT + separator;
         }
       }
       // now should add all properties associated to this stereotype
       List<String> properties = propertiesToDisplay.get(stereotype.getQualifiedName());
       if (properties != null) {
         // retrieve property
         for (String propertyName : properties) {
           out =
               out
                   + StereotypeUtil.displayPropertyValue(
                       stereotype,
                       StereotypeUtil.getPropertyByName(stereotype, propertyName),
                       getUMLElement(editPart),
                       " ");
         }
       }
     }
   }
   if (out.endsWith(",")) {
     return out.substring(0, out.length() - 1);
   }
   if (out.endsWith(separator)) {
     return out.substring(0, out.length() - separator.length());
   }
   return out;
 }