<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def on_lock(self, widget, data=None):
 """Locks respective selected core element"""

        path_list = None
        if self.view is not None:
            model, path_list = self.tree_view.get_selection().get_selected_rows()
        models = [self.list_store[path][self.MODEL_STORAGE_ID] for path in path_list] if path_list else []
        if models:
            if len(models) > 1:
                self._logger.warning("Please select only one element to be locked.")
            try:
                self.model.global_variable_manager.lock_variable(models[0])
            except AttributeError as e:
                self._logger.warning("The respective core element of {1}.list_store couldn't be locked. -> {0}"
                                  "".format(e, self.__class__.__name__))
            return True
        else:
            self._logger.warning("Please select an element to be locked.")