protected String getIndent(ICSSNode node) {
    if (node == null) return ""; // $NON-NLS-1$
    ICSSNode parent = node.getParentNode();
    if (node instanceof ICSSAttr) parent = ((ICSSAttr) node).getOwnerCSSNode();
    if (parent == null) return ""; // $NON-NLS-1$
    if (node instanceof org.w3c.dom.css.CSSStyleDeclaration) parent = parent.getParentNode();
    if (parent == null) return ""; // $NON-NLS-1$

    String parentIndent = getIndent(parent);
    if (parent instanceof org.w3c.dom.css.CSSRule) return parentIndent + getIndentString();
    if (node.getParentNode() instanceof ICSSStyleDeclaration)
      return parentIndent + getIndentString();
    return parentIndent;
  }
 private boolean isFontFaceRule() {
   ICSSNode targetNode = fContext.getTargetNode();
   while (targetNode instanceof ICSSPrimitiveValue) {
     targetNode = targetNode.getParentNode();
   }
   if (targetNode instanceof ICSSStyleDeclItem) {
     targetNode = targetNode.getParentNode(); // get Declaration
     if (targetNode != null) {
       // inline style has no rule node
       targetNode = targetNode.getParentNode(); // get rule
     }
   }
   return (targetNode instanceof CSSFontFaceRule);
 }
 private void addImportant(List candidates) {
   ICSSNode targetNode = fContext.getTargetNode();
   while (targetNode instanceof ICSSPrimitiveValue) {
     targetNode = targetNode.getParentNode();
   }
   if (!(targetNode instanceof ICSSStyleDeclItem)) {
     return;
   }
   // 1. has no priority region
   // 2. cursor position is after of last child
   // 3. normal isMatch method
   String priority = ((ICSSStyleDeclItem) targetNode).getPriority();
   if (priority == null || priority.length() == 0) {
     ICSSNode lastChild = targetNode.getLastChild();
     if (lastChild instanceof IndexedRegion) {
       int startOffset = ((IndexedRegion) lastChild).getStartOffset();
       //	int endOffset = ((IndexedRegion)lastChild).getEndOffset();
       if (startOffset < fContext.getCursorPos() && isMatch(IMPORTANT)) {
         CSSCACandidate item = new CSSCACandidate();
         item.setReplacementString(IMPORTANT);
         item.setCursorPosition(IMPORTANT.length());
         item.setDisplayString(IMPORTANT);
         item.setImageType(CSSImageType.VALUE_STRING);
         appendSemiColon(item);
         candidates.add(item);
       }
     }
   }
 }
 /**
  * Generate or format source between children('child' and its previous sibling) and append to
  * string buffer
  */
 public final StringBuffer formatBefore(ICSSNode node, ICSSNode child, IRegion exceptFor) {
   Assert.isTrue(child == null || child.getParentNode() == node);
   StringBuffer buf = new StringBuffer();
   formatBefore(
       node, child, /* (child != null) ? (child.getCssText()) : */ "", buf,
       exceptFor); //$NON-NLS-1$
   return buf;
 }
 /** @return java.lang.String */
 private String getPropertyName() {
   ICSSNode targetNode = fContext.getTargetNode();
   while (targetNode instanceof ICSSPrimitiveValue) {
     targetNode = targetNode.getParentNode();
   }
   if (targetNode instanceof ICSSStyleDeclItem) {
     return ((ICSSStyleDeclItem) targetNode).getPropertyName();
   } else {
     return null;
   }
 }
 protected CSSSourceGenerator getParentFormatter(ICSSNode node) {
   ICSSNode parent = node.getParentNode();
   if (parent != null) {
     CSSSourceGenerator formatter =
         (CSSSourceGenerator) ((INodeNotifier) parent).getAdapterFor(CSSSourceFormatter.class);
     if (formatter == null) {
       formatter =
           CSSSourceFormatterFactory.getInstance().getSourceFormatter((INodeNotifier) parent);
     }
     return formatter;
   }
   return null;
 }
  public ISelection getInputSelection(IWorkbenchPart selectingPart, ISelection selection) {
    // remove UI refresh adapters
    if (fSelectedNotifiers != null) {
      for (int i = 0; i < fSelectedNotifiers.length; i++) {
        fSelectedNotifiers[i].removeAdapter(fRefreshAdapter);
      }
      fSelectedNotifiers = null;
    }

    ISelection preferredSelection = super.getInputSelection(selectingPart, selection);
    if (preferredSelection instanceof IStructuredSelection) {
      Object[] selectedObjects = new Object[((IStructuredSelection) selection).size()];
      System.arraycopy(
          ((IStructuredSelection) selection).toArray(),
          0,
          selectedObjects,
          0,
          selectedObjects.length);
      for (int i = 0; i < selectedObjects.length; i++) {
        if (selectedObjects[i] instanceof ICSSNode) {
          ICSSNode node = (ICSSNode) selectedObjects[i];
          while (node.getNodeType() == ICSSNode.PRIMITIVEVALUE_NODE
              || node.getNodeType() == ICSSNode.STYLEDECLITEM_NODE) {
            node = node.getParentNode();
            selectedObjects[i] = node;
          }
        }
      }

      /*
       * Add UI refresh adapters and remember notifiers for later removal
       */
      if (selectedObjects.length > 0) {
        List selectedNotifiers = new ArrayList(1);
        for (int i = 0; i < selectedObjects.length; i++) {
          if (selectedObjects[i] instanceof INodeNotifier) {
            selectedNotifiers.add(selectedObjects[i]);
            ((INodeNotifier) selectedObjects[i]).addAdapter(fRefreshAdapter);
          }
        }
        fSelectedNotifiers =
            (INodeNotifier[])
                selectedNotifiers.toArray(new INodeNotifier[selectedNotifiers.size()]);
      }
      preferredSelection = new StructuredSelection(selectedObjects);
    }
    return preferredSelection;
  }