use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSPropertySource method getPropertyDescriptors.
/**
* Returns the current collection of property descriptors.
*
* @return a vector containing all descriptors.
*/
public IPropertyDescriptor[] getPropertyDescriptors() {
time0 = System.currentTimeMillis();
CSSMetaModel metamodel = CSSMetaModelFinder.getInstance().findMetaModelFor(fNode);
Iterator iProperties = Collections.EMPTY_LIST.iterator();
switch(fNode.getNodeType()) {
case ICSSNode.STYLERULE_NODE:
case ICSSNode.FONTFACERULE_NODE:
case ICSSNode.PAGERULE_NODE:
case ICSSNode.STYLEDECLARATION_NODE:
CSSMMNode mmParent = new CSSMetaModelUtil(metamodel).getMetaModelNodeFor(fNode);
if (mmParent != null) {
iProperties = mmParent.getChildNodes();
}
break;
case ICSSNode.STYLEDECLITEM_NODE:
CSSMMNode mmNode = new CSSMetaModelUtil(metamodel).getMetaModelNodeFor(fNode);
if (mmNode != null) {
iProperties = Collections.singletonList(mmNode).iterator();
}
break;
default:
break;
}
// setup categories
Map categories = new HashMap();
Iterator iCategories = metamodel.getCategories();
while (iCategories.hasNext()) {
CSSMMCategory category = (CSSMMCategory) iCategories.next();
categories.put(category.getName(), category.getCaption());
}
// collect property names
Set declaredProperties = new HashSet();
if (iProperties.hasNext()) {
CSSStyleDeclaration declaration = getDeclarationNode();
if (declaration != null) {
ICSSNodeList nodeList = ((ICSSNode) declaration).getChildNodes();
int nProps = (nodeList != null) ? nodeList.getLength() : 0;
for (int i = 0; i < nProps; i++) {
ICSSNode node = nodeList.item(i);
if (node instanceof ICSSStyleDeclItem) {
String name = ((ICSSStyleDeclItem) node).getPropertyName();
if (name != null && 0 < name.length()) {
declaredProperties.add(name.toLowerCase());
}
}
}
}
}
List descriptors = new ArrayList();
// first: properties from content model
while (iProperties.hasNext()) {
CSSMMNode node = (CSSMMNode) iProperties.next();
if (node.getType() == CSSMMNode.TYPE_PROPERTY || node.getType() == CSSMMNode.TYPE_DESCRIPTOR) {
// $NON-NLS-1$
String category = (String) categories.get(node.getAttribute("category"));
String name = node.getName().toLowerCase();
if (declaredProperties.contains(name)) {
declaredProperties.remove(name);
}
IPropertyDescriptor descriptor = createPropertyDescriptor(name, category);
if (descriptor != null) {
descriptors.add(descriptor);
}
}
}
// second: existing properties but not in content model
Iterator iRemains = declaredProperties.iterator();
while (iRemains.hasNext()) {
IPropertyDescriptor descriptor = createPropertyDescriptor((String) iRemains.next(), null);
if (descriptor != null) {
descriptors.add(descriptor);
}
}
IPropertyDescriptor[] resultArray = new IPropertyDescriptor[descriptors.size()];
if (PERF_GETDESCRIPTORS) {
// $NON-NLS-1$ //$NON-NLS-2$
System.out.println(getClass().getName() + ".getPropertyDescriptors: " + (System.currentTimeMillis() - time0) + "ms");
}
return (IPropertyDescriptor[]) descriptors.toArray(resultArray);
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSPropertySource method getPropertyValue.
/**
* Returns the current value for the named property.
*
* @param name
* the name of the property as named by its property descriptor
* @return the current value of the property
*/
public Object getPropertyValue(Object name) {
if (name == null) {
// $NON-NLS-1$
return "";
}
String valueString = null;
String nameString = name.toString();
CSSStyleDeclaration declaration = null;
switch(fNode.getNodeType()) {
case ICSSNode.STYLEDECLITEM_NODE:
valueString = ((ICSSStyleDeclItem) fNode).getCSSValueText();
break;
case ICSSNode.STYLERULE_NODE:
case ICSSNode.FONTFACERULE_NODE:
case ICSSNode.PAGERULE_NODE:
declaration = (CSSStyleDeclaration) fNode.getFirstChild();
if (declaration != null) {
valueString = declaration.getPropertyValue(nameString);
}
break;
case ICSSNode.STYLEDECLARATION_NODE:
valueString = ((CSSStyleDeclaration) fNode).getPropertyValue(nameString);
break;
case ICSSNode.PRIMITIVEVALUE_NODE:
ICSSNode parent = fNode;
while (parent != null && !(parent instanceof ICSSStyleDeclItem)) {
parent = parent.getParentNode();
}
if (parent != null) {
valueString = ((ICSSStyleDeclItem) parent).getCSSValueText();
}
break;
default:
break;
}
if (valueString == null) {
// $NON-NLS-1$
valueString = "";
}
return valueString;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSContentOutlineConfiguration method getFilteredNode.
private Object getFilteredNode(Object o) {
ICSSNode node = null;
if (o instanceof ICSSNode) {
node = (ICSSNode) o;
short nodeType = node.getNodeType();
if (node instanceof ICSSValue) {
while (node != null && !(node instanceof ICSSStyleDeclItem)) {
node = node.getParentNode();
}
} else if (nodeType == ICSSNode.STYLEDECLARATION_NODE) {
node = node.getParentNode();
} else if (nodeType == ICSSNode.MEDIALIST_NODE) {
node = node.getParentNode();
}
}
return node;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSQueryContext method applyFull.
/**
*/
public void applyFull(ICSSStyleDeclaration decl) {
if (decl == null)
return;
Enumeration keys = fProperties.keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object val = fProperties.get(key);
if (val instanceof CSSQueryDeclarationData) {
ICSSStyleDeclItem declItem = ((CSSQueryDeclarationData) val).getDeclItem();
if (declItem.getLength() <= 0) {
ICSSStyleDeclItem itemToRemove = decl.getDeclItemNode(key.toString());
if (itemToRemove != null) {
decl.removeDeclItemNode(itemToRemove);
}
} else {
decl.setDeclItemNode(declItem);
}
} else {
String value = (val instanceof ICSSValue) ? ((ICSSValue) val).getCSSValueText() : val.toString();
if (value == null || value.length() <= 0) {
ICSSStyleDeclItem itemToRemove = decl.getDeclItemNode(key.toString());
if (itemToRemove != null) {
decl.removeDeclItemNode(itemToRemove);
}
} else {
decl.setProperty(key.toString(), value, null);
}
}
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForDeclarationValue method addSemiColon.
/**
*/
private void addSemiColon(List candidates) {
ICSSNode targetNode = fContext.getTargetNode();
if (targetNode instanceof ICSSStyleDeclItem) {
ICSSNode firstChild = targetNode.getFirstChild();
if (firstChild == null) {
return;
}
if (firstChild instanceof IndexedRegion) {
int startOffset = ((IndexedRegion) firstChild).getStartOffset();
if (fContext.getCursorPos() <= startOffset) {
return;
}
}
}
boolean bAddCloser = false;
ITextRegion targetRegion = fContext.getTargetRegion();
if (targetRegion != null && targetRegion.getType() != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
// find trailing ":" or ";"
// if ":" before ";" is found, add ";"
RegionIterator iterator = fContext.getRegionIterator();
IStructuredDocumentRegion container = iterator.getStructuredDocumentRegion();
while (iterator.hasNext()) {
ITextRegion region = iterator.next();
if (iterator.getStructuredDocumentRegion() != container) {
break;
}
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
bAddCloser = true;
break;
}
}
if (!bAddCloser) {
// second chance:
// leading IStructuredDocumentRegion is not ";"
IStructuredDocumentRegion nextStructuredDocumentRegion = CSSUtil.findNextSignificantNode(container);
if (CSSUtil.getStructuredDocumentRegionType(nextStructuredDocumentRegion) != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
bAddCloser = true;
}
}
}
if (bAddCloser) {
CSSCACandidate item = new CSSCACandidate();
// $NON-NLS-1$
String text = fContext.getTextToReplace() + ";";
item.setReplacementString(text);
item.setCursorPosition(text.length());
// $NON-NLS-1$
item.setDisplayString(";");
item.setImageType(null);
candidates.add(item);
}
}
Aggregations