1   /*
2    * Created on Aug 19, 2007
3    * 
4    * Copyright 2005 CafeSip.org 
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License"); 
7    * you may not use this file except in compliance with the License. 
8    * You may obtain a copy of the License at 
9    *
10   *	http://www.apache.org/licenses/LICENSE-2.0 
11   *
12   * Unless required by applicable law or agreed to in writing, software 
13   * distributed under the License is distributed on an "AS IS" BASIS, 
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
15   * See the License for the specific language governing permissions and 
16   * limitations under the License.
17   *
18   */
19  package org.cafesip.gwtcomp.examples.client;
20  
21  import org.cafesip.gwtcomp.client.ui.ServerFileBrowser;
22  import org.cafesip.gwtcomp.client.ui.ServerFileBrowserListener;
23  import org.cafesip.gwtcomp.client.ui.TitleBar;
24  
25  import com.google.gwt.event.dom.client.ClickEvent;
26  import com.google.gwt.event.dom.client.ClickHandler;
27  import com.google.gwt.user.client.Window;
28  import com.google.gwt.user.client.ui.Button;
29  import com.google.gwt.user.client.ui.FlowPanel;
30  import com.google.gwt.user.client.ui.Widget;
31  
32  /**
33   * @author Amit Chatterjee
34   * 
35   */
36  public class ServerFileBrowserSample extends FlowPanel
37  {
38      private Button serverFileBrowserButton;
39      private ServerFileBrowser browser;
40  
41  
42      /**
43       * A constructor for this class.
44       * 
45       * @param grid
46       */
47      public ServerFileBrowserSample()
48      {
49          super();
50          setWidth("100%");
51          
52          init();
53      }
54  
55      protected void init()
56      {
57          TitleBar titleBar = new TitleBar("Server File Selector", null, 1);
58          add(titleBar);
59          titleBar.setWidth("100%");
60  
61          serverFileBrowserButton = new Button();
62          add(serverFileBrowserButton);
63          
64          serverFileBrowserButton.addClickHandler(new ClickHandler() {
65  
66              public void onClick(ClickEvent event)
67              {
68                  popupServerFileBrowser();                
69              }});
70          
71          serverFileBrowserButton.setText("Show me!");
72      }
73  
74      private void popupServerFileBrowser()
75      {
76          if (browser == null)
77          {
78              browser = new ServerFileBrowser();
79              browser.addServerFileListener(new ServerFileBrowserListener()
80              {
81  
82                  public void onCancel(Widget sender)
83                  {
84                      onFileCancel();
85                  }
86  
87                  public void onOk(Widget sender, String path)
88                  {
89                      onFileSelect(path);
90  
91                  }
92              });
93          }
94  
95          browser.setPopupPosition(
96                  serverFileBrowserButton.getAbsoluteLeft() + 25,
97                  serverFileBrowserButton.getAbsoluteTop() + 25);
98          browser.show();
99      }
100 
101     private void onFileSelect(String path)
102     {
103         browser.hide();
104         Window.alert(path + " selected");
105     }
106 
107     protected void onFileCancel()
108     {
109         browser.hide();
110     }
111 
112 }