Search in sources :

Example 96 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class AbstractContentAssistProcessor method computeCompletionProposals.

/**
 * CONTENT ASSIST STARTS HERE
 *
 * Return a list of proposed code completions based on the specified
 * location within the document that corresponds to the current cursor
 * position within the text-editor control.
 *
 * @param textViewer
 * @param documentPosition -
 *            the cursor location within the document
 *
 * an array of ICompletionProposals
 */
public ICompletionProposal[] computeCompletionProposals(ITextViewer textViewer, int documentPosition) {
    setErrorMessage(null);
    fTextViewer = textViewer;
    IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition);
    Node node = (Node) treeNode;
    while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) {
        node = node.getParentNode();
    }
    IDOMNode xmlnode = (IDOMNode) node;
    ContentAssistRequest contentAssistRequest = null;
    IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
    ITextRegion completionRegion = getCompletionRegion(documentPosition, node);
    String matchString = getMatchString(sdRegion, completionRegion, documentPosition);
    // Handle empty Documents
    if (completionRegion == null) {
        if (((treeNode == null) || (((Node) treeNode).getNodeType() == Node.DOCUMENT_NODE)) && (completionRegion == null) && ((xmlnode == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
            IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(textViewer.getDocument());
            try {
                if (sModel != null) {
                    IDOMDocument docNode = ((IDOMModel) sModel).getDocument();
                    contentAssistRequest = newContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition, 0, null);
                    addEmptyDocumentProposals(contentAssistRequest);
                }
            } finally {
                if (sModel != null) {
                    sModel.releaseFromRead();
                }
            }
            if (contentAssistRequest == null) {
                // $NON-NLS-1$
                Logger.logException(new IllegalStateException("problem getting model"));
                return new ICompletionProposal[0];
            }
            return contentAssistRequest.getCompletionProposals();
        }
        // MASSIVE ERROR CONDITION
        // $NON-NLS-1$
        Logger.logException(new IllegalStateException("completion region was null"));
        setErrorMessage(INTERNALERROR);
        // $NON-NLS-1$
        contentAssistRequest = newContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, "");
        return contentAssistRequest.getCompletionProposals();
    }
    // catch documents where no region can be determined
    if ((xmlnode.getNodeType() == Node.DOCUMENT_NODE) && ((completionRegion == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
        contentAssistRequest = computeStartDocumentProposals(documentPosition, matchString, completionRegion, (IDOMNode) treeNode, xmlnode);
        return contentAssistRequest.getCompletionProposals();
    }
    // compute normal proposals
    contentAssistRequest = computeCompletionProposals(documentPosition, matchString, completionRegion, (IDOMNode) treeNode, xmlnode);
    if (contentAssistRequest == null) {
        // $NON-NLS-1$
        contentAssistRequest = newContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, "");
        if (Debug.displayWarnings) {
            // $NON-NLS-2$//$NON-NLS-1$
            System.out.println(UNKNOWN_CONTEXT + " " + completionRegion.getType() + "@" + documentPosition);
        }
        setErrorMessage(UNKNOWN_CONTEXT);
    }
    /* 
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=123892
		 * Only set this error message if nothing else was already set 
		 **/
    if (contentAssistRequest.getProposals().size() == 0 && getErrorMessage() == null) {
        setErrorMessage(UNKNOWN_CONTEXT);
    }
    return contentAssistRequest.getCompletionProposals();
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Node(org.w3c.dom.Node) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)

Example 97 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method addTagInsertionProposals.

protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition, CompletionProposalInvocationContext context) {
    List cmnodes = null;
    Node parent = contentAssistRequest.getParent();
    String error = null;
    // only valid if it's XML (check added 2/17/2004)
    if ((parent != null) && (parent.getNodeType() == Node.DOCUMENT_NODE) && ((IDOMDocument) parent).isXMLType() && !isCursorAfterXMLPI(contentAssistRequest)) {
        return;
    }
    // only want proposals if cursor is after doctype...
    if (!isCursorAfterDoctype(contentAssistRequest)) {
        return;
    }
    // have a content model (so can't propose any children..)
    if ((parent != null) && (parent instanceof IDOMNode) && isCommentNode((IDOMNode) parent)) {
        // loop and find non comment node?
        while ((parent != null) && isCommentNode((IDOMNode) parent)) {
            parent = parent.getParentNode();
        }
    }
    if (parent.getNodeType() == Node.ELEMENT_NODE) {
        CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
        if (parentDecl != null) {
            // XSD-specific ability - no filtering
            CMDataType childType = parentDecl.getDataType();
            if (childType != null) {
                String[] childStrings = childType.getEnumeratedValues();
                String defaultValue = childType.getImpliedValue();
                if (childStrings != null || defaultValue != null) {
                    // the content string is the sole valid child...so replace the rest
                    int begin = contentAssistRequest.getReplacementBeginPosition();
                    int length = contentAssistRequest.getReplacementLength();
                    if (parent instanceof IDOMNode) {
                        if (((IDOMNode) parent).getLastStructuredDocumentRegion() != ((IDOMNode) parent).getFirstStructuredDocumentRegion()) {
                            begin = ((IDOMNode) parent).getFirstStructuredDocumentRegion().getEndOffset();
                            length = ((IDOMNode) parent).getLastStructuredDocumentRegion().getStartOffset() - begin;
                        }
                    }
                    String proposedInfo = getAdditionalInfo(parentDecl, childType);
                    for (int i = 0; i < childStrings.length; i++) {
                        if (!childStrings[i].equals(defaultValue)) {
                            CustomCompletionProposal textProposal = new MarkupCompletionProposal(childStrings[i], begin, length, childStrings[i].length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM), childStrings[i], null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
                            contentAssistRequest.addProposal(textProposal);
                        }
                    }
                    if (defaultValue != null) {
                        CustomCompletionProposal textProposal = new MarkupCompletionProposal(defaultValue, begin, length, defaultValue.length(), XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT), defaultValue, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
                        contentAssistRequest.addProposal(textProposal);
                    }
                }
            }
        }
        if ((parentDecl != null) && (parentDecl.getContentType() == CMElementDeclaration.PCDATA)) {
            addPCDATAProposal(parentDecl.getNodeName(), contentAssistRequest, context);
        } else {
            // retrieve the list of all possible children within this parent context
            cmnodes = getAvailableChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT);
            // retrieve the list of the possible children within this
            // parent context and at this index
            List strictCMNodeSuggestions = null;
            if (XMLUIPreferenceNames.SUGGESTION_STRATEGY_VALUE_STRICT.equals(XMLUIPlugin.getInstance().getPreferenceStore().getString(XMLUIPreferenceNames.SUGGESTION_STRATEGY))) {
                strictCMNodeSuggestions = getValidChildElementDeclarations((Element) parent, childPosition, ModelQueryAction.INSERT);
            }
            Iterator nodeIterator = cmnodes.iterator();
            if (!nodeIterator.hasNext()) {
                if (getCMElementDeclaration(parent) != null) {
                    error = NLS.bind(XMLUIMessages._Has_no_available_child, (new Object[] { parent.getNodeName() }));
                } else {
                    error = NLS.bind(XMLUIMessages.Element__is_unknown, (new Object[] { parent.getNodeName() }));
                }
            }
            String matchString = contentAssistRequest.getMatchString();
            // chop off any leading <'s and whitespace from the matchstring
            while ((matchString.length() > 0) && (Character.isWhitespace(matchString.charAt(0)) || beginsWith(matchString, "<"))) {
                // $NON-NLS-1$
                matchString = matchString.substring(1);
            }
            while (nodeIterator.hasNext()) {
                Object o = nodeIterator.next();
                if (o instanceof CMElementDeclaration) {
                    CMElementDeclaration elementDecl = (CMElementDeclaration) o;
                    // only add proposals for the child element's that
                    // begin with the matchstring
                    String tagname = getRequiredName(parent, elementDecl);
                    boolean isStrictCMNodeSuggestion = strictCMNodeSuggestions != null ? strictCMNodeSuggestions.contains(elementDecl) : false;
                    // get the proposal image
                    Image image = CMImageUtil.getImage(elementDecl);
                    if (image == null) {
                        if (strictCMNodeSuggestions != null) {
                            image = isStrictCMNodeSuggestion ? this.getEmphasizedTagImage() : this.getDeemphasizedTagImage();
                        } else {
                            image = this.getGenericTagImage();
                        }
                    }
                    if (beginsWith(tagname, matchString)) {
                        String proposedText = getRequiredText(parent, elementDecl);
                        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=89811
                        // place cursor in first empty quotes
                        int markupAdjustment = getCursorPositionForProposedText(proposedText);
                        String proposedInfo = getAdditionalInfo(parentDecl, elementDecl);
                        int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION;
                        CustomCompletionProposal proposal = new MarkupCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, relevance);
                        contentAssistRequest.addProposal(proposal);
                    }
                }
            }
            if (contentAssistRequest.getProposals().size() == 0) {
                if (error != null) {
                    setErrorMessage(error);
                } else if ((contentAssistRequest.getMatchString() != null) && (contentAssistRequest.getMatchString().length() > 0)) {
                    setErrorMessage(NLS.bind(XMLUIMessages.No_known_child_tag, (new Object[] { parent.getNodeName(), contentAssistRequest.getMatchString() })));
                } else {
                    setErrorMessage(NLS.bind(XMLUIMessages.__Has_no_known_child, (new Object[] { parent.getNodeName() })));
                }
            }
        }
    } else if (parent.getNodeType() == Node.DOCUMENT_NODE) {
        // Can only prompt with elements if the cursor position is past
        // the XML processing
        // instruction and DOCTYPE declaration
        boolean xmlpiFound = false;
        boolean doctypeFound = false;
        int minimumOffset = -1;
        for (Node child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
            // $NON-NLS-1$
            boolean xmlpi = ((child.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) && child.getNodeName().equals("xml"));
            boolean doctype = child.getNodeType() == Node.DOCUMENT_TYPE_NODE;
            if (xmlpi || (doctype && (minimumOffset < 0))) {
                minimumOffset = ((IDOMNode) child).getFirstStructuredDocumentRegion().getStartOffset() + ((IDOMNode) child).getFirstStructuredDocumentRegion().getTextLength();
            }
            xmlpiFound = xmlpiFound || xmlpi;
            doctypeFound = doctypeFound || doctype;
        }
        if (contentAssistRequest.getReplacementBeginPosition() >= minimumOffset) {
            List childDecls = getAvailableRootChildren((Document) parent, childPosition);
            for (int i = 0; i < childDecls.size(); i++) {
                CMElementDeclaration ed = (CMElementDeclaration) childDecls.get(i);
                if (ed != null) {
                    Image image = CMImageUtil.getImage(ed);
                    if (image == null) {
                        image = this.getGenericTagImage();
                    }
                    String proposedText = getRequiredText(parent, ed);
                    String tagname = getRequiredName(parent, ed);
                    // account for the &lt; and &gt;
                    int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, ed);
                    String proposedInfo = getAdditionalInfo(null, ed);
                    CustomCompletionProposal proposal = new MarkupCompletionProposal(proposedText, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), markupAdjustment, image, tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
                    contentAssistRequest.addProposal(proposal);
                }
            }
        }
    }
}
Also used : CMDataType(org.eclipse.wst.xml.core.internal.contentmodel.CMDataType) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Image(org.eclipse.swt.graphics.Image) Document(org.w3c.dom.Document) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList)

Example 98 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class AbstractXMLCompletionProposalComputer method computeCompletionProposals.

/**
 * <p>Return a list of proposed code completions based on the specified
 * location within the document that corresponds to the current cursor
 * position within the text-editor control.</p>
 *
 * @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
 */
public List computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
    ITextViewer textViewer = context.getViewer();
    int documentPosition = context.getInvocationOffset();
    setErrorMessage(null);
    fTextViewer = textViewer;
    IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition);
    Node node = (Node) treeNode;
    while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) {
        node = node.getParentNode();
    }
    IDOMNode xmlnode = (IDOMNode) node;
    ContentAssistRequest contentAssistRequest = null;
    IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
    ITextRegion completionRegion = getCompletionRegion(documentPosition, node);
    String matchString = getMatchString(sdRegion, completionRegion, documentPosition);
    // Handle empty Documents
    if (completionRegion == null) {
        if (((treeNode == null) || (((Node) treeNode).getNodeType() == Node.DOCUMENT_NODE)) && (completionRegion == null) && ((xmlnode == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
            IStructuredModel sModel = null;
            try {
                if (textViewer.getDocument() instanceof IStructuredDocument) {
                    sModel = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument) textViewer.getDocument());
                }
                if (sModel != null) {
                    IDOMDocument docNode = ((IDOMModel) sModel).getDocument();
                    contentAssistRequest = new ContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition, 0, null);
                    addEmptyDocumentProposals(contentAssistRequest, context);
                }
            } finally {
                if (sModel != null) {
                    sModel.releaseFromRead();
                }
            }
            if (contentAssistRequest == null) {
                // $NON-NLS-1$
                Logger.logException(new IllegalStateException("problem getting model"));
                return new ArrayList(0);
            }
            ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
            return (props != null) ? Arrays.asList(props) : new ArrayList(0);
        }
        // MASSIVE ERROR CONDITION
        // $NON-NLS-1$
        Logger.logException(new IllegalStateException("completion region was null"));
        setErrorMessage(XMLUIMessages.SEVERE_internal_error_occu_UI_);
        // $NON-NLS-1$
        contentAssistRequest = new ContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, "");
        ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
        return (props != null) ? Arrays.asList(props) : new ArrayList(0);
    }
    // catch documents where no region can be determined
    if ((xmlnode.getNodeType() == Node.DOCUMENT_NODE) && ((completionRegion == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
        contentAssistRequest = computeStartDocumentProposals(matchString, completionRegion, (IDOMNode) treeNode, xmlnode, context);
        ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
        return (props != null) ? Arrays.asList(props) : new ArrayList(0);
    }
    // compute normal proposals
    contentAssistRequest = computeCompletionProposals(matchString, completionRegion, (IDOMNode) treeNode, xmlnode, context);
    if (contentAssistRequest == null) {
        // $NON-NLS-1$
        contentAssistRequest = new ContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, "");
        setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
    }
    /* 
		 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=123892
		 * Only set this error message if nothing else was already set 
		 **/
    if (contentAssistRequest.getProposals().size() == 0 && getErrorMessage() == null) {
        setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
    }
    ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
    return (props != null) ? Arrays.asList(props) : new ArrayList(0);
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) ITextViewer(org.eclipse.jface.text.ITextViewer) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 99 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method doSaveAs.

