Search in sources :

Example 46 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method getPossibleDataTypeValues.

/**
 * Retrieves all of the possible valid values for this attribute
 * declaration
 */
private List getPossibleDataTypeValues(Node node, CMAttributeDeclaration ad) {
    List list = null;
    if (node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        String[] dataTypeValues = null;
        // The ModelQuery may not be available if the corresponding
        // adapter
        // is absent
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
        if (modelQuery != null) {
            dataTypeValues = modelQuery.getPossibleDataTypeValues(element, ad);
        } else {
            if (ad.getAttrType() != null) {
                dataTypeValues = ad.getAttrType().getEnumeratedValues();
            }
        }
        if (dataTypeValues != null) {
            list = new ArrayList(dataTypeValues.length);
            for (int i = 0; i < dataTypeValues.length; i++) {
                list.add(dataTypeValues[i]);
            }
        }
    }
    if (list == null) {
        list = new ArrayList(0);
    }
    return list;
}
Also used : Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) ArrayList(java.util.ArrayList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 47 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class AbstractXMLModelQueryCompletionProposalComputer method getAvailableModelQueryActionsAtIndex.

/**
 * returns a list of ModelQueryActions
 *
 * @param parent
 * @param index
 * @param validityChecking
 * @return
 */
private List getAvailableModelQueryActionsAtIndex(Element parent, int index, int validityChecking) {
    List list = new ArrayList();
    CMElementDeclaration parentDecl = getCMElementDeclaration(parent);
    if (parentDecl != null) {
        ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument());
        // taken from ActionManagers
        // int editMode = modelQuery.getEditMode();
        int editMode = ModelQuery.EDIT_MODE_UNCONSTRAINED;
        int ic = (editMode == ModelQuery.EDIT_MODE_CONSTRAINED_STRICT) ? ModelQuery.INCLUDE_CHILD_NODES | ModelQuery.INCLUDE_SEQUENCE_GROUPS : ModelQuery.INCLUDE_CHILD_NODES;
        modelQuery.getInsertActions(parent, parentDecl, index, ic, validityChecking, list);
    }
    list = filterAvailableModelQueryActions(list);
    return list;
}
Also used : CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) ArrayList(java.util.ArrayList) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 48 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class JFaceNodeAdapterFactory method initAdapter.

protected void initAdapter(INodeAdapter adapter, INodeNotifier node) {
    Assert.isTrue(cmDocumentManager == null);
    Assert.isTrue(fCMDocumentManagerListener == null);
    // register for CMDocumentManager events
    ModelQueryAdapter mqadapter = (ModelQueryAdapter) node.getAdapterFor(ModelQueryAdapter.class);
    if (mqadapter != null) {
        ModelQuery mquery = mqadapter.getModelQuery();
        if ((mquery != null) && (mquery.getCMDocumentManager() != null)) {
            cmDocumentManager = mquery.getCMDocumentManager();
            fCMDocumentManagerListener = new CMDocumentManagerListenerImpl();
            cmDocumentManager.addListener(fCMDocumentManagerListener);
        }
    }
}
Also used : ModelQueryAdapter(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 49 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class CMImageUtil method getDeclaration.

public static CMNode getDeclaration(Node node) {
    CMNode decl = null;
    ModelQuery mq = null;
    switch(node.getNodeType()) {
        case Node.ATTRIBUTE_NODE:
            {
                mq = ModelQueryUtil.getModelQuery(((Attr) node).getOwnerDocument());
                decl = mq.getCMAttributeDeclaration((Attr) node);
            }
            break;
        case Node.ELEMENT_NODE:
            {
                mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument());
                decl = mq.getCMElementDeclaration((Element) node);
            }
            break;
    }
    return decl;
}
Also used : CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 50 with ModelQuery

use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery in project webtools.sourceediting by eclipse.

the class ReloadDependenciesHandler method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor)
        textEditor = (ITextEditor) editor;
    else {
        Object o = editor.getAdapter(ITextEditor.class);
        if (o != null)
            textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
        if (model != null) {
            ModelQuery modelQuery = null;
            try {
                modelQuery = ModelQueryUtil.getModelQuery(model);
            } finally {
                model.releaseFromRead();
            }
            Document domDocument = ((IDOMModel) model).getDocument();
            if ((modelQuery != null) && (modelQuery.getCMDocumentManager() != null)) {
                modelQuery.getCMDocumentManager().getCMDocumentCache().clear();
                // TODO... need to figure out how to access the
                // DOMObserver via ModelQuery
                // ...why?
                CMDocumentLoader loader = new InferredGrammarBuildingCMDocumentLoader(domDocument, modelQuery);
                loader.loadCMDocuments();
            }
        }
    }
    return null;
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) InferredGrammarBuildingCMDocumentLoader(org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) CMDocumentLoader(org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.CMDocumentLoader) InferredGrammarBuildingCMDocumentLoader(org.eclipse.wst.xml.core.internal.contentmodel.modelqueryimpl.InferredGrammarBuildingCMDocumentLoader) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IEditorPart(org.eclipse.ui.IEditorPart) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IDocument(org.eclipse.jface.text.IDocument) Document(org.w3c.dom.Document) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)76 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)38 List (java.util.List)22 ArrayList (java.util.ArrayList)19 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)18 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)16 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)15 Element (org.w3c.dom.Element)15 Document (org.w3c.dom.Document)14 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)13 Node (org.w3c.dom.Node)12 Iterator (java.util.Iterator)10 CMAttributeDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)10 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)10 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)10 NodeList (org.w3c.dom.NodeList)10 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 IFile (org.eclipse.core.resources.IFile)6