use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForDeclarationValue method addImportant.
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);
}
}
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSProposalArranger method buildProposals.
/**
*/
void buildProposals() {
fProposals.clear();
/*
* String text; ICompletionProposal item; text = "---- Test
* Information ----"; item = new CompletionProposal("",
* fContext.getReplaceBegin(), 0, 0, null, text, null, null);
* fProposals.add(item);
*
* text = "Target: \"" + fContext.getRegionText() + "\"";
*
* item = new CompletionProposal("", fContext.getReplaceBegin(), 0, 0,
* null, text, null, null); fProposals.add(item);
*
* text = fContext.getTargetNode().getClass().toString(); int
* lastPeriodPos = text.lastIndexOf('.'); text = "Node: " +
* text.substring(lastPeriodPos + 1); item = new
* CompletionProposal("", fContext.getReplaceBegin(), 0, 0, null,
* text, null, null); fProposals.add(item);
*/
ICSSNode targetNode = fContext.getTargetNode();
// int targetPos = fContext.getTargetPos();
if (targetNode instanceof ICSSStyleSheet) {
buildProposalsForAnyRule();
} else if ((targetNode instanceof ICSSMediaRule && fContext.isTargetPosAfterOf(CSSRegionContexts.CSS_LBRACE)) || (targetNode instanceof ICSSStyleRule && fContext.isTargetPosBeforeOf(CSSRegionContexts.CSS_LBRACE))) {
buildProposalsForAnyRule();
// buildProposalsForStyleRule();
} else if ((targetNode instanceof ICSSPageRule && fContext.isTargetPosBeforeOf(CSSRegionContexts.CSS_LBRACE))) {
buildProposalsForPageRulePseudoClass();
} else if ((targetNode instanceof ICSSStyleRule || targetNode instanceof CSSFontFaceRule || targetNode instanceof ICSSPageRule || targetNode instanceof ICSSStyleDeclaration) && (targetNode.getOwnerDocument() instanceof ICSSStyleDeclaration || fContext.targetFollows(CSSRegionContexts.CSS_DECLARATION_DELIMITER) || fContext.targetFollows(CSSRegionContexts.CSS_LBRACE))) {
buildProposalsForDeclarationName();
} else if (targetNode instanceof ICSSStyleDeclItem) {
if (fContext.isTargetPosAfterOf(CSSRegionContexts.CSS_DECLARATION_SEPARATOR)) {
buildProposalsForDeclarationValue();
} else {
buildProposalsForDeclarationName();
}
} else if (targetNode instanceof ICSSPrimitiveValue) {
buildProposalsForDeclarationValue();
}
/*
* else if (targetNode instanceof ICSSPrimitiveValue || ((targetNode
* instanceof ICSSStyleRule || targetNode instanceof CSSFontFaceRule ||
* targetNode instanceof ICSSStyleDeclaration || targetNode instanceof
* ICSSStyleDeclItem) &&
* fContext.isTargetPosAfterOf(CSSRegionContexts.COLON))) {
* buildProposalsForDeclarationValue(); }
*/
// for Test
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForDeclarationName method getCandidates.
/**
* getCandidates method comment.
*/
protected Iterator getCandidates() {
List candidates = new ArrayList();
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
// $NON-NLS-1$
String preDelim = "";
for (int i = 0; i < preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_PRE_DELIM); i++) {
// $NON-NLS-1$
preDelim += ' ';
}
// $NON-NLS-1$
String postDelim = "";
for (int i = 0; i < preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_POST_DELIM); i++) {
// $NON-NLS-1$
postDelim += ' ';
}
ICSSNode targetNode = fContext.getTargetNode();
boolean bFontRule = false;
for (ICSSNode node = targetNode; node != null; node = node.getParentNode()) {
if (node instanceof org.w3c.dom.css.CSSFontFaceRule) {
bFontRule = true;
break;
}
}
List names = new ArrayList();
CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
Iterator iNames = util.collectNodesByType((bFontRule) ? CSSMMNode.TYPE_DESCRIPTOR : CSSMMNode.TYPE_PROPERTY);
while (iNames.hasNext()) {
CSSMMNode node = (CSSMMNode) iNames.next();
names.add(node);
}
sortNames(names);
// Collections.sort(names);
boolean bAddColon = true;
if ((targetNode instanceof ICSSStyleRule || targetNode instanceof ICSSStyleDeclItem || targetNode instanceof ICSSStyleDeclaration) && fContext.targetHas(CSSRegionContexts.CSS_DECLARATION_SEPARATOR)) {
bAddColon = false;
}
Iterator i = names.iterator();
while (i.hasNext()) {
CSSMMNode node = (CSSMMNode) i.next();
String text = node.getName();
text = (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME) == CSSCorePreferenceNames.UPPER) ? text.toUpperCase() : text.toLowerCase();
if (!isMatch(text)) {
continue;
}
int cursorPos = 0;
StringBuffer buf = new StringBuffer();
buf.append(text);
buf.append(preDelim);
cursorPos = buf.length();
if (bAddColon) {
// $NON-NLS-1$
buf.append(':');
buf.append(postDelim);
cursorPos += 1 + postDelim.length();
}
// if (! (targetNode instanceof ICSSStyleDeclItem)) {
// buf.append(';');//$NON-NLS-1$
// }
CSSCACandidate item = new CSSCACandidate();
item.setReplacementString(buf.toString());
item.setCursorPosition(cursorPos);
item.setDisplayString(text);
item.setMMNode(node);
item.setImageType(getCategoryImageType(node));
candidates.add(item);
}
return candidates.iterator();
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class PrimitiveValueFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
int start = ((IndexedRegion) node).getStartOffset();
int end = ((IndexedRegion) node).getEndOffset();
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
CSSCleanupStrategy stgy = getCleanupStrategy(node);
if (end > 0) {
// format source
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
boolean appendQuote = regions.length > 1 && node.getParentNode() instanceof ICSSStyleDeclItem && isCleanup() && getCleanupStrategy(node).isQuoteValues() && (((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_FONT) || ((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_FONT_FAMILY) || ((ICSSStyleDeclItem) node.getParentNode()).getPropertyName().equals(PropCMProperty.P_VOICE_FAMILY));
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
StringBuffer strBuf = new StringBuffer();
boolean skipSpace = false;
for (int i = 0; i < regions.length; i++) {
if (i != 0 && !skipSpace)
appendSpaceBefore(node, regions[i], strBuf);
skipSpace = false;
strBuf.append(decoratedPropValueRegion(regions[i], stgy));
if (regions[i].getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
skipSpace = true;
}
if (appendQuote) {
source.append(quote);
String str = strBuf.toString();
str = str.replace('\'', ' ');
str = str.replace('\"', ' ');
str = str.trim();
source.append(str);
source.append(quote);
} else {
source.append(strBuf);
}
} else {
// generate source
ICSSPrimitiveValue value = (ICSSPrimitiveValue) node;
short type = value.getPrimitiveType();
String quote = preferences.getString(CSSCorePreferenceNames.FORMAT_QUOTE);
String str = null;
switch(type) {
case CSSPrimitiveValue.CSS_NUMBER:
case CSSPrimitiveValue.CSS_PERCENTAGE:
case CSSPrimitiveValue.CSS_EMS:
case CSSPrimitiveValue.CSS_EXS:
case CSSPrimitiveValue.CSS_PX:
case CSSPrimitiveValue.CSS_CM:
case CSSPrimitiveValue.CSS_MM:
case CSSPrimitiveValue.CSS_IN:
case CSSPrimitiveValue.CSS_PT:
case CSSPrimitiveValue.CSS_PC:
case CSSPrimitiveValue.CSS_DEG:
case CSSPrimitiveValue.CSS_RAD:
case CSSPrimitiveValue.CSS_GRAD:
case CSSPrimitiveValue.CSS_MS:
case CSSPrimitiveValue.CSS_S:
case CSSPrimitiveValue.CSS_HZ:
case CSSPrimitiveValue.CSS_KHZ:
case CSSPrimitiveValue.CSS_DIMENSION:
case ICSSPrimitiveValue.CSS_INTEGER:
if (value.getFloatValue(type) == ((int) value.getFloatValue(type))) {
str = Integer.toString((int) value.getFloatValue(type));
} else {
str = Float.toString(value.getFloatValue(type));
}
break;
case CSSPrimitiveValue.CSS_IDENT:
case ICSSPrimitiveValue.CSS_HASH:
case ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE:
str = value.getStringValue();
if (str != null) {
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER)
str = str.toUpperCase();
else
str.toLowerCase();
}
break;
case CSSPrimitiveValue.CSS_STRING:
case CSSPrimitiveValue.CSS_URI:
case CSSPrimitiveValue.CSS_ATTR:
case ICSSPrimitiveValue.CSS_URANGE:
case ICSSPrimitiveValue.CSS_FORMAT:
case ICSSPrimitiveValue.CSS_LOCAL:
case ICSSPrimitiveValue.CSS_COMMA:
case ICSSPrimitiveValue.CSS_SLASH:
str = value.getStringValue();
}
String preStr = null, postStr = null;
switch(type) {
case CSSPrimitiveValue.CSS_ATTR:
// $NON-NLS-1$
preStr = "attr(";
// $NON-NLS-1$
postStr = ")";
break;
case CSSPrimitiveValue.CSS_CM:
// $NON-NLS-1$
postStr = "cm";
break;
// case ICSSPrimitiveValue.CSS_COUNTER:
case CSSPrimitiveValue.CSS_DEG:
// $NON-NLS-1$
postStr = "deg";
break;
case CSSPrimitiveValue.CSS_EMS:
// $NON-NLS-1$
postStr = "em";
break;
case CSSPrimitiveValue.CSS_EXS:
// $NON-NLS-1$
postStr = "ex";
break;
case CSSPrimitiveValue.CSS_GRAD:
// $NON-NLS-1$
postStr = "grad";
break;
case CSSPrimitiveValue.CSS_HZ:
// $NON-NLS-1$
postStr = "Hz";
break;
case CSSPrimitiveValue.CSS_IN:
// $NON-NLS-1$
postStr = "in";
break;
case CSSPrimitiveValue.CSS_KHZ:
// $NON-NLS-1$
postStr = "kHz";
break;
case CSSPrimitiveValue.CSS_MM:
// $NON-NLS-1$
postStr = "mm";
break;
case CSSPrimitiveValue.CSS_MS:
// $NON-NLS-1$
postStr = "ms";
break;
case CSSPrimitiveValue.CSS_PC:
// $NON-NLS-1$
postStr = "pc";
break;
case CSSPrimitiveValue.CSS_PERCENTAGE:
// $NON-NLS-1$
postStr = "%";
break;
case CSSPrimitiveValue.CSS_PT:
// $NON-NLS-1$
postStr = "pt";
break;
case CSSPrimitiveValue.CSS_PX:
// $NON-NLS-1$
postStr = "px";
break;
case CSSPrimitiveValue.CSS_RAD:
// $NON-NLS-1$
postStr = "rad";
break;
// case ICSSPrimitiveValue.CSS_RGBCOLOR:
case CSSPrimitiveValue.CSS_S:
// $NON-NLS-1$
postStr = "s";
break;
case CSSPrimitiveValue.CSS_STRING:
quote = CSSUtil.detectQuote(str, quote);
preStr = quote;
postStr = quote;
break;
case CSSPrimitiveValue.CSS_URI:
quote = CSSUtil.detectQuote(str, quote);
// $NON-NLS-1$
preStr = "url(" + quote;
// $NON-NLS-1$
postStr = quote + ")";
break;
// the followings are original primitive values
case CSSPrimitiveValue.CSS_IDENT:
case CSSPrimitiveValue.CSS_UNKNOWN:
// use str
case ICSSPrimitiveValue.CSS_INTEGER:
case ICSSPrimitiveValue.CSS_HASH:
case ICSSPrimitiveValue.CSS_SLASH:
case ICSSPrimitiveValue.CSS_COMMA:
case CSSPrimitiveValue.CSS_DIMENSION:
case CSSPrimitiveValue.CSS_NUMBER:
case ICSSPrimitiveValue.CSS_INHERIT_PRIMITIVE:
break;
case ICSSPrimitiveValue.CSS_URANGE:
// $NON-NLS-1$
preStr = "U+";
break;
case ICSSPrimitiveValue.CSS_FORMAT:
quote = CSSUtil.detectQuote(str, quote);
// $NON-NLS-1$
preStr = "format(" + quote;
// $NON-NLS-1$
postStr = quote + ")";
break;
case ICSSPrimitiveValue.CSS_LOCAL:
quote = CSSUtil.detectQuote(str, quote);
// $NON-NLS-1$
preStr = "local(" + quote;
// $NON-NLS-1$
postStr = quote + ")";
break;
}
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_VALUE) == CSSCorePreferenceNames.UPPER) {
if (preStr != null)
preStr = preStr.toUpperCase();
if (postStr != null)
postStr = postStr.toUpperCase();
}
if (preStr != null)
source.append(preStr);
if (str != null)
source.append(str);
if (postStr != null)
source.append(postStr);
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method getChildInsertPos.
/**
*/
public int getChildInsertPos(ICSSNode node) {
int n = ((IndexedRegion) node).getEndOffset();
if (n < 0) {
return -1;
}
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(n - 1);
if (flatNode != null && flatNode.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
n -= flatNode.getLength();
}
if (n > 0) {
String important = ((ICSSStyleDeclItem) node).getPriority();
if (important != null && important.length() > 0) {
// find before "!important" position
flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(n - 1);
RegionIterator it = new RegionIterator(flatNode, flatNode.getRegionAtCharacterOffset(n - 1));
while (it.hasPrev()) {
ITextRegion region = it.prev();
if (it.getStructuredDocumentRegion() != flatNode)
break;
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_IMPORTANT)
return it.getStructuredDocumentRegion().getStartOffset(region);
}
}
// skip last space
flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(n - 1);
ITextRegion region = flatNode.getRegionAtCharacterOffset(n - 1);
if (region != null) {
n -= region.getLength() - region.getTextLength();
}
return n;
}
return -1;
}
Aggregations