Search in sources :

Example 6 with ModelQueryAction

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

the class BaseNodeActionManager method addActionHelper.

protected void addActionHelper(IMenuManager menu, List modelQueryActionList) {
    List actionList = new Vector();
    for (Iterator i = modelQueryActionList.iterator(); i.hasNext(); ) {
        ModelQueryAction action = (ModelQueryAction) i.next();
        if (action.getCMNode() != null) {
            int cmNodeType = action.getCMNode().getNodeType();
            if (action.getKind() == ModelQueryAction.INSERT) {
                switch(cmNodeType) {
                    case CMNode.ATTRIBUTE_DECLARATION:
                        {
                            actionList.add(createAddAttributeAction((Element) action.getParent(), (CMAttributeDeclaration) action.getCMNode()));
                            break;
                        }
                    case CMNode.ELEMENT_DECLARATION:
                        {
                            actionList.add(createAddElementAction(action.getParent(), (CMElementDeclaration) action.getCMNode(), action.getStartIndex()));
                            break;
                        }
                }
            } else if (action.getKind() == ModelQueryAction.REPLACE) {
                if ((action.getParent() != null) && (action.getCMNode() != null)) {
                    actionList.add(createReplaceAction(action.getParent(), action.getCMNode(), action.getStartIndex(), action.getEndIndex()));
                }
            }
        }
    }
    menuBuilder.populateMenu(menu, actionList, false);
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) Vector(java.util.Vector)

Example 7 with ModelQueryAction

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

the class AbstractXMLModelQueryCompletionProposalComputer method filterAvailableModelQueryActions.

/**
 * <p>Filters out any model query actions that are not valid for this
 * implementation of the model query computer based on the {@link CMNode}
 * of the action.</p>
 *
 * @param modelQueryActions
 * @return the filtered list of {@link ModelQueryAction}s
 */
private List filterAvailableModelQueryActions(List modelQueryActions) {
    List filtered = new ArrayList(modelQueryActions.size());
    Iterator iterator = modelQueryActions.iterator();
    while (iterator.hasNext()) {
        ModelQueryAction action = (ModelQueryAction) iterator.next();
        if (validModelQueryNode(action.getCMNode())) {
            filtered.add(action);
        }
    }
    return filtered;
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList)

Example 8 with ModelQueryAction

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

the class AbstractXMLElementContentAssistRequest method getAvailableChildElementDeclarations.

/**
 * Returns a list of CMNodes that are available within this parent context
 * Given the grammar shown below and a snippet of XML code (where the '|'
 * indicated the cursor position)
 * the list would return all of the element declarations that are
 * potential child elements of Foo.
 *
 * grammar : Foo -> (A, B, C)
 * snippet : <Foo><A>|
 * result : {A, B, C}
 *
 * @param parent
 * @param childPosition
 * @return
 */
protected List<CMNode> getAvailableChildElementDeclarations(Element parent, int childPosition) {
    List modelQueryActions = getAvailableChildrenAtIndex(parent, childPosition, ModelQuery.VALIDITY_NONE);
    Iterator iterator = modelQueryActions.iterator();
    List<CMNode> cmnodes = new Vector();
    while (iterator.hasNext()) {
        ModelQueryAction action = (ModelQueryAction) iterator.next();
        if ((childPosition < 0) || (((action.getStartIndex() <= childPosition) && (childPosition <= action.getEndIndex())))) {
            CMNode actionCMNode = action.getCMNode();
            if ((actionCMNode != null) && !cmnodes.contains(actionCMNode)) {
                cmnodes.add(actionCMNode);
            }
        }
    }
    return cmnodes;
}
Also used : ModelQueryAction(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Vector(java.util.Vector)

Aggregations

ArrayList (java.util.ArrayList)8 Iterator (java.util.Iterator)8 List (java.util.List)8 ModelQueryAction (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQueryAction)8 Vector (java.util.Vector)6 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)5 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)5 NodeList (org.w3c.dom.NodeList)4 CMNodeList (org.eclipse.wst.xml.core.internal.contentmodel.CMNodeList)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)1 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)1