use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSHyperlinkDetector method getHyperlinkRegion.
private IRegion getHyperlinkRegion(ICSSNode node, String href) {
CSSRegionContainer uriRegion = null;
switch(node.getNodeType()) {
case ICSSNode.PRIMITIVEVALUE_NODE:
uriRegion = (CSSRegionContainer) node;
break;
case ICSSNode.IMPORTRULE_NODE:
// $NON-NLS-1$
ICSSNode attribute = node.getAttributes().getNamedItem("href");
if (attribute instanceof CSSRegionContainer) {
uriRegion = (CSSRegionContainer) attribute;
}
break;
}
if (uriRegion != null) {
final int start = uriRegion.getStartOffset();
final int end = uriRegion.getEndOffset();
if (end > start)
return new Region(start, end - start);
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode 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.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForAtmarkRule method getCandidateImportRule.
/**
*/
private CSSCACandidate getCandidateImportRule() {
// check content model
CSSMetaModelUtil util = new CSSMetaModelUtil(fContext.getMetaModel());
if (!util.collectNodesByType(CSSMMNode.TYPE_IMPORT_RULE).hasNext()) {
return null;
}
// charset and import can precede import rule.
int offset = fContext.getCursorPos();
if (0 < offset) {
SelectionCollector trav = new SelectionCollector();
trav.setRegion(0, offset - 1);
trav.apply(fContext.getModel().getDocument());
Iterator i = trav.getSelectedNodes().iterator();
while (i.hasNext()) {
Object obj = i.next();
if (obj instanceof ICSSNode && !(obj instanceof ICSSDocument || obj instanceof ICSSCharsetRule || obj instanceof ICSSImportRule)) {
return null;
}
}
}
int cursorPos = 0;
String ident = (fUseUpperCase) ? IMPORT.toUpperCase() : IMPORT.toLowerCase();
StringBuffer buf = new StringBuffer();
buf.append(ident);
// $NON-NLS-1$
buf.append(" ");
cursorPos = buf.length();
StringAndOffset sao;
sao = generateURI();
buf.append(sao.fString);
cursorPos += sao.fOffset;
sao = generateSemicolon();
buf.append(sao.fString);
String text = buf.toString();
if (isMatch(text)) {
CSSCACandidate item = new CSSCACandidate();
item.setReplacementString(buf.toString());
item.setCursorPosition(cursorPos);
item.setDisplayString(ident);
item.setImageType(CSSImageType.RULE_IMPORT);
return item;
} else {
return null;
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class StructuredSelectPreviousCSSActionDelegate method getNewSelectionRegion.
protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
Region newRegion = null;
if (indexedRegion instanceof ICSSNode) {
ICSSNode cursorNode = (ICSSNode) indexedRegion;
Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
int currentOffset = textSelection.getOffset();
int currentEndOffset = currentOffset + textSelection.getLength();
if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
ICSSNode newNode = cursorNode.getPreviousSibling();
if (newNode == null) {
newNode = cursorNode.getParentNode();
if (newNode instanceof IndexedRegion) {
IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
}
} else {
if (newNode instanceof IndexedRegion) {
IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
newRegion = new Region(newIndexedRegion.getStartOffset(), currentEndOffset - newIndexedRegion.getStartOffset());
}
}
} else
newRegion = cursorNodeRegion;
}
return newRegion;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class JSPedCSSPropertySheetConfiguration method getInputSelection.
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;
}
Aggregations