use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class CSSPropertySheetConfiguration 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;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSNode in project webtools.sourceediting by eclipse.
the class StructuredSelectEnclosingHandler 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.getParentNode();
if (newNode instanceof CSSStyleDeclaration) {
newNode = newNode.getParentNode();
}
if (newNode instanceof IndexedRegion) {
IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - 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 StructuredSelectPreviousHandler 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 StructuredSelectEnclosingCSSActionDelegate 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.getParentNode();
if (newNode instanceof IndexedRegion) {
IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - 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 CSSTextNodeCleanupHandler method getCSSContent.
/**
*/
private String getCSSContent(Node text) {
ICSSModel model = getCSSModel(text);
if (model == null)
return null;
ICSSNode document = model.getDocument();
if (document == null)
return null;
INodeNotifier notifier = (INodeNotifier) document;
CSSSourceFormatter formatter = (CSSSourceFormatter) notifier.getAdapterFor(CSSSourceFormatter.class);
// try another way to get formatter
if (formatter == null)
formatter = CSSSourceFormatterFactory.getInstance().getSourceFormatter(notifier);
if (formatter == null)
return null;
StringBuffer buffer = formatter.cleanup(document);
if (buffer == null)
return null;
return buffer.toString();
}
Aggregations