6 tablespoons butter, plus more for greasing dish
1 large onion, thinly sliced
Kosher salt and freshly ground black pepper
4 cups 1/2-inch bread cubes (crusts removed)
8 ounces cremini mushrooms, sliced
8 large eggs
1 1/4 cups half-and-half
1 teaspoon Dijon mustard
4 ounces ham, diced
1 1/2 cups shredded Gruyere, Emmental or Jarlsberg (about 4 ounces)
2 small plum tomatoes, sliced very thinly
2 tablespoons grated Parmesan
2 tablespoons chopped parsley, for garnish
Preheat the oven to 350 degrees F. Butter a 9-by-13-inch casserole dish.
Heat 2 tablespoons of the butter in a large skillet over medium-high heat. Add the onions and cook, stirring occasionally, until lightly browned, about 5 minutes. Lower the heat to medium and continue cooking and stirring until the onions are soft and caramelized, 20 minutes more. If they start to burn, lower the heat further. Season with salt and black pepper.
Meanwhile, heat another large skillet over medium heat. Add 2 tablespoons of the butter and the bread and cook, stirring occasionally, until light golden brown all over, about 8 minutes. Season with salt and black pepper. Transfer the bread to a large bowl. Increase the heat to medium-high, add the remaining 2 tablespoons butter and the mushrooms and cook undisturbed to brown for 1 minute. Continue cooking, stirring occasionally, until soft, about 2 minutes more. Season with salt and black pepper.
Whisk together the eggs, half-and-half, mustard, cayenne, 1/2 teaspoon salt and a few grinds of black pepper in a large bowl. Stir in the onions, bread, mushrooms, ham and 1 cup of the Gruyere. Transfer the mixture to the buttered baking dish. Top with a single layer of tomatoes and sprinkle with the remaining 1/2 cup Gruyere and the Parmesan. (The casserole can be refrigerated overnight and baked the next day.)
Bake until the top is golden brown and the casserole is set (doesn't jiggle when shaken), about 40 minutes. Top with the parsley.