/**
  * Returns the image for the element
  *
  * @param editPart the edit part that displays the element
  * @return the image
  */
 public Image getImage(GraphicalEditPart editPart) {
   Element element = getUMLElement(editPart);
   String key = "";
   if (element instanceof NamedElement) {
     key = ((NamedElement) element).getName() + "::" + ((NamedElement) element).getVisibility();
   } else if (element != null) {
     key = element.getClass().getName();
   } else {
     return null;
   }
   ImageRegistry imageRegistry = Activator.getDefault().getImageRegistry();
   Image image = imageRegistry.get(key);
   ImageDescriptor descriptor = null;
   if (image == null) {
     AdapterFactory factory = Activator.getDefault().getItemProvidersAdapterFactory();
     IItemLabelProvider labelProvider =
         (IItemLabelProvider) factory.adapt(getUMLElement(editPart), IItemLabelProvider.class);
     if (labelProvider != null) {
       descriptor =
           ExtendedImageRegistry.getInstance()
               .getImageDescriptor(labelProvider.getImage(getUMLElement(editPart)));
     }
     if (descriptor == null) {
       descriptor = ImageDescriptor.getMissingImageDescriptor();
     }
     imageRegistry.put(key, descriptor);
     image = imageRegistry.get(key);
   }
   return image;
 }
  /** @{inheritDoc */
  @Override
  protected IDialogSettings getDialogSettings() {
    IDialogSettings settings =
        Activator.getDefault().getDialogSettings().getSection(DIALOG_SETTINGS);

    if (settings == null) {
      settings = Activator.getDefault().getDialogSettings().addNewSection(DIALOG_SETTINGS);
    }

    return settings;
  }
Beispiel #3
0
  /**
   * Find the image (SWT) in registry Store image in registry if it is not found
   *
   * @param umlImage to retrieve as SWT Image in registry
   * @return the stored SWT image
   */
  public static Image getImageInRegistry(
      org.eclipse.uml2.uml.Image umlImage, VisibilityKind visibility) {
    // Retrieve registry
    ImageRegistry papyrusRegistry = getDefault().getImageRegistry();

    // Get image id for registry
    String image_id = ImageUtil.getImageId(umlImage);
    if (visibility != null) {
      image_id = image_id + "_" + visibility.getLiteral();
    }

    // Get SWT image for shape in the registry
    Image image = papyrusRegistry.get(image_id);

    // If image was not found in registry,
    // try to find an image and to update registry
    if (image == null) {

      try {
        // Try to retrieve image from UML Image content property
        image = ImageUtil.getContent(umlImage);
      } catch (Exception e) {
        // Activator.log.error(e);
      }

      // If no image was found in Content
      // Try to retrieve image from UML Image location property
      if (image == null) {
        image = ImageUtil.getImageFromLocation(umlImage);
      }

      // Add visibility decorator
      if (visibility != null) {

        getDefault();
        ImageDescriptor visDesc =
            Activator.getImageDescriptor(
                UML_VIS_ICONS_16x16 + "VisibilityKind_" + visibility.getLiteral() + ".gif");

        // Overlay custom image over base image
        OverlayVisibilityIcon overlayIcon = new OverlayVisibilityIcon(image, visDesc);
        image = overlayIcon.getImage();
      }

      if (image != null) {
        // Store image in registry
        ImageData imdata = image.getImageData();
        papyrusRegistry.put(image_id, ImageDescriptor.createFromImageData(imdata));
        image = papyrusRegistry.get(image_id);
      }
    }

    return image;
  }
  /**
   * saves the given root memento with the given key in the preference area
   *
   * @param xmlMemento the memento to save
   * @param key the key for the preference store
   */
  private static void saveMemento(XMLMemento xmlMemento, String key) {
    // save memento
    StringWriter writer = new StringWriter();
    try {
      xmlMemento.save(writer);

      if (getPreferenceStore() != null) {
        getPreferenceStore().setValue(key, writer.toString());
      }
    } catch (IOException e) {
      Activator.getDefault().logError("input/ouput exception", e);
    }
  }
 /**
  * Retrieves the root memento from the plugin preferences if there were existing palette
  * customizations.
  *
  * @return the root memento if there were existing customizations; null otherwise
  */
 protected static XMLMemento getExistingCustomizations() {
   String sValue = getPreferenceStore().getString(PALETTE_CUSTOMIZATIONS_ID);
   try {
     if (sValue != null && !sValue.equals("")) { // $NON-NLS-1$
       XMLMemento rootMemento = XMLMemento.createReadRoot(new StringReader(sValue));
       return rootMemento;
     } else {
       return XMLMemento.createWriteRoot(PALETTE_CUSTOMIZATIONS_ID);
     }
   } catch (WorkbenchException e) {
     Activator.getDefault().logError("Impossible to read preferences", e);
   }
   return null;
 }
 /**
  * Retrieves the root memento from the plugin preferences if there were existing local palette
  * redefinitions.
  *
  * @return the root memento if there were existing customizations, a newly created one otherwise
  *     (empty one)
  */
 protected static XMLMemento getLocalRedefinitions() {
   String sValue = getPreferenceStore().getString(PALETTE_REDEFINITIONS);
   try {
     if (sValue != null && !sValue.equals("")) { // $NON-NLS-1$
       XMLMemento rootMemento = XMLMemento.createReadRoot(new StringReader(sValue));
       return rootMemento;
     } else {
       return XMLMemento.createWriteRoot(PALETTE_REDEFINITIONS);
     }
   } catch (WorkbenchException e) {
     Activator.getDefault()
         .logError("Impossible to read preferences for palette local redefinitions", e);
   }
   return null;
 }
Beispiel #7
0
  /**
   * Returns an <code>org.eclipse.swt.graphics.Image</code> identified by its key.<br>
   * By default, it returns a default image. This image is the image placed in the directory
   * <em>resources/icons/default.gif</em>
   *
   * @param key the key of the image
   * @param visKey must not be null : "" || "public" || "private" ...
   * @return the Image
   */
  public static Image getImage(String key, String visKey) {

    String image_id = key;
    if (!"".equals(visKey)) {
      image_id = image_id + "::" + visKey;
    }

    ImageRegistry registry = getDefault().getImageRegistry();
    Image image = registry.get(image_id);

    if (image == null) { // Image not yet in registry

      // Get the descriptor of the image without visibility
      ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(ID, key);

      if (!"".equals(visKey)) { // Add visibility overlay

        Image initialImage = desc.createImage();
        getDefault();
        ImageDescriptor visDesc =
            Activator.getImageDescriptor(UML_VIS_ICONS_16x16 + "VisibilityKind_" + visKey + ".gif");

        // Overlay custom image over base image
        OverlayVisibilityIcon overlayIcon = new OverlayVisibilityIcon(initialImage, visDesc);
        image = overlayIcon.getImage();

        registry.put(image_id, image);

      } else {
        registry.put(key, desc);
      }

      image = registry.get(image_id);
    }

    if ((image == null) && !image_id.equals(DEFAULT_IMAGE)) {
      image = getImage(DEFAULT_IMAGE);
    }

    return image;
  }
 /**
  * Returns the preference store used to store palette preferences.
  *
  * @return the preference store of this plugin
  */
 protected static IPreferenceStore getPreferenceStore() {
   return Activator.getDefault().getPreferenceStore();
 }
 /**
  * Computes the string that displays the stereotypes for the current element
  *
  * @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
  * @return the string that represent the stereotypes
  */
 public String stereotypesToDisplay(
     GraphicalEditPart editPart,
     String separator,
     String stereotypesToDisplay,
     String stereotypeWithQualifiedName) {
   // AL Changes Feb. 07 - Beg
   // Style Handling for STEREOTYPE_NAME_APPEARANCE from
   // ProfileApplicationPreferencePage
   // Stereotype displayed according to UML standard (first letter forced
   // to lower case) -
   // default -
   // or kept as entered by user (user controlled)
   // 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 "";
   }
   String sNameAppearance =
       store.getString(UMLVisualInformationPapyrusConstant.P_STEREOTYPE_NAME_APPEARANCE);
   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 + name + 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 + name + separator;
         }
       }
     }
   }
   if (out.endsWith(",")) {
     return out.substring(0, out.length() - 1);
   }
   if (out.endsWith(separator)) {
     return out.substring(0, out.length() - separator.length());
   }
   return out;
 }
 /**
  * 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;
 }