This multiline if/else makes my head hurt, but getting rid of the default widget type should make it unnecessary.