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);
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations