Source:
<code>protected IEditorSite createSite(IEditorPart editor) { return new MultiPageEditorSite(this, editor) { @Override protected void handleSelectionChanged(SelectionChangedEvent event) { ISelectionProvider parentProvider = getMultiPageEditor().getSite().getSelectionProvider(); if (parentProvider instanceof MultiPageSelectionProvider) { SelectionChangedEvent newEvent = getNewEvent(parentProvider, event); MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; prov.fireSelectionChanged(newEvent); } } @Override protected void handlePostSelectionChanged(SelectionChangedEvent event) { ISelectionProvider parentProvider = getMultiPageEditor().getSite().getSelectionProvider(); if (parentProvider instanceof MultiPageSelectionProvider) { SelectionChangedEvent newEvent = getNewEvent(parentProvider, event); MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; prov.firePostSelectionChanged(newEvent); } } protected SelectionChangedEvent getNewEvent(ISelectionProvider parentProvider, SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; Object o = ss.getFirstElement(); if (o instanceof Node) { selection = getNewSelection((Node) o); } } if (selection != null) { return new SelectionChangedEvent(parentProvider, selection); } return event; } protected StructuredSelection getNewSelection(Node node) { int type = node.getNodeType(); <START> if (type == 1 || type == 3) { <END> return getNewSelection(node.getParentNode()); } else if (type == 2) { Attr attr = (Attr) node; return getNewSelection(attr.getOwnerElement()); } return null; } }; }</code><technical_language>constants defined in Node for values? more readable</technical_language>

Target:
protected IEditorSite createSite(IEditorPart editor) { return new MultiPageEditorSite(this, editor) { @Override protected void handleSelectionChanged(SelectionChangedEvent event) { ISelectionProvider parentProvider = getMultiPageEditor().getSite().getSelectionProvider(); if (parentProvider instanceof MultiPageSelectionProvider) { SelectionChangedEvent newEvent = getNewEvent(parentProvider, event); MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; prov.fireSelectionChanged(newEvent); } } @Override protected void handlePostSelectionChanged(SelectionChangedEvent event) { ISelectionProvider parentProvider = getMultiPageEditor().getSite().getSelectionProvider(); if (parentProvider instanceof MultiPageSelectionProvider) { SelectionChangedEvent newEvent = getNewEvent(parentProvider, event); MultiPageSelectionProvider prov = (MultiPageSelectionProvider) parentProvider; prov.firePostSelectionChanged(newEvent); } } protected SelectionChangedEvent getNewEvent(ISelectionProvider parentProvider, SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; Object o = ss.getFirstElement(); if (o instanceof Node) { selection = getNewSelection((Node) o); } } if (selection != null) { return new SelectionChangedEvent(parentProvider, selection); } return event; } protected StructuredSelection getNewSelection(Node node) { int type = node.getNodeType(); if (type == Node.ELEMENT_NODE || type == Node.TEXT_NODE) { return getNewSelection(node.getParentNode()); } else if (type == Node.ATTRIBUTE_NODE) { Attr attr = (Attr) node; return getNewSelection(attr.getOwnerElement()); } return null; } }; }