Great deal for both sides IMO.
Matthews is here for another 5 seasons, so that gives the Leafs a window to hopefully make some noise in the Playoffs. You'll still have Matthew in his prime years so no worries about his age or any regression. Also, gives Brad Treliving enough of a window to build this team into a Stanley Cup contender via free agents, trades and draft picks.
Matthews only signs a 4 year-extension so nothing crazy long term like 8-10 years. He'll become a FA by the age of 30, so he'll still have an opportunity to earn big money and a contract if he keeps up his high level of play and especially if the NHL raises the salary cap which by then will definitely be more. As well, gives Matthews one last chance to try to lead the Leafs to the Promise Land. If he fails, he can leave and sign somewhere else. If he wins here in Toronto, he'll likely earn a huge payday after from the Leafs or another team once he becomes a FA.