Search in sources :

Example 1 with NodeList

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

the class DTDTreeContentProvider method expandToNode.

private void expandToNode(DTDNode node) {
    DTDFile dtdFile = node.getDTDFile();
    // first expand the root
    AbstractTreeViewer viewer = (AbstractTreeViewer) fViewer;
    viewer.expandToLevel(dtdFile, 1);
    NodeList listToExpand = null;
    if (node instanceof Element || node instanceof ParameterEntityReference) {
        listToExpand = dtdFile.getElementsAndParameterEntityReferences();
    } else if (node instanceof Notation) {
        listToExpand = dtdFile.getNotations();
    } else if (node instanceof Entity) {
        listToExpand = dtdFile.getEntities();
    } else if (node instanceof Comment) {
        listToExpand = dtdFile.getComments();
    }
    if (listToExpand != null) {
        viewer.expandToLevel(listToExpand, 1);
    }
    viewer.expandToLevel(node, 0);
}
Also used : ParameterEntityReference(org.eclipse.wst.dtd.core.internal.ParameterEntityReference) Entity(org.eclipse.wst.dtd.core.internal.Entity) Comment(org.eclipse.wst.dtd.core.internal.Comment) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) Element(org.eclipse.wst.dtd.core.internal.Element) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Notation(org.eclipse.wst.dtd.core.internal.Notation) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Example 2 with NodeList

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

the class DTDTreeContentProvider method getParents.

/**
 * @param element get the tree parents of this element
 * @return {@link List} of parents of the given element
 */
private List getParents(Object element) {
    List parents = new ArrayList();
    Object parent = null;
    if (element instanceof DTDNode) {
        DTDNode node = (DTDNode) element;
        if (element instanceof Attribute) {
            parent = node.getParentNode();
            if (parent != null && parent instanceof AttributeList) {
                parents.addAll(getElementParentsOfAttributeList((AttributeList) parent));
            }
        } else if (element instanceof AttributeList) {
            parents.addAll(getElementParentsOfAttributeList((AttributeList) element));
        }
        // acting as a parent in the tree
        if (isShowLogicalOrder()) {
            Object[] indexedNodeLists = getChildren(((DTDModelImpl) fInputObject).getDTDFile());
            for (int i = 0; i < indexedNodeLists.length && parent == null; i++) {
                if (indexedNodeLists[i] instanceof NodeList) {
                    if (((NodeList) indexedNodeLists[i]).getNodes().contains(element)) {
                        parents.add(indexedNodeLists[i]);
                    }
                }
            }
        }
        // try and get the simple parent
        parent = ((DTDNode) element).getParentNode();
        if (parent != null) {
            parents.add(parent);
        }
        // if no parents found must be new nodes so refresh from root
        if (parents.size() == 0) {
            parents.add(((DTDModelImpl) fInputObject).getDTDFile());
        }
    } else if (element instanceof NodeList && fInputObject instanceof DTDModelImpl) {
        parents.add(((DTDModelImpl) fInputObject).getDTDFile());
    }
    return parents;
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) DTDModelImpl(org.eclipse.wst.dtd.core.internal.document.DTDModelImpl) Attribute(org.eclipse.wst.dtd.core.internal.Attribute) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) 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)

Example 3 with NodeList

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

the class DTDModelImpl method createParmEntityContentItems.

// 
// The following function helps determine the list of things that
// can be used in a parameter entity reference content
// Optional parameter is to allow the currently used DTDEntity to
// be included in the combobox.
// 
public LabelValuePair[] createParmEntityContentItems(Entity entity) {
    NodeList entities = getDTDFile().getEntities();
    Vector items = new Vector();
    if (entity != null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        String name = "%" + entity.getName() + ";";
        items.addElement(new LabelValuePair(name, name));
    }
    for (Iterator i = entities.getNodes().iterator(); i.hasNext(); ) {
        Entity entityAt = (Entity) i.next();
        if (entityAt.isParameterEntity() && entityAt.isExternalEntity()) {
            // $NON-NLS-1$ //$NON-NLS-2$
            String name = "%" + entityAt.getName() + ";";
            items.addElement(new LabelValuePair(name, name));
        }
    }
    LabelValuePair[] comboArray = new LabelValuePair[items.size()];
    items.copyInto(comboArray);
    return comboArray;
}
Also used : Entity(org.eclipse.wst.dtd.core.internal.Entity) LabelValuePair(org.eclipse.wst.dtd.core.internal.util.LabelValuePair) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) Iterator(java.util.Iterator) Vector(java.util.Vector)

Example 4 with NodeList

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

the class DTDLabelProvider method getImage.

/**
 * Returns the image for the label of the given element.
 *
 * @param element
 *            the element for which to provide the label image
 * @return the image used to label the element, or <code>null</code> if
 *         these is no image for the given object
 */
public Image getImage(Object element) {
    Image image = null;
    if (element instanceof DTDNode) {
        final String imgPath = ((DTDNode) element).getImagePath();
        image = imgPath != null ? DTDUIPlugin.getDefault().getImage(imgPath) : null;
    } else if (element instanceof NodeList) {
        final String imgPath = ((NodeList) element).getImagePath();
        image = imgPath != null ? DTDUIPlugin.getDefault().getImage(imgPath) : null;
    } else if (element instanceof DTDFile) {
        image = DTDUIPlugin.getDefault().getImage(DTDResource.DTDFILEICON);
    } else {
        image = super.getImage(element);
    }
    return image;
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) NodeList(org.eclipse.wst.dtd.core.internal.NodeList) Image(org.eclipse.swt.graphics.Image) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Example 5 with NodeList

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

Aggregations

NodeList (org.eclipse.wst.dtd.core.internal.NodeList)6 DTDFile (org.eclipse.wst.dtd.core.internal.DTDFile)4 DTDNode (org.eclipse.wst.dtd.core.internal.DTDNode)4 AttributeList (org.eclipse.wst.dtd.core.internal.AttributeList)3 Element (org.eclipse.wst.dtd.core.internal.Element)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Entity (org.eclipse.wst.dtd.core.internal.Entity)2 LabelValuePair (org.eclipse.wst.dtd.core.internal.util.LabelValuePair)2 Vector (java.util.Vector)1 Separator (org.eclipse.jface.action.Separator)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 Image (org.eclipse.swt.graphics.Image)1 Attribute (org.eclipse.wst.dtd.core.internal.Attribute)1 CMGroupNode (org.eclipse.wst.dtd.core.internal.CMGroupNode)1 CMNode (org.eclipse.wst.dtd.core.internal.CMNode)1 Comment (org.eclipse.wst.dtd.core.internal.Comment)1 Notation (org.eclipse.wst.dtd.core.internal.Notation)1 ParameterEntityReference (org.eclipse.wst.dtd.core.internal.ParameterEntityReference)1