use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class StyleAttrAdapter method valueChanged.
/**
*/
private void valueChanged() {
Element element = getElement();
if (element == null)
return;
if (!isModelNecessary()) {
// removed
setModel(null);
notifyStyleChanged(element);
return;
}
ICSSModel model = getExistingModel();
if (model == null)
// defer
return;
IStructuredDocument structuredDocument = model.getStructuredDocument();
if (structuredDocument == null)
// error
return;
String value = null;
Attr attr = element.getAttributeNode(org.eclipse.wst.html.core.internal.provisional.HTML40Namespace.ATTR_NAME_STYLE);
if (attr != null)
value = ((IDOMNode) attr).getValueSource();
structuredDocument.setText(this, value);
notifyStyleChanged(element);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class HTMLAttributeValidationQuickFixProcessor method computeQuickAssistProposals.
/*
* @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#computeQuickAssistProposals(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)
*/
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
ISourceViewer viewer = invocationContext.getSourceViewer();
int documentOffset = invocationContext.getOffset();
int length = viewer != null ? viewer.getSelectedRange().y : 0;
IAnnotationModel model = viewer.getAnnotationModel();
if (model == null)
return null;
List proposals = new ArrayList();
if (model instanceof IAnnotationModelExtension2) {
Iterator iter = ((IAnnotationModelExtension2) model).getAnnotationIterator(documentOffset, length, true, true);
while (iter.hasNext()) {
Annotation anno = (Annotation) iter.next();
if (canFix(anno)) {
int offset = -1;
if (anno instanceof TemporaryAnnotation) {
offset = ((TemporaryAnnotation) anno).getPosition().getOffset();
} else if (anno instanceof MarkerAnnotation) {
offset = ((MarkerAnnotation) anno).getMarker().getAttribute(IMarker.CHAR_START, -1);
}
if (offset == -1)
continue;
IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset);
if (!(node instanceof Element))
continue;
Object adapter = (node instanceof IAdaptable ? ((IAdaptable) node).getAdapter(IResource.class) : null);
IProject project = (adapter instanceof IResource ? ((IResource) adapter).getProject() : null);
IScopeContext[] fLookupOrder = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
if (project != null) {
ProjectScope projectScope = new ProjectScope(project);
if (projectScope.getNode(getPreferenceNodeQualifier()).getBoolean(getProjectSettingsKey(), false))
fLookupOrder = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
}
boolean ignore = fPreferenceService.getBoolean(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES, HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES_DEFAULT, fLookupOrder);
String ignoreList = fPreferenceService.getString(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE, HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE_DEFAULT, fLookupOrder);
Set result = new HashSet();
if (ignoreList.trim().length() > 0) {
// $NON-NLS-1$
String[] names = ignoreList.split(",");
for (int i = 0; names != null && i < names.length; i++) {
String name = names[i] == null ? null : names[i].trim();
if (name != null && name.length() > 0)
result.add(name.toLowerCase());
}
}
String name = getAttributeName(node, offset);
if (name == null)
continue;
// If ignore == false. then show a quick fix anyway (due to allow to turn 'ignore' option on)
if (!ignore || shouldShowQuickFix(result, name.toLowerCase())) {
IgnoreAttributeNameCompletionProposal p = new IgnoreAttributeNameCompletionProposal(name.toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAttribute, name), HTMLUIMessages.DoNotValidateAttributeAddInfo, node);
if (!proposals.contains(p))
proposals.add(p);
}
int dashIndex = name.indexOf('-');
while (dashIndex != -1) {
StringBuffer namePattern = new StringBuffer(name.substring(0, dashIndex + 1)).append('*');
// a more common pattern is already created
if (ignore && result.contains(namePattern.toString().toLowerCase()))
break;
IgnoreAttributeNameCompletionProposal p = new IgnoreAttributeNameCompletionProposal(namePattern.toString().toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAllAttributes, namePattern.toString()), HTMLUIMessages.DoNotValidateAllAttributesAddInfo, node);
if (!proposals.contains(p))
proposals.add(p);
dashIndex = name.indexOf('-', dashIndex + 1);
}
}
}
}
if (proposals.isEmpty())
return null;
return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class EMF2DOMSSEAdapter method getNewlineString.
protected String getNewlineString(Node node) {
/*
* We should always have IDOMNode, and IStructuredDocument, and
* consquently a valid "preferred" line delimiter, but just to be
* safe, we'll assign something by default.
*/
if (node instanceof IDOMNode) {
IDOMNode xmlNode = (IDOMNode) node;
IStructuredDocument document = xmlNode.getStructuredDocument();
if (document != null) {
return document.getLineDelimiter();
}
}
return DOMUtilities.NEWLINE_STRING;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyJSP method smartInsertForEndTag.
private void smartInsertForEndTag(DocumentCommand command, IDocument document, IStructuredModel model) {
try {
if (command.text.equals("/") && (document.getLength() >= 1) && document.get(command.offset - 1, 1).equals("<") && HTMLUIPlugin.getDefault().getPreferenceStore().getBoolean(HTMLUIPreferenceNames.TYPING_COMPLETE_END_TAGS)) {
// $NON-NLS-1$ //$NON-NLS-2$
IDOMNode parentNode = (IDOMNode) ((IDOMNode) model.getIndexedRegion(command.offset - 1)).getParentNode();
if (isCommentNode(parentNode)) {
// loop and find non comment node parent
while ((parentNode != null) && isCommentNode(parentNode)) {
parentNode = (IDOMNode) parentNode.getParentNode();
}
}
if (!isDocumentNode(parentNode)) {
// only add end tag if one does not already exist or if
// add '/' does not create one already
IStructuredDocumentRegion endTagStructuredDocumentRegion = parentNode.getEndStructuredDocumentRegion();
IDOMNode ancestor = parentNode;
boolean smartInsertForEnd = false;
if (endTagStructuredDocumentRegion != null) {
// Look for ancestors by the same name that are missing end tags
while ((ancestor = (IDOMNode) ancestor.getParentNode()) != null) {
if (ancestor.getEndStructuredDocumentRegion() == null && parentNode.getNodeName().equals(ancestor.getNodeName())) {
smartInsertForEnd = true;
break;
}
}
}
if (endTagStructuredDocumentRegion == null || smartInsertForEnd) {
StringBuffer toAdd = new StringBuffer(parentNode.getNodeName());
if (toAdd.length() > 0) {
// $NON-NLS-1$
toAdd.append(">");
String suffix = toAdd.toString();
if ((document.getLength() < command.offset + suffix.length()) || (!suffix.equals(document.get(command.offset, suffix.length())))) {
command.text += suffix;
}
}
}
}
}
} catch (BadLocationException e) {
Logger.logException(e);
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyJSP method customizeDocumentCommand.
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
if (!supportsSmartInsert(document)) {
return;
}
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null) {
if (command.text != null) {
smartInsertForEndTag(command, document, model);
smartRemoveEndTag(command, document, model);
if (command.text.equals("%") && isPreferenceEnabled(JSPUIPreferenceNames.TYPING_COMPLETE_SCRIPTLETS)) {
// $NON-NLS-1$
// scriptlet - add end %>
IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset);
if (node != null && prefixedWith(document, command.offset, "<") && !node.getSource().endsWith("%>")) {
// $NON-NLS-1$ //$NON-NLS-2$
// $NON-NLS-1$
command.text += " %>";
command.shiftsCaret = false;
command.caretOffset = command.offset + 1;
command.doit = false;
}
}
if (command.text.equals("{") && isPreferenceEnabled(JSPUIPreferenceNames.TYPING_COMPLETE_EL_BRACES)) {
// $NON-NLS-1$
IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset);
if (// $NON-NLS-1$ //$NON-NLS-2$
node != null && (prefixedWith(document, command.offset, "$") || prefixedWith(document, command.offset, "#")) && !node.getSource().endsWith("}")) {
// $NON-NLS-1$ //$NON-NLS-2$
// $NON-NLS-1$
command.text += " }";
command.shiftsCaret = false;
command.caretOffset = command.offset + 1;
command.doit = false;
}
}
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
Aggregations