PDA

View Full Version : [SOLVED] Help with View and Widget Control



javacrazed
27 Jul 2010, 9:01 PM
I've read the post and none so far have answered my question.

I am trying to clear a ControlPanel of its content when i switch from views. Current the center ControlPanel is set to a url. I am trying to clear it and then add text. Here is an example of my code.

<code>
public class GXTProject implements EntryPoint {
[This post has been solved]
private Dispatcher dispatch;

@Override
public void onModuleLoad() {

dispatch = Dispatcher.get();
dispatch.addController(new WelcomeController());
dispatch.addController(new NewPageController());
dispatch.dispatch(AppEvents.Init);

}

}


WELCOMEVIEW


public class WelcomeView extends View{
public static final String VIEWPORT = "viewport";
public static final String NORTH_PANEL = "northPanel";
public static final String WEST_PANEL = "westPanel";
public static final String CENTER_PANEL = "centerPanel";


private ContentPanel centerPanel;
private HtmlContainer northPanel;
private ContentPanel westPanel;
private Viewport viewport ;

public WelcomeView(Controller controller) {
super(controller);
// TODO Auto-generated constructor stub
}

@Override
protected void handleEvent(AppEvent event) {
// TODO Auto-generated method stub

}
protected void initialize(){
viewport = new Viewport();
viewport.setLayout(new BorderLayout());

Registry.register(VIEWPORT, viewport);

createCenter();
createNorth();
createWest();

RootPanel.get().add(viewport);
}

private void createCenter(){
centerPanel = new ContentPanel();
centerPanel.setStateful(true);
centerPanel.setUrl("http://www.videmantay.net");
centerPanel.setBounds(100, 50, 150, 300);

BorderLayoutData cData = new BorderLayoutData(LayoutRegion.CENTER);
cData.setMargins(new Margins(5,5,5,5));

Registry.register(CENTER_PANEL, centerPanel);
viewport.add(centerPanel, cData);
}
private void createNorth(){

String html = "<img src=\"images/logo.png\" /> <h1> Welcome Page</h1> ";

northPanel = new HtmlContainer(html);
BorderLayoutData nData = new BorderLayoutData(LayoutRegion.NORTH);
nData.setMargins(new Margins(5,5,5,5));
float size = 0.1f;
nData.setSize(size);

Registry.register(NORTH_PANEL, northPanel);
viewport.add(northPanel, nData);
}
private void createWest(){
westPanel = new ContentPanel();
westPanel.setBounds(0, 150, 50, 500);

Button page2Button = new Button("Goto Pg2");
page2Button.addSelectionListener(new SelectionListener<ButtonEvent>(){

@Override
public void componentSelected(ButtonEvent ce) {
try{

MessageBox.alert("Didn't Work", "The call made it", null);
Dispatcher.forwardEvent(AppEvents.ShowPage);
}catch(Exception e){
centerPanel.clearState();
centerPanel.addText("an Exception occurred");
centerPanel.setVisible(false);
MessageBox.WARNING = "An exception occured";
}

}

});

westPanel.addText("this is the West Panel click button to go to page 2...");
westPanel.add(page2Button);
Registry.register( WEST_PANEL, westPanel);

viewport.add(westPanel);



}

}

public class NewPageView extends View{

Viewport viewport;
ContentPanel content;

public NewPageView(Controller controller) {
super(controller);
// TODO Auto-generated constructor stub
}

@Override
protected void handleEvent(AppEvent event) {
if(event.getType()== AppEvents.ShowPage){
content.setUrl(null);
content.addText("new Page");
}

}
protected void initialize(){
viewport = (Viewport)Registry.get(WelcomeView.VIEWPORT);
content = (ContentPanel)Registry.get(WelcomeView.CENTER_PANEL);

}



}

The controller for NewPageView


public class NewPageController extends Controller{
NewPageView view;


protected void initialize(){
super.initialize();
view= new NewPageView(this);
registerEventTypes(AppEvents.ShowPage);
}
@Override
public void handleEvent(AppEvent event) {
if(event.getType() == AppEvents.ShowPage){
forwardToView(view, event);
}

}
}


Welcome view work fine event my little MessageBox alert test is fine and there are no stack trace errors but the content panel from is not changing what so ever. So either the problem is with the Registry or the Dispatcher is not doing anything with the Event from Dispatcher.fo


</code>

sven
27 Jul 2010, 11:31 PM
You need to call layout after changing components inside a container

javacrazed
28 Jul 2010, 10:11 AM
Wow, SVEN, I am honored and humbled that you took the time to answer such a newbie question, i think you and daryll rock and that GXT is great. Keep on rock'n.