Search in sources :

Example 16 with DTDFile

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

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

the class DTDTreeContentProvider method refreshTree.

/**
 * <p>Refreshes the tree from the parents of the given node.</p>
 * @param node refresh the tree from the parents of this node
 */
private void refreshTree(Object node) {
    List parents = getParents(node);
    if (parents.size() > 0) {
        for (int p = 0; p < parents.size(); ++p) {
            final Object parent = parents.get(p);
            // insert the node directly to improve performance
            if (parent instanceof DTDFile) {
                Object[] objs = getChildren(parent);
                for (int i = 0; i < objs.length; i++) {
                    if (objs[i] == node) {
                        ((AbstractTreeViewer) fViewer).insert(parent, node, i);
                        break;
                    }
                }
            }
            this.refreshTreeNode(parent, true);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Example 18 with DTDFile

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

the class AddParameterEntityReferenceAction method run.

public void run() {
    DTDFile dtdFile = getModel().getDTDFile();
    String extEntity = getFirstExternalParameterEntity(dtdFile);
    DTDNode selectedNode = getFirstNodeSelected();
    if (extEntity != null) {
        dtdFile.createParameterEntityReference(selectedNode, extEntity, true);
    } else {
        // $NON-NLS-1$
        dtdFile.createParameterEntityReference(selectedNode, "%NewEntityReference;", true);
    }
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Aggregations

DTDFile (org.eclipse.wst.dtd.core.internal.DTDFile)18 DTDNode (org.eclipse.wst.dtd.core.internal.DTDNode)13 Element (org.eclipse.wst.dtd.core.internal.Element)9 Iterator (java.util.Iterator)5 AttributeList (org.eclipse.wst.dtd.core.internal.AttributeList)5 NodeList (org.eclipse.wst.dtd.core.internal.NodeList)5 Entity (org.eclipse.wst.dtd.core.internal.Entity)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 CMGroupNode (org.eclipse.wst.dtd.core.internal.CMGroupNode)3 Notation (org.eclipse.wst.dtd.core.internal.Notation)3 ParameterEntityReference (org.eclipse.wst.dtd.core.internal.ParameterEntityReference)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)2 Image (org.eclipse.swt.graphics.Image)2 Attribute (org.eclipse.wst.dtd.core.internal.Attribute)2 CMNode (org.eclipse.wst.dtd.core.internal.CMNode)2 Comment (org.eclipse.wst.dtd.core.internal.Comment)2 Separator (org.eclipse.jface.action.Separator)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1