Search in sources :

Example 11 with Element

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

the class DTDModelUpdater method objectAboutToBeDeleted.

public synchronized void objectAboutToBeDeleted(Object requestor, DTDNode node) {
    if (isUpdating) {
        return;
    }
    if (!(node instanceof Entity || node instanceof Element)) {
        // just ignore if it is not one of these
        return;
    }
    if (node instanceof Entity && !((Entity) node).isParameterEntity()) {
        // if it is not a parameter entity, ignore as well
        return;
    }
    isUpdating = true;
    this.requestor = requestor;
    this.nodeToDelete = node;
    oldRefName = node.getName();
    isParmEntity = false;
    nodesToDelete.clear();
    if (node instanceof Entity) {
        isParmEntity = true;
        // $NON-NLS-1$ //$NON-NLS-2$
        oldRefName = "%" + oldRefName + ";";
    }
    DTDFile dtdFile = node.getDTDFile();
    visit(dtdFile);
    for (int i = 0; i < nodesToDelete.size(); i++) {
        dtdFile.deleteNode(requestor, (DTDNode) nodesToDelete.get(i));
    }
    isUpdating = false;
}
Also used : Entity(org.eclipse.wst.dtd.core.internal.Entity) Element(org.eclipse.wst.dtd.core.internal.Element) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Example 12 with Element

use of org.eclipse.wst.dtd.core.internal.Element 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 13 with Element

use of org.eclipse.wst.dtd.core.internal.Element 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 14 with Element

use of org.eclipse.wst.dtd.core.internal.Element 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 15 with Element

use of org.eclipse.wst.dtd.core.internal.Element 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

Element (org.eclipse.wst.dtd.core.internal.Element)15 DTDNode (org.eclipse.wst.dtd.core.internal.DTDNode)12 DTDFile (org.eclipse.wst.dtd.core.internal.DTDFile)8 Entity (org.eclipse.wst.dtd.core.internal.Entity)6 Iterator (java.util.Iterator)5 AttributeList (org.eclipse.wst.dtd.core.internal.AttributeList)5 CMGroupNode (org.eclipse.wst.dtd.core.internal.CMGroupNode)4 CMNode (org.eclipse.wst.dtd.core.internal.CMNode)4 NodeList (org.eclipse.wst.dtd.core.internal.NodeList)4 CMBasicNode (org.eclipse.wst.dtd.core.internal.CMBasicNode)3 Notation (org.eclipse.wst.dtd.core.internal.Notation)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Comment (org.eclipse.wst.dtd.core.internal.Comment)2 ParameterEntityReference (org.eclipse.wst.dtd.core.internal.ParameterEntityReference)2 Separator (org.eclipse.jface.action.Separator)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Attribute (org.eclipse.wst.dtd.core.internal.Attribute)1