Search in sources :

Example 21 with ModelQuery

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

the class XMLPropertySheetConfiguration method getInputSelection.

public ISelection getInputSelection(IWorkbenchPart selectingPart, ISelection selection) {
    if (fSelectedNotifiers != null) {
        for (int i = 0; i < fSelectedNotifiers.length; i++) {
            fSelectedNotifiers[i].removeAdapter(fRefreshAdapter);
        }
        fSelectedNotifiers = null;
    }
    for (int i = 0; i < fSelectedCMDocumentManagers.length; i++) {
        fSelectedCMDocumentManagers[i].removeListener(fCMDocumentManagerListener);
    }
    ISelection preferredSelection = selection;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSel = (IStructuredSelection) selection;
        /*
			 * On Attr nodes, select the owner Element. On Text nodes, select
			 * the parent Element.
			 */
        Object[] selectedObjects = new Object[structuredSel.size()];
        System.arraycopy(structuredSel.toArray(), 0, selectedObjects, 0, selectedObjects.length);
        for (int i = 0; i < selectedObjects.length; i++) {
            Object inode = selectedObjects[i];
            if (inode instanceof Node) {
                Node node = (Node) inode;
                // replace Attribute Node with its owner
                Node parentNode = node.getParentNode();
                if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
                    Element ownerElement = ((Attr) node).getOwnerElement();
                    selectedObjects[i] = ownerElement;
                } else // replace Text Node with its parent
                if (((node.getNodeType() == Node.TEXT_NODE) || (node.getNodeType() == Node.CDATA_SECTION_NODE)) && (parentNode != null)) {
                    selectedObjects[i] = parentNode;
                }
            }
        }
        if (selectedObjects.length > 0) {
            Set managers = new HashSet(1);
            Set selectedNotifiers = new HashSet(1);
            for (int i = 0; i < selectedObjects.length; i++) {
                if (selectedObjects[i] instanceof Node) {
                    ModelQuery query = ModelQueryUtil.getModelQuery(((Node) selectedObjects[i]).getOwnerDocument());
                    if (query != null) {
                        CMDocumentManager mgr = query.getCMDocumentManager();
                        if (mgr != null) {
                            managers.add(mgr);
                            mgr.addListener(fCMDocumentManagerListener);
                        }
                    }
                }
                /*
					 * Add UI refresh adapters and remember notifiers for
					 * later removal
					 */
                if (selectedObjects[i] instanceof INodeNotifier) {
                    selectedNotifiers.add(selectedObjects[i]);
                    ((INodeNotifier) selectedObjects[i]).addAdapter(fRefreshAdapter);
                }
            }
            fSelectedCMDocumentManagers = (CMDocumentManager[]) managers.toArray(new CMDocumentManager[managers.size()]);
            fSelectedNotifiers = (INodeNotifier[]) selectedNotifiers.toArray(new INodeNotifier[selectedNotifiers.size()]);
        }
        preferredSelection = new StructuredSelection(selectedObjects);
    }
    return preferredSelection;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Attr(org.w3c.dom.Attr) ISelection(org.eclipse.jface.viewers.ISelection) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) HashSet(java.util.HashSet)

Example 22 with ModelQuery

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

the class XMLTableTreeContentProvider method inputChanged.

public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    // remove our listeners to the old state
    if (oldInput != null) {
        Document domDoc = (Document) oldInput;
        ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
        if (mq != null) {
            documentManager = mq.getCMDocumentManager();
            if (documentManager != null) {
                documentManager.removeListener(this);
            }
        }
    }
    if ((oldInput != null) && (oldInput instanceof IDOMNode)) {
        IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) oldInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
        if (factory != null) {
            factory.removeListener(viewer);
        }
    }
    if (viewer instanceof StructuredViewer) {
        fViewer = null;
    } else {
        fViewer = (StructuredViewer) viewer;
    }
    if ((newInput != null) && (newInput instanceof IDOMNode)) {
        IJFaceNodeAdapterFactory factory = (IJFaceNodeAdapterFactory) ((IDOMNode) newInput).getModel().getFactoryRegistry().getFactoryFor(IJFaceNodeAdapter.class);
        if (factory != null) {
            factory.addListener(viewer);
        }
    }
    if (newInput != null) {
        Document domDoc = (Document) newInput;
        ModelQuery mq = ModelQueryUtil.getModelQuery(domDoc);
        if (mq != null) {
            documentManager = mq.getCMDocumentManager();
            if (documentManager != null) {
                documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
                documentManager.addListener(this);
            }
        }
    }
}
Also used : IJFaceNodeAdapterFactory(org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapterFactory) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Document(org.w3c.dom.Document) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IJFaceNodeAdapter(org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter)

Example 23 with ModelQuery

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

the class XMLTableTreePropertyDescriptorFactory method createAttributePropertyDescriptor.

public IPropertyDescriptor createAttributePropertyDescriptor(Attr attr) {
    IPropertyDescriptor result = null;
    String attributeName = attr.getName();
    ModelQuery mq = ModelQueryUtil.getModelQuery(attr.getOwnerDocument());
    CMAttributeDeclaration ad = null;
    if (mq != null) {
        ad = mq.getCMAttributeDeclaration(attr);
    }
    if (ad != null) {
        result = createPropertyDescriptorHelper(attributeName, attr.getOwnerElement(), ad);
    }
    if (result == null) {
        result = new TextPropertyDescriptor(attributeName, attributeName);
    }
    return result;
}
Also used : ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor)

Example 24 with ModelQuery

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

the class XMLTableTreePropertyDescriptorFactory method createPropertyDescriptorHelper.

protected IPropertyDescriptor createPropertyDescriptorHelper(String name, Element element, CMNode cmNode) {
    IPropertyDescriptor result = null;
    ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument());
    String[] valuesArray = null;
    if (mq != null) {
        valuesArray = mq.getPossibleDataTypeValues(element, cmNode);
    }
    if ((valuesArray != null) && (valuesArray.length > 0)) {
        result = new EnumeratedStringPropertyDescriptor(name, name, valuesArray);
    } else {
        result = createDefaultPropertyDescriptor(name);
    }
    return result;
}
Also used : ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) EnumeratedStringPropertyDescriptor(org.eclipse.wst.xml.ui.internal.properties.EnumeratedStringPropertyDescriptor)

Example 25 with ModelQuery

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

the class ElementImpl method getDeclaration.

/**
 */
protected CMElementDeclaration getDeclaration() {
    Document document = getOwnerDocument();
    if (document == null)
        return null;
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
    if (modelQuery == null)
        return null;
    return modelQuery.getCMElementDeclaration(this);
}
Also used : ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) Document(org.w3c.dom.Document) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)

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