}
@Override
public void buildContextMenu( final IMenuManager menuManager )
{
final ISapphirePart part;
final DiagramPresentation presentation;
final GraphicalEditPart editPart;
final String context;
final List<GraphicalEditPart> selection = this.editor.getSelectedEditParts();
List<ISapphirePart> emptySelection = new ArrayList<ISapphirePart>();
if( selection.size() == 1 )
{
editPart = selection.get( 0 );
if( editPart instanceof SapphireDiagramEditorPageEditPart )
{
context = SapphireActionSystem.CONTEXT_DIAGRAM_EDITOR;
presentation = this.editor.getDiagramPresentation();
}
else if( editPart instanceof DiagramNodeEditPart )
{
DiagramNodeEditPart nodePart = (DiagramNodeEditPart)editPart;
if (isMouseOnEditPart(nodePart))
{
context = SapphireActionSystem.CONTEXT_DIAGRAM_NODE;
presentation = ((DiagramNodeEditPart)editPart).getPresentation();
}
else
{
this.editor.selectParts(emptySelection);
context = SapphireActionSystem.CONTEXT_DIAGRAM_EDITOR;
presentation = this.editor.getDiagramPresentation();
}
}
else if (editPart instanceof ShapeEditPart)
{
DiagramNodeEditPart nodePart = ((ShapeEditPart)editPart).getNodeEditPart();
if (isMouseOnEditPart(nodePart))
{
context = SapphireActionSystem.CONTEXT_DIAGRAM_NODE_SHAPE;
presentation = ((ShapeEditPart)editPart).getShapePresentation();
}
else
{
this.editor.selectParts(emptySelection);
context = SapphireActionSystem.CONTEXT_DIAGRAM_EDITOR;
presentation = this.editor.getDiagramPresentation();
}
}
else if( editPart instanceof DiagramConnectionEditPart )
{
if (isMouseOnEditPart(editPart))
{
context = SapphireActionSystem.CONTEXT_DIAGRAM_CONNECTION;
presentation = ((DiagramConnectionEditPart)editPart).getPresentation();
}
else
{
this.editor.selectParts(emptySelection);
context = SapphireActionSystem.CONTEXT_DIAGRAM_EDITOR;
presentation = this.editor.getDiagramPresentation();
}
}
else if( editPart instanceof DiagramConnectionLabelEditPart )
{
return;
}
else
{
throw new IllegalStateException();
}
part = presentation.part();
}
else if( selection.size() > 1 )
{
if (isMouseOnEditParts(selection))
{
context = SapphireActionSystem.CONTEXT_DIAGRAM_MULTIPLE_PARTS;
}
else
{
this.editor.selectParts(emptySelection);
context = SapphireActionSystem.CONTEXT_DIAGRAM_EDITOR;
}
presentation = this.editor.getDiagramPresentation();
part = this.editor.getPart();
}
else
{
throw new IllegalStateException();
}
final Map<SapphireActionSystemPart,ActionSystemPartBridge> updatedCache = new IdentityHashMap<SapphireActionSystemPart,ActionSystemPartBridge>();
String currentGroupId = null;
for( SapphireAction action : part.getActions( context ).getActions() )
{
if( action.getId().equals( DIAGRAM_NODE_DEFAULT_ACTION ) )
{
continue;
}