Search in sources :

Example 1 with AttributeList

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

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

the class DragAttributeCommand method execute.

public void execute() {
    DTDNode referenceNode = (DTDNode) target;
    DTDFile dtdFile = referenceNode.getDTDFile();
    if (referenceNode instanceof Attribute) {
        // $NON-NLS-1$
        dtdFile.getDTDModel().beginRecording(this, DTDUIMessages._UI_MOVE_ATTRIBUTE);
        AttributeList attList = (AttributeList) referenceNode.getParentNode();
        Iterator iter = sources.iterator();
        while (iter.hasNext()) {
            DTDNode node = (DTDNode) iter.next();
            if (node instanceof Attribute) {
                attList.insertIntoModel(this, (Attribute) referenceNode, (Attribute) node, isAfter());
                dtdFile.deleteNode(this, node);
            }
        }
        dtdFile.getDTDModel().endRecording(this);
    }
}
Also used : DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) Attribute(org.eclipse.wst.dtd.core.internal.Attribute) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) Iterator(java.util.Iterator) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile)

Example 3 with AttributeList

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

the class DTDSectionLabelProvider method getText.

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
 */
public String getText(Object object) {
    if (object == null || object.equals(StructuredSelection.EMPTY)) {
        return null;
    }
    Object selected = object;
    if (object instanceof IStructuredSelection) {
        selected = ((IStructuredSelection) object).getFirstElement();
    }
    if (selected instanceof DTDFile) {
        return ((DTDFile) selected).getName();
    } else if (selected instanceof CMBasicNode) {
        if (((CMBasicNode) selected).isReference())
            return DTDPropertiesMessages._UI_PROPERTIES_VIEW_TITLE_ELEMENT_REF;
        else
            return ((CMBasicNode) selected).getName();
    } else if (selected instanceof CMRepeatableNode) {
        CMRepeatableNode node = (CMRepeatableNode) selected;
        String name = node.getName();
        if (node instanceof CMGroupNode) {
            if (((CMGroupNode) node).getConnector() == CMGroupNode.CHOICE)
                name = DTDPropertiesMessages.DTDSectionLabelProvider_0;
            else
                name = DTDPropertiesMessages.DTDSectionLabelProvider_1;
        }
        char occurrence = node.getOccurrence();
        switch(occurrence) {
            case CMRepeatableNode.ONCE:
                // $NON-NLS-1$
                name += " [1..1]";
                break;
            case CMRepeatableNode.OPTIONAL:
                // $NON-NLS-1$
                name += " [0..1]";
                break;
            case CMRepeatableNode.ONE_OR_MORE:
                // $NON-NLS-1$
                name += " [1..*]";
                break;
            case CMRepeatableNode.ZERO_OR_MORE:
                // $NON-NLS-1$
                name += " [0..*]";
                break;
        }
        return name;
    } else if (selected instanceof DTDNode) {
        if (selected instanceof Element)
            return DTDPropertiesMessages.DTDSectionLabelProvider_6;
        else if (selected instanceof Attribute)
            return DTDPropertiesMessages.DTDSectionLabelProvider_7;
        else if (selected instanceof AttributeList)
            return DTDPropertiesMessages.DTDSectionLabelProvider_8;
        else if (selected instanceof Comment)
            return DTDPropertiesMessages.DTDSectionLabelProvider_9;
        else if (selected instanceof Entity)
            return DTDPropertiesMessages.DTDSectionLabelProvider_10;
        else if (selected instanceof Notation)
            return DTDPropertiesMessages.DTDSectionLabelProvider_11;
        else if (selected instanceof ParameterEntityReference)
            // return "parameter entity reference";
            return null;
        else
            return ((DTDNode) selected).getName();
    } else if (selected instanceof org.w3c.dom.Element) {
        return ((org.w3c.dom.Element) selected).getLocalName();
    } else if (object instanceof ITextSelection) {
        // $NON-NLS-1$
        return "";
    } else
        return object.toString();
}
Also used : Comment(org.eclipse.wst.dtd.core.internal.Comment) Entity(org.eclipse.wst.dtd.core.internal.Entity) CMRepeatableNode(org.eclipse.wst.dtd.core.internal.CMRepeatableNode) Attribute(org.eclipse.wst.dtd.core.internal.Attribute) AttributeList(org.eclipse.wst.dtd.core.internal.AttributeList) Element(org.eclipse.wst.dtd.core.internal.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) CMGroupNode(org.eclipse.wst.dtd.core.internal.CMGroupNode) Notation(org.eclipse.wst.dtd.core.internal.Notation) DTDFile(org.eclipse.wst.dtd.core.internal.DTDFile) ITextSelection(org.eclipse.jface.text.ITextSelection) ParameterEntityReference(org.eclipse.wst.dtd.core.internal.ParameterEntityReference) DTDNode(org.eclipse.wst.dtd.core.internal.DTDNode) CMBasicNode(org.eclipse.wst.dtd.core.internal.CMBasicNode)

Example 4 with AttributeList

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

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

Aggregations

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