Search in sources :

Example 26 with DTDNode

use of org.eclipse.wst.dtd.core.internal.DTDNode in project webtools.sourceediting by eclipse.

the class DTDContextMenuHelper method addActionItemsForSelection.

void addActionItemsForSelection(Object selectedObject, IMenuManager menu) {
    if (selectedObject instanceof NodeList) {
        // add appropriate menu to logical view
        NodeList folder = (NodeList) selectedObject;
        if (folder.getListType().equals(DTDRegionTypes.NOTATION_TAG)) {
            menu.add(addNotationAction);
        } else if (folder.getListType().equals(DTDRegionTypes.ENTITY_TAG)) {
            menu.add(addEntityAction);
        } else if (folder.getListType().equals(DTDRegionTypes.ELEMENT_TAG)) {
            LabelValuePair[] availableEntities = fModel.createParmEntityContentItems(null);
            addParameterEntityReferenceAction.setEnabled(availableEntities.length > 0);
            menu.add(addElementAction);
            menu.add(addParameterEntityReferenceAction);
        } else if (folder.getListType().equals(DTDRegionTypes.ATTLIST_TAG)) {
            menu.add(addAttributeListAction);
        }
    }
    if (selectedObject instanceof DTDFile || selectedObject == null) {
        LabelValuePair[] availableEntities = fModel.createParmEntityContentItems(null);
        addParameterEntityReferenceAction.setEnabled(availableEntities.length > 0);
        menu.add(addElementAction);
        menu.add(addEntityAction);
        menu.add(addNotationAction);
        menu.add(addParameterEntityReferenceAction);
        menu.add(addCommentAction);
        menu.add(addAttributeListAction);
        menu.add(new Separator());
    }
    if (selectedObject instanceof Element) {
        Element dtdElement = (Element) selectedObject;
        CMNode contentModel = dtdElement.getContentModel();
        if (contentModel == null) {
            menu.add(addGroupToContentModelAction);
            menu.add(addElementToContentModelAction);
        } else if (contentModel != null && CMNode.EMPTY.equals(contentModel.getType())) {
            menu.add(replaceEmptyContentModelWithGroupAction);
        }
        menu.add(addAttributeAction);
    } else if (selectedObject instanceof CMGroupNode) {
        menu.add(addElementToContentModelAction);
        menu.add(addGroupToContentModelAction);
    } else if (selectedObject instanceof AttributeList) {
        menu.add(addAttributeAction);
    }
    menu.add(new Separator());
    addEditActions(menu);
    menu.add(new Separator());
    if (selectedObject instanceof DTDNode && !(selectedObject instanceof CMNode && ((CMNode) selectedObject).isRootElementContent())) {
        menu.add(deleteAction);
        deleteAction.setEnabled(true);
    }
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) LabelValuePair(org.eclipse.wst.dtd.core.internal.util.LabelValuePair) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) Element(org.eclipse.wst.dtd.core.internal.Element) CMNode(org.eclipse.wst.dtd.core.internal.CMNode) CMGroupNode(org.eclipse.wst.dtd.core.internal.CMGroupNode) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile) Separator(org.eclipse.jface.action.Separator)

Example 27 with DTDNode

use of org.eclipse.wst.dtd.core.internal.DTDNode in project webtools.sourceediting by eclipse.

the class DTDTreeContentProvider method getElementParentsOfAttributeList.

/**
 * @param attList get the element parents of the given {@link AttributeList}
 * @return the element parents of the given {@link AttributeList}, if no parents
 * can be found the list contains the DTD file element
 */
private List getElementParentsOfAttributeList(AttributeList attList) {
    List parents = new ArrayList();
    Iterator iterAttList = attList.getDTDFile().getNodes().iterator();
    while (iterAttList.hasNext()) {
        DTDNode currentNode = (DTDNode) iterAttList.next();
        if (currentNode instanceof Element && currentNode.getName().equals(attList.getName())) {
            parents.add(currentNode);
        }
    }
    if (parents.size() == 0) {
        parents.add(((DTDModelImpl) fInputObject).getDTDFile());
    }
    return parents;
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) Element(org.eclipse.wst.dtd.core.internal.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) NodeList(org.eclipse.wst.dtd.core.internal.NodeList)

Example 28 with DTDNode

use of org.eclipse.wst.dtd.core.internal.DTDNode in project webtools.sourceediting by eclipse.

