@Override
protected EditPart convert(EditPartViewer viewer, EditPart part) {
Object o = part.getModel();
if (o instanceof RouteSupport) {
RouteSupport newRoute = (RouteSupport)o;
RouteSupport oldRoute = editor.getSelectedRoute();
if (!oldRoute.equals(newRoute)) {
// user selected a route which is not currently displayed in the diagram editor -> we need to load the route into the editor now first
editor.switchRoute(newRoute);
}
// the route was selected - so we need to return the topmost editPart
return viewer.getRootEditPart();
} else if (o instanceof RouteContainer) {
return viewer.getRootEditPart();
} else if (o instanceof AbstractNode) {
PictogramElement[] pes = editor.getFeatureProvider().getAllPictogramElementsForBusinessObject(o);
if (pes.length>0) {
AbstractNode node = (AbstractNode)o;
RouteSupport oldRoute = editor.getSelectedRoute();
RouteSupport newRoute = (RouteSupport)node.getParent();
if (!oldRoute.equals(newRoute)) {
editor.switchRoute(newRoute);
editor.autoLayoutRoute();
}
}
if (pes.length == 0) {
// an element from another route was selected - we need to load the route into the diagram
AbstractNode node = (AbstractNode)o;
editor.switchRoute((RouteSupport)node.getParent());
editor.getDiagramBehavior().refreshContent();
Iterator<?> it = viewer.getEditPartRegistry().entrySet().iterator();
while (it.hasNext()) {
Entry<?, ?> e = (Entry<?, ?>)it.next();
Object key = e.getKey();
EditPart value = (EditPart)e.getValue();
if (key instanceof ContainerShape) {
ContainerShape cs = (ContainerShape)key;
if (cs.getLink() != null &&
cs.getLink().getBusinessObjects() != null &&
cs.getLink().getBusinessObjects().size() > 0 &&
cs.getLink().getBusinessObjects().get(0) != null &&
cs.getLink().getBusinessObjects().get(0).equals(o)) {
// found the correct entry
return value;
}
}
continue;
}
// if all fails return the root edit part
return viewer.getRootEditPart();
}
return editor.getDiagramBehavior().getEditPartForPictogramElement(pes[0]);
} else if (o instanceof Diagram) {
// someone selected the route inside the diagram editor
RouteSupport route = editor.getSelectedRoute();
return getEditPart(viewer, route);
} else if (o instanceof ContainerShape) {
// someone selected a diagram figure in the diagram editor
AbstractNode node = null;
node = (AbstractNode)Activator.getDiagramEditor().getFeatureProvider().getBusinessObjectForPictogramElement(((ContainerShape)o));