/**
   * 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();
        }
      }
    }
  }
Example #2
0
  protected ZombieStereotypesDescriptor getZombieStereotypes(Resource resource) {
    ZombieStereotypesDescriptor result = null;
    Element root = getRootUMLElement(resource);

    // Only check for zombies in resources that we can modify (those being the resources in the user
    // model opened in the editor)
    if ((root instanceof Package)
        && !EMFHelper.isReadOnly(resource, EMFHelper.resolveEditingDomain(root))) {
      result = getZombieStereotypes(resource, (Package) root);
    }

    return result;
  }
  protected Resource getNotationResource(ModelSet modelSet, EObject owner, EObject element) {
    if (element
        == null) { // If the element is null, the root element of the main model will be used.
      // Return the main notation resource
      return NotationUtils.getNotationResource(modelSet);
    }
    URI uriWithoutExtension = element.eResource().getURI().trimFileExtension();

    URI notationURI =
        uriWithoutExtension.appendFileExtension(NotationModel.NOTATION_FILE_EXTENSION);
    Resource notationResource = modelSet.getResource(notationURI, false);

    // The resource doesn't exist. Maybe we're trying to create a
    // diagram on a pure-UML library. Try to create a new resource
    if (notationResource == null) {
      notationResource = modelSet.createResource(notationURI);
      if (notationResource == null) {
        modelSet.getResources().remove(notationResource);
        return null;
      }

      EditingDomain editingDomain = EMFHelper.resolveEditingDomain(element);

      if (EMFHelper.isReadOnly(notationResource, editingDomain)) {
        // Check whether the resource can be made writable
        IReadOnlyHandler2 roHandler = ReadOnlyManager.getReadOnlyHandler(editingDomain);
        if (roHandler
            .canMakeWritable(ReadOnlyAxis.anyAxis(), new URI[] {notationResource.getURI()})
            .or(false)) {
          return notationResource; // The read-only manager will eventually ask for a user
          // confirmation
        } else {
          modelSet.getResources().remove(notationResource);
          return null; // The resource can't be made writable; don't go further
        }
      }
    }

    return notationResource;
  }