@Override
  public boolean applyCSSProperty(
      Object element, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    Widget widget = SWTElementHelpers.getWidget(element);
    if (widget instanceof CTabItem) {
      Item item = (Item) widget;
      boolean showClose = ((Boolean) engine.convert(value, Boolean.class, null)).booleanValue();
      if ("selected".equals(pseudo)) {
        Control parent = getParent(widget);

        ShowCloseSelectionListener listener =
            (ShowCloseSelectionListener)
                parent.getData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY);
        if (listener == null) {
          listener = new ShowCloseSelectionListener(engine);
          parent.addListener(SWT.Paint, listener);
          parent.setData(CSS_CTABITEM_SELECTED_SHOW_CLOSE_LISTENER_KEY, listener);
        } else {
          listener.setEngine(engine);
        }
        item = getSelection(getParent(widget));

        listener.setSelection(item);
        if (item != null) {
          setShowClose(item, showClose);
        }
      } else {
        setShowClose(item, showClose);
      }
      return true;
    }
    return false;
  }
 public void applyCSSProperty(
     Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
     throws Exception {
   boolean isSingle = (Boolean) engine.convert(value, Boolean.class, null);
   if (control instanceof CTabFolder) {
     CTabFolder folder = (CTabFolder) control;
     folder.setSingle(isSingle);
   }
 }
  @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);
    }
  }
 @Override
 protected String retrieveCSSProperty(
     Control control, String property, String pseudo, CSSEngine engine) throws Exception {
   if (control instanceof ToolBar) {
     if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
       Color fgColor = ((ToolBar) control).getForeground();
       return engine.convert(fgColor, Color.class, null);
     }
   }
   return null;
 }
  @Override
  protected void applyCSSProperty(
      Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    if (!(control instanceof ToolBar)) return;

    ToolBar toolBar = (ToolBar) control;
    if (ICathyConstants.PROPERTY_TOOL_ITEM_COLOR.equals(property)) {
      Color color = (Color) engine.convert(value, Color.class, toolBar.getDisplay());
      toolBar.setForeground(color);

      ToolItem[] items = toolBar.getItems();
      for (ToolItem each : items) {
        String text = each.getText();
        each.setText(text);
      }
    } else if (ICathyConstants.PROPERTY_VIEW_MENU.equals(property)) {
      if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
        if (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
          String imageUrl = ((CSSPrimitiveValue) value).getStringValue();
          ImageDescriptor imageDescriptor =
              ImageDescriptor.createFromURL(new URL(imageUrl.toString()));
          Image image = JFaceResources.getResources().createImage(imageDescriptor);
          if (TOOLBAR_TAG_VIEW_MENU.equals(toolBar.getData())) {
            toolBar.getItem(0).setImage(image);
          }
        }
      }
    }
    //        else if ("xswt-view-properties-pin".equals(property)) {
    //            ToolItem[] items = toolBar.getItems();
    //            for (ToolItem each : items) {
    //                Object data = each.getData();
    //                if (data instanceof ActionContributionItem) {
    //                    String id = ((ActionContributionItem) data).getId();
    //                    if (id.contains("org.eclipse.ui.views.properties.PinPropertySheetAction"))
    // {
    //
    //                    }
    //                }
    //            }
    //        }
  }
  @Override
  protected void applyCSSProperty(
      Control control, String property, CSSValue value, String pseudo, CSSEngine engine)
      throws Exception {
    if (!(control instanceof CTabFolder)) {
      return;
    }
    CTabFolder folder = (CTabFolder) control;
    CTabFolderRenderer renderer = folder.getRenderer();
    if (!(renderer instanceof ICTabFolderRendering)) return;

    ICTabFolderRendering tabFolderRendering = (ICTabFolderRendering) renderer;

    Image image = null;
    if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
      if (((CSSPrimitiveValue) value).getPrimitiveType() == CSSPrimitiveValue.CSS_URI) {
        String imageUrl = ((CSSPrimitiveValue) value).getStringValue();
        ImageDescriptor imageDescriptor =
            ImageDescriptor.createFromURL(new URL(imageUrl.toString()));
        image = JFaceResources.getResources().createImage(imageDescriptor);
      }
    }

    if (ICathyConstants.PROPERTY_MAXIMIZE_IMAGE.equals(property)) {
      tabFolderRendering.setMaximizeImage(image);
    } else if (ICathyConstants.PROPERTY_MINIMIZE_IMAGE.equals(property)) {
      tabFolderRendering.setMinimizeImage(image);
    } else if (ICathyConstants.PROPERTY_CLOSE_IMAGE.equals(property)) {
      tabFolderRendering.setCloseImage(image);
    } else if (ICathyConstants.PROPERTY_CLOSE_HOVER_IMAGE.equals(property)) {
      tabFolderRendering.setClsoeHoverImage(image);
    } else if (ICathyConstants.PROPERTY_CHEVRON_VISIBLE.equals(property)) {
      ReflectionSupport<CTabFolder> reflect = new ReflectionSupport<CTabFolder>(CTabFolder.class);
      boolean chevronVisible = (Boolean) engine.convert(value, Boolean.class, null);
      Method setChevronVisible =
          reflect.getMethod(METHOD_SET_CHEVRON_VISIBLE, new Class<?>[] {boolean.class});
      reflect.executeMethod(setChevronVisible, folder, new Object[] {chevronVisible});
    }
  }