/**
   * 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();
        }
      }
    }
  }
Exemplo n.º 2
0
  /** @generated */
  @Override
  public Object getPreferredValue(EStructuralFeature feature) {
    IPreferenceStore preferenceStore =
        (IPreferenceStore) getDiagramPreferencesHint().getPreferenceStore();
    Object result = null;

    if (feature == NotationPackage.eINSTANCE.getLineStyle_LineColor()
        || feature == NotationPackage.eINSTANCE.getFontStyle_FontColor()
        || feature == NotationPackage.eINSTANCE.getFillStyle_FillColor()) {
      String prefColor = null;
      if (feature == NotationPackage.eINSTANCE.getLineStyle_LineColor()) {
        prefColor =
            PreferenceConstantHelper.getElementConstant(
                "Metaclass", PreferenceConstantHelper.COLOR_LINE);
      } else if (feature == NotationPackage.eINSTANCE.getFontStyle_FontColor()) {
        prefColor =
            PreferenceConstantHelper.getElementConstant(
                "Metaclass", PreferenceConstantHelper.COLOR_FONT);
      } else if (feature == NotationPackage.eINSTANCE.getFillStyle_FillColor()) {
        prefColor =
            PreferenceConstantHelper.getElementConstant(
                "Metaclass", PreferenceConstantHelper.COLOR_FILL);
      }
      result =
          FigureUtilities.RGBToInteger(
              PreferenceConverter.getColor((IPreferenceStore) preferenceStore, prefColor));
    } else if (feature == NotationPackage.eINSTANCE.getFillStyle_Transparency()
        || feature == NotationPackage.eINSTANCE.getFillStyle_Gradient()) {
      String prefGradient =
          PreferenceConstantHelper.getElementConstant(
              "Metaclass", PreferenceConstantHelper.COLOR_GRADIENT);
      GradientPreferenceConverter gradientPreferenceConverter =
          new GradientPreferenceConverter(preferenceStore.getString(prefGradient));
      if (feature == NotationPackage.eINSTANCE.getFillStyle_Transparency()) {
        result = new Integer(gradientPreferenceConverter.getTransparency());
      } else if (feature == NotationPackage.eINSTANCE.getFillStyle_Gradient()) {
        result = gradientPreferenceConverter.getGradientData();
      }
    }

    if (result == null) {
      result = getStructuralFeatureValue(feature);
    }
    return result;
  }