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.
Copyright 2013 Television Food Network, G.P. All rights reserved