I've been using SmartGWT for 1-2 months now and have most of an app developed. The majority of the app uses all SmartGWT items and panels, but the very first couple classes that get called use vanilla GWT. I need to find a way around this, because it seems that when I use SimplePanel (vanilla) some performance issues arise (CPU usage continually rises even without doing any actions).
I managed to change this code over to using SmartGWT, but when it was compiled as Javascript, the buttons were killed and events never worked. This is my issue.
Can someone help me change the following sample code from using GWT SimplePanel to using SmartGWT techniques? The main purpose is to add some wrapper object (whether it be a panel, a layout, etc - this will be the "main viewable screen of the app") to RootPanel in the div region "wrapper" (wrapper is used to center the whole app in the middle of browser using CSS, rather than positioning at 0,0 of browser like default draw() method seems to do) . When the user clicks login, the main wrapper object (login panel) should be replaced with another panel (main_panel - the main section of application). From there, everything is SmartGWT code and should work.
The bolded regions are the main issues I believe. Using Composite and SimplePanel. The code works below in both Hosted and Web mode - however, CPU usage gradually rises until it hardly runs anymore, even if you don't touch anything. I managed to avoid this issue by changing the SimplePanel to a VLayout. However, the login button / events would not function in Web mode anymore - just hosted.
I managed to change this code over to using SmartGWT, but when it was compiled as Javascript, the buttons were killed and events never worked. This is my issue.
Can someone help me change the following sample code from using GWT SimplePanel to using SmartGWT techniques? The main purpose is to add some wrapper object (whether it be a panel, a layout, etc - this will be the "main viewable screen of the app") to RootPanel in the div region "wrapper" (wrapper is used to center the whole app in the middle of browser using CSS, rather than positioning at 0,0 of browser like default draw() method seems to do) . When the user clicks login, the main wrapper object (login panel) should be replaced with another panel (main_panel - the main section of application). From there, everything is SmartGWT code and should work.
The bolded regions are the main issues I believe. Using Composite and SimplePanel. The code works below in both Hosted and Web mode - however, CPU usage gradually rises until it hardly runs anymore, even if you don't touch anything. I managed to avoid this issue by changing the SimplePanel to a VLayout. However, the login button / events would not function in Web mode anymore - just hosted.
Code:
public class GnetsProject implements EntryPoint { [b]private static SimplePanel panel;[/b] /** * <code>onModuleLoad</code> is automatically called when this class is instantiated - in this case, * when the application is started for the first time. * */ public void onModuleLoad() { // initialize data InitializationController.getInstance().initializeDataSource(new AsyncCallback() { public void onFailure(Throwable caught) { SC.say("The application failed to load properly."); } public void onSuccess(Object result) { //Load Faculty Records FacultyRecords.getInstance(); // Load StudentRecords StudentRecords.getInstance(); } }); [b]panel.setWidget(new LoginPanel());[/b] // add to the wrapper div region in HTML document [b]RootPanel.get("wrapper").add(panel);[/b] // remove the loading message Element loading = DOM.getElementById("loading"); DOM.removeChild(RootPanel.getBodyElement(), loading); if (!GWT.isScript()) { KeyIdentifier debugKey = new KeyIdentifier(); debugKey.setCtrlKey(true); debugKey.setKeyName("D"); Page.registerKey(debugKey, new KeyCallback() { public void execute(String keyName) { SC.showConsole(); } }); } } /** * Sets the widget of the <code>SimplePanel</code>. This new widget will be the only thing visible in the * application. * * @param new_widget the widget to be used for the application */ public static void setPanel(Widget new_widget) { [b]panel.setWidget(new_widget);[/b] } }
Code:
public class LoginPanel extends [b]Composite[/b] { VLayout layout = new VLayout(); DynamicForm login_form; TextItem username; PasswordItem password; ButtonItem login_button; /** * Initializes the login form and displays it to the user */ public LoginPanel() { // configure form (omitted) // configure fields (omitted) login_button = new ButtonItem("Login"); login_button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { // switch to main panel String user = (String) username.getValue(); String plaintext = (String) password.getValue(); String result = FacultyRecords.getInstance().verifyLogin(user, plaintext); if (!result.equals("Success")) { SC.say(result); } else { String[] full_name = user.split(","); String first_name = full_name[1].trim(); String last_name = full_name[0].trim(); Faculty user_logged_in = FacultyRecords.getInstance().getFacultyWithName(first_name, last_name); // change screen to main panel [b]GnetsProject.setPanel(new MainPanel(user_logged_in));[/b] } } }); // add fields to form login_form.setFields(username, password, login_button); // add form to panel [b]initWidget(layout);[/b] [b]layout.draw();[/b] } }
Code:
public class MainPanel extends [b]Composite[/b] implements HistoryListener { VLayout main_layout = new VLayout(); HLayout center_layout = new HLayout(); Img header; NavigationWidget navigation; HLayout content_wrapper; ContentWidget home_widget; // ... ContentWidget weekly_widget; ContentWidget monthly_widget; ContentWidget student_widget; static Faculty user_logged_in; /** * Initializes the application with a banner, navigation, content region, and footer. Also registers * this class as a <code>HistoryListener</code> in order to make use of the browser control buttons. * @param user_logged_in user who has passed verification in <code>LoginPanel</code> */ public MainPanel(Faculty f) { /* * Set Faculty member */ user_logged_in = f; /* * Add header image to the layout (some omitted) */ main_layout.addMember(header); main_layout.setID("main_layout"); // Center layout holds navigation and content region center_layout.setID("center_layout"); center_layout.setStyleName("center_layout"); /* * Add navigation to the layout */ navigation = new NavigationWidget(user_logged_in); navigation.setID("navigation"); navigation.setStyleName("navigation"); center_layout.addMember(navigation); /* * Add Content region (some omitted) */ // Add widgets to the content region content_wrapper.addMember(HomeWidget.getInstance()); // Add content region to center layout center_layout.addMember(content_wrapper); // Add center layout to main layout main_layout.addMember(center_layout); /* * Add footer (some omitted) */ // Add footer to main layout main_layout.addMember(footer); /* * Add this class as a HistoryListener so it gets notified everytime * history changes */ History.addHistoryListener(this); [b]initWidget(main_layout);[/b] // draw main_layout [b]main_layout.draw();[/b] }
Comment