Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (5.2 kB)

1 39f6d7b0 Christos Stathis
/*
2 e6e9f6e6 Christos KK Loverdos
 * Copyright 2012-2013 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 67d30f02 Christos KK Loverdos
import com.google.gwt.user.client.ui.*;
46 39f6d7b0 Christos Stathis
47 39f6d7b0 Christos Stathis
public class PithosDisclosurePanel extends Composite {
48 39f6d7b0 Christos Stathis
49 39f6d7b0 Christos Stathis
        public interface Style extends CssResource {
50 39f6d7b0 Christos Stathis
                String disclosurePanel();
51 7e8e9ff0 Christos Stathis
                
52 e56be452 Christos Stathis
                String header();
53 e56be452 Christos Stathis
                
54 08cc5916 Christos Stathis
                String arrow();
55 08cc5916 Christos Stathis
                
56 7e8e9ff0 Christos Stathis
                String content();
57 39f6d7b0 Christos Stathis
        }
58 39f6d7b0 Christos Stathis
        
59 39f6d7b0 Christos Stathis
        public interface Resources extends ClientBundle {
60 39f6d7b0 Christos Stathis
                @Source("PithosDisclosurePanel.css")
61 39f6d7b0 Christos Stathis
                Style pithosDisclosurePanelCss();
62 39f6d7b0 Christos Stathis
                
63 39f6d7b0 Christos Stathis
                @Source("upArrow.png")
64 39f6d7b0 Christos Stathis
                ImageResource icon();
65 39f6d7b0 Christos Stathis
                
66 39f6d7b0 Christos Stathis
                @Source("upArrow.png")
67 39f6d7b0 Christos Stathis
                ImageResource open();
68 39f6d7b0 Christos Stathis
                
69 39f6d7b0 Christos Stathis
                @Source("downArrow.png")
70 39f6d7b0 Christos Stathis
                ImageResource closed();
71 d4ace10a Christos KK Loverdos
72 d4ace10a Christos KK Loverdos
        @Source("gr/grnet/pithos/resources/ajax-loader.gif")
73 d4ace10a Christos KK Loverdos
        ImageResource ajaxLoader();
74 39f6d7b0 Christos Stathis
        }
75 39f6d7b0 Christos Stathis
        
76 67d30f02 Christos KK Loverdos
        private final DisclosurePanel panel;
77 67d30f02 Christos KK Loverdos
    private final Resources resources;
78 67d30f02 Christos KK Loverdos
    private final String title;
79 d4ace10a Christos KK Loverdos
80 d4ace10a Christos KK Loverdos
    public PithosDisclosurePanel(final Resources _resources, final String title, boolean open) {
81 67d30f02 Christos KK Loverdos
        this(_resources, title, false, open);
82 d4ace10a Christos KK Loverdos
    }
83 d4ace10a Christos KK Loverdos
84 67d30f02 Christos KK Loverdos
        public PithosDisclosurePanel(final Resources _resources, final String title, boolean ajaxLoader, boolean open) {
85 67d30f02 Christos KK Loverdos
        this.title = title;
86 d4ace10a Christos KK Loverdos
87 67d30f02 Christos KK Loverdos
                this.resources = _resources;
88 39f6d7b0 Christos Stathis
                resources.pithosDisclosurePanelCss().ensureInjected();
89 67d30f02 Christos KK Loverdos
                this.panel = new DisclosurePanel();
90 39f6d7b0 Christos Stathis
                panel.addStyleName(resources.pithosDisclosurePanelCss().disclosurePanel());
91 67d30f02 Christos KK Loverdos
                panel.setHeader(createHeader(resources, title, ajaxLoader, open));
92 39f6d7b0 Christos Stathis
                panel.setOpen(open);
93 67d30f02 Christos KK Loverdos
94 67d30f02 Christos KK Loverdos
        if(!ajaxLoader) {
95 67d30f02 Christos KK Loverdos
            addOpenCloseHandlers();
96 67d30f02 Christos KK Loverdos
        }
97 67d30f02 Christos KK Loverdos
98 39f6d7b0 Christos Stathis
                initWidget(panel);
99 39f6d7b0 Christos Stathis
        }
100 67d30f02 Christos KK Loverdos
101 67d30f02 Christos KK Loverdos
    private void addOpenCloseHandlers() {
102 67d30f02 Christos KK Loverdos
        panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
103 67d30f02 Christos KK Loverdos
            @Override
104 67d30f02 Christos KK Loverdos
            public void onOpen(OpenEvent<DisclosurePanel> event) {
105 67d30f02 Christos KK Loverdos
                panel.setHeader(createHeader(resources, title, false, true));
106 67d30f02 Christos KK Loverdos
            }
107 67d30f02 Christos KK Loverdos
        });
108 67d30f02 Christos KK Loverdos
        panel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
109 67d30f02 Christos KK Loverdos
110 67d30f02 Christos KK Loverdos
            @Override
111 67d30f02 Christos KK Loverdos
            public void onClose(CloseEvent<DisclosurePanel> event) {
112 67d30f02 Christos KK Loverdos
                panel.setHeader(createHeader(resources, title, false, false));
113 67d30f02 Christos KK Loverdos
            }
114 67d30f02 Christos KK Loverdos
        });
115 67d30f02 Christos KK Loverdos
    }
116 67d30f02 Christos KK Loverdos
117 67d30f02 Christos KK Loverdos
    public void setLoaded(boolean open) {
118 67d30f02 Christos KK Loverdos
        this.panel.setHeader(createHeader(resources, title, false, open));
119 67d30f02 Christos KK Loverdos
        addOpenCloseHandlers();
120 67d30f02 Christos KK Loverdos
    }
121 39f6d7b0 Christos Stathis
        
122 67d30f02 Christos KK Loverdos
        Widget createHeader(Resources resources, String title, boolean ajaxLoader, boolean open) {
123 08cc5916 Christos Stathis
                HorizontalPanel header = new HorizontalPanel();
124 08cc5916 Christos Stathis
        
125 08cc5916 Christos Stathis
                Image img = new Image(resources.icon());
126 08cc5916 Christos Stathis
                header.add(img);
127 08cc5916 Christos Stathis
                header.setCellVerticalAlignment(img, HasVerticalAlignment.ALIGN_MIDDLE);
128 08cc5916 Christos Stathis
                header.setCellWidth(img, "32px");
129 08cc5916 Christos Stathis
                HTML titleHtml = new HTML(title);
130 08cc5916 Christos Stathis
                header.add(titleHtml);
131 08cc5916 Christos Stathis
                header.setCellVerticalAlignment(titleHtml, HasVerticalAlignment.ALIGN_MIDDLE);
132 67d30f02 Christos KK Loverdos
                Image arrow = new Image(ajaxLoader ? resources.ajaxLoader() : open ? resources.open() : resources.closed());
133 08cc5916 Christos Stathis
                arrow.addStyleName(resources.pithosDisclosurePanelCss().arrow());
134 08cc5916 Christos Stathis
                header.add(arrow);
135 08cc5916 Christos Stathis
                header.setCellHorizontalAlignment(arrow, HasHorizontalAlignment.ALIGN_RIGHT);
136 08cc5916 Christos Stathis
                header.setCellVerticalAlignment(arrow, HasVerticalAlignment.ALIGN_MIDDLE);
137 08cc5916 Christos Stathis
                
138 08cc5916 Christos Stathis
                header.addStyleName(resources.pithosDisclosurePanelCss().header());
139 08cc5916 Christos Stathis
                return header;
140 39f6d7b0 Christos Stathis
        }
141 39f6d7b0 Christos Stathis
        
142 db365c2d Christos Stathis
        public void setContent(Widget widget) {
143 db365c2d Christos Stathis
                panel.setContent(widget);
144 7e8e9ff0 Christos Stathis
                panel.getContent().removeStyleName("content");
145 7e8e9ff0 Christos Stathis
                panel.getContent().addStyleName(resources.pithosDisclosurePanelCss().content());
146 39f6d7b0 Christos Stathis
        }
147 39f6d7b0 Christos Stathis
}