Search in sources :

Example 21 with IDOMNode

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);
}
Also used : ICSSModel(org.eclipse.wst.css.core.internal.provisional.document.ICSSModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Element(org.w3c.dom.Element) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) Attr(org.w3c.dom.Attr)

Example 22 with IDOMNode

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()]);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IAdaptable(org.eclipse.core.runtime.IAdaptable) HashSet(java.util.HashSet) Set(java.util.Set) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) Annotation(org.eclipse.jface.text.source.Annotation) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) IProject(org.eclipse.core.resources.IProject) IAnnotationModelExtension2(org.eclipse.jface.text.source.IAnnotationModelExtension2) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) IResource(org.eclipse.core.resources.IResource)

Example 23 with IDOMNode

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;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

Example 24 with IDOMNode

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);
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 25 with IDOMNode

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();
    }
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Aggregations

IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)250 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)91 Node (org.w3c.dom.Node)63 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)57 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)44 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)43 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)38 List (java.util.List)35 ArrayList (java.util.ArrayList)34 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)30 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)30 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)27 Element (org.w3c.dom.Element)27 NodeList (org.w3c.dom.NodeList)23 BadLocationException (org.eclipse.jface.text.BadLocationException)22 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)22 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)20 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)19 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)18 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)18