/* (non-Javadoc)
   * @see org.eclipse.ui.part.EditorPart#doSaveAs()
   */
public void doSaveAs() {
    // When performing a save as, the document changes.   Our model state listeners should listen
    // to the new document.
    // First get the current document
    IDocument currentDocument = getDocument();
    XSDModelAdapter modelAdapter = null;
    IDOMDocument doc = null;
    if (currentDocument != null) {
        IStructuredModel structuredModel = StructuredModelManager.getModelManager().getExistingModelForRead(currentDocument);
        if (structuredModel != null) {
            try {
                if ((structuredModel != null) && (structuredModel instanceof IDOMModel)) {
                    // Get the associated IDOMDocument model
                    doc = ((IDOMModel) structuredModel).getDocument();
                    // and now get our adapter that listens to DOM changes
                    if (doc != null) {
                        modelAdapter = (XSDModelAdapter) doc.getExistingAdapter(XSDModelAdapter.class);
                    }
                }
            } finally {
                structuredModel.releaseFromRead();
            }
        }
    }
    IEditorInput editorInput = structuredTextEditor.getEditorInput();
    // perform save as
    structuredTextEditor.doSaveAs();
    // See AbstractDecoratedTextEditor's performSaveAs
    if (editorInput != structuredTextEditor.getEditorInput()) {
        setInput(structuredTextEditor.getEditorInput());
        setPartName(structuredTextEditor.getEditorInput().getName());
        getCommandStack().markSaveLocation();
        // Now do the clean up on the old document
        if (modelAdapter != null) {
            // clear out model adapter
            modelAdapter.clear();
            modelAdapter = null;
        }
    }
}
Also used : XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument) IEditorInput(org.eclipse.ui.IEditorInput)

Example 100 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project webtools.sourceediting by eclipse.

the class InternalXSDMultiPageEditor method dispose.

public void dispose() {
    IStructuredModel structuredModel = null;
    XSDModelAdapter modelAdapter = null;
    IDOMDocument doc = null;
    IDocument idoc = structuredTextEditor.getDocumentProvider().getDocument(getEditorInput());
    if (idoc != null) {
        structuredModel = StructuredModelManager.getModelManager().getExistingModelForRead(idoc);
        if ((structuredModel != null) && (structuredModel instanceof IDOMModel)) {
            try {
                if ((structuredModel != null) && (structuredModel instanceof IDOMModel)) {
                    doc = ((IDOMModel) structuredModel).getDocument();
                    if (doc != null) {
                        modelAdapter = (XSDModelAdapter) doc.getExistingAdapter(XSDModelAdapter.class);
                        if (modelAdapter != null) {
                            doc.getModel().removeModelStateListener(modelAdapter.getModelReconcileAdapter());
                            doc.removeAdapter(modelAdapter.getModelReconcileAdapter());
                            doc.removeAdapter(modelAdapter);
                            modelAdapter.clear();
                            modelAdapter = null;
                        }
                    }
                }
            } finally {
                structuredModel.releaseFromRead();
            }
        }
    }
    if (fOutlinePage != null) {
        // }
        if (fOutlineListener != null) {
            fOutlinePage.removeSelectionChangedListener(fOutlineListener);
        }
    }
    getSelectionManager().removeSelectionChangedListener(fXSDSelectionListener);
    XSDEditorPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(xsdPreferenceStoreListener);
    xsdPreferenceStoreListener = null;
    super.dispose();
}
Also used : XSDModelAdapter(org.eclipse.wst.xsd.ui.internal.text.XSDModelAdapter) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)176 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)109 IFile (org.eclipse.core.resources.IFile)48 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)39 Element (org.w3c.dom.Element)39 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 NodeList (org.w3c.dom.NodeList)27 IStatus (org.eclipse.core.runtime.IStatus)23 Node (org.w3c.dom.Node)21 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)14 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)14 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)14 Document (org.w3c.dom.Document)14 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 IOException (java.io.IOException)11 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)11 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)10 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)9