use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class CSSModelParser method getStructuredDocumentRegionList.
/**
*/
private IStructuredDocumentRegionList getStructuredDocumentRegionList(int start, int end) {
IStructuredDocumentRegionList nodeList = null;
if (0 <= start && start <= end) {
ICSSModel model = fDocument.getModel();
if (model instanceof CSSModelImpl) {
IStructuredDocument structuredDocument = ((CSSModelImpl) model).getStructuredDocument();
if (structuredDocument != null) {
IStructuredDocumentRegion startNode = structuredDocument.getRegionAtCharacterOffset(start);
IStructuredDocumentRegion endNode = structuredDocument.getRegionAtCharacterOffset(end - 1);
if (startNode != null && endNode != null) {
nodeList = new CoreNodeList(startNode, endNode);
}
}
}
}
return nodeList;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class CSSFormatUtil method collectCSSNodes.
public List collectCSSNodes(IStructuredModel model, int start, int length) {
List nodes = new ArrayList();
IndexedRegion startNode = model.getIndexedRegion(start);
IndexedRegion endNode = model.getIndexedRegion(start + length - 1);
if (startNode == null || endNode == null) {
return nodes;
}
if (model instanceof ICSSModel && startNode instanceof ICSSNode && endNode instanceof ICSSNode) {
// CSS model
ICSSNode ca = getCommonAncestor((ICSSNode) startNode, (ICSSNode) endNode);
if (ca != null) {
for (ICSSNode node = ca.getFirstChild(); node != null && start + length < ((IndexedRegion) node).getStartOffset(); node = node.getNextSibling()) {
if (start < ((IndexedRegion) node).getEndOffset()) {
nodes.add(node);
}
}
}
} else if (model instanceof IDOMModel && startNode instanceof IDOMNode && endNode instanceof IDOMNode) {
if (startNode instanceof Text) {
startNode = (IndexedRegion) ((Text) startNode).getParentNode();
}
if (endNode instanceof Text) {
endNode = (IndexedRegion) ((Text) endNode).getParentNode();
}
// HTML model, maybe
IDOMNode ca = (IDOMNode) getCommonAncestor((Node) startNode, (Node) endNode);
findCSS(nodes, ca);
}
return nodes;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class CSSFormatUtil method findCSS.
private void findCSS(List cssNodes, IDOMNode node) {
ICSSModelAdapter adapter;
adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleSheetAdapter.class);
if (adapter != null) {
ICSSModel model = adapter.getModel();
if (model != null && model.getStyleSheetType() == ICSSModel.EMBEDDED) {
cssNodes.add(model.getDocument());
}
} else {
adapter = (ICSSModelAdapter) node.getAdapterFor(IStyleDeclarationAdapter.class);
if (adapter != null) {
ICSSModel model = adapter.getModel();
if (model != null && model.getStyleSheetType() == ICSSModel.INLINE) {
cssNodes.add(model.getDocument());
}
}
}
for (IDOMNode child = (IDOMNode) node.getFirstChild(); child != null; child = (IDOMNode) child.getNextSibling()) {
findCSS(cssNodes, child);
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class CSSStyleSheetImpl method getParentStyleSheets.
/**
* @return org.w3c.dom.stylesheets.StyleSheetList
*/
public org.w3c.dom.stylesheets.StyleSheetList getParentStyleSheets() {
List list = (getModel().getStyleListeners() != null) ? new Vector(getModel().getStyleListeners()) : null;
if (list == null)
return null;
InternalStyleSheetList sheets = new InternalStyleSheetList();
Iterator it = list.iterator();
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof ICSSModel) {
sheets.appendNode(((ICSSModel) obj).getDocument());
}
}
if (sheets.getLength() > 0)
return sheets;
else
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSModel in project webtools.sourceediting by eclipse.
the class StyleDeclarationFormatter method formatBefore.
/**
*/
protected void formatBefore(ICSSNode node, ICSSNode child, IRegion region, String toAppend, StringBuffer source) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
ICSSModel cssModel = node.getOwnerDocument().getModel();
// with no model associated with it
if (cssModel != null) {
IStructuredDocument structuredDocument = cssModel.getStructuredDocument();
if (structuredDocument != null) {
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, region, stgy);
CompoundRegion[] outside = getOutsideRegions(structuredDocument, region);
for (int i = 0; i < regions.length; i++) {
if (i != 0 || needS(outside[0]))
appendSpaceBefore(node, regions[i], source);
// must
source.append(decoratedRegion(regions[i], 0, stgy));
// be
// comments
}
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (needS(outside[1])) {
if (((IndexedRegion) child).getStartOffset() == region.getOffset() + region.getLength() && preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_ONE_PER_LINE) && (node.getOwnerDocument() != node || !preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR))) {
appendDelimBefore(node, null, source);
} else
appendSpaceBefore(node, toAppend, source);
}
}
}
}
Aggregations