3333class SplitLayoutDemo extends Composite <SplitLayout > {
3434
3535 private MultiSourceCodeViewer code ;
36+ private Component demo ;
3637 private SourcePosition sourcePosition ;
3738
3839 public SplitLayoutDemo (Component demo , String sourceUrl , SourcePosition sourcePosition ) {
@@ -47,35 +48,31 @@ public SplitLayoutDemo(Component demo, List<SourceCodeTab> tabs) {
4748 properties .put ("flow" , Version .getFullVersion ());
4849
4950 code = new MultiSourceCodeViewer (tabs , properties );
50-
51- sourcePosition = code .getSourcePosition ();
52- switch (sourcePosition ) {
53- case PRIMARY :
54- getContent ().addToPrimary (code );
55- getContent ().addToSecondary (demo );
56- break ;
57- case SECONDARY :
58- default :
59- getContent ().addToPrimary (demo );
60- getContent ().addToSecondary (code );
61- }
51+ this .demo = demo ;
52+ setSourcePosition (code .getSourcePosition ());
6253
6354 getContent ().setSizeFull ();
6455 }
6556
6657 private void setSourcePosition (SourcePosition position ) {
67- if (!sourcePosition .equals (position )) {
68- toggleSourcePosition ();
58+ if (!position .equals (sourcePosition )) {
59+ getContent ().removeAll ();
60+ switch (position ) {
61+ case PRIMARY :
62+ getContent ().addToPrimary (code );
63+ getContent ().addToSecondary (demo );
64+ break ;
65+ case SECONDARY :
66+ default :
67+ getContent ().addToPrimary (demo );
68+ getContent ().addToSecondary (code );
69+ }
70+ sourcePosition = position ;
6971 }
7072 }
7173
7274 public void toggleSourcePosition () {
73- Component primary = getContent ().getPrimaryComponent ();
74- Component secondary = getContent ().getSecondaryComponent ();
75- getContent ().removeAll ();
76- getContent ().addToPrimary (secondary );
77- getContent ().addToSecondary (primary );
78- sourcePosition = sourcePosition .toggle ();
75+ setSourcePosition (sourcePosition .toggle ());
7976 }
8077
8178 public void setOrientation (Orientation o ) {
0 commit comments