public HyperlinkSettings getHyperlinkSettings() {
    // #132723 cannot have null settings
    if (hyperlinkSettings == null) {
      Display display = SWTUtil.getStandardDisplay();
      hyperlinkSettings = new HyperlinkSettings(display);

      // Setting link foreground color for windows 7
      final String osName = System.getProperty("os.name"); // $NON-NLS-1$
      if (osName.toLowerCase().startsWith("windows 7")) { // $NON-NLS-1$
        activeForeground = new Color(display, LINK_FOREGROUND);
        hyperlinkSettings.setForeground(activeForeground);
      }
      enabledForeground = hyperlinkSettings.getForeground();
      // Bug 22782 - DCR - Need API to draw disabled text in native platform way
      disabledForeground = display.getSystemColor(SWT.COLOR_GRAY);
    }
    return hyperlinkSettings;
  }
  @Override
  protected void applyCSSProperty(
      Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    if (!(control instanceof FormText)) return;

    FormText formText = (FormText) control;
    if (ICathyConstants.PROPERTY_HYPERLINK_COLOR.equals(property)) {
      if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
        Color hyperlinkColor = (Color) engine.convert(value, Color.class, formText.getDisplay());
        HyperlinkSettings hyperlinkSettings = formText.getHyperlinkSettings();
        hyperlinkSettings.setForeground(hyperlinkColor);
      }
    } else if (ICathyConstants.PROPERTY_ACTIVE_HYPERLINK_COLOR.equals(property)) {
      Color activeHyperlinkColor =
          (Color) engine.convert(value, Color.class, formText.getDisplay());
      formText.getHyperlinkSettings().setActiveForeground(activeHyperlinkColor);
    }
  }
  /** {@inheritDoc} */
  @Override
  public void createPartControl(Composite parent, FormToolkit toolkit) {
    main = toolkit.createComposite(parent, SWT.BORDER);
    main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    GridLayout gl = new GridLayout(8, false);
    main.setLayout(gl);

    toolkit
        .createLabel(main, null)
        .setImage(InspectIT.getDefault().getImage(InspectITImages.IMG_DATABASE));

    totalSql = toolkit.createFormText(main, false);
    totalSql.setToolTipText("Total amount of SQL Statements executed in the invocation");
    totalSql.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    toolkit
        .createLabel(main, null)
        .setImage(InspectIT.getDefault().getImage(InspectITImages.IMG_TIME));

    totalDuration = toolkit.createFormText(main, false);
    totalDuration.setToolTipText("Duration sum of all SQL Statements executed in the invocation");
    totalDuration.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    toolkit
        .createLabel(main, null)
        .setImage(InspectIT.getDefault().getImage(InspectITImages.IMG_INVOCATION));

    percentageOfDuration = toolkit.createFormText(main, false);
    percentageOfDuration.setToolTipText(
        "Percentage of the time spent in the invocation on SQL Statements execution");
    percentageOfDuration.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    toolkit
        .createLabel(main, null)
        .setImage(InspectIT.getDefault().getImage(InspectITImages.IMG_HELP));

    slowestCount = toolkit.createFormText(main, false);
    slowestCount.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    slowestCount.setToolTipText(
        "Amount of slowest SQL Statements that take 80%/20% time of total SQL execution duration");

    // remove left and right margins from the parent
    Layout parentLayout = parent.getLayout();
    if (parentLayout instanceof GridLayout) {
      ((GridLayout) parentLayout).marginWidth = 0;
      ((GridLayout) parentLayout).marginHeight = 0;
    }

    setDefaultText();

    slowestHyperlinkSettings = new HyperlinkSettings(parent.getDisplay());
    slowestHyperlinkSettings.setHyperlinkUnderlineMode(HyperlinkSettings.UNDERLINE_HOVER);
    slowestCount.setHyperlinkSettings(slowestHyperlinkSettings);
    slowestCount.addHyperlinkListener(getHyperlinkAdapter());
  }
 public void setEnabled(boolean enabled) {
   HyperlinkSettings settings = getHyperlinkSettings();
   settings.setForeground(enabled ? enabledForeground : disabledForeground);
 }
  /**
   * Updates the representation of the text form.
   *
   * @param invocations Invocations to display.
   */
  @SuppressWarnings("unchecked")
  private void updateRepresentation(List<InvocationSequenceData> invocations) {
    sourceInvocations = invocations;
    resetDisplayed = false;

    MutableDouble duration = new MutableDouble(0d);
    List<SqlStatementData> sqlList = new ArrayList<>();
    InvocationSequenceDataHelper.collectSqlsInInvocations(invocations, sqlList, duration);
    double totalInvocationsDuration = 0d;
    for (InvocationSequenceData inv : invocations) {
      totalInvocationsDuration += inv.getDuration();
    }
    double percentage = (duration.toDouble() / totalInvocationsDuration) * 100;

    slowest80List.clear();
    int slowest80 = getSlowestSqlCount(duration.toDouble(), sqlList, 0.8d, slowest80List);
    int slowest20 = sqlList.size() - slowest80;
    slowest20List = CollectionUtils.subtract(sqlList, slowest80List);

    totalSql.setText(
        "<form><p><b>" + TOTAL_SQLS + "</b> " + sqlList.size() + "</p></form>", true, false);
    totalDuration.setText(
        "<form><p><b>"
            + TOTAL_DURATION
            + "</b> "
            + NumberFormatter.formatDouble(duration.doubleValue())
            + " ms</p></form>",
        true,
        false);

    String formatedPercentage = NumberFormatter.formatDouble(percentage, 1);
    if (CollectionUtils.isNotEmpty(sqlList)) {
      Color durationInInvocationColor =
          ColorFormatter.getPerformanceColor(
              GREEN_RGB, YELLOW_RGB, RED_RGB, percentage, 20d, 80d, resourceManager);
      percentageOfDuration.setColor("durationInInvocationColor", durationInInvocationColor);
      percentageOfDuration.setText(
          "<form><p><b>"
              + SQLS_DURATION_IN_INVOCATION
              + "</b> <span color=\"durationInInvocationColor\">"
              + formatedPercentage
              + "%</span></p></form>",
          true,
          false);
    } else {
      percentageOfDuration.setText(
          "<form><p><b>"
              + SQLS_DURATION_IN_INVOCATION
              + "</b> "
              + formatedPercentage
              + "%</p></form>",
          true,
          false);
    }

    String slowest80String = getCountAndPercentage(slowest80, sqlList.size());
    String slowest20String = getCountAndPercentage(slowest20, sqlList.size());
    if (CollectionUtils.isNotEmpty(sqlList)) {
      double slowest80Percentage = ((double) slowest80 / sqlList.size()) * 100;
      if (Double.isNaN(slowest80Percentage)) {
        slowest80Percentage = 0;
      }
      Color color8020 =
          ColorFormatter.getPerformanceColor(
              GREEN_RGB, YELLOW_RGB, RED_RGB, slowest80Percentage, 70d, 10d, resourceManager);
      slowestCount.setColor(SLOWEST8020_COLOR, color8020);
      slowestHyperlinkSettings.setForeground(color8020);

      StringBuilder text = new StringBuilder("<b>" + SLOWEST_80_20 + "</b> ");
      if (slowest80 > 0) {
        text.append("<a href=\"" + SLOWEST80_LINK + "\">" + slowest80String + "</a>");
      } else {
        text.append("<span color=\"" + SLOWEST8020_COLOR + "\">" + slowest80String + "</span>");
      }
      text.append(" / ");
      if (slowest20 > 0) {
        text.append("<a href=\"" + SLOWEST20_LINK + "\">" + slowest20String + "</a>");
      } else {
        text.append("<span color=\"" + SLOWEST8020_COLOR + "\">" + slowest20String + "</span>");
      }
      slowestContent = text.toString();
    } else {
      slowestContent = "<b>" + SLOWEST_80_20 + "</b> " + slowest80String + " / " + slowest20String;
    }
    slowestCount.setText("<form><p>" + slowestContent + "</p></form>", true, false);

    main.layout();
  }