use of org.eclipse.wst.dtd.core.internal.DTDNode 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);
}
}
use of org.eclipse.wst.dtd.core.internal.DTDNode 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;
}
use of org.eclipse.wst.dtd.core.internal.DTDNode 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();
}
use of org.eclipse.wst.dtd.core.internal.DTDNode in project webtools.sourceediting by eclipse.
the class DTDTreeContentProvider method nodesAdded.
public void nodesAdded(NodesEvent event) {
if (fViewer instanceof AbstractTreeViewer) {
StructuredViewer viewer = (StructuredViewer) fViewer;
ISelection selection = viewer.getSelection();
Object firstObj = (!selection.isEmpty() && selection instanceof IStructuredSelection) ? ((IStructuredSelection) selection).getFirstElement() : null;
DTDNode oldSelectedNode = null;
if (firstObj instanceof DTDNode) {
oldSelectedNode = (DTDNode) firstObj;
}
// update the tree
refreshTree(event);
final List nodes = event.getNodes();
if (!nodes.isEmpty()) {
final DTDNode node = (DTDNode) nodes.get(0);
if (oldSelectedNode == null || node.getStructuredDTDDocumentRegion() != oldSelectedNode.getStructuredDTDDocumentRegion() || node.getStartOffset() != oldSelectedNode.getStartOffset() || node.getEndOffset() != oldSelectedNode.getEndOffset()) {
expandToNode(node);
viewer.setSelection(new StructuredSelection(node));
}
}
}
}
use of org.eclipse.wst.dtd.core.internal.DTDNode in project webtools.sourceediting by eclipse.
the class AddAttributeAction method run.
public void run() {
DTDNode selectedNode = getFirstNodeSelected();
// $NON-NLS-1$
String newName = "NewAttribute";
if (selectedNode instanceof AttributeList) {
((AttributeList) selectedNode).addAttribute(newName);
} else if (selectedNode instanceof Element) {
((Element) selectedNode).addAttribute(newName);
}
}
Aggregations