First you removed panel1 from mainDockPanel.
Then you use if(mainDockPanel.getWidgetDirection(panel1).equals(DockPanel.EAST)){
From the API docs
the widget's layout direction, or null if it is not a child of this panel Blockquote
Chances are, you are getting a NPE