the class DTDTreeContentProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    // otherwise
    if (parentElement instanceof DTDFile) {
        if (isShowLogicalOrder()) {
            // return the visible node lists
            if (logicalNodeLists == null) {
                Iterator nodeLists = ((DTDFile) parentElement).getNodeLists().iterator();
                List visibleLists = new ArrayList(7);
                while (nodeLists.hasNext()) {
                    NodeList list = (NodeList) nodeLists.next();
                    if (isVisibleNodeList(list)) {
                        visibleLists.add(list);
                    }
                }
                logicalNodeLists = visibleLists.toArray();
            }
            return logicalNodeLists;
        } else {
            // return the visible nodes
            List allNodes = ((DTDFile) parentElement).getNodes();
            List visibleNodes = new ArrayList(allNodes.size());
            for (int i = 0; i < allNodes.size(); i++) {
                Object o = allNodes.get(i);
                if (isVisibleNode(o)) {
                    visibleNodes.add(o);
                }
            }
            return visibleNodes.toArray();
        }
    } else if (parentElement instanceof NodeList) {
        return ((NodeList) parentElement).getNodes().toArray();
    } else if (parentElement instanceof Element) {
        // always group the attributes directly under the element
        Object[] children = ((DTDNode) parentElement).getChildren();
        List attributes = ((Element) parentElement).getElementAttributes();
        Object[] logicalChildren = new Object[children.length + attributes.size()];
        int index = 0;
        for (index = 0; index < children.length; index++) {
            logicalChildren[index] = children[index];
        }
        for (Iterator iter = attributes.iterator(); iter.hasNext(); ) {
            logicalChildren[index++] = iter.next();
        }
        return logicalChildren;
    } else if (parentElement instanceof DTDNode) {
        return ((DTDNode) parentElement).getChildren();
    }
    return Collections.EMPTY_LIST.toArray();
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) Element(org.eclipse.wst.dtd.core.internal.Element) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Example 29 with DTDNode

use of org.eclipse.wst.dtd.core.internal.DTDNode in project webtools.sourceediting by eclipse.

the class DTDTreeContentProvider method nodesAdded.

public void nodesAdded(NodesEvent event) {
    if (fViewer instanceof AbstractTreeViewer) {
        StructuredViewer viewer = (StructuredViewer) fViewer;
        ISelection selection = viewer.getSelection();
        Object firstObj = (!selection.isEmpty() && selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null;
        DTDNode oldSelectedNode = null;
        if (firstObj instanceof DTDNode) {
            oldSelectedNode = (DTDNode) firstObj;
        }
        // update the tree
        refreshTree(event);
        final List nodes = event.getNodes();
        if (!nodes.isEmpty()) {
            final DTDNode node = (DTDNode) nodes.get(0);
            if (oldSelectedNode == null || node.getStructuredDTDDocumentRegion() != oldSelectedNode.getStructuredDTDDocumentRegion() || node.getStartOffset() != oldSelectedNode.getStartOffset() || node.getEndOffset() != oldSelectedNode.getEndOffset()) {
                expandToNode(node);
                viewer.setSelection(new StructuredSelection(node));
            }
        }
    }
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) ArrayList(java.util.ArrayList) List(java.util.List) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 30 with DTDNode

use of org.eclipse.wst.dtd.core.internal.DTDNode in project webtools.sourceediting by eclipse.

the class AddAttributeAction method run.

public void run() {
    DTDNode selectedNode = getFirstNodeSelected();
    // $NON-NLS-1$
    String newName = "NewAttribute";
    if (selectedNode instanceof AttributeList) {
        ((AttributeList) selectedNode).addAttribute(newName);
    } else if (selectedNode instanceof Element) {
        ((Element) selectedNode).addAttribute(newName);
    }
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) Element(org.eclipse.wst.dtd.core.internal.Element)

Aggregations

DTDNode (org.eclipse.wst.dtd.core.internal.DTDNode)32 DTDFile (org.eclipse.wst.dtd.core.internal.DTDFile)13 Element (org.eclipse.wst.dtd.core.internal.Element)13 Iterator (java.util.Iterator)9 AttributeList (org.eclipse.wst.dtd.core.internal.AttributeList)8 NodeList (org.eclipse.wst.dtd.core.internal.NodeList)6 CMGroupNode (org.eclipse.wst.dtd.core.internal.CMGroupNode)5 CMNode (org.eclipse.wst.dtd.core.internal.CMNode)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Attribute (org.eclipse.wst.dtd.core.internal.Attribute)4 CMBasicNode (org.eclipse.wst.dtd.core.internal.CMBasicNode)3 Comment (org.eclipse.wst.dtd.core.internal.Comment)3 Entity (org.eclipse.wst.dtd.core.internal.Entity)3 Image (org.eclipse.swt.graphics.Image)2 ParameterEntityReference (org.eclipse.wst.dtd.core.internal.ParameterEntityReference)2 TopLevelNode (org.eclipse.wst.dtd.core.internal.TopLevelNode)2 DTDModelImpl (org.eclipse.wst.dtd.core.internal.document.DTDModelImpl)2 Separator (org.eclipse.jface.action.Separator)1