<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def contextMenuEvent(self, event):
 """ Creates and executes the context menu for the tree view """

        menu = QtWidgets.QMenu(self)

        for action in self.actions():
            menu.addAction(action)

        openAsMenu = self.createOpenAsMenu(parent=menu)
        menu.insertMenu(self.closeItemAction, openAsMenu)

        menu.exec_(event.globalPos())