Search in sources :

Example 11 with DTDNode

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

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

the class AddAttributeAction method updateSelection.

protected boolean updateSelection(IStructuredSelection selection) {
    boolean rc = super.updateSelection(selection);
    DTDNode node = getFirstNodeSelected(selection);
    if (node instanceof Element) {
        // System.out.println("attribute set to true");
        setEnabled(true);
    } else {
        // System.out.println("attribute set to false");
        setEnabled(false);
    }
    return rc;
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) Element(org.eclipse.wst.dtd.core.internal.Element)

Example 13 with DTDNode

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

the class AddElementToContentModelAction method updateSelection.

protected boolean updateSelection(IStructuredSelection selection) {
    boolean rc = super.updateSelection(selection);
    DTDNode node = getFirstNodeSelected(selection);
    if (node instanceof CMGroupNode) {
        setEnabled(true);
    } else {
        setEnabled(false);
    }
    return rc;
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) CMGroupNode(org.eclipse.wst.dtd.core.internal.CMGroupNode)

Example 14 with DTDNode

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

the class DeleteAction method run.

public void run() {
    IStructuredSelection selection = getStructuredSelection();
    Iterator iter = selection.iterator();
    DTDBatchNodeDelete batchDelete = null;
    DTDFile dtdFile = null;
    while (iter.hasNext()) {
        Object element = iter.next();
        if (element instanceof DTDNode) {
            DTDNode node = (DTDNode) element;
            dtdFile = node.getDTDFile();
            if (batchDelete == null) {
                batchDelete = new DTDBatchNodeDelete(dtdFile);
            }
            batchDelete.addNode((DTDNode) element);
        }
    }
    // $NON-NLS-1$
    dtdFile.getDTDModel().beginRecording(this, DTDUIMessages._UI_LABEL_DTD_FILE_DELETE);
    batchDelete.deleteNodes(this);
    dtdFile.getDTDModel().endRecording(this);
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) DTDBatchNodeDelete(org.eclipse.wst.dtd.core.internal.util.DTDBatchNodeDelete) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Example 15 with DTDNode

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

the class DTDModelUpdater method visitReference.

public void visitReference(CMBasicNode node) {
    super.visitReference(node);
    if (node.getName().equals(oldRefName)) {
        DTDNode parent = (DTDNode) node.getParentNode();
        parent.delete(requestor, node);
    }
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode)

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