Announcement

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

    Notice main window when popup is closed

    Hi.

    I have a main window that is calling a new window (lets call the new window popup).

    In the popup i list some items (buttons). When the user clicks on an item, the popup is closed. The clicked item is stored in an puplic accessible variable.

    Now i need to know in my main window when the popup is closed, to determine what the user has clicked.

    Is this possible somehow? Or could it be solved otherwise?
    I hope you understand my problem.

    Greet Major

    #2
    Make your own interface called CloseHandler or what ever you want. And in the window add a method called addCloseHandler and call that CloseHandler when you close it.

    Comment


      #3
      i am a little bit confused. Can you give me a small example (with Classes called MainWindow and Popup if possible).

      Thx Major

      Comment


        #4
        Example

        Originally posted by GFEMajor
        Can you give me a small example
        ENTRY POINT:
        Code:
        package samples.client;
        
        import samples.client.windows.popup.MainWindow;
        
        import com.google.gwt.core.client.EntryPoint;
        
        public class Main implements EntryPoint {
        
        	@Override
        	public void onModuleLoad() {
        		MainWindow wndMain=new MainWindow();
        		wndMain.setSize("100%", "100%");
        		wndMain.setTitle("Main Window");
        		
        		wndMain.draw();
        	}
        
        }
        MAIN WINDOW:
        Code:
        package samples.client.windows.popup;
        
        import samples.client.windows.popup.PopupWindow.CloseHandler;
        
        import com.smartgwt.client.widgets.IButton;
        import com.smartgwt.client.widgets.Label;
        import com.smartgwt.client.widgets.Window;
        import com.smartgwt.client.widgets.events.ClickEvent;
        import com.smartgwt.client.widgets.events.ClickHandler;
        
        public class MainWindow extends Window {
        
        	public MainWindow(){
        		IButton btnShowPopup=new IButton("Show popup");
        		btnShowPopup.addClickHandler(new ClickHandler() {
        			@Override
        			public void onClick(ClickEvent event) {
        				showPopupWindow();
        			}
        
        			private void showPopupWindow() {
        				PopupWindow wndPopup=new PopupWindow();
        				wndPopup.addCloseHandler(new CloseHandler() {
        					@Override
        					public void onClosed(String message) {
        						Label lblPopupWindowMessage=new Label(message);
        						MainWindow.this.addItem(lblPopupWindowMessage);
        					}
        				});
        				wndPopup.setTitle("Popup Window");
        				wndPopup.setSize("50%", "50%");
        				wndPopup.centerInPage();
        				wndPopup.show();
        			}
        		});
        		
        		addItem(btnShowPopup);
        	}
        }
        POPUP WINDOW:
        Code:
        package samples.client.windows.popup;
        
        import java.util.ArrayList;
        import java.util.List;
        
        import com.smartgwt.client.widgets.IButton;
        import com.smartgwt.client.widgets.Window;
        import com.smartgwt.client.widgets.events.ClickEvent;
        import com.smartgwt.client.widgets.events.ClickHandler;
        
        public class PopupWindow extends Window {
        	
        	public static interface CloseHandler{
        		void onClosed(String message);
        	}
        	private List<CloseHandler> closeHandlers=new ArrayList<CloseHandler>();
        	public void addCloseHandler(CloseHandler handler){
        		closeHandlers.add(handler);
        	}
        	public void removeHandler(CloseHandler handler){
        		closeHandlers.remove(handler);
        	}
        	protected void fireCloseEvent(String message){
        		for(CloseHandler handler:closeHandlers)
        			handler.onClosed(message);
        	}
        
        	public PopupWindow() {
        		IButton btnClosePopupWindow=new IButton("Close");
        		btnClosePopupWindow.setTooltip("Close popup window");
        		btnClosePopupWindow.addClickHandler(new ClickHandler() {
        			@Override
        			public void onClick(ClickEvent event) {
        				PopupWindow.this.destroy();
        				fireCloseEvent("Popup window has been destroyed");
        			}
        		});
        		
        		addItem(btnClosePopupWindow);
        	}
        }

        Comment

        Working...
        X