Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / PithosDisclosurePanel.java @ ba6ffffb

History | View | Annotate | Download (4.7 kB)

1 39f6d7b0 Christos Stathis
/*
2 39f6d7b0 Christos Stathis
 * Copyright 2012 GRNET S.A. All rights reserved.
3 39f6d7b0 Christos Stathis
 *
4 39f6d7b0 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 39f6d7b0 Christos Stathis
 * without modification, are permitted provided that the following
6 39f6d7b0 Christos Stathis
 * conditions are met:
7 39f6d7b0 Christos Stathis
 *
8 39f6d7b0 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 39f6d7b0 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 39f6d7b0 Christos Stathis
 *      disclaimer.
11 39f6d7b0 Christos Stathis
 *
12 39f6d7b0 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 39f6d7b0 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 39f6d7b0 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 39f6d7b0 Christos Stathis
 *      provided with the distribution.
16 39f6d7b0 Christos Stathis
 *
17 39f6d7b0 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 39f6d7b0 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 39f6d7b0 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 39f6d7b0 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 39f6d7b0 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 39f6d7b0 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 39f6d7b0 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 39f6d7b0 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 39f6d7b0 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 39f6d7b0 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 39f6d7b0 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 39f6d7b0 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 39f6d7b0 Christos Stathis
 *
30 39f6d7b0 Christos Stathis
 * The views and conclusions contained in the software and
31 39f6d7b0 Christos Stathis
 * documentation are those of the authors and should not be
32 39f6d7b0 Christos Stathis
 * interpreted as representing official policies, either expressed
33 39f6d7b0 Christos Stathis
 * or implied, of GRNET S.A.
34 39f6d7b0 Christos Stathis
 */
35 39f6d7b0 Christos Stathis
36 39f6d7b0 Christos Stathis
package gr.grnet.pithos.web.client;
37 39f6d7b0 Christos Stathis
38 39f6d7b0 Christos Stathis
import com.google.gwt.event.logical.shared.CloseEvent;
39 39f6d7b0 Christos Stathis
import com.google.gwt.event.logical.shared.CloseHandler;
40 39f6d7b0 Christos Stathis
import com.google.gwt.event.logical.shared.OpenEvent;
41 39f6d7b0 Christos Stathis
import com.google.gwt.event.logical.shared.OpenHandler;
42 39f6d7b0 Christos Stathis
import com.google.gwt.resources.client.ClientBundle;
43 39f6d7b0 Christos Stathis
import com.google.gwt.resources.client.CssResource;
44 39f6d7b0 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
45 39f6d7b0 Christos Stathis
import com.google.gwt.user.client.ui.Composite;
46 39f6d7b0 Christos Stathis
import com.google.gwt.user.client.ui.DisclosurePanel;
47 39f6d7b0 Christos Stathis
import com.google.gwt.user.client.ui.HTML;
48 08cc5916 Christos Stathis
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
49 08cc5916 Christos Stathis
import com.google.gwt.user.client.ui.HasVerticalAlignment;
50 08cc5916 Christos Stathis
import com.google.gwt.user.client.ui.HorizontalPanel;
51 08cc5916 Christos Stathis
import com.google.gwt.user.client.ui.Image;
52 08cc5916 Christos Stathis
import com.google.gwt.user.client.ui.Widget;
53 39f6d7b0 Christos Stathis
54 39f6d7b0 Christos Stathis
public class PithosDisclosurePanel extends Composite {
55 39f6d7b0 Christos Stathis
56 39f6d7b0 Christos Stathis
        public interface Style extends CssResource {
57 39f6d7b0 Christos Stathis
                String disclosurePanel();
58 7e8e9ff0 Christos Stathis
                
59 e56be452 Christos Stathis
                String header();
60 e56be452 Christos Stathis
                
61 08cc5916 Christos Stathis
                String arrow();
62 08cc5916 Christos Stathis
                
63 7e8e9ff0 Christos Stathis
                String content();
64 39f6d7b0 Christos Stathis
        }
65 39f6d7b0 Christos Stathis
        
66 39f6d7b0 Christos Stathis
        public interface Resources extends ClientBundle {
67 39f6d7b0 Christos Stathis
                @Source("PithosDisclosurePanel.css")
68 39f6d7b0 Christos Stathis
                Style pithosDisclosurePanelCss();
69 39f6d7b0 Christos Stathis
                
70 39f6d7b0 Christos Stathis
                @Source("upArrow.png")
71 39f6d7b0 Christos Stathis
                ImageResource icon();
72 39f6d7b0 Christos Stathis
                
73 39f6d7b0 Christos Stathis
                @Source("upArrow.png")
74 39f6d7b0 Christos Stathis
                ImageResource open();
75 39f6d7b0 Christos Stathis
                
76 39f6d7b0 Christos Stathis
                @Source("downArrow.png")
77 39f6d7b0 Christos Stathis
                ImageResource closed();
78 39f6d7b0 Christos Stathis
        }
79 39f6d7b0 Christos Stathis
        
80 39f6d7b0 Christos Stathis
        DisclosurePanel panel;
81 39f6d7b0 Christos Stathis
        
82 7e8e9ff0 Christos Stathis
        Resources resources;
83 7e8e9ff0 Christos Stathis
        
84 7e8e9ff0 Christos Stathis
        public PithosDisclosurePanel(final Resources _resources, final String title, boolean open) {
85 7e8e9ff0 Christos Stathis
                resources = _resources;
86 39f6d7b0 Christos Stathis
                resources.pithosDisclosurePanelCss().ensureInjected();
87 39f6d7b0 Christos Stathis
                panel = new DisclosurePanel();
88 39f6d7b0 Christos Stathis
                panel.addStyleName(resources.pithosDisclosurePanelCss().disclosurePanel());
89 39f6d7b0 Christos Stathis
                panel.setHeader(createHeader(resources, title, open));
90 39f6d7b0 Christos Stathis
                panel.setOpen(open);
91 39f6d7b0 Christos Stathis
                panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
92 39f6d7b0 Christos Stathis
                        
93 39f6d7b0 Christos Stathis
                        @Override
94 39f6d7b0 Christos Stathis
                        public void onOpen(OpenEvent<DisclosurePanel> event) {
95 39f6d7b0 Christos Stathis
                                panel.setHeader(createHeader(resources, title, true));
96 39f6d7b0 Christos Stathis
                        }
97 39f6d7b0 Christos Stathis
                });
98 39f6d7b0 Christos Stathis
                panel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
99 39f6d7b0 Christos Stathis
                        
100 39f6d7b0 Christos Stathis
                        @Override
101 39f6d7b0 Christos Stathis
                        public void onClose(CloseEvent<DisclosurePanel> event) {
102 39f6d7b0 Christos Stathis
                                panel.setHeader(createHeader(resources, title, false));
103 39f6d7b0 Christos Stathis
                        }
104 39f6d7b0 Christos Stathis
                });
105 7e8e9ff0 Christos Stathis
                
106 39f6d7b0 Christos Stathis
                initWidget(panel);
107 39f6d7b0 Christos Stathis
        }
108 39f6d7b0 Christos Stathis
        
109 08cc5916 Christos Stathis
        Widget createHeader(Resources resources, String title, boolean open) {
110 08cc5916 Christos Stathis
                HorizontalPanel header = new HorizontalPanel();
111 08cc5916 Christos Stathis
        
112 08cc5916 Christos Stathis
                Image img = new Image(resources.icon());
113 08cc5916 Christos Stathis
                header.add(img);
114 08cc5916 Christos Stathis
                header.setCellVerticalAlignment(img, HasVerticalAlignment.ALIGN_MIDDLE);
115 08cc5916 Christos Stathis
                header.setCellWidth(img, "32px");
116 08cc5916 Christos Stathis
                HTML titleHtml = new HTML(title);
117 08cc5916 Christos Stathis
                header.add(titleHtml);
118 08cc5916 Christos Stathis
                header.setCellVerticalAlignment(titleHtml, HasVerticalAlignment.ALIGN_MIDDLE);
119 08cc5916 Christos Stathis
                Image arrow = new Image(open ? resources.open() : resources.closed());
120 08cc5916 Christos Stathis
                arrow.addStyleName(resources.pithosDisclosurePanelCss().arrow());
121 08cc5916 Christos Stathis
                header.add(arrow);
122 08cc5916 Christos Stathis
                header.setCellHorizontalAlignment(arrow, HasHorizontalAlignment.ALIGN_RIGHT);
123 08cc5916 Christos Stathis
                header.setCellVerticalAlignment(arrow, HasVerticalAlignment.ALIGN_MIDDLE);
124 08cc5916 Christos Stathis
                
125 08cc5916 Christos Stathis
                header.addStyleName(resources.pithosDisclosurePanelCss().header());
126 08cc5916 Christos Stathis
                return header;
127 39f6d7b0 Christos Stathis
        }
128 39f6d7b0 Christos Stathis
        
129 db365c2d Christos Stathis
        public void setContent(Widget widget) {
130 db365c2d Christos Stathis
                panel.setContent(widget);
131 7e8e9ff0 Christos Stathis
                panel.getContent().removeStyleName("content");
132 7e8e9ff0 Christos Stathis
                panel.getContent().addStyleName(resources.pithosDisclosurePanelCss().content());
133 39f6d7b0 Christos Stathis
        }
134 39f6d7b0 Christos Stathis
}