ServerFileBrowserSample.java
001 /*
002  * Created on Aug 19, 2007
003  
004  * Copyright 2005 CafeSip.org 
005  *
006  * Licensed under the Apache License, Version 2.0 (the "License"); 
007  * you may not use this file except in compliance with the License. 
008  * You may obtain a copy of the License at 
009  *
010  *  http://www.apache.org/licenses/LICENSE-2.0 
011  *
012  * Unless required by applicable law or agreed to in writing, software 
013  * distributed under the License is distributed on an "AS IS" BASIS, 
014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
015  * See the License for the specific language governing permissions and 
016  * limitations under the License.
017  *
018  */
019 package org.cafesip.gwtcomp.examples.client;
020 
021 import org.cafesip.gwtcomp.client.ui.ServerFileBrowser;
022 import org.cafesip.gwtcomp.client.ui.ServerFileBrowserListener;
023 import org.cafesip.gwtcomp.client.ui.TitleBar;
024 
025 import com.google.gwt.user.client.Window;
026 import com.google.gwt.user.client.ui.Button;
027 import com.google.gwt.user.client.ui.ClickListener;
028 import com.google.gwt.user.client.ui.FlowPanel;
029 import com.google.gwt.user.client.ui.Widget;
030 
031 /**
032  @author Amit Chatterjee
033  
034  */
035 public class ServerFileBrowserSample extends FlowPanel
036 {
037     private Button serverFileBrowserButton;
038     private ServerFileBrowser browser;
039 
040 
041     /**
042      * A constructor for this class.
043      
044      @param grid
045      */
046     public ServerFileBrowserSample()
047     {
048         super();
049         setWidth("100%");
050         
051         init();
052     }
053 
054     protected void init()
055     {
056         TitleBar titleBar = new TitleBar("Server File Selector", null, 1);
057         add(titleBar);
058         titleBar.setWidth("100%");
059 
060         serverFileBrowserButton = new Button();
061         add(serverFileBrowserButton);
062         serverFileBrowserButton.addClickListener(new ClickListener()
063         {
064             public void onClick(Widget sender)
065             {
066                 popupServerFileBrowser();
067             }
068         });
069         serverFileBrowserButton.setText("Show me!");
070     }
071 
072     private void popupServerFileBrowser()
073     {
074         if (browser == null)
075         {
076             browser = new ServerFileBrowser();
077             browser.addServerFileListener(new ServerFileBrowserListener()
078             {
079 
080                 public void onCancel(Widget sender)
081                 {
082                     onFileCancel();
083                 }
084 
085                 public void onOk(Widget sender, String path)
086                 {
087                     onFileSelect(path);
088 
089                 }
090             });
091         }
092 
093         browser.setPopupPosition(
094                 serverFileBrowserButton.getAbsoluteLeft() 200,
095                 serverFileBrowserButton.getAbsoluteTop() 450);
096         browser.show();
097     }
098 
099     private void onFileSelect(String path)
100     {
101         browser.hide();
102         Window.alert(path + " selected");
103     }
104 
105     protected void onFileCancel()
106     {
107         browser.hide();
108     }
109 
110 }