2012-06-06 4 views
0

GWT 탭 패널이 있으며 특정 이벤트 (예 : 버튼 클릭)가 다른 탭에서 발생하면 하나의 탭을 다시로드하려고합니다. 그렇게 할 수있는 방법이 있습니까? 탭을 선택하면 일부 코드 (예 : 탭에 새 요소 추가)가 실행될 수도 있습니다. 도움이 될 것입니다. 이미 잠시 붙어 있습니다.GWT : 탭 패널에 단일 탭 다시로드

더 구체적인 질문을하기 위해 아래에 몇 가지 코드를 제공합니다.

화면에 정리 된 코드가 있습니다. 탭 패널을 시작하는 홈 스크린이 있습니다. 그리고 각 탭의 시작을위한 별도의 화면이 있습니다.

홈 화면에 대한 간단한 코드 : 탭 화면

public class HomeScreen extends Composite{ 

    public HomeScreen() { 

    TabPanel tabPanel = new TabPanel(); 
    FlowPanel flowpanel; 

    flowpanel = new FlowPanel(); 
    ProfileTabScreen profileTabScreen = new ProfileTabScreen(); 
    flowpanel.add(profileTabScreen); 
    tabPanel.add(flowpanel, "Profile"); 

    flowpanel = new FlowPanel(); 
    GroupsTabScreen groupsTabScreen = new GroupsTabScreen(); 
    flowpanel.add(groupsTabScreen); 
    tabPanel.add(flowpanel, "Groups"); 

    initWidget(tabPanel); 
    } 
    } 

코드 내가 다시로드 시작하려는 : 다시로드 할 수있는 탭 화면

private VerticalPanel groupPanel = new VerticalPanel(); 
private Button newGroupButton = new Button("New group"); 

    public GroupsTabScreen() {  

    newGroupButton.addClickHandler(new ClickHandler(){ 
     public void onClick(ClickEvent event) { 
      createNewGroup(); 
     } 
    }); 

      groupPanel.add(newGroupButton); 

    initWidget(groupPanel); 
} 

코드 :

private VerticalPanel profilePanel = new VerticalPanel(); 
private Label label = new Label("No groups yet."); 

    public ProfileTabScreen() {  

      profilePanel.add(label); 
    initWidget(profilePanel); 
} 

은 그래서 난 그냥 WHI profileTab에서 라벨의 텍스트를 (변경하려는 가정 해 봅시다 실제로 ListBox 및 기타 요소), newGroupButton을 groupTab에서 클릭하면됩니다.

내가 말했듯이, 매번 프로필 탭을 다시로드하는 것이 허용 될 수도 있습니다.

답변

0

버튼의 경우 마우스 또는 키 수신기를 사용할 수 있습니다. 그러한 청취자를 탭 패널에 추가하고 함수를 호출하게하십시오. "rebuild"라고 부르 자.

재구성 기능은 업데이트하고 값을 다시 계산할 탭의 요소에 액세스 할 수 있어야합니다.

코드 예제를 보내 주셔서 감사합니다. 홈 스크린에 자신의 클래스가있는 경우 초기화하기 전에 이미 사용중인 요소를 정의해야합니다. 그냥 빨리 예 :

public class HomeScreen extends Composite{ 

    private TabPanel tabPanel; 
    private FlowPanel profileTabScreenPanel; 
    private FlowPanel groupsTabScreenPanel; 

    public HomeScreen() {   

     tabPanel = new TabPanel(); 

     profileTabScreenPanel = new FlowPanel(); 
     ProfileTabScreen profileTabScreen = new ProfileTabScreen(); 
     profileTabScreenPanel.add(profileTabScreen); 
     tabPanel.add(flowpanel, "Profile"); 

     groupsTabScreenPanel = new FlowPanel(); 
     GroupsTabScreen groupsTabScreen = new GroupsTabScreen(); 
     groupsTabScreenPanel.add(groupsTabScreen); 
     tabPanel.add(flowpanel, "Groups"); 

     initWidget(tabPanel); 
    } 
} 

장점은 당신이 구현하는 모든 처리기가 직접 당신이 eleements에 액세스하거나 재설정 할 수 있습니다 즉, 특정 요소에 액세스 할 수 있다는 것이다.

또한 getters 및 setters를 TabsScreen-Elements로 광고하여 레이블에 액세스 할 수 없도록해야합니다.

예를 들어, 당신은 당신의 createNewGroup()에서이 작업을 수행 할 수 있습니다 - 기능을 다음 :

profileTabScreenPanel.getLabel().setText("New Text"); 
+0

탭 패널에 클릭 리스너를 추가하는 방법과 탭 패널에서 탭의 요소에 액세스하는 방법을 잘 모르겠습니다. 좀 더 구체적인 질문을하기 위해 프로그램의 간단한 코드를 추가했습니다. – april

+0

나는 내 편집도 :-) – Corsair

+0

답장을 보내 주셔서 감사합니다. getters와 setter를 사용하기 전에 요소를 정의하는 아이디어는 매우 유용했습니다. 그러나 나는 당신이 제안한 예제로 작동하도록 할 수 없었다 : profileTabScreenPanel.getLabel(). setText ("New Text"); 다른 한편으로는 다음과 같이 작업했습니다 : HomeScreen.getProfileTabScreen(). getLabel(). setText ("some text"); HomeScreen 클래스에 하나와 ProfileTabScreen 클래스에 하나씩 두 개의 getter 메서드를 추가했습니다. – april

0

더러운 대답은 홈 화면에 업데이트하고 탭의 양쪽에 전달하고자하는 라벨을 구축하는 것입니다 예 :

public class HomeScreen extends Composite { 
    public HomeScreen() { 
     TabPanel tabPanel = new TabPanel(); 
     FlowPanel flowpanel; 
     Label labelToUpdate = new Label("No Groups yet"); 

     flowpanel = new FlowPanel(); 
     ProfileTabScreen profileTabScreen = new ProfileTabScreen(labelToUpdate); 
     flowpanel.add(profileTabScreen); 
     tabPanel.add(flowpanel, "Profile"); 

     flowpanel = new FlowPanel(); 
     GroupsTabScreen groupsTabScreen = new GroupsTabScreen(labelToUpdate); 
     flowpanel.add(groupsTabScreen); 
     tabPanel.add(flowpanel, "Groups"); 

     initWidget(tabPanel); 
    } 
} 

public class GroupsTabScreen { 
    private VerticalPanel groupPanel = new VerticalPanel(); 
    private Button newGroupButton = new Button("New group"); 
    private final Label labelToUpdate; 

    public GroupsTabScreen(Label label) { 
     this.labelToUpdate = label;  

     newGroupButton.addClickHandler(new ClickHandler(){ 
       public void onClick(ClickEvent event) { 
        createNewGroup(); 
        labelToUpdate.setText("A group has been created"); 
       } 
     }); 

     groupPanel.add(newGroupButton); 

     initWidget(groupPanel); 
    } 
} 

public class ProfileTabScreen { 
    private VerticalPanel profilePanel = new VerticalPanel(); 
    private final Label labelToUpdate; 

    public ProfileTabScreen(Label label) {  
     this.labelToUpdate = label; 
     profilePanel.add(labelToUpdate); 
     initWidget(profilePanel); 
    } 
} 

이벤트 변경을 실행하고 감지하기 위해 클래스 사이에 이벤트 버스를 사용하는 것이 더 예민한 솔루션입니다. How to use the GWT EventBus

+0

감사합니다 jonas, 나는 이벤트 버스가이 문제에 대한 해결책이 될 수 있다고 생각합니다! – april

관련 문제