Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    hideSection showSection insert the section header again

    Hi,

    I don't want sectionHeaders, so I setShowHeader(false).
    I add these sections, and all goes well.

    Now I've got a script which hides some sections and shows some sections, which gives the effect as though the stack is being replaced with new sections.

    But when doing this, the sectionheaders pop-up again. I'm even trying to re-set the setShowHeader(false), but that doens't work anymore.


    Reprocase: press the button a few times to see the unexpected headers come back suddenly.

    Code:
    private class MySec extends SectionStackSection {
    	public MySec(String text) {
    		this.setExpanded(true);
    		this.setCanCollapse(false);
    		this.setResizeable(false);
    		this.setShowHeader(false);
    		Label label = new Label();
    		label.setContents(text);
    		this.setItems(label);
    	}
    }
    
    private VLayout getTest6() {
    	VLayout result = new VLayout();
    
    	final SectionStack stack = new SectionStack();
    	stack.setVisibilityMode(VisibilityMode.MULTIPLE);
    	stack.setAnimateSections(true);
    	stack.setShowResizeBar(true);
    	stack.setWidth(220);
    
    	final MySec section1 = new MySec("A");
    	final MySec section2 = new MySec("B");
    	final MySec section3 = new MySec("C");
    
    	stack.setSections(section1, section2);
    
    	//Click the button to switch sections (actually hide/show and add if needed)
    	final Button b = new Button("2");
    	b.addClickHandler(new ClickHandler() {
    
    		public void onClick(ClickEvent event) {
    
    			SectionStackSection[] existingSections = stack.getSections();
    
    
    			SectionStackSection[] sections;
    			if (b.getTitle().equals("2")) {
    				sections = new SectionStackSection[]{section3};
    				b.setTitle("1");
    			} else {
    				sections = new SectionStackSection[]{section1, section2};
    				b.setTitle("2");
    			}
    
    			boolean [] containsSection = new boolean[sections.length];
    			for (int i=0; i<existingSections.length; i++) {
    				stack.hideSection(i);
    
    				for (int j=0; j<sections.length; j++) {
    					if (sections[j].getID().equals(existingSections[i].getID())) {
    						containsSection[j] = true;
    
    						if (existingSections[i].getAttributeAsBoolean("expanded")) {
    							//Somewhere during hideSection the expandable sections are collapsed
    							// so we need to expand them again ourselves.
    							stack.expandSection(i);
    						}
    						//uuuh, and somewhere during the switch, the header comes up again
    						existingSections[i].setShowHeader(false);
    
    						stack.showSection(i);
    						break;
    					}
    				}
    			}
    
    
    			for (int j=0; j<sections.length; j++) {
    				if (!containsSection[j]) {
    					//uuuh, and somewhere during the switch, the header comes up again
    					sections[j].setShowHeader(false);
    					stack.addSection(sections[j]);
    				}
    			}
    		}
    	});
    
    	result.setMembers(stack, b);
    
    	return result;
    }
    TIA
    IE8 GWT 2.1 dev mode SmartClient Version: SC_SNAPSHOT-2010-10-27/EVAL Deployment

    #2
    The issue is actually being caused by the call to expandSection.
    If you simplify your code to get rid of that the behavior goes away.
    Here's a modified click handler without the call to 'expandSection' - or the calls to 'setShowHeader(false)' - which works for us.

    Code:
    		b.addClickHandler(new com.smartgwt.client.widgets.events.ClickHandler() {
    		
    			public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
    
    				SectionStackSection[] existingSections = stack.getSections();
    
    
    				SectionStackSection[] sections;
    				if (b.getTitle().equals("2")) {
    					sections = new SectionStackSection[]{section3};
    					b.setTitle("1");
    				} else {
    					sections = new SectionStackSection[]{section1, section2};
    					b.setTitle("2");
    				}
    
    				boolean [] containsSection = new boolean[sections.length];
    				for (int i=0; i<existingSections.length; i++) {
    					stack.hideSection(i);
    
    					for (int j=0; j<sections.length; j++) {
    						if (sections[j].getID().equals(existingSections[i].getID())) {
    							containsSection[j] = true;
    							stack.showSection(i);
    							break;
    						}
    					}
    				}
    
    
    				for (int j=0; j<sections.length; j++) {
    					if (!containsSection[j]) {
    						stack.addSection(sections[j]);
    					}
    				}
    			}
    		});
    We're fixing the issue with 'expandSection()' - obviously it shouldn't force the header to show - but it also shouldn't be necessary for your use case.
    If this is not the case, please feel free to post example code demonstrating why this call is necessary and we can look at that as well.

    Comment


      #3
      Ah, you're right. When I first started with this, I added this as comment at the expandSection line:
      //Somewhere during hideSection the expandable sections are collapsed
      //so we need to expand them again ourselves.

      I noticed that when I setExpanded(true) in the constructor and added them to the stack, they were expanded (OK).
      But doing a hide and show on theses sections, made the sections collapsed again, so I manually did an expandSection.
      I didn't realize what was causing this behavior, till now:
      Now I think that's probably because I put the stack visibility mode on MUTEX. In the example below I put the mode on MULTIPLE, which is more correct since all sections should be shown at once.

      Comment

      Working...
      X