Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (4.2 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 gr.grnet.pithos.web.client.grouptree.GroupTreeView;
39 39f6d7b0 Christos Stathis
import gr.grnet.pithos.web.client.grouptree.GroupTreeView.Templates;
40 39f6d7b0 Christos Stathis
41 39f6d7b0 Christos Stathis
import com.google.gwt.dom.client.Style;
42 39f6d7b0 Christos Stathis
import com.google.gwt.event.logical.shared.CloseEvent;
43 39f6d7b0 Christos Stathis
import com.google.gwt.event.logical.shared.CloseHandler;
44 39f6d7b0 Christos Stathis
import com.google.gwt.event.logical.shared.OpenEvent;
45 39f6d7b0 Christos Stathis
import com.google.gwt.event.logical.shared.OpenHandler;
46 39f6d7b0 Christos Stathis
import com.google.gwt.resources.client.ClientBundle;
47 39f6d7b0 Christos Stathis
import com.google.gwt.resources.client.CssResource;
48 39f6d7b0 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
49 39f6d7b0 Christos Stathis
import com.google.gwt.resources.client.CssResource.ImportedWithPrefix;
50 39f6d7b0 Christos Stathis
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
51 39f6d7b0 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
52 39f6d7b0 Christos Stathis
import com.google.gwt.user.client.ui.Composite;
53 39f6d7b0 Christos Stathis
import com.google.gwt.user.client.ui.DisclosurePanel;
54 39f6d7b0 Christos Stathis
import com.google.gwt.user.client.ui.HTML;
55 39f6d7b0 Christos Stathis
import com.google.gwt.user.client.ui.IsWidget;
56 39f6d7b0 Christos Stathis
57 39f6d7b0 Christos Stathis
public class PithosDisclosurePanel extends Composite {
58 39f6d7b0 Christos Stathis
59 39f6d7b0 Christos Stathis
        public interface Style extends CssResource {
60 39f6d7b0 Christos Stathis
                String disclosurePanel();
61 39f6d7b0 Christos Stathis
        }
62 39f6d7b0 Christos Stathis
        
63 39f6d7b0 Christos Stathis
        public interface Resources extends ClientBundle {
64 39f6d7b0 Christos Stathis
                @Source("PithosDisclosurePanel.css")
65 39f6d7b0 Christos Stathis
                Style pithosDisclosurePanelCss();
66 39f6d7b0 Christos Stathis
                
67 39f6d7b0 Christos Stathis
                @Source("upArrow.png")
68 39f6d7b0 Christos Stathis
                ImageResource icon();
69 39f6d7b0 Christos Stathis
                
70 39f6d7b0 Christos Stathis
                @Source("upArrow.png")
71 39f6d7b0 Christos Stathis
                ImageResource open();
72 39f6d7b0 Christos Stathis
                
73 39f6d7b0 Christos Stathis
                @Source("downArrow.png")
74 39f6d7b0 Christos Stathis
                ImageResource closed();
75 39f6d7b0 Christos Stathis
        }
76 39f6d7b0 Christos Stathis
        
77 39f6d7b0 Christos Stathis
        DisclosurePanel panel;
78 39f6d7b0 Christos Stathis
        
79 39f6d7b0 Christos Stathis
        public PithosDisclosurePanel(final Resources resources, final String title, boolean open) {
80 39f6d7b0 Christos Stathis
                resources.pithosDisclosurePanelCss().ensureInjected();
81 39f6d7b0 Christos Stathis
                panel = new DisclosurePanel();
82 39f6d7b0 Christos Stathis
                panel.addStyleName(resources.pithosDisclosurePanelCss().disclosurePanel());
83 39f6d7b0 Christos Stathis
                panel.setHeader(createHeader(resources, title, open));
84 39f6d7b0 Christos Stathis
                panel.setOpen(open);
85 39f6d7b0 Christos Stathis
                panel.setAnimationEnabled(true);
86 39f6d7b0 Christos Stathis
                panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
87 39f6d7b0 Christos Stathis
                        
88 39f6d7b0 Christos Stathis
                        @Override
89 39f6d7b0 Christos Stathis
                        public void onOpen(OpenEvent<DisclosurePanel> event) {
90 39f6d7b0 Christos Stathis
                                panel.setHeader(createHeader(resources, title, true));
91 39f6d7b0 Christos Stathis
                        }
92 39f6d7b0 Christos Stathis
                });
93 39f6d7b0 Christos Stathis
                panel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
94 39f6d7b0 Christos Stathis
                        
95 39f6d7b0 Christos Stathis
                        @Override
96 39f6d7b0 Christos Stathis
                        public void onClose(CloseEvent<DisclosurePanel> event) {
97 39f6d7b0 Christos Stathis
                                panel.setHeader(createHeader(resources, title, false));
98 39f6d7b0 Christos Stathis
                        }
99 39f6d7b0 Christos Stathis
                });
100 39f6d7b0 Christos Stathis
                initWidget(panel);
101 39f6d7b0 Christos Stathis
        }
102 39f6d7b0 Christos Stathis
        
103 39f6d7b0 Christos Stathis
        HTML createHeader(Resources resources, String title, boolean open) {
104 39f6d7b0 Christos Stathis
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
105 39f6d7b0 Christos Stathis
        sb.appendHtmlConstant(AbstractImagePrototype.create(resources.icon()).getHTML()).appendHtmlConstant("&nbsp;");
106 39f6d7b0 Christos Stathis
        sb.append(Templates.INSTANCE.nameSpan(title));
107 39f6d7b0 Christos Stathis
        sb.appendHtmlConstant(AbstractImagePrototype.create(open ? resources.open() : resources.closed()).getHTML());
108 39f6d7b0 Christos Stathis
        return new HTML(sb.toSafeHtml());
109 39f6d7b0 Christos Stathis
        }
110 39f6d7b0 Christos Stathis
        
111 39f6d7b0 Christos Stathis
        public void add(IsWidget widget) {
112 39f6d7b0 Christos Stathis
                panel.add(widget);
113 39f6d7b0 Christos Stathis
        }
114 39f6d7b0 Christos Stathis